No issue: Partially update the add-on manager list
This commit is contained in:
parent
1aa473b112
commit
e55a4fd274
|
@ -19,8 +19,6 @@ import kotlinx.android.synthetic.main.fragment_add_ons_management.view.*
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.cancel
|
|
||||||
import kotlinx.coroutines.flow.collect
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import mozilla.components.feature.addons.Addon
|
import mozilla.components.feature.addons.Addon
|
||||||
import mozilla.components.feature.addons.AddonManagerException
|
import mozilla.components.feature.addons.AddonManagerException
|
||||||
|
@ -28,8 +26,6 @@ import mozilla.components.feature.addons.ui.AddonsManagerAdapter
|
||||||
import mozilla.components.feature.addons.ui.AddonsManagerAdapterDelegate
|
import mozilla.components.feature.addons.ui.AddonsManagerAdapterDelegate
|
||||||
import mozilla.components.feature.addons.ui.PermissionsDialogFragment
|
import mozilla.components.feature.addons.ui.PermissionsDialogFragment
|
||||||
import mozilla.components.feature.addons.ui.translatedName
|
import mozilla.components.feature.addons.ui.translatedName
|
||||||
import mozilla.components.lib.state.ext.flowScoped
|
|
||||||
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
|
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.getRootView
|
import org.mozilla.fenix.ext.getRootView
|
||||||
|
@ -47,6 +43,7 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management),
|
||||||
*/
|
*/
|
||||||
private var isInstallationInProgress = false
|
private var isInstallationInProgress = false
|
||||||
private var scope: CoroutineScope? = null
|
private var scope: CoroutineScope? = null
|
||||||
|
private var adapter: AddonsManagerAdapter? = null
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
@ -63,20 +60,6 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management),
|
||||||
findPreviousDialogFragment()?.let { dialog ->
|
findPreviousDialogFragment()?.let { dialog ->
|
||||||
dialog.onPositiveButtonClicked = onPositiveButtonClicked
|
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) {
|
override fun onAddonItemClicked(addon: Addon) {
|
||||||
|
@ -91,29 +74,35 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management),
|
||||||
showPermissionDialog(addon)
|
showPermissionDialog(addon)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNotYetSupportedSectionClicked(unsupportedAddons: ArrayList<Addon>) {
|
override fun onNotYetSupportedSectionClicked(unsupportedAddons: List<Addon>) {
|
||||||
showNotYetSupportedAddonFragment(unsupportedAddons)
|
showNotYetSupportedAddonFragment(ArrayList(unsupportedAddons))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bindRecyclerView(view: View) {
|
private fun bindRecyclerView(view: View) {
|
||||||
val recyclerView = view.add_ons_list
|
val recyclerView = view.add_ons_list
|
||||||
recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||||
|
val shouldRefresh = adapter != null
|
||||||
lifecycleScope.launch(IO) {
|
lifecycleScope.launch(IO) {
|
||||||
try {
|
try {
|
||||||
val addons = requireContext().components.addonManager.getAddons()
|
val addons = requireContext().components.addonManager.getAddons()
|
||||||
lifecycleScope.launch(Dispatchers.Main) {
|
lifecycleScope.launch(Dispatchers.Main) {
|
||||||
runIfFragmentIsAttached {
|
runIfFragmentIsAttached {
|
||||||
val adapter = AddonsManagerAdapter(
|
if (!shouldRefresh) {
|
||||||
requireContext().components.addonCollectionProvider,
|
adapter = AddonsManagerAdapter(
|
||||||
this@AddonsManagementFragment,
|
requireContext().components.addonCollectionProvider,
|
||||||
addons,
|
this@AddonsManagementFragment,
|
||||||
style = createAddonStyle(requireContext())
|
addons,
|
||||||
)
|
style = createAddonStyle(requireContext())
|
||||||
|
)
|
||||||
|
}
|
||||||
isInstallationInProgress = false
|
isInstallationInProgress = false
|
||||||
view.add_ons_progress_bar.isVisible = false
|
view.add_ons_progress_bar.isVisible = false
|
||||||
view.add_ons_empty_message.isVisible = false
|
view.add_ons_empty_message.isVisible = false
|
||||||
|
|
||||||
recyclerView.adapter = adapter
|
recyclerView.adapter = adapter
|
||||||
|
if (shouldRefresh) {
|
||||||
|
adapter?.updateAddons(addons)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: AddonManagerException) {
|
} catch (e: AddonManagerException) {
|
||||||
|
@ -213,7 +202,7 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management),
|
||||||
it.translatedName
|
it.translatedName
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
bindRecyclerView(view)
|
adapter?.updateAddon(it)
|
||||||
addonProgressOverlay?.visibility = View.GONE
|
addonProgressOverlay?.visibility = View.GONE
|
||||||
isInstallationInProgress = false
|
isInstallationInProgress = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user