mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05: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
3 changed files with 52 additions and 6 deletions
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.extension.api
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
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.Extension
|
||||||
import eu.kanade.tachiyomi.extension.model.LoadResult
|
import eu.kanade.tachiyomi.extension.model.LoadResult
|
||||||
import eu.kanade.tachiyomi.extension.util.ExtensionLoader
|
import eu.kanade.tachiyomi.extension.util.ExtensionLoader
|
||||||
|
@ -80,12 +81,23 @@ internal class ExtensionGithubApi {
|
||||||
versionCode = it.code,
|
versionCode = it.code,
|
||||||
lang = it.lang,
|
lang = it.lang,
|
||||||
isNsfw = it.nsfw == 1,
|
isNsfw = it.nsfw == 1,
|
||||||
|
sources = it.sources.toExtensionSources(),
|
||||||
apkName = it.apk,
|
apkName = it.apk,
|
||||||
iconUrl = "${REPO_URL_PREFIX}icon/${it.apk.replace(".apk", ".png")}"
|
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 {
|
fun getApkUrl(extension: Extension.Available): String {
|
||||||
return "${REPO_URL_PREFIX}apk/${extension.apkName}"
|
return "${REPO_URL_PREFIX}apk/${extension.apkName}"
|
||||||
}
|
}
|
||||||
|
@ -98,8 +110,17 @@ private data class ExtensionJsonObject(
|
||||||
val name: String,
|
val name: String,
|
||||||
val pkg: String,
|
val pkg: String,
|
||||||
val apk: String,
|
val apk: String,
|
||||||
val version: String,
|
|
||||||
val code: Long,
|
|
||||||
val lang: String,
|
val lang: String,
|
||||||
|
val code: Long,
|
||||||
|
val version: String,
|
||||||
val nsfw: Int,
|
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 versionCode: Long,
|
||||||
override val lang: String,
|
override val lang: String,
|
||||||
override val isNsfw: Boolean,
|
override val isNsfw: Boolean,
|
||||||
|
val sources: List<AvailableExtensionSources>,
|
||||||
val apkName: String,
|
val apkName: String,
|
||||||
val iconUrl: String
|
val iconUrl: String
|
||||||
) : Extension()
|
) : Extension()
|
||||||
|
@ -46,3 +47,9 @@ sealed class Extension {
|
||||||
override val isNsfw: Boolean = false
|
override val isNsfw: Boolean = false
|
||||||
) : Extension()
|
) : 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.R
|
||||||
import eu.kanade.tachiyomi.databinding.ExtensionControllerBinding
|
import eu.kanade.tachiyomi.databinding.ExtensionControllerBinding
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
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.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.ui.browse.BrowseController
|
import eu.kanade.tachiyomi.ui.browse.BrowseController
|
||||||
|
@ -56,7 +57,8 @@ open class ExtensionController :
|
||||||
return ExtensionPresenter()
|
return ExtensionPresenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createBinding(inflater: LayoutInflater) = ExtensionControllerBinding.inflate(inflater)
|
override fun createBinding(inflater: LayoutInflater) =
|
||||||
|
ExtensionControllerBinding.inflate(inflater)
|
||||||
|
|
||||||
override fun onViewCreated(view: View) {
|
override fun onViewCreated(view: View) {
|
||||||
super.onViewCreated(view)
|
super.onViewCreated(view)
|
||||||
|
@ -189,11 +191,27 @@ open class ExtensionController :
|
||||||
|
|
||||||
private fun updateExtensionsList() {
|
private fun updateExtensionsList() {
|
||||||
if (query.isNotBlank()) {
|
if (query.isNotBlank()) {
|
||||||
val extensionNames = query.split(",")
|
val queries = query.split(",")
|
||||||
adapter?.updateDataSet(
|
adapter?.updateDataSet(
|
||||||
extensions.filter {
|
extensions.filter {
|
||||||
extensionNames.any { queriedName ->
|
queries.any { query ->
|
||||||
it.extension.name.contains(queriedName, ignoreCase = true)
|
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 a new issue