fix crash

This commit is contained in:
Bnyro 2022-08-23 09:15:28 +02:00
parent c9007e3456
commit 29afd06478
9 changed files with 19 additions and 19 deletions

View File

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

View File

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

View File

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

View File

@ -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<Preference>(PreferenceKeys.CLEAR_SEARCH_HISTORY)

View File

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

View File

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

View File

@ -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<SwitchPreferenceCompat>(PreferenceKeys.NOTIFICATION_ENABLED)

View File

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

View File

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