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

Commit d6dae74b authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Prevent home page from being loaded again in background

parent 31a50cf2
Loading
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -186,12 +186,14 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall
    }

    override fun loadData(authObjectList: List<AuthObject>) {
        if (homeViewModel.haveSourcesChanged()) {
            showLoadingUI()
            homeViewModel.loadData(authObjectList, viewLifecycleOwner) { _ ->
                clearAndRestartGPlayLogin()
                true
            }
        }
    }

    override fun showLoadingUI() {
        binding.shimmerLayout.startShimmer()
+20 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import foundation.e.apps.data.application.data.Home
import foundation.e.apps.data.login.AuthObject
import foundation.e.apps.data.login.exceptions.CleanApkException
import foundation.e.apps.data.login.exceptions.GPlayException
import foundation.e.apps.data.preference.AppLoungePreference
import foundation.e.apps.ui.applicationlist.ApplicationDiffUtil
import foundation.e.apps.ui.parentFragment.LoadingViewModel
import kotlinx.coroutines.launch
@@ -41,6 +42,8 @@ class HomeViewModel @Inject constructor(
    private val applicationRepository: ApplicationRepository,
) : LoadingViewModel() {

    @Inject
    lateinit var appLoungePreference: AppLoungePreference

    /*
     * Hold list of applications, as well as application source type.
@@ -52,6 +55,8 @@ class HomeViewModel @Inject constructor(

    var currentHomes: List<Home>? = null

    private var previousSources = emptyList<Boolean>()

    fun loadData(
        authObjectList: List<AuthObject>,
        lifecycleOwner: LifecycleOwner,
@@ -71,6 +76,21 @@ class HomeViewModel @Inject constructor(
        }, retryBlock)
    }

    fun haveSourcesChanged(): Boolean {
        val sources = listOf(
            appLoungePreference.isGplaySelected(),
            appLoungePreference.isOpenSourceSelected(),
            appLoungePreference.isPWASelected()
        )

        if (sources == previousSources) {
            return false
        }

        previousSources = sources
        return true
    }

    fun getHomeScreenData(
        authData: AuthData,
        lifecycleOwner: LifecycleOwner,
@@ -109,8 +129,6 @@ class HomeViewModel @Inject constructor(
            currentHomes = homeResult.data?.map { it.copy() }
            return
        }

        homeScreenData.value = ResultSupreme.Error("No change is found in homepage")
    }

    private fun shouldUpdateResult(homeResult: ResultSupreme<List<Home>>) =