Skip to content
Snippets Groups Projects
Commit 3e6fa4e6 authored by clairehurst's avatar clairehurst
Browse files

fixup! Implement Android-native Connection Assist UI

parent 737cb590
No related branches found
No related tags found
1 merge request!91Bug_41187: Add quick start setting
......@@ -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 =
......
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
}
}
......@@ -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)
}
......
......@@ -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(
......
<?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" />
......@@ -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>
......
......@@ -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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment