diff --git a/app/src/main/java/foundation/e/apps/data/gplay/GplayStoreRepositoryImpl.kt b/app/src/main/java/foundation/e/apps/data/gplay/GplayStoreRepositoryImpl.kt index 85be60956b90140ee9c70c9f417bdb4b81009798..23d4e842771cba5651803d124090403875ffd95b 100644 --- a/app/src/main/java/foundation/e/apps/data/gplay/GplayStoreRepositoryImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/gplay/GplayStoreRepositoryImpl.kt @@ -52,11 +52,10 @@ class GplayStoreRepositoryImpl @Inject constructor( private val loginSourceRepository: LoginSourceRepository ) : GplayStoreRepository { - private val authData by lazy { loginSourceRepository.gplayAuth!! } - override suspend fun getHomeScreenData(): Any { val homeScreenData = mutableMapOf>() val homeElements = createTopChartElements() + val authData = loginSourceRepository.gplayAuth ?: return homeScreenData homeElements.forEach { val chart = it.value.keys.iterator().next() @@ -81,10 +80,13 @@ class GplayStoreRepositoryImpl @Inject constructor( query: String, ): Flow, Boolean>> { return flow { + /* * Variable names and logic made same as that of Aurora store. * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5171 */ + var authData = loginSourceRepository.gplayAuth ?: return@flow + val searchHelper = SearchHelper(authData).using(gPlayHttpClient) val searchBundle = searchHelper.searchResults(query) @@ -148,6 +150,8 @@ class GplayStoreRepositoryImpl @Inject constructor( } override suspend fun getSearchSuggestions(query: String): List { + val authData = loginSourceRepository.gplayAuth ?: return listOf() + val searchData = mutableListOf() withContext(Dispatchers.IO) { val searchHelper = SearchHelper(authData).using(gPlayHttpClient) @@ -157,6 +161,8 @@ class GplayStoreRepositoryImpl @Inject constructor( } override suspend fun getAppsByCategory(category: String, pageUrl: String?): StreamCluster { + val authData = loginSourceRepository.gplayAuth ?: return StreamCluster() + val subCategoryHelper = CategoryAppsHelper(authData).using(gPlayHttpClient) @@ -173,6 +179,8 @@ class GplayStoreRepositoryImpl @Inject constructor( return categoryList } + val authData = loginSourceRepository.gplayAuth ?: return categoryList + withContext(Dispatchers.IO) { val categoryHelper = CategoryHelper(authData).using(gPlayHttpClient) categoryList.addAll(categoryHelper.getAllCategoriesList(getCategoryType(type))) @@ -182,6 +190,8 @@ class GplayStoreRepositoryImpl @Inject constructor( override suspend fun getAppDetails(packageNameOrId: String): App? { var appDetails: App? + val authData = loginSourceRepository.gplayAuth ?: return null + withContext(Dispatchers.IO) { val appDetailsHelper = AppDetailsHelper(authData).using(gPlayHttpClient) appDetails = appDetailsHelper.getAppByPackageName(packageNameOrId) @@ -191,6 +201,8 @@ class GplayStoreRepositoryImpl @Inject constructor( override suspend fun getAppsDetails(packageNamesOrIds: List): List { val appDetailsList = mutableListOf() + val authData = loginSourceRepository.gplayAuth ?: return appDetailsList + withContext(Dispatchers.IO) { val appDetailsHelper = AppDetailsHelper(authData).using(gPlayHttpClient) appDetailsList.addAll(appDetailsHelper.getAppByPackageName(packageNamesOrIds)) @@ -267,6 +279,8 @@ class GplayStoreRepositoryImpl @Inject constructor( offerType: Int ): List { val downloadData = mutableListOf() + val authData = loginSourceRepository.gplayAuth ?: return downloadData + withContext(Dispatchers.IO) { val version = versionCode?.let { it as Int } ?: -1 val purchaseHelper = PurchaseHelper(authData).using(gPlayHttpClient) @@ -282,6 +296,8 @@ class GplayStoreRepositoryImpl @Inject constructor( offerType: Int ): List { val downloadData = mutableListOf() + val authData = loginSourceRepository.gplayAuth ?: return downloadData + withContext(Dispatchers.IO) { val purchaseHelper = PurchaseHelper(authData).using(gPlayHttpClient) downloadData.addAll( diff --git a/app/src/main/java/foundation/e/apps/data/login/LoginSourceRepository.kt b/app/src/main/java/foundation/e/apps/data/login/LoginSourceRepository.kt index bbe9d7b7aeb342225f06dd47fb20e84e3261d38d..6cbf9999810088217b171e77bf60b2b0564ed520 100644 --- a/app/src/main/java/foundation/e/apps/data/login/LoginSourceRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/login/LoginSourceRepository.kt @@ -67,6 +67,8 @@ class LoginSourceRepository @Inject constructor( suspend fun getValidatedAuthData(): ResultSupreme { val authDataValidator = (sources.find { it is AuthDataValidator } as AuthDataValidator) - return authDataValidator.validateAuthData() + val validateAuthData = authDataValidator.validateAuthData() + this.gplayAuth = validateAuthData.data + return validateAuthData } } diff --git a/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt index bbc68cd5eda2003d1e04941182867b815319c519..bcc048f4f24d83e32d1743a13f9a89c250022d4c 100644 --- a/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt @@ -118,7 +118,10 @@ class SearchFragment : authObjects.observe(viewLifecycleOwner) { val currentQuery = searchView?.query?.toString() ?: "" - if (it == null || (currentQuery.isNotEmpty() && lastSearch == currentQuery)) return@observe + if (it == null || shouldIgnore(it, currentQuery)) { + return@observe + } + loadDataWhenNetworkAvailable(it) } @@ -127,6 +130,12 @@ class SearchFragment : } } + private fun shouldIgnore( + authObjectList: List?, + currentQuery: String + ) = currentQuery.isNotEmpty() && searchViewModel.isAuthObjectListSame(authObjectList) && + lastSearch == currentQuery + private fun observeSearchResult(listAdapter: ApplicationListRVAdapter?) { searchViewModel.searchResult.observe(viewLifecycleOwner) { if (it.data?.first.isNullOrEmpty() && it.data?.second == false) { @@ -427,10 +436,11 @@ class SearchFragment : } private fun showKeyboard() { - val inputMethodManager = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + val inputMethodManager = + requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager searchView?.javaClass?.getDeclaredField("mSearchSrcTextView")?.runCatching { isAccessible = true - get(searchView)as EditText + get(searchView) as EditText }?.onSuccess { inputMethodManager.showSoftInput(it, InputMethodManager.SHOW_FORCED) } diff --git a/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt b/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt index 09f8b2d6aede5ad21bfb736fc47451f68e3a61e0..fc9d6022f050ced168b1a1a923743426846eee36 100644 --- a/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt @@ -47,6 +47,8 @@ class SearchViewModel @Inject constructor( private var searchResultLiveData: LiveData, Boolean>>> = MutableLiveData() + private var lastAuthObjects: List? = null + fun getSearchSuggestions(query: String, gPlayAuth: AuthObject.GPlayAuth) { viewModelScope.launch(Dispatchers.IO) { if (gPlayAuth.result.isSuccess()) @@ -68,6 +70,7 @@ class SearchViewModel @Inject constructor( if (query.isBlank()) return + this.lastAuthObjects = authObjectList super.onLoadData(authObjectList, { successAuthList, _ -> successAuthList.find { it is AuthObject.GPlayAuth }?.run { @@ -124,6 +127,7 @@ class SearchViewModel @Inject constructor( oldFusedApps: List ) = fusedAPIRepository.isAnyFusedAppUpdated(newFusedApps, oldFusedApps) - fun hasAnyAppInstallStatusChanged(currentList: List) = - fusedAPIRepository.isAnyAppInstallStatusChanged(currentList) + fun isAuthObjectListSame(authObjectList: List?): Boolean { + return lastAuthObjects == authObjectList + } }