Merge pull request #2248 from Bnyro/prefs-titles

Fix wrong titles of preferences
This commit is contained in:
Bnyro 2022-12-05 19:04:14 +01:00 committed by GitHub
commit b5827369a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 19 additions and 54 deletions

View File

@ -1,6 +1,5 @@
package com.github.libretube.ui.base package com.github.libretube.ui.base
import android.os.Bundle
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
import androidx.preference.ListPreference import androidx.preference.ListPreference
@ -8,14 +7,20 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.databinding.DialogTextPreferenceBinding import com.github.libretube.databinding.DialogTextPreferenceBinding
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
/** /**
* PreferenceFragmentCompat using the [MaterialAlertDialogBuilder] instead of the old dialog builder * PreferenceFragmentCompat using the [MaterialAlertDialogBuilder] instead of the old dialog builder
*/ */
open class BasePreferenceFragment : PreferenceFragmentCompat() { abstract class BasePreferenceFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {} abstract val titleResourceId: Int
override fun onStart() {
super.onStart()
(activity as? SettingsActivity)?.changeTopBarText(getString(titleResourceId))
}
override fun onDisplayPreferenceDialog(preference: Preference) { override fun onDisplayPreferenceDialog(preference: Preference) {
when (preference) { when (preference) {

View File

@ -5,20 +5,17 @@ import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
class AdvancedSettings : BasePreferenceFragment() { class AdvancedSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.advanced
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.advanced_settings, rootKey) setPreferencesFromResource(R.xml.advanced_settings, rootKey)
val settingsActivity = activity as? SettingsActivity
settingsActivity?.changeTopBarText(getString(R.string.advanced))
val maxImageCache = findPreference<ListPreference>(PreferenceKeys.MAX_IMAGE_CACHE) val maxImageCache = findPreference<ListPreference>(PreferenceKeys.MAX_IMAGE_CACHE)
maxImageCache?.setOnPreferenceChangeListener { _, _ -> maxImageCache?.setOnPreferenceChangeListener { _, _ ->
ImageHelper.initializeImageLoader(requireContext()) ImageHelper.initializeImageLoader(requireContext())

View File

@ -6,7 +6,6 @@ import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.adapters.IconsSheetAdapter import com.github.libretube.ui.adapters.IconsSheetAdapter
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.ui.dialogs.NavBarOptionsDialog import com.github.libretube.ui.dialogs.NavBarOptionsDialog
@ -16,12 +15,10 @@ import com.github.libretube.util.PreferenceHelper
import com.google.android.material.color.DynamicColors import com.google.android.material.color.DynamicColors
class AppearanceSettings : BasePreferenceFragment() { class AppearanceSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.appearance
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.appearance_settings, rootKey) setPreferencesFromResource(R.xml.appearance_settings, rootKey)
val settingsActivity = activity as? SettingsActivity
settingsActivity?.changeTopBarText(getString(R.string.appearance))
val themeToggle = findPreference<ListPreference>(PreferenceKeys.THEME_MODE) val themeToggle = findPreference<ListPreference>(PreferenceKeys.THEME_MODE)
themeToggle?.setOnPreferenceChangeListener { _, _ -> themeToggle?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog() val restartDialog = RequireRestartDialog()

View File

@ -2,15 +2,12 @@ package com.github.libretube.ui.preferences
import android.os.Bundle import android.os.Bundle
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
class AudioVideoSettings : BasePreferenceFragment() { class AudioVideoSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.audio_video
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.audio_video_settings, rootKey) setPreferencesFromResource(R.xml.audio_video_settings, rootKey)
val settingsActivity = activity as? SettingsActivity
settingsActivity?.changeTopBarText(getString(R.string.audio_video))
} }
} }

View File

@ -16,6 +16,7 @@ import java.time.LocalDate
import java.time.LocalTime import java.time.LocalTime
class BackupRestoreSettings : BasePreferenceFragment() { class BackupRestoreSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.backup_restore
// backup and restore database // backup and restore database
private lateinit var getBackupFile: ActivityResultLauncher<String> private lateinit var getBackupFile: ActivityResultLauncher<String>

View File

@ -7,20 +7,17 @@ import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.ui.dialogs.RequireRestartDialog import com.github.libretube.ui.dialogs.RequireRestartDialog
import com.github.libretube.util.LocaleHelper import com.github.libretube.util.LocaleHelper
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
class GeneralSettings : BasePreferenceFragment() { class GeneralSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.general
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.general_settings, rootKey) setPreferencesFromResource(R.xml.general_settings, rootKey)
val settingsActivity = activity as? SettingsActivity
settingsActivity?.changeTopBarText(getString(R.string.general))
val language = findPreference<ListPreference>("language") val language = findPreference<ListPreference>("language")
language?.setOnPreferenceChangeListener { _, _ -> language?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog() val restartDialog = RequireRestartDialog()

View File

@ -6,18 +6,15 @@ import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.db.DatabaseHolder.Companion.Database import com.github.libretube.db.DatabaseHolder.Companion.Database
import com.github.libretube.extensions.query import com.github.libretube.extensions.query
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
class HistorySettings : BasePreferenceFragment() { class HistorySettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.history
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.history_settings, rootKey) setPreferencesFromResource(R.xml.history_settings, rootKey)
val settingsActivity = activity as? SettingsActivity
settingsActivity?.changeTopBarText(getString(R.string.history))
// clear search history // clear search history
val clearHistory = findPreference<Preference>(PreferenceKeys.CLEAR_SEARCH_HISTORY) val clearHistory = findPreference<Preference>(PreferenceKeys.CLEAR_SEARCH_HISTORY)
clearHistory?.setOnPreferenceClickListener { clearHistory?.setOnPreferenceClickListener {

View File

@ -11,7 +11,6 @@ import com.github.libretube.api.RetrofitInstance
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.db.DatabaseHolder.Companion.Database import com.github.libretube.db.DatabaseHolder.Companion.Database
import com.github.libretube.extensions.awaitQuery import com.github.libretube.extensions.awaitQuery
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.ui.dialogs.CustomInstanceDialog import com.github.libretube.ui.dialogs.CustomInstanceDialog
import com.github.libretube.ui.dialogs.DeleteAccountDialog import com.github.libretube.ui.dialogs.DeleteAccountDialog
@ -20,13 +19,11 @@ import com.github.libretube.ui.dialogs.LogoutDialog
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
class InstanceSettings : BasePreferenceFragment() { class InstanceSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.instance
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.instance_settings, rootKey) setPreferencesFromResource(R.xml.instance_settings, rootKey)
val settingsActivity = activity as? SettingsActivity
settingsActivity?.changeTopBarText(getString(R.string.instance))
val instance = findPreference<ListPreference>(PreferenceKeys.FETCH_INSTANCE) val instance = findPreference<ListPreference>(PreferenceKeys.FETCH_INSTANCE)
// fetchInstance() // fetchInstance()
initCustomInstances(instance!!) initCustomInstances(instance!!)

View File

@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class MainSettings : BasePreferenceFragment() { class MainSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.settings
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.settings, rootKey) setPreferencesFromResource(R.xml.settings, rootKey)

View File

@ -6,19 +6,16 @@ import androidx.preference.SwitchPreferenceCompat
import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.ExistingPeriodicWorkPolicy
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.ui.views.TimePickerPreference import com.github.libretube.ui.views.TimePickerPreference
import com.github.libretube.util.NotificationHelper import com.github.libretube.util.NotificationHelper
class NotificationSettings : BasePreferenceFragment() { class NotificationSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.notifications
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.notification_settings, rootKey) setPreferencesFromResource(R.xml.notification_settings, rootKey)
val settingsActivity = activity as? SettingsActivity
settingsActivity?.changeTopBarText(getString(R.string.notifications))
val notificationsEnabled = val notificationsEnabled =
findPreference<SwitchPreferenceCompat>(PreferenceKeys.NOTIFICATION_ENABLED) findPreference<SwitchPreferenceCompat>(PreferenceKeys.NOTIFICATION_ENABLED)
val checkingFrequency = findPreference<ListPreference>(PreferenceKeys.CHECKING_FREQUENCY) val checkingFrequency = findPreference<ListPreference>(PreferenceKeys.CHECKING_FREQUENCY)

View File

@ -10,19 +10,16 @@ import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.util.LocaleHelper import com.github.libretube.util.LocaleHelper
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
class PlayerSettings : BasePreferenceFragment() { class PlayerSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.player
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.player_settings, rootKey) setPreferencesFromResource(R.xml.player_settings, rootKey)
val settingsActivity = activity as? SettingsActivity
settingsActivity?.changeTopBarText(getString(R.string.player))
val playerOrientation = val playerOrientation =
findPreference<ListPreference>(PreferenceKeys.FULLSCREEN_ORIENTATION) findPreference<ListPreference>(PreferenceKeys.FULLSCREEN_ORIENTATION)
val autoRotateToFullscreen = val autoRotateToFullscreen =

View File

@ -2,15 +2,12 @@ package com.github.libretube.ui.preferences
import android.os.Bundle import android.os.Bundle
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
class SponsorBlockSettings : BasePreferenceFragment() { class SponsorBlockSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.sponsorblock
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.sponsorblock_settings, rootKey) setPreferencesFromResource(R.xml.sponsorblock_settings, rootKey)
val settingsActivity = activity as? SettingsActivity
settingsActivity?.changeTopBarText(getString(R.string.sponsorblock))
} }
} }

View File

@ -56,19 +56,4 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory app:title="@string/restore">
<Preference
android:icon="@drawable/ic_download_filled"
android:summary="@string/import_from_yt_summary"
app:key="import_from_yt"
app:title="@string/import_from_yt" />
<Preference
android:icon="@drawable/ic_upload"
app:key="export_subs"
app:title="@string/export_subscriptions" />
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>