mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 12:47:26 +01:00
Add Better Extension Search (#6359)
Add support to searching with source name, id and baseUrl for a extension's sources.
This commit is contained in:
parent
2ed01af723
commit
9e83130bd8
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.extension.api
|
||||
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.extension.model.AvailableExtensionSources
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
import eu.kanade.tachiyomi.extension.model.LoadResult
|
||||
import eu.kanade.tachiyomi.extension.util.ExtensionLoader
|
||||
@ -80,12 +81,23 @@ internal class ExtensionGithubApi {
|
||||
versionCode = it.code,
|
||||
lang = it.lang,
|
||||
isNsfw = it.nsfw == 1,
|
||||
sources = it.sources.toExtensionSources(),
|
||||
apkName = it.apk,
|
||||
iconUrl = "${REPO_URL_PREFIX}icon/${it.apk.replace(".apk", ".png")}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<ExtensionSourceJsonObject>.toExtensionSources(): List<AvailableExtensionSources> {
|
||||
return this.map {
|
||||
AvailableExtensionSources(
|
||||
name = it.name,
|
||||
id = it.id,
|
||||
baseUrl = it.baseUrl
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun getApkUrl(extension: Extension.Available): String {
|
||||
return "${REPO_URL_PREFIX}apk/${extension.apkName}"
|
||||
}
|
||||
@ -98,8 +110,17 @@ private data class ExtensionJsonObject(
|
||||
val name: String,
|
||||
val pkg: String,
|
||||
val apk: String,
|
||||
val version: String,
|
||||
val code: Long,
|
||||
val lang: String,
|
||||
val code: Long,
|
||||
val version: String,
|
||||
val nsfw: Int,
|
||||
val sources: List<ExtensionSourceJsonObject>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
private data class ExtensionSourceJsonObject(
|
||||
val name: String,
|
||||
val id: Long,
|
||||
val baseUrl: String
|
||||
|
||||
)
|
||||
|
@ -32,6 +32,7 @@ sealed class Extension {
|
||||
override val versionCode: Long,
|
||||
override val lang: String,
|
||||
override val isNsfw: Boolean,
|
||||
val sources: List<AvailableExtensionSources>,
|
||||
val apkName: String,
|
||||
val iconUrl: String
|
||||
) : Extension()
|
||||
@ -46,3 +47,9 @@ sealed class Extension {
|
||||
override val isNsfw: Boolean = false
|
||||
) : Extension()
|
||||
}
|
||||
|
||||
data class AvailableExtensionSources(
|
||||
val name: String,
|
||||
val id: Long,
|
||||
val baseUrl: String
|
||||
)
|
||||
|
@ -15,6 +15,7 @@ import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.ExtensionControllerBinding
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.browse.BrowseController
|
||||
@ -56,7 +57,8 @@ open class ExtensionController :
|
||||
return ExtensionPresenter()
|
||||
}
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater) = ExtensionControllerBinding.inflate(inflater)
|
||||
override fun createBinding(inflater: LayoutInflater) =
|
||||
ExtensionControllerBinding.inflate(inflater)
|
||||
|
||||
override fun onViewCreated(view: View) {
|
||||
super.onViewCreated(view)
|
||||
@ -189,11 +191,27 @@ open class ExtensionController :
|
||||
|
||||
private fun updateExtensionsList() {
|
||||
if (query.isNotBlank()) {
|
||||
val extensionNames = query.split(",")
|
||||
val queries = query.split(",")
|
||||
adapter?.updateDataSet(
|
||||
extensions.filter {
|
||||
extensionNames.any { queriedName ->
|
||||
it.extension.name.contains(queriedName, ignoreCase = true)
|
||||
queries.any { query ->
|
||||
when (it.extension) {
|
||||
is Extension.Available -> {
|
||||
it.extension.sources.any {
|
||||
it.name.contains(query, ignoreCase = true) ||
|
||||
it.baseUrl.contains(query, ignoreCase = true) ||
|
||||
it.id == query.toLongOrNull()
|
||||
} || it.extension.name.contains(query, ignoreCase = true)
|
||||
}
|
||||
is Extension.Installed -> {
|
||||
it.extension.sources.any {
|
||||
it.name.contains(query, ignoreCase = true) ||
|
||||
it.id == query.toLongOrNull() ||
|
||||
if (it is HttpSource) { it.baseUrl.contains(query, ignoreCase = true) } else false
|
||||
} || it.extension.name.contains(query, ignoreCase = true)
|
||||
}
|
||||
is Extension.Untrusted -> it.extension.name.contains(query, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user