Reimplemented sort
[WIP] ImHentai
This commit is contained in:
@@ -107,25 +107,21 @@ data class ItemInfo(
|
||||
}
|
||||
}
|
||||
|
||||
enum class DefaultSortMode : SortModeInterface {
|
||||
DEFAULT
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
class DefaultSearchSuggestion(override val body: String) : SearchSuggestion
|
||||
|
||||
interface SortModeInterface {
|
||||
val ordinal: Int
|
||||
val name: String
|
||||
val name: Int
|
||||
}
|
||||
|
||||
abstract class Source {
|
||||
abstract val name: String
|
||||
abstract val iconResID: Int
|
||||
abstract val preferenceID: Int
|
||||
abstract val availableSortMode: List<SortModeInterface>
|
||||
abstract val availableSortMode: List<String>
|
||||
|
||||
abstract suspend fun search(query: String, range: IntRange, sortMode: SortModeInterface) : Pair<Channel<ItemInfo>, Int>
|
||||
abstract suspend fun search(query: String, range: IntRange, sortMode: Int) : Pair<Channel<ItemInfo>, Int>
|
||||
abstract suspend fun suggestion(query: String) : List<SearchSuggestion>
|
||||
abstract suspend fun images(itemID: String) : List<String>
|
||||
abstract suspend fun info(itemID: String) : ItemInfo
|
||||
@@ -146,11 +142,13 @@ val sourceModule = DI.Module(name = "source") {
|
||||
bindSet<SourceEntry>()
|
||||
bindSet<SourcePreferenceID>()
|
||||
|
||||
listOf<Source>(
|
||||
Hitomi()
|
||||
).forEach { source ->
|
||||
inSet { multiton { _: Unit -> source.name to source } }
|
||||
inSet { singleton { source.name to source.preferenceID } }
|
||||
onReady {
|
||||
listOf<Source>(
|
||||
Hitomi(instance())
|
||||
).forEach { source ->
|
||||
inSet { multiton { _: Unit -> source.name to source } }
|
||||
inSet { singleton { source.name to source.preferenceID } }
|
||||
}
|
||||
}
|
||||
|
||||
bind { factory { source: String -> History(di, source) } }
|
||||
|
||||
@@ -41,11 +41,11 @@ class Downloads(override val di: DI) : Source(), DIAware {
|
||||
get() = R.drawable.ic_download
|
||||
override val preferenceID: Int
|
||||
get() = R.xml.download_preferences
|
||||
override val availableSortMode: List<DefaultSortMode> = DefaultSortMode.values().toList()
|
||||
override val availableSortMode: List<String> = emptyList()
|
||||
|
||||
private val downloadManager: DownloadManager by instance()
|
||||
|
||||
override suspend fun search(query: String, range: IntRange, sortMode: SortModeInterface): Pair<Channel<ItemInfo>, Int> {
|
||||
override suspend fun search(query: String, range: IntRange, sortMode: Int): Pair<Channel<ItemInfo>, Int> {
|
||||
val downloads = downloadManager.downloads.toList()
|
||||
|
||||
val channel = Channel<ItemInfo>()
|
||||
|
||||
@@ -40,9 +40,9 @@ class History(override val di: DI, source: String) : Source(), DIAware {
|
||||
get() = source.iconResID
|
||||
override val preferenceID: Int
|
||||
get() = source.preferenceID
|
||||
override val availableSortMode: List<DefaultSortMode> = DefaultSortMode.values().toList()
|
||||
override val availableSortMode: List<String> = emptyList()
|
||||
|
||||
override suspend fun search(query: String, range: IntRange, sortMode: SortModeInterface): Pair<Channel<ItemInfo>, Int> {
|
||||
override suspend fun search(query: String, range: IntRange, sortMode: Int): Pair<Channel<ItemInfo>, Int> {
|
||||
val channel = Channel<ItemInfo>()
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package xyz.quaver.pupil.sources
|
||||
|
||||
import android.app.Application
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.TextView
|
||||
import io.ktor.http.*
|
||||
@@ -35,12 +36,7 @@ import xyz.quaver.pupil.util.wordCapitalize
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
class Hitomi : Source() {
|
||||
|
||||
enum class SortMode : SortModeInterface {
|
||||
NEWEST,
|
||||
POPULAR
|
||||
}
|
||||
class Hitomi(app: Application) : Source() {
|
||||
|
||||
@Parcelize
|
||||
data class TagSuggestion(val s: String, val t: Int, val u: String, val n: String) : SearchSuggestion {
|
||||
@@ -60,18 +56,18 @@ class Hitomi : Source() {
|
||||
override val name: String = "hitomi.la"
|
||||
override val iconResID: Int = R.drawable.hitomi
|
||||
override val preferenceID: Int = R.xml.hitomi_preferences
|
||||
override val availableSortMode: List<SortModeInterface> = SortMode.values().toList()
|
||||
override val availableSortMode: List<String> = app.resources.getStringArray(R.array.hitomi_sort_mode).toList()
|
||||
|
||||
var cachedQuery: String? = null
|
||||
var cachedSortMode: SortMode? = null
|
||||
var cachedSortMode: Int = -1
|
||||
val cache = mutableListOf<Int>()
|
||||
|
||||
override suspend fun search(query: String, range: IntRange, sortMode: SortModeInterface): Pair<Channel<ItemInfo>, Int> {
|
||||
override suspend fun search(query: String, range: IntRange, sortMode: Int): Pair<Channel<ItemInfo>, Int> {
|
||||
if (cachedQuery != query || cachedSortMode != sortMode || cache.isEmpty()) {
|
||||
cachedQuery = null
|
||||
cache.clear()
|
||||
yield()
|
||||
doSearch("$query ${Preferences["hitomi.default_query", ""]}", sortMode == SortMode.POPULAR).let {
|
||||
doSearch("$query ${Preferences["hitomi.default_query", ""]}", sortMode == 1).let {
|
||||
yield()
|
||||
cache.addAll(it)
|
||||
}
|
||||
|
||||
88
app/src/main/java/xyz/quaver/pupil/sources/ImHentai.kt
Normal file
88
app/src/main/java/xyz/quaver/pupil/sources/ImHentai.kt
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Pupil, Hitomi.la viewer for Android
|
||||
* Copyright (C) 2021 tom5079
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package xyz.quaver.pupil.sources
|
||||
|
||||
import android.app.Application
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.features.*
|
||||
import io.ktor.client.features.get
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Element
|
||||
import org.kodein.di.DI
|
||||
import org.kodein.di.DIAware
|
||||
import org.kodein.di.instance
|
||||
import xyz.quaver.floatingsearchview.suggestions.model.SearchSuggestion
|
||||
import xyz.quaver.pupil.R
|
||||
|
||||
class ImHentai(override val di: DI) : Source(), DIAware {
|
||||
|
||||
private val app: Application by instance()
|
||||
private val client: HttpClient by instance()
|
||||
|
||||
override val name: String
|
||||
get() = ImHentai.name
|
||||
override val iconResID: Int
|
||||
get() = R.drawable.ic_imhentai
|
||||
override val preferenceID: Int
|
||||
get() = R.xml.imhentai_preferences
|
||||
override val availableSortMode = app.resources.getStringArray(R.array.imhentai_sort_mode).toList()
|
||||
|
||||
override suspend fun search(query: String, range: IntRange, sortMode: Int): Pair<Channel<ItemInfo>, Int> = withContext(Dispatchers.IO) {
|
||||
val channel = Channel<ItemInfo>()
|
||||
|
||||
val doc = Jsoup.connect("https://imhentai.xxx/search/?key=$query").get()
|
||||
|
||||
val count = countRegex.find(doc.getElementsByClass("heading2").text())?.groupValues?.get(1)?.toIntOrNull() ?: 0
|
||||
|
||||
launch {
|
||||
doc.getElementsByClass("thumb")
|
||||
}
|
||||
|
||||
return@withContext Pair(channel, count)
|
||||
}
|
||||
|
||||
override suspend fun suggestion(query: String): List<SearchSuggestion> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun images(itemID: String): List<String> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun info(itemID: String): ItemInfo {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val name = "imhentai"
|
||||
private val countRegex = Regex("""\(\d+\) results found.""")
|
||||
private val idRegex = Regex("""/gallery/(\d+)/""")
|
||||
|
||||
private fun transform(item: Element) {
|
||||
val caption = item.select(".caption a")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user