Wire up UI to make add-on installation cancelable
parent
8c73218822
commit
d16c70d8be
|
@ -18,7 +18,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import kotlinx.android.synthetic.main.fragment_add_ons_management.*
|
import kotlinx.android.synthetic.main.fragment_add_ons_management.*
|
||||||
import kotlinx.android.synthetic.main.fragment_add_ons_management.view.*
|
import kotlinx.android.synthetic.main.fragment_add_ons_management.view.*
|
||||||
import kotlinx.android.synthetic.main.overlay_add_on_progress.view.*
|
import kotlinx.android.synthetic.main.overlay_add_on_progress.view.*
|
||||||
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.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -35,6 +34,7 @@ import org.mozilla.fenix.ext.getRootView
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
import org.mozilla.fenix.ext.showToolbar
|
import org.mozilla.fenix.ext.showToolbar
|
||||||
import org.mozilla.fenix.theme.ThemeManager
|
import org.mozilla.fenix.theme.ThemeManager
|
||||||
|
import java.util.concurrent.CancellationException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment use for managing add-ons.
|
* Fragment use for managing add-ons.
|
||||||
|
@ -46,7 +46,6 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management),
|
||||||
* Whether or not an add-on installation is in progress.
|
* Whether or not an add-on installation is in progress.
|
||||||
*/
|
*/
|
||||||
private var isInstallationInProgress = false
|
private var isInstallationInProgress = false
|
||||||
private var scope: CoroutineScope? = null
|
|
||||||
private var adapter: AddonsManagerAdapter? = null
|
private var adapter: AddonsManagerAdapter? = null
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
@ -244,7 +243,7 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management),
|
||||||
|
|
||||||
isInstallationInProgress = true
|
isInstallationInProgress = true
|
||||||
|
|
||||||
requireContext().components.addonManager.installAddon(
|
val installOperation = requireContext().components.addonManager.installAddon(
|
||||||
addon,
|
addon,
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
runIfFragmentIsAttached {
|
runIfFragmentIsAttached {
|
||||||
|
@ -254,8 +253,10 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management),
|
||||||
showInstallationDialog(it)
|
showInstallationDialog(it)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError = { _, _ ->
|
onError = { _, e ->
|
||||||
this@AddonsManagementFragment.view?.let { view ->
|
this@AddonsManagementFragment.view?.let { view ->
|
||||||
|
// No need to display an error message if installation was cancelled by the user.
|
||||||
|
if (e !is CancellationException) {
|
||||||
val rootView = activity?.getRootView() ?: view
|
val rootView = activity?.getRootView() ?: view
|
||||||
showSnackBar(
|
showSnackBar(
|
||||||
rootView,
|
rootView,
|
||||||
|
@ -264,11 +265,21 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management),
|
||||||
addon.translatedName
|
addon.translatedName
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
addonProgressOverlay?.visibility = View.GONE
|
addonProgressOverlay?.visibility = View.GONE
|
||||||
isInstallationInProgress = false
|
isInstallationInProgress = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
addonProgressOverlay.cancel_button.setOnClickListener {
|
||||||
|
lifecycleScope.launch(Dispatchers.Main) {
|
||||||
|
// Hide the installation progress overlay once cancellation is successful.
|
||||||
|
if (installOperation.cancel().await()) {
|
||||||
|
addonProgressOverlay.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun announceForAccessibility(announcementText: CharSequence) {
|
private fun announceForAccessibility(announcementText: CharSequence) {
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:elevation="1dp">
|
android:elevation="1dp">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/add_ons_overlay_text"
|
android:id="@+id/add_ons_overlay_text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -21,4 +25,18 @@
|
||||||
android:text="@string/mozac_add_on_install_progress_caption"
|
android:text="@string/mozac_add_on_install_progress_caption"
|
||||||
app:drawableStartCompat="@drawable/mozac_ic_extensions_black" />
|
app:drawableStartCompat="@drawable/mozac_ic_extensions_black" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/cancel_button"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/add_ons_overlay_text"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:text="@string/mozac_feature_addons_install_addon_dialog_cancel"
|
||||||
|
android:textAllCaps="false" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
Loading…
Reference in New Issue