Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43bc7506 authored by Hasib Prince's avatar Hasib Prince
Browse files

Merge branch '1445-token_expiration' into 'release-1.13-rc'

fix: token refresh for searchpage

See merge request !337
parents 352a62de 16e0fa61
Loading
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -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<String, List<App>>()
        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<Pair<List<App>, 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<SearchSuggestEntry> {
        val authData = loginSourceRepository.gplayAuth ?: return listOf()

        val searchData = mutableListOf<SearchSuggestEntry>()
        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<String>): List<App> {
        val appDetailsList = mutableListOf<App>()
        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<File> {
        val downloadData = mutableListOf<File>()
        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<File> {
        val downloadData = mutableListOf<File>()
        val authData = loginSourceRepository.gplayAuth ?: return downloadData

        withContext(Dispatchers.IO) {
            val purchaseHelper = PurchaseHelper(authData).using(gPlayHttpClient)
            downloadData.addAll(
+3 −1
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ class LoginSourceRepository @Inject constructor(

    suspend fun getValidatedAuthData(): ResultSupreme<AuthData?> {
        val authDataValidator = (sources.find { it is AuthDataValidator } as AuthDataValidator)
        return authDataValidator.validateAuthData()
        val validateAuthData = authDataValidator.validateAuthData()
        this.gplayAuth = validateAuthData.data
        return validateAuthData
    }
}
+13 −3
Original line number Diff line number Diff line
@@ -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<AuthObject>?,
        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,7 +436,8 @@ 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
+6 −2
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ class SearchViewModel @Inject constructor(
    private var searchResultLiveData: LiveData<ResultSupreme<Pair<List<FusedApp>, Boolean>>> =
        MutableLiveData()

    private var lastAuthObjects: List<AuthObject>? = 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<FusedApp>
    ) = fusedAPIRepository.isAnyFusedAppUpdated(newFusedApps, oldFusedApps)

    fun hasAnyAppInstallStatusChanged(currentList: List<FusedApp>) =
        fusedAPIRepository.isAnyAppInstallStatusChanged(currentList)
    fun isAuthObjectListSame(authObjectList: List<AuthObject>?): Boolean {
        return lastAuthObjects == authObjectList
    }
}