From 1dc975428dfbb46f987687c6fb7ef47a101ffe70 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Wed, 23 Mar 2022 21:23:30 +0000 Subject: Fix dashboard not refreshed on restart app --- .../features/dashboard/DashboardFragment.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt index f0eda52..d2138af 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt @@ -42,8 +42,10 @@ import foundation.e.privacycentralapp.features.internetprivacy.InternetPrivacyFr import foundation.e.privacycentralapp.features.location.FakeLocationFragment import foundation.e.privacycentralapp.features.trackers.TrackersFragment import kotlinx.coroutines.FlowPreview +import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.launch @FlowPreview class DashboardFragment : @@ -63,9 +65,6 @@ class DashboardFragment : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - lifecycleScope.launchWhenStarted { - viewModel.dashboardFeature.takeView(this, this@DashboardFragment) - } lifecycleScope.launchWhenStarted { viewModel.dashboardFeature.singleEvents.collect { event -> when (event) { @@ -129,17 +128,26 @@ class DashboardFragment : } } + private var updateUIJob: Job? = null override fun onResume() { super.onResume() + updateUIJob = lifecycleScope.launch { + viewModel.dashboardFeature.takeView(this, this@DashboardFragment) + } + viewModel.submitAction(DashboardFeature.Action.FetchStatistics) } + override fun onPause() { + super.onPause() + updateUIJob?.cancel() + } + override fun getTitle(): String { return getString(R.string.dashboard_title) } override fun render(state: State) { - binding.stateLabel.text = getString( if (state.isQuickPrivacyEnabled) R.string.dashboard_state_title_on else R.string.dashboard_state_title_off -- cgit v1.2.1