Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Bug 1881676 - Unconditionally set the "Enabled" label on the toggle switch #6022

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<!-- Indicates the add-on is enabled. -->
<string name="mozac_feature_addons_settings_on">On</string>
<!-- Indicates the add-on is disabled. -->
<string name="mozac_feature_addons_settings_off">Off</string>
<string name="mozac_feature_addons_settings_off" moz:removedIn="125" tools:ignore="UnusedResources">Off</string>
<!-- Indicates the add-on is allowed in private browsing mode. -->
<string name="mozac_feature_addons_settings_allow_in_private_browsing">Allow in private browsing</string>
<!-- Indicates the add-on is allowed in private browsing mode. -->
Expand All @@ -106,7 +106,7 @@
<!-- Indicates the add-on is enabled. -->
<string name="mozac_feature_addons_enabled">Enabled</string>
<!-- Indicates the add-on is disabled. -->
<string name="mozac_feature_addons_disabled">Disabled</string>
<string name="mozac_feature_addons_disabled" moz:removedIn="125" tools:ignore="UnusedResources">Disabled</string>
<!-- This is displayed in a page where the user can see the installed and recommended(not installed yet) add-ons, this string indicates the installed section. -->
<string name="mozac_feature_addons_installed_section">Installed</string>
<!-- This is displayed in a page where the user can see the installed and recommended(not installed yet) add-ons, this string indicates the recommended section. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ class InstalledAddonDetailsActivity : AppCompatActivity() {

private fun bindEnableSwitch(addon: Addon) {
val switch = findViewById<SwitchCompat>(R.id.enable_switch)
switch.setState(addon.isEnabled())
switch.isChecked = addon.isEnabled()
switch.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
this.components.addonManager.enableAddon(
addon,
onSuccess = {
switch.setState(true)
switch.isChecked = true
showAddonToast(
addonsR.string.mozac_feature_addons_successfully_enabled,
addon,
Expand All @@ -104,7 +104,7 @@ class InstalledAddonDetailsActivity : AppCompatActivity() {
this.components.addonManager.disableAddon(
addon,
onSuccess = {
switch.setState(false)
switch.isChecked = false
showAddonToast(
addonsR.string.mozac_feature_addons_successfully_disabled,
addon,
Expand Down Expand Up @@ -197,14 +197,4 @@ class InstalledAddonDetailsActivity : AppCompatActivity() {
Toast.LENGTH_SHORT,
).show()
}

private fun SwitchCompat.setState(checked: Boolean) {
val text = if (checked) {
addonsR.string.mozac_feature_addons_enabled
} else {
addonsR.string.mozac_feature_addons_disabled
}
setText(text)
isChecked = checked
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:checked="true"
android:clickable="true"
android:focusable="true"
android:text="@string/mozac_feature_addons_settings_off"
android:text="@string/mozac_feature_addons_enabled"
android:padding="16dp"
android:textSize="18sp"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand All @@ -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()
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -221,7 +218,7 @@ class InstalledAddonDetailsFragment : Fragment() {
onError = {
runIfFragmentIsAttached {
switch.isClickable = true
switch.setState(addon.isEnabled())
switch.isChecked = addon.isEnabled()
enableButtons()
context?.let {
showSnackBar(
Expand Down Expand Up @@ -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()
}
Loading