Loading app/src/main/java/foundation/e/apps/data/fused/FusedApiImpl.kt +42 −1 Original line number Diff line number Diff line Loading @@ -61,13 +61,18 @@ import foundation.e.apps.data.fused.utils.CategoryUtils import foundation.e.apps.data.fusedDownload.models.FusedDownload import foundation.e.apps.data.gplay.GplayStoreRepository import foundation.e.apps.data.handleNetworkResult import foundation.e.apps.data.login.AuthObject import foundation.e.apps.data.preference.PreferenceManagerModule import foundation.e.apps.install.pkg.PWAManagerModule import foundation.e.apps.install.pkg.PkgManagerModule import foundation.e.apps.ui.home.model.HomeChildFusedAppDiffUtil import foundation.e.apps.utils.eventBus.AppEvent import foundation.e.apps.utils.eventBus.EventBus import kotlinx.coroutines.Deferred import kotlinx.coroutines.MainScope import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import retrofit2.Response import timber.log.Timber import javax.inject.Inject Loading @@ -91,6 +96,8 @@ class FusedApiImpl @Inject constructor( private const val CATEGORY_TITLE_REPLACEABLE_CONJUNCTION = "&" private const val CATEGORY_OPEN_GAMES_ID = "game_open_games" private const val CATEGORY_OPEN_GAMES_TITLE = "Open games" private const val THRESHOLD_LIMITED_RESULT_HOME_PAGE = 4 private const val KEYWORD_TEST_SEARCH = "facebook" } /** Loading Loading @@ -1030,6 +1037,8 @@ class FusedApiImpl @Inject constructor( val fusedAppList = searchResults.first.map { app -> replaceWithFDroid(app) }.toMutableList() handleLimitedResult(fusedAppList) if (searchResults.second.isNotEmpty()) { fusedAppList.add(FusedApp(isPlaceHolder = true)) } Loading @@ -1038,6 +1047,18 @@ class FusedApiImpl @Inject constructor( } } private suspend fun handleLimitedResult(appList: List<FusedApp>?) { if (appList.isNullOrEmpty()) { // Call search api with a common keyword (ex: facebook) // to ensure Gplay is returning empty as search result for other keywords as well val searchResult = gplayRepository.getSearchResult(KEYWORD_TEST_SEARCH, null) if (searchResult.first.isEmpty()) { Timber.w("Limited result for search is found...") refreshToken() } } } /* * This function will replace a GPlay app with F-Droid app if exists, * else will show the GPlay app itself. Loading Loading @@ -1174,10 +1195,30 @@ class FusedApiImpl @Inject constructor( } list.add(FusedHome(it.key, fusedApps)) } Timber.d("===> $list") handleLimitedResult(list) Timber.d("HomePageData: $list") return list } private fun handleLimitedResult(fusedHomeList: List<FusedHome>) { val gplayHomes = fusedHomeList.filter { fusedHome -> fusedHome.source.isEmpty() } val hasGplayLimitedResult = gplayHomes.any { fusedHome -> fusedHome.list.size < THRESHOLD_LIMITED_RESULT_HOME_PAGE } if (hasGplayLimitedResult) { Timber.w("Limited result is found for homepage...") refreshToken() } } private fun refreshToken() { MainScope().launch { EventBus.invokeEvent( AppEvent.InvalidAuthEvent(AuthObject.GPlayAuth::class.java.simpleName) ) } } /* * FusedApp-related internal extensions and functions */ Loading Loading
app/src/main/java/foundation/e/apps/data/fused/FusedApiImpl.kt +42 −1 Original line number Diff line number Diff line Loading @@ -61,13 +61,18 @@ import foundation.e.apps.data.fused.utils.CategoryUtils import foundation.e.apps.data.fusedDownload.models.FusedDownload import foundation.e.apps.data.gplay.GplayStoreRepository import foundation.e.apps.data.handleNetworkResult import foundation.e.apps.data.login.AuthObject import foundation.e.apps.data.preference.PreferenceManagerModule import foundation.e.apps.install.pkg.PWAManagerModule import foundation.e.apps.install.pkg.PkgManagerModule import foundation.e.apps.ui.home.model.HomeChildFusedAppDiffUtil import foundation.e.apps.utils.eventBus.AppEvent import foundation.e.apps.utils.eventBus.EventBus import kotlinx.coroutines.Deferred import kotlinx.coroutines.MainScope import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import retrofit2.Response import timber.log.Timber import javax.inject.Inject Loading @@ -91,6 +96,8 @@ class FusedApiImpl @Inject constructor( private const val CATEGORY_TITLE_REPLACEABLE_CONJUNCTION = "&" private const val CATEGORY_OPEN_GAMES_ID = "game_open_games" private const val CATEGORY_OPEN_GAMES_TITLE = "Open games" private const val THRESHOLD_LIMITED_RESULT_HOME_PAGE = 4 private const val KEYWORD_TEST_SEARCH = "facebook" } /** Loading Loading @@ -1030,6 +1037,8 @@ class FusedApiImpl @Inject constructor( val fusedAppList = searchResults.first.map { app -> replaceWithFDroid(app) }.toMutableList() handleLimitedResult(fusedAppList) if (searchResults.second.isNotEmpty()) { fusedAppList.add(FusedApp(isPlaceHolder = true)) } Loading @@ -1038,6 +1047,18 @@ class FusedApiImpl @Inject constructor( } } private suspend fun handleLimitedResult(appList: List<FusedApp>?) { if (appList.isNullOrEmpty()) { // Call search api with a common keyword (ex: facebook) // to ensure Gplay is returning empty as search result for other keywords as well val searchResult = gplayRepository.getSearchResult(KEYWORD_TEST_SEARCH, null) if (searchResult.first.isEmpty()) { Timber.w("Limited result for search is found...") refreshToken() } } } /* * This function will replace a GPlay app with F-Droid app if exists, * else will show the GPlay app itself. Loading Loading @@ -1174,10 +1195,30 @@ class FusedApiImpl @Inject constructor( } list.add(FusedHome(it.key, fusedApps)) } Timber.d("===> $list") handleLimitedResult(list) Timber.d("HomePageData: $list") return list } private fun handleLimitedResult(fusedHomeList: List<FusedHome>) { val gplayHomes = fusedHomeList.filter { fusedHome -> fusedHome.source.isEmpty() } val hasGplayLimitedResult = gplayHomes.any { fusedHome -> fusedHome.list.size < THRESHOLD_LIMITED_RESULT_HOME_PAGE } if (hasGplayLimitedResult) { Timber.w("Limited result is found for homepage...") refreshToken() } } private fun refreshToken() { MainScope().launch { EventBus.invokeEvent( AppEvent.InvalidAuthEvent(AuthObject.GPlayAuth::class.java.simpleName) ) } } /* * FusedApp-related internal extensions and functions */ Loading