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

Commit

Permalink
Bug 1881676 - Unconditionally set the "Enabled" label on the toggle s…
Browse files Browse the repository at this point in the history
…witch
  • Loading branch information
willdurand committed Mar 14, 2024
1 parent 8a49590 commit 1c72df6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 25 deletions.
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 @@ -199,12 +199,6 @@ class InstalledAddonDetailsActivity : AppCompatActivity() {
}

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()
}

0 comments on commit 1c72df6

Please sign in to comment.