diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupHolder.kt index 8bf0a6197..70cf8a981 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupHolder.kt @@ -3,18 +3,14 @@ package eu.kanade.tachiyomi.ui.extension import android.annotation.SuppressLint import android.view.View import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder -import kotlinx.android.synthetic.main.extension_card_header.* +import kotlinx.android.synthetic.main.extension_card_header.title class ExtensionGroupHolder(view: View, adapter: FlexibleAdapter<*>) : BaseFlexibleViewHolder(view, adapter) { @SuppressLint("SetTextI18n") fun bind(item: ExtensionGroupItem) { - title.text = when { - item.installed -> itemView.context.getString(R.string.ext_installed) - else -> itemView.context.getString(R.string.ext_available) - } + " (" + item.size + ")" + title.text = item.name + " (" + item.size + ")" } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupItem.kt index 2c45f894e..c7f565645 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupItem.kt @@ -6,11 +6,12 @@ import eu.davidea.flexibleadapter.items.AbstractHeaderItem import eu.kanade.tachiyomi.R /** - * Item that contains the language header. + * Item that contains the group header. * - * @param code The lang code. + * @param name The header name. + * @param size The number of items in the group. */ -data class ExtensionGroupItem(val installed: Boolean, val size: Int) : AbstractHeaderItem() { +data class ExtensionGroupItem(val name: String, val size: Int) : AbstractHeaderItem() { /** * Returns the layout resource of this item. @@ -38,13 +39,13 @@ data class ExtensionGroupItem(val installed: Boolean, val size: Int) : AbstractH override fun equals(other: Any?): Boolean { if (this === other) return true if (other is ExtensionGroupItem) { - return installed == other.installed + return name == other.name } return false } override fun hashCode(): Int { - return installed.hashCode() + return name.hashCode() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt index 95faaece2..04ff5f3ce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt @@ -1,10 +1,13 @@ package eu.kanade.tachiyomi.ui.extension +import android.app.Application import android.os.Bundle +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.InstallStep import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter +import eu.kanade.tachiyomi.util.LocaleHelper import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers @@ -49,6 +52,8 @@ open class ExtensionPresenter( @Synchronized private fun toItems(tuple: ExtensionTuple): List { + val context = Injekt.get() + val (installed, untrusted, available) = tuple val items = mutableListOf() @@ -62,7 +67,7 @@ open class ExtensionPresenter( .sortedBy { it.pkgName } if (installedSorted.isNotEmpty() || untrustedSorted.isNotEmpty()) { - val header = ExtensionGroupItem(true, installedSorted.size + untrustedSorted.size) + val header = ExtensionGroupItem(context.getString(R.string.ext_installed), installedSorted.size + untrustedSorted.size) items += installedSorted.map { extension -> ExtensionItem(extension, header, currentDownloads[extension.pkgName]) } @@ -71,10 +76,17 @@ open class ExtensionPresenter( } } if (availableSorted.isNotEmpty()) { - val header = ExtensionGroupItem(false, availableSorted.size) - items += availableSorted.map { extension -> - ExtensionItem(extension, header, currentDownloads[extension.pkgName]) - } + val availableGroupedByLang = availableSorted + .groupBy { LocaleHelper.getDisplayName(it.lang, context) } + .toSortedMap() + + availableGroupedByLang + .forEach { + val header = ExtensionGroupItem(it.key, it.value.size) + items += it.value.map { extension -> + ExtensionItem(extension, header, currentDownloads[extension.pkgName]) + } + } } this.extensions = items