Sort sources/extensions filter languages

This commit is contained in:
arkon 2020-05-31 15:05:24 -04:00
parent 7dd9a0211b
commit 0bf14fd31c
4 changed files with 10 additions and 13 deletions

View File

@ -91,7 +91,6 @@ open class ExtensionController :
ExtensionFilterController().withFadeTransaction() ExtensionFilterController().withFadeTransaction()
) )
} }
else -> return super.onOptionsItemSelected(item)
} }
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }

View File

@ -45,11 +45,12 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
val extension = presenter.extension ?: return val extension = presenter.extension ?: return
val context = view.context val context = view.context
extension.getApplicationIcon(context)?.let { binding.extensionIcon.setImageDrawable(it) }
binding.extensionTitle.text = extension.name binding.extensionTitle.text = extension.name
binding.extensionVersion.text = context.getString(R.string.ext_version_info, extension.versionName) binding.extensionVersion.text = context.getString(R.string.ext_version_info, extension.versionName)
binding.extensionLang.text = context.getString(R.string.ext_language_info, LocaleHelper.getSourceDisplayName(extension.lang, context)) binding.extensionLang.text = context.getString(R.string.ext_language_info, LocaleHelper.getSourceDisplayName(extension.lang, context))
binding.extensionPkg.text = extension.pkgName binding.extensionPkg.text = extension.pkgName
extension.getApplicationIcon(context)?.let { binding.extensionIcon.setImageDrawable(it) }
binding.extensionUninstallButton.clicks() binding.extensionUninstallButton.clicks()
.onEach { presenter.uninstallExtension() } .onEach { presenter.uninstallExtension() }
.launchIn(scope) .launchIn(scope)

View File

@ -21,11 +21,9 @@ class ExtensionFilterController : SettingsController() {
val availableLangs = val availableLangs =
Injekt.get<ExtensionManager>().availableExtensions.groupBy { Injekt.get<ExtensionManager>().availableExtensions.groupBy {
it.lang it.lang
}.keys.minus("all").partition { }.keys
it in activeLangs .minus("all")
}.let { .sortedWith(compareBy({ it !in activeLangs }, { LocaleHelper.getSourceDisplayName(it, context) }))
it.first + it.second
}
availableLangs.forEach { availableLangs.forEach {
switchPreference { switchPreference {
@ -38,11 +36,11 @@ class ExtensionFilterController : SettingsController() {
val checked = newValue as Boolean val checked = newValue as Boolean
val currentActiveLangs = preferences.enabledLanguages().get() val currentActiveLangs = preferences.enabledLanguages().get()
if (checked) { preferences.enabledLanguages().set(if (checked) {
preferences.enabledLanguages().set(currentActiveLangs + it) currentActiveLangs + it
} else { } else {
preferences.enabledLanguages().set(currentActiveLangs - it) currentActiveLangs - it
} })
true true
} }
} }

View File

@ -30,8 +30,7 @@ class SettingsSourcesController : SettingsController() {
val sourcesByLang = onlineSources.groupByTo(TreeMap(), { it.lang }) val sourcesByLang = onlineSources.groupByTo(TreeMap(), { it.lang })
// Order first by active languages, then inactive ones // Order first by active languages, then inactive ones
val orderedLangs = sourcesByLang.keys.filter { it in activeLangsCodes } + val orderedLangs = sourcesByLang.keys.sortedWith(compareBy({ it !in activeLangsCodes }, { LocaleHelper.getSourceDisplayName(it, context) }))
sourcesByLang.keys.filterNot { it in activeLangsCodes }
orderedLangs.forEach { lang -> orderedLangs.forEach { lang ->
val sources = sourcesByLang[lang].orEmpty().sortedBy { it.name } val sources = sourcesByLang[lang].orEmpty().sortedBy { it.name }