Cleanup MangaSource fields
This commit is contained in:
@@ -59,6 +59,7 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
|||||||
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||||
freeCompilerArgs += [
|
freeCompilerArgs += [
|
||||||
'-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
'-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
||||||
|
'-Xopt-in=kotlinx.coroutines.FlowPreview',
|
||||||
'-Xopt-in=kotlin.contracts.ExperimentalContracts',
|
'-Xopt-in=kotlin.contracts.ExperimentalContracts',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.koin.core.component.get
|
|||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.core.model.MangaPage
|
import org.koitharu.kotatsu.core.model.MangaPage
|
||||||
import org.koitharu.kotatsu.core.network.CommonHeaders
|
import org.koitharu.kotatsu.core.network.CommonHeaders
|
||||||
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.utils.CacheUtils
|
import org.koitharu.kotatsu.utils.CacheUtils
|
||||||
import org.koitharu.kotatsu.utils.ext.await
|
import org.koitharu.kotatsu.utils.ext.await
|
||||||
import org.koitharu.kotatsu.utils.ext.medianOrNull
|
import org.koitharu.kotatsu.utils.ext.medianOrNull
|
||||||
@@ -28,7 +29,7 @@ object MangaUtils : KoinComponent {
|
|||||||
suspend fun determineMangaIsWebtoon(pages: List<MangaPage>): Boolean? {
|
suspend fun determineMangaIsWebtoon(pages: List<MangaPage>): Boolean? {
|
||||||
try {
|
try {
|
||||||
val page = pages.medianOrNull() ?: return null
|
val page = pages.medianOrNull() ?: return null
|
||||||
val url = page.source.repository.getPageUrl(page)
|
val url = MangaRepository(page.source).getPageUrl(page)
|
||||||
val uri = Uri.parse(url)
|
val uri = Uri.parse(url)
|
||||||
val size = if (uri.scheme == "cbz") {
|
val size = if (uri.scheme == "cbz") {
|
||||||
val zip = ZipFile(uri.schemeSpecificPart)
|
val zip = ZipFile(uri.schemeSpecificPart)
|
||||||
|
|||||||
@@ -2,51 +2,38 @@ package org.koitharu.kotatsu.core.model
|
|||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
import org.koin.core.context.GlobalContext
|
|
||||||
import org.koin.core.error.NoBeanDefFoundException
|
|
||||||
import org.koin.core.qualifier.named
|
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
|
||||||
import org.koitharu.kotatsu.core.parser.site.*
|
|
||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
@Suppress("SpellCheckingInspection")
|
||||||
@Parcelize
|
@Parcelize
|
||||||
enum class MangaSource(
|
enum class MangaSource(
|
||||||
val title: String,
|
val title: String,
|
||||||
val locale: String?,
|
val locale: String?,
|
||||||
val cls: Class<out MangaRepository>,
|
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
LOCAL("Local", null, LocalMangaRepository::class.java),
|
LOCAL("Local", null),
|
||||||
READMANGA_RU("ReadManga", "ru", ReadmangaRepository::class.java),
|
READMANGA_RU("ReadManga", "ru"),
|
||||||
MINTMANGA("MintManga", "ru", MintMangaRepository::class.java),
|
MINTMANGA("MintManga", "ru"),
|
||||||
SELFMANGA("SelfManga", "ru", SelfMangaRepository::class.java),
|
SELFMANGA("SelfManga", "ru"),
|
||||||
MANGACHAN("Манга-тян", "ru", MangaChanRepository::class.java),
|
MANGACHAN("Манга-тян", "ru"),
|
||||||
DESUME("Desu.me", "ru", DesuMeRepository::class.java),
|
DESUME("Desu.me", "ru"),
|
||||||
HENCHAN("Хентай-тян", "ru", HenChanRepository::class.java),
|
HENCHAN("Хентай-тян", "ru"),
|
||||||
YAOICHAN("Яой-тян", "ru", YaoiChanRepository::class.java),
|
YAOICHAN("Яой-тян", "ru"),
|
||||||
MANGATOWN("MangaTown", "en", MangaTownRepository::class.java),
|
MANGATOWN("MangaTown", "en"),
|
||||||
MANGALIB("MangaLib", "ru", MangaLibRepository::class.java),
|
MANGALIB("MangaLib", "ru"),
|
||||||
|
|
||||||
// NUDEMOON("Nude-Moon", "ru", NudeMoonRepository::class.java),
|
// NUDEMOON("Nude-Moon", "ru", NudeMoonRepository::class.java),
|
||||||
MANGAREAD("MangaRead", "en", MangareadRepository::class.java),
|
MANGAREAD("MangaRead", "en"),
|
||||||
REMANGA("Remanga", "ru", RemangaRepository::class.java),
|
REMANGA("Remanga", "ru"),
|
||||||
HENTAILIB("HentaiLib", "ru", HentaiLibRepository::class.java),
|
HENTAILIB("HentaiLib", "ru"),
|
||||||
ANIBEL("Anibel", "be", AnibelRepository::class.java),
|
ANIBEL("Anibel", "be"),
|
||||||
NINEMANGA_EN("NineManga English", "en", NineMangaRepository.English::class.java),
|
NINEMANGA_EN("NineManga English", "en"),
|
||||||
NINEMANGA_ES("NineManga Español", "es", NineMangaRepository.Spanish::class.java),
|
NINEMANGA_ES("NineManga Español", "es"),
|
||||||
NINEMANGA_RU("NineManga Русский", "ru", NineMangaRepository.Russian::class.java),
|
NINEMANGA_RU("NineManga Русский", "ru"),
|
||||||
NINEMANGA_DE("NineManga Deutsch", "de", NineMangaRepository.Deutsch::class.java),
|
NINEMANGA_DE("NineManga Deutsch", "de"),
|
||||||
NINEMANGA_IT("NineManga Italiano", "it", NineMangaRepository.Italiano::class.java),
|
NINEMANGA_IT("NineManga Italiano", "it"),
|
||||||
NINEMANGA_BR("NineManga Brasil", "pt", NineMangaRepository.Brazil::class.java),
|
NINEMANGA_BR("NineManga Brasil", "pt"),
|
||||||
NINEMANGA_FR("NineManga Français", "fr", NineMangaRepository.Francais::class.java),
|
NINEMANGA_FR("NineManga Français", "fr"),
|
||||||
EXHENTAI("ExHentai", null, ExHentaiRepository::class.java),
|
EXHENTAI("ExHentai", null),
|
||||||
MANGAOWL("MangaOwl", "en", MangaOwlRepository::class.java),
|
MANGAOWL("MangaOwl", "en"),
|
||||||
MANGADEX("MangaDex", null, MangaDexRepository::class.java),
|
MANGADEX("MangaDex", null),
|
||||||
;
|
;
|
||||||
|
|
||||||
@get:Throws(NoBeanDefFoundException::class)
|
|
||||||
@Deprecated("", ReplaceWith("MangaRepository(this)",
|
|
||||||
"org.koitharu.kotatsu.core.parser.MangaRepository"))
|
|
||||||
val repository: MangaRepository
|
|
||||||
get() = GlobalContext.get().get(named(this))
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import org.koin.core.qualifier.named
|
|||||||
import org.koin.dsl.bind
|
import org.koin.dsl.bind
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
|
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.utils.CacheUtils
|
import org.koitharu.kotatsu.utils.CacheUtils
|
||||||
import org.koitharu.kotatsu.utils.DownloadManagerHelper
|
import org.koitharu.kotatsu.utils.DownloadManagerHelper
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@@ -30,4 +31,5 @@ val networkModule
|
|||||||
}.build()
|
}.build()
|
||||||
}
|
}
|
||||||
factory { DownloadManagerHelper(get(), get()) }
|
factory { DownloadManagerHelper(get(), get()) }
|
||||||
|
single { MangaLoaderContext(get(), get()) }
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,8 @@ import org.koitharu.kotatsu.core.model.*
|
|||||||
|
|
||||||
interface MangaRepository {
|
interface MangaRepository {
|
||||||
|
|
||||||
|
val source: MangaSource
|
||||||
|
|
||||||
val sortOrders: Set<SortOrder>
|
val sortOrders: Set<SortOrder>
|
||||||
|
|
||||||
suspend fun getList2(
|
suspend fun getList2(
|
||||||
|
|||||||
@@ -2,15 +2,12 @@ package org.koitharu.kotatsu.core.parser
|
|||||||
|
|
||||||
import org.koin.core.qualifier.named
|
import org.koin.core.qualifier.named
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.core.parser.site.*
|
import org.koitharu.kotatsu.core.parser.site.*
|
||||||
|
|
||||||
val parserModule
|
val parserModule
|
||||||
get() = module {
|
get() = module {
|
||||||
|
|
||||||
single { MangaLoaderContext(get(), get()) }
|
|
||||||
|
|
||||||
factory<MangaRepository>(named(MangaSource.READMANGA_RU)) { ReadmangaRepository(get()) }
|
factory<MangaRepository>(named(MangaSource.READMANGA_RU)) { ReadmangaRepository(get()) }
|
||||||
factory<MangaRepository>(named(MangaSource.MINTMANGA)) { MintMangaRepository(get()) }
|
factory<MangaRepository>(named(MangaSource.MINTMANGA)) { MintMangaRepository(get()) }
|
||||||
factory<MangaRepository>(named(MangaSource.SELFMANGA)) { SelfMangaRepository(get()) }
|
factory<MangaRepository>(named(MangaSource.SELFMANGA)) { SelfMangaRepository(get()) }
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.koitharu.kotatsu.core.parser
|
|||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
import org.koitharu.kotatsu.core.exceptions.ParseException
|
||||||
import org.koitharu.kotatsu.core.model.MangaPage
|
import org.koitharu.kotatsu.core.model.MangaPage
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaTag
|
import org.koitharu.kotatsu.core.model.MangaTag
|
||||||
import org.koitharu.kotatsu.core.model.SortOrder
|
import org.koitharu.kotatsu.core.model.SortOrder
|
||||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||||
@@ -12,8 +11,6 @@ abstract class RemoteMangaRepository(
|
|||||||
protected val loaderContext: MangaLoaderContext
|
protected val loaderContext: MangaLoaderContext
|
||||||
) : MangaRepository {
|
) : MangaRepository {
|
||||||
|
|
||||||
protected abstract val source: MangaSource
|
|
||||||
|
|
||||||
protected abstract val defaultDomain: String
|
protected abstract val defaultDomain: String
|
||||||
|
|
||||||
private val conf by lazy {
|
private val conf by lazy {
|
||||||
@@ -29,6 +26,8 @@ abstract class RemoteMangaRepository(
|
|||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> = emptySet()
|
override suspend fun getTags(): Set<MangaTag> = emptySet()
|
||||||
|
|
||||||
|
fun getFaviconUrl() = "https://${getDomain()}/favicon.ico"
|
||||||
|
|
||||||
open fun onCreatePreferences(map: MutableMap<String, Any>) {
|
open fun onCreatePreferences(map: MutableMap<String, Any>) {
|
||||||
map[SourceSettings.KEY_DOMAIN] = defaultDomain
|
map[SourceSettings.KEY_DOMAIN] = defaultDomain
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class DetailsViewModel(
|
|||||||
var manga = mangaDataRepository.resolveIntent(intent)
|
var manga = mangaDataRepository.resolveIntent(intent)
|
||||||
?: throw MangaNotFoundException("Cannot find manga")
|
?: throw MangaNotFoundException("Cannot find manga")
|
||||||
mangaData.value = manga
|
mangaData.value = manga
|
||||||
manga = manga.source.repository.getDetails(manga)
|
manga = MangaRepository(manga.source).getDetails(manga)
|
||||||
// find default branch
|
// find default branch
|
||||||
val hist = historyRepository.getOne(manga)
|
val hist = historyRepository.getOne(manga)
|
||||||
selectedBranch.value = if (hist != null) {
|
selectedBranch.value = if (hist != null) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.util.zip.ZipFile
|
|||||||
|
|
||||||
class LocalMangaRepository(private val context: Context) : MangaRepository {
|
class LocalMangaRepository(private val context: Context) : MangaRepository {
|
||||||
|
|
||||||
|
override val source = MangaSource.LOCAL
|
||||||
private val filenameFilter = CbzFilter()
|
private val filenameFilter = CbzFilter()
|
||||||
|
|
||||||
override suspend fun getList2(
|
override suspend fun getList2(
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class PageLoader(
|
|||||||
|
|
||||||
private fun loadAsync(page: MangaPage): Deferred<File> {
|
private fun loadAsync(page: MangaPage): Deferred<File> {
|
||||||
var repo = repository
|
var repo = repository
|
||||||
if (repo?.javaClass != page.source.cls) {
|
if (repo?.source != page.source) {
|
||||||
repo = mangaRepositoryOf(page.source)
|
repo = mangaRepositoryOf(page.source)
|
||||||
repository = repo
|
repository = repo
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.koitharu.kotatsu.reader.ui
|
package org.koitharu.kotatsu.reader.ui
|
||||||
|
|
||||||
import android.content.ContentResolver
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.util.LongSparseArray
|
import android.util.LongSparseArray
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
@@ -77,7 +76,7 @@ class ReaderViewModel(
|
|||||||
var manga = dataRepository.resolveIntent(intent)
|
var manga = dataRepository.resolveIntent(intent)
|
||||||
?: throw MangaNotFoundException("Cannot find manga")
|
?: throw MangaNotFoundException("Cannot find manga")
|
||||||
mangaData.value = manga
|
mangaData.value = manga
|
||||||
val repo = manga.source.repository
|
val repo = MangaRepository(manga.source)
|
||||||
manga = repo.getDetails(manga)
|
manga = repo.getDetails(manga)
|
||||||
manga.chapters?.forEach {
|
manga.chapters?.forEach {
|
||||||
chapters.put(it.id, it)
|
chapters.put(it.id, it)
|
||||||
@@ -206,7 +205,7 @@ class ReaderViewModel(
|
|||||||
private suspend fun loadChapter(chapterId: Long): List<ReaderPage> {
|
private suspend fun loadChapter(chapterId: Long): List<ReaderPage> {
|
||||||
val manga = checkNotNull(mangaData.value) { "Manga is null" }
|
val manga = checkNotNull(mangaData.value) { "Manga is null" }
|
||||||
val chapter = checkNotNull(chapters[chapterId]) { "Requested chapter not found" }
|
val chapter = checkNotNull(chapters[chapterId]) { "Requested chapter not found" }
|
||||||
val repo = manga.source.repository
|
val repo = MangaRepository(manga.source)
|
||||||
return repo.getPages(chapter).mapIndexed { index, page ->
|
return repo.getPages(chapter).mapIndexed { index, page ->
|
||||||
ReaderPage.from(page, index, chapterId)
|
ReaderPage.from(page, index, chapterId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.koitharu.kotatsu.core.db.MangaDatabase
|
|||||||
import org.koitharu.kotatsu.core.model.Manga
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.core.model.SortOrder
|
import org.koitharu.kotatsu.core.model.SortOrder
|
||||||
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider
|
import org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider
|
||||||
import org.koitharu.kotatsu.utils.ext.levenshteinDistance
|
import org.koitharu.kotatsu.utils.ext.levenshteinDistance
|
||||||
@@ -29,7 +30,7 @@ class MangaSearchRepository(
|
|||||||
MangaProviderFactory.getSources(settings, includeHidden = false).asFlow()
|
MangaProviderFactory.getSources(settings, includeHidden = false).asFlow()
|
||||||
.flatMapMerge(concurrency) { source ->
|
.flatMapMerge(concurrency) { source ->
|
||||||
runCatching {
|
runCatching {
|
||||||
source.repository.getList2(
|
MangaRepository(source).getList2(
|
||||||
offset = 0,
|
offset = 0,
|
||||||
query = query,
|
query = query,
|
||||||
sortOrder = SortOrder.POPULARITY
|
sortOrder = SortOrder.POPULARITY
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class RemoteMangaRepositoryTest(private val source: MangaSource) : KoinTest {
|
|||||||
@get:Rule
|
@get:Rule
|
||||||
val koinTestRule = KoinTestRule.create {
|
val koinTestRule = KoinTestRule.create {
|
||||||
printLogger(Level.ERROR)
|
printLogger(Level.ERROR)
|
||||||
modules(repositoryTestModule)
|
modules(repositoryTestModule, parserModule)
|
||||||
}
|
}
|
||||||
|
|
||||||
@get:Rule
|
@get:Rule
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.core.network.TestCookieJar
|
import org.koitharu.kotatsu.core.network.TestCookieJar
|
||||||
import org.koitharu.kotatsu.core.network.UserAgentInterceptor
|
import org.koitharu.kotatsu.core.network.UserAgentInterceptor
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.core.parser.SourceSettingsStub
|
import org.koitharu.kotatsu.core.parser.SourceSettingsStub
|
||||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@@ -31,12 +30,4 @@ val repositoryTestModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
factory { (source: MangaSource) ->
|
|
||||||
runCatching {
|
|
||||||
source.cls.getDeclaredConstructor(MangaLoaderContext::class.java)
|
|
||||||
.newInstance(get<MangaLoaderContext>())
|
|
||||||
}.recoverCatching {
|
|
||||||
source.cls.newInstance()
|
|
||||||
}.getOrThrow() as RemoteMangaRepository
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user