From d6dae74bd9d7420d7aa6fcb1e36bc49dea59aacb Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Tue, 19 Nov 2024 11:51:00 +0100 Subject: [PATCH] Prevent home page from being loaded again in background --- .../foundation/e/apps/ui/home/HomeFragment.kt | 10 +++++---- .../e/apps/ui/home/HomeViewModel.kt | 22 +++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt b/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt index 277f5e0a8..3ff38c4f0 100644 --- a/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt @@ -186,10 +186,12 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall } override fun loadData(authObjectList: List) { - showLoadingUI() - homeViewModel.loadData(authObjectList, viewLifecycleOwner) { _ -> - clearAndRestartGPlayLogin() - true + if (homeViewModel.haveSourcesChanged()) { + showLoadingUI() + homeViewModel.loadData(authObjectList, viewLifecycleOwner) { _ -> + clearAndRestartGPlayLogin() + true + } } } diff --git a/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt b/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt index afd4f8cd2..30ecfb9bd 100644 --- a/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt @@ -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? = null + private var previousSources = emptyList() + fun loadData( authObjectList: List, 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>) = -- GitLab