From 97641d54592ebc38fe424291353dc91519b4dcc9 Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Tue, 9 Nov 2021 22:40:12 +0800 Subject: [PATCH] fix: Edge case bug of setting preferred media without any provider that has mainPage (#231) --- .../lagradost/cloudstream3/ui/settings/SettingsFragment.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index 1dfafcd9..cb563ba5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -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