From 0bf14fd31c9b1d3274be23acabf4d34f18864f90 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 31 May 2020 15:05:24 -0400 Subject: [PATCH] Sort sources/extensions filter languages --- .../ui/browse/extension/ExtensionController.kt | 1 - .../extension/ExtensionDetailsController.kt | 3 ++- .../extension/ExtensionFilterController.kt | 16 +++++++--------- .../ui/setting/SettingsSourcesController.kt | 3 +-- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt index 667fa08c82..ad22837098 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt @@ -91,7 +91,6 @@ open class ExtensionController : ExtensionFilterController().withFadeTransaction() ) } - else -> return super.onOptionsItemSelected(item) } return super.onOptionsItemSelected(item) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt index b66c03cdbe..952d583f24 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt @@ -45,11 +45,12 @@ class ExtensionDetailsController(bundle: Bundle? = null) : val extension = presenter.extension ?: return val context = view.context + extension.getApplicationIcon(context)?.let { binding.extensionIcon.setImageDrawable(it) } binding.extensionTitle.text = extension.name 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.extensionPkg.text = extension.pkgName - extension.getApplicationIcon(context)?.let { binding.extensionIcon.setImageDrawable(it) } + binding.extensionUninstallButton.clicks() .onEach { presenter.uninstallExtension() } .launchIn(scope) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt index 5675b6d40b..a74208fc19 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt @@ -21,11 +21,9 @@ class ExtensionFilterController : SettingsController() { val availableLangs = Injekt.get().availableExtensions.groupBy { it.lang - }.keys.minus("all").partition { - it in activeLangs - }.let { - it.first + it.second - } + }.keys + .minus("all") + .sortedWith(compareBy({ it !in activeLangs }, { LocaleHelper.getSourceDisplayName(it, context) })) availableLangs.forEach { switchPreference { @@ -38,11 +36,11 @@ class ExtensionFilterController : SettingsController() { val checked = newValue as Boolean val currentActiveLangs = preferences.enabledLanguages().get() - if (checked) { - preferences.enabledLanguages().set(currentActiveLangs + it) + preferences.enabledLanguages().set(if (checked) { + currentActiveLangs + it } else { - preferences.enabledLanguages().set(currentActiveLangs - it) - } + currentActiveLangs - it + }) true } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt index 8a44bd0aec..33d14c1e83 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt @@ -30,8 +30,7 @@ class SettingsSourcesController : SettingsController() { val sourcesByLang = onlineSources.groupByTo(TreeMap(), { it.lang }) // Order first by active languages, then inactive ones - val orderedLangs = sourcesByLang.keys.filter { it in activeLangsCodes } + - sourcesByLang.keys.filterNot { it in activeLangsCodes } + val orderedLangs = sourcesByLang.keys.sortedWith(compareBy({ it !in activeLangsCodes }, { LocaleHelper.getSourceDisplayName(it, context) })) orderedLangs.forEach { lang -> val sources = sourcesByLang[lang].orEmpty().sortedBy { it.name }