From 80fefa9115ff83075f62fdcb61d1e778e920375f Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 9 Dec 2024 10:53:56 +0100 Subject: [PATCH 1/4] Remove useless AuthData arguments --- .../data/application/ApplicationRepository.kt | 7 +++---- .../e/apps/data/application/apps/AppsApi.kt | 3 +-- .../apps/data/application/apps/AppsApiImpl.kt | 8 ++------ .../e/apps/data/updates/UpdatesManagerImpl.kt | 2 -- .../e/apps/ui/MainActivityViewModel.kt | 3 +-- .../e/apps/UpdateManagerImptTest.kt | 3 --- .../foundation/e/apps/apps/AppsApiTest.kt | 20 ++++++++----------- .../AppInstallProcessorTest.kt | 2 -- 8 files changed, 15 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/application/ApplicationRepository.kt b/app/src/main/java/foundation/e/apps/data/application/ApplicationRepository.kt index 9e32ed817..e0ec4c9f0 100644 --- a/app/src/main/java/foundation/e/apps/data/application/ApplicationRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/application/ApplicationRepository.kt @@ -62,14 +62,13 @@ class ApplicationRepository @Inject constructor( suspend fun getApplicationDetails( packageNameList: List, - authData: AuthData, origin: Origin ): Pair, ResultStatus> { - return appsApi.getApplicationDetails(packageNameList, authData, origin) + return appsApi.getApplicationDetails(packageNameList, origin) } - suspend fun getAppFilterLevel(application: Application, authData: AuthData?): FilterLevel { - return appsApi.getAppFilterLevel(application, authData) + suspend fun getAppFilterLevel(application: Application): FilterLevel { + return appsApi.getAppFilterLevel(application) } suspend fun getApplicationDetails( diff --git a/app/src/main/java/foundation/e/apps/data/application/apps/AppsApi.kt b/app/src/main/java/foundation/e/apps/data/application/apps/AppsApi.kt index 72f5eb4d6..435288eac 100644 --- a/app/src/main/java/foundation/e/apps/data/application/apps/AppsApi.kt +++ b/app/src/main/java/foundation/e/apps/data/application/apps/AppsApi.kt @@ -36,7 +36,6 @@ interface AppsApi { suspend fun getApplicationDetails( packageNameList: List, - authData: AuthData, origin: Origin ): Pair, ResultStatus> @@ -55,7 +54,7 @@ interface AppsApi { */ fun getFusedAppInstallationStatus(application: Application): Status - suspend fun getAppFilterLevel(application: Application, authData: AuthData?): FilterLevel + suspend fun getAppFilterLevel(application: Application): FilterLevel /** * @return returns true if there is changes in data, otherwise false diff --git a/app/src/main/java/foundation/e/apps/data/application/apps/AppsApiImpl.kt b/app/src/main/java/foundation/e/apps/data/application/apps/AppsApiImpl.kt index 9aa108c64..ecd417b5d 100644 --- a/app/src/main/java/foundation/e/apps/data/application/apps/AppsApiImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/application/apps/AppsApiImpl.kt @@ -78,7 +78,6 @@ class AppsApiImpl @Inject constructor( override suspend fun getApplicationDetails( packageNameList: List, - authData: AuthData, origin: Origin ): Pair, ResultStatus> { val list = mutableListOf() @@ -87,7 +86,7 @@ class AppsApiImpl @Inject constructor( if (origin == Origin.CLEANAPK) { getAppDetailsListFromCleanApk(packageNameList) } else { - getAppDetailsListFromGPlay(packageNameList, authData) + getAppDetailsListFromGPlay(packageNameList) } response.first.forEach { @@ -123,13 +122,12 @@ class AppsApiImpl @Inject constructor( private suspend fun getAppDetailsListFromGPlay( packageNameList: List, - authData: AuthData, ): Pair, ResultStatus> { val applicationList = mutableListOf() val result = handleNetworkResult { appSources.gplayRepo.getAppsDetails(packageNameList).forEach { app -> - handleFilteredApps(app, authData, applicationList) + handleFilteredApps(app, applicationList) } } @@ -144,7 +142,6 @@ class AppsApiImpl @Inject constructor( */ private suspend fun handleFilteredApps( app: App, - authData: AuthData, applicationList: MutableList ) { val application = app.toApplication(context) @@ -215,7 +212,6 @@ class AppsApiImpl @Inject constructor( override suspend fun getAppFilterLevel( application: Application, - authData: AuthData? ): FilterLevel { return applicationDataManager.getAppFilterLevel(application) } diff --git a/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt b/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt index 89628886b..9169a172c 100644 --- a/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt @@ -100,7 +100,6 @@ class UpdatesManagerImpl @Inject constructor( status = getUpdatesFromApi({ applicationRepository.getApplicationDetails( openSourceInstalledApps, - authData, Origin.CLEANAPK ) }, updateList) @@ -156,7 +155,6 @@ class UpdatesManagerImpl @Inject constructor( status = getUpdatesFromApi({ applicationRepository.getApplicationDetails( openSourceInstalledApps, - AuthData("", ""), Origin.CLEANAPK ) }, updateList) diff --git a/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt index 1de981227..a91df34c0 100644 --- a/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt @@ -179,11 +179,10 @@ class MainActivityViewModel @Inject constructor( */ fun verifyUiFilter(application: Application, method: () -> Unit) { viewModelScope.launch { - val authData = gPlayAuthData if (application.filterLevel.isInitialized()) { method() } else { - applicationRepository.getAppFilterLevel(application, authData).run { + applicationRepository.getAppFilterLevel(application).run { if (isInitialized()) { application.filterLevel = this method() diff --git a/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt b/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt index eb5c7090f..06ad1b1a4 100644 --- a/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt +++ b/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt @@ -372,7 +372,6 @@ class UpdateManagerImptTest { ) { Mockito.`when`( applicationRepository.getApplicationDetails( - any(), any(), eq(Origin.CLEANAPK) ) @@ -386,7 +385,6 @@ class UpdateManagerImptTest { if (gplayUpdates.first.isNotEmpty()) { Mockito.`when`( applicationRepository.getApplicationDetails( - any(), any(), any(), eq(Origin.GPLAY) @@ -398,7 +396,6 @@ class UpdateManagerImptTest { } else { Mockito.`when`( applicationRepository.getApplicationDetails( - any(), any(), any(), eq(Origin.GPLAY) diff --git a/app/src/test/java/foundation/e/apps/apps/AppsApiTest.kt b/app/src/test/java/foundation/e/apps/apps/AppsApiTest.kt index 8cda6e3cf..e76fa0a5a 100644 --- a/app/src/test/java/foundation/e/apps/apps/AppsApiTest.kt +++ b/app/src/test/java/foundation/e/apps/apps/AppsApiTest.kt @@ -92,10 +92,6 @@ class AppsApiTest { private lateinit var formatterMocked: MockedStatic - companion object { - private val AUTH_DATA = AuthData("e@e.email", "AtadyMsIAtadyM") - } - @Before fun setup() { MockitoAnnotations.openMocks(this) @@ -429,7 +425,7 @@ class AppsApiTest { latest_version_code = 123, ) - val filterLevel = appsApi.getAppFilterLevel(application, AUTH_DATA) + val filterLevel = appsApi.getAppFilterLevel(application) assertEquals("getAppFilterLevel", FilterLevel.UNKNOWN, filterLevel) } @@ -437,7 +433,7 @@ class AppsApiTest { fun `getAppFilterLevel when app is CleanApk`() = runTest { val fusedApp = getFusedAppForFilterLevelTest() - val filterLevel = appsApi.getAppFilterLevel(fusedApp, AUTH_DATA) + val filterLevel = appsApi.getAppFilterLevel(fusedApp) assertEquals("getAppFilterLevel", FilterLevel.NONE, filterLevel) } @@ -456,7 +452,7 @@ class AppsApiTest { fun `getAppFilterLevel when Authdata is NULL`() = runTest { val fusedApp = getFusedAppForFilterLevelTest() - val filterLevel = appsApi.getAppFilterLevel(fusedApp, null) + val filterLevel = appsApi.getAppFilterLevel(fusedApp) assertEquals("getAppFilterLevel", FilterLevel.NONE, filterLevel) } @@ -467,7 +463,7 @@ class AppsApiTest { this.restriction = Constants.Restriction.UNKNOWN } - val filterLevel = appsApi.getAppFilterLevel(fusedApp, AUTH_DATA) + val filterLevel = appsApi.getAppFilterLevel(fusedApp) assertEquals("getAppFilterLevel", FilterLevel.UI, filterLevel) } @@ -478,7 +474,7 @@ class AppsApiTest { this.restriction = Constants.Restriction.NOT_RESTRICTED } - val filterLevel = appsApi.getAppFilterLevel(fusedApp, AUTH_DATA) + val filterLevel = appsApi.getAppFilterLevel(fusedApp) assertEquals("getAppFilterLevel", FilterLevel.UI, filterLevel) } @@ -501,7 +497,7 @@ class AppsApiTest { ) ).thenReturn(listOf()) - val filterLevel = appsApi.getAppFilterLevel(fusedApp, AUTH_DATA) + val filterLevel = appsApi.getAppFilterLevel(fusedApp) assertEquals("getAppFilterLevel", FilterLevel.NONE, filterLevel) } @@ -521,7 +517,7 @@ class AppsApiTest { ) ).thenReturn(listOf()) - val filterLevel = appsApi.getAppFilterLevel(fusedApp, AUTH_DATA) + val filterLevel = appsApi.getAppFilterLevel(fusedApp) assertEquals("getAppFilterLevel", FilterLevel.DATA, filterLevel) } @@ -541,7 +537,7 @@ class AppsApiTest { ) ).thenThrow(RuntimeException()) - val filterLevel = appsApi.getAppFilterLevel(fusedApp, AUTH_DATA) + val filterLevel = appsApi.getAppFilterLevel(fusedApp) assertEquals("getAppFilterLevel", FilterLevel.UI, filterLevel) } } diff --git a/app/src/test/java/foundation/e/apps/installProcessor/AppInstallProcessorTest.kt b/app/src/test/java/foundation/e/apps/installProcessor/AppInstallProcessorTest.kt index 25edd4c73..a11efa092 100644 --- a/app/src/test/java/foundation/e/apps/installProcessor/AppInstallProcessorTest.kt +++ b/app/src/test/java/foundation/e/apps/installProcessor/AppInstallProcessorTest.kt @@ -20,7 +20,6 @@ package foundation.e.apps.installProcessor import android.content.Context import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import com.aurora.gplayapi.data.models.AuthData import foundation.e.apps.data.ResultSupreme import foundation.e.apps.data.enums.Status import foundation.e.apps.data.fdroid.FDroidRepository @@ -120,7 +119,6 @@ class AppInstallProcessorTest { ): AppInstall { val fusedDownload = createFusedDownload(packageName, downloadUrlList) fakeFusedDownloadDAO.addDownload(fusedDownload) - Mockito.`when`(appLoungeDataStore.getAuthData()).thenReturn(AuthData("", "")) return fusedDownload } -- GitLab From c812449db772190b77c1abbc239135bb59619426 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 9 Dec 2024 16:01:44 +0100 Subject: [PATCH 2/4] Remove home blinking --- .../foundation/e/apps/ui/home/HomeFragment.kt | 2 -- .../e/apps/ui/home/HomeViewModel.kt | 35 ------------------- 2 files changed, 37 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt b/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt index 11685cc09..2dfc6806d 100644 --- a/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt @@ -266,8 +266,6 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) { updateProgressOfDownloadingAppItemViews(homeParentRVAdapter, it) } - - homeViewModel.checkAnyChangeInAppStatus() } override fun onPause() { diff --git a/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt b/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt index 861527a73..455a9e304 100644 --- a/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt @@ -181,39 +181,4 @@ class HomeViewModel @Inject constructor( return false } - - fun checkAnyChangeInAppStatus() { - if (this.currentHomes == null) { - return - } - - val fusedHomes: MutableList = mutableListOf() - checkForChangesInAppStatus(fusedHomes) - - if (fusedHomes.isNotEmpty() && hasAnyChange(fusedHomes)) { - homeScreenData.value = ResultSupreme.Success(fusedHomes) - currentHomes = fusedHomes - } - } - - private fun checkForChangesInAppStatus(fusedHomes: MutableList) { - var home: Home? = null - this.currentHomes?.forEach { - - it.list.forEach { application -> - val status = - applicationRepository.getFusedAppInstallationStatus(application) - - if (application.status != status) { - application.status = status - home = it.copy() - // Setting a new id, so that recyclerview can find that this item is changed - home?.id = UUID.randomUUID().toString() - } - } - - fusedHomes.add(home ?: it) - home = null - } - } } -- GitLab From de77d1824f43e8b3ff3cb17827917305ddb2f963 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Tue, 10 Dec 2024 08:12:50 +0100 Subject: [PATCH 3/4] Refresh token when version code of app is 0 --- .../foundation/e/apps/data/NetworkHandler.kt | 2 + .../data/application/ApplicationRepository.kt | 3 +- .../e/apps/data/application/apps/AppsApi.kt | 1 - .../apps/data/application/apps/AppsApiImpl.kt | 1 - .../data/application/search/SearchApiImpl.kt | 7 ++-- .../data/playstore/PlayStoreRepository.kt | 19 +++++---- .../e/apps/data/updates/UpdatesManagerImpl.kt | 4 +- .../workmanager/AppInstallProcessor.kt | 3 ++ .../ui/application/ApplicationViewModel.kt | 41 +++++-------------- 9 files changed, 33 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/NetworkHandler.kt b/app/src/main/java/foundation/e/apps/data/NetworkHandler.kt index 6cadc578d..edf5d6146 100644 --- a/app/src/main/java/foundation/e/apps/data/NetworkHandler.kt +++ b/app/src/main/java/foundation/e/apps/data/NetworkHandler.kt @@ -46,6 +46,8 @@ suspend fun handleNetworkResult(call: suspend () -> T): ResultSupreme { handleSocketTimeoutException(e) } catch (e: GplayHttpRequestException) { resultSupremeGplayHttpRequestException(e) + } catch (e: IllegalStateException) { + throw e } catch (e: Exception) { handleOthersException(e) } diff --git a/app/src/main/java/foundation/e/apps/data/application/ApplicationRepository.kt b/app/src/main/java/foundation/e/apps/data/application/ApplicationRepository.kt index e0ec4c9f0..126b589d5 100644 --- a/app/src/main/java/foundation/e/apps/data/application/ApplicationRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/application/ApplicationRepository.kt @@ -74,10 +74,9 @@ class ApplicationRepository @Inject constructor( suspend fun getApplicationDetails( id: String, packageName: String, - authData: AuthData, origin: Origin ): Pair { - return appsApi.getApplicationDetails(id, packageName, authData, origin) + return appsApi.getApplicationDetails(id, packageName, origin) } suspend fun getCleanapkAppDetails(packageName: String): Pair { diff --git a/app/src/main/java/foundation/e/apps/data/application/apps/AppsApi.kt b/app/src/main/java/foundation/e/apps/data/application/apps/AppsApi.kt index 435288eac..067646e8f 100644 --- a/app/src/main/java/foundation/e/apps/data/application/apps/AppsApi.kt +++ b/app/src/main/java/foundation/e/apps/data/application/apps/AppsApi.kt @@ -42,7 +42,6 @@ interface AppsApi { suspend fun getApplicationDetails( id: String, packageName: String, - authData: AuthData, origin: Origin ): Pair diff --git a/app/src/main/java/foundation/e/apps/data/application/apps/AppsApiImpl.kt b/app/src/main/java/foundation/e/apps/data/application/apps/AppsApiImpl.kt index ecd417b5d..f98e6c154 100644 --- a/app/src/main/java/foundation/e/apps/data/application/apps/AppsApiImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/application/apps/AppsApiImpl.kt @@ -182,7 +182,6 @@ class AppsApiImpl @Inject constructor( override suspend fun getApplicationDetails( id: String, packageName: String, - authData: AuthData, origin: Origin ): Pair { var application: Application diff --git a/app/src/main/java/foundation/e/apps/data/application/search/SearchApiImpl.kt b/app/src/main/java/foundation/e/apps/data/application/search/SearchApiImpl.kt index 9c2fa1356..ead91ecce 100644 --- a/app/src/main/java/foundation/e/apps/data/application/search/SearchApiImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/application/search/SearchApiImpl.kt @@ -191,7 +191,7 @@ class SearchApiImpl @Inject constructor( val result = handleNetworkResult { if (appLoungePreference.isGplaySelected()) { - gplayPackageResult = getGplayPackagResult(query, authData) + gplayPackageResult = getGplayPackageResult(query) } if (appLoungePreference.isOpenSourceSelected()) { @@ -257,11 +257,10 @@ class SearchApiImpl @Inject constructor( return null } - private suspend fun getGplayPackagResult( + private suspend fun getGplayPackageResult( query: String, - authData: AuthData, ): Application? { - appsApi.getApplicationDetails(query, query, authData, Origin.GPLAY).let { + appsApi.getApplicationDetails(query, query, Origin.GPLAY).let { if (it.second == ResultStatus.OK && it.first.package_name.isNotEmpty()) { return it.first } diff --git a/app/src/main/java/foundation/e/apps/data/playstore/PlayStoreRepository.kt b/app/src/main/java/foundation/e/apps/data/playstore/PlayStoreRepository.kt index 41d0ce4d3..9977924a9 100644 --- a/app/src/main/java/foundation/e/apps/data/playstore/PlayStoreRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/playstore/PlayStoreRepository.kt @@ -31,7 +31,6 @@ import com.aurora.gplayapi.helpers.ContentRatingHelper import com.aurora.gplayapi.helpers.PurchaseHelper import com.aurora.gplayapi.helpers.contracts.TopChartsContract.Chart import com.aurora.gplayapi.helpers.contracts.TopChartsContract.Type -import com.aurora.gplayapi.helpers.web.WebAppDetailsHelper import com.aurora.gplayapi.helpers.web.WebCategoryHelper import com.aurora.gplayapi.helpers.web.WebCategoryStreamHelper import com.aurora.gplayapi.helpers.web.WebSearchHelper @@ -149,32 +148,34 @@ class PlayStoreRepository @Inject constructor( override suspend fun getAppDetails(packageNameOrId: String): Application { var appDetails: GplayApp? - val appDetailsHelper = try { + val appDetailsHelper = AppDetailsHelper(authenticatorRepository.getGPlayAuthOrThrow()).using(gPlayHttpClient) - } catch (exception: Exception) { - WebAppDetailsHelper().using(gPlayHttpClient) - } withContext(Dispatchers.IO) { appDetails = appDetailsHelper.getAppByPackageName(packageNameOrId) } + if (appDetails?.versionCode == 0) { + throw IllegalStateException("App version code cannot be 0") + } + return appDetails?.toApplication(context) ?: Application() } suspend fun getAppsDetails(packageNamesOrIds: List): List { val appDetailsList = mutableListOf() - val appDetailsHelper = try { + val appDetailsHelper = AppDetailsHelper(authenticatorRepository.getGPlayAuthOrThrow()).using(gPlayHttpClient) - } catch (exception: Exception) { - WebAppDetailsHelper().using(gPlayHttpClient) - } withContext(Dispatchers.IO) { appDetailsList.addAll(appDetailsHelper.getAppByPackageName(packageNamesOrIds)) } + if (appDetailsList.first().versionCode == 0) { + throw IllegalStateException("App version code cannot be 0") + } + return appDetailsList } diff --git a/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt b/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt index 9169a172c..d6cd28ffa 100644 --- a/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt @@ -35,8 +35,11 @@ import foundation.e.apps.data.application.search.SearchApi.Companion.APP_TYPE_AN import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.gitlab.SystemAppsUpdatesRepository import foundation.e.apps.data.handleNetworkResult +import foundation.e.apps.data.login.AuthObject import foundation.e.apps.data.preference.AppLoungePreference import foundation.e.apps.install.pkg.AppLoungePackageManager +import foundation.e.apps.utils.eventBus.AppEvent +import foundation.e.apps.utils.eventBus.EventBus import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll @@ -284,7 +287,6 @@ class UpdatesManagerImpl @Inject constructor( applicationRepository.getApplicationDetails( "", packageName, - authData, Origin.GPLAY ) } diff --git a/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt b/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt index 2c929ce8f..099f1f8c4 100644 --- a/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt +++ b/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt @@ -31,6 +31,7 @@ import foundation.e.apps.data.application.UpdatesDao import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.enums.Origin import foundation.e.apps.data.install.models.AppInstall +import foundation.e.apps.data.login.AuthObject import foundation.e.apps.data.playstore.utils.GplayHttpRequestException import foundation.e.apps.data.preference.AppLoungeDataStore import foundation.e.apps.domain.ValidateAppAgeLimitUseCase @@ -185,6 +186,8 @@ class AppInstallProcessor @Inject constructor( e ) return false + } catch (e: IllegalStateException) { + EventBus.invokeEvent(AppEvent.InvalidAuthEvent(AuthObject.GPlayAuth::class.java.simpleName)) } catch (e: Exception) { handleUpdateDownloadError( appInstall, diff --git a/app/src/main/java/foundation/e/apps/ui/application/ApplicationViewModel.kt b/app/src/main/java/foundation/e/apps/ui/application/ApplicationViewModel.kt index 4e72c47f8..d22258c37 100644 --- a/app/src/main/java/foundation/e/apps/ui/application/ApplicationViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/application/ApplicationViewModel.kt @@ -34,8 +34,6 @@ import foundation.e.apps.data.enums.Status import foundation.e.apps.data.install.AppManagerWrapper import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.CleanApkException -import foundation.e.apps.data.login.exceptions.GPlayException import foundation.e.apps.data.parentalcontrol.fdroid.FDroidAntiFeatureRepository import foundation.e.apps.data.playstore.PlayStoreRepository import foundation.e.apps.install.download.data.DownloadProgress @@ -43,6 +41,8 @@ import foundation.e.apps.install.download.data.DownloadProgressLD import foundation.e.apps.ui.application.ShareButtonVisibilityState.Hidden import foundation.e.apps.ui.application.ShareButtonVisibilityState.Visible import foundation.e.apps.ui.parentFragment.LoadingViewModel +import foundation.e.apps.utils.eventBus.AppEvent +import foundation.e.apps.utils.eventBus.EventBus import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow @@ -106,7 +106,6 @@ class ApplicationViewModel @Inject constructor( params.appId, params.packageName, params.isPurchased, - authData, params.origin ) return@onLoadData @@ -117,7 +116,6 @@ class ApplicationViewModel @Inject constructor( params.appId, params.packageName, params.isPurchased, - AuthData("", ""), params.origin ) return@onLoadData @@ -125,47 +123,30 @@ class ApplicationViewModel @Inject constructor( }, retryBlock) } - fun getApplicationDetails( + private fun getApplicationDetails( id: String, packageName: String, isPurchased: Boolean, - authData: AuthData, origin: Origin ) { viewModelScope.launch(Dispatchers.IO) { try { - val appData = + val result = applicationRepository.getApplicationDetails( id, packageName, - authData, origin ) - appData.first.isPurchased = isPurchased - applicationLiveData.postValue(appData) + result.first.isPurchased = isPurchased + applicationLiveData.postValue(result) - updateShareVisibilityState(appData.first.shareUri.toString()) - updateAppContentRatingState(packageName, appData.first.contentRating) - - val status = appData.second - - if (appData.second != ResultStatus.OK) { - val exception = - if (authData.aasToken.isNotBlank() || authData.authToken.isNotBlank()) - GPlayException( - appData.second == ResultStatus.TIMEOUT, - status.message.ifBlank { "Data load error" } - ) - else CleanApkException( - appData.second == ResultStatus.TIMEOUT, - status.message.ifBlank { "Data load error" } - ) - - exceptionsList.add(exception) - exceptionsLiveData.postValue(exceptionsList) - } + updateShareVisibilityState(result.first.shareUri.toString()) + updateAppContentRatingState(packageName, result.first.contentRating) } catch (e: InternalException.AppNotFound) { _errorMessageLiveData.postValue(R.string.app_not_found) + } catch (exception: IllegalStateException) { + exception.printStackTrace() + EventBus.invokeEvent(AppEvent.InvalidAuthEvent(AuthObject.GPlayAuth::class.java.simpleName)) } catch (e: Exception) { _errorMessageLiveData.postValue(R.string.unknown_error) } -- GitLab From 933721bafaa649517a523873eba3408060bf7945 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Tue, 10 Dec 2024 08:46:22 +0100 Subject: [PATCH 4/4] Remove useless delay It was added because we had uncomplete results at some point with gplayapi. We are now using the web api to display home page so this delay is useless. --- .../java/foundation/e/apps/ui/home/HomeFragment.kt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt b/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt index 2dfc6806d..b349adb42 100644 --- a/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt @@ -69,10 +69,6 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall @Inject lateinit var pwaManager: PwaManager - companion object { - private const val SCROLL_DELAY_IN_MILLIS = 500L - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) _binding = FragmentHomeBinding.bind(view) @@ -97,12 +93,6 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall } homeParentRVAdapter?.setData(it.data!!) - - // scrolling to top 500 ms later to give time UI elements to be rendered - viewLifecycleOwner.lifecycleScope.launch { - delay(SCROLL_DELAY_IN_MILLIS) - binding.parentRV.scrollToPosition(0) - } } } -- GitLab