Part of #288 - Set up basic settings menu
parent
4d804981f0
commit
8368f4fbb2
|
@ -132,6 +132,7 @@ dependencies {
|
||||||
armImplementation Deps.geckoview_nightly_arm
|
armImplementation Deps.geckoview_nightly_arm
|
||||||
x86Implementation Deps.geckoview_nightly_x86
|
x86Implementation Deps.geckoview_nightly_x86
|
||||||
implementation Deps.androidx_legacy
|
implementation Deps.androidx_legacy
|
||||||
|
implementation Deps.androidx_preference
|
||||||
implementation Deps.android_arch_navigation
|
implementation Deps.android_arch_navigation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,12 @@
|
||||||
<data android:mimeType="text/plain" />
|
<data android:mimeType="text/plain" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".settings.SettingsActivity"
|
||||||
|
android:label="@string/settings"
|
||||||
|
android:parentActivityName=".HomeActivity"
|
||||||
|
android:theme="@style/AppTheme" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -42,6 +42,11 @@ class HomeFragment : Fragment() {
|
||||||
BitmapDrawable(resources, it.icon)
|
BitmapDrawable(resources, it.icon)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Temporary so we can easily test settings
|
||||||
|
menuButton.setOnClickListener {
|
||||||
|
Navigation.findNavController(it).navigate(R.id.action_homeFragment_to_settingsActivity, null, null)
|
||||||
|
}
|
||||||
|
|
||||||
toolbar.setCompoundDrawablesWithIntrinsicBounds(searchIcon, null, null, null)
|
toolbar.setCompoundDrawablesWithIntrinsicBounds(searchIcon, null, null, null)
|
||||||
val roundToInt = (toolbarPaddingDp * Resources.getSystem().displayMetrics.density).roundToInt()
|
val roundToInt = (toolbarPaddingDp * Resources.getSystem().displayMetrics.density).roundToInt()
|
||||||
toolbar.compoundDrawablePadding = roundToInt
|
toolbar.compoundDrawablePadding = roundToInt
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* 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.R.id.content
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
|
||||||
|
class SettingsActivity : AppCompatActivity(), SettingsFragment.ActionBarUpdater {
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
with(supportFragmentManager.beginTransaction()) {
|
||||||
|
replace(content, SettingsFragment())
|
||||||
|
commit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||||
|
android.R.id.home -> {
|
||||||
|
onBackPressed()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateTitle(titleResId: Int) {
|
||||||
|
setTitle(titleResId)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
/* 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.Bundle
|
||||||
|
import android.provider.Settings
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.preference.Preference.OnPreferenceClickListener
|
||||||
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.R.string.pref_key_make_default_browser
|
||||||
|
import org.mozilla.fenix.ext.getPreferenceKey
|
||||||
|
|
||||||
|
class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
|
interface ActionBarUpdater {
|
||||||
|
fun updateTitle(titleResId: Int)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
|
setPreferencesFromResource(R.xml.preferences, rootKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
|
||||||
|
setupPreferences()
|
||||||
|
getActionBarUpdater().apply {
|
||||||
|
updateTitle(R.string.settings)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("LongMethod") // Yep, this should be refactored.
|
||||||
|
private fun setupPreferences() {
|
||||||
|
val makeDefaultBrowserKey = context?.getPreferenceKey(pref_key_make_default_browser)
|
||||||
|
|
||||||
|
val preferenceMakeDefaultBrowser = findPreference(makeDefaultBrowserKey)
|
||||||
|
|
||||||
|
preferenceMakeDefaultBrowser.onPreferenceClickListener = getClickListenerForMakeDefaultBrowser()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val defaultClickListener = OnPreferenceClickListener { preference ->
|
||||||
|
Toast.makeText(context, "${preference.title} Clicked", Toast.LENGTH_SHORT).show()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getClickListenerForMakeDefaultBrowser(): OnPreferenceClickListener {
|
||||||
|
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
||||||
|
OnPreferenceClickListener {
|
||||||
|
val intent = Intent(
|
||||||
|
Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS
|
||||||
|
)
|
||||||
|
startActivity(intent)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
defaultClickListener
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getActionBarUpdater() = activity as ActionBarUpdater
|
||||||
|
}
|
|
@ -1,29 +1,54 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/nav_graph"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
app:startDestination="@id/homeFragment">
|
android:id="@+id/nav_graph"
|
||||||
|
app:startDestination="@id/homeFragment">
|
||||||
|
|
||||||
<fragment android:id="@+id/homeFragment" android:name="org.mozilla.fenix.home.HomeFragment"
|
<fragment
|
||||||
android:label="fragment_home" tools:layout="@layout/fragment_home">
|
android:id="@+id/homeFragment"
|
||||||
<action android:id="@+id/action_homeFragment_to_searchFragment" app:destination="@id/searchFragment"
|
android:name="org.mozilla.fenix.home.HomeFragment"
|
||||||
/>
|
android:label="fragment_home"
|
||||||
<action android:id="@+id/action_homeFragment_to_browserFragment" app:destination="@id/browserFragment"/>
|
tools:layout="@layout/fragment_home">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_homeFragment_to_searchFragment"
|
||||||
|
app:destination="@id/searchFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_homeFragment_to_browserFragment"
|
||||||
|
app:destination="@id/browserFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_homeFragment_to_settingsActivity"
|
||||||
|
app:destination="@id/settingsActivity" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment android:id="@+id/searchFragment" android:name="org.mozilla.fenix.search.SearchFragment"
|
<fragment
|
||||||
android:label="fragment_search" tools:layout="@layout/fragment_search">
|
android:id="@+id/searchFragment"
|
||||||
<action android:id="@+id/action_searchFragment_to_browserFragment" app:destination="@id/browserFragment"
|
android:name="org.mozilla.fenix.search.SearchFragment"
|
||||||
app:popUpTo="@id/homeFragment"/>
|
android:label="fragment_search"
|
||||||
|
tools:layout="@layout/fragment_search">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_searchFragment_to_browserFragment"
|
||||||
|
app:destination="@id/browserFragment"
|
||||||
|
app:popUpTo="@id/homeFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment android:id="@+id/browserFragment" android:name="org.mozilla.fenix.browser.BrowserFragment"
|
<fragment
|
||||||
android:label="fragment_browser" tools:layout="@layout/fragment_browser">
|
android:id="@+id/browserFragment"
|
||||||
|
android:name="org.mozilla.fenix.browser.BrowserFragment"
|
||||||
|
android:label="fragment_browser"
|
||||||
|
tools:layout="@layout/fragment_browser">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_browserFragment_to_homeFragment"
|
android:id="@+id/action_browserFragment_to_homeFragment"
|
||||||
app:destination="@id/homeFragment" />
|
app:destination="@id/homeFragment" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_browserFragment_to_searchFragment"
|
android:id="@+id/action_browserFragment_to_searchFragment"
|
||||||
app:destination="@id/searchFragment" />
|
app:destination="@id/searchFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_browserFragment_to_settingsActivity"
|
||||||
|
app:destination="@id/settingsActivity" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
<activity
|
||||||
|
android:id="@+id/settingsActivity"
|
||||||
|
android:name="org.mozilla.fenix.settings.SettingsActivity"
|
||||||
|
android:label="SettingsActivity" />
|
||||||
</navigation>
|
</navigation>
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?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/. -->
|
||||||
|
<resources>
|
||||||
|
<string name="pref_key_make_default_browser" translatable="false">pref_key_make_default_browser</string>
|
||||||
|
</resources>
|
|
@ -23,4 +23,10 @@
|
||||||
<string name="sessions_intro_description">Fenix will collect your browsing sessions on your Home Screen for you to retrieve later.</string>
|
<string name="sessions_intro_description">Fenix will collect your browsing sessions on your Home Screen for you to retrieve later.</string>
|
||||||
<string name="search_scan_button">Scan</string>
|
<string name="search_scan_button">Scan</string>
|
||||||
<string name="search_shortcuts_button">Shortcuts</string>
|
<string name="search_shortcuts_button">Shortcuts</string>
|
||||||
|
|
||||||
|
<!-- Preference for settings related to changing the default browser -->
|
||||||
|
<string name="preferences_make_default_browser">Make default browser</string>
|
||||||
|
|
||||||
|
<!-- Menu option on the toolbar that takes you to settings page-->
|
||||||
|
<string name="settings">Settings</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -8,6 +8,12 @@
|
||||||
<item name="colorPrimary">@color/colorPrimary</item>
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
<item name="colorAccent">@color/colorAccent</item>
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
|
||||||
|
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme" parent="Theme.AppCompat.Light">
|
||||||
|
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="search_pill" parent="Widget.AppCompat.Button.Borderless">
|
<style name="search_pill" parent="Widget.AppCompat.Button.Borderless">
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?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.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<androidx.preference.Preference
|
||||||
|
android:key="@string/pref_key_make_default_browser"
|
||||||
|
android:title="@string/preferences_make_default_browser" />
|
||||||
|
|
||||||
|
</androidx.preference.PreferenceScreen>
|
|
@ -13,6 +13,7 @@ private object Versions {
|
||||||
|
|
||||||
const val androidx_appcompat = "1.0.2"
|
const val androidx_appcompat = "1.0.2"
|
||||||
const val androidx_constraint_layout = "2.0.0-alpha3"
|
const val androidx_constraint_layout = "2.0.0-alpha3"
|
||||||
|
const val androidx_preference = "1.0.0"
|
||||||
|
|
||||||
const val mozilla_android_components = "0.41.0-SNAPSHOT"
|
const val mozilla_android_components = "0.41.0-SNAPSHOT"
|
||||||
|
|
||||||
|
@ -86,6 +87,7 @@ object Deps {
|
||||||
const val tools_espresso_core = "com.android.support.test.espresso:espresso-core:${Versions.espresso_core}"
|
const val tools_espresso_core = "com.android.support.test.espresso:espresso-core:${Versions.espresso_core}"
|
||||||
|
|
||||||
const val androidx_legacy = "androidx.legacy:legacy-support-v4:${Versions.androidx_legacy}"
|
const val androidx_legacy = "androidx.legacy:legacy-support-v4:${Versions.androidx_legacy}"
|
||||||
|
const val androidx_preference = "androidx.preference:preference-ktx:${Versions.androidx_preference}"
|
||||||
const val android_arch_navigation = "android.arch.navigation:navigation-fragment:${Versions.android_arch_navigation}"
|
const val android_arch_navigation = "android.arch.navigation:navigation-fragment:${Versions.android_arch_navigation}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue