diff options
author | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2022-03-23 21:23:30 +0000 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2022-03-23 21:23:30 +0000 |
commit | 1dc975428dfbb46f987687c6fb7ef47a101ffe70 (patch) | |
tree | a29eeb95467957a04e81560dbad7acaeb20aa292 /app/src/main/java/foundation/e | |
parent | 82a45020557916da2a133df297eafc92f9f7c3db (diff) |
Fix dashboard not refreshed on restart app
Diffstat (limited to 'app/src/main/java/foundation/e')
-rw-r--r-- | app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt | 16 |
1 files changed, 12 insertions, 4 deletions
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 : @@ -64,9 +66,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) { is DashboardFeature.SingleEvent.NavigateToLocationSingleEvent -> { @@ -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 |