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
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) {

View File

@ -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<ListPreference>(PreferenceKeys.MAX_IMAGE_CACHE)
maxImageCache?.setOnPreferenceChangeListener { _, _ ->
ImageHelper.initializeImageLoader(requireContext())

View File

@ -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<ListPreference>(PreferenceKeys.THEME_MODE)
themeToggle?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()

View File

@ -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))
}
}

View File

@ -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<String>

View File

@ -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<ListPreference>("language")
language?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()

View File

@ -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<Preference>(PreferenceKeys.CLEAR_SEARCH_HISTORY)
clearHistory?.setOnPreferenceClickListener {

View File

@ -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<ListPreference>(PreferenceKeys.FETCH_INSTANCE)
// fetchInstance()
initCustomInstances(instance!!)

View File

@ -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)

View File

@ -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<SwitchPreferenceCompat>(PreferenceKeys.NOTIFICATION_ENABLED)
val checkingFrequency = findPreference<ListPreference>(PreferenceKeys.CHECKING_FREQUENCY)

View File

@ -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<ListPreference>(PreferenceKeys.FULLSCREEN_ORIENTATION)
val autoRotateToFullscreen =

View File

@ -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))
}
}

View File

@ -56,19 +56,4 @@
</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>