From 93a68736a363d50a65637821031005d44175666f Mon Sep 17 00:00:00 2001 From: Arturo Mejia Date: Mon, 10 Feb 2020 15:09:35 -0500 Subject: [PATCH] For issue #8272: Keep the add-ons management ui in sync with add-ons changes --- .../fenix/addons/AddonsManagementFragment.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/main/java/org/mozilla/fenix/addons/AddonsManagementFragment.kt b/app/src/main/java/org/mozilla/fenix/addons/AddonsManagementFragment.kt index 071cd2c18..c80a5d3a8 100644 --- a/app/src/main/java/org/mozilla/fenix/addons/AddonsManagementFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/addons/AddonsManagementFragment.kt @@ -16,6 +16,12 @@ import kotlinx.android.synthetic.main.fragment_add_ons_management.view.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.CoroutineScope +import mozilla.components.lib.state.ext.flowScoped +import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.cancel import mozilla.components.feature.addons.Addon import mozilla.components.feature.addons.AddonManagerException import mozilla.components.feature.addons.ui.AddonsManagerAdapter @@ -36,6 +42,7 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management), * Whether or not an add-on installation is in progress. */ private var isInstallationInProgress = false + private var scope: CoroutineScope? = null override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -47,11 +54,26 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management), showToolbar(getString(R.string.preferences_addons)) } + @UseExperimental(ExperimentalCoroutinesApi::class) override fun onStart() { super.onStart() findPreviousDialogFragment()?.let { dialog -> dialog.onPositiveButtonClicked = onPositiveButtonClicked } + + scope = requireContext().components.core.store.flowScoped { flow -> + flow.ifChanged { it.extensions } + .collect { _ -> + view?.let { + bindRecyclerView(it) + } + } + } + } + + override fun onStop() { + super.onStop() + scope?.cancel() } override fun onAddonItemClicked(addon: Addon) {