Group available extensions by language (#2210)
This commit is contained in:
parent
d3cb10a74e
commit
86e53e08de
@ -3,18 +3,14 @@ package eu.kanade.tachiyomi.ui.extension
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
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<*>) :
|
class ExtensionGroupHolder(view: View, adapter: FlexibleAdapter<*>) :
|
||||||
BaseFlexibleViewHolder(view, adapter) {
|
BaseFlexibleViewHolder(view, adapter) {
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
fun bind(item: ExtensionGroupItem) {
|
fun bind(item: ExtensionGroupItem) {
|
||||||
title.text = when {
|
title.text = item.name + " (" + item.size + ")"
|
||||||
item.installed -> itemView.context.getString(R.string.ext_installed)
|
|
||||||
else -> itemView.context.getString(R.string.ext_available)
|
|
||||||
} + " (" + item.size + ")"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,12 @@ import eu.davidea.flexibleadapter.items.AbstractHeaderItem
|
|||||||
import eu.kanade.tachiyomi.R
|
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<ExtensionGroupHolder>() {
|
data class ExtensionGroupItem(val name: String, val size: Int) : AbstractHeaderItem<ExtensionGroupHolder>() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the layout resource of this item.
|
* 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 {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other is ExtensionGroupItem) {
|
if (other is ExtensionGroupItem) {
|
||||||
return installed == other.installed
|
return name == other.name
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return installed.hashCode()
|
return name.hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package eu.kanade.tachiyomi.ui.extension
|
package eu.kanade.tachiyomi.ui.extension
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
import eu.kanade.tachiyomi.extension.model.InstallStep
|
import eu.kanade.tachiyomi.extension.model.InstallStep
|
||||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||||
|
import eu.kanade.tachiyomi.util.LocaleHelper
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
@ -49,6 +52,8 @@ open class ExtensionPresenter(
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun toItems(tuple: ExtensionTuple): List<ExtensionItem> {
|
private fun toItems(tuple: ExtensionTuple): List<ExtensionItem> {
|
||||||
|
val context = Injekt.get<Application>()
|
||||||
|
|
||||||
val (installed, untrusted, available) = tuple
|
val (installed, untrusted, available) = tuple
|
||||||
|
|
||||||
val items = mutableListOf<ExtensionItem>()
|
val items = mutableListOf<ExtensionItem>()
|
||||||
@ -62,7 +67,7 @@ open class ExtensionPresenter(
|
|||||||
.sortedBy { it.pkgName }
|
.sortedBy { it.pkgName }
|
||||||
|
|
||||||
if (installedSorted.isNotEmpty() || untrustedSorted.isNotEmpty()) {
|
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 ->
|
items += installedSorted.map { extension ->
|
||||||
ExtensionItem(extension, header, currentDownloads[extension.pkgName])
|
ExtensionItem(extension, header, currentDownloads[extension.pkgName])
|
||||||
}
|
}
|
||||||
@ -71,10 +76,17 @@ open class ExtensionPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (availableSorted.isNotEmpty()) {
|
if (availableSorted.isNotEmpty()) {
|
||||||
val header = ExtensionGroupItem(false, availableSorted.size)
|
val availableGroupedByLang = availableSorted
|
||||||
items += availableSorted.map { extension ->
|
.groupBy { LocaleHelper.getDisplayName(it.lang, context) }
|
||||||
ExtensionItem(extension, header, currentDownloads[extension.pkgName])
|
.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
|
this.extensions = items
|
||||||
|
Loading…
Reference in New Issue
Block a user