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

Commit 484cb0ab authored by Hasib Prince's avatar Hasib Prince
Browse files

fixed: duplicate item in search page

parent 14e62e57
Loading
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -259,11 +259,7 @@ class FusedApiImpl @Inject constructor(
        val packageSpecificResults = ArrayList<FusedApp>()
        var finalSearchResult: ResultSupreme<Pair<List<FusedApp>, Boolean>> = ResultSupreme.Error()

        fetchPackageSpecificResult(authData, query, packageSpecificResults).let {
            if (it.data?.second != true) { // if there are no data to load
                return it
            }
        }
        fetchPackageSpecificResult(authData, query, packageSpecificResults)

        val searchResult = mutableListOf<FusedApp>()
        val cleanApkResults = mutableListOf<FusedApp>()
@@ -375,6 +371,10 @@ class FusedApiImpl @Inject constructor(
            gplayPackageResult?.let { packageSpecificResults.add(it) }
        }

        if (preferenceManagerModule.isGplaySelected()) {
            packageSpecificResults.add(FusedApp(isPlaceHolder = true))
        }

        /*
         * If there was a timeout, return it and don't try to fetch anything else.
         * Also send true in the pair to signal more results being loaded.
@@ -400,7 +400,14 @@ class FusedApiImpl @Inject constructor(
    ): List<FusedApp> {
        val filteredResults = list.distinctBy { it.package_name }
            .filter { packageSpecificResults.isEmpty() || it.package_name != query }
        return packageSpecificResults + filteredResults

        val finalList = (packageSpecificResults + filteredResults).toMutableList()
        finalList.removeIf { it.isPlaceHolder }
        if (preferenceManagerModule.isGplaySelected()) {
            finalList.add(FusedApp(isPlaceHolder = true))
        }

        return finalList
    }

    private suspend fun getCleanApkPackageResult(
+7 −8
Original line number Diff line number Diff line
@@ -193,16 +193,8 @@ class GPlayHttpClient @Inject constructor(
        return PlayResponse().apply {
            isSuccessful = response.isSuccessful
            code = response.code

            Timber.d("$TAG: Url: ${response.request.url}\nStatus: $code")

            // TODO: exception will be thrown for all apis when all gplay api implementation
            // will handle the exceptions. this will be done in following issue.
            // Issue: https://gitlab.e.foundation/e/os/backlog/-/issues/1483
            if (response.request.url.toString().contains(SEARCH) && code != 200) {
                throw GplayHttpRequestException(code, response.message)
            }

            if (code == 401) {
                MainScope().launch {
                    EventBus.invokeEvent(
@@ -211,6 +203,13 @@ class GPlayHttpClient @Inject constructor(
                }
            }

            // TODO: exception will be thrown for all apis when all gplay api implementation
            // will handle the exceptions. this will be done in following issue.
            // Issue: https://gitlab.e.foundation/e/os/backlog/-/issues/1483
            if (response.request.url.toString().contains(SEARCH) && code != 200) {
                throw GplayHttpRequestException(code, response.message)
            }

            if (response.body != null) {
                responseBytes = response.body!!.bytes()
            }
+1 −6
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.widget.ImageView
import android.widget.LinearLayout
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SearchView
import androidx.core.view.isVisible
import androidx.cursoradapter.widget.CursorAdapter
import androidx.cursoradapter.widget.SimpleCursorAdapter
import androidx.fragment.app.activityViewModels
@@ -195,10 +194,7 @@ class SearchFragment :
    private fun updateSearchResult(
        listAdapter: ApplicationListRVAdapter?,
        appList: List<FusedApp>,
        hasMore: Boolean,
    ): Boolean {
        binding.loadingProgressBar.isVisible = hasMore

        val currentList = listAdapter?.currentList ?: listOf()
        if (!searchViewModel.isAnyAppUpdated(appList, currentList)) {
            return false
@@ -289,9 +285,8 @@ class SearchFragment :
        val searchList =
            searchViewModel.searchResult.value?.data?.first?.toMutableList() ?: emptyList()

        val hasMoreDataToLoad = searchViewModel.searchResult.value?.data?.second == true
        mainActivityViewModel.updateStatusOfFusedApps(searchList, fusedDownloadList)
        updateSearchResult(applicationListRVAdapter, searchList, hasMoreDataToLoad)
        updateSearchResult(applicationListRVAdapter, searchList)
    }

    override fun onTimeout(
+12 −2
Original line number Diff line number Diff line
@@ -35,10 +35,12 @@ import foundation.e.apps.data.login.exceptions.CleanApkException
import foundation.e.apps.data.login.exceptions.GPlayException
import foundation.e.apps.data.login.exceptions.UnknownSourceException
import foundation.e.apps.ui.parentFragment.LoadingViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
import kotlin.coroutines.coroutineContext

@HiltViewModel
class SearchViewModel @Inject constructor(
@@ -154,8 +156,16 @@ class SearchViewModel @Inject constructor(
            handleException(gplaySearchResult.exception ?: UnknownSourceException())
        }

        val isFirstFetch = nextSubBundle == null
        nextSubBundle = gplaySearchResult.data?.second

        // if first page has less data, then fetch next page data without waiting for users' scroll
        if (isFirstFetch && gplaySearchResult.data?.first?.size!! < 4) {
            CoroutineScope(coroutineContext).launch {
                fetchGplayData(query)
            }
        }

        val currentAppList = updateCurrentAppList(gplaySearchResult)
        val finalResult = ResultSupreme.Success(
            Pair(currentAppList.toList(), nextSubBundle?.isNotEmpty() ?: false)
@@ -165,12 +175,12 @@ class SearchViewModel @Inject constructor(
        isLoading = false
    }

    private fun updateCurrentAppList(gplaySearchResult: GplaySearchResult): MutableList<FusedApp> {
    private fun updateCurrentAppList(gplaySearchResult: GplaySearchResult): List<FusedApp> {
        val currentSearchResult = searchResult.value?.data
        val currentAppList = currentSearchResult?.first?.toMutableList() ?: mutableListOf()
        currentAppList.removeIf { item -> item.isPlaceHolder }
        currentAppList.addAll(gplaySearchResult.data?.first ?: emptyList())
        return currentAppList
        return currentAppList.distinctBy { it.package_name }
    }

    private fun handleException(exception: Exception) {
+0 −9
Original line number Diff line number Diff line
@@ -95,13 +95,4 @@

    </com.facebook.shimmer.ShimmerFrameLayout>

    <ProgressBar
        android:id="@+id/loadingProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        style="?android:attr/progressBarStyleHorizontal"
        android:visibility="gone"
        />

</LinearLayout>
 No newline at end of file