This commit is contained in:
tom5079
2021-02-11 19:24:40 +09:00
parent c7b3ae7ed1
commit 5a61fcf6ee
34 changed files with 656 additions and 329 deletions

View File

@@ -29,10 +29,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import org.kodein.di.DI
import org.kodein.di.bind
import org.kodein.di.contexted
import org.kodein.di.instance
import org.kodein.di.*
import xyz.quaver.floatingsearchview.databinding.SearchSuggestionItemBinding
import xyz.quaver.floatingsearchview.suggestions.model.SearchSuggestion
import xyz.quaver.pupil.R
@@ -139,29 +136,18 @@ abstract class Source<Query_SortMode: Enum<Query_SortMode>, Suggestion: SearchSu
}
}
@Deprecated("")
val sources = mutableMapOf<String, AnySource>()
val sourceIcons = mutableMapOf<String, Drawable?>()
typealias SourceEntry = Pair<String, AnySource>
typealias SourceEntries = Set<SourceEntry>
@Suppress("UNCHECKED_CAST")
val sourceModule = DI.Module(name = "source") {
listOf(
Hitomi(),
Hiyobi()
).forEach {
bind<AnySource>(tag = it.name) with instance (it as AnySource)
}
}
bind() from setBinding<SourceEntry>()
@Deprecated("")
@Suppress("UNCHECKED_CAST")
fun initSources(context: Context) {
// Add Default Sources
listOf(
Hitomi(),
Hiyobi()
).forEach {
sources[it.name] = it as AnySource
sourceIcons[it.name] = ContextCompat.getDrawable(context, it.iconResID)
).forEach { source ->
bind<SourceEntry>().inSet() with multiton { _: Unit -> source.name to (source as AnySource) }
}
bind<History>() with factory { source: String -> History(di, source) }
}

View File

@@ -0,0 +1,72 @@
/*
* 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.util.Log
import com.orhanobut.logger.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import org.kodein.di.DI
import org.kodein.di.DIAware
import org.kodein.di.android.di
import org.kodein.di.instance
import xyz.quaver.floatingsearchview.suggestions.model.SearchSuggestion
import xyz.quaver.pupil.util.SavedSourceSet
import xyz.quaver.pupil.util.source
class History(override val di: DI, source: String) : Source<DefaultSortMode, SearchSuggestion>(), DIAware {
private val source: AnySource by source(source)
private val histories: SavedSourceSet by instance(tag = "histories")
override val name: String
get() = source.name
override val iconResID: Int
get() = source.iconResID
override val availableSortMode: Array<DefaultSortMode> = DefaultSortMode.values()
override suspend fun search(query: String, range: IntRange, sortMode: Enum<*>): Pair<Channel<ItemInfo>, Int> {
val channel = Channel<ItemInfo>()
CoroutineScope(Dispatchers.IO).launch {
Logger.d(histories.map)
histories.map[source.name]?.forEach {
channel.send(source.info(it))
}
}
return Pair(channel, histories.map.size)
}
override suspend fun suggestion(query: String): List<SearchSuggestion> {
return source.suggestion(query)
}
override suspend fun images(itemID: String): List<String> {
return source.images(itemID)
}
override suspend fun info(itemID: String): ItemInfo {
return source.info(itemID)
}
}

View File

@@ -73,7 +73,7 @@ class Hiyobi : Source<DefaultSortMode, DefaultSearchSuggestion>() {
}
override suspend fun images(itemID: String): List<String> {
return createImgList(itemID, getGalleryInfo(itemID), false).map {
return createImgList(itemID, getGalleryInfo(itemID), true).map {
it.path
}
}