2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/15115 - Part 1: Convert the CloseTabsSettingsFragment to a general TabsSettingsFragment

- Renames CloseTabsSettingsFragment.kt to TabsSettingsFragment.kt
- Renames close_tabs_preferences.xml to tabs_preferences.xml
- Adds preference options for the switching between the Grid and List tab views
This commit is contained in:
Gabriel Luong 2020-10-06 11:34:12 -04:00
parent d7ea7c3555
commit 88ce83d0d2
11 changed files with 103 additions and 51 deletions

View File

@ -24,7 +24,6 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.amo_collection_override_dialog.view.*
import kotlinx.android.synthetic.main.fragment_installed_add_on_details.view.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@ -187,7 +186,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
val tabSettingsPreference =
requirePreference<Preference>(R.string.pref_key_close_tabs)
requirePreference<Preference>(R.string.pref_key_tabs)
tabSettingsPreference.summary = context?.settings()?.getTabTimeoutString()
setupPreferences()
@ -212,8 +211,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
resources.getString(R.string.pref_key_sign_in) -> {
SettingsFragmentDirections.actionSettingsFragmentToTurnOnSyncFragment()
}
resources.getString(R.string.pref_key_close_tabs) -> {
SettingsFragmentDirections.actionSettingsFragmentToCloseTabsSettingsFragment()
resources.getString(R.string.pref_key_tabs) -> {
SettingsFragmentDirections.actionSettingsFragmentToTabsSettingsFragment()
}
resources.getString(R.string.pref_key_search_settings) -> {
SettingsFragmentDirections.actionSettingsFragmentToSearchEngineFragment()

View File

@ -13,31 +13,42 @@ import org.mozilla.fenix.utils.view.addToRadioGroup
/**
* Lets the user customize auto closing tabs.
*/
class CloseTabsSettingsFragment : PreferenceFragmentCompat() {
class TabsSettingsFragment : PreferenceFragmentCompat() {
private lateinit var listRadioButton: RadioButtonPreference
private lateinit var gridRadioButton: RadioButtonPreference
private lateinit var radioManual: RadioButtonPreference
private lateinit var radioOneDay: RadioButtonPreference
private lateinit var radioOneWeek: RadioButtonPreference
private lateinit var radioOneMonth: RadioButtonPreference
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.close_tabs_preferences, rootKey)
setPreferencesFromResource(R.xml.tabs_preferences, rootKey)
}
override fun onResume() {
super.onResume()
showToolbar(getString(R.string.preferences_close_tabs))
showToolbar(getString(R.string.preferences_tabs))
setupPreferences()
}
private fun setupPreferences() {
listRadioButton = requirePreference(R.string.pref_key_tab_view_list)
gridRadioButton = requirePreference(R.string.pref_key_tab_view_grid)
radioManual = requirePreference(R.string.pref_key_close_tabs_manually)
radioOneDay = requirePreference(R.string.pref_key_close_tabs_after_one_day)
radioOneWeek = requirePreference(R.string.pref_key_close_tabs_after_one_week)
radioOneMonth = requirePreference(R.string.pref_key_close_tabs_after_one_month)
setupRadioGroups()
}
private fun setupRadioGroups() {
addToRadioGroup(
listRadioButton,
gridRadioButton
)
addToRadioGroup(
radioManual,
radioOneDay,

View File

@ -92,7 +92,7 @@ class DefaultTabTrayController(
}
override fun handleTabSettingsClicked() {
navController.navigate(TabTrayDialogFragmentDirections.actionGlobalCloseTabSettingsFragment())
navController.navigate(TabTrayDialogFragmentDirections.actionGlobalTabSettingsFragment())
}
override fun onTabTrayDismissed() {
@ -187,7 +187,7 @@ class DefaultTabTrayController(
}
override fun handleSetUpAutoCloseTabsClicked() {
val directions = TabTrayDialogFragmentDirections.actionGlobalCloseTabSettingsFragment()
val directions = TabTrayDialogFragmentDirections.actionGlobalTabSettingsFragment()
navController.navigate(directions)
}
}

View File

@ -345,6 +345,16 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = false
)
var listTabView by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_tab_view_list),
default = true
)
var gridTabView by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_tab_view_grid),
default = false
)
var manuallyCloseTabs by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_close_tabs_manually),
default = true

View File

@ -111,8 +111,8 @@
android:id="@+id/action_global_tabHistoryDialogFragment"
app:destination="@id/tabHistoryDialogFragment" />
<action
android:id="@+id/action_global_closeTabSettingsFragment"
app:destination="@id/closeTabsSettingsFragment" />
android:id="@+id/action_global_tabSettingsFragment"
app:destination="@id/tabsSettingsFragment" />
<dialog
android:id="@+id/tabTrayDialogFragment"
@ -513,17 +513,17 @@
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/action_settingsFragment_to_closeTabsSettingsFragment"
app:destination="@id/closeTabsSettingsFragment"
android:id="@+id/action_settingsFragment_to_tabsSettingsFragment"
app:destination="@id/tabsSettingsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/closeTabsSettingsFragment"
android:name="org.mozilla.fenix.settings.CloseTabsSettingsFragment"
android:label="@string/preferences_close_tabs" />
android:id="@+id/tabsSettingsFragment"
android:name="org.mozilla.fenix.settings.TabsSettingsFragment"
android:label="@string/preferences_tabs" />
<fragment
android:id="@+id/dataChoicesFragment"
android:name="org.mozilla.fenix.settings.DataChoicesFragment"

View File

@ -129,8 +129,6 @@
<!-- Customization Settings -->
<string name="pref_home_category" translatable="false">pref_home_category</string>
<!-- Customization Settings -->
<string name="pref_key_website_pull_to_refresh" translatable="false">pref_key_website_pull_to_refresh</string>
<string name="pref_key_dynamic_toolbar" translatable="false">pref_key_dynamic_toolbar</string>
<string name="pref_key_swipe_toolbar_switch_tabs" translatable="false">pref_key_swipe_toolbar_switch_tabs</string>
@ -225,7 +223,10 @@
<string name="pref_key_show_collections_placeholder_home" translatable="false">pref_key_show_collections_home</string>
<string name="pref_key_close_tabs" translatable="false">pref_key_close_tabs</string>
<!-- Tabs Settings -->
<string name="pref_key_tab_view_list" translatable="false">pref_key_tab_view_list</string>
<string name="pref_key_tab_view_grid" translatable="false">pref_key_tab_view_grid</string>
<string name="pref_key_tabs" translatable="false">pref_key_tabs</string>
<string name="pref_key_close_tabs_manually" translatable="false">pref_key_close_tabs_manually</string>
<string name="pref_key_close_tabs_after_one_day" translatable="false">pref_key_close_tabs_after_one_day</string>
<string name="pref_key_close_tabs_after_one_week" translatable="false">pref_key_close_tabs_after_one_week</string>

View File

@ -531,6 +531,14 @@
<string name="recently_closed_empty_message">No recently closed tabs here</string>
<!-- Tab Management -->
<!-- Title of preference for tabs management -->
<string name="preferences_tabs">Tabs</string>
<!-- Title of preference that allows a user to specify the tab view -->
<string name="preferences_tab_view">Tab view</string>
<!-- Option for a list tab view -->
<string name="tab_view_list">List</string>
<!-- Option for a grid tab view -->
<string name="tab_view_grid">Grid</string>
<!-- Title of preference that allows a user to auto close tabs after a specified amount of time -->
<string name="preferences_close_tabs">Close tabs</string>
<!-- Option for auto closing tabs that will never auto close tabs, always allows user to manually close tabs -->

View File

@ -1,25 +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/. -->
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="true"
android:key="@string/pref_key_close_tabs_manually"
android:title="@string/close_tabs_manually" />
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="false"
android:key="@string/pref_key_close_tabs_after_one_day"
android:title="@string/close_tabs_after_one_day" />
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="false"
android:key="@string/pref_key_close_tabs_after_one_week"
android:title="@string/close_tabs_after_one_week" />
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="false"
android:key="@string/pref_key_close_tabs_after_one_month"
android:title="@string/close_tabs_after_one_month" />
</androidx.preference.PreferenceScreen>

View File

@ -53,6 +53,11 @@
android:key="@string/pref_key_search_settings"
android:title="@string/preferences_search" />
<androidx.preference.Preference
android:icon="@drawable/ic_multiple_tabs"
android:key="@string/pref_key_tabs"
android:title="@string/preferences_tabs" />
<androidx.preference.Preference
android:icon="@drawable/ic_customize"
android:key="@string/pref_key_customize"
@ -77,11 +82,6 @@
android:icon="@drawable/ic_internet"
android:key="@string/pref_key_make_default_browser"
android:title="@string/preferences_set_as_default_browser" />
<androidx.preference.Preference
android:icon="@drawable/ic_multiple_tabs"
android:key="@string/pref_key_close_tabs"
android:title="@string/preferences_close_tabs" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory

View File

@ -0,0 +1,48 @@
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_tab_view"
app:allowDividerAbove="false"
app:iconSpaceReserved="false">
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="true"
android:key="@string/pref_key_tab_view_list"
android:title="@string/tab_view_list" />
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="false"
android:key="@string/pref_key_tab_view_grid"
android:title="@string/tab_view_grid" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_close_tabs"
app:allowDividerAbove="false"
app:iconSpaceReserved="false">
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="true"
android:key="@string/pref_key_close_tabs_manually"
android:title="@string/close_tabs_manually" />
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="false"
android:key="@string/pref_key_close_tabs_after_one_day"
android:title="@string/close_tabs_after_one_day" />
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="false"
android:key="@string/pref_key_close_tabs_after_one_week"
android:title="@string/close_tabs_after_one_week" />
<org.mozilla.fenix.settings.RadioButtonPreference
android:defaultValue="false"
android:key="@string/pref_key_close_tabs_after_one_month"
android:title="@string/close_tabs_after_one_month" />
</androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>

View File

@ -106,7 +106,7 @@ class DefaultTabTrayControllerTest {
verify {
navController.navigate(
TabTrayDialogFragmentDirections.actionGlobalCloseTabSettingsFragment()
TabTrayDialogFragmentDirections.actionGlobalTabSettingsFragment()
)
}
}
@ -252,7 +252,7 @@ class DefaultTabTrayControllerTest {
@Test
fun handleSetUpAutoCloseTabsClicked() {
controller.handleSetUpAutoCloseTabsClicked()
val directions = TabTrayDialogFragmentDirections.actionGlobalCloseTabSettingsFragment()
val directions = TabTrayDialogFragmentDirections.actionGlobalTabSettingsFragment()
verify {
navController.navigate(directions)