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

Commit 2a450d9b authored by Hasib Prince's avatar Hasib Prince
Browse files

fixed: install button status after uninstall an app

fixed: install button status for app list and search page
parent 3d299a6a
Loading
Loading
Loading
Loading
+38 −14
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.applicationlist.model.ApplicationListRVAdapter
import foundation.e.apps.databinding.FragmentApplicationListBinding
import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil
import foundation.e.apps.manager.download.data.DownloadProgress
import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.Status
@@ -51,7 +52,8 @@ import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_list), FusedAPIInterface {
class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_list),
    FusedAPIInterface {

    private val args: ApplicationListFragmentArgs by navArgs()

@@ -115,7 +117,6 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li

    override fun onResume() {
        super.onResume()
        binding.shimmerLayout.startShimmer()

        val recyclerView = binding.recyclerView
        recyclerView.recycledViewPool.setMaxRecycledViews(0, 0)
@@ -156,10 +157,18 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
        }

        viewModel.appListLiveData.observe(viewLifecycleOwner) {
            stopLoadingUI()
            if (!it.isSuccess()) {
                onTimeout()
            } else {
                isDetailsLoaded = true
                val currentList = listAdapter?.currentList
                if (it.data != null && !currentList.isNullOrEmpty() && !compareOldFusedAppsListWithNewFusedAppsList(
                        it.data!!,
                        currentList
                    )
                ) {
                    return@observe
                }
                listAdapter?.setData(it.data!!)
                listAdapter?.let { adapter ->
                    observeDownloadList(adapter)
@@ -169,7 +178,6 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
                    updateProgressOfDownloadingItems(binding.recyclerView, it)
                }
            }
            stopLoadingUI()
        }

        /*
@@ -220,7 +228,6 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
         *
         * Issue: https://gitlab.e.foundation/e/os/backlog/-/issues/478
         */
        if (!isDetailsLoaded) {
        showLoadingUI()
        viewModel.getList(
            args.category,
@@ -228,7 +235,6 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
            authData,
            args.source
        )
        }

        if (args.source != "Open Source" && args.source != "PWA") {
            /*
@@ -260,6 +266,23 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
        }
    }

    /**
     * @return returns true if there is changes in data, otherwise false
     */
    fun compareOldFusedAppsListWithNewFusedAppsList(
        newFusedApps: List<FusedApp>,
        oldFusedApps: List<FusedApp>
    ): Boolean {
        val fusedAppDiffUtil = HomeChildFusedAppDiffUtil()
        newFusedApps.forEach {
            val indexOfNewFusedApp = newFusedApps.indexOf(it)
            if (!fusedAppDiffUtil.areContentsTheSame(it, oldFusedApps[indexOfNewFusedApp])) {
                return true
            }
        }
        return false
    }

    private fun showLoadingUI() {
        binding.shimmerLayout.startShimmer()
        binding.shimmerLayout.visibility = View.VISIBLE
@@ -280,7 +303,8 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
        lifecycleScope.launch {
            adapter.currentList.forEach { fusedApp ->
                if (fusedApp.status == Status.DOWNLOADING) {
                    val progress = appProgressViewModel.calculateProgress(fusedApp, downloadProgress)
                    val progress =
                        appProgressViewModel.calculateProgress(fusedApp, downloadProgress)
                    if (progress == -1) {
                        return@forEach
                    }
+16 −2
Original line number Diff line number Diff line
@@ -36,8 +36,10 @@ import foundation.e.apps.R
import foundation.e.apps.api.fused.FusedAPIImpl
import foundation.e.apps.api.fused.FusedAPIInterface
import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.api.fused.data.FusedHome
import foundation.e.apps.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.databinding.FragmentHomeBinding
import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil
import foundation.e.apps.home.model.HomeChildRVAdapter
import foundation.e.apps.home.model.HomeParentRVAdapter
import foundation.e.apps.manager.download.data.DownloadProgress
@@ -49,6 +51,7 @@ import foundation.e.apps.utils.modules.CommonUtilsModule.safeNavigate
import foundation.e.apps.utils.modules.PWAManagerModule
import foundation.e.apps.utils.parentFragment.TimeoutFragment
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@AndroidEntryPoint
@@ -140,7 +143,11 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), FusedAPIInterface
            if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) {
                ApplicationDialogFragment(
                    title = getString(R.string.dialog_title_paid_app, fusedApp.name),
                    message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price),
                    message = getString(
                        R.string.dialog_paidapp_message,
                        fusedApp.name,
                        fusedApp.price
                    ),
                    positiveButtonText = getString(R.string.dialog_confirm),
                    positiveButtonAction = {
                        getApplication(fusedApp)
@@ -158,7 +165,11 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), FusedAPIInterface
        homeViewModel.homeScreenData.observe(viewLifecycleOwner) {
            stopLoadingUI()
            if (it.second == ResultStatus.OK) {
                if (!homeParentRVAdapter?.currentList.isNullOrEmpty()) {
                if (homeParentRVAdapter?.currentList?.isNotEmpty() == true && !homeViewModel.compareNewHomeDataWithOldHomeData(
                        it.first,
                        homeParentRVAdapter?.currentList as List<FusedHome>
                    )
                ) {
                    return@observe
                }
                dismissTimeoutDialog()
@@ -266,6 +277,9 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), FusedAPIInterface
        appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) {
            updateProgressOfDownloadingAppItemViews(homeParentRVAdapter, it)
        }
        mainActivityViewModel.authData.value?.let {
            refreshData(it)
        }
    }

    override fun onPause() {
+32 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.aurora.gplayapi.data.models.AuthData
import dagger.hilt.android.lifecycle.HiltViewModel
import foundation.e.apps.api.fused.FusedAPIRepository
import foundation.e.apps.api.fused.data.FusedHome
import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil
import foundation.e.apps.utils.enums.ResultStatus
import kotlinx.coroutines.launch
import javax.inject.Inject
@@ -44,7 +45,8 @@ class HomeViewModel @Inject constructor(

    fun getHomeScreenData(authData: AuthData) {
        viewModelScope.launch {
            homeScreenData.postValue(fusedAPIRepository.getHomeScreenData(authData))
            val screenData = fusedAPIRepository.getHomeScreenData(authData)
            homeScreenData.postValue(screenData)
        }
    }

@@ -57,4 +59,33 @@ class HomeViewModel @Inject constructor(
            fusedAPIRepository.isFusedHomesEmpty(it)
        } ?: true
    }

    fun compareNewHomeDataWithOldHomeData(
        newHomeData: List<FusedHome>,
        oldHomeData: List<FusedHome>
    ): Boolean {
        oldHomeData.forEach {
            val fusedHome = newHomeData[oldHomeData.indexOf(it)]
            if (!it.title.contentEquals(fusedHome.title) || !areOldAndNewFusedAppListSame(it, fusedHome)) {
                return true
            }
        }
        return false
    }

    private fun areOldAndNewFusedAppListSame(
        it: FusedHome,
        fusedHome: FusedHome,
    ): Boolean {
        val fusedAppDiffUtil = HomeChildFusedAppDiffUtil()

        it.list.forEach { oldFusedApp ->
            val indexOfOldFusedApp = it.list.indexOf(oldFusedApp)
            val fusedApp = fusedHome.list[indexOfOldFusedApp]
            if (!fusedAppDiffUtil.areContentsTheSame(oldFusedApp, fusedApp)) {
                return false
            }
        }
        return true
    }
}
+4 −9
Original line number Diff line number Diff line
@@ -26,9 +26,10 @@ import dagger.hilt.android.AndroidEntryPoint
import foundation.e.apps.api.faultyApps.FaultyAppRepository
import foundation.e.apps.manager.fused.FusedManagerRepository
import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.eventBus.AppEvent
import foundation.e.apps.utils.eventBus.EventBus
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Named
@@ -67,16 +68,10 @@ open class PkgManagerBR : BroadcastReceiver() {
                        Intent.ACTION_PACKAGE_ADDED -> {
                            updateDownloadStatus(pkgName)
                            removeFaultyAppByPackageName(pkgName)
                            MainScope().launch {
                                EventBus.invokeEvent(AppEvent.AppStatusUpdated())
                            }
                        }
                        Intent.ACTION_PACKAGE_REMOVED -> {
                            if (!isUpdating) deleteDownload(pkgName)
                            removeFaultyAppByPackageName(pkgName)
                            MainScope().launch {
                                EventBus.invokeEvent(AppEvent.AppStatusUpdated())
                            }
                        }
                        PkgManagerModule.ERROR_PACKAGE_INSTALL -> {
                            Timber.e("Installation failed due to error: $extra")
+36 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.applicationlist.model.ApplicationListRVAdapter
import foundation.e.apps.databinding.FragmentSearchBinding
import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil
import foundation.e.apps.manager.download.data.DownloadProgress
import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.Status
@@ -165,6 +166,14 @@ class SearchFragment :
            if (it.data?.first.isNullOrEmpty()) {
                noAppsFoundLayout?.visibility = View.VISIBLE
            } else {
                val currentList = listAdapter?.currentList
                if (it.data?.first != null && !currentList.isNullOrEmpty() && !compareOldFusedAppsListWithNewFusedAppsList(
                        it.data?.first!!,
                        currentList
                    )
                ) {
                    return@observe
                }
                listAdapter?.setData(it.data!!.first)
                binding.loadingProgressBar.isVisible = it.data!!.second
                stopLoadingUI()
@@ -203,6 +212,27 @@ class SearchFragment :
        }
    }

    /**
     * @return returns true if there is changes in data, otherwise false
     */
    fun compareOldFusedAppsListWithNewFusedAppsList(
        newFusedApps: List<FusedApp>,
        oldFusedApps: List<FusedApp>
    ): Boolean {
        val fusedAppDiffUtil = HomeChildFusedAppDiffUtil()
        if (newFusedApps.size != oldFusedApps.size) {
            return true
        }
        
        newFusedApps.forEach {
            val indexOfNewFusedApp = newFusedApps.indexOf(it)
            if (!fusedAppDiffUtil.areContentsTheSame(it, oldFusedApps[indexOfNewFusedApp])) {
                return true
            }
        }
        return false
    }

    private fun observeDownloadList(applicationListRVAdapter: ApplicationListRVAdapter) {
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            val searchList =
@@ -281,6 +311,12 @@ class SearchFragment :
        appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) {
            updateProgressOfInstallingApps(it)
        }

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

    override fun onPause() {
Loading