From 98169c3a7c312eb3eb30328c9678c9dd10732765 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Tue, 18 Jul 2023 12:22:45 +0600 Subject: [PATCH 1/2] fix: token refresh for searchpage --- .../data/gplay/GplayStoreRepositoryImpl.kt | 20 +++++++++++++++++-- .../e/apps/ui/search/SearchFragment.kt | 20 ++++++++++++++++--- .../e/apps/ui/search/SearchViewModel.kt | 8 ++++++-- 3 files changed, 41 insertions(+), 7 deletions(-) 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 85be60956..23d4e8427 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/ui/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt index bbc68cd5e..ee34eaa59 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,16 @@ 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 +440,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 09f8b2d6a..fc9d6022f 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 + } } -- GitLab From 16e0fa61eaa12ea42893318706ac5c36a900e273 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Tue, 18 Jul 2023 14:44:05 +0600 Subject: [PATCH 2/2] fix: validated token for update process --- .../foundation/e/apps/data/login/LoginSourceRepository.kt | 4 +++- .../java/foundation/e/apps/ui/search/SearchFragment.kt | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) 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 bbe9d7b7a..6cbf99998 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 ee34eaa59..bcc048f4f 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 @@ -133,12 +133,8 @@ class SearchFragment : private fun shouldIgnore( authObjectList: List?, currentQuery: String - ) = - ( - currentQuery.isNotEmpty() && searchViewModel.isAuthObjectListSame( - authObjectList - ) && lastSearch == currentQuery - ) + ) = currentQuery.isNotEmpty() && searchViewModel.isAuthObjectListSame(authObjectList) && + lastSearch == currentQuery private fun observeSearchResult(listAdapter: ApplicationListRVAdapter?) { searchViewModel.searchResult.observe(viewLifecycleOwner) { -- GitLab