From 29afd06478b3fc13950937d7c05432f2dbb68762 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 23 Aug 2022 09:15:28 +0200 Subject: [PATCH] fix crash --- .../com/github/libretube/preferences/AdvancedSettings.kt | 4 ++-- .../com/github/libretube/preferences/AppearanceSettings.kt | 4 ++-- .../com/github/libretube/preferences/GeneralSettings.kt | 4 ++-- .../com/github/libretube/preferences/HistorySettings.kt | 4 ++-- .../com/github/libretube/preferences/InstanceSettings.kt | 4 ++-- .../java/com/github/libretube/preferences/MainSettings.kt | 6 +++--- .../github/libretube/preferences/NotificationSettings.kt | 4 ++-- .../java/com/github/libretube/preferences/PlayerSettings.kt | 4 ++-- .../github/libretube/preferences/SponsorBlockSettings.kt | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) 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 83a58554f..764de788c 100644 --- a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt @@ -39,8 +39,8 @@ class AdvancedSettings : MaterialPreferenceFragment() { 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 settingsActivity = activity as? SettingsActivity + settingsActivity?.changeTopBarText(getString(R.string.advanced)) val maxImageCache = findPreference(PreferenceKeys.MAX_IMAGE_CACHE) maxImageCache?.setOnPreferenceChangeListener { _, _ -> 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 0d6c021ba..4eac15ab5 100644 --- a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt @@ -19,8 +19,8 @@ class AppearanceSettings : MaterialPreferenceFragment() { 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 settingsActivity = activity as? SettingsActivity + settingsActivity?.changeTopBarText(getString(R.string.appearance)) val themeToggle = findPreference(PreferenceKeys.THEME_MODE) themeToggle?.setOnPreferenceChangeListener { _, _ -> diff --git a/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt b/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt index 7559dd38b..3e8fba413 100644 --- a/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt @@ -13,8 +13,8 @@ class GeneralSettings : MaterialPreferenceFragment() { 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 settingsActivity = activity as? SettingsActivity + settingsActivity?.changeTopBarText(getString(R.string.general)) val language = findPreference("language") language?.setOnPreferenceChangeListener { _, _ -> 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 640bbf880..d871fd24a 100644 --- a/app/src/main/java/com/github/libretube/preferences/HistorySettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/HistorySettings.kt @@ -13,8 +13,8 @@ class HistorySettings : MaterialPreferenceFragment() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.history_settings, rootKey) - val settingsActivity = activity as SettingsActivity - settingsActivity.changeTopBarText(getString(R.string.history)) + val settingsActivity = activity as? SettingsActivity + settingsActivity?.changeTopBarText(getString(R.string.history)) // clear search history val clearHistory = findPreference(PreferenceKeys.CLEAR_SEARCH_HISTORY) 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 ddf4cf02e..893452912 100644 --- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt @@ -51,8 +51,8 @@ class InstanceSettings : MaterialPreferenceFragment() { 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 settingsActivity = activity as? SettingsActivity + settingsActivity?.changeTopBarText(getString(R.string.instance)) val instance = findPreference(PreferenceKeys.FETCH_INSTANCE) // fetchInstance() diff --git a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt index 572ad7b01..4f464bfdb 100644 --- a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt @@ -87,14 +87,14 @@ class MainSettings : MaterialPreferenceFragment() { update?.setOnPreferenceClickListener { CoroutineScope(Dispatchers.IO).launch { if (!NetworkHelper.isNetworkAvailable(requireContext())) { - (activity as SettingsActivity).binding.root.getStyledSnackBar(R.string.unknown_error).show() + (activity as? SettingsActivity)?.binding?.root?.getStyledSnackBar(R.string.unknown_error)?.show() return@launch } // check for update val updateInfo = UpdateChecker.getLatestReleaseInfo() if (updateInfo?.name == null) { // request failed - (activity as SettingsActivity).binding.root.getStyledSnackBar(R.string.unknown_error).show() + (activity as? SettingsActivity)?.binding?.root?.getStyledSnackBar(R.string.unknown_error)?.show() } else if (BuildConfig.VERSION_NAME != updateInfo.name) { // show the UpdateAvailableDialog if there's an update available val updateAvailableDialog = UpdateDialog(updateInfo) @@ -104,7 +104,7 @@ class MainSettings : MaterialPreferenceFragment() { ) } else { // otherwise show the no update available snackBar - (activity as SettingsActivity).binding.root.getStyledSnackBar(R.string.app_uptodate).show() + (activity as? SettingsActivity)?.binding?.root?.getStyledSnackBar(R.string.app_uptodate)?.show() } } true diff --git a/app/src/main/java/com/github/libretube/preferences/NotificationSettings.kt b/app/src/main/java/com/github/libretube/preferences/NotificationSettings.kt index 5dae981a4..bd1c6fe99 100644 --- a/app/src/main/java/com/github/libretube/preferences/NotificationSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/NotificationSettings.kt @@ -14,8 +14,8 @@ class NotificationSettings : MaterialPreferenceFragment() { 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 settingsActivity = activity as? SettingsActivity + settingsActivity?.changeTopBarText(getString(R.string.notifications)) val notificationsEnabled = findPreference(PreferenceKeys.NOTIFICATION_ENABLED) 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 7f9099b28..735b6f634 100644 --- a/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt @@ -14,8 +14,8 @@ class PlayerSettings : MaterialPreferenceFragment() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.player_settings, rootKey) - val settingsActivity = activity as SettingsActivity - settingsActivity.changeTopBarText(getString(R.string.audio_video)) + val settingsActivity = activity as? SettingsActivity + settingsActivity?.changeTopBarText(getString(R.string.audio_video)) val playerOrientation = findPreference(PreferenceKeys.FULLSCREEN_ORIENTATION) diff --git a/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt b/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt index d8baa1623..511880d9f 100644 --- a/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/SponsorBlockSettings.kt @@ -10,7 +10,7 @@ class SponsorBlockSettings : MaterialPreferenceFragment() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.sponsorblock_settings, rootKey) - val settingsActivity = activity as SettingsActivity - settingsActivity.changeTopBarText(getString(R.string.sponsorblock)) + val settingsActivity = activity as? SettingsActivity + settingsActivity?.changeTopBarText(getString(R.string.sponsorblock)) } }