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)) } } diff --git a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt index f3932a304..899576dbe 100644 --- a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt +++ b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt @@ -125,7 +125,7 @@ class BackgroundMode : Service() { val position = intent.getLongExtra("position", 0L) // initialize the playlist autoPlay Helper - if (playlistId != null) autoPlayHelper = AutoPlayHelper(playlistId!!) + autoPlayHelper = AutoPlayHelper(playlistId) // play the audio in the background playAudio(videoId, position)