fix: Edge case bug of setting preferred media without any provider that has mainPage (#231)

This commit is contained in:
Jace 2021-11-09 22:40:12 +08:00 committed by GitHub
parent f38ffc8ce9
commit 97641d5459
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -347,8 +347,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
settingsManager.edit()
.putInt(getString(R.string.preferred_media_settings), prefValues[it])
.apply()
val apiRandom = AppUtils.filterProviderByPreferredMedia(apis, prefValues[it]).random()
context?.setKey(HOMEPAGE_API, apiRandom.name)
val apilist = AppUtils.filterProviderByPreferredMedia(apis, prefValues[it])
val apiRandom = if (apilist?.size > 0) { apilist.random().name } else { "" }
context?.setKey(HOMEPAGE_API, apiRandom)
context?.initRequestClient()
}
return@setOnPreferenceClickListener true