* For #514 & #5742: Updates "launch links in private tab" functionality * Fixes commentsnightly-build-test
parent
4a0917ba32
commit
371e2ac3d8
@ -0,0 +1,105 @@
|
|||||||
|
/* 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.content.SharedPreferences
|
||||||
|
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 android.widget.Toast
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.preference.CheckBoxPreference
|
||||||
|
import androidx.preference.Preference
|
||||||
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
|
import mozilla.components.support.utils.Browsers
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.ext.components
|
||||||
|
import org.mozilla.fenix.ext.getPreferenceKey
|
||||||
|
import org.mozilla.fenix.ext.settings
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lets the user control their default browser preferences
|
||||||
|
*/
|
||||||
|
class DefaultBrowserSettingsFragment : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
|
private val preferenceChangeListener =
|
||||||
|
SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
|
||||||
|
when (key) {
|
||||||
|
getPreferenceKey(R.string.pref_key_telemetry) -> {
|
||||||
|
if (sharedPreferences.getBoolean(key, requireContext().settings().isTelemetryEnabled)) {
|
||||||
|
context?.components?.analytics?.metrics?.start()
|
||||||
|
} else {
|
||||||
|
context?.components?.analytics?.metrics?.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
context?.let {
|
||||||
|
preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceChangeListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
val makeDefaultBrowserKey = getPreferenceKey(R.string.pref_key_make_default_browser)
|
||||||
|
val preferenceMakeDefaultBrowser = findPreference<Preference>(makeDefaultBrowserKey)
|
||||||
|
|
||||||
|
preferenceMakeDefaultBrowser?.onPreferenceClickListener =
|
||||||
|
getClickListenerForMakeDefaultBrowser()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
(activity as AppCompatActivity).title = getString(R.string.preferences_set_as_default_browser)
|
||||||
|
(activity as AppCompatActivity).supportActionBar?.show()
|
||||||
|
|
||||||
|
updatePreferences()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
context?.let {
|
||||||
|
preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener)
|
||||||
|
}
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_open_links_in_a_private_tab))?.apply {
|
||||||
|
isEnabled = Browsers.all(requireContext()).isDefaultBrowser
|
||||||
|
isChecked = context.settings().openLinksInAPrivateTab
|
||||||
|
onPreferenceChangeListener = SharedPreferenceUpdater()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
defaultClickListener
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val defaultClickListener =
|
||||||
|
Preference.OnPreferenceClickListener { preference ->
|
||||||
|
Toast.makeText(context, "${preference.title} Clicked", Toast.LENGTH_SHORT).show()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
<?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/. -->
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?android:selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingEnd="?android:attr/scrollbarSize">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@android:id/widget_frame"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/title"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/state_list_text_color"
|
||||||
|
android:textSize="16sp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@android:id/summary"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@android:id/widget_frame"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
|
tools:text="Delete browsing data category" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/summary"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/secondary_state_list_text_color"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@android:id/widget_frame"
|
||||||
|
app:layout_constraintTop_toBottomOf="@android:id/title"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
|
tools:text="Delete browsing data summary" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,15 @@
|
|||||||
|
<?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" />
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:layout="@layout/checkbox_left_preference"
|
||||||
|
android:key="@string/pref_key_open_links_in_a_private_tab"
|
||||||
|
android:title="@string/preferences_open_links_in_a_private_tab" />
|
||||||
|
</PreferenceScreen>
|
Loading…
Reference in New Issue