From 74f6f7a626660320b56d21f6de028cd03cd5625c Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 17 Jul 2022 18:18:39 +0200 Subject: [PATCH] cleanup preference keys --- .../libretube/activities/MainActivity.kt | 15 ++-- .../github/libretube/dialogs/ShareDialog.kt | 3 +- .../libretube/fragments/HomeFragment.kt | 5 +- .../libretube/fragments/LibraryFragment.kt | 3 +- .../libretube/fragments/PlayerFragment.kt | 27 +++---- .../libretube/fragments/SearchFragment.kt | 3 +- .../fragments/SubscriptionsFragment.kt | 3 +- .../libretube/preferences/AdvancedSettings.kt | 4 +- .../preferences/AppearanceSettings.kt | 14 ++-- .../libretube/preferences/HistorySettings.kt | 6 +- .../libretube/preferences/InstanceSettings.kt | 20 +++--- .../libretube/preferences/PlayerSettings.kt | 6 +- .../libretube/preferences/PreferenceKeys.kt | 70 +++++++++++++++++++ .../libretube/services/DownloadService.kt | 7 +- .../github/libretube/util/BackgroundMode.kt | 3 +- .../com/github/libretube/util/LocaleHelper.kt | 3 +- .../com/github/libretube/util/ThemeHelper.kt | 7 +- app/src/main/res/xml/history_settings.xml | 2 +- 18 files changed, 141 insertions(+), 60 deletions(-) create mode 100644 app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 07fc0c3f1..5b614a4cd 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -30,6 +30,7 @@ import com.github.libretube.R import com.github.libretube.databinding.ActivityMainBinding import com.github.libretube.fragments.PlayerFragment import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.services.ClosingService import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.CronetHelper @@ -62,12 +63,12 @@ class MainActivity : AppCompatActivity() { CronetHelper.initCronet(this.applicationContext) RetrofitInstance.url = - PreferenceHelper.getString("selectInstance", PIPED_API_URL)!! + PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, PIPED_API_URL)!! // set auth instance RetrofitInstance.authUrl = - if (PreferenceHelper.getBoolean("auth_instance_toggle", false)) { + if (PreferenceHelper.getBoolean(PreferenceKeys.AUTH_INSTANCE_TOGGLE, false)) { PreferenceHelper.getString( - "selectAuthInstance", + PreferenceKeys.AUTH_INSTANCE, PIPED_API_URL )!! } else { @@ -76,7 +77,7 @@ class MainActivity : AppCompatActivity() { // save whether the data saver mode is enabled Globals.dataSaverModeEnabled = PreferenceHelper.getBoolean( - "data_saver_mode", + PreferenceKeys.DATA_SAVER_MODE, false ) @@ -98,12 +99,12 @@ class MainActivity : AppCompatActivity() { window.navigationBarColor = color // hide the trending page if enabled - val hideTrendingPage = PreferenceHelper.getBoolean("hide_trending_page", false) + val hideTrendingPage = PreferenceHelper.getBoolean(PreferenceKeys.HIDE_TRENDING_PAGE, false) if (hideTrendingPage) binding.bottomNav.menu.findItem(R.id.homeFragment).isVisible = false // save start tab fragment id - startFragmentId = when (PreferenceHelper.getString("default_tab", "home")) { + startFragmentId = when (PreferenceHelper.getString(PreferenceKeys.DEFAULT_TAB, "home")) { "home" -> R.id.homeFragment "subscriptions" -> R.id.subscriptionsFragment "library" -> R.id.libraryFragment @@ -117,7 +118,7 @@ class MainActivity : AppCompatActivity() { navController.navigate(startFragmentId) val labelVisibilityMode = when ( - PreferenceHelper.getString("label_visibility", "always") + PreferenceHelper.getString(PreferenceKeys.LABEL_VISIBILITY, "always") ) { "always" -> NavigationBarView.LABEL_VISIBILITY_LABELED "selected" -> NavigationBarView.LABEL_VISIBILITY_SELECTED diff --git a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt index ff9461dc0..dd81f0e96 100644 --- a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt @@ -8,6 +8,7 @@ import com.github.libretube.PIPED_FRONTEND_URL import com.github.libretube.R import com.github.libretube.YOUTUBE_FRONTEND_URL import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import com.google.android.material.dialog.MaterialAlertDialogBuilder class ShareDialog( @@ -57,7 +58,7 @@ class ShareDialog( // get the frontend url if it's a custom instance private fun getCustomInstanceFrontendUrl(): String { val instancePref = PreferenceHelper.getString( - "selectInstance", + PreferenceKeys.FETCH_INSTANCE, PIPED_FRONTEND_URL ) diff --git a/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt b/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt index f8891801d..a65364b8c 100644 --- a/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt @@ -13,6 +13,7 @@ import com.github.libretube.R import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.databinding.FragmentHomeBinding import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.util.LocaleHelper import com.github.libretube.util.RetrofitInstance import retrofit2.HttpException @@ -41,11 +42,11 @@ class HomeFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val grid = PreferenceHelper.getString( - "grid", + PreferenceKeys.GRID_COLUMNS, resources.getInteger(R.integer.grid_items).toString() )!! - val regionPref = PreferenceHelper.getString("region", "sys")!! + val regionPref = PreferenceHelper.getString(PreferenceKeys.REGION, "sys")!! // get the system default country if auto region selected region = if (regionPref == "sys") { diff --git a/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt b/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt index a458468a6..296922a52 100644 --- a/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt @@ -16,6 +16,7 @@ import com.github.libretube.adapters.PlaylistsAdapter import com.github.libretube.databinding.FragmentLibraryBinding import com.github.libretube.dialogs.CreatePlaylistDialog import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.util.RetrofitInstance import retrofit2.HttpException import java.io.IOException @@ -48,7 +49,7 @@ class LibraryFragment : Fragment() { // hide watch history button of history disabled val watchHistoryEnabled = - PreferenceHelper.getBoolean("watch_history_toggle", true) + PreferenceHelper.getBoolean(PreferenceKeys.WATCH_HISTORY_TOGGLE, true) if (!watchHistoryEnabled) { binding.showWatchHistory.visibility = View.GONE } else { diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index a09a5eb8a..67e56ba2e 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -57,6 +57,7 @@ import com.github.libretube.obj.StreamItem import com.github.libretube.obj.Streams import com.github.libretube.obj.Subscribe import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.services.IS_DOWNLOAD_RUNNING import com.github.libretube.util.BackgroundMode import com.github.libretube.util.ConnectionHelper @@ -232,67 +233,67 @@ class PlayerFragment : Fragment() { // save whether auto rotation is enabled autoRotationEnabled = PreferenceHelper.getBoolean( - "auto_fullscreen", + PreferenceKeys.AUTO_FULLSCREEN, false ) // save whether related streams and autoplay are enabled autoplayEnabled = PreferenceHelper.getBoolean( - "autoplay", + PreferenceKeys.AUTO_PLAY, false ) relatedStreamsEnabled = PreferenceHelper.getBoolean( - "related_streams_toggle", + PreferenceKeys.RELATED_STREAMS, true ) playbackSpeed = PreferenceHelper.getString( - "playback_speed", + PreferenceKeys.PLAYBACK_SPEED, "1F" )!! fullscreenOrientationPref = PreferenceHelper.getString( - "fullscreen_orientation", + PreferenceKeys.FULLSCREEN_ORIENTATION, "ratio" )!! pausePlayerOnScreenOffEnabled = PreferenceHelper.getBoolean( - "pause_screen_off", + PreferenceKeys.PAUSE_ON_SCREEN_OFF, false ) watchPositionsEnabled = PreferenceHelper.getBoolean( - "watch_positions_toggle", + PreferenceKeys.WATCH_POSITION_TOGGLE, true ) watchHistoryEnabled = PreferenceHelper.getBoolean( - "watch_history_toggle", + PreferenceKeys.WATCH_HISTORY_TOGGLE, true ) useSystemCaptionStyle = PreferenceHelper.getBoolean( - "system_caption_style", + PreferenceKeys.SYSTEM_CAPTION_STYLE, true ) seekIncrement = PreferenceHelper.getString( - "seek_increment", + PreferenceKeys.SEEK_INCREMENT, "5" )?.toLong()!! * 1000 videoFormatPreference = PreferenceHelper.getString( - "player_video_format", + PreferenceKeys.PLAYER_VIDEO_FORMAT, "WEBM" )!! defRes = PreferenceHelper.getString( - "default_res", + PreferenceKeys.DEFAULT_RESOLUTION, "" )!! bufferingGoal = PreferenceHelper.getString( - "buffering_goal", + PreferenceKeys.BUFFERING_GOAL, "50" )?.toInt()!! * 1000 } diff --git a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt index 226991177..29d7d2815 100644 --- a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt @@ -26,6 +26,7 @@ import com.github.libretube.adapters.SearchHistoryAdapter import com.github.libretube.adapters.SearchSuggestionsAdapter import com.github.libretube.databinding.FragmentSearchBinding import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.util.RetrofitInstance import com.google.android.material.dialog.MaterialAlertDialogBuilder import retrofit2.HttpException @@ -271,7 +272,7 @@ class SearchFragment : Fragment() { private fun addToHistory(query: String) { val searchHistoryEnabled = - PreferenceHelper.getBoolean("search_history_toggle", true) + PreferenceHelper.getBoolean(PreferenceKeys.SEARCH_HISTORY_TOGGLE, true) if (searchHistoryEnabled) { var historyList = PreferenceHelper.getHistory() diff --git a/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt index 57e28510d..f853b7d3b 100644 --- a/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt @@ -18,6 +18,7 @@ import com.github.libretube.adapters.SubscriptionAdapter import com.github.libretube.adapters.SubscriptionChannelAdapter import com.github.libretube.databinding.FragmentSubscriptionsBinding import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.util.RetrofitInstance import retrofit2.HttpException import java.io.IOException @@ -56,7 +57,7 @@ class SubscriptionsFragment : Fragment() { binding.subProgress.visibility = View.VISIBLE val grid = PreferenceHelper.getString( - "grid", + PreferenceKeys.GRID_COLUMNS, resources.getInteger(R.integer.grid_items).toString() )!! binding.subFeed.layoutManager = GridLayoutManager(view.context, grid.toInt()) diff --git a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt index 12839ff5c..35cc1e7ed 100644 --- a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt @@ -18,14 +18,14 @@ class AdvancedSettings : PreferenceFragmentCompat() { val settingsActivity = activity as SettingsActivity settingsActivity.changeTopBarText(getString(R.string.advanced)) - val dataSaverMode = findPreference("data_saver_mode") + val dataSaverMode = findPreference(PreferenceKeys.DATA_SAVER_MODE) dataSaverMode?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() restartDialog.show(childFragmentManager, "RequireRestartDialog") true } - val resetSettings = findPreference("reset_settings") + val resetSettings = findPreference(PreferenceKeys.RESET_SETTINGS) resetSettings?.setOnPreferenceClickListener { showResetDialog() true diff --git a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt index 5a6dcc5e9..eac4eae1e 100644 --- a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt @@ -18,21 +18,21 @@ class AppearanceSettings : PreferenceFragmentCompat() { val settingsActivity = activity as SettingsActivity settingsActivity.changeTopBarText(getString(R.string.appearance)) - val themeToggle = findPreference("theme_toggle") + val themeToggle = findPreference(PreferenceKeys.THEME_MODE) themeToggle?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() restartDialog.show(childFragmentManager, "RequireRestartDialog") true } - val pureTheme = findPreference("pure_theme") + val pureTheme = findPreference(PreferenceKeys.PURE_THEME) pureTheme?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() restartDialog.show(childFragmentManager, "RequireRestartDialog") true } - val accentColor = findPreference("accent_color") + val accentColor = findPreference(PreferenceKeys.ACCENT_COLOR) updateAccentColorValues(accentColor!!) accentColor.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() @@ -40,27 +40,27 @@ class AppearanceSettings : PreferenceFragmentCompat() { true } - val iconChange = findPreference("icon_change") + val iconChange = findPreference(PreferenceKeys.APP_ICON) iconChange?.setOnPreferenceChangeListener { _, newValue -> ThemeHelper.changeIcon(requireContext(), newValue.toString()) true } - val gridColumns = findPreference("grid") + val gridColumns = findPreference(PreferenceKeys.GRID_COLUMNS) gridColumns?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() restartDialog.show(childFragmentManager, "RequireRestartDialog") true } - val hideTrending = findPreference("hide_trending_page") + val hideTrending = findPreference(PreferenceKeys.HIDE_TRENDING_PAGE) hideTrending?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() restartDialog.show(childFragmentManager, "RequireRestartDialog") true } - val labelVisibilityMode = findPreference("label_visibility") + val labelVisibilityMode = findPreference(PreferenceKeys.LABEL_VISIBILITY) labelVisibilityMode?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() restartDialog.show(childFragmentManager, "RequireRestartDialog") diff --git a/app/src/main/java/com/github/libretube/preferences/HistorySettings.kt b/app/src/main/java/com/github/libretube/preferences/HistorySettings.kt index 471ea3f92..96160e3ac 100644 --- a/app/src/main/java/com/github/libretube/preferences/HistorySettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/HistorySettings.kt @@ -15,21 +15,21 @@ class HistorySettings : PreferenceFragmentCompat() { settingsActivity.changeTopBarText(getString(R.string.history)) // clear search history - val clearHistory = findPreference("clear_history") + val clearHistory = findPreference(PreferenceKeys.CLEAR_SEARCH_HISTORY) clearHistory?.setOnPreferenceClickListener { PreferenceHelper.removePreference("search_history") true } // clear watch history and positions - val clearWatchHistory = findPreference("clear_watch_history") + val clearWatchHistory = findPreference(PreferenceKeys.CLEAR_WATCH_HISTORY) clearWatchHistory?.setOnPreferenceClickListener { PreferenceHelper.removePreference("watch_history") true } // clear watch positions - val clearWatchPositions = findPreference("clear_watch_positions") + val clearWatchPositions = findPreference(PreferenceKeys.CLEAR_WATCH_POSITIONS) clearWatchPositions?.setOnPreferenceClickListener { PreferenceHelper.removePreference("watch_positions") true diff --git a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt index 7ad1bb73f..968442743 100644 --- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt @@ -115,14 +115,14 @@ class InstanceSettings : PreferenceFragmentCompat() { val settingsActivity = activity as SettingsActivity settingsActivity.changeTopBarText(getString(R.string.instance)) - val instance = findPreference("selectInstance") + val instance = findPreference(PreferenceKeys.FETCH_INSTANCE) // fetchInstance() initCustomInstances(instance!!) instance.setOnPreferenceChangeListener { _, newValue -> val restartDialog = RequireRestartDialog() restartDialog.show(childFragmentManager, "RequireRestartDialog") RetrofitInstance.url = newValue.toString() - if (!PreferenceHelper.getBoolean("auth_instance_toggle", false)) { + if (!PreferenceHelper.getBoolean(PreferenceKeys.AUTH_INSTANCE_TOGGLE, false)) { RetrofitInstance.authUrl = newValue.toString() logout() } @@ -130,10 +130,10 @@ class InstanceSettings : PreferenceFragmentCompat() { true } - val authInstance = findPreference("selectAuthInstance") + val authInstance = findPreference(PreferenceKeys.AUTH_INSTANCE) initCustomInstances(authInstance!!) // hide auth instance if option deselected - if (!PreferenceHelper.getBoolean("auth_instance_toggle", false)) { + if (!PreferenceHelper.getBoolean(PreferenceKeys.AUTH_INSTANCE_TOGGLE, false)) { authInstance.isVisible = false } authInstance.setOnPreferenceChangeListener { _, newValue -> @@ -146,7 +146,7 @@ class InstanceSettings : PreferenceFragmentCompat() { true } - val authInstanceToggle = findPreference("auth_instance_toggle") + val authInstanceToggle = findPreference(PreferenceKeys.AUTH_INSTANCE_TOGGLE) authInstanceToggle?.setOnPreferenceChangeListener { _, newValue -> authInstance.isVisible = newValue == true logout() @@ -158,14 +158,14 @@ class InstanceSettings : PreferenceFragmentCompat() { true } - val customInstance = findPreference("customInstance") + val customInstance = findPreference(PreferenceKeys.CUSTOM_INSTANCE) customInstance?.setOnPreferenceClickListener { val newFragment = CustomInstanceDialog() newFragment.show(childFragmentManager, "CustomInstanceDialog") true } - val clearCustomInstances = findPreference("clearCustomInstances") + val clearCustomInstances = findPreference(PreferenceKeys.CLEAR_CUSTOM_INSTANCES) clearCustomInstances?.setOnPreferenceClickListener { PreferenceHelper.removePreference("customInstances") val intent = Intent(context, SettingsActivity::class.java) @@ -173,7 +173,7 @@ class InstanceSettings : PreferenceFragmentCompat() { true } - val login = findPreference("login_register") + val login = findPreference(PreferenceKeys.LOGIN_REGISTER) val token = PreferenceHelper.getToken() if (token != "") login?.setTitle(R.string.logout) login?.setOnPreferenceClickListener { @@ -188,7 +188,7 @@ class InstanceSettings : PreferenceFragmentCompat() { true } - val deleteAccount = findPreference("delete_account") + val deleteAccount = findPreference(PreferenceKeys.DELETE_ACCOUNT) deleteAccount?.setOnPreferenceClickListener { val token = PreferenceHelper.getToken() if (token != "") { @@ -200,7 +200,7 @@ class InstanceSettings : PreferenceFragmentCompat() { true } - val importFromYt = findPreference("import_from_yt") + val importFromYt = findPreference(PreferenceKeys.IMPORT_SUBS) importFromYt?.setOnPreferenceClickListener { importSubscriptions() true diff --git a/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt b/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt index 6d07a5c54..5d90b3aec 100644 --- a/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt @@ -16,12 +16,12 @@ class PlayerSettings : PreferenceFragmentCompat() { val settingsActivity = activity as SettingsActivity settingsActivity.changeTopBarText(getString(R.string.audio_video)) - val playerOrientation = findPreference("fullscreen_orientation") - val autoRotateToFullscreen = findPreference("auto_fullscreen") + val playerOrientation = findPreference(PreferenceKeys.FULLSCREEN_ORIENTATION) + val autoRotateToFullscreen = findPreference(PreferenceKeys.AUTO_FULLSCREEN) // only show the player orientation option if auto fullscreen is disabled playerOrientation?.isEnabled != PreferenceHelper.getBoolean( - "auto_fullscreen", + PreferenceKeys.AUTO_FULLSCREEN, false ) diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt new file mode 100644 index 000000000..781cc1d3d --- /dev/null +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt @@ -0,0 +1,70 @@ +package com.github.libretube.preferences + +/** + * keys for the shared preferences + */ +object PreferenceKeys { + /** + * General + */ + const val LANGUAGE = "language" + const val REGION = "region" + + /** + * Appearance + */ + const val THEME_MODE = "theme_toggle" + const val PURE_THEME = "pure_theme" + const val ACCENT_COLOR = "accent_color" + const val GRID_COLUMNS = "grid" + const val DEFAULT_TAB = "default_tab" + const val LABEL_VISIBILITY = "label_visibility" + const val HIDE_TRENDING_PAGE = "hide_trending_page" + const val APP_ICON = "icon_change" + + /** + * Instance + */ + const val FETCH_INSTANCE = "selectInstance" + const val AUTH_INSTANCE = "selectAuthInstance" + const val AUTH_INSTANCE_TOGGLE = "auth_instance_toggle" + const val CUSTOM_INSTANCE = "customInstance" + const val CLEAR_CUSTOM_INSTANCES = "clearCustomInstances" + const val LOGIN_REGISTER = "login_register" + const val DELETE_ACCOUNT = "delete_account" + const val IMPORT_SUBS = "import_from_yt" + + /** + * Player + */ + const val AUTO_FULLSCREEN = "auto_fullscreen" + const val AUTO_PLAY = "autoplay" + const val RELATED_STREAMS = "related_streams_toggle" + const val PLAYBACK_SPEED = "playback_speed" + const val FULLSCREEN_ORIENTATION = "fullscreen_orientation" + const val PAUSE_ON_SCREEN_OFF = "pause_screen_off" + const val WATCH_POSITION_TOGGLE = "watch_position_toggle" + const val WATCH_HISTORY_TOGGLE = "watch_history_toggle" + const val SEARCH_HISTORY_TOGGLE = "search_history_toggle" + const val SYSTEM_CAPTION_STYLE = "system_caption_style" + const val SEEK_INCREMENT = "seek_increment" + const val PLAYER_VIDEO_FORMAT = "player_video_format" + const val DEFAULT_RESOLUTION = "default_res" + const val BUFFERING_GOAL = "buffering_goal" + + /** + * Download + */ + const val DOWNLOAD_VIDEO_FORMAT = "video_format" + const val DOWNLOAD_LOCATION = "download_location" + const val DOWNLOAD_FOLDER = "download_folder" + + /** + * Advanced + */ + const val DATA_SAVER_MODE = "data_saver_mode" + const val RESET_SETTINGS = "reset_settings" + const val CLEAR_SEARCH_HISTORY = "clear_search_history" + const val CLEAR_WATCH_HISTORY = "clear_watch_history" + const val CLEAR_WATCH_POSITIONS = "clear_watch_positions" +} diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index 589c86438..f01a9a903 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -21,6 +21,7 @@ import com.arthenica.ffmpegkit.FFmpegKit import com.github.libretube.R import com.github.libretube.obj.DownloadType import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import java.io.File var IS_DOWNLOAD_RUNNING = false @@ -52,7 +53,7 @@ class DownloadService : Service() { videoUrl = intent.getStringExtra("videoUrl")!! audioUrl = intent.getStringExtra("audioUrl")!! duration = intent.getIntExtra("duration", 1) - extension = PreferenceHelper.getString("video_format", ".mp4")!! + extension = PreferenceHelper.getString(PreferenceKeys.DOWNLOAD_VIDEO_FORMAT, ".mp4")!! downloadType = if (audioUrl != "" && videoUrl != "") DownloadType.MUX else if (audioUrl != "") DownloadType.AUDIO else if (videoUrl != "") DownloadType.VIDEO @@ -86,8 +87,8 @@ class DownloadService : Service() { Log.e(TAG, "Directory already have") } - val downloadLocationPref = PreferenceHelper.getString("download_location", "") - val folderName = PreferenceHelper.getString("download_folder", "LibreTube") + val downloadLocationPref = PreferenceHelper.getString(PreferenceKeys.DOWNLOAD_LOCATION, "") + val folderName = PreferenceHelper.getString(PreferenceKeys.DOWNLOAD_FOLDER, "LibreTube") val location = when (downloadLocationPref) { "downloads" -> Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS) diff --git a/app/src/main/java/com/github/libretube/util/BackgroundMode.kt b/app/src/main/java/com/github/libretube/util/BackgroundMode.kt index 9f6ebaa70..ae440f1a1 100644 --- a/app/src/main/java/com/github/libretube/util/BackgroundMode.kt +++ b/app/src/main/java/com/github/libretube/util/BackgroundMode.kt @@ -5,6 +5,7 @@ import android.content.Context import android.support.v4.media.session.MediaSessionCompat import com.github.libretube.obj.Streams import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import com.google.android.exoplayer2.C import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.MediaItem @@ -71,7 +72,7 @@ class BackgroundMode { */ player!!.addListener(object : Player.Listener { override fun onPlaybackStateChanged(@Player.State state: Int) { - val autoplay = PreferenceHelper.getBoolean("autoplay", false) + val autoplay = PreferenceHelper.getBoolean(PreferenceKeys.AUTO_PLAY, false) if (state == Player.STATE_ENDED) { if (autoplay) playNextVideo(c) } diff --git a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt index 1e0cb8ef9..a5ce2e973 100644 --- a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt +++ b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt @@ -4,12 +4,13 @@ import android.content.Context import android.os.Build import android.telephony.TelephonyManager import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import java.util.* object LocaleHelper { fun updateLanguage(context: Context) { - val languageName = PreferenceHelper.getString("language", "sys") + val languageName = PreferenceHelper.getString(PreferenceKeys.LANGUAGE, "sys") if (languageName == "sys") updateLocaleConf(context, Locale.getDefault()) else if ("$languageName".length < 3) { val locale = Locale(languageName.toString()) diff --git a/app/src/main/java/com/github/libretube/util/ThemeHelper.kt b/app/src/main/java/com/github/libretube/util/ThemeHelper.kt index bf6a8f1ed..6efb2591b 100644 --- a/app/src/main/java/com/github/libretube/util/ThemeHelper.kt +++ b/app/src/main/java/com/github/libretube/util/ThemeHelper.kt @@ -12,13 +12,14 @@ import androidx.appcompat.app.AppCompatDelegate import androidx.core.text.HtmlCompat import com.github.libretube.R import com.github.libretube.preferences.PreferenceHelper +import com.github.libretube.preferences.PreferenceKeys import com.google.android.material.color.DynamicColors object ThemeHelper { fun updateTheme(activity: AppCompatActivity) { - val themeMode = PreferenceHelper.getString("theme_toggle", "A")!! - val pureThemeEnabled = PreferenceHelper.getBoolean("pure_theme", false) + val themeMode = PreferenceHelper.getString(PreferenceKeys.THEME_MODE, "A")!! + val pureThemeEnabled = PreferenceHelper.getBoolean(PreferenceKeys.PURE_THEME, false) updateAccentColor(activity, pureThemeEnabled) updateThemeMode(themeMode) @@ -30,7 +31,7 @@ object ThemeHelper { ) { val theme = when ( PreferenceHelper.getString( - "accent_color", + PreferenceKeys.ACCENT_COLOR, "purple" ) ) { diff --git a/app/src/main/res/xml/history_settings.xml b/app/src/main/res/xml/history_settings.xml index 538b84e31..cc95a9ca4 100644 --- a/app/src/main/res/xml/history_settings.xml +++ b/app/src/main/res/xml/history_settings.xml @@ -13,7 +13,7 @@