diff --git a/app/src/main/java/com/github/libretube/ui/base/BasePreferenceFragment.kt b/app/src/main/java/com/github/libretube/ui/base/BasePreferenceFragment.kt index fe2eb9a39..49879195d 100644 --- a/app/src/main/java/com/github/libretube/ui/base/BasePreferenceFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/base/BasePreferenceFragment.kt @@ -1,6 +1,5 @@ package com.github.libretube.ui.base -import android.os.Bundle import androidx.fragment.app.Fragment import androidx.preference.EditTextPreference import androidx.preference.ListPreference @@ -8,14 +7,20 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import com.github.libretube.R import com.github.libretube.databinding.DialogTextPreferenceBinding +import com.github.libretube.ui.activities.SettingsActivity import com.github.libretube.util.PreferenceHelper import com.google.android.material.dialog.MaterialAlertDialogBuilder /** * PreferenceFragmentCompat using the [MaterialAlertDialogBuilder] instead of the old dialog builder */ -open class BasePreferenceFragment : PreferenceFragmentCompat() { - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {} +abstract class BasePreferenceFragment : PreferenceFragmentCompat() { + abstract val titleResourceId: Int + + override fun onStart() { + super.onStart() + (activity as? SettingsActivity)?.changeTopBarText(getString(titleResourceId)) + } override fun onDisplayPreferenceDialog(preference: Preference) { when (preference) { diff --git a/app/src/main/java/com/github/libretube/ui/preferences/AdvancedSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/AdvancedSettings.kt index e1ef6be6a..c888debeb 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/AdvancedSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/AdvancedSettings.kt @@ -5,20 +5,17 @@ import androidx.preference.ListPreference import androidx.preference.Preference import com.github.libretube.R import com.github.libretube.constants.PreferenceKeys -import com.github.libretube.ui.activities.SettingsActivity import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.util.ImageHelper import com.github.libretube.util.PreferenceHelper import com.google.android.material.dialog.MaterialAlertDialogBuilder class AdvancedSettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.advanced override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.advanced_settings, rootKey) - val settingsActivity = activity as? SettingsActivity - settingsActivity?.changeTopBarText(getString(R.string.advanced)) - val maxImageCache = findPreference(PreferenceKeys.MAX_IMAGE_CACHE) maxImageCache?.setOnPreferenceChangeListener { _, _ -> ImageHelper.initializeImageLoader(requireContext()) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/AppearanceSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/AppearanceSettings.kt index 583e3235d..89f391d62 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/AppearanceSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/AppearanceSettings.kt @@ -6,7 +6,6 @@ import androidx.preference.Preference import androidx.preference.SwitchPreferenceCompat import com.github.libretube.R 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.base.BasePreferenceFragment import com.github.libretube.ui.dialogs.NavBarOptionsDialog @@ -16,12 +15,10 @@ import com.github.libretube.util.PreferenceHelper import com.google.android.material.color.DynamicColors class AppearanceSettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.appearance override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.appearance_settings, rootKey) - val settingsActivity = activity as? SettingsActivity - settingsActivity?.changeTopBarText(getString(R.string.appearance)) - val themeToggle = findPreference(PreferenceKeys.THEME_MODE) themeToggle?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() diff --git a/app/src/main/java/com/github/libretube/ui/preferences/AudioVideoSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/AudioVideoSettings.kt index 7c9d34b9c..0faa13d53 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/AudioVideoSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/AudioVideoSettings.kt @@ -2,15 +2,12 @@ package com.github.libretube.ui.preferences import android.os.Bundle import com.github.libretube.R -import com.github.libretube.ui.activities.SettingsActivity import com.github.libretube.ui.base.BasePreferenceFragment class AudioVideoSettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.audio_video override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.audio_video_settings, rootKey) - - val settingsActivity = activity as? SettingsActivity - settingsActivity?.changeTopBarText(getString(R.string.audio_video)) } } diff --git a/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt index 7db39b5e8..9aa6bb95e 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt @@ -16,6 +16,7 @@ import java.time.LocalDate import java.time.LocalTime class BackupRestoreSettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.backup_restore // backup and restore database private lateinit var getBackupFile: ActivityResultLauncher diff --git a/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt index 5f0d07849..4c4b58e3f 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt @@ -7,20 +7,17 @@ import androidx.preference.Preference import androidx.preference.SwitchPreferenceCompat import com.github.libretube.R 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.dialogs.RequireRestartDialog import com.github.libretube.util.LocaleHelper import com.github.libretube.util.PreferenceHelper class GeneralSettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.general override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.general_settings, rootKey) - val settingsActivity = activity as? SettingsActivity - settingsActivity?.changeTopBarText(getString(R.string.general)) - val language = findPreference("language") language?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() diff --git a/app/src/main/java/com/github/libretube/ui/preferences/HistorySettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/HistorySettings.kt index 45e4f811b..7bda49e6c 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/HistorySettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/HistorySettings.kt @@ -6,18 +6,15 @@ import com.github.libretube.R import com.github.libretube.constants.PreferenceKeys import com.github.libretube.db.DatabaseHolder.Companion.Database import com.github.libretube.extensions.query -import com.github.libretube.ui.activities.SettingsActivity import com.github.libretube.ui.base.BasePreferenceFragment import com.google.android.material.dialog.MaterialAlertDialogBuilder class HistorySettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.history override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.history_settings, rootKey) - val settingsActivity = activity as? SettingsActivity - settingsActivity?.changeTopBarText(getString(R.string.history)) - // clear search history val clearHistory = findPreference(PreferenceKeys.CLEAR_SEARCH_HISTORY) clearHistory?.setOnPreferenceClickListener { diff --git a/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt index 211b7e177..ba18f4b13 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt @@ -11,7 +11,6 @@ import com.github.libretube.api.RetrofitInstance import com.github.libretube.constants.PreferenceKeys import com.github.libretube.db.DatabaseHolder.Companion.Database 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.dialogs.CustomInstanceDialog import com.github.libretube.ui.dialogs.DeleteAccountDialog @@ -20,13 +19,11 @@ import com.github.libretube.ui.dialogs.LogoutDialog import com.github.libretube.util.PreferenceHelper class InstanceSettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.instance override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.instance_settings, rootKey) - val settingsActivity = activity as? SettingsActivity - settingsActivity?.changeTopBarText(getString(R.string.instance)) - val instance = findPreference(PreferenceKeys.FETCH_INSTANCE) // fetchInstance() initCustomInstances(instance!!) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt index c87ca340b..8fac8d33b 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class MainSettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.settings override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.settings, rootKey) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/NotificationSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/NotificationSettings.kt index 736e6fbf2..a43723057 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/NotificationSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/NotificationSettings.kt @@ -6,19 +6,16 @@ import androidx.preference.SwitchPreferenceCompat import androidx.work.ExistingPeriodicWorkPolicy import com.github.libretube.R 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.views.TimePickerPreference import com.github.libretube.util.NotificationHelper class NotificationSettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.notifications override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.notification_settings, rootKey) - val settingsActivity = activity as? SettingsActivity - settingsActivity?.changeTopBarText(getString(R.string.notifications)) - val notificationsEnabled = findPreference(PreferenceKeys.NOTIFICATION_ENABLED) val checkingFrequency = findPreference(PreferenceKeys.CHECKING_FREQUENCY) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt index 75d4d9f40..d0666ef87 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt @@ -10,19 +10,16 @@ import androidx.preference.Preference import androidx.preference.SwitchPreferenceCompat import com.github.libretube.R import com.github.libretube.constants.PreferenceKeys -import com.github.libretube.ui.activities.SettingsActivity import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.util.LocaleHelper import com.github.libretube.util.PreferenceHelper class PlayerSettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.player override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.player_settings, rootKey) - val settingsActivity = activity as? SettingsActivity - settingsActivity?.changeTopBarText(getString(R.string.player)) - val playerOrientation = findPreference(PreferenceKeys.FULLSCREEN_ORIENTATION) val autoRotateToFullscreen = diff --git a/app/src/main/java/com/github/libretube/ui/preferences/SponsorBlockSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/SponsorBlockSettings.kt index 3732140fb..9c8c2e052 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/SponsorBlockSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/SponsorBlockSettings.kt @@ -2,15 +2,12 @@ package com.github.libretube.ui.preferences import android.os.Bundle import com.github.libretube.R -import com.github.libretube.ui.activities.SettingsActivity import com.github.libretube.ui.base.BasePreferenceFragment class SponsorBlockSettings : BasePreferenceFragment() { + override val titleResourceId: Int = R.string.sponsorblock override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.sponsorblock_settings, rootKey) - - val settingsActivity = activity as? SettingsActivity - settingsActivity?.changeTopBarText(getString(R.string.sponsorblock)) } } diff --git a/app/src/main/res/xml/instance_settings.xml b/app/src/main/res/xml/instance_settings.xml index 40fc7824e..c40b9e370 100644 --- a/app/src/main/res/xml/instance_settings.xml +++ b/app/src/main/res/xml/instance_settings.xml @@ -56,19 +56,4 @@ - - - - - - - - \ No newline at end of file