1
0
Fork 0

For #11365: Reorganizes 'SettingsFragment' items

Moved all the functionality form 'DefaultBrowserSettingsFragment' to
'SettingsFragment'.
master
ValentinTimisica 2020-06-09 16:35:55 +03:00
parent 11697c1363
commit bc53296603
7 changed files with 44 additions and 108 deletions

View File

@ -24,7 +24,6 @@ enum class BrowserDirection(@IdRes val fragmentId: Int) {
FromExceptions(R.id.exceptionsFragment), FromExceptions(R.id.exceptionsFragment),
FromAbout(R.id.aboutFragment), FromAbout(R.id.aboutFragment),
FromTrackingProtection(R.id.trackingProtectionFragment), FromTrackingProtection(R.id.trackingProtectionFragment),
FromDefaultBrowserSettingsFragment(R.id.defaultBrowserSettingsFragment),
FromSavedLoginsFragment(R.id.savedLoginsFragment), FromSavedLoginsFragment(R.id.savedLoginsFragment),
FromAddNewDeviceFragment(R.id.addNewDeviceFragment), FromAddNewDeviceFragment(R.id.addNewDeviceFragment),
FromAddSearchEngineFragment(R.id.addSearchEngineFragment), FromAddSearchEngineFragment(R.id.addSearchEngineFragment),

View File

@ -70,7 +70,6 @@ import org.mozilla.fenix.library.history.HistoryFragmentDirections
import org.mozilla.fenix.perf.Performance import org.mozilla.fenix.perf.Performance
import org.mozilla.fenix.perf.StartupTimeline import org.mozilla.fenix.perf.StartupTimeline
import org.mozilla.fenix.search.SearchFragmentDirections import org.mozilla.fenix.search.SearchFragmentDirections
import org.mozilla.fenix.settings.DefaultBrowserSettingsFragmentDirections
import org.mozilla.fenix.settings.SettingsFragmentDirections import org.mozilla.fenix.settings.SettingsFragmentDirections
import org.mozilla.fenix.settings.TrackingProtectionFragmentDirections import org.mozilla.fenix.settings.TrackingProtectionFragmentDirections
import org.mozilla.fenix.settings.about.AboutFragmentDirections import org.mozilla.fenix.settings.about.AboutFragmentDirections
@ -384,8 +383,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
AboutFragmentDirections.actionGlobalBrowser(customTabSessionId) AboutFragmentDirections.actionGlobalBrowser(customTabSessionId)
BrowserDirection.FromTrackingProtection -> BrowserDirection.FromTrackingProtection ->
TrackingProtectionFragmentDirections.actionGlobalBrowser(customTabSessionId) TrackingProtectionFragmentDirections.actionGlobalBrowser(customTabSessionId)
BrowserDirection.FromDefaultBrowserSettingsFragment ->
DefaultBrowserSettingsFragmentDirections.actionGlobalBrowser(customTabSessionId)
BrowserDirection.FromSavedLoginsFragment -> BrowserDirection.FromSavedLoginsFragment ->
SavedLoginsAuthFragmentDirections.actionGlobalBrowser(customTabSessionId) SavedLoginsAuthFragmentDirections.actionGlobalBrowser(customTabSessionId)
BrowserDirection.FromAddNewDeviceFragment -> BrowserDirection.FromAddNewDeviceFragment ->

View File

@ -1,73 +0,0 @@
/* 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/. */
package org.mozilla.fenix.settings
import android.content.Intent
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle
import android.provider.Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.showToolbar
/**
* Lets the user control their default browser preferences
*/
class DefaultBrowserSettingsFragment : PreferenceFragmentCompat() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val makeDefaultBrowserKey = getPreferenceKey(R.string.pref_key_make_default_browser)
val preferenceMakeDefaultBrowser = findPreference<Preference>(makeDefaultBrowserKey)
preferenceMakeDefaultBrowser?.onPreferenceClickListener =
getClickListenerForMakeDefaultBrowser()
}
override fun onResume() {
super.onResume()
showToolbar(getString(R.string.preferences_set_as_default_browser))
updatePreferences()
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.default_browser_preferences, rootKey)
updatePreferences()
}
private fun updatePreferences() {
findPreference<DefaultBrowserPreference>(getPreferenceKey(R.string.pref_key_make_default_browser))
?.updateSwitch()
}
private fun getClickListenerForMakeDefaultBrowser(): Preference.OnPreferenceClickListener {
return if (SDK_INT >= Build.VERSION_CODES.N) {
Preference.OnPreferenceClickListener {
val intent = Intent(ACTION_MANAGE_DEFAULT_APPS_SETTINGS)
startActivity(intent)
true
}
} else {
Preference.OnPreferenceClickListener {
(activity as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = SupportUtils.getSumoURLForTopic(
requireContext(),
SupportUtils.SumoTopic.SET_AS_DEFAULT_BROWSER
),
newTab = true,
from = BrowserDirection.FromDefaultBrowserSettingsFragment
)
true
}
}
}
}

View File

@ -8,8 +8,10 @@ import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.provider.Settings
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.content.res.AppCompatResources
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
@ -114,6 +116,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey) setPreferencesFromResource(R.xml.preferences, rootKey)
updateMakeDefaultBrowserPreference()
} }
override fun onResume() { override fun onResume() {
@ -173,6 +176,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
requireComponents.backgroundServices.accountManager.accountProfile() requireComponents.backgroundServices.accountManager.accountProfile()
) )
} }
updateMakeDefaultBrowserPreference()
} }
@Suppress("ComplexMethod", "LongMethod") @Suppress("ComplexMethod", "LongMethod")
@ -208,9 +213,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
requireContext().metrics.track(Event.AddonsOpenInSettings) requireContext().metrics.track(Event.AddonsOpenInSettings)
SettingsFragmentDirections.actionSettingsFragmentToAddonsFragment() SettingsFragmentDirections.actionSettingsFragmentToAddonsFragment()
} }
resources.getString(R.string.pref_key_make_default_browser) -> {
SettingsFragmentDirections.actionSettingsFragmentToDefaultBrowserSettingsFragment()
}
resources.getString(R.string.pref_key_data_choices) -> { resources.getString(R.string.pref_key_data_choices) -> {
SettingsFragmentDirections.actionSettingsFragmentToDataChoicesFragment() SettingsFragmentDirections.actionSettingsFragmentToDataChoicesFragment()
} }
@ -289,9 +291,11 @@ class SettingsFragment : PreferenceFragmentCompat() {
private fun setupPreferences() { private fun setupPreferences() {
val leakKey = getPreferenceKey(R.string.pref_key_leakcanary) val leakKey = getPreferenceKey(R.string.pref_key_leakcanary)
val debuggingKey = getPreferenceKey(R.string.pref_key_remote_debugging) val debuggingKey = getPreferenceKey(R.string.pref_key_remote_debugging)
val makeDefaultBrowserKey = getPreferenceKey(R.string.pref_key_make_default_browser)
val preferenceLeakCanary = findPreference<Preference>(leakKey) val preferenceLeakCanary = findPreference<Preference>(leakKey)
val preferenceRemoteDebugging = findPreference<Preference>(debuggingKey) val preferenceRemoteDebugging = findPreference<Preference>(debuggingKey)
val preferenceMakeDefaultBrowser = findPreference<Preference>(makeDefaultBrowserKey)
if (!Config.channel.isReleased) { if (!Config.channel.isReleased) {
preferenceLeakCanary?.setOnPreferenceChangeListener { _, newValue -> preferenceLeakCanary?.setOnPreferenceChangeListener { _, newValue ->
@ -308,6 +312,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
true true
} }
preferenceMakeDefaultBrowser?.onPreferenceClickListener =
getClickListenerForMakeDefaultBrowser()
val preferenceFxAOverride = val preferenceFxAOverride =
findPreference<Preference>(getPreferenceKey(R.string.pref_key_override_fxa_server)) findPreference<Preference>(getPreferenceKey(R.string.pref_key_override_fxa_server))
val preferenceSyncOverride = val preferenceSyncOverride =
@ -335,6 +342,33 @@ class SettingsFragment : PreferenceFragmentCompat() {
)?.isVisible = requireContext().settings().showSecretDebugMenuThisSession )?.isVisible = requireContext().settings().showSecretDebugMenuThisSession
} }
private fun getClickListenerForMakeDefaultBrowser(): Preference.OnPreferenceClickListener {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Preference.OnPreferenceClickListener {
val intent = Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS)
startActivity(intent)
true
}
} else {
Preference.OnPreferenceClickListener {
(activity as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = SupportUtils.getSumoURLForTopic(
requireContext(),
SupportUtils.SumoTopic.SET_AS_DEFAULT_BROWSER
),
newTab = true,
from = BrowserDirection.FromSettings
)
true
}
}
}
private fun updateMakeDefaultBrowserPreference() {
findPreference<DefaultBrowserPreference>(getPreferenceKey(R.string.pref_key_make_default_browser))
?.updateSwitch()
}
private fun navigateFromSettings(directions: NavDirections) { private fun navigateFromSettings(directions: NavDirections) {
view?.findNavController()?.let { navController -> view?.findNavController()?.let { navController ->
if (navController.currentDestination?.id == R.id.settingsFragment) { if (navController.currentDestination?.id == R.id.settingsFragment) {

View File

@ -446,13 +446,6 @@
app:popEnterAnim="@anim/slide_in_left" app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" app:popExitAnim="@anim/slide_out_right"
app:destination="@id/deleteBrowsingDataOnQuitFragment" /> app:destination="@id/deleteBrowsingDataOnQuitFragment" />
<action
android:id="@+id/action_settingsFragment_to_defaultBrowserSettingsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/defaultBrowserSettingsFragment" />
<action <action
android:id="@+id/action_settingsFragment_to_localeSettingsFragment" android:id="@+id/action_settingsFragment_to_localeSettingsFragment"
app:enterAnim="@anim/slide_in_right" app:enterAnim="@anim/slide_in_right"
@ -709,9 +702,6 @@
<fragment <fragment
android:id="@+id/addNewDeviceFragment" android:id="@+id/addNewDeviceFragment"
android:name="org.mozilla.fenix.share.AddNewDeviceFragment" /> android:name="org.mozilla.fenix.share.AddNewDeviceFragment" />
<fragment
android:id="@+id/defaultBrowserSettingsFragment"
android:name="org.mozilla.fenix.settings.DefaultBrowserSettingsFragment"/>
<fragment <fragment
android:id="@+id/addSearchEngineFragment" android:id="@+id/addSearchEngineFragment"
android:name="org.mozilla.fenix.settings.search.AddSearchEngineFragment" /> android:name="org.mozilla.fenix.settings.search.AddSearchEngineFragment" />

View File

@ -1,11 +0,0 @@
<?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/. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<org.mozilla.fenix.settings.DefaultBrowserPreference
android:key="@string/pref_key_make_default_browser"
android:title="@string/preferences_set_as_default_browser"
app:iconSpaceReserved="false" />
</PreferenceScreen>

View File

@ -73,7 +73,7 @@
android:key="@string/pref_key_language" android:key="@string/pref_key_language"
android:title="@string/preferences_language" /> android:title="@string/preferences_language" />
<androidx.preference.Preference <org.mozilla.fenix.settings.DefaultBrowserPreference
android:icon="@drawable/ic_internet" android:icon="@drawable/ic_internet"
android:key="@string/pref_key_make_default_browser" android:key="@string/pref_key_make_default_browser"
android:title="@string/preferences_set_as_default_browser" /> android:title="@string/preferences_set_as_default_browser" />
@ -114,12 +114,6 @@
android:key="@string/pref_key_data_choices" android:key="@string/pref_key_data_choices"
android:title="@string/preferences_data_collection" /> android:title="@string/preferences_data_collection" />
<androidx.preference.SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_app_links"
android:key="@string/pref_key_open_links_in_external_app"
android:title="@string/preferences_open_links_in_apps" />
</androidx.preference.PreferenceCategory> </androidx.preference.PreferenceCategory>
<PreferenceCategory <PreferenceCategory
@ -132,6 +126,12 @@
android:key="@string/pref_key_addons" android:key="@string/pref_key_addons"
android:title="@string/preferences_addons" /> android:title="@string/preferences_addons" />
<androidx.preference.SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_app_links"
android:key="@string/pref_key_open_links_in_external_app"
android:title="@string/preferences_open_links_in_apps" />
<androidx.preference.SwitchPreference <androidx.preference.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:icon="@drawable/ic_info" android:icon="@drawable/ic_info"