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

Commit 96099ae7 authored by Hasib Prince's avatar Hasib Prince
Browse files

improved refreshing data for better UX

parent abcc66e9
Loading
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -290,13 +290,18 @@ class SearchFragment :
            updateProgressOfInstallingApps(it)
        }

        if (searchText.isNotEmpty()) {
        if (shouldRefreshData()) {
            mainActivityViewModel.authData.value?.let {
                refreshData(it)
            }
        }
    }

    private fun shouldRefreshData() =
        searchText.isNotEmpty() && recyclerView?.adapter != null && searchViewModel.hasAnyAppInstallStatusChanged(
            (recyclerView?.adapter as ApplicationListRVAdapter).currentList
        )

    override fun onPause() {
        binding.shimmerLayout.stopShimmer()
        super.onPause()
+17 −1
Original line number Diff line number Diff line
@@ -29,13 +29,16 @@ import foundation.e.apps.api.ResultSupreme
import foundation.e.apps.api.fused.FusedAPIRepository
import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil
import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.Status
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SearchViewModel @Inject constructor(
    private val fusedAPIRepository: FusedAPIRepository
    private val fusedAPIRepository: FusedAPIRepository,
    private val pkgManagerModule: PkgManagerModule
) : ViewModel() {

    val searchSuggest: MutableLiveData<List<SearchSuggestEntry>?> = MutableLiveData()
@@ -81,4 +84,17 @@ class SearchViewModel @Inject constructor(
        }
        return false
    }

    fun hasAnyAppInstallStatusChanged(currentList: List<FusedApp>): Boolean {
        currentList.forEach {
            if (it.status == Status.INSTALLATION_ISSUE) {
                return@forEach
            }
            val currentAppStatus = pkgManagerModule.getPackageStatus(it.package_name, it.latest_version_code)
            if (it.status != currentAppStatus) {
                return true
            }
        }
        return false
    }
}