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