[tbb-commits] [Git][tpo/applications/firefox-android][firefox-android-115.2.1-13.5-1] fixup! Implement Android-native Connection Assist UI

Dan Ballard (@dan) git at gitlab.torproject.org
Wed May 8 20:35:35 UTC 2024



Dan Ballard pushed to branch firefox-android-115.2.1-13.5-1 at The Tor Project / Applications / firefox-android


Commits:
3e6fa4e6 by clairehurst at 2024-05-07T17:54:07-06:00
fixup! Implement Android-native Connection Assist UI

- - - - -


7 changed files:

- fenix/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
- + fenix/app/src/main/java/org/mozilla/fenix/tor/QuickStartPreference.kt
- fenix/app/src/main/java/org/mozilla/fenix/tor/TorConnectionAssistFragment.kt
- fenix/app/src/main/java/org/mozilla/fenix/tor/TorConnectionAssistViewModel.kt
- + fenix/app/src/main/res/layout/preference_quick_start.xml
- fenix/app/src/main/res/values/preference_keys.xml
- fenix/app/src/main/res/xml/preferences.xml


Changes:

=====================================
fenix/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
=====================================
@@ -61,6 +61,7 @@ import org.mozilla.fenix.ext.showToolbar
 import org.mozilla.fenix.nimbus.FxNimbus
 import org.mozilla.fenix.perf.ProfilerViewModel
 import org.mozilla.fenix.settings.account.AccountUiView
+import org.mozilla.fenix.tor.QuickStartPreference
 import org.mozilla.fenix.tor.TorBridgeTransportConfig
 import org.mozilla.fenix.tor.TorEvents
 import org.mozilla.fenix.utils.Settings
@@ -729,6 +730,14 @@ class SettingsFragment : PreferenceFragmentCompat() {
             }
         }
 
+        requirePreference<QuickStartPreference>(R.string.pref_key_quick_start).apply {
+            setOnPreferenceClickListener {
+                context.components.torController.quickstart = !context.components.torController.quickstart
+                updateSwitch()
+                true
+            }
+        }
+
         requirePreference<Preference>(R.string.pref_key_use_new_bootstrap).apply {
             setOnPreferenceClickListener {
                 val directions =


=====================================
fenix/app/src/main/java/org/mozilla/fenix/tor/QuickStartPreference.kt
=====================================
@@ -0,0 +1,32 @@
+package org.mozilla.fenix.tor
+
+import android.content.Context
+import android.util.AttributeSet
+import androidx.preference.PreferenceViewHolder
+import androidx.preference.SwitchPreference
+import com.google.android.material.switchmaterial.SwitchMaterial
+import org.mozilla.fenix.R
+import org.mozilla.fenix.ext.components
+
+class QuickStartPreference @JvmOverloads constructor(
+    context: Context,
+    attrs: AttributeSet? = null,
+) : SwitchPreference(context, attrs) {
+
+    private var switchView: SwitchMaterial? = null
+
+    init {
+        widgetLayoutResource = R.layout.preference_quick_start
+    }
+
+    override fun onBindViewHolder(holder: PreferenceViewHolder) {
+        super.onBindViewHolder(holder)
+        switchView = holder.findViewById(R.id.switch_widget) as SwitchMaterial
+
+        updateSwitch()
+    }
+
+    fun updateSwitch() {
+        switchView?.isChecked = context.components.torController.quickstart
+    }
+}


=====================================
fenix/app/src/main/java/org/mozilla/fenix/tor/TorConnectionAssistFragment.kt
=====================================
@@ -27,6 +27,7 @@ import kotlinx.coroutines.launch
 import mozilla.components.support.base.feature.UserInteractionHandler
 import org.mozilla.fenix.R
 import org.mozilla.fenix.databinding.FragmentTorConnectionAssistBinding
+import org.mozilla.fenix.ext.components
 import org.mozilla.fenix.ext.hideToolbar
 
 class TorConnectionAssistFragment : Fragment(), UserInteractionHandler {
@@ -74,11 +75,6 @@ class TorConnectionAssistFragment : Fragment(), UserInteractionHandler {
             }
         }
 
-        viewModel.quickstartToggle().observe(
-            viewLifecycleOwner,
-        ) {
-            binding.quickstartSwitch.isChecked = it == true
-        }
     }
 
     override fun onDestroyView() {
@@ -140,7 +136,7 @@ class TorConnectionAssistFragment : Fragment(), UserInteractionHandler {
                 titleDescription.text = getString(screen.titleDescriptionTextStringResource)
             }
             quickstartSwitch.visibility = if (screen.quickstartSwitchVisible) View.VISIBLE else View.GONE
-            quickstartSwitch.isChecked = viewModel.quickstartToggle().value == true
+            quickstartSwitch.isChecked = requireContext().components.torController.quickstart
             quickstartSwitch.setOnCheckedChangeListener { _, isChecked ->
                 viewModel.handleQuickstartChecked(isChecked)
             }


=====================================
fenix/app/src/main/java/org/mozilla/fenix/tor/TorConnectionAssistViewModel.kt
=====================================
@@ -31,12 +31,6 @@ class TorConnectionAssistViewModel(
         return _progress
     }
 
-    private val _quickStartToggle = MutableLiveData<Boolean>() // don't initialize with quickstart off the bat
-    fun quickstartToggle(): LiveData<Boolean?> {
-        _quickStartToggle.value = _torController.quickstart // quickstart isn't ready until torSettings is ready
-        return _quickStartToggle
-    }
-
     init {
         Log.d(TAG, "initiating TorConnectionAssistViewModel")
         _torController.registerTorListener(this)
@@ -55,7 +49,6 @@ class TorConnectionAssistViewModel(
 
     fun handleQuickstartChecked(checked: Boolean) {
         _torController.quickstart = checked
-        _quickStartToggle.value = checked
     }
 
     fun handleButton1Pressed(


=====================================
fenix/app/src/main/res/layout/preference_quick_start.xml
=====================================
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<com.google.android.material.switchmaterial.SwitchMaterial xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/switch_widget"
+    android:layout_width="wrap_content"
+    android:layout_height="match_parent"
+    android:clickable="false"
+    android:focusable="false"
+    android:gravity="center_vertical"
+    android:orientation="vertical" />


=====================================
fenix/app/src/main/res/values/preference_keys.xml
=====================================
@@ -16,6 +16,7 @@
     <string name="pref_key_accessibility_font_scale" translatable="false">pref_key_accessibility_font_scale</string>
     <string name="pref_key_privacy" translatable="false">pref_key_privacy</string>
     <string name="pref_key_connection" translatable="false">pref_key_connection</string>
+    <string name="pref_key_quick_start" translatable="false">pref_key_quick_start</string>
     <string name="pref_key_accessibility_force_enable_zoom" translatable="false">pref_key_accessibility_force_enable_zoom</string>
     <string name="pref_key_advanced" translatable="false">pref_key_advanced</string>
     <string name="pref_key_language" translatable="false">pref_key_language</string>


=====================================
fenix/app/src/main/res/xml/preferences.xml
=====================================
@@ -170,6 +170,12 @@
             android:title="@string/preferences_tor_network_settings_bridge_config"
             android:summary="@string/preferences_tor_network_settings_bridge_config_description" />
 
+        <org.mozilla.fenix.tor.QuickStartPreference
+            android:key="@string/pref_key_quick_start"
+            android:summary="@string/connection_assist_always_connect_automatically_toggle_description"
+            android:title="@string/tor_bootstrap_quick_start_label"
+            app:iconSpaceReserved="false" />
+
         <Preference
             android:key="@string/pref_key_use_new_bootstrap"
             app:iconSpaceReserved="false"



View it on GitLab: https://gitlab.torproject.org/tpo/applications/firefox-android/-/commit/3e6fa4e6dc3ffd2c99d7d5da7fc16b80bb4c69db

-- 
This project does not include diff previews in email notifications.
View it on GitLab: https://gitlab.torproject.org/tpo/applications/firefox-android/-/commit/3e6fa4e6dc3ffd2c99d7d5da7fc16b80bb4c69db
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20240508/89b5b89b/attachment-0001.htm>


More information about the tbb-commits mailing list