Fix crashes

This commit is contained in:
Koitharu
2023-07-19 15:18:30 +03:00
parent 1d78c64350
commit 08acf2d882
3 changed files with 15 additions and 6 deletions

View File

@@ -62,12 +62,20 @@ class UserDataSettingsFragment : BasePreferenceFragment(R.string.data_and_privac
findPreference<Preference>(AppSettings.KEY_HTTP_CACHE_CLEAR)?.bindBytesSizeSummary(viewModel.httpCacheSize)
findPreference<Preference>(AppSettings.KEY_SEARCH_HISTORY_CLEAR)?.let { pref ->
viewModel.searchHistoryCount.observe(viewLifecycleOwner) {
pref.summary = pref.context.resources.getQuantityString(R.plurals.items, it, it)
pref.summary = if (it < 0) {
view.context.getString(R.string.loading_)
} else {
pref.context.resources.getQuantityString(R.plurals.items, it, it)
}
}
}
findPreference<Preference>(AppSettings.KEY_UPDATES_FEED_CLEAR)?.let { pref ->
viewModel.feedItemsCount.observe(viewLifecycleOwner) {
pref.summary = pref.context.resources.getQuantityString(R.plurals.items, it, it)
pref.summary = if (it < 0) {
view.context.getString(R.string.loading_)
} else {
pref.context.resources.getQuantityString(R.plurals.items, it, it)
}
}
}
viewModel.loadingKeys.observe(viewLifecycleOwner) { keys ->

View File

@@ -13,8 +13,9 @@ class MultiSummaryProvider(@StringRes private val emptySummaryId: Int) :
return preference.context.getString(emptySummaryId)
} else {
values.joinToString(", ") {
preference.entries[preference.findIndexOfValue(it)]
preference.entries.getOrNull(preference.findIndexOfValue(it))
?: preference.context.getString(androidx.preference.R.string.not_set)
}
}
}
}
}