Compare commits
76 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef0cf4766a | ||
|
|
910069ec99 | ||
|
|
d56107bf1f | ||
|
|
03426694c8 | ||
|
|
385003bcc8 | ||
|
|
225aacff43 | ||
|
|
208c0a494b | ||
|
|
0045c7cf44 | ||
|
|
eed7f89518 | ||
|
|
80c8b9eac0 | ||
|
|
53a680d13c | ||
|
|
3e77df20a2 | ||
|
|
7c1c0a38fa | ||
|
|
012eefe4fe | ||
|
|
cb0f0c70d0 | ||
|
|
23111dfef9 | ||
|
|
d050c9ad0e | ||
|
|
efd952a91a | ||
|
|
d3f23ea3a3 | ||
|
|
acba312e8d | ||
|
|
880dd6da27 | ||
|
|
0c839ce49a | ||
|
|
1afd2d3976 | ||
|
|
f2d881f9bc | ||
|
|
c838e57f22 | ||
|
|
2075b1be19 | ||
|
|
cf33cb66c6 | ||
|
|
8010c5079b | ||
|
|
a87a77083e | ||
|
|
ca20422344 | ||
|
|
c213b9d4b5 | ||
|
|
95fbe496cb | ||
|
|
b9fd2e100d | ||
|
|
1242a88f8e | ||
|
|
55851fb22f | ||
|
|
7801456d17 | ||
|
|
38a1fafa26 | ||
|
|
aa02233883 | ||
|
|
5405fdb85a | ||
|
|
38ad7e1fd4 | ||
|
|
06372083fd | ||
|
|
d5d3154074 | ||
|
|
1a279966d9 | ||
|
|
3222c2128e | ||
|
|
872c859efe | ||
|
|
b79c00f8df | ||
|
|
e7d3d9811d | ||
|
|
4fdfc75833 | ||
|
|
9754ebf1bb | ||
|
|
fee35cceab | ||
|
|
b928c4123c | ||
|
|
b093a885c9 | ||
|
|
dd898579c9 | ||
|
|
73143d2f94 | ||
|
|
563752f6a4 | ||
|
|
7135902100 | ||
|
|
969947ef71 | ||
|
|
806e4eade6 | ||
|
|
063cfbe6b9 | ||
|
|
7cb94a3baa | ||
|
|
894c584c78 | ||
|
|
2f65e7776a | ||
|
|
76c56c9119 | ||
|
|
e0a803399c | ||
|
|
7803f42486 | ||
|
|
39713b3cf6 | ||
|
|
8ebf5cea62 | ||
|
|
663dabe218 | ||
|
|
3a5d0120bf | ||
|
|
a773f932d4 | ||
|
|
2a5812735f | ||
|
|
06ec145802 | ||
|
|
6624778f7f | ||
|
|
1af1f071ad | ||
|
|
f87db4e6d3 | ||
|
|
07bd66fb39 |
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,2 +0,0 @@
|
||||
ko_fi: xtimms
|
||||
custom: ["https://yoomoney.ru/to/410012543938752"]
|
||||
@@ -16,8 +16,8 @@ android {
|
||||
applicationId 'org.koitharu.kotatsu'
|
||||
minSdk = 21
|
||||
targetSdk = 34
|
||||
versionCode = 593
|
||||
versionName = '6.2.5'
|
||||
versionCode = 602
|
||||
versionName = '6.4.2'
|
||||
generatedDensities = []
|
||||
testInstrumentationRunner "org.koitharu.kotatsu.HiltTestRunner"
|
||||
ksp {
|
||||
@@ -33,7 +33,6 @@ android {
|
||||
applicationIdSuffix = '.debug'
|
||||
}
|
||||
release {
|
||||
multiDexEnabled false
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
@@ -48,11 +47,12 @@ android {
|
||||
main.java.srcDirs += 'src/main/kotlin/'
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
coreLibraryDesugaringEnabled true
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||
freeCompilerArgs += [
|
||||
'-opt-in=kotlin.ExperimentalStdlibApi',
|
||||
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
||||
@@ -82,17 +82,18 @@ afterEvaluate {
|
||||
}
|
||||
dependencies {
|
||||
//noinspection GradleDependency
|
||||
implementation('com.github.KotatsuApp:kotatsu-parsers:4ca3a492b0') {
|
||||
implementation('com.github.KotatsuApp:kotatsu-parsers:0efd5437f9') {
|
||||
exclude group: 'org.json', module: 'json'
|
||||
}
|
||||
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.10'
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.20'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'androidx.core:core-ktx:1.12.0'
|
||||
implementation 'androidx.activity:activity-ktx:1.8.0'
|
||||
implementation 'androidx.fragment:fragment-ktx:1.6.1'
|
||||
implementation 'androidx.activity:activity-ktx:1.8.1'
|
||||
implementation 'androidx.fragment:fragment-ktx:1.6.2'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
|
||||
implementation 'androidx.lifecycle:lifecycle-service:2.6.2'
|
||||
@@ -119,8 +120,8 @@ dependencies {
|
||||
implementation 'androidx.room:room-ktx:2.6.0'
|
||||
ksp 'androidx.room:room-compiler:2.6.0'
|
||||
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.11.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.12.0'
|
||||
implementation 'com.squareup.okio:okio:3.6.0'
|
||||
|
||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
||||
@@ -128,12 +129,12 @@ dependencies {
|
||||
|
||||
implementation 'com.google.dagger:hilt-android:2.48.1'
|
||||
kapt 'com.google.dagger:hilt-compiler:2.48.1'
|
||||
implementation 'androidx.hilt:hilt-work:1.0.0'
|
||||
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
||||
implementation 'androidx.hilt:hilt-work:1.1.0'
|
||||
kapt 'androidx.hilt:hilt-compiler:1.1.0'
|
||||
|
||||
implementation 'io.coil-kt:coil-base:2.4.0'
|
||||
implementation 'io.coil-kt:coil-svg:2.4.0'
|
||||
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:cf089a264d'
|
||||
implementation 'io.coil-kt:coil-base:2.5.0'
|
||||
implementation 'io.coil-kt:coil-svg:2.5.0'
|
||||
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:771c8753ae'
|
||||
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
||||
implementation 'io.noties.markwon:core:4.6.2'
|
||||
|
||||
@@ -143,7 +144,7 @@ dependencies {
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation 'org.json:json:20230618'
|
||||
testImplementation 'org.json:json:20231013'
|
||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
|
||||
|
||||
androidTestImplementation 'androidx.test:runner:1.5.2'
|
||||
|
||||
2
app/proguard-rules.pro
vendored
2
app/proguard-rules.pro
vendored
@@ -19,3 +19,5 @@
|
||||
-keep class org.koitharu.kotatsu.settings.NotificationSettingsLegacyFragment
|
||||
-keep class org.koitharu.kotatsu.core.prefs.ScreenshotsPolicy { *; }
|
||||
-keep class org.koitharu.kotatsu.settings.backup.PeriodicalBackupSettingsFragment { *; }
|
||||
-keep class org.jsoup.parser.Tag
|
||||
-keep class org.jsoup.internal.StringUtil
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.koitharu.kotatsu.parsers.MangaParser
|
||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
@@ -19,19 +20,14 @@ class DummyParser(context: MangaLoaderContext) : MangaParser(context, MangaSourc
|
||||
override val configKeyDomain: ConfigKey.Domain
|
||||
get() = ConfigKey.Domain("")
|
||||
|
||||
override val sortOrders: Set<SortOrder>
|
||||
override val availableSortOrders: Set<SortOrder>
|
||||
get() = EnumSet.allOf(SortOrder::class.java)
|
||||
|
||||
override suspend fun getDetails(manga: Manga): Manga {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getList(
|
||||
offset: Int,
|
||||
query: String?,
|
||||
tags: Set<MangaTag>?,
|
||||
sortOrder: SortOrder,
|
||||
): List<Manga> {
|
||||
override suspend fun getList(offset: Int, filter: MangaListFilter?): List<Manga> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
@@ -39,7 +35,7 @@ class DummyParser(context: MangaLoaderContext) : MangaParser(context, MangaSourc
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getTags(): Set<MangaTag> {
|
||||
override suspend fun getAvailableTags(): Set<MangaTag> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +221,9 @@
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
<activity
|
||||
android:name="org.koitharu.kotatsu.settings.sources.catalog.SourcesCatalogActivity"
|
||||
android:label="@string/sources_catalog" />
|
||||
|
||||
<service
|
||||
android:name="androidx.work.impl.foreground.SystemForegroundService"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.koitharu.kotatsu.bookmarks.domain
|
||||
|
||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||
import org.koitharu.kotatsu.local.data.ImageFileFilter
|
||||
import org.koitharu.kotatsu.local.data.hasImageExtension
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import java.util.Date
|
||||
@@ -38,7 +38,6 @@ data class Bookmark(
|
||||
)
|
||||
|
||||
private fun isImageUrlDirect(): Boolean {
|
||||
val extension = imageUrl.substringAfterLast('.')
|
||||
return extension.isNotEmpty() && ImageFileFilter().isExtensionValid(extension)
|
||||
return hasImageExtension(imageUrl)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ class CloudFlareActivity : BaseActivity<ActivityBrowserBinding>(), CloudFlareCal
|
||||
if (!catchingWebViewUnavailability {
|
||||
setContentView(
|
||||
ActivityBrowserBinding.inflate(
|
||||
layoutInflater
|
||||
)
|
||||
layoutInflater,
|
||||
),
|
||||
)
|
||||
}) {
|
||||
return
|
||||
@@ -82,9 +82,11 @@ class CloudFlareActivity : BaseActivity<ActivityBrowserBinding>(), CloudFlareCal
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
viewBinding.webView.run {
|
||||
stopLoading()
|
||||
destroy()
|
||||
runCatching {
|
||||
viewBinding.webView
|
||||
}.onSuccess {
|
||||
it.stopLoading()
|
||||
it.destroy()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
@@ -4,10 +4,15 @@ import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.RawQuery
|
||||
import androidx.room.Transaction
|
||||
import androidx.room.Upsert
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import org.intellij.lang.annotations.Language
|
||||
import org.koitharu.kotatsu.core.db.entity.MangaSourceEntity
|
||||
import org.koitharu.kotatsu.explore.data.SourcesSortOrder
|
||||
|
||||
@Dao
|
||||
abstract class MangaSourcesDao {
|
||||
@@ -15,11 +20,11 @@ abstract class MangaSourcesDao {
|
||||
@Query("SELECT * FROM sources ORDER BY sort_key")
|
||||
abstract suspend fun findAll(): List<MangaSourceEntity>
|
||||
|
||||
@Query("SELECT * FROM sources WHERE enabled = 1 ORDER BY sort_key")
|
||||
abstract suspend fun findAllEnabled(): List<MangaSourceEntity>
|
||||
@Query("SELECT * FROM sources WHERE enabled = 0 ORDER BY sort_key")
|
||||
abstract suspend fun findAllDisabled(): List<MangaSourceEntity>
|
||||
|
||||
@Query("SELECT * FROM sources WHERE enabled = 1 ORDER BY sort_key")
|
||||
abstract fun observeEnabled(): Flow<List<MangaSourceEntity>>
|
||||
@Query("SELECT * FROM sources WHERE enabled = 0")
|
||||
abstract fun observeDisabled(): Flow<List<MangaSourceEntity>>
|
||||
|
||||
@Query("SELECT * FROM sources ORDER BY sort_key")
|
||||
abstract fun observeAll(): Flow<List<MangaSourceEntity>>
|
||||
@@ -40,6 +45,22 @@ abstract class MangaSourcesDao {
|
||||
@Upsert
|
||||
abstract suspend fun upsert(entry: MangaSourceEntity)
|
||||
|
||||
fun observeEnabled(order: SourcesSortOrder): Flow<List<MangaSourceEntity>> {
|
||||
val orderBy = getOrderBy(order)
|
||||
|
||||
@Language("RoomSql")
|
||||
val query = SimpleSQLiteQuery("SELECT * FROM sources WHERE enabled = 1 ORDER BY $orderBy")
|
||||
return observeImpl(query)
|
||||
}
|
||||
|
||||
suspend fun findAllEnabled(order: SourcesSortOrder): List<MangaSourceEntity> {
|
||||
val orderBy = getOrderBy(order)
|
||||
|
||||
@Language("RoomSql")
|
||||
val query = SimpleSQLiteQuery("SELECT * FROM sources WHERE enabled = 1 ORDER BY $orderBy")
|
||||
return findAllImpl(query)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open suspend fun setEnabled(source: String, isEnabled: Boolean) {
|
||||
if (updateIsEnabled(source, isEnabled) == 0) {
|
||||
@@ -54,4 +75,16 @@ abstract class MangaSourcesDao {
|
||||
|
||||
@Query("UPDATE sources SET enabled = :isEnabled WHERE source = :source")
|
||||
protected abstract suspend fun updateIsEnabled(source: String, isEnabled: Boolean): Int
|
||||
|
||||
@RawQuery(observedEntities = [MangaSourceEntity::class])
|
||||
protected abstract fun observeImpl(query: SupportSQLiteQuery): Flow<List<MangaSourceEntity>>
|
||||
|
||||
@RawQuery
|
||||
protected abstract suspend fun findAllImpl(query: SupportSQLiteQuery): List<MangaSourceEntity>
|
||||
|
||||
private fun getOrderBy(order: SourcesSortOrder) = when (order) {
|
||||
SourcesSortOrder.ALPHABETIC -> "source ASC"
|
||||
SourcesSortOrder.POPULARITY -> "(SELECT COUNT(*) FROM manga WHERE source = sources.source) DESC"
|
||||
SourcesSortOrder.MANUAL -> "sort_key ASC"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package org.koitharu.kotatsu.core.model
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.util.ext.iterator
|
||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaState
|
||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||
|
||||
@JvmName("mangaIds")
|
||||
@@ -31,6 +34,15 @@ fun Collection<ChapterListItem>.countChaptersByBranch(): Int {
|
||||
return acc.values.max()
|
||||
}
|
||||
|
||||
@get:StringRes
|
||||
val MangaState.titleResId: Int
|
||||
get() = when (this) {
|
||||
MangaState.ONGOING -> R.string.state_ongoing
|
||||
MangaState.FINISHED -> R.string.state_finished
|
||||
MangaState.ABANDONED -> R.string.state_abandoned
|
||||
MangaState.PAUSED -> R.string.state_paused
|
||||
}
|
||||
|
||||
fun Manga.findChapter(id: Long): MangaChapter? {
|
||||
return chapters?.findById(id)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.koitharu.kotatsu.core.model
|
||||
|
||||
import android.content.Context
|
||||
import androidx.annotation.StringRes
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||
@@ -18,3 +21,18 @@ fun MangaSource(name: String): MangaSource {
|
||||
}
|
||||
|
||||
fun MangaSource.isNsfw() = contentType == ContentType.HENTAI
|
||||
|
||||
@get:StringRes
|
||||
val ContentType.titleResId
|
||||
get() = when (this) {
|
||||
ContentType.MANGA -> R.string.content_type_manga
|
||||
ContentType.HENTAI -> R.string.content_type_hentai
|
||||
ContentType.COMICS -> R.string.content_type_comics
|
||||
ContentType.OTHER -> R.string.content_type_other
|
||||
}
|
||||
|
||||
fun MangaSource.getSummary(context: Context): String {
|
||||
val type = context.getString(contentType.titleResId)
|
||||
val locale = getLocaleTitle() ?: context.getString(R.string.various_languages)
|
||||
return context.getString(R.string.source_summary_pattern, type, locale)
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ class CloudFlareInterceptor : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val response = chain.proceed(chain.request())
|
||||
if (response.code == HTTP_FORBIDDEN || response.code == HTTP_UNAVAILABLE) {
|
||||
val content = response.body?.source()?.peek()?.use {
|
||||
Jsoup.parse(it.inputStream(), Charsets.UTF_8.name(), response.request.url.toString())
|
||||
val content = response.body?.let { response.peekBody(Long.MAX_VALUE) }?.byteStream()?.use {
|
||||
Jsoup.parse(it, Charsets.UTF_8.name(), response.request.url.toString())
|
||||
} ?: return response
|
||||
if (content.getElementById("challenge-error-title") != null) {
|
||||
val request = response.request
|
||||
|
||||
@@ -63,6 +63,9 @@ class MirrorSwitchInterceptor @Inject constructor(
|
||||
}
|
||||
synchronized(obtainLock(repository.source)) {
|
||||
val currentMirror = repository.domain
|
||||
if (currentMirror !in mirrors) {
|
||||
return@synchronized false
|
||||
}
|
||||
addToBlacklist(repository.source, currentMirror)
|
||||
val newMirror = mirrors.firstOrNull { x ->
|
||||
x != currentMirror && !isBlacklisted(repository.source, x)
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.koitharu.kotatsu.core.db.entity.toEntities
|
||||
import org.koitharu.kotatsu.core.db.entity.toEntity
|
||||
import org.koitharu.kotatsu.core.db.entity.toManga
|
||||
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||
import org.koitharu.kotatsu.core.model.isLocal
|
||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
@@ -77,10 +78,18 @@ class MangaDataRepository @Inject constructor(
|
||||
}
|
||||
|
||||
suspend fun storeManga(manga: Manga) {
|
||||
val tags = manga.tags.toEntities()
|
||||
db.withTransaction {
|
||||
db.getTagsDao().upsert(tags)
|
||||
db.getMangaDao().upsert(manga.toEntity(), tags)
|
||||
// avoid storing local manga if remote one is already stored
|
||||
val existing = if (manga.isLocal) {
|
||||
db.getMangaDao().find(manga.id)?.manga
|
||||
} else {
|
||||
null
|
||||
}
|
||||
if (existing == null || existing.source == manga.source.name) {
|
||||
val tags = manga.tags.toEntities()
|
||||
db.getTagsDao().upsert(tags)
|
||||
db.getMangaDao().upsert(manga.toEntity(), tags)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.koitharu.kotatsu.core.parser
|
||||
|
||||
import android.net.Uri
|
||||
import coil.request.CachePolicy
|
||||
import dagger.Reusable
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.core.util.ext.ifNullOrEmpty
|
||||
@@ -8,6 +9,7 @@ import org.koitharu.kotatsu.explore.data.MangaSourcesRepository
|
||||
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
||||
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.util.almostEquals
|
||||
import org.koitharu.kotatsu.parsers.util.levenshteinDistance
|
||||
@@ -58,7 +60,7 @@ class MangaLinkResolver @Inject constructor(
|
||||
|
||||
private suspend fun MangaRepository.findExact(url: String?, title: String?): Manga? {
|
||||
if (!title.isNullOrEmpty()) {
|
||||
val list = getList(0, title)
|
||||
val list = getList(0, MangaListFilter.Search(title))
|
||||
if (url != null) {
|
||||
list.find { it.url == url }?.let {
|
||||
return it
|
||||
@@ -77,14 +79,14 @@ class MangaLinkResolver @Inject constructor(
|
||||
}.ifNullOrEmpty {
|
||||
seed.author
|
||||
} ?: return@runCatchingCancellable null
|
||||
val seedList = getList(0, seedTitle)
|
||||
val seedList = getList(0, MangaListFilter.Search(seedTitle))
|
||||
seedList.first { x -> x.url == url }
|
||||
}.getOrThrow()
|
||||
}
|
||||
|
||||
private suspend fun MangaRepository.getDetailsNoCache(manga: Manga): Manga {
|
||||
return if (this is RemoteMangaRepository) {
|
||||
getDetails(manga, withCache = false)
|
||||
getDetails(manga, CachePolicy.READ_ONLY)
|
||||
} else {
|
||||
getDetails(manga)
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@ import org.koitharu.kotatsu.local.data.LocalMangaRepository
|
||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaState
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||
import java.lang.ref.WeakReference
|
||||
@@ -23,11 +25,13 @@ interface MangaRepository {
|
||||
|
||||
val sortOrders: Set<SortOrder>
|
||||
|
||||
val states: Set<MangaState>
|
||||
|
||||
var defaultSortOrder: SortOrder
|
||||
|
||||
suspend fun getList(offset: Int, query: String): List<Manga>
|
||||
val isMultipleTagsSupported: Boolean
|
||||
|
||||
suspend fun getList(offset: Int, tags: Set<MangaTag>?, sortOrder: SortOrder?): List<Manga>
|
||||
suspend fun getList(offset: Int, filter: MangaListFilter?): List<Manga>
|
||||
|
||||
suspend fun getDetails(manga: Manga): Manga
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.koitharu.kotatsu.core.parser
|
||||
|
||||
import android.util.Log
|
||||
import coil.request.CachePolicy
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -23,8 +24,10 @@ import org.koitharu.kotatsu.parsers.exception.ParseException
|
||||
import org.koitharu.kotatsu.parsers.model.Favicons
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaState
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||
import org.koitharu.kotatsu.parsers.util.domain
|
||||
@@ -40,7 +43,10 @@ class RemoteMangaRepository(
|
||||
get() = parser.source
|
||||
|
||||
override val sortOrders: Set<SortOrder>
|
||||
get() = parser.sortOrders
|
||||
get() = parser.availableSortOrders
|
||||
|
||||
override val states: Set<MangaState>
|
||||
get() = parser.availableStates
|
||||
|
||||
override var defaultSortOrder: SortOrder
|
||||
get() = getConfig().defaultSortOrder ?: sortOrders.first()
|
||||
@@ -48,6 +54,9 @@ class RemoteMangaRepository(
|
||||
getConfig().defaultSortOrder = value
|
||||
}
|
||||
|
||||
override val isMultipleTagsSupported: Boolean
|
||||
get() = parser.isMultipleTagsSupported
|
||||
|
||||
var domain: String
|
||||
get() = parser.domain
|
||||
set(value) {
|
||||
@@ -68,19 +77,13 @@ class RemoteMangaRepository(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getList(offset: Int, query: String): List<Manga> {
|
||||
override suspend fun getList(offset: Int, filter: MangaListFilter?): List<Manga> {
|
||||
return mirrorSwitchInterceptor.withMirrorSwitching {
|
||||
parser.getList(offset, query)
|
||||
parser.getList(offset, filter)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getList(offset: Int, tags: Set<MangaTag>?, sortOrder: SortOrder?): List<Manga> {
|
||||
return mirrorSwitchInterceptor.withMirrorSwitching {
|
||||
parser.getList(offset, tags, sortOrder)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getDetails(manga: Manga): Manga = getDetails(manga, withCache = true)
|
||||
override suspend fun getDetails(manga: Manga): Manga = getDetails(manga, CachePolicy.ENABLED)
|
||||
|
||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
||||
cache.getPages(source, chapter.url)?.let { return it }
|
||||
@@ -98,7 +101,7 @@ class RemoteMangaRepository(
|
||||
}
|
||||
|
||||
override suspend fun getTags(): Set<MangaTag> = mirrorSwitchInterceptor.withMirrorSwitching {
|
||||
parser.getTags()
|
||||
parser.getAvailableTags()
|
||||
}
|
||||
|
||||
suspend fun getFavicons(): Favicons = mirrorSwitchInterceptor.withMirrorSwitching {
|
||||
@@ -114,17 +117,18 @@ class RemoteMangaRepository(
|
||||
return related.await()
|
||||
}
|
||||
|
||||
suspend fun getDetails(manga: Manga, withCache: Boolean): Manga {
|
||||
if (!withCache) {
|
||||
return parser.getDetails(manga)
|
||||
suspend fun getDetails(manga: Manga, cachePolicy: CachePolicy): Manga {
|
||||
if (cachePolicy.readEnabled) {
|
||||
cache.getDetails(source, manga.url)?.let { return it }
|
||||
}
|
||||
cache.getDetails(source, manga.url)?.let { return it }
|
||||
val details = asyncSafe {
|
||||
mirrorSwitchInterceptor.withMirrorSwitching {
|
||||
parser.getDetails(manga)
|
||||
}
|
||||
}
|
||||
cache.putDetails(source, manga.url, details)
|
||||
if (cachePolicy.writeEnabled) {
|
||||
cache.putDetails(source, manga.url, details)
|
||||
}
|
||||
return details.await()
|
||||
}
|
||||
|
||||
@@ -133,7 +137,7 @@ class RemoteMangaRepository(
|
||||
}
|
||||
|
||||
suspend fun find(manga: Manga): Manga? {
|
||||
val list = getList(0, manga.title)
|
||||
val list = getList(0, MangaListFilter.Search(manga.title))
|
||||
return list.find { x -> x.id == manga.id }
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.koitharu.kotatsu.core.util.ext.observe
|
||||
import org.koitharu.kotatsu.core.util.ext.putEnumValue
|
||||
import org.koitharu.kotatsu.core.util.ext.takeIfReadable
|
||||
import org.koitharu.kotatsu.core.util.ext.toUriOrNull
|
||||
import org.koitharu.kotatsu.explore.data.SourcesSortOrder
|
||||
import org.koitharu.kotatsu.list.domain.ListSortOrder
|
||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||
import org.koitharu.kotatsu.parsers.util.find
|
||||
@@ -108,6 +109,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||
val isReaderTapsAdaptive: Boolean
|
||||
get() = !prefs.getBoolean(KEY_READER_TAPS_LTR, false)
|
||||
|
||||
val isReaderOptimizationEnabled: Boolean
|
||||
get() = prefs.getBoolean(KEY_READER_OPTIMIZE, false)
|
||||
|
||||
var isTrafficWarningEnabled: Boolean
|
||||
get() = prefs.getBoolean(KEY_TRAFFIC_WARNING, true)
|
||||
set(value) = prefs.edit { putBoolean(KEY_TRAFFIC_WARNING, value) }
|
||||
@@ -209,6 +213,10 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||
return policy.isNetworkAllowed(connectivityManager)
|
||||
}
|
||||
|
||||
var sourcesSortOrder: SourcesSortOrder
|
||||
get() = prefs.getEnumValue(KEY_SOURCES_ORDER, SourcesSortOrder.MANUAL)
|
||||
set(value) = prefs.edit { putEnumValue(KEY_SOURCES_ORDER, value) }
|
||||
|
||||
var isSourcesGridMode: Boolean
|
||||
get() = prefs.getBoolean(KEY_SOURCES_GRID, false)
|
||||
set(value) = prefs.edit { putBoolean(KEY_SOURCES_GRID, value) }
|
||||
@@ -501,6 +509,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||
const val KEY_READER_SCREEN_ON = "reader_screen_on"
|
||||
const val KEY_SHORTCUTS = "dynamic_shortcuts"
|
||||
const val KEY_READER_TAPS_LTR = "reader_taps_ltr"
|
||||
const val KEY_READER_OPTIMIZE = "reader_optimize"
|
||||
const val KEY_LOCAL_LIST_ORDER = "local_order"
|
||||
const val KEY_HISTORY_ORDER = "history_order"
|
||||
const val KEY_WEBTOON_ZOOM = "webtoon_zoom"
|
||||
@@ -528,6 +537,8 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||
const val KEY_RELATED_MANGA = "related_manga"
|
||||
const val KEY_NAV_MAIN = "nav_main"
|
||||
const val KEY_32BIT_COLOR = "enhanced_colors"
|
||||
const val KEY_SOURCES_ORDER = "sources_sort_order"
|
||||
const val KEY_SOURCES_CATALOG = "sources_catalog"
|
||||
|
||||
// About
|
||||
const val KEY_APP_UPDATE = "app_update"
|
||||
|
||||
@@ -4,11 +4,11 @@ import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.text.HtmlCompat
|
||||
import androidx.core.text.htmlEncode
|
||||
import androidx.core.text.method.LinkMovementMethodCompat
|
||||
import androidx.core.text.parseAsHtml
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
@@ -37,7 +37,7 @@ class ErrorDetailsDialog : AlertDialogFragment<DialogErrorDetailsBinding>() {
|
||||
override fun onViewBindingCreated(binding: DialogErrorDetailsBinding, savedInstanceState: Bundle?) {
|
||||
super.onViewBindingCreated(binding, savedInstanceState)
|
||||
with(binding.textViewMessage) {
|
||||
movementMethod = LinkMovementMethod.getInstance()
|
||||
movementMethod = LinkMovementMethodCompat.getInstance()
|
||||
text = context.getString(
|
||||
R.string.manga_error_description_pattern,
|
||||
exception.message?.htmlEncode().orEmpty(),
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package org.koitharu.kotatsu.core.ui.list.lifecycle
|
||||
|
||||
import android.view.View
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.LifecycleRegistry
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
abstract class LifecycleAwareViewHolder(
|
||||
itemView: View,
|
||||
private val parentLifecycleOwner: LifecycleOwner,
|
||||
) : RecyclerView.ViewHolder(itemView), LifecycleOwner {
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
final override val lifecycle = LifecycleRegistry(this)
|
||||
private var isCurrent = false
|
||||
|
||||
init {
|
||||
parentLifecycleOwner.lifecycle.addObserver(ParentLifecycleObserver())
|
||||
if (parentLifecycleOwner.lifecycle.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
||||
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
||||
}
|
||||
}
|
||||
|
||||
fun setIsCurrent(value: Boolean) {
|
||||
isCurrent = value
|
||||
dispatchResumed()
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
open fun onStart() = lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
||||
|
||||
@CallSuper
|
||||
open fun onResume() = lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
|
||||
@CallSuper
|
||||
open fun onPause() = lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||
|
||||
@CallSuper
|
||||
open fun onStop() = lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||
|
||||
private fun dispatchResumed() {
|
||||
val isParentResumed = parentLifecycleOwner.lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)
|
||||
if (isCurrent && isParentResumed) {
|
||||
if (!isResumed()) {
|
||||
onResume()
|
||||
}
|
||||
} else {
|
||||
if (isResumed()) {
|
||||
onPause()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected fun isResumed(): Boolean {
|
||||
return lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)
|
||||
}
|
||||
|
||||
private inner class ParentLifecycleObserver : DefaultLifecycleObserver {
|
||||
|
||||
override fun onCreate(owner: LifecycleOwner) {
|
||||
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
||||
}
|
||||
|
||||
override fun onStart(owner: LifecycleOwner) {
|
||||
onStart()
|
||||
}
|
||||
|
||||
override fun onResume(owner: LifecycleOwner) {
|
||||
dispatchResumed()
|
||||
}
|
||||
|
||||
override fun onPause(owner: LifecycleOwner) {
|
||||
dispatchResumed()
|
||||
}
|
||||
|
||||
override fun onStop(owner: LifecycleOwner) {
|
||||
onStop()
|
||||
}
|
||||
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
owner.lifecycle.removeObserver(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.koitharu.kotatsu.core.ui.list.lifecycle
|
||||
|
||||
import androidx.core.view.children
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
||||
|
||||
class PagerLifecycleDispatcher(
|
||||
private val pager: ViewPager2,
|
||||
) : ViewPager2.OnPageChangeCallback() {
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
super.onPageSelected(position)
|
||||
val rv = pager.recyclerView ?: return
|
||||
for (child in rv.children) {
|
||||
val wh = rv.getChildViewHolder(child) ?: continue
|
||||
(wh as? LifecycleAwareViewHolder)?.setIsCurrent(wh.absoluteAdapterPosition == position)
|
||||
}
|
||||
}
|
||||
|
||||
fun invalidate() {
|
||||
onPageSelected(pager.currentItem)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.koitharu.kotatsu.core.ui.list.lifecycle
|
||||
|
||||
import androidx.core.view.children
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.NO_POSITION
|
||||
|
||||
class RecyclerViewLifecycleDispatcher : RecyclerView.OnScrollListener() {
|
||||
|
||||
private var prevFirst = NO_POSITION
|
||||
private var prevLast = NO_POSITION
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
invalidate(recyclerView)
|
||||
}
|
||||
|
||||
fun invalidate(recyclerView: RecyclerView) {
|
||||
val lm = recyclerView.layoutManager as? LinearLayoutManager ?: return
|
||||
val first = lm.findFirstVisibleItemPosition()
|
||||
val last = lm.findLastVisibleItemPosition()
|
||||
if (first == prevFirst && last == prevLast) {
|
||||
return
|
||||
}
|
||||
prevFirst = first
|
||||
prevLast = last
|
||||
if (first == NO_POSITION || last == NO_POSITION) {
|
||||
return
|
||||
}
|
||||
for (child in recyclerView.children) {
|
||||
val wh = recyclerView.getChildViewHolder(child) ?: continue
|
||||
(wh as? LifecycleAwareViewHolder)?.setIsCurrent(wh.absoluteAdapterPosition in first..last)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.koitharu.kotatsu.core.ui.widgets
|
||||
|
||||
import android.content.Context
|
||||
import android.util.ArrayMap
|
||||
import android.util.AttributeSet
|
||||
import com.google.android.material.slider.Slider
|
||||
import kotlin.math.cbrt
|
||||
import kotlin.math.pow
|
||||
|
||||
class CubicSlider @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
) : Slider(context, attrs) {
|
||||
|
||||
private val changeListeners = ArrayMap<OnChangeListener, OnChangeListenerMapper>(1)
|
||||
|
||||
override fun setValue(value: Float) {
|
||||
super.setValue(value.unmap())
|
||||
}
|
||||
|
||||
override fun getValue(): Float {
|
||||
return super.getValue().map()
|
||||
}
|
||||
|
||||
override fun getValueFrom(): Float {
|
||||
return super.getValueFrom().map()
|
||||
}
|
||||
|
||||
override fun setValueFrom(valueFrom: Float) {
|
||||
super.setValueFrom(valueFrom.unmap())
|
||||
}
|
||||
|
||||
override fun getValueTo(): Float {
|
||||
return super.getValueTo().map()
|
||||
}
|
||||
|
||||
override fun setValueTo(valueTo: Float) {
|
||||
super.setValueTo(valueTo.unmap())
|
||||
}
|
||||
|
||||
override fun addOnChangeListener(listener: OnChangeListener) {
|
||||
val mapper = OnChangeListenerMapper(listener)
|
||||
super.addOnChangeListener(mapper)
|
||||
changeListeners[listener] = mapper
|
||||
}
|
||||
|
||||
override fun removeOnChangeListener(listener: OnChangeListener) {
|
||||
changeListeners.remove(listener)?.let {
|
||||
super.removeOnChangeListener(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun clearOnChangeListeners() {
|
||||
super.clearOnChangeListeners()
|
||||
changeListeners.clear()
|
||||
}
|
||||
|
||||
private fun Float.map(): Float {
|
||||
return this.pow(3)
|
||||
}
|
||||
|
||||
private fun Float.unmap(): Float {
|
||||
return cbrt(this)
|
||||
}
|
||||
|
||||
private inner class OnChangeListenerMapper(
|
||||
private val delegate: OnChangeListener,
|
||||
) : OnChangeListener {
|
||||
|
||||
override fun onValueChange(slider: Slider, value: Float, fromUser: Boolean) {
|
||||
delegate.onValueChange(slider, value.map(), fromUser)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CompositeMutex<T : Any> : Set<T> {
|
||||
}
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
return state.isEmpty
|
||||
return state.isEmpty()
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<T> {
|
||||
|
||||
@@ -19,7 +19,7 @@ class CompositeMutex2<T : Any> : Set<T> {
|
||||
}
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
return delegates.isEmpty
|
||||
return delegates.isEmpty()
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<T> {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.koitharu.kotatsu.core.util
|
||||
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import org.koitharu.kotatsu.core.util.ext.map
|
||||
import java.util.Locale
|
||||
|
||||
class LocaleComparator : Comparator<Locale?> {
|
||||
|
||||
private val deviceLocales = LocaleListCompat.getAdjustedDefault()//LocaleManagerCompat.getSystemLocales(context)
|
||||
.map { it.language }
|
||||
.distinct()
|
||||
|
||||
override fun compare(a: Locale?, b: Locale?): Int {
|
||||
return if (a === b) {
|
||||
0
|
||||
} else {
|
||||
val indexA = if (a == null) -1 else deviceLocales.indexOf(a.language)
|
||||
val indexB = if (b == null) -1 else deviceLocales.indexOf(b.language)
|
||||
if (indexA < 0 && indexB < 0) {
|
||||
compareValues(a?.language, b?.language)
|
||||
} else {
|
||||
-2 - (indexA - indexB)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,16 @@ import android.content.res.Configuration
|
||||
import android.database.ContentObserver
|
||||
import android.os.Handler
|
||||
import android.provider.Settings
|
||||
import dagger.hilt.android.scopes.ActivityScoped
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.channels.trySendBlocking
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import javax.inject.Inject
|
||||
|
||||
class ScreenOrientationHelper(private val activity: Activity) {
|
||||
@ActivityScoped
|
||||
class ScreenOrientationHelper @Inject constructor(private val activity: Activity) {
|
||||
|
||||
val isAutoRotationEnabled: Boolean
|
||||
get() = Settings.System.getInt(
|
||||
@@ -31,9 +34,15 @@ class ScreenOrientationHelper(private val activity: Activity) {
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleOrientation() {
|
||||
isLandscape = !isLandscape
|
||||
}
|
||||
var isLocked: Boolean
|
||||
get() = activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED
|
||||
set(value) {
|
||||
activity.requestedOrientation = if (value) {
|
||||
ActivityInfo.SCREEN_ORIENTATION_LOCKED
|
||||
} else {
|
||||
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
fun observeAutoOrientation() = callbackFlow {
|
||||
val observer = object : ContentObserver(Handler(activity.mainLooper)) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.core.util.ext
|
||||
|
||||
import androidx.collection.ArrayMap
|
||||
import androidx.collection.ArraySet
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
import java.util.Collections
|
||||
import java.util.EnumSet
|
||||
|
||||
@@ -57,3 +58,13 @@ inline fun <reified E : Enum<E>> Collection<E>.toEnumSet(): EnumSet<E> = if (isE
|
||||
}
|
||||
|
||||
fun <E : Enum<E>> Collection<E>.sortedByOrdinal() = sortedBy { it.ordinal }
|
||||
|
||||
fun <T> Iterable<T>.sortedWithSafe(comparator: Comparator<in T>): List<T> = try {
|
||||
sortedWith(comparator)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
throw e
|
||||
} else {
|
||||
toList()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.os.storage.StorageManager
|
||||
import android.provider.OpenableColumns
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.core.database.getStringOrNull
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runInterruptible
|
||||
@@ -19,7 +18,9 @@ import java.io.FileFilter
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipFile
|
||||
import kotlin.io.path.ExperimentalPathApi
|
||||
import kotlin.io.path.readAttributes
|
||||
import kotlin.io.path.walk
|
||||
|
||||
fun File.subdir(name: String) = File(this, name).also {
|
||||
if (!it.exists()) it.mkdirs()
|
||||
@@ -49,7 +50,7 @@ fun File.getStorageName(context: Context): String = runCatching {
|
||||
}
|
||||
}.getOrNull() ?: context.getString(R.string.other_storage)
|
||||
|
||||
fun Uri.toFileOrNull() = if (scheme == "file") path?.let(::File) else null
|
||||
fun Uri.toFileOrNull() = if (scheme == URI_SCHEME_FILE) path?.let(::File) else null
|
||||
|
||||
suspend fun File.deleteAwait() = withContext(Dispatchers.IO) {
|
||||
delete() || deleteRecursively()
|
||||
@@ -71,31 +72,7 @@ fun ContentResolver.resolveName(uri: Uri): String? {
|
||||
}
|
||||
|
||||
suspend fun File.computeSize(): Long = runInterruptible(Dispatchers.IO) {
|
||||
computeSizeInternal(this)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun computeSizeInternal(file: File): Long {
|
||||
return if (file.isDirectory) {
|
||||
file.children().sumOf { computeSizeInternal(it) }
|
||||
} else {
|
||||
file.length()
|
||||
}
|
||||
}
|
||||
|
||||
fun File.listFilesRecursive(filter: FileFilter? = null): Sequence<File> = sequence {
|
||||
listFilesRecursiveImpl(this@listFilesRecursive, filter)
|
||||
}
|
||||
|
||||
private suspend fun SequenceScope<File>.listFilesRecursiveImpl(root: File, filter: FileFilter?) {
|
||||
val ss = root.children()
|
||||
for (f in ss) {
|
||||
if (f.isDirectory) {
|
||||
listFilesRecursiveImpl(f, filter)
|
||||
} else if (filter == null || filter.accept(f)) {
|
||||
yield(f)
|
||||
}
|
||||
}
|
||||
walkCompat().sumOf { it.length() }
|
||||
}
|
||||
|
||||
fun File.children() = FileSequence(this)
|
||||
@@ -108,3 +85,12 @@ val File.creationTime
|
||||
} else {
|
||||
lastModified()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
fun File.walkCompat() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// Use lazy loading on Android 8.0 and later
|
||||
toPath().walk().map { it.toFile() }
|
||||
} else {
|
||||
// Directories are excluded by default in Path.walk(), so do it here as well
|
||||
walk().filter { it.isFile }
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import okhttp3.Response
|
||||
import okhttp3.internal.closeQuietly
|
||||
import okio.IOException
|
||||
import org.json.JSONObject
|
||||
import org.jsoup.HttpStatusException
|
||||
import java.net.HttpURLConnection
|
||||
|
||||
private val TYPE_JSON = "application/json".toMediaType()
|
||||
@@ -34,9 +35,8 @@ val HttpUrl.isHttpOrHttps: Boolean
|
||||
|
||||
fun Response.ensureSuccess() = apply {
|
||||
if (!isSuccessful || code == HttpURLConnection.HTTP_NO_CONTENT) {
|
||||
val message = "Invalid response: $code $message at ${request.url}"
|
||||
closeQuietly()
|
||||
throw IllegalStateException(message)
|
||||
throw HttpStatusException(message, code, request.url.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package org.koitharu.kotatsu.core.util.ext
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||
import java.util.Locale
|
||||
|
||||
operator fun LocaleListCompat.iterator(): ListIterator<Locale> = LocaleListCompatIterator(this)
|
||||
@@ -17,6 +20,14 @@ inline fun <T> LocaleListCompat.mapToSet(block: (Locale) -> T): Set<T> {
|
||||
|
||||
fun LocaleListCompat.getOrThrow(index: Int) = get(index) ?: throw NoSuchElementException()
|
||||
|
||||
fun String?.getLocaleDisplayName(context: Context): String {
|
||||
if (this == null) {
|
||||
return context.getString(R.string.various_languages)
|
||||
}
|
||||
val lc = Locale(this)
|
||||
return lc.getDisplayLanguage(lc).toTitleCase(lc)
|
||||
}
|
||||
|
||||
private class LocaleListCompatIterator(private val list: LocaleListCompat) : ListIterator<Locale> {
|
||||
|
||||
private var index = 0
|
||||
|
||||
@@ -27,7 +27,10 @@ import java.net.SocketTimeoutException
|
||||
import java.net.UnknownHostException
|
||||
|
||||
private const val MSG_NO_SPACE_LEFT = "No space left on device"
|
||||
private const val IMAGE_FORMAT_NO_SUPPORTED = "Image format not supported"
|
||||
private const val IMAGE_FORMAT_NOT_SUPPORTED = "Image format not supported"
|
||||
private const val MULTIPLE_GENRES_NOT_SUPPORTED = "Multiple genres are not supported by this source"
|
||||
private const val MULTIPLE_STATES_NOT_SUPPORTED = "Multiple states are not supported by this source"
|
||||
private const val SEARCH_NOT_SUPPORTED = "Search is not supported by this source"
|
||||
|
||||
fun Throwable.getDisplayMessage(resources: Resources): String = when (this) {
|
||||
is AuthRequiredException -> resources.getString(R.string.auth_required)
|
||||
@@ -56,8 +59,7 @@ fun Throwable.getDisplayMessage(resources: Resources): String = when (this) {
|
||||
is HttpException -> getHttpDisplayMessage(response.code, resources)
|
||||
is HttpStatusException -> getHttpDisplayMessage(statusCode, resources)
|
||||
|
||||
is IOException -> getDisplayMessage(message, resources) ?: localizedMessage
|
||||
else -> localizedMessage
|
||||
else -> getDisplayMessage(message, resources) ?: localizedMessage
|
||||
}.ifNullOrEmpty {
|
||||
resources.getString(R.string.error_occurred)
|
||||
}
|
||||
@@ -82,7 +84,10 @@ private fun getHttpDisplayMessage(statusCode: Int, resources: Resources): String
|
||||
private fun getDisplayMessage(msg: String?, resources: Resources): String? = when {
|
||||
msg.isNullOrEmpty() -> null
|
||||
msg.contains(MSG_NO_SPACE_LEFT) -> resources.getString(R.string.error_no_space_left)
|
||||
msg.contains(IMAGE_FORMAT_NO_SUPPORTED) -> resources.getString(R.string.error_corrupted_file)
|
||||
msg.contains(IMAGE_FORMAT_NOT_SUPPORTED) -> resources.getString(R.string.error_corrupted_file)
|
||||
msg == MULTIPLE_GENRES_NOT_SUPPORTED -> resources.getString(R.string.error_multiple_genres_not_supported)
|
||||
msg == MULTIPLE_STATES_NOT_SUPPORTED -> resources.getString(R.string.error_multiple_states_not_supported)
|
||||
msg == SEARCH_NOT_SUPPORTED -> resources.getString(R.string.error_search_not_supported)
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.koitharu.kotatsu.core.util.ext
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.core.net.toFile
|
||||
import okio.Source
|
||||
import okio.source
|
||||
import okio.use
|
||||
import org.koitharu.kotatsu.local.data.util.withExtraCloseable
|
||||
import java.io.File
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
const val URI_SCHEME_FILE = "file"
|
||||
const val URI_SCHEME_ZIP = "file+zip"
|
||||
|
||||
fun Uri.exists(): Boolean = when (scheme) {
|
||||
URI_SCHEME_FILE -> toFile().exists()
|
||||
URI_SCHEME_ZIP -> {
|
||||
val file = File(requireNotNull(schemeSpecificPart))
|
||||
file.exists() && ZipFile(file).use { it.getEntry(fragment) != null }
|
||||
}
|
||||
|
||||
else -> unsupportedUri(this)
|
||||
}
|
||||
|
||||
fun Uri.isTargetNotEmpty(): Boolean = when (scheme) {
|
||||
URI_SCHEME_FILE -> toFile().isNotEmpty()
|
||||
URI_SCHEME_ZIP -> {
|
||||
val file = File(requireNotNull(schemeSpecificPart))
|
||||
file.exists() && ZipFile(file).use { (it.getEntry(fragment)?.size ?: 0L) != 0L }
|
||||
}
|
||||
|
||||
else -> unsupportedUri(this)
|
||||
}
|
||||
|
||||
fun Uri.source(): Source = when (scheme) {
|
||||
URI_SCHEME_FILE -> toFile().source()
|
||||
URI_SCHEME_ZIP -> {
|
||||
val zip = ZipFile(schemeSpecificPart)
|
||||
val entry = zip.getEntry(fragment)
|
||||
zip.getInputStream(entry).source().withExtraCloseable(zip)
|
||||
}
|
||||
|
||||
else -> unsupportedUri(this)
|
||||
}
|
||||
|
||||
fun File.toZipUri(entryName: String): Uri = Uri.parse("$URI_SCHEME_ZIP://$absolutePath#$entryName")
|
||||
|
||||
private fun unsupportedUri(uri: Uri): Nothing {
|
||||
throw IllegalArgumentException("Bad uri $uri: only schemes $URI_SCHEME_FILE and $URI_SCHEME_ZIP are supported")
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import androidx.core.view.children
|
||||
import androidx.core.view.descendants
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.progressindicator.BaseProgressIndicator
|
||||
import com.google.android.material.slider.Slider
|
||||
@@ -68,6 +69,10 @@ inline fun ViewPager2.doOnPageChanged(crossinline callback: (Int) -> Unit) {
|
||||
val ViewPager2.recyclerView: RecyclerView?
|
||||
get() = children.firstNotNullOfOrNull { it as? RecyclerView }
|
||||
|
||||
fun ViewPager2.findCurrentViewHolder(): ViewHolder? {
|
||||
return recyclerView?.findViewHolderForAdapterPosition(currentItem)
|
||||
}
|
||||
|
||||
fun View.resetTransformations() {
|
||||
alpha = 1f
|
||||
translationX = 0f
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package org.koitharu.kotatsu.core.zip
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.collection.LruCache
|
||||
import okhttp3.internal.closeQuietly
|
||||
import okio.Source
|
||||
import okio.source
|
||||
import java.io.File
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
class ZipPool(maxSize: Int) : LruCache<String, ZipFile>(maxSize) {
|
||||
|
||||
override fun entryRemoved(evicted: Boolean, key: String, oldValue: ZipFile, newValue: ZipFile?) {
|
||||
super.entryRemoved(evicted, key, oldValue, newValue)
|
||||
oldValue.closeQuietly()
|
||||
}
|
||||
|
||||
override fun create(key: String): ZipFile {
|
||||
return ZipFile(File(key), ZipFile.OPEN_READ)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@WorkerThread
|
||||
operator fun get(uri: Uri): Source {
|
||||
val zip = requireNotNull(get(uri.schemeSpecificPart)) {
|
||||
"Cannot obtain zip by \"$uri\""
|
||||
}
|
||||
val entry = zip.getEntry(uri.fragment)
|
||||
return zip.getInputStream(entry).source()
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.runInterruptible
|
||||
import okio.IOException
|
||||
import org.koitharu.kotatsu.core.model.isLocal
|
||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||
import org.koitharu.kotatsu.core.parser.MangaIntent
|
||||
@@ -46,9 +47,15 @@ class DetailsLoadUseCase @Inject constructor(
|
||||
null
|
||||
}
|
||||
send(MangaDetails(manga, null, null, false))
|
||||
val details = getDetails(manga)
|
||||
send(MangaDetails(details, local?.peek(), details.description?.parseAsHtml(withImages = false), false))
|
||||
send(MangaDetails(details, local?.await(), details.description?.parseAsHtml(withImages = true), true))
|
||||
try {
|
||||
val details = getDetails(manga)
|
||||
send(MangaDetails(details, local?.peek(), details.description?.parseAsHtml(withImages = false), false))
|
||||
send(MangaDetails(details, local?.await(), details.description?.parseAsHtml(withImages = true), true))
|
||||
} catch (e: IOException) {
|
||||
local?.await()?.manga?.also { localManga ->
|
||||
send(MangaDetails(localManga, null, localManga.description?.parseAsHtml(withImages = false), true))
|
||||
} ?: throw e
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getDetails(seed: Manga) = runCatchingCancellable {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.koitharu.kotatsu.details.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.transition.TransitionManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -13,6 +12,7 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.text.buildSpannedString
|
||||
import androidx.core.text.color
|
||||
import androidx.core.text.method.LinkMovementMethodCompat
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updatePadding
|
||||
@@ -107,7 +107,7 @@ class DetailsFragment :
|
||||
binding.infoLayout.textViewSource.setOnClickListener(this)
|
||||
binding.textViewDescription.addOnLayoutChangeListener(this)
|
||||
binding.textViewDescription.viewTreeObserver.addOnDrawListener(this)
|
||||
binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance()
|
||||
binding.textViewDescription.movementMethod = LinkMovementMethodCompat.getInstance()
|
||||
binding.chipsTags.onChipClickListener = this
|
||||
binding.recyclerViewRelated.addItemDecoration(
|
||||
SpacingItemDecoration(resources.getDimensionPixelOffset(R.dimen.grid_spacing)),
|
||||
@@ -197,6 +197,11 @@ class DetailsFragment :
|
||||
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_state_abandoned)
|
||||
}
|
||||
|
||||
MangaState.PAUSED -> infoLayout.textViewState.apply {
|
||||
textAndVisible = resources.getString(R.string.state_paused)
|
||||
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_action_pause)
|
||||
}
|
||||
|
||||
null -> infoLayout.textViewState.isVisible = false
|
||||
}
|
||||
if (manga.source == MangaSource.LOCAL) {
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.koitharu.kotatsu.core.os.AppShortcutManager
|
||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||
import org.koitharu.kotatsu.core.util.ShareHelper
|
||||
import org.koitharu.kotatsu.download.ui.dialog.DownloadOption
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.FavouriteSheet
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.FavoriteSheet
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.scrobbling.common.ui.selector.ScrobblingSelectorSheet
|
||||
import org.koitharu.kotatsu.search.ui.multi.MultiSearchActivity
|
||||
@@ -63,7 +63,7 @@ class DetailsMenuProvider(
|
||||
|
||||
R.id.action_favourite -> {
|
||||
viewModel.manga.value?.let {
|
||||
FavouriteSheet.show(activity.supportFragmentManager, it)
|
||||
FavoriteSheet.show(activity.supportFragmentManager, it)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.koitharu.kotatsu.details.ui.scrobbling
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
@@ -12,6 +11,7 @@ import android.widget.RatingBar
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.text.method.LinkMovementMethodCompat
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import coil.ImageLoader
|
||||
@@ -71,7 +71,7 @@ class ScrobblingInfoSheet :
|
||||
binding.ratingBar.onRatingBarChangeListener = this
|
||||
binding.buttonMenu.setOnClickListener(this)
|
||||
binding.imageViewCover.setOnClickListener(this)
|
||||
binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance()
|
||||
binding.textViewDescription.movementMethod = LinkMovementMethodCompat.getInstance()
|
||||
|
||||
menu = PopupMenu(binding.root.context, binding.buttonMenu).apply {
|
||||
inflate(R.menu.opt_scrobbling)
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
||||
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||
import java.util.Collections
|
||||
import java.util.EnumSet
|
||||
import javax.inject.Inject
|
||||
@@ -43,15 +44,44 @@ class MangaSourcesRepository @Inject constructor(
|
||||
get() = Collections.unmodifiableSet(remoteSources)
|
||||
|
||||
suspend fun getEnabledSources(): List<MangaSource> {
|
||||
return dao.findAllEnabled().toSources(settings.isNsfwContentDisabled)
|
||||
val order = settings.sourcesSortOrder
|
||||
return dao.findAllEnabled(order).toSources(settings.isNsfwContentDisabled, order)
|
||||
}
|
||||
|
||||
fun observeEnabledSources(): Flow<List<MangaSource>> = observeIsNsfwDisabled().flatMapLatest { skipNsfw ->
|
||||
dao.observeEnabled().map {
|
||||
it.toSources(skipNsfw)
|
||||
}
|
||||
suspend fun getDisabledSources(): List<MangaSource> {
|
||||
return dao.findAllDisabled().toSources(settings.isNsfwContentDisabled, null)
|
||||
}
|
||||
|
||||
fun observeEnabledSourcesCount(): Flow<Int> {
|
||||
return combine(
|
||||
observeIsNsfwDisabled(),
|
||||
dao.observeEnabled(SourcesSortOrder.MANUAL),
|
||||
) { skipNsfw, sources ->
|
||||
sources.count { skipNsfw || !MangaSource(it.source).isNsfw() }
|
||||
}.distinctUntilChanged()
|
||||
}
|
||||
|
||||
fun observeAvailableSourcesCount(): Flow<Int> {
|
||||
return combine(
|
||||
observeIsNsfwDisabled(),
|
||||
dao.observeEnabled(SourcesSortOrder.MANUAL),
|
||||
) { skipNsfw, enabledSources ->
|
||||
val enabled = enabledSources.mapToSet { it.source }
|
||||
allMangaSources.count { x ->
|
||||
x.name !in enabled && (!skipNsfw || !x.isNsfw())
|
||||
}
|
||||
}.distinctUntilChanged()
|
||||
}
|
||||
|
||||
fun observeEnabledSources(): Flow<List<MangaSource>> = combine(
|
||||
observeIsNsfwDisabled(),
|
||||
observeSortOrder(),
|
||||
) { skipNsfw, order ->
|
||||
dao.observeEnabled(order).map {
|
||||
it.toSources(skipNsfw, order)
|
||||
}
|
||||
}.flatMapLatest { it }
|
||||
|
||||
fun observeAll(): Flow<List<Pair<MangaSource, Boolean>>> = dao.observeAll().map { entities ->
|
||||
val result = ArrayList<Pair<MangaSource, Boolean>>(entities.size)
|
||||
for (entity in entities) {
|
||||
@@ -146,7 +176,10 @@ class MangaSourcesRepository @Inject constructor(
|
||||
return result
|
||||
}
|
||||
|
||||
private fun List<MangaSourceEntity>.toSources(skipNsfwSources: Boolean): List<MangaSource> {
|
||||
private fun List<MangaSourceEntity>.toSources(
|
||||
skipNsfwSources: Boolean,
|
||||
sortOrder: SourcesSortOrder?,
|
||||
): List<MangaSource> {
|
||||
val result = ArrayList<MangaSource>(size)
|
||||
for (entity in this) {
|
||||
val source = MangaSource(entity.source)
|
||||
@@ -157,6 +190,9 @@ class MangaSourcesRepository @Inject constructor(
|
||||
result.add(source)
|
||||
}
|
||||
}
|
||||
if (sortOrder == SourcesSortOrder.ALPHABETIC) {
|
||||
result.sortBy { it.title }
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -167,4 +203,8 @@ class MangaSourcesRepository @Inject constructor(
|
||||
private fun observeIsNewSourcesEnabled() = settings.observeAsFlow(AppSettings.KEY_SOURCES_NEW) {
|
||||
isNewSourcesTipEnabled
|
||||
}
|
||||
|
||||
private fun observeSortOrder() = settings.observeAsFlow(AppSettings.KEY_SOURCES_ORDER) {
|
||||
sourcesSortOrder
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.koitharu.kotatsu.explore.data
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import org.koitharu.kotatsu.R
|
||||
|
||||
enum class SourcesSortOrder(
|
||||
@StringRes val titleResId: Int,
|
||||
) {
|
||||
ALPHABETIC(R.string.by_name),
|
||||
POPULARITY(R.string.popular),
|
||||
MANUAL(R.string.manual),
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import org.koitharu.kotatsu.explore.data.MangaSourcesRepository
|
||||
import org.koitharu.kotatsu.history.data.HistoryRepository
|
||||
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||
import org.koitharu.kotatsu.suggestions.domain.TagsBlacklist
|
||||
@@ -73,7 +74,15 @@ class ExploreRepository @Inject constructor(
|
||||
val tag = tags.firstNotNullOfOrNull { title ->
|
||||
availableTags.find { x -> x.title.almostEquals(title, 0.4f) }
|
||||
}
|
||||
val list = repository.getList(0, setOfNotNull(tag), order).asArrayList()
|
||||
val list = repository.getList(
|
||||
offset = 0,
|
||||
filter = MangaListFilter.Advanced(
|
||||
sortOrder = order,
|
||||
tags = setOfNotNull(tag),
|
||||
locale = null,
|
||||
states = emptySet(),
|
||||
),
|
||||
).asArrayList()
|
||||
if (settings.isSuggestionsExcludeNsfw) {
|
||||
list.removeAll { it.isNsfw }
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -18,7 +19,7 @@ class RecoverMangaUseCase @Inject constructor(
|
||||
return@runCatchingCancellable null
|
||||
}
|
||||
val repository = repositoryFactory.create(manga.source)
|
||||
val list = repository.getList(offset = 0, query = manga.title)
|
||||
val list = repository.getList(offset = 0, filter = MangaListFilter.Search(manga.title))
|
||||
val newManga = list.find { x -> x.title == manga.title }?.let {
|
||||
repository.getDetails(it)
|
||||
} ?: return@runCatchingCancellable null
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.koitharu.kotatsu.explore.ui
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
@@ -46,6 +47,7 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||
import org.koitharu.kotatsu.settings.newsources.NewSourcesDialogFragment
|
||||
import org.koitharu.kotatsu.settings.sources.catalog.SourcesCatalogActivity
|
||||
import org.koitharu.kotatsu.suggestions.ui.SuggestionsActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -83,7 +85,7 @@ class ExploreFragment :
|
||||
SpanSizeResolver(this, resources.getDimensionPixelSize(R.dimen.explore_grid_width)).attach()
|
||||
addItemDecoration(TypedListSpacingDecoration(context, false))
|
||||
}
|
||||
addMenuProvider(ExploreMenuProvider(binding.root.context, viewModel))
|
||||
addMenuProvider(ExploreMenuProvider(binding.root.context))
|
||||
viewModel.content.observe(viewLifecycleOwner) {
|
||||
exploreAdapter?.items = it
|
||||
}
|
||||
@@ -109,7 +111,7 @@ class ExploreFragment :
|
||||
}
|
||||
|
||||
override fun onListHeaderClick(item: ListHeader, view: View) {
|
||||
startActivity(SettingsActivity.newManageSourcesIntent(view.context))
|
||||
startActivity(Intent(view.context, SourcesCatalogActivity::class.java))
|
||||
}
|
||||
|
||||
override fun onPrimaryButtonClick(tipView: TipView) {
|
||||
@@ -174,7 +176,6 @@ class ExploreFragment :
|
||||
} else {
|
||||
LinearLayoutManager(requireContext())
|
||||
}
|
||||
activity?.invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
private fun showSuggestionsTip() {
|
||||
|
||||
@@ -6,10 +6,10 @@ import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import androidx.core.view.MenuProvider
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||
|
||||
class ExploreMenuProvider(
|
||||
private val context: Context,
|
||||
private val viewModel: ExploreViewModel,
|
||||
) : MenuProvider {
|
||||
|
||||
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||
@@ -18,17 +18,12 @@ class ExploreMenuProvider(
|
||||
|
||||
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||
return when (menuItem.itemId) {
|
||||
R.id.action_grid -> {
|
||||
viewModel.setGridMode(!menuItem.isChecked)
|
||||
R.id.action_manage -> {
|
||||
context.startActivity(SettingsActivity.newSourcesSettingsIntent(context))
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPrepareMenu(menu: Menu) {
|
||||
super.onPrepareMenu(menu)
|
||||
menu.findItem(R.id.action_grid)?.isChecked = viewModel.isGrid.value == true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.koitharu.kotatsu.core.ui.util.ReversibleAction
|
||||
import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
|
||||
import org.koitharu.kotatsu.core.util.ext.call
|
||||
import org.koitharu.kotatsu.explore.data.MangaSourcesRepository
|
||||
import org.koitharu.kotatsu.explore.data.SourcesSortOrder
|
||||
import org.koitharu.kotatsu.explore.domain.ExploreRepository
|
||||
import org.koitharu.kotatsu.explore.ui.model.ExploreButtons
|
||||
import org.koitharu.kotatsu.explore.ui.model.MangaSourceItem
|
||||
@@ -50,11 +51,13 @@ class ExploreViewModel @Inject constructor(
|
||||
valueProducer = { isSourcesGridMode },
|
||||
)
|
||||
|
||||
val isSuggestionsEnabled = settings.observeAsFlow(
|
||||
private val isSuggestionsEnabled = settings.observeAsFlow(
|
||||
key = AppSettings.KEY_SUGGESTIONS,
|
||||
valueProducer = { isSuggestionsEnabled },
|
||||
)
|
||||
|
||||
val sortOrder = MutableStateFlow(SourcesSortOrder.MANUAL) // TODO
|
||||
|
||||
val onOpenManga = MutableEventFlow<Manga>()
|
||||
val onActionDone = MutableEventFlow<ReversibleAction>()
|
||||
val onShowSuggestionsTip = MutableEventFlow<Unit>()
|
||||
@@ -104,10 +107,6 @@ class ExploreViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun setGridMode(value: Boolean) {
|
||||
settings.isSourcesGridMode = value
|
||||
}
|
||||
|
||||
fun respondSuggestionTip(isAccepted: Boolean) {
|
||||
settings.isSuggestionsEnabled = isAccepted
|
||||
settings.closeTip(TIP_SUGGESTIONS)
|
||||
@@ -137,7 +136,7 @@ class ExploreViewModel @Inject constructor(
|
||||
result += RecommendationsItem(recommendation)
|
||||
}
|
||||
if (sources.isNotEmpty()) {
|
||||
result += ListHeader(R.string.remote_sources, R.string.manage)
|
||||
result += ListHeader(R.string.remote_sources, R.string.catalog)
|
||||
if (newSources.isNotEmpty()) {
|
||||
result += TipModel(
|
||||
key = TIP_NEW_SOURCES,
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.swiperefreshlayout.widget.CircularProgressDrawable
|
||||
import coil.ImageLoader
|
||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.getSummary
|
||||
import org.koitharu.kotatsu.core.parser.favicon.faviconUri
|
||||
import org.koitharu.kotatsu.core.ui.image.FaviconDrawable
|
||||
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
||||
@@ -48,8 +49,8 @@ fun exploreButtonsAD(
|
||||
icon.setColorSchemeColors(
|
||||
context.getThemeColor(
|
||||
materialR.attr.colorPrimary,
|
||||
Color.DKGRAY
|
||||
)
|
||||
Color.DKGRAY,
|
||||
),
|
||||
)
|
||||
binding.buttonRandom.icon = icon
|
||||
icon.start()
|
||||
@@ -98,7 +99,7 @@ fun exploreSourceListItemAD(
|
||||
ItemExploreSourceListBinding.inflate(
|
||||
layoutInflater,
|
||||
parent,
|
||||
false
|
||||
false,
|
||||
)
|
||||
},
|
||||
on = { item, _, _ -> item is MangaSourceItem && !item.isGrid },
|
||||
@@ -112,6 +113,7 @@ fun exploreSourceListItemAD(
|
||||
|
||||
bind {
|
||||
binding.textViewTitle.text = item.source.title
|
||||
binding.textViewSubtitle.text = item.source.getSummary(context)
|
||||
val fallbackIcon = FaviconDrawable(context, R.style.FaviconDrawable_Small, item.source.name)
|
||||
binding.imageViewIcon.newImageRequest(lifecycleOwner, item.source.faviconUri())?.run {
|
||||
fallback(fallbackIcon)
|
||||
@@ -132,7 +134,7 @@ fun exploreSourceGridItemAD(
|
||||
ItemExploreSourceGridBinding.inflate(
|
||||
layoutInflater,
|
||||
parent,
|
||||
false
|
||||
false,
|
||||
)
|
||||
},
|
||||
on = { item, _, _ -> item is MangaSourceItem && item.isGrid },
|
||||
|
||||
@@ -106,6 +106,9 @@ abstract class FavouritesDao {
|
||||
@Query("SELECT DISTINCT category_id FROM favourites WHERE manga_id = :id AND deleted_at = 0")
|
||||
abstract fun observeIds(id: Long): Flow<List<Long>>
|
||||
|
||||
@Query("SELECT DISTINCT category_id FROM favourites WHERE manga_id IN (:mangaIds) AND deleted_at = 0")
|
||||
abstract suspend fun findCategoriesIds(mangaIds: Collection<Long>): List<Long>
|
||||
|
||||
/** INSERT **/
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
@@ -171,6 +174,7 @@ abstract class FavouritesDao {
|
||||
ListSortOrder.NEW_CHAPTERS -> "(SELECT chapters_new FROM tracks WHERE tracks.manga_id = manga.manga_id) DESC"
|
||||
ListSortOrder.UPDATED, // for legacy support
|
||||
ListSortOrder.PROGRESS -> "(SELECT percent FROM history WHERE history.manga_id = manga.manga_id) DESC"
|
||||
|
||||
else -> throw IllegalArgumentException("Sort order $sortOrder is not supported")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,10 @@ class FavouritesRepository @Inject constructor(
|
||||
return db.getFavouriteCategoriesDao().find(id.toInt()).toFavouriteCategory()
|
||||
}
|
||||
|
||||
suspend fun getCategoriesIds(mangaIds: Collection<Long>): Set<Long> {
|
||||
return db.getFavouritesDao().findCategoriesIds(mangaIds).toSet()
|
||||
}
|
||||
|
||||
suspend fun createCategory(
|
||||
title: String,
|
||||
sortOrder: ListSortOrder,
|
||||
|
||||
@@ -19,17 +19,12 @@ import org.koitharu.kotatsu.core.util.ext.withArgs
|
||||
import org.koitharu.kotatsu.databinding.SheetFavoriteCategoriesBinding
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.adapter.MangaCategoriesAdapter
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.model.MangaCategoryItem
|
||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
|
||||
@AndroidEntryPoint
|
||||
class FavouriteSheet :
|
||||
BaseAdaptiveSheet<SheetFavoriteCategoriesBinding>(),
|
||||
OnListItemClickListener<MangaCategoryItem> {
|
||||
class FavoriteSheet : BaseAdaptiveSheet<SheetFavoriteCategoriesBinding>(), OnListItemClickListener<MangaCategoryItem> {
|
||||
|
||||
private val viewModel: MangaCategoriesViewModel by viewModels()
|
||||
|
||||
private var adapter: MangaCategoriesAdapter? = null
|
||||
private val viewModel by viewModels<FavoriteSheetViewModel>()
|
||||
|
||||
override fun onCreateViewBinding(
|
||||
inflater: LayoutInflater,
|
||||
@@ -41,44 +36,32 @@ class FavouriteSheet :
|
||||
savedInstanceState: Bundle?,
|
||||
) {
|
||||
super.onViewBindingCreated(binding, savedInstanceState)
|
||||
adapter = MangaCategoriesAdapter(this)
|
||||
val adapter = MangaCategoriesAdapter(this)
|
||||
binding.recyclerViewCategories.adapter = adapter
|
||||
viewModel.content.observe(viewLifecycleOwner, this::onContentChanged)
|
||||
viewModel.content.observe(viewLifecycleOwner, adapter)
|
||||
viewModel.onError.observeEvent(viewLifecycleOwner, ::onError)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
adapter = null
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
override fun onItemClick(item: MangaCategoryItem, view: View) {
|
||||
viewModel.setChecked(item.category.id, !item.isChecked)
|
||||
}
|
||||
|
||||
private fun onContentChanged(categories: List<ListModel>) {
|
||||
adapter?.items = categories
|
||||
}
|
||||
|
||||
private fun onError(e: Throwable) {
|
||||
Toast.makeText(context ?: return, e.getDisplayMessage(resources), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val TAG = "FavouriteCategoriesDialog"
|
||||
private const val TAG = "FavoriteSheet"
|
||||
const val KEY_MANGA_LIST = "manga_list"
|
||||
|
||||
fun show(fm: FragmentManager, manga: Manga) = Companion.show(fm, listOf(manga))
|
||||
fun show(fm: FragmentManager, manga: Manga) = show(fm, setOf(manga))
|
||||
|
||||
fun show(fm: FragmentManager, manga: Collection<Manga>) =
|
||||
FavouriteSheet().withArgs(1) {
|
||||
putParcelableArrayList(
|
||||
KEY_MANGA_LIST,
|
||||
manga.mapTo(ArrayList(manga.size)) {
|
||||
ParcelableManga(it)
|
||||
},
|
||||
)
|
||||
}.showDistinct(fm, TAG)
|
||||
fun show(fm: FragmentManager, manga: Collection<Manga>) = FavoriteSheet().withArgs(1) {
|
||||
putParcelableArrayList(
|
||||
KEY_MANGA_LIST,
|
||||
manga.mapTo(ArrayList(manga.size), ::ParcelableManga),
|
||||
)
|
||||
}.showDistinct(fm, TAG)
|
||||
}
|
||||
}
|
||||
@@ -4,77 +4,70 @@ import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.plus
|
||||
import org.koitharu.kotatsu.core.model.ids
|
||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
||||
import org.koitharu.kotatsu.core.util.ext.firstNotNull
|
||||
import org.koitharu.kotatsu.core.util.ext.require
|
||||
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.FavouriteSheet.Companion.KEY_MANGA_LIST
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.model.CategoriesHeaderItem
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.model.MangaCategoryItem
|
||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class MangaCategoriesViewModel @Inject constructor(
|
||||
class FavoriteSheetViewModel @Inject constructor(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
private val favouritesRepository: FavouritesRepository,
|
||||
settings: AppSettings,
|
||||
) : BaseViewModel() {
|
||||
|
||||
private val manga = savedStateHandle.require<List<ParcelableManga>>(KEY_MANGA_LIST).map { it.manga }
|
||||
private val manga = savedStateHandle.require<List<ParcelableManga>>(FavoriteSheet.KEY_MANGA_LIST).mapToSet {
|
||||
it.manga
|
||||
}
|
||||
private val header = CategoriesHeaderItem()
|
||||
|
||||
val content: StateFlow<List<ListModel>> = combine(
|
||||
private val checkedCategories = MutableStateFlow<Set<Long>?>(null)
|
||||
val content = combine(
|
||||
favouritesRepository.observeCategories(),
|
||||
observeCategoriesIds(),
|
||||
) { all, checked ->
|
||||
buildList(all.size + 1) {
|
||||
checkedCategories.filterNotNull(),
|
||||
settings.observeAsFlow(AppSettings.KEY_TRACKER_ENABLED) { isTrackerEnabled },
|
||||
) { categories, checked, tracker ->
|
||||
buildList(categories.size + 1) {
|
||||
add(header)
|
||||
all.mapTo(this) {
|
||||
categories.mapTo(this) { cat ->
|
||||
MangaCategoryItem(
|
||||
category = it,
|
||||
isChecked = it.id in checked,
|
||||
isTrackerEnabled = settings.isTrackerEnabled && AppSettings.TRACK_FAVOURITES in settings.trackSources,
|
||||
category = cat,
|
||||
isChecked = cat.id in checked,
|
||||
isTrackerEnabled = tracker,
|
||||
)
|
||||
}
|
||||
}
|
||||
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, emptyList())
|
||||
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, listOf(header))
|
||||
|
||||
init {
|
||||
launchJob(Dispatchers.Default) {
|
||||
checkedCategories.value = favouritesRepository.getCategoriesIds(manga.ids())
|
||||
}
|
||||
}
|
||||
|
||||
fun setChecked(categoryId: Long, isChecked: Boolean) {
|
||||
launchJob(Dispatchers.Default) {
|
||||
val checkedIds = checkedCategories.firstNotNull()
|
||||
if (isChecked) {
|
||||
checkedCategories.value = checkedIds + categoryId
|
||||
favouritesRepository.addToCategory(categoryId, manga)
|
||||
} else {
|
||||
checkedCategories.value = checkedIds - categoryId
|
||||
favouritesRepository.removeFromCategory(categoryId, manga.ids())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeCategoriesIds() = if (manga.size == 1) {
|
||||
// Fast path
|
||||
favouritesRepository.observeCategoriesIds(manga[0].id)
|
||||
} else {
|
||||
combine(
|
||||
manga.map { favouritesRepository.observeCategoriesIds(it.id) },
|
||||
) { array ->
|
||||
val result = HashSet<Long>()
|
||||
var isFirst = true
|
||||
for (ids in array) {
|
||||
if (isFirst) {
|
||||
result.addAll(ids)
|
||||
isFirst = false
|
||||
} else {
|
||||
result.retainAll(ids.toSet())
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ class FilterAdapter(
|
||||
init {
|
||||
addDelegate(ListItemType.FILTER_SORT, filterSortDelegate(listener))
|
||||
addDelegate(ListItemType.FILTER_TAG, filterTagDelegate(listener))
|
||||
addDelegate(ListItemType.FILTER_TAG_MULTI, filterTagMultipleDelegate(listener))
|
||||
addDelegate(ListItemType.FILTER_STATE, filterStateDelegate(listener))
|
||||
addDelegate(ListItemType.HEADER, listHeaderAD(listener))
|
||||
addDelegate(ListItemType.STATE_LOADING, loadingStateAD())
|
||||
addDelegate(ListItemType.FOOTER_LOADING, loadingFooterAD())
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.widget.TextView
|
||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegate
|
||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.titleResId
|
||||
import org.koitharu.kotatsu.core.ui.model.titleRes
|
||||
import org.koitharu.kotatsu.core.util.ext.setChecked
|
||||
import org.koitharu.kotatsu.databinding.ItemCheckableMultipleBinding
|
||||
@@ -27,14 +28,48 @@ fun filterSortDelegate(
|
||||
}
|
||||
}
|
||||
|
||||
fun filterTagDelegate(
|
||||
fun filterStateDelegate(
|
||||
listener: OnFilterChangedListener,
|
||||
) = adapterDelegateViewBinding<FilterItem.Tag, ListModel, ItemCheckableMultipleBinding>(
|
||||
) = adapterDelegateViewBinding<FilterItem.State, ListModel, ItemCheckableMultipleBinding>(
|
||||
{ layoutInflater, parent -> ItemCheckableMultipleBinding.inflate(layoutInflater, parent, false) },
|
||||
) {
|
||||
|
||||
itemView.setOnClickListener {
|
||||
listener.onTagItemClick(item)
|
||||
listener.onStateItemClick(item)
|
||||
}
|
||||
|
||||
bind { payloads ->
|
||||
binding.root.setText(item.state.titleResId)
|
||||
binding.root.setChecked(item.isChecked, payloads.isNotEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
fun filterTagDelegate(
|
||||
listener: OnFilterChangedListener,
|
||||
) = adapterDelegateViewBinding<FilterItem.Tag, ListModel, ItemCheckableSingleBinding>(
|
||||
{ layoutInflater, parent -> ItemCheckableSingleBinding.inflate(layoutInflater, parent, false) },
|
||||
on = { item, _, _ -> item is FilterItem.Tag && !item.isMultiple },
|
||||
) {
|
||||
|
||||
itemView.setOnClickListener {
|
||||
listener.onTagItemClick(item, isFromChip = false)
|
||||
}
|
||||
|
||||
bind { payloads ->
|
||||
binding.root.text = item.tag.title
|
||||
binding.root.setChecked(item.isChecked, payloads.isNotEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
fun filterTagMultipleDelegate(
|
||||
listener: OnFilterChangedListener,
|
||||
) = adapterDelegateViewBinding<FilterItem.Tag, ListModel, ItemCheckableMultipleBinding>(
|
||||
{ layoutInflater, parent -> ItemCheckableMultipleBinding.inflate(layoutInflater, parent, false) },
|
||||
on = { item, _, _ -> item is FilterItem.Tag && item.isMultiple },
|
||||
) {
|
||||
|
||||
itemView.setOnClickListener {
|
||||
listener.onTagItemClick(item, isFromChip = false)
|
||||
}
|
||||
|
||||
bind { payloads ->
|
||||
|
||||
@@ -28,11 +28,11 @@ import org.koitharu.kotatsu.core.util.ext.require
|
||||
import org.koitharu.kotatsu.core.util.ext.sortedByOrdinal
|
||||
import org.koitharu.kotatsu.filter.ui.model.FilterHeaderModel
|
||||
import org.koitharu.kotatsu.filter.ui.model.FilterItem
|
||||
import org.koitharu.kotatsu.filter.ui.model.FilterState
|
||||
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||
import org.koitharu.kotatsu.list.ui.model.LoadingFooter
|
||||
import org.koitharu.kotatsu.list.ui.model.LoadingState
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.parsers.util.SuspendLazy
|
||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||
@@ -55,7 +55,8 @@ class FilterCoordinator @Inject constructor(
|
||||
|
||||
private val coroutineScope = lifecycle.lifecycleScope
|
||||
private val repository = mangaRepositoryFactory.create(savedStateHandle.require(RemoteListFragment.ARG_SOURCE))
|
||||
private val currentState = MutableStateFlow(FilterState(repository.defaultSortOrder, emptySet()))
|
||||
private val currentState =
|
||||
MutableStateFlow(MangaListFilter.Advanced(repository.defaultSortOrder, emptySet(), null, emptySet()))
|
||||
private var searchQuery = MutableStateFlow("")
|
||||
private val localTags = SuspendLazy {
|
||||
dataRepository.findTags(repository.source)
|
||||
@@ -68,7 +69,12 @@ class FilterCoordinator @Inject constructor(
|
||||
override val header: StateFlow<FilterHeaderModel> = getHeaderFlow().stateIn(
|
||||
scope = coroutineScope + Dispatchers.Default,
|
||||
started = SharingStarted.Lazily,
|
||||
initialValue = FilterHeaderModel(emptyList(), repository.defaultSortOrder, false),
|
||||
initialValue = FilterHeaderModel(
|
||||
chips = emptyList(),
|
||||
sortOrder = repository.defaultSortOrder,
|
||||
hasSelectedTags = false,
|
||||
allowMultipleTags = repository.isMultipleTagsSupported,
|
||||
),
|
||||
)
|
||||
|
||||
init {
|
||||
@@ -81,24 +87,48 @@ class FilterCoordinator @Inject constructor(
|
||||
|
||||
override fun onSortItemClick(item: FilterItem.Sort) {
|
||||
currentState.update { oldValue ->
|
||||
FilterState(item.order, oldValue.tags)
|
||||
oldValue.copy(sortOrder = item.order)
|
||||
}
|
||||
repository.defaultSortOrder = item.order
|
||||
}
|
||||
|
||||
override fun onTagItemClick(item: FilterItem.Tag) {
|
||||
override fun onTagItemClick(item: FilterItem.Tag, isFromChip: Boolean) {
|
||||
currentState.update { oldValue ->
|
||||
val newTags = if (item.isChecked) {
|
||||
val newTags = if (!item.isMultiple) {
|
||||
if (isFromChip && item.isChecked) {
|
||||
emptySet()
|
||||
} else {
|
||||
setOf(item.tag)
|
||||
}
|
||||
} else if (item.isChecked) {
|
||||
oldValue.tags - item.tag
|
||||
} else {
|
||||
oldValue.tags + item.tag
|
||||
}
|
||||
FilterState(oldValue.sortOrder, newTags)
|
||||
oldValue.copy(tags = newTags)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStateItemClick(item: FilterItem.State) {
|
||||
currentState.update { oldValue ->
|
||||
val newStates = if (item.isChecked) {
|
||||
oldValue.states - item.state
|
||||
} else {
|
||||
oldValue.states + item.state
|
||||
}
|
||||
oldValue.copy(states = newStates)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onListHeaderClick(item: ListHeader, view: View) {
|
||||
reset()
|
||||
currentState.update { oldValue ->
|
||||
oldValue.copy(
|
||||
sortOrder = oldValue.sortOrder,
|
||||
tags = if (item.payload == R.string.genres) emptySet() else oldValue.tags,
|
||||
locale = null,
|
||||
states = if (item.payload == R.string.state) emptySet() else oldValue.states,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun observeAvailableTags(): Flow<Set<MangaTag>?> = flow {
|
||||
@@ -112,13 +142,13 @@ class FilterCoordinator @Inject constructor(
|
||||
|
||||
fun setTags(tags: Set<MangaTag>) {
|
||||
currentState.update { oldValue ->
|
||||
FilterState(oldValue.sortOrder, tags)
|
||||
oldValue.copy(tags = tags)
|
||||
}
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
currentState.update { oldValue ->
|
||||
FilterState(oldValue.sortOrder, emptySet())
|
||||
oldValue.copy(oldValue.sortOrder, emptySet(), null, emptySet())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +163,12 @@ class FilterCoordinator @Inject constructor(
|
||||
observeAvailableTags(),
|
||||
) { state, available ->
|
||||
val chips = createChipsList(state, available.orEmpty(), 8)
|
||||
FilterHeaderModel(chips, state.sortOrder, state.tags.isNotEmpty())
|
||||
FilterHeaderModel(
|
||||
chips = chips,
|
||||
sortOrder = state.sortOrder,
|
||||
hasSelectedTags = state.tags.isNotEmpty(),
|
||||
allowMultipleTags = repository.isMultipleTagsSupported,
|
||||
)
|
||||
}
|
||||
|
||||
private fun getItemsFlow() = combine(
|
||||
@@ -156,7 +191,7 @@ class FilterCoordinator @Inject constructor(
|
||||
}
|
||||
|
||||
private suspend fun createChipsList(
|
||||
filterState: FilterState,
|
||||
filterState: MangaListFilter.Advanced,
|
||||
availableTags: Set<MangaTag>,
|
||||
limit: Int,
|
||||
): List<ChipsView.ChipModel> {
|
||||
@@ -205,12 +240,14 @@ class FilterCoordinator @Inject constructor(
|
||||
@WorkerThread
|
||||
private fun buildFilterList(
|
||||
allTags: TagsWrapper,
|
||||
state: FilterState,
|
||||
state: MangaListFilter.Advanced,
|
||||
query: String,
|
||||
): List<ListModel> {
|
||||
val sortOrders = repository.sortOrders.sortedByOrdinal()
|
||||
val states = repository.states
|
||||
val tags = mergeTags(state.tags, allTags.tags).toList()
|
||||
val list = ArrayList<ListModel>(tags.size + sortOrders.size + 3)
|
||||
val list = ArrayList<ListModel>(tags.size + states.size + sortOrders.size + 4)
|
||||
val isMultiTag = repository.isMultipleTagsSupported
|
||||
if (query.isEmpty()) {
|
||||
if (sortOrders.isNotEmpty()) {
|
||||
list.add(ListHeader(R.string.sort_order))
|
||||
@@ -218,10 +255,28 @@ class FilterCoordinator @Inject constructor(
|
||||
FilterItem.Sort(it, isSelected = it == state.sortOrder)
|
||||
}
|
||||
}
|
||||
if (states.isNotEmpty()) {
|
||||
list.add(
|
||||
ListHeader(
|
||||
textRes = R.string.state,
|
||||
buttonTextRes = if (state.states.isEmpty()) 0 else R.string.reset,
|
||||
payload = R.string.state,
|
||||
),
|
||||
)
|
||||
states.mapTo(list) {
|
||||
FilterItem.State(it, isChecked = it in state.states)
|
||||
}
|
||||
}
|
||||
if (allTags.isLoading || allTags.isError || tags.isNotEmpty()) {
|
||||
list.add(ListHeader(R.string.genres, if (state.tags.isEmpty()) 0 else R.string.reset))
|
||||
list.add(
|
||||
ListHeader(
|
||||
textRes = R.string.genres,
|
||||
buttonTextRes = if (state.tags.isEmpty()) 0 else R.string.reset,
|
||||
payload = R.string.genres,
|
||||
),
|
||||
)
|
||||
tags.mapTo(list) {
|
||||
FilterItem.Tag(it, isChecked = it in state.tags)
|
||||
FilterItem.Tag(it, isMultiple = isMultiTag, isChecked = it in state.tags)
|
||||
}
|
||||
}
|
||||
if (allTags.isError) {
|
||||
@@ -232,7 +287,7 @@ class FilterCoordinator @Inject constructor(
|
||||
} else {
|
||||
tags.mapNotNullTo(list) {
|
||||
if (it.title.contains(query, ignoreCase = true)) {
|
||||
FilterItem.Tag(it, isChecked = it in state.tags)
|
||||
FilterItem.Tag(it, isMultiple = isMultiTag, isChecked = it in state.tags)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
@@ -39,7 +39,8 @@ class FilterHeaderFragment : BaseFragment<FragmentFilterHeaderBinding>(), ChipsV
|
||||
if (tag == null) {
|
||||
FilterSheetFragment.show(parentFragmentManager)
|
||||
} else {
|
||||
filter.onTagItemClick(FilterItem.Tag(tag, !chip.isChecked))
|
||||
val filterItem = FilterItem.Tag(tag, filter.header.value.allowMultipleTags, !chip.isChecked)
|
||||
filter.onTagItemClick(filterItem, isFromChip = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,5 +7,7 @@ interface OnFilterChangedListener : ListHeaderClickListener {
|
||||
|
||||
fun onSortItemClick(item: FilterItem.Sort)
|
||||
|
||||
fun onTagItemClick(item: FilterItem.Tag)
|
||||
fun onTagItemClick(item: FilterItem.Tag, isFromChip: Boolean)
|
||||
|
||||
fun onStateItemClick(item: FilterItem.State)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ class FilterHeaderModel(
|
||||
val chips: Collection<ChipsView.ChipModel>,
|
||||
val sortOrder: SortOrder?,
|
||||
val hasSelectedTags: Boolean,
|
||||
val allowMultipleTags: Boolean,
|
||||
) {
|
||||
|
||||
val textSummary: String
|
||||
@@ -19,6 +20,7 @@ class FilterHeaderModel(
|
||||
other as FilterHeaderModel
|
||||
|
||||
if (chips != other.chips) return false
|
||||
if (allowMultipleTags != other.allowMultipleTags) return false
|
||||
return sortOrder == other.sortOrder
|
||||
// Not need to check hasSelectedTags
|
||||
|
||||
@@ -26,6 +28,7 @@ class FilterHeaderModel(
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = chips.hashCode()
|
||||
result = 31 * result + allowMultipleTags.hashCode()
|
||||
result = 31 * result + (sortOrder?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.filter.ui.model
|
||||
import androidx.annotation.StringRes
|
||||
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||
import org.koitharu.kotatsu.parsers.model.MangaState
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||
|
||||
@@ -28,11 +29,12 @@ sealed interface FilterItem : ListModel {
|
||||
|
||||
data class Tag(
|
||||
val tag: MangaTag,
|
||||
val isMultiple: Boolean,
|
||||
val isChecked: Boolean,
|
||||
) : FilterItem {
|
||||
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is Tag && other.tag == tag
|
||||
return other is Tag && other.isMultiple == isMultiple && other.tag == tag
|
||||
}
|
||||
|
||||
override fun getChangePayload(previousState: ListModel): Any? {
|
||||
@@ -44,6 +46,24 @@ sealed interface FilterItem : ListModel {
|
||||
}
|
||||
}
|
||||
|
||||
data class State(
|
||||
val state: MangaState,
|
||||
val isChecked: Boolean
|
||||
) : FilterItem {
|
||||
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is State && other.state == state
|
||||
}
|
||||
|
||||
override fun getChangePayload(previousState: ListModel): Any? {
|
||||
return if (previousState is State && previousState.isChecked != isChecked) {
|
||||
ListModelDiffCallback.PAYLOAD_CHECKED_CHANGED
|
||||
} else {
|
||||
super.getChangePayload(previousState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class Error(
|
||||
@StringRes val textResId: Int,
|
||||
) : FilterItem {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package org.koitharu.kotatsu.filter.ui.model
|
||||
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||
|
||||
data class FilterState(
|
||||
val sortOrder: SortOrder?,
|
||||
val tags: Set<MangaTag>,
|
||||
)
|
||||
@@ -16,6 +16,7 @@ import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||
import org.koitharu.kotatsu.core.model.findById
|
||||
import org.koitharu.kotatsu.core.model.isLocal
|
||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
||||
import org.koitharu.kotatsu.core.util.ext.mapItems
|
||||
@@ -36,6 +37,7 @@ class HistoryRepository @Inject constructor(
|
||||
private val trackingRepository: TrackingRepository,
|
||||
private val settings: AppSettings,
|
||||
private val scrobblers: Set<@JvmSuppressWildcards Scrobbler>,
|
||||
private val mangaRepository: MangaDataRepository,
|
||||
) {
|
||||
|
||||
suspend fun getList(offset: Int, limit: Int): List<Manga> {
|
||||
@@ -92,13 +94,8 @@ class HistoryRepository @Inject constructor(
|
||||
if (shouldSkip(manga)) {
|
||||
return
|
||||
}
|
||||
val tags = manga.tags.toEntities()
|
||||
db.withTransaction {
|
||||
val existing = db.getMangaDao().find(manga.id)?.manga
|
||||
if (existing == null || existing.source == manga.source.name) {
|
||||
db.getTagsDao().upsert(tags)
|
||||
db.getMangaDao().upsert(manga.toEntity(), tags)
|
||||
}
|
||||
mangaRepository.storeManga(manga)
|
||||
db.getHistoryDao().upsert(
|
||||
HistoryEntity(
|
||||
mangaId = manga.id,
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.koitharu.kotatsu.core.util.ext.viewLifecycleScope
|
||||
import org.koitharu.kotatsu.databinding.FragmentListBinding
|
||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||
import org.koitharu.kotatsu.download.ui.worker.DownloadStartedObserver
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.FavouriteSheet
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.FavoriteSheet
|
||||
import org.koitharu.kotatsu.list.ui.adapter.ListItemType
|
||||
import org.koitharu.kotatsu.list.ui.adapter.MangaListAdapter
|
||||
import org.koitharu.kotatsu.list.ui.adapter.MangaListListener
|
||||
@@ -284,7 +284,7 @@ abstract class MangaListFragment :
|
||||
}
|
||||
|
||||
R.id.action_favourite -> {
|
||||
FavouriteSheet.show(childFragmentManager, selectedItems)
|
||||
FavoriteSheet.show(childFragmentManager, selectedItems)
|
||||
mode.finish()
|
||||
true
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ enum class ListItemType {
|
||||
|
||||
FILTER_SORT,
|
||||
FILTER_TAG,
|
||||
FILTER_TAG_MULTI,
|
||||
FILTER_STATE,
|
||||
HEADER,
|
||||
MANGA_LIST,
|
||||
MANGA_LIST_DETAILED,
|
||||
|
||||
@@ -29,6 +29,8 @@ class TypedListSpacingDecoration(
|
||||
when (itemType) {
|
||||
ListItemType.FILTER_SORT,
|
||||
ListItemType.FILTER_TAG,
|
||||
ListItemType.FILTER_TAG_MULTI,
|
||||
ListItemType.FILTER_STATE,
|
||||
-> outRect.set(0)
|
||||
|
||||
ListItemType.HEADER,
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.koitharu.kotatsu.core.util.ext.require
|
||||
import org.koitharu.kotatsu.core.util.ext.sortedByOrdinal
|
||||
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||
import org.koitharu.kotatsu.list.domain.ListSortOrder
|
||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
@@ -54,7 +55,7 @@ class ListConfigViewModel @Inject constructor(
|
||||
}?.sortedByOrdinal()
|
||||
|
||||
fun getSelectedSortOrder(): ListSortOrder? = when (section) {
|
||||
is ListConfigSection.Favorites -> runBlocking { favouritesRepository.getCategory(section.categoryId).order }
|
||||
is ListConfigSection.Favorites -> getCategorySortOrder(section.categoryId)
|
||||
ListConfigSection.General -> null
|
||||
ListConfigSection.History -> settings.historySortOrder
|
||||
ListConfigSection.Suggestions -> ListSortOrder.RELEVANCE // TODO
|
||||
@@ -73,4 +74,10 @@ class ListConfigViewModel @Inject constructor(
|
||||
ListConfigSection.Suggestions -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCategorySortOrder(id: Long): ListSortOrder = runBlocking {
|
||||
runCatchingCancellable {
|
||||
favouritesRepository.getCategory(id).order
|
||||
}.getOrDefault(ListSortOrder.NEWEST)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.koitharu.kotatsu.list.ui.preview
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.text.method.LinkMovementMethodCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.viewModels
|
||||
import coil.ImageLoader
|
||||
@@ -52,7 +52,7 @@ class PreviewFragment : BaseFragment<FragmentPreviewBinding>(), View.OnClickList
|
||||
super.onViewBindingCreated(binding, savedInstanceState)
|
||||
binding.buttonClose.isVisible = activity is MangaListActivity
|
||||
binding.buttonClose.setOnClickListener(this)
|
||||
binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance()
|
||||
binding.textViewDescription.movementMethod = LinkMovementMethodCompat.getInstance()
|
||||
binding.chipsTags.onChipClickListener = this
|
||||
binding.textViewAuthor.setOnClickListener(this)
|
||||
binding.imageViewCover.setOnClickListener(this)
|
||||
@@ -98,7 +98,8 @@ class PreviewFragment : BaseFragment<FragmentPreviewBinding>(), View.OnClickList
|
||||
if (filter == null) {
|
||||
startActivity(MangaListActivity.newIntent(requireContext(), setOf(tag)))
|
||||
} else {
|
||||
filter.onTagItemClick(FilterItem.Tag(tag, false))
|
||||
val filterItem = FilterItem.Tag(tag, filter.header.value.allowMultipleTags, false)
|
||||
filter.onTagItemClick(filterItem, isFromChip = false)
|
||||
closeSelf()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,20 @@
|
||||
package org.koitharu.kotatsu.local.data
|
||||
|
||||
import android.net.Uri
|
||||
import org.koitharu.kotatsu.core.util.ext.URI_SCHEME_ZIP
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
import java.io.FilenameFilter
|
||||
import java.util.Locale
|
||||
|
||||
class CbzFilter : FileFilter, FilenameFilter {
|
||||
|
||||
override fun accept(dir: File, name: String): Boolean {
|
||||
return isFileSupported(name)
|
||||
}
|
||||
|
||||
override fun accept(pathname: File?): Boolean {
|
||||
return isFileSupported(pathname?.name ?: return false)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun isFileSupported(name: String): Boolean {
|
||||
val ext = name.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
return ext == "cbz" || ext == "zip"
|
||||
}
|
||||
|
||||
fun isUriSupported(uri: Uri): Boolean {
|
||||
val scheme = uri.scheme?.lowercase(Locale.ROOT)
|
||||
return scheme != null && scheme == "cbz" || scheme == "zip"
|
||||
}
|
||||
}
|
||||
private fun isCbzExtension(ext: String?): Boolean {
|
||||
return ext.equals("cbz", ignoreCase = true) || ext.equals("zip", ignoreCase = true)
|
||||
}
|
||||
|
||||
fun hasCbzExtension(string: String): Boolean {
|
||||
val ext = string.substringAfterLast('.', "")
|
||||
return isCbzExtension(ext)
|
||||
}
|
||||
|
||||
fun File.hasCbzExtension() = isCbzExtension(extension)
|
||||
|
||||
fun Uri.isZipUri() = scheme.let {
|
||||
it == URI_SCHEME_ZIP || it == "cbz" || it == "zip"
|
||||
}
|
||||
|
||||
@@ -1,29 +1,11 @@
|
||||
package org.koitharu.kotatsu.local.data
|
||||
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
import java.io.FilenameFilter
|
||||
import java.util.Locale
|
||||
import java.util.zip.ZipEntry
|
||||
|
||||
class ImageFileFilter : FilenameFilter, FileFilter {
|
||||
|
||||
override fun accept(dir: File, name: String): Boolean {
|
||||
val ext = name.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
return isExtensionValid(ext)
|
||||
}
|
||||
|
||||
override fun accept(pathname: File?): Boolean {
|
||||
val ext = pathname?.extension?.lowercase(Locale.ROOT) ?: return false
|
||||
return isExtensionValid(ext)
|
||||
}
|
||||
|
||||
fun accept(entry: ZipEntry): Boolean {
|
||||
val ext = entry.name.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
return isExtensionValid(ext)
|
||||
}
|
||||
|
||||
fun isExtensionValid(ext: String): Boolean {
|
||||
return ext == "png" || ext == "jpg" || ext == "jpeg" || ext == "webp"
|
||||
}
|
||||
fun hasImageExtension(string: String): Boolean {
|
||||
val ext = string.substringAfterLast('.', "")
|
||||
return ext.equals("png", ignoreCase = true) || ext.equals("jpg", ignoreCase = true)
|
||||
|| ext.equals("jpeg", ignoreCase = true) || ext.equals("webp", ignoreCase = true)
|
||||
}
|
||||
|
||||
fun hasImageExtension(file: File) = hasImageExtension(file.name)
|
||||
|
||||
@@ -14,6 +14,7 @@ import kotlinx.coroutines.runInterruptible
|
||||
import org.koitharu.kotatsu.core.model.isLocal
|
||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.util.AlphanumComparator
|
||||
import org.koitharu.kotatsu.core.util.CompositeMutex2
|
||||
import org.koitharu.kotatsu.core.util.ext.children
|
||||
import org.koitharu.kotatsu.core.util.ext.deleteAwait
|
||||
@@ -25,8 +26,10 @@ import org.koitharu.kotatsu.local.data.output.LocalMangaUtil
|
||||
import org.koitharu.kotatsu.local.domain.model.LocalManga
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaState
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||
@@ -47,7 +50,9 @@ class LocalMangaRepository @Inject constructor(
|
||||
override val source = MangaSource.LOCAL
|
||||
private val locks = CompositeMutex2<Long>()
|
||||
|
||||
override val isMultipleTagsSupported: Boolean = true
|
||||
override val sortOrders: Set<SortOrder> = EnumSet.of(SortOrder.ALPHABETICAL, SortOrder.RATING, SortOrder.NEWEST)
|
||||
override val states = emptySet<MangaState>()
|
||||
|
||||
override var defaultSortOrder: SortOrder
|
||||
get() = settings.localListOrder
|
||||
@@ -55,33 +60,32 @@ class LocalMangaRepository @Inject constructor(
|
||||
settings.localListOrder = value
|
||||
}
|
||||
|
||||
override suspend fun getList(offset: Int, query: String): List<Manga> {
|
||||
override suspend fun getList(offset: Int, filter: MangaListFilter?): List<Manga> {
|
||||
if (offset > 0) {
|
||||
return emptyList()
|
||||
}
|
||||
val list = getRawList()
|
||||
if (query.isNotEmpty()) {
|
||||
list.retainAll { x -> x.isMatchesQuery(query) }
|
||||
}
|
||||
return list.unwrap()
|
||||
}
|
||||
when (filter) {
|
||||
is MangaListFilter.Search -> {
|
||||
list.retainAll { x -> x.isMatchesQuery(filter.query) }
|
||||
}
|
||||
|
||||
override suspend fun getList(offset: Int, tags: Set<MangaTag>?, sortOrder: SortOrder?): List<Manga> {
|
||||
if (offset > 0) {
|
||||
return emptyList()
|
||||
}
|
||||
val list = getRawList()
|
||||
if (!tags.isNullOrEmpty()) {
|
||||
list.retainAll { x -> x.containsTags(tags) }
|
||||
}
|
||||
when (sortOrder) {
|
||||
SortOrder.ALPHABETICAL -> list.sortWith(compareBy(org.koitharu.kotatsu.core.util.AlphanumComparator()) { x -> x.manga.title })
|
||||
SortOrder.RATING -> list.sortByDescending { it.manga.rating }
|
||||
SortOrder.NEWEST,
|
||||
SortOrder.UPDATED,
|
||||
-> list.sortByDescending { it.createdAt }
|
||||
is MangaListFilter.Advanced -> {
|
||||
if (filter.tags.isNotEmpty()) {
|
||||
list.retainAll { x -> x.containsTags(filter.tags) }
|
||||
}
|
||||
when (filter.sortOrder) {
|
||||
SortOrder.ALPHABETICAL -> list.sortWith(compareBy(AlphanumComparator()) { x -> x.manga.title })
|
||||
SortOrder.RATING -> list.sortByDescending { it.manga.rating }
|
||||
SortOrder.NEWEST,
|
||||
SortOrder.UPDATED,
|
||||
-> list.sortByDescending { it.createdAt }
|
||||
|
||||
else -> Unit
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
null -> Unit
|
||||
}
|
||||
return list.unwrap()
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import kotlinx.coroutines.runInterruptible
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.Cache
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.util.ext.URI_SCHEME_FILE
|
||||
import org.koitharu.kotatsu.core.util.ext.computeSize
|
||||
import org.koitharu.kotatsu.core.util.ext.getStorageName
|
||||
import org.koitharu.kotatsu.core.util.ext.resolveFile
|
||||
@@ -84,7 +85,7 @@ class LocalStorageManager @Inject constructor(
|
||||
}
|
||||
|
||||
suspend fun resolveUri(uri: Uri): File? = runInterruptible(Dispatchers.IO) {
|
||||
if (uri.scheme == "file") {
|
||||
if (uri.scheme == URI_SCHEME_FILE) {
|
||||
uri.toFile()
|
||||
} else {
|
||||
uri.resolveFile(context)
|
||||
|
||||
@@ -15,9 +15,9 @@ import okio.source
|
||||
import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException
|
||||
import org.koitharu.kotatsu.core.util.ext.resolveName
|
||||
import org.koitharu.kotatsu.core.util.ext.writeAllCancellable
|
||||
import org.koitharu.kotatsu.local.data.CbzFilter
|
||||
import org.koitharu.kotatsu.local.data.LocalStorageChanges
|
||||
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
||||
import org.koitharu.kotatsu.local.data.hasCbzExtension
|
||||
import org.koitharu.kotatsu.local.data.input.LocalMangaInput
|
||||
import org.koitharu.kotatsu.local.domain.model.LocalManga
|
||||
import java.io.File
|
||||
@@ -46,7 +46,7 @@ class SingleMangaImporter @Inject constructor(
|
||||
private suspend fun importFile(uri: Uri): LocalManga = withContext(Dispatchers.IO) {
|
||||
val contentResolver = storageManager.contentResolver
|
||||
val name = contentResolver.resolveName(uri) ?: throw IOException("Cannot fetch name from uri: $uri")
|
||||
if (!CbzFilter.isFileSupported(name)) {
|
||||
if (!hasCbzExtension(name)) {
|
||||
throw UnsupportedFileException("Unsupported file on $uri")
|
||||
}
|
||||
val dest = File(getOutputDir(), name)
|
||||
|
||||
@@ -6,12 +6,12 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runInterruptible
|
||||
import org.koitharu.kotatsu.core.util.AlphanumComparator
|
||||
import org.koitharu.kotatsu.core.util.ext.creationTime
|
||||
import org.koitharu.kotatsu.core.util.ext.listFilesRecursive
|
||||
import org.koitharu.kotatsu.core.util.ext.longHashCode
|
||||
import org.koitharu.kotatsu.core.util.ext.toListSorted
|
||||
import org.koitharu.kotatsu.local.data.CbzFilter
|
||||
import org.koitharu.kotatsu.local.data.ImageFileFilter
|
||||
import org.koitharu.kotatsu.core.util.ext.walkCompat
|
||||
import org.koitharu.kotatsu.local.data.MangaIndex
|
||||
import org.koitharu.kotatsu.local.data.hasCbzExtension
|
||||
import org.koitharu.kotatsu.local.data.hasImageExtension
|
||||
import org.koitharu.kotatsu.local.data.output.LocalMangaOutput
|
||||
import org.koitharu.kotatsu.local.domain.model.LocalManga
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
@@ -91,16 +91,12 @@ class LocalMangaDirInput(root: File) : LocalMangaInput(root) {
|
||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> = runInterruptible(Dispatchers.IO) {
|
||||
val file = chapter.url.toUri().toFile()
|
||||
if (file.isDirectory) {
|
||||
file.listFilesRecursive(ImageFileFilter())
|
||||
file.walkCompat()
|
||||
.filter { hasImageExtension(it) }
|
||||
.toListSorted(compareBy(AlphanumComparator()) { x -> x.name })
|
||||
.map {
|
||||
val pageUri = it.toUri().toString()
|
||||
MangaPage(
|
||||
id = pageUri.longHashCode(),
|
||||
url = pageUri,
|
||||
preview = null,
|
||||
source = MangaSource.LOCAL,
|
||||
)
|
||||
MangaPage(pageUri.longHashCode(), pageUri, null, MangaSource.LOCAL)
|
||||
}
|
||||
} else {
|
||||
ZipFile(file).use { zip ->
|
||||
@@ -124,20 +120,20 @@ class LocalMangaDirInput(root: File) : LocalMangaInput(root) {
|
||||
|
||||
private fun String.toHumanReadable() = replace("_", " ").toCamelCase()
|
||||
|
||||
private fun getChaptersFiles(): List<File> = root.listFilesRecursive(CbzFilter())
|
||||
.toListSorted(compareBy(AlphanumComparator()) { x -> x.name })
|
||||
private fun getChaptersFiles(): List<File> = root.walkCompat()
|
||||
.filter { it.hasCbzExtension() }
|
||||
.toListSorted(compareBy(AlphanumComparator()) { it.name })
|
||||
|
||||
private fun findFirstImageEntry(): String? {
|
||||
val filter = ImageFileFilter()
|
||||
root.listFilesRecursive(filter).firstOrNull()?.let {
|
||||
return it.toUri().toString()
|
||||
}
|
||||
val cbz = root.listFilesRecursive(CbzFilter()).firstOrNull() ?: return null
|
||||
return ZipFile(cbz).use { zip ->
|
||||
zip.entries().asSequence()
|
||||
.firstOrNull { x -> !x.isDirectory && filter.accept(x) }
|
||||
?.let { entry -> zipUri(cbz, entry.name) }
|
||||
}
|
||||
return root.walkCompat().firstOrNull { hasImageExtension(it) }?.toUri()?.toString()
|
||||
?: run {
|
||||
val cbz = root.walkCompat().firstOrNull { it.hasCbzExtension() } ?: return null
|
||||
ZipFile(cbz).use { zip ->
|
||||
zip.entries().asSequence()
|
||||
.firstOrNull { !it.isDirectory && hasImageExtension(it.name) }
|
||||
?.let { zipUri(cbz, it.name) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun fileUri(base: File, name: String): String {
|
||||
|
||||
@@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koitharu.kotatsu.local.data.CbzFilter
|
||||
import org.koitharu.kotatsu.local.data.hasCbzExtension
|
||||
import org.koitharu.kotatsu.local.domain.model.LocalManga
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
@@ -39,7 +39,7 @@ sealed class LocalMangaInput(
|
||||
|
||||
fun ofOrNull(file: File): LocalMangaInput? = when {
|
||||
file.isDirectory -> LocalMangaDirInput(file)
|
||||
CbzFilter.isFileSupported(file.name) -> LocalMangaZipInput(file)
|
||||
hasCbzExtension(file.name) -> LocalMangaZipInput(file)
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.koitharu.kotatsu.local.domain
|
||||
|
||||
import org.koitharu.kotatsu.core.model.isLocal
|
||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||
import org.koitharu.kotatsu.history.data.HistoryRepository
|
||||
import org.koitharu.kotatsu.local.data.LocalMangaRepository
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -27,7 +27,7 @@ class DeleteLocalMangaUseCase @Inject constructor(
|
||||
}
|
||||
|
||||
suspend operator fun invoke(ids: Set<Long>) {
|
||||
val list = localMangaRepository.getList(0, null, null)
|
||||
val list = localMangaRepository.getList(0, null)
|
||||
var removed = 0
|
||||
for (manga in list) {
|
||||
if (manga.id in ids) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.fragment.app.commit
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.withResumed
|
||||
import androidx.transition.TransitionManager
|
||||
@@ -229,6 +230,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
||||
supportFragmentManager.commit {
|
||||
setReorderingAllowed(true)
|
||||
add(R.id.container, SearchSuggestionFragment.newInstance(), TAG_SEARCH)
|
||||
navigationDelegate.primaryFragment?.let {
|
||||
setMaxLifecycle(it, Lifecycle.State.STARTED)
|
||||
}
|
||||
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||
runOnCommit { onSearchOpened() }
|
||||
}
|
||||
@@ -414,16 +418,20 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
||||
private inner class CloseSearchCallback : OnBackPressedCallback(false) {
|
||||
|
||||
override fun handleOnBackPressed() {
|
||||
val fragment = supportFragmentManager.findFragmentByTag(TAG_SEARCH)
|
||||
val fm = supportFragmentManager
|
||||
val fragment = fm.findFragmentByTag(TAG_SEARCH)
|
||||
viewBinding.searchView.clearFocus()
|
||||
if (fragment == null) {
|
||||
// this should not happen but who knows
|
||||
isEnabled = false
|
||||
return
|
||||
}
|
||||
supportFragmentManager.commit {
|
||||
fm.commit {
|
||||
setReorderingAllowed(true)
|
||||
remove(fragment)
|
||||
navigationDelegate.primaryFragment?.let {
|
||||
setMaxLifecycle(it, Lifecycle.State.RESUMED)
|
||||
}
|
||||
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||
runOnCommit { onSearchClosed() }
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.net.Uri
|
||||
import androidx.annotation.AnyThread
|
||||
import androidx.collection.LongSparseArray
|
||||
import androidx.collection.set
|
||||
import androidx.core.net.toUri
|
||||
import dagger.hilt.android.ActivityRetainedLifecycle
|
||||
import dagger.hilt.android.lifecycle.RetainedLifecycle
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
@@ -33,17 +34,18 @@ import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.util.FileSize
|
||||
import org.koitharu.kotatsu.core.util.RetainedLifecycleCoroutineScope
|
||||
import org.koitharu.kotatsu.core.util.ext.URI_SCHEME_ZIP
|
||||
import org.koitharu.kotatsu.core.util.ext.ensureSuccess
|
||||
import org.koitharu.kotatsu.core.util.ext.exists
|
||||
import org.koitharu.kotatsu.core.util.ext.getCompletionResultOrNull
|
||||
import org.koitharu.kotatsu.core.util.ext.isNotEmpty
|
||||
import org.koitharu.kotatsu.core.util.ext.isPowerSaveMode
|
||||
import org.koitharu.kotatsu.core.util.ext.isTargetNotEmpty
|
||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||
import org.koitharu.kotatsu.core.util.ext.ramAvailable
|
||||
import org.koitharu.kotatsu.core.util.ext.withProgress
|
||||
import org.koitharu.kotatsu.core.util.progress.ProgressDeferred
|
||||
import org.koitharu.kotatsu.core.zip.ZipPool
|
||||
import org.koitharu.kotatsu.local.data.CbzFilter
|
||||
import org.koitharu.kotatsu.local.data.PagesCache
|
||||
import org.koitharu.kotatsu.local.data.isZipUri
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
||||
@@ -71,13 +73,12 @@ class PageLoader @Inject constructor(
|
||||
|
||||
val loaderScope = RetainedLifecycleCoroutineScope(lifecycle) + InternalErrorHandler() + Dispatchers.Default
|
||||
|
||||
private val tasks = LongSparseArray<ProgressDeferred<File, Float>>()
|
||||
private val tasks = LongSparseArray<ProgressDeferred<Uri, Float>>()
|
||||
private val semaphore = Semaphore(3)
|
||||
private val convertLock = Mutex()
|
||||
private val prefetchLock = Mutex()
|
||||
private var repository: MangaRepository? = null
|
||||
private val prefetchQueue = LinkedList<MangaPage>()
|
||||
private val zipPool = ZipPool(2)
|
||||
private val counter = AtomicInteger(0)
|
||||
private var prefetchQueueLimit = PREFETCH_LIMIT_DEFAULT // TODO adaptive
|
||||
|
||||
@@ -85,7 +86,6 @@ class PageLoader @Inject constructor(
|
||||
synchronized(tasks) {
|
||||
tasks.clear()
|
||||
}
|
||||
zipPool.evictAll()
|
||||
}
|
||||
|
||||
fun isPrefetchApplicable(): Boolean {
|
||||
@@ -113,7 +113,7 @@ class PageLoader @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun loadPageAsync(page: MangaPage, force: Boolean): ProgressDeferred<File, Float> {
|
||||
fun loadPageAsync(page: MangaPage, force: Boolean): ProgressDeferred<Uri, Float> {
|
||||
var task = tasks[page.id]?.takeIf { it.isValid() }
|
||||
if (force) {
|
||||
task?.cancel()
|
||||
@@ -127,7 +127,7 @@ class PageLoader @Inject constructor(
|
||||
return task
|
||||
}
|
||||
|
||||
suspend fun loadPage(page: MangaPage, force: Boolean): File {
|
||||
suspend fun loadPage(page: MangaPage, force: Boolean): Uri {
|
||||
return loadPageAsync(page, force).await()
|
||||
}
|
||||
|
||||
@@ -167,11 +167,11 @@ class PageLoader @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadPageAsyncImpl(page: MangaPage, skipCache: Boolean): ProgressDeferred<File, Float> {
|
||||
private fun loadPageAsyncImpl(page: MangaPage, skipCache: Boolean): ProgressDeferred<Uri, Float> {
|
||||
val progress = MutableStateFlow(PROGRESS_UNDEFINED)
|
||||
val deferred = loaderScope.async {
|
||||
if (!skipCache) {
|
||||
cache.get(page.url)?.let { return@async it }
|
||||
cache.get(page.url)?.let { return@async it.toUri() }
|
||||
}
|
||||
counter.incrementAndGet()
|
||||
try {
|
||||
@@ -195,26 +195,24 @@ class PageLoader @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun loadPageImpl(page: MangaPage, progress: MutableStateFlow<Float>): File = semaphore.withPermit {
|
||||
private suspend fun loadPageImpl(page: MangaPage, progress: MutableStateFlow<Float>): Uri = semaphore.withPermit {
|
||||
val pageUrl = getPageUrl(page)
|
||||
check(pageUrl.isNotBlank()) { "Cannot obtain full image url" }
|
||||
val uri = Uri.parse(pageUrl)
|
||||
return if (CbzFilter.isUriSupported(uri)) {
|
||||
runInterruptible(Dispatchers.IO) {
|
||||
zipPool[uri]
|
||||
}.use {
|
||||
cache.put(pageUrl, it)
|
||||
return if (uri.isZipUri()) {
|
||||
if (uri.scheme == URI_SCHEME_ZIP) {
|
||||
uri
|
||||
} else { // legacy uri
|
||||
uri.buildUpon().scheme(URI_SCHEME_ZIP).build()
|
||||
}
|
||||
} else {
|
||||
val request = createPageRequest(page, pageUrl)
|
||||
imageProxyInterceptor.interceptPageRequest(request, okHttp).ensureSuccess().use { response ->
|
||||
val body = checkNotNull(response.body) {
|
||||
"Null response"
|
||||
}
|
||||
val body = checkNotNull(response.body) { "Null response body" }
|
||||
body.withProgress(progress).use {
|
||||
cache.put(pageUrl, it.source())
|
||||
}
|
||||
}
|
||||
}.toUri()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,9 +220,9 @@ class PageLoader @Inject constructor(
|
||||
return context.ramAvailable <= FileSize.MEGABYTES.convert(PREFETCH_MIN_RAM_MB, FileSize.BYTES)
|
||||
}
|
||||
|
||||
private fun Deferred<File>.isValid(): Boolean {
|
||||
return getCompletionResultOrNull()?.map { file ->
|
||||
file.exists() && file.isNotEmpty()
|
||||
private fun Deferred<Uri>.isValid(): Boolean {
|
||||
return getCompletionResultOrNull()?.map { uri ->
|
||||
uri.exists() && uri.isTargetNotEmpty()
|
||||
}?.getOrDefault(false) ?: true
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okio.IOException
|
||||
import okio.buffer
|
||||
import okio.sink
|
||||
import okio.source
|
||||
import org.koitharu.kotatsu.core.util.ext.source
|
||||
import org.koitharu.kotatsu.core.util.ext.toFileOrNull
|
||||
import org.koitharu.kotatsu.core.util.ext.writeAllCancellable
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.parsers.util.toFileNameSafe
|
||||
@@ -41,8 +42,8 @@ class PageSaveHelper @Inject constructor(
|
||||
saveLauncher: ActivityResultLauncher<String>,
|
||||
): Uri {
|
||||
val pageUrl = pageLoader.getPageUrl(page)
|
||||
val pageFile = pageLoader.loadPage(page, force = false)
|
||||
val proposedName = getProposedFileName(pageUrl, pageFile)
|
||||
val pageUri = pageLoader.loadPage(page, force = false)
|
||||
val proposedName = getProposedFileName(pageUrl, pageUri)
|
||||
val destination = withContext(Dispatchers.Main) {
|
||||
suspendCancellableCoroutine { cont ->
|
||||
continuation = cont
|
||||
@@ -54,7 +55,7 @@ class PageSaveHelper @Inject constructor(
|
||||
runInterruptible(Dispatchers.IO) {
|
||||
contentResolver.openOutputStream(destination)?.sink()?.buffer()
|
||||
}?.use { output ->
|
||||
pageFile.source().use { input ->
|
||||
pageUri.source().use { input ->
|
||||
output.writeAllCancellable(input)
|
||||
}
|
||||
} ?: throw IOException("Output stream is null")
|
||||
@@ -65,7 +66,7 @@ class PageSaveHelper @Inject constructor(
|
||||
resume(uri)
|
||||
} != null
|
||||
|
||||
private suspend fun getProposedFileName(url: String, file: File): String {
|
||||
private suspend fun getProposedFileName(url: String, fileUri: Uri): String {
|
||||
var name = if (url.startsWith("cbz://")) {
|
||||
requireNotNull(url.toUri().fragment)
|
||||
} else {
|
||||
@@ -74,7 +75,7 @@ class PageSaveHelper @Inject constructor(
|
||||
var extension = name.substringAfterLast('.', "")
|
||||
name = name.substringBeforeLast('.')
|
||||
if (extension.length !in 2..4) {
|
||||
val mimeType = getImageMimeType(file)
|
||||
val mimeType = fileUri.toFileOrNull()?.let { file -> getImageMimeType(file) }
|
||||
extension = if (mimeType != null) {
|
||||
MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType) ?: EXTENSION_FALLBACK
|
||||
} else {
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.koitharu.kotatsu.core.parser.MangaIntent
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||
import org.koitharu.kotatsu.core.ui.BaseFullscreenActivity
|
||||
import org.koitharu.kotatsu.core.ui.widgets.ZoomControl
|
||||
import org.koitharu.kotatsu.core.util.GridTouchHelper
|
||||
import org.koitharu.kotatsu.core.util.IdlingDetector
|
||||
import org.koitharu.kotatsu.core.util.ShareHelper
|
||||
@@ -73,7 +74,8 @@ class ReaderActivity :
|
||||
ReaderConfigSheet.Callback,
|
||||
ReaderControlDelegate.OnInteractionListener,
|
||||
OnApplyWindowInsetsListener,
|
||||
IdlingDetector.Callback {
|
||||
IdlingDetector.Callback,
|
||||
ZoomControl.ZoomControlListener {
|
||||
|
||||
@Inject
|
||||
lateinit var settings: AppSettings
|
||||
@@ -111,6 +113,7 @@ class ReaderActivity :
|
||||
controlDelegate = ReaderControlDelegate(resources, settings, this, this)
|
||||
viewBinding.toolbarBottom.setOnMenuItemClickListener(::onOptionsItemSelected)
|
||||
viewBinding.slider.setLabelFormatter(PageLabelFormatter())
|
||||
viewBinding.zoomControl.listener = this
|
||||
ReaderSliderListener(this, viewModel).attachToSlider(viewBinding.slider)
|
||||
insetsDelegate.interceptingWindowInsetsListener = this
|
||||
idlingDetector.bindToLifecycle(this)
|
||||
@@ -146,6 +149,9 @@ class ReaderActivity :
|
||||
.setAnchorView(viewBinding.appbarBottom)
|
||||
.show()
|
||||
}
|
||||
viewModel.isZoomControlsEnabled.observe(this) {
|
||||
viewBinding.zoomControl.isVisible = it
|
||||
}
|
||||
}
|
||||
|
||||
override fun getParentActivityIntent(): Intent? {
|
||||
@@ -163,6 +169,14 @@ class ReaderActivity :
|
||||
viewModel.saveCurrentState(readerManager.currentReader?.getCurrentState())
|
||||
}
|
||||
|
||||
override fun onZoomIn() {
|
||||
readerManager.currentReader?.onZoomIn()
|
||||
}
|
||||
|
||||
override fun onZoomOut() {
|
||||
readerManager.currentReader?.onZoomOut()
|
||||
}
|
||||
|
||||
private fun onInitReader(mode: ReaderMode?) {
|
||||
if (mode == null) {
|
||||
return
|
||||
@@ -293,15 +307,13 @@ class ReaderActivity :
|
||||
private fun onPageSaved(uri: Uri?) {
|
||||
if (uri != null) {
|
||||
Snackbar.make(viewBinding.container, R.string.page_saved, Snackbar.LENGTH_LONG)
|
||||
.setAnchorView(viewBinding.appbarBottom)
|
||||
.setAction(R.string.share) {
|
||||
ShareHelper(this).shareImage(uri)
|
||||
}.show()
|
||||
}
|
||||
} else {
|
||||
Snackbar.make(viewBinding.container, R.string.error_occurred, Snackbar.LENGTH_SHORT)
|
||||
.setAnchorView(viewBinding.appbarBottom)
|
||||
.show()
|
||||
}
|
||||
}.setAnchorView(viewBinding.appbarBottom)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun setWindowSecure(isSecure: Boolean) {
|
||||
|
||||
@@ -118,17 +118,16 @@ class ReaderViewModel @Inject constructor(
|
||||
valueProducer = { isReaderKeepScreenOn },
|
||||
)
|
||||
|
||||
val isWebtoonZoomEnabled = settings.observeAsStateFlow(
|
||||
scope = viewModelScope + Dispatchers.Default,
|
||||
key = AppSettings.KEY_WEBTOON_ZOOM,
|
||||
valueProducer = { isWebtoonZoomEnable },
|
||||
)
|
||||
val isWebtoonZooEnabled = observeIsWebtoonZoomEnabled()
|
||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, false)
|
||||
|
||||
val isZoomControlEnabled = settings.observeAsStateFlow(
|
||||
scope = viewModelScope + Dispatchers.Default,
|
||||
key = AppSettings.KEY_READER_ZOOM_BUTTONS,
|
||||
valueProducer = { isReaderZoomButtonsEnabled },
|
||||
)
|
||||
val isZoomControlsEnabled = getObserveIsZoomControlEnabled().flatMapLatest { zoom ->
|
||||
if (zoom) {
|
||||
combine(readerMode, isWebtoonZooEnabled) { mode, ze -> ze || mode != ReaderMode.WEBTOON }
|
||||
} else {
|
||||
flowOf(false)
|
||||
}
|
||||
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, false)
|
||||
|
||||
val readerSettings = ReaderSettings(
|
||||
parentScope = viewModelScope,
|
||||
@@ -259,10 +258,13 @@ class ReaderViewModel @Inject constructor(
|
||||
@MainThread
|
||||
fun onCurrentPageChanged(position: Int) {
|
||||
val prevJob = stateChangeJob
|
||||
val pages = content.value.pages // capture immediately
|
||||
stateChangeJob = launchJob(Dispatchers.Default) {
|
||||
prevJob?.cancelAndJoin()
|
||||
loadingJob?.join()
|
||||
val pages = content.value.pages
|
||||
if (pages.size != content.value.pages.size) {
|
||||
return@launchJob // TODO
|
||||
}
|
||||
pages.getOrNull(position)?.let { page ->
|
||||
currentState.update { cs ->
|
||||
cs?.copy(chapterId = page.chapterId, page = page.index)
|
||||
@@ -402,4 +404,14 @@ class ReaderViewModel @Inject constructor(
|
||||
val ppc = 1f / chaptersCount
|
||||
return ppc * chapterIndex + ppc * pagePercent
|
||||
}
|
||||
|
||||
private fun observeIsWebtoonZoomEnabled() = settings.observeAsFlow(
|
||||
key = AppSettings.KEY_WEBTOON_ZOOM,
|
||||
valueProducer = { isWebtoonZoomEnable },
|
||||
)
|
||||
|
||||
private fun getObserveIsZoomControlEnabled() = settings.observeAsFlow(
|
||||
key = AppSettings.KEY_READER_ZOOM_BUTTONS,
|
||||
valueProducer = { isReaderZoomButtonsEnabled },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -47,7 +47,10 @@ class ReaderConfigSheet :
|
||||
|
||||
private val viewModel by activityViewModels<ReaderViewModel>()
|
||||
private val savePageRequest = registerForActivityResult(PageSaveContract(), this)
|
||||
private var orientationHelper: ScreenOrientationHelper? = null
|
||||
|
||||
@Inject
|
||||
lateinit var orientationHelper: ScreenOrientationHelper
|
||||
|
||||
private lateinit var mode: ReaderMode
|
||||
|
||||
@Inject
|
||||
@@ -113,7 +116,7 @@ class ReaderConfigSheet :
|
||||
}
|
||||
|
||||
R.id.button_screen_rotate -> {
|
||||
orientationHelper?.toggleOrientation()
|
||||
orientationHelper.isLandscape = !orientationHelper.isLandscape
|
||||
}
|
||||
|
||||
R.id.button_color_filter -> {
|
||||
@@ -128,9 +131,13 @@ class ReaderConfigSheet :
|
||||
when (buttonView.id) {
|
||||
R.id.switch_scroll_timer -> {
|
||||
findCallback()?.isAutoScrollEnabled = isChecked
|
||||
requireViewBinding().labelTimer.isVisible = isChecked
|
||||
requireViewBinding().layoutTimer.isVisible = isChecked
|
||||
requireViewBinding().sliderTimer.isVisible = isChecked
|
||||
}
|
||||
|
||||
R.id.switch_screen_lock_rotation -> {
|
||||
orientationHelper.isLocked = isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,6 +166,7 @@ class ReaderConfigSheet :
|
||||
if (fromUser) {
|
||||
settings.readerAutoscrollSpeed = value
|
||||
}
|
||||
(viewBinding ?: return).labelTimerValue.text = getString(R.string.speed_value, value * 10f)
|
||||
}
|
||||
|
||||
override fun onActivityResult(result: Uri?) {
|
||||
@@ -167,14 +175,23 @@ class ReaderConfigSheet :
|
||||
}
|
||||
|
||||
private fun observeScreenOrientation() {
|
||||
val helper = ScreenOrientationHelper(requireActivity())
|
||||
orientationHelper = helper
|
||||
helper.observeAutoOrientation()
|
||||
orientationHelper.observeAutoOrientation()
|
||||
.onEach {
|
||||
requireViewBinding().buttonScreenRotate.isGone = it
|
||||
with(requireViewBinding()) {
|
||||
buttonScreenRotate.isGone = it
|
||||
switchScreenLockRotation.isVisible = it
|
||||
updateOrientationLockSwitch()
|
||||
}
|
||||
}.launchIn(viewLifecycleScope)
|
||||
}
|
||||
|
||||
private fun updateOrientationLockSwitch() {
|
||||
val switch = viewBinding?.switchScreenLockRotation ?: return
|
||||
switch.setOnCheckedChangeListener(null)
|
||||
switch.isChecked = orientationHelper.isLocked
|
||||
switch.setOnCheckedChangeListener(this)
|
||||
}
|
||||
|
||||
private fun findCallback(): Callback? {
|
||||
return (parentFragment as? Callback) ?: (activity as? Callback)
|
||||
}
|
||||
|
||||
@@ -36,6 +36,9 @@ class ReaderSettings(
|
||||
val colorFilter: ReaderColorFilter?
|
||||
get() = colorFilterFlow.value?.takeUnless { it.isEmpty }
|
||||
|
||||
val isReaderOptimizationEnabled: Boolean
|
||||
get() = settings.isReaderOptimizationEnabled
|
||||
|
||||
val bitmapConfig: Bitmap.Config
|
||||
get() = if (settings.is32BitColorsEnabled) {
|
||||
Bitmap.Config.ARGB_8888
|
||||
@@ -46,9 +49,6 @@ class ReaderSettings(
|
||||
val isPagesNumbersEnabled: Boolean
|
||||
get() = settings.isPagesNumbersEnabled
|
||||
|
||||
val isZoomControlsEnabled: Boolean
|
||||
get() = settings.isReaderZoomButtonsEnabled
|
||||
|
||||
fun applyBackground(view: View) {
|
||||
val bg = settings.readerBackground
|
||||
view.background = bg.resolve(view.context)
|
||||
@@ -106,10 +106,9 @@ class ReaderSettings(
|
||||
if (
|
||||
key == AppSettings.KEY_ZOOM_MODE ||
|
||||
key == AppSettings.KEY_PAGES_NUMBERS ||
|
||||
key == AppSettings.KEY_WEBTOON_ZOOM ||
|
||||
key == AppSettings.KEY_READER_ZOOM_BUTTONS ||
|
||||
key == AppSettings.KEY_READER_BACKGROUND ||
|
||||
key == AppSettings.KEY_32BIT_COLOR
|
||||
key == AppSettings.KEY_32BIT_COLOR ||
|
||||
key == AppSettings.KEY_READER_OPTIMIZE
|
||||
) {
|
||||
notifyChanged()
|
||||
}
|
||||
|
||||
@@ -2,13 +2,16 @@ package org.koitharu.kotatsu.reader.ui.pager
|
||||
|
||||
import android.content.Context
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||
import org.koitharu.kotatsu.core.os.NetworkState
|
||||
import org.koitharu.kotatsu.core.ui.list.lifecycle.LifecycleAwareViewHolder
|
||||
import org.koitharu.kotatsu.core.util.ext.isLowRamDevice
|
||||
import org.koitharu.kotatsu.databinding.LayoutPageInfoBinding
|
||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||
import org.koitharu.kotatsu.reader.ui.pager.PageHolderDelegate.State
|
||||
|
||||
abstract class BasePageHolder<B : ViewBinding>(
|
||||
protected val binding: B,
|
||||
@@ -16,7 +19,8 @@ abstract class BasePageHolder<B : ViewBinding>(
|
||||
protected val settings: ReaderSettings,
|
||||
networkState: NetworkState,
|
||||
exceptionResolver: ExceptionResolver,
|
||||
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
||||
lifecycleOwner: LifecycleOwner,
|
||||
) : LifecycleAwareViewHolder(binding.root, lifecycleOwner), PageHolderDelegate.Callback {
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
protected val delegate = PageHolderDelegate(loader, settings, this, networkState, exceptionResolver)
|
||||
@@ -43,6 +47,13 @@ abstract class BasePageHolder<B : ViewBinding>(
|
||||
|
||||
protected abstract fun onBind(data: ReaderPage)
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (delegate.state == State.ERROR && !delegate.isLoading()) {
|
||||
boundData?.let { delegate.retry(it.toMangaPage(), isFromUser = false) }
|
||||
}
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
open fun onAttachedToWindow() {
|
||||
delegate.onAttachedToWindow()
|
||||
@@ -57,4 +68,10 @@ abstract class BasePageHolder<B : ViewBinding>(
|
||||
open fun onRecycled() {
|
||||
delegate.onRecycle()
|
||||
}
|
||||
|
||||
protected fun getBackgroundDownsampling() = when {
|
||||
!settings.isReaderOptimizationEnabled -> 1
|
||||
context.isLowRamDevice() -> 8
|
||||
else -> 4
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.fragment.app.activityViewModels
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
|
||||
import org.koitharu.kotatsu.core.ui.BaseFragment
|
||||
import org.koitharu.kotatsu.core.ui.widgets.ZoomControl
|
||||
import org.koitharu.kotatsu.core.util.ext.getParcelableCompat
|
||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||
import org.koitharu.kotatsu.core.util.ext.observe
|
||||
@@ -14,7 +15,7 @@ import org.koitharu.kotatsu.reader.ui.ReaderViewModel
|
||||
|
||||
private const val KEY_STATE = "state"
|
||||
|
||||
abstract class BaseReaderFragment<B : ViewBinding> : BaseFragment<B>() {
|
||||
abstract class BaseReaderFragment<B : ViewBinding> : BaseFragment<B>(), ZoomControl.ZoomControlListener {
|
||||
|
||||
protected val viewModel by activityViewModels<ReaderViewModel>()
|
||||
private var stateToSave: ReaderState? = null
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.koitharu.kotatsu.reader.ui.pager
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.core.net.toFile
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.Observer
|
||||
import com.davemorrissey.labs.subscaleview.DefaultOnImageEventListener
|
||||
@@ -20,10 +21,10 @@ import kotlinx.coroutines.yield
|
||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||
import org.koitharu.kotatsu.core.os.NetworkState
|
||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||
import org.koitharu.kotatsu.core.util.ext.toFileOrNull
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
class PageHolderDelegate(
|
||||
@@ -35,15 +36,20 @@ class PageHolderDelegate(
|
||||
) : DefaultOnImageEventListener, Observer<ReaderSettings> {
|
||||
|
||||
private val scope = loader.loaderScope + Dispatchers.Main.immediate
|
||||
private var state = State.EMPTY
|
||||
var state = State.EMPTY
|
||||
private set
|
||||
private var job: Job? = null
|
||||
private var file: File? = null
|
||||
private var uri: Uri? = null
|
||||
private var error: Throwable? = null
|
||||
|
||||
init {
|
||||
callback.onConfigChanged()
|
||||
scope.launch(Dispatchers.Main) { // the same as post() -- wait until child fields init
|
||||
callback.onConfigChanged()
|
||||
}
|
||||
}
|
||||
|
||||
fun isLoading() = job?.isActive == true
|
||||
|
||||
fun onBind(page: MangaPage) {
|
||||
val prevJob = job
|
||||
job = scope.launch {
|
||||
@@ -52,12 +58,15 @@ class PageHolderDelegate(
|
||||
}
|
||||
}
|
||||
|
||||
fun retry(page: MangaPage) {
|
||||
fun retry(page: MangaPage, isFromUser: Boolean) {
|
||||
val prevJob = job
|
||||
job = scope.launch {
|
||||
prevJob?.cancelAndJoin()
|
||||
val e = error
|
||||
if (e != null && ExceptionResolver.canResolve(e)) {
|
||||
if (!isFromUser) {
|
||||
return@launch
|
||||
}
|
||||
exceptionResolver.resolve(e)
|
||||
}
|
||||
doLoad(page, force = true)
|
||||
@@ -79,15 +88,15 @@ class PageHolderDelegate(
|
||||
|
||||
fun onRecycle() {
|
||||
state = State.EMPTY
|
||||
file = null
|
||||
uri = null
|
||||
error = null
|
||||
job?.cancel()
|
||||
}
|
||||
|
||||
fun reload() {
|
||||
if (state == State.SHOWN ) {
|
||||
file?.let {
|
||||
callback.onImageReady(it.toUri())
|
||||
if (state == State.SHOWN) {
|
||||
uri?.let {
|
||||
callback.onImageReady(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,10 +115,10 @@ class PageHolderDelegate(
|
||||
|
||||
override fun onImageLoadError(e: Throwable) {
|
||||
e.printStackTraceDebug()
|
||||
val file = this.file
|
||||
val uri = this.uri
|
||||
error = e
|
||||
if (state == State.LOADED && e is IOException && file != null && file.exists()) {
|
||||
tryConvert(file, e)
|
||||
if (state == State.LOADED && e is IOException && uri != null && uri.toFileOrNull()?.exists() != false) {
|
||||
tryConvert(uri, e)
|
||||
} else {
|
||||
state = State.ERROR
|
||||
callback.onError(e)
|
||||
@@ -123,12 +132,13 @@ class PageHolderDelegate(
|
||||
callback.onConfigChanged()
|
||||
}
|
||||
|
||||
private fun tryConvert(file: File, e: Exception) {
|
||||
private fun tryConvert(uri: Uri, e: Exception) {
|
||||
val prevJob = job
|
||||
job = scope.launch {
|
||||
prevJob?.join()
|
||||
state = State.CONVERTING
|
||||
try {
|
||||
val file = uri.toFile()
|
||||
loader.convertInPlace(file)
|
||||
state = State.CONVERTED
|
||||
callback.onImageReady(file.toUri())
|
||||
@@ -149,14 +159,14 @@ class PageHolderDelegate(
|
||||
yield()
|
||||
try {
|
||||
val task = loader.loadPageAsync(data, force)
|
||||
file = coroutineScope {
|
||||
uri = coroutineScope {
|
||||
val progressObserver = observeProgress(this, task.progressAsFlow())
|
||||
val file = task.await()
|
||||
progressObserver.cancelAndJoin()
|
||||
file
|
||||
}
|
||||
state = State.LOADED
|
||||
callback.onImageReady(checkNotNull(file).toUri())
|
||||
callback.onImageReady(checkNotNull(uri))
|
||||
} catch (e: CancellationException) {
|
||||
throw e
|
||||
} catch (e: Throwable) {
|
||||
@@ -166,7 +176,7 @@ class PageHolderDelegate(
|
||||
callback.onError(e)
|
||||
if (e is IOException && !networkState.value) {
|
||||
networkState.awaitForConnection()
|
||||
retry(data)
|
||||
retry(data, isFromUser = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,7 +186,7 @@ class PageHolderDelegate(
|
||||
.onEach { callback.onProgressChanged((100 * it).toInt()) }
|
||||
.launchIn(scope)
|
||||
|
||||
private enum class State {
|
||||
enum class State {
|
||||
EMPTY, LOADING, LOADED, CONVERTING, CONVERTED, SHOWING, SHOWN, ERROR
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,15 @@ import android.view.ViewGroup
|
||||
import androidx.core.view.children
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.yield
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.os.NetworkState
|
||||
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
|
||||
import org.koitharu.kotatsu.core.ui.list.lifecycle.PagerLifecycleDispatcher
|
||||
import org.koitharu.kotatsu.core.util.ext.doOnPageChanged
|
||||
import org.koitharu.kotatsu.core.util.ext.findCurrentViewHolder
|
||||
import org.koitharu.kotatsu.core.util.ext.observe
|
||||
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
||||
import org.koitharu.kotatsu.core.util.ext.resetTransformations
|
||||
@@ -28,6 +30,7 @@ import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
|
||||
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderFragment
|
||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
||||
import org.koitharu.kotatsu.reader.ui.pager.standard.NoAnimPageTransformer
|
||||
import org.koitharu.kotatsu.reader.ui.pager.standard.PageHolder
|
||||
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerEventSupplier
|
||||
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
|
||||
import javax.inject.Inject
|
||||
@@ -44,6 +47,8 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
||||
@Inject
|
||||
lateinit var pageLoader: PageLoader
|
||||
|
||||
private var pagerLifecycleDispatcher: PagerLifecycleDispatcher? = null
|
||||
|
||||
override fun onCreateViewBinding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
@@ -60,6 +65,9 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
||||
recyclerView?.defaultFocusHighlightEnabled = false
|
||||
}
|
||||
PagerEventSupplier(this).attach()
|
||||
pagerLifecycleDispatcher = PagerLifecycleDispatcher(this).also {
|
||||
registerOnPageChangeCallback(it)
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.pageAnimation.observe(viewLifecycleOwner) {
|
||||
@@ -78,6 +86,7 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
pagerLifecycleDispatcher = null
|
||||
requireViewBinding().pager.adapter = null
|
||||
super.onDestroyView()
|
||||
}
|
||||
@@ -104,6 +113,15 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
||||
exceptionResolver = exceptionResolver,
|
||||
)
|
||||
|
||||
override fun onZoomIn() {
|
||||
(viewBinding?.pager?.findCurrentViewHolder() as? PageHolder)?.onZoomIn()
|
||||
}
|
||||
|
||||
override fun onZoomOut() {
|
||||
(viewBinding?.pager?.findCurrentViewHolder() as? PageHolder)?.onZoomOut()
|
||||
}
|
||||
|
||||
|
||||
override fun switchPageBy(delta: Int) {
|
||||
with(requireViewBinding().pager) {
|
||||
setCurrentItem(currentItem - delta, isAnimationEnabled())
|
||||
@@ -121,15 +139,16 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
||||
|
||||
override suspend fun onPagesChanged(pages: List<ReaderPage>, pendingState: ReaderState?) = coroutineScope {
|
||||
val reversedPages = pages.asReversed()
|
||||
val items = async {
|
||||
val items = launch {
|
||||
requireAdapter().setItems(reversedPages)
|
||||
yield()
|
||||
pagerLifecycleDispatcher?.invalidate()
|
||||
}
|
||||
if (pendingState != null) {
|
||||
val position = reversedPages.indexOfLast {
|
||||
it.chapterId == pendingState.chapterId && it.index == pendingState.page
|
||||
}
|
||||
items.await()
|
||||
items.join()
|
||||
if (position != -1) {
|
||||
requireViewBinding().pager.setCurrentItem(position, false)
|
||||
notifyPageChanged(position)
|
||||
@@ -138,7 +157,7 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
||||
.show()
|
||||
}
|
||||
} else {
|
||||
items.await()
|
||||
items.join()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
||||
import android.graphics.PointF
|
||||
import android.net.Uri
|
||||
import android.view.View
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.davemorrissey.labs.subscaleview.ImageSource
|
||||
@@ -12,6 +13,7 @@ import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||
import org.koitharu.kotatsu.core.model.ZoomMode
|
||||
import org.koitharu.kotatsu.core.os.NetworkState
|
||||
import org.koitharu.kotatsu.core.ui.widgets.ZoomControl
|
||||
import org.koitharu.kotatsu.core.util.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.core.util.ext.ifZero
|
||||
import org.koitharu.kotatsu.core.util.ext.isLowRamDevice
|
||||
@@ -28,8 +30,9 @@ open class PageHolder(
|
||||
settings: ReaderSettings,
|
||||
networkState: NetworkState,
|
||||
exceptionResolver: ExceptionResolver,
|
||||
) : BasePageHolder<ItemPageBinding>(binding, loader, settings, networkState, exceptionResolver),
|
||||
View.OnClickListener {
|
||||
) : BasePageHolder<ItemPageBinding>(binding, loader, settings, networkState, exceptionResolver, owner),
|
||||
View.OnClickListener,
|
||||
ZoomControl.ZoomControlListener {
|
||||
|
||||
init {
|
||||
binding.ssiv.bindToLifecycle(owner)
|
||||
@@ -40,16 +43,24 @@ open class PageHolder(
|
||||
@Suppress("LeakingThis")
|
||||
bindingInfo.buttonErrorDetails.setOnClickListener(this)
|
||||
binding.textViewNumber.isVisible = settings.isPagesNumbersEnabled
|
||||
binding.zoomControl.listener = SsivZoomListener(binding.ssiv)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
binding.ssiv.downsampling = 1
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
binding.ssiv.downsampling = getBackgroundDownsampling()
|
||||
}
|
||||
|
||||
override fun onConfigChanged() {
|
||||
super.onConfigChanged()
|
||||
binding.zoomControl.isVisible = settings.isZoomControlsEnabled
|
||||
@Suppress("SENSELESS_COMPARISON")
|
||||
if (settings.applyBitmapConfig(binding.ssiv) && delegate != null) {
|
||||
if (settings.applyBitmapConfig(binding.ssiv)) {
|
||||
delegate.reload()
|
||||
}
|
||||
binding.ssiv.downsampling = if (isResumed()) 1 else getBackgroundDownsampling()
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@@ -128,7 +139,7 @@ open class PageHolder(
|
||||
|
||||
final override fun onClick(v: View) {
|
||||
when (v.id) {
|
||||
R.id.button_retry -> delegate.retry(boundData?.toMangaPage() ?: return)
|
||||
R.id.button_retry -> delegate.retry(boundData?.toMangaPage() ?: return, isFromUser = true)
|
||||
R.id.button_error_details -> delegate.showErrorDetails(boundData?.url)
|
||||
}
|
||||
}
|
||||
@@ -141,4 +152,23 @@ open class PageHolder(
|
||||
bindingInfo.layoutError.isVisible = true
|
||||
bindingInfo.progressBar.hide()
|
||||
}
|
||||
|
||||
override fun onZoomIn() {
|
||||
scaleBy(1.2f)
|
||||
}
|
||||
|
||||
override fun onZoomOut() {
|
||||
scaleBy(0.8f)
|
||||
}
|
||||
|
||||
private fun scaleBy(factor: Float) {
|
||||
val ssiv = binding.ssiv
|
||||
val center = ssiv.getCenter() ?: return
|
||||
val newScale = ssiv.scale * factor
|
||||
ssiv.animateScaleAndCenter(newScale, center)?.apply {
|
||||
withDuration(ssiv.resources.getInteger(android.R.integer.config_shortAnimTime).toLong())
|
||||
withInterpolator(DecelerateInterpolator())
|
||||
start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,15 @@ import android.view.ViewGroup
|
||||
import androidx.core.view.children
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.yield
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.os.NetworkState
|
||||
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
|
||||
import org.koitharu.kotatsu.core.ui.list.lifecycle.PagerLifecycleDispatcher
|
||||
import org.koitharu.kotatsu.core.util.ext.doOnPageChanged
|
||||
import org.koitharu.kotatsu.core.util.ext.findCurrentViewHolder
|
||||
import org.koitharu.kotatsu.core.util.ext.observe
|
||||
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
||||
import org.koitharu.kotatsu.core.util.ext.resetTransformations
|
||||
@@ -41,6 +43,8 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>(),
|
||||
@Inject
|
||||
lateinit var pageLoader: PageLoader
|
||||
|
||||
private var pagerLifecycleDispatcher: PagerLifecycleDispatcher? = null
|
||||
|
||||
override fun onCreateViewBinding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
@@ -60,6 +64,9 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>(),
|
||||
recyclerView?.defaultFocusHighlightEnabled = false
|
||||
}
|
||||
PagerEventSupplier(this).attach()
|
||||
pagerLifecycleDispatcher = PagerLifecycleDispatcher(this).also {
|
||||
registerOnPageChangeCallback(it)
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.pageAnimation.observe(viewLifecycleOwner) {
|
||||
@@ -78,10 +85,19 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>(),
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
pagerLifecycleDispatcher = null
|
||||
requireViewBinding().pager.adapter = null
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
override fun onZoomIn() {
|
||||
(viewBinding?.pager?.findCurrentViewHolder() as? PageHolder)?.onZoomIn()
|
||||
}
|
||||
|
||||
override fun onZoomOut() {
|
||||
(viewBinding?.pager?.findCurrentViewHolder() as? PageHolder)?.onZoomOut()
|
||||
}
|
||||
|
||||
override fun onGenericMotion(v: View?, event: MotionEvent): Boolean {
|
||||
if (event.source and InputDevice.SOURCE_CLASS_POINTER != 0) {
|
||||
if (event.actionMasked == MotionEvent.ACTION_SCROLL) {
|
||||
@@ -98,15 +114,16 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>(),
|
||||
|
||||
override suspend fun onPagesChanged(pages: List<ReaderPage>, pendingState: ReaderState?) =
|
||||
coroutineScope {
|
||||
val items = async {
|
||||
val items = launch {
|
||||
requireAdapter().setItems(pages)
|
||||
yield()
|
||||
pagerLifecycleDispatcher?.invalidate()
|
||||
}
|
||||
if (pendingState != null) {
|
||||
val position = pages.indexOfFirst {
|
||||
it.chapterId == pendingState.chapterId && it.index == pendingState.page
|
||||
}
|
||||
items.await()
|
||||
items.join()
|
||||
if (position != -1) {
|
||||
requireViewBinding().pager.setCurrentItem(position, false)
|
||||
notifyPageChanged(position)
|
||||
@@ -115,7 +132,7 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>(),
|
||||
.show()
|
||||
}
|
||||
} else {
|
||||
items.await()
|
||||
items.join()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.koitharu.kotatsu.reader.ui.pager.standard
|
||||
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
import org.koitharu.kotatsu.core.ui.widgets.ZoomControl
|
||||
|
||||
class SsivZoomListener(
|
||||
private val ssiv: SubsamplingScaleImageView,
|
||||
) : ZoomControl.ZoomControlListener {
|
||||
|
||||
override fun onZoomIn() {
|
||||
scaleBy(1.2f)
|
||||
}
|
||||
|
||||
override fun onZoomOut() {
|
||||
scaleBy(0.8f)
|
||||
}
|
||||
|
||||
private fun scaleBy(factor: Float) {
|
||||
val center = ssiv.getCenter() ?: return
|
||||
val newScale = ssiv.scale * factor
|
||||
ssiv.animateScaleAndCenter(newScale, center)?.apply {
|
||||
withDuration(ssiv.resources.getInteger(android.R.integer.config_shortAnimTime).toLong())
|
||||
withInterpolator(DecelerateInterpolator())
|
||||
start()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class WebtoonHolder(
|
||||
settings: ReaderSettings,
|
||||
networkState: NetworkState,
|
||||
exceptionResolver: ExceptionResolver,
|
||||
) : BasePageHolder<ItemPageWebtoonBinding>(binding, loader, settings, networkState, exceptionResolver),
|
||||
) : BasePageHolder<ItemPageWebtoonBinding>(binding, loader, settings, networkState, exceptionResolver, owner),
|
||||
View.OnClickListener {
|
||||
|
||||
private var scrollToRestore = 0
|
||||
@@ -40,10 +40,20 @@ class WebtoonHolder(
|
||||
|
||||
override fun onConfigChanged() {
|
||||
super.onConfigChanged()
|
||||
@Suppress("SENSELESS_COMPARISON")
|
||||
if (settings.applyBitmapConfig(binding.ssiv) && delegate != null) {
|
||||
if (settings.applyBitmapConfig(binding.ssiv)) {
|
||||
delegate.reload()
|
||||
}
|
||||
// FIXME binding.ssiv.downsampling = if (isResumed()) 1 else getBackgroundDownsampling()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
binding.ssiv.downsampling = 1
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
// FIXME binding.ssiv.downsampling = getBackgroundDownsampling()
|
||||
}
|
||||
|
||||
override fun onBind(data: ReaderPage) {
|
||||
@@ -107,7 +117,7 @@ class WebtoonHolder(
|
||||
|
||||
override fun onClick(v: View) {
|
||||
when (v.id) {
|
||||
R.id.button_retry -> delegate.retry(boundData?.toMangaPage() ?: return)
|
||||
R.id.button_retry -> delegate.retry(boundData?.toMangaPage() ?: return, isFromUser = true)
|
||||
R.id.button_error_details -> delegate.showErrorDetails(boundData?.url)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,14 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.yield
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.os.NetworkState
|
||||
import org.koitharu.kotatsu.core.ui.list.lifecycle.RecyclerViewLifecycleDispatcher
|
||||
import org.koitharu.kotatsu.core.util.ext.findCenterViewPosition
|
||||
import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition
|
||||
import org.koitharu.kotatsu.core.util.ext.observe
|
||||
@@ -35,6 +34,8 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
||||
|
||||
private val scrollInterpolator = DecelerateInterpolator()
|
||||
|
||||
private var recyclerLifecycleDispatcher: RecyclerViewLifecycleDispatcher? = null
|
||||
|
||||
override fun onCreateViewBinding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
@@ -46,19 +47,17 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
||||
setHasFixedSize(true)
|
||||
adapter = readerAdapter
|
||||
addOnPageScrollListener(PageScrollListener())
|
||||
recyclerLifecycleDispatcher = RecyclerViewLifecycleDispatcher().also {
|
||||
addOnScrollListener(it)
|
||||
}
|
||||
}
|
||||
binding.zoomControl.listener = binding.frame
|
||||
|
||||
viewModel.isWebtoonZoomEnabled.observe(viewLifecycleOwner) {
|
||||
viewModel.isWebtoonZooEnabled.observe(viewLifecycleOwner) {
|
||||
binding.frame.isZoomEnable = it
|
||||
}
|
||||
combine(viewModel.isWebtoonZoomEnabled, viewModel.isZoomControlEnabled, Boolean::and)
|
||||
.observe(viewLifecycleOwner) {
|
||||
binding.zoomControl.isVisible = it
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
recyclerLifecycleDispatcher = null
|
||||
requireViewBinding().recyclerView.adapter = null
|
||||
super.onDestroyView()
|
||||
}
|
||||
@@ -72,15 +71,18 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
||||
)
|
||||
|
||||
override suspend fun onPagesChanged(pages: List<ReaderPage>, pendingState: ReaderState?) = coroutineScope {
|
||||
val setItems = async {
|
||||
val setItems = launch {
|
||||
requireAdapter().setItems(pages)
|
||||
yield()
|
||||
viewBinding?.recyclerView?.let { rv ->
|
||||
recyclerLifecycleDispatcher?.invalidate(rv)
|
||||
}
|
||||
}
|
||||
if (pendingState != null) {
|
||||
val position = pages.indexOfFirst {
|
||||
it.chapterId == pendingState.chapterId && it.index == pendingState.page
|
||||
}
|
||||
setItems.await()
|
||||
setItems.join()
|
||||
if (position != -1) {
|
||||
with(requireViewBinding().recyclerView) {
|
||||
firstVisibleItemPosition = position
|
||||
@@ -95,7 +97,7 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
||||
.show()
|
||||
}
|
||||
} else {
|
||||
setItems.await()
|
||||
setItems.join()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +113,14 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
||||
)
|
||||
}
|
||||
|
||||
override fun onZoomIn() {
|
||||
viewBinding?.frame?.onZoomIn()
|
||||
}
|
||||
|
||||
override fun onZoomOut() {
|
||||
viewBinding?.frame?.onZoomOut()
|
||||
}
|
||||
|
||||
private fun notifyPageChanged(page: Int) {
|
||||
viewModel.onCurrentPageChanged(page)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
||||
private val targetHitRect = Rect()
|
||||
private var animator: ValueAnimator? = null
|
||||
|
||||
var isZoomEnable = true
|
||||
var isZoomEnable = false
|
||||
set(value) {
|
||||
field = value
|
||||
if (scale != 1f) {
|
||||
|
||||
@@ -19,8 +19,8 @@ import okio.source
|
||||
import org.koitharu.kotatsu.core.network.ImageProxyInterceptor
|
||||
import org.koitharu.kotatsu.core.network.MangaHttpClient
|
||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||
import org.koitharu.kotatsu.local.data.CbzFilter
|
||||
import org.koitharu.kotatsu.local.data.PagesCache
|
||||
import org.koitharu.kotatsu.local.data.isZipUri
|
||||
import org.koitharu.kotatsu.local.data.util.withExtraCloseable
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.parsers.util.mimeType
|
||||
@@ -56,7 +56,7 @@ class MangaPageFetcher(
|
||||
|
||||
private suspend fun loadPage(pageUrl: String): SourceResult {
|
||||
val uri = pageUrl.toUri()
|
||||
return if (CbzFilter.isUriSupported(uri)) {
|
||||
return if (uri.isZipUri()) {
|
||||
runInterruptible(Dispatchers.IO) {
|
||||
val zip = ZipFile(uri.schemeSpecificPart)
|
||||
val entry = zip.getEntry(uri.fragment)
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.koitharu.kotatsu.download.ui.worker.DownloadWorker
|
||||
import org.koitharu.kotatsu.explore.domain.ExploreRepository
|
||||
import org.koitharu.kotatsu.filter.ui.FilterCoordinator
|
||||
import org.koitharu.kotatsu.filter.ui.MangaFilter
|
||||
import org.koitharu.kotatsu.filter.ui.model.FilterState
|
||||
import org.koitharu.kotatsu.list.domain.ListExtraProvider
|
||||
import org.koitharu.kotatsu.list.ui.MangaListViewModel
|
||||
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
||||
@@ -40,6 +39,7 @@ import org.koitharu.kotatsu.list.ui.model.toErrorFooter
|
||||
import org.koitharu.kotatsu.list.ui.model.toErrorState
|
||||
import org.koitharu.kotatsu.list.ui.model.toUi
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import javax.inject.Inject
|
||||
@@ -122,7 +122,7 @@ open class RemoteListViewModel @Inject constructor(
|
||||
applyFilter(tags)
|
||||
}
|
||||
|
||||
protected fun loadList(filterState: FilterState, append: Boolean): Job {
|
||||
protected fun loadList(filterState: MangaListFilter.Advanced, append: Boolean): Job {
|
||||
loadingJob?.let {
|
||||
if (it.isActive) return it
|
||||
}
|
||||
@@ -131,8 +131,7 @@ open class RemoteListViewModel @Inject constructor(
|
||||
listError.value = null
|
||||
val list = repository.getList(
|
||||
offset = if (append) mangaList.value?.size ?: 0 else 0,
|
||||
sortOrder = filterState.sortOrder,
|
||||
tags = filterState.tags,
|
||||
filter = filterState,
|
||||
)
|
||||
val oldList = mangaList.getAndUpdate { oldList ->
|
||||
if (!append || oldList.isNullOrEmpty()) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.koitharu.kotatsu.list.ui.model.toErrorFooter
|
||||
import org.koitharu.kotatsu.list.ui.model.toErrorState
|
||||
import org.koitharu.kotatsu.list.ui.model.toUi
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
@@ -101,7 +102,7 @@ class SearchViewModel @Inject constructor(
|
||||
listError.value = null
|
||||
val list = repository.getList(
|
||||
offset = if (append) mangaList.value?.size ?: 0 else 0,
|
||||
query = query,
|
||||
filter = MangaListFilter.Search(query)
|
||||
)
|
||||
if (!append) {
|
||||
mangaList.value = list
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.view.ActionMode
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.view.updatePadding
|
||||
import coil.ImageLoader
|
||||
@@ -26,7 +25,7 @@ import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||
import org.koitharu.kotatsu.databinding.ActivitySearchMultiBinding
|
||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||
import org.koitharu.kotatsu.download.ui.worker.DownloadStartedObserver
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.FavouriteSheet
|
||||
import org.koitharu.kotatsu.favourites.ui.categories.select.FavoriteSheet
|
||||
import org.koitharu.kotatsu.list.ui.MangaSelectionDecoration
|
||||
import org.koitharu.kotatsu.list.ui.adapter.MangaListListener
|
||||
import org.koitharu.kotatsu.list.ui.adapter.TypedListSpacingDecoration
|
||||
@@ -159,7 +158,7 @@ class MultiSearchActivity :
|
||||
}
|
||||
|
||||
R.id.action_favourite -> {
|
||||
FavouriteSheet.show(supportFragmentManager, collectSelectedItems())
|
||||
FavoriteSheet.show(supportFragmentManager, collectSelectedItems())
|
||||
mode.finish()
|
||||
true
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.koitharu.kotatsu.list.ui.model.LoadingFooter
|
||||
import org.koitharu.kotatsu.list.ui.model.LoadingState
|
||||
import org.koitharu.kotatsu.list.ui.model.toUi
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -115,7 +116,7 @@ class MultiSearchViewModel @Inject constructor(
|
||||
launch {
|
||||
val item = runCatchingCancellable {
|
||||
semaphore.withPermit {
|
||||
mangaRepositoryFactory.create(source).getList(offset = 0, query = q)
|
||||
mangaRepositoryFactory.create(source).getList(offset = 0, filter = MangaListFilter.Search(q))
|
||||
.toUi(ListMode.GRID, extraProvider)
|
||||
}
|
||||
}.fold(
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.lifecycle.LifecycleOwner
|
||||
import coil.ImageLoader
|
||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.getSummary
|
||||
import org.koitharu.kotatsu.core.parser.favicon.faviconUri
|
||||
import org.koitharu.kotatsu.core.ui.image.FaviconDrawable
|
||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
||||
@@ -40,6 +41,7 @@ fun searchSuggestionSourceAD(
|
||||
} else {
|
||||
item.source.title
|
||||
}
|
||||
binding.textViewSubtitle.text = item.source.getSummary(context)
|
||||
binding.switchLocal.isChecked = item.isEnabled
|
||||
val fallbackIcon = FaviconDrawable(context, R.style.FaviconDrawable_Small, item.source.name)
|
||||
binding.imageViewCover.newImageRequest(lifecycleOwner, item.source.faviconUri())?.run {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.koitharu.kotatsu.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
@@ -9,7 +8,6 @@ import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.app.LocaleManagerCompat
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.Preference
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
@@ -18,16 +16,16 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
||||
import org.koitharu.kotatsu.core.ui.BasePreferenceFragment
|
||||
import org.koitharu.kotatsu.core.ui.util.ActivityRecreationHandle
|
||||
import org.koitharu.kotatsu.core.util.LocaleComparator
|
||||
import org.koitharu.kotatsu.core.util.ext.getLocalesConfig
|
||||
import org.koitharu.kotatsu.core.util.ext.map
|
||||
import org.koitharu.kotatsu.core.util.ext.postDelayed
|
||||
import org.koitharu.kotatsu.core.util.ext.setDefaultValueCompat
|
||||
import org.koitharu.kotatsu.core.util.ext.sortedWithSafe
|
||||
import org.koitharu.kotatsu.core.util.ext.toList
|
||||
import org.koitharu.kotatsu.parsers.util.names
|
||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||
import org.koitharu.kotatsu.settings.utils.ActivityListPreference
|
||||
import org.koitharu.kotatsu.settings.utils.SliderPreference
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
@@ -110,7 +108,7 @@ class AppearanceSettingsFragment :
|
||||
private fun initLocalePicker(preference: ListPreference) {
|
||||
val locales = preference.context.getLocalesConfig()
|
||||
.toList()
|
||||
.sortedWith(LocaleComparator(preference.context))
|
||||
.sortedWithSafe(LocaleComparator())
|
||||
preference.entries = Array(locales.size + 1) { i ->
|
||||
if (i == 0) {
|
||||
getString(R.string.automatic)
|
||||
@@ -134,24 +132,4 @@ class AppearanceSettingsFragment :
|
||||
getString(it.title)
|
||||
}
|
||||
}
|
||||
|
||||
private class LocaleComparator(context: Context) : Comparator<Locale> {
|
||||
|
||||
private val deviceLocales = LocaleManagerCompat.getSystemLocales(context)
|
||||
.map { it.language }
|
||||
|
||||
override fun compare(a: Locale, b: Locale): Int {
|
||||
return if (a === b) {
|
||||
0
|
||||
} else {
|
||||
val indexA = deviceLocales.indexOf(a.language)
|
||||
val indexB = deviceLocales.indexOf(b.language)
|
||||
if (indexA == -1 && indexB == -1) {
|
||||
compareValues(a.language, b.language)
|
||||
} else {
|
||||
-2 - (indexA - indexB)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.plus
|
||||
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
||||
@@ -18,7 +17,6 @@ class RootSettingsViewModel @Inject constructor(
|
||||
|
||||
val totalSourcesCount = sourcesRepository.allMangaSources.size
|
||||
|
||||
val enabledSourcesCount = sourcesRepository.observeEnabledSources()
|
||||
.map { it.size }
|
||||
val enabledSourcesCount = sourcesRepository.observeEnabledSourcesCount()
|
||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, -1)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,8 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.settings.about.AboutSettingsFragment
|
||||
import org.koitharu.kotatsu.settings.about.AppUpdateDialog
|
||||
import org.koitharu.kotatsu.settings.sources.SourceSettingsFragment
|
||||
import org.koitharu.kotatsu.settings.sources.SourcesManageFragment
|
||||
import org.koitharu.kotatsu.settings.sources.SourcesSettingsFragment
|
||||
import org.koitharu.kotatsu.settings.sources.manage.SourcesManageFragment
|
||||
import org.koitharu.kotatsu.settings.tracker.TrackerSettingsFragment
|
||||
import org.koitharu.kotatsu.settings.userdata.UserDataSettingsFragment
|
||||
|
||||
@@ -153,6 +154,7 @@ class SettingsActivity :
|
||||
ACTION_SUGGESTIONS -> SuggestionsSettingsFragment()
|
||||
ACTION_HISTORY -> UserDataSettingsFragment()
|
||||
ACTION_TRACKER -> TrackerSettingsFragment()
|
||||
ACTION_SOURCES -> SourcesSettingsFragment()
|
||||
ACTION_MANAGE_DOWNLOADS -> DownloadsSettingsFragment()
|
||||
ACTION_SOURCE -> SourceSettingsFragment.newInstance(
|
||||
intent.getSerializableExtraCompat(EXTRA_SOURCE) as? MangaSource ?: MangaSource.LOCAL,
|
||||
@@ -182,6 +184,7 @@ class SettingsActivity :
|
||||
private const val ACTION_TRACKER = "${BuildConfig.APPLICATION_ID}.action.MANAGE_TRACKER"
|
||||
private const val ACTION_HISTORY = "${BuildConfig.APPLICATION_ID}.action.MANAGE_HISTORY"
|
||||
private const val ACTION_SOURCE = "${BuildConfig.APPLICATION_ID}.action.MANAGE_SOURCE_SETTINGS"
|
||||
private const val ACTION_SOURCES = "${BuildConfig.APPLICATION_ID}.action.MANAGE_SOURCES"
|
||||
private const val ACTION_MANAGE_SOURCES = "${BuildConfig.APPLICATION_ID}.action.MANAGE_SOURCES_LIST"
|
||||
private const val ACTION_MANAGE_DOWNLOADS = "${BuildConfig.APPLICATION_ID}.action.MANAGE_DOWNLOADS"
|
||||
private const val EXTRA_SOURCE = "source"
|
||||
@@ -206,6 +209,10 @@ class SettingsActivity :
|
||||
Intent(context, SettingsActivity::class.java)
|
||||
.setAction(ACTION_HISTORY)
|
||||
|
||||
fun newSourcesSettingsIntent(context: Context) =
|
||||
Intent(context, SettingsActivity::class.java)
|
||||
.setAction(ACTION_SOURCES)
|
||||
|
||||
fun newManageSourcesIntent(context: Context) =
|
||||
Intent(context, SettingsActivity::class.java)
|
||||
.setAction(ACTION_MANAGE_SOURCES)
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.koitharu.kotatsu.core.ui.AlertDialogFragment
|
||||
import org.koitharu.kotatsu.core.util.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.core.util.ext.observe
|
||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||
import org.koitharu.kotatsu.core.util.ext.tryLaunch
|
||||
import org.koitharu.kotatsu.databinding.DialogProgressBinding
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
@@ -28,7 +29,7 @@ class BackupDialogFragment : AlertDialogFragment<DialogProgressBinding>() {
|
||||
|
||||
private var backup: File? = null
|
||||
private val saveFileContract = registerForActivityResult(
|
||||
ActivityResultContracts.CreateDocument("*/*"),
|
||||
ActivityResultContracts.CreateDocument("application/zip"),
|
||||
) { uri ->
|
||||
val file = backup
|
||||
if (uri != null && file != null) {
|
||||
@@ -81,7 +82,10 @@ class BackupDialogFragment : AlertDialogFragment<DialogProgressBinding>() {
|
||||
|
||||
private fun onBackupDone(file: File) {
|
||||
this.backup = file
|
||||
saveFileContract.launch(file.name)
|
||||
if (!saveFileContract.tryLaunch(file.name)) {
|
||||
Toast.makeText(requireContext(), R.string.operation_not_supported, Toast.LENGTH_SHORT).show()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveBackup(file: File, output: Uri) {
|
||||
@@ -91,7 +95,7 @@ class BackupDialogFragment : AlertDialogFragment<DialogProgressBinding>() {
|
||||
it.write(file.readBytes())
|
||||
}
|
||||
}
|
||||
Toast.makeText(requireContext(), R.string.backup_saved, Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(requireContext(), R.string.backup_saved, Toast.LENGTH_SHORT).show()
|
||||
dismiss()
|
||||
} catch (e: InterruptedException) {
|
||||
throw e
|
||||
|
||||
@@ -16,15 +16,11 @@ import androidx.work.workDataOf
|
||||
import dagger.Reusable
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedInject
|
||||
import okio.buffer
|
||||
import okio.sink
|
||||
import okio.source
|
||||
import org.koitharu.kotatsu.core.backup.BackupRepository
|
||||
import org.koitharu.kotatsu.core.backup.BackupZipOutput
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.util.ext.awaitUniqueWorkInfoByName
|
||||
import org.koitharu.kotatsu.core.util.ext.deleteAwait
|
||||
import org.koitharu.kotatsu.core.util.ext.writeAllCancellable
|
||||
import org.koitharu.kotatsu.settings.work.PeriodicWorkScheduler
|
||||
import java.util.Date
|
||||
import java.util.concurrent.TimeUnit
|
||||
@@ -52,12 +48,10 @@ class PeriodicalBackupWorker @AssistedInject constructor(
|
||||
}
|
||||
val dirUri = settings.periodicalBackupOutput ?: return Result.success(resultData)
|
||||
val target = DocumentFile.fromTreeUri(applicationContext, dirUri)
|
||||
?.createFile("application/zip", file.name)
|
||||
?.createFile("application/zip", file.nameWithoutExtension)
|
||||
?.uri ?: return Result.failure()
|
||||
applicationContext.contentResolver.openOutputStream(target)?.use { output ->
|
||||
file.source().use { input ->
|
||||
output.sink().buffer().writeAllCancellable(input)
|
||||
}
|
||||
applicationContext.contentResolver.openOutputStream(target, "wt")?.use { output ->
|
||||
file.inputStream().copyTo(output)
|
||||
} ?: return Result.failure()
|
||||
file.deleteAwait()
|
||||
return Result.success(resultData)
|
||||
@@ -79,6 +73,7 @@ class PeriodicalBackupWorker @AssistedInject constructor(
|
||||
settings.periodicalBackupFrequency,
|
||||
TimeUnit.DAYS,
|
||||
).setConstraints(constraints.build())
|
||||
.keepResultsForAtLeast(20, TimeUnit.DAYS)
|
||||
.addTag(TAG)
|
||||
.build()
|
||||
workManager
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user