mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-16 11:42:16 -04:00
AuthProvider: Return null instead of invalid AuthData
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -41,7 +41,7 @@ class AuthProvider @Inject constructor(
|
||||
private val gson: Gson
|
||||
) {
|
||||
|
||||
val authData: AuthData get() = getSavedAuthData()
|
||||
val authData: AuthData? get() = getSavedAuthData()
|
||||
|
||||
val isAnonymous: Boolean
|
||||
get() {
|
||||
@@ -52,22 +52,22 @@ class AuthProvider @Inject constructor(
|
||||
suspend fun isSavedAuthDataValid(): Boolean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
AuthValidator(getSavedAuthData())
|
||||
AuthValidator(authData ?: return@withContext false)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
.isValid()
|
||||
} catch (e: Exception) {
|
||||
} catch (exception: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSavedAuthData(): AuthData {
|
||||
private fun getSavedAuthData(): AuthData? {
|
||||
Log.i("Loading saved AuthData")
|
||||
val rawAuth: String = Preferences.getString(context, PREFERENCE_AUTH_DATA)
|
||||
return if (rawAuth.isNotEmpty()) {
|
||||
gson.fromJson(rawAuth, AuthData::class.java)
|
||||
} else {
|
||||
AuthData("", "")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,13 @@ class DownloadWorker @AssistedInject constructor(
|
||||
private val TAG = DownloadWorker::class.java.simpleName
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
// Bail out immediately if authData is not valid
|
||||
if (!authProvider.isSavedAuthDataValid()) {
|
||||
Log.e(TAG, "AuthData is not valid, exiting!")
|
||||
onFailure()
|
||||
return Result.failure()
|
||||
}
|
||||
|
||||
// Try to parse input data into a valid app
|
||||
try {
|
||||
val downloadData = inputData.getString(DownloadWorkerUtil.DOWNLOAD_DATA)
|
||||
@@ -97,6 +104,7 @@ class DownloadWorker @AssistedInject constructor(
|
||||
icon = Bitmap.createScaledBitmap(bitmap, 96, 96, true)
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, "Failed to parse download data", exception)
|
||||
onFailure()
|
||||
return Result.failure()
|
||||
}
|
||||
|
||||
@@ -104,7 +112,7 @@ class DownloadWorker @AssistedInject constructor(
|
||||
setForeground(getForegroundInfo())
|
||||
|
||||
// Purchase the app (free apps needs to be purchased too)
|
||||
purchaseHelper = PurchaseHelper(authProvider.authData)
|
||||
purchaseHelper = PurchaseHelper(authProvider.authData!!)
|
||||
.using(HttpClient.getPreferredClient(appContext))
|
||||
|
||||
notificationManager =
|
||||
@@ -116,7 +124,7 @@ class DownloadWorker @AssistedInject constructor(
|
||||
}
|
||||
if (download.fileList.isEmpty()) {
|
||||
Log.i(TAG, "Nothing to download!")
|
||||
notifyStatus(DownloadStatus.FAILED)
|
||||
onFailure()
|
||||
return Result.failure()
|
||||
}
|
||||
|
||||
@@ -171,7 +179,11 @@ class DownloadWorker @AssistedInject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
if (!requestList.all { it.file.exists() }) return Result.failure()
|
||||
if (!requestList.all { it.file.exists() }) {
|
||||
Log.e(TAG, "Downloaded files are missing")
|
||||
onFailure()
|
||||
return Result.failure()
|
||||
}
|
||||
|
||||
// Mark download as completed
|
||||
onSuccess()
|
||||
|
||||
@@ -130,7 +130,7 @@ class UpdateWorker @AssistedInject constructor(
|
||||
try {
|
||||
val updatesList = AppUtil.getUpdatableApps(
|
||||
context = appContext,
|
||||
authData = authProvider.authData,
|
||||
authData = authProvider.authData!!,
|
||||
gson = gson,
|
||||
verifyCert = true,
|
||||
selfUpdate = false
|
||||
|
||||
@@ -57,7 +57,7 @@ class AccountFragment : BaseFragment<FragmentAccountBinding>() {
|
||||
binding.chipTos.setOnClickListener { browse(URL_TOS) }
|
||||
}
|
||||
|
||||
authProvider.authData.userProfile?.let {
|
||||
authProvider.authData?.userProfile?.let {
|
||||
val avatar = if (authProvider.isAnonymous) R.mipmap.ic_launcher else it.artwork.url
|
||||
binding.imgAvatar.load(avatar) {
|
||||
placeholder(R.drawable.bg_placeholder)
|
||||
|
||||
@@ -198,7 +198,7 @@ class MoreDialogFragment : DialogFragment() {
|
||||
) {
|
||||
SubcomposeAsyncImage(
|
||||
model = ImageRequest.Builder(LocalContext.current)
|
||||
.data(if (authProvider.isAnonymous) R.mipmap.ic_launcher else authProvider.authData.userProfile?.artwork?.url)
|
||||
.data(if (authProvider.isAnonymous) R.mipmap.ic_launcher else authProvider.authData?.userProfile?.artwork?.url)
|
||||
.placeholder(R.drawable.ic_account)
|
||||
.crossfade(true)
|
||||
.build(),
|
||||
@@ -213,12 +213,12 @@ class MoreDialogFragment : DialogFragment() {
|
||||
horizontalAlignment = Alignment.Start
|
||||
) {
|
||||
Text(
|
||||
text = if (authProvider.isAnonymous) "anonymous" else authProvider.authData.userProfile!!.name,
|
||||
text = if (authProvider.isAnonymous) "anonymous" else authProvider.authData!!.userProfile!!.name,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontSize = 16.sp
|
||||
)
|
||||
Text(
|
||||
text = if (authProvider.isAnonymous) "anonymous@gmail.com" else authProvider.authData.userProfile!!.email,
|
||||
text = if (authProvider.isAnonymous) "anonymous@gmail.com" else authProvider.authData!!.userProfile!!.email,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 14.sp
|
||||
)
|
||||
|
||||
@@ -46,7 +46,7 @@ class BlacklistViewModel @Inject constructor(
|
||||
authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
private val blacklistProvider: BlacklistProvider = BlacklistProvider.with(context)
|
||||
private val appDetailsHelper = AppDetailsHelper(authProvider.authData)
|
||||
private val appDetailsHelper = AppDetailsHelper(authProvider.authData!!)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
private val _blacklistedApps = MutableStateFlow<List<App>?>(null)
|
||||
|
||||
@@ -56,11 +56,7 @@ class InstalledViewModel @Inject constructor(
|
||||
fun fetchApps() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val apps = AppUtil.getFilteredInstalledApps(
|
||||
context,
|
||||
authProvider.authData
|
||||
)
|
||||
|
||||
val apps = AppUtil.getFilteredInstalledApps(context, authProvider.authData!!)
|
||||
_installedApps.emit(apps.sortedBy { it.displayName.lowercase(Locale.getDefault()) })
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, "Failed to get installed apps", exception)
|
||||
|
||||
@@ -71,7 +71,7 @@ class UpdatesViewModel @Inject constructor(
|
||||
|
||||
val updates = AppUtil.getUpdatableApps(
|
||||
context,
|
||||
authProvider.authData,
|
||||
authProvider.authData!!,
|
||||
gson,
|
||||
!isExtendedUpdateEnabled
|
||||
).sortedBy { it.displayName.lowercase(Locale.getDefault()) }
|
||||
|
||||
@@ -43,7 +43,7 @@ class ExpandedStreamBrowseViewModel @Inject constructor(
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private val streamHelper: ExpandedBrowseHelper = ExpandedBrowseHelper(authProvider.authData)
|
||||
private val streamHelper: ExpandedBrowseHelper = ExpandedBrowseHelper(authProvider.authData!!)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<StreamCluster> = MutableLiveData()
|
||||
|
||||
@@ -46,7 +46,7 @@ class CategoryViewModel @Inject constructor(
|
||||
) : ViewModel() {
|
||||
private val TAG = CategoryViewModel::class.java.simpleName
|
||||
|
||||
private val categoryHelper: CategoryHelper = CategoryHelper(authProvider.authData)
|
||||
private val categoryHelper: CategoryHelper = CategoryHelper(authProvider.authData!!)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
private var stash: CategoryStash = mutableMapOf(
|
||||
|
||||
@@ -43,8 +43,8 @@ class AppDetailsViewModel @Inject constructor(
|
||||
private val exodusApiKey = "Token bbe6ebae4ad45a9cbacb17d69739799b8df2c7ae"
|
||||
|
||||
private val httpClient = HttpClient.getPreferredClient(context)
|
||||
private val appDetailsHelper = AppDetailsHelper(authProvider.authData).using(httpClient)
|
||||
private val reviewsHelper = ReviewsHelper(authProvider.authData).using(httpClient)
|
||||
private val appDetailsHelper = AppDetailsHelper(authProvider.authData!!).using(httpClient)
|
||||
private val reviewsHelper = ReviewsHelper(authProvider.authData!!).using(httpClient)
|
||||
|
||||
private val appStash: MutableMap<String, App> = mutableMapOf()
|
||||
private val _app = MutableSharedFlow<App>()
|
||||
|
||||
@@ -46,9 +46,9 @@ class DetailsClusterViewModel @Inject constructor(
|
||||
authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private var appDetailsHelper = AppDetailsHelper(authProvider.authData)
|
||||
private var appDetailsHelper = AppDetailsHelper(authProvider.authData!!)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
private var streamHelper = StreamHelper(authProvider.authData)
|
||||
private var streamHelper = StreamHelper(authProvider.authData!!)
|
||||
|
||||
|
||||
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
||||
|
||||
@@ -24,7 +24,7 @@ class DetailsMoreViewModel @Inject constructor(
|
||||
|
||||
private val TAG = DetailsMoreViewModel::class.java.simpleName
|
||||
|
||||
private val appDetailsHelper = AppDetailsHelper(authProvider.authData)
|
||||
private val appDetailsHelper = AppDetailsHelper(authProvider.authData!!)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
private val dependantAppsStash = mutableMapOf<String, List<App>>()
|
||||
|
||||
@@ -48,9 +48,9 @@ class DevProfileViewModel @Inject constructor(
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
private var appDetailsHelper = AppDetailsHelper(authProvider.authData)
|
||||
private var appDetailsHelper = AppDetailsHelper(authProvider.authData!!)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
private var streamHelper = StreamHelper(authProvider.authData)
|
||||
private var streamHelper = StreamHelper(authProvider.authData!!)
|
||||
|
||||
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
||||
var devStream:DevStream = DevStream()
|
||||
|
||||
@@ -43,7 +43,7 @@ class ReviewViewModel @Inject constructor(
|
||||
private val authProvider: AuthProvider
|
||||
) : ViewModel() {
|
||||
|
||||
var reviewsHelper: ReviewsHelper = ReviewsHelper(authProvider.authData)
|
||||
var reviewsHelper: ReviewsHelper = ReviewsHelper(authProvider.authData!!)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<ReviewCluster> = MutableLiveData()
|
||||
|
||||
@@ -51,7 +51,7 @@ class SearchResultViewModel @Inject constructor(
|
||||
private val TAG = SearchResultViewModel::class.java.simpleName
|
||||
|
||||
private val webSearchHelper: WebSearchHelper = WebSearchHelper()
|
||||
private val searchHelper: SearchHelper = SearchHelper(authProvider.authData)
|
||||
private val searchHelper: SearchHelper = SearchHelper(authProvider.authData!!)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveData: MutableLiveData<SearchBundle> = MutableLiveData()
|
||||
|
||||
@@ -44,7 +44,7 @@ class SearchSuggestionViewModel @Inject constructor(
|
||||
) : ViewModel() {
|
||||
|
||||
private val webSearchHelper: WebSearchHelper = WebSearchHelper()
|
||||
private val searchHelper: SearchHelper = SearchHelper(authProvider.authData)
|
||||
private val searchHelper: SearchHelper = SearchHelper(authProvider.authData!!)
|
||||
.using(HttpClient.getPreferredClient(context))
|
||||
|
||||
val liveSearchSuggestions: MutableLiveData<List<SearchSuggestEntry>> = MutableLiveData()
|
||||
|
||||
@@ -32,7 +32,7 @@ class SheetsViewModel @Inject constructor(
|
||||
fun purchase(app: App, customVersion: Int) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val purchaseHelper = PurchaseHelper(authProvider.authData)
|
||||
val purchaseHelper = PurchaseHelper(authProvider.authData!!)
|
||||
val files = purchaseHelper.purchase(app.packageName, customVersion, app.offerType)
|
||||
if (files.isNotEmpty()) {
|
||||
AuroraApp.events.send(
|
||||
|
||||
Reference in New Issue
Block a user