|
|
|
@ -15,7 +15,6 @@ import androidx.lifecycle.lifecycleScope
|
|
|
|
|
import androidx.navigation.Navigation
|
|
|
|
|
import androidx.navigation.findNavController
|
|
|
|
|
import androidx.navigation.fragment.findNavController
|
|
|
|
|
import com.google.android.material.switchmaterial.SwitchMaterial
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import mozilla.components.concept.engine.webextension.EnableSource
|
|
|
|
@ -140,7 +139,7 @@ class InstalledAddonDetailsFragment : Fragment() {
|
|
|
|
|
internal fun bindEnableSwitch() {
|
|
|
|
|
val switch = provideEnableSwitch()
|
|
|
|
|
val privateBrowsingSwitch = providePrivateBrowsingSwitch()
|
|
|
|
|
switch.setState(addon.isEnabled())
|
|
|
|
|
switch.isChecked = addon.isEnabled()
|
|
|
|
|
// When the ad-on is blocklisted or not correctly signed, we do not want to enable the toggle switch
|
|
|
|
|
// because users shouldn't be able to re-enable an add-on in this state.
|
|
|
|
|
if (
|
|
|
|
@ -162,7 +161,6 @@ class InstalledAddonDetailsFragment : Fragment() {
|
|
|
|
|
runIfFragmentIsAttached {
|
|
|
|
|
this.addon = it
|
|
|
|
|
switch.isClickable = true
|
|
|
|
|
switch.setText(R.string.mozac_feature_addons_enabled)
|
|
|
|
|
privateBrowsingSwitch.isVisible = it.isEnabled()
|
|
|
|
|
privateBrowsingSwitch.isChecked =
|
|
|
|
|
it.incognito != Addon.Incognito.NOT_ALLOWED && it.isAllowedInPrivateBrowsing()
|
|
|
|
@ -183,7 +181,7 @@ class InstalledAddonDetailsFragment : Fragment() {
|
|
|
|
|
runIfFragmentIsAttached {
|
|
|
|
|
switch.isClickable = true
|
|
|
|
|
enableButtons()
|
|
|
|
|
switch.setState(addon.isEnabled())
|
|
|
|
|
switch.isChecked = addon.isEnabled()
|
|
|
|
|
context?.let {
|
|
|
|
|
showSnackBar(
|
|
|
|
|
binding.root,
|
|
|
|
@ -204,7 +202,6 @@ class InstalledAddonDetailsFragment : Fragment() {
|
|
|
|
|
runIfFragmentIsAttached {
|
|
|
|
|
this.addon = it
|
|
|
|
|
switch.isClickable = true
|
|
|
|
|
switch.setText(R.string.mozac_feature_addons_disabled)
|
|
|
|
|
privateBrowsingSwitch.isVisible = it.isEnabled()
|
|
|
|
|
enableButtons()
|
|
|
|
|
context?.let {
|
|
|
|
@ -221,7 +218,7 @@ class InstalledAddonDetailsFragment : Fragment() {
|
|
|
|
|
onError = {
|
|
|
|
|
runIfFragmentIsAttached {
|
|
|
|
|
switch.isClickable = true
|
|
|
|
|
switch.setState(addon.isEnabled())
|
|
|
|
|
switch.isChecked = addon.isEnabled()
|
|
|
|
|
enableButtons()
|
|
|
|
|
context?.let {
|
|
|
|
|
showSnackBar(
|
|
|
|
@ -424,15 +421,5 @@ class InstalledAddonDetailsFragment : Fragment() {
|
|
|
|
|
binding.reportAddOn.isEnabled = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun SwitchMaterial.setState(checked: Boolean) {
|
|
|
|
|
val text = if (checked) {
|
|
|
|
|
R.string.mozac_feature_addons_enabled
|
|
|
|
|
} else {
|
|
|
|
|
R.string.mozac_feature_addons_disabled
|
|
|
|
|
}
|
|
|
|
|
setText(text)
|
|
|
|
|
isChecked = checked
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun shouldSettingsBeVisible() = !addon.installedState?.optionsPageUrl.isNullOrEmpty()
|
|
|
|
|
}
|
|
|
|
|