Source settings
This commit is contained in:
@@ -18,9 +18,6 @@
|
||||
|
||||
package xyz.quaver.pupil.sources
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.core.content.ContextCompat
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
@@ -120,6 +117,7 @@ typealias AnySource = Source<*, SearchSuggestion>
|
||||
abstract class Source<Query_SortMode: Enum<Query_SortMode>, Suggestion: SearchSuggestion> {
|
||||
abstract val name: String
|
||||
abstract val iconResID: Int
|
||||
abstract val preferenceID: Int
|
||||
abstract val availableSortMode: Array<Query_SortMode>
|
||||
|
||||
abstract suspend fun search(query: String, range: IntRange, sortMode: Enum<*>) : Pair<Channel<ItemInfo>, Int>
|
||||
@@ -138,15 +136,19 @@ abstract class Source<Query_SortMode: Enum<Query_SortMode>, Suggestion: SearchSu
|
||||
|
||||
typealias SourceEntry = Pair<String, AnySource>
|
||||
typealias SourceEntries = Set<SourceEntry>
|
||||
typealias PreferenceID = Pair<String, Int>
|
||||
typealias PreferenceIDs = Set<PreferenceID>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val sourceModule = DI.Module(name = "source") {
|
||||
bind() from setBinding<SourceEntry>()
|
||||
bindSet<SourceEntry>()
|
||||
bindSet<PreferenceID>()
|
||||
|
||||
listOf(
|
||||
Hitomi()
|
||||
).forEach { source ->
|
||||
bind<SourceEntry>().inSet() with multiton { _: Unit -> source.name to (source as AnySource) }
|
||||
inSet { multiton { _: Unit -> source.name to (source as AnySource) } }
|
||||
inSet { singleton { source.name to source.preferenceID } }
|
||||
}
|
||||
|
||||
bind<History>() with factory { source: String -> History(di, source) }
|
||||
bind { factory { source: String -> History(di, source) } }
|
||||
}
|
||||
@@ -26,6 +26,7 @@ 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
|
||||
import xyz.quaver.pupil.util.SavedSourceSet
|
||||
import xyz.quaver.pupil.util.source
|
||||
|
||||
@@ -38,6 +39,8 @@ class History(override val di: DI, source: String) : Source<DefaultSortMode, Sea
|
||||
get() = source.name
|
||||
override val iconResID: Int
|
||||
get() = source.iconResID
|
||||
override val preferenceID: Int
|
||||
get() = source.preferenceID
|
||||
override val availableSortMode: Array<DefaultSortMode> = DefaultSortMode.values()
|
||||
|
||||
override suspend fun search(query: String, range: IntRange, sortMode: Enum<*>): Pair<Channel<ItemInfo>, Int> {
|
||||
|
||||
@@ -29,6 +29,7 @@ import xyz.quaver.floatingsearchview.suggestions.model.SearchSuggestion
|
||||
import xyz.quaver.hitomi.*
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.sources.ItemInfo.ExtraType
|
||||
import xyz.quaver.pupil.util.Preferences
|
||||
import xyz.quaver.pupil.util.translations
|
||||
import xyz.quaver.pupil.util.wordCapitalize
|
||||
import kotlin.math.max
|
||||
@@ -56,6 +57,7 @@ class Hitomi : Source<Hitomi.SortMode, Hitomi.TagSuggestion>() {
|
||||
|
||||
override val name: String = "hitomi.la"
|
||||
override val iconResID: Int = R.drawable.hitomi
|
||||
override val preferenceID: Int = R.xml.hitomi_preferences
|
||||
override val availableSortMode: Array<SortMode> = SortMode.values()
|
||||
|
||||
var cachedQuery: String? = null
|
||||
@@ -67,7 +69,7 @@ class Hitomi : Source<Hitomi.SortMode, Hitomi.TagSuggestion>() {
|
||||
cachedQuery = null
|
||||
cache.clear()
|
||||
yield()
|
||||
doSearch(query, sortMode == SortMode.POPULAR).let {
|
||||
doSearch("$query ${Preferences["hitomi.default_query", ""]}", sortMode == SortMode.POPULAR).let {
|
||||
yield()
|
||||
cache.addAll(it)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user