Compare commits
94 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
4bb0d52217 | ||
|
|
66de4bd49e | ||
|
|
ff12d63696 | ||
|
|
c168a841f3 | ||
|
|
8bfb676e6a | ||
|
|
d5c0ce280e | ||
|
|
b34627c361 | ||
|
|
cbc3be056a | ||
|
|
d9acc4ec18 | ||
|
|
577cc848ee | ||
|
|
8a64c88a07 | ||
|
|
1cd7745e38 | ||
|
|
395b3f7200 | ||
|
|
b8db4c81d8 | ||
|
|
98bd42f3ae | ||
|
|
db8835a7b8 | ||
|
|
afe50a9ed6 | ||
|
|
beba818f57 | ||
|
|
beb17ef442 | ||
|
|
24f1546019 | ||
|
|
1b0fed5c56 | ||
|
|
3d32bd9d58 | ||
|
|
590120433c | ||
|
|
4bd7656681 | ||
|
|
2c7438e64d | ||
|
|
665bebaa7b | ||
|
|
6ed5994726 | ||
|
|
311ed865b7 | ||
|
|
b59fb678fe | ||
|
|
ed9ebdcc55 | ||
|
|
74569615e3 | ||
|
|
f3c320a90f | ||
|
|
a3012ab458 | ||
|
|
6ec58879fd | ||
|
|
571cf08c53 | ||
|
|
fca53eee7a | ||
|
|
ed9e2eb4d2 | ||
|
|
c0e94f8415 | ||
|
|
e172d619a1 | ||
|
|
d6c64fc638 | ||
|
|
37404cb9a6 | ||
|
|
9d5271ff26 | ||
|
|
5f59432e48 | ||
|
|
5c082b5cdb |
@@ -16,11 +16,12 @@ android {
|
|||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdk = 21
|
minSdk = 21
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 587
|
versionCode = 598
|
||||||
versionName = '6.2'
|
versionName = '6.3.1'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "org.koitharu.kotatsu.HiltTestRunner"
|
testInstrumentationRunner "org.koitharu.kotatsu.HiltTestRunner"
|
||||||
ksp {
|
ksp {
|
||||||
|
// arg("room.generateKotlin", "true") TODO: enable later
|
||||||
arg("room.schemaLocation", "$projectDir/schemas")
|
arg("room.schemaLocation", "$projectDir/schemas")
|
||||||
}
|
}
|
||||||
androidResources {
|
androidResources {
|
||||||
@@ -32,7 +33,6 @@ android {
|
|||||||
applicationIdSuffix = '.debug'
|
applicationIdSuffix = '.debug'
|
||||||
}
|
}
|
||||||
release {
|
release {
|
||||||
multiDexEnabled false
|
|
||||||
minifyEnabled true
|
minifyEnabled true
|
||||||
shrinkResources true
|
shrinkResources true
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
@@ -47,11 +47,12 @@ android {
|
|||||||
main.java.srcDirs += 'src/main/kotlin/'
|
main.java.srcDirs += 'src/main/kotlin/'
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_17
|
coreLibraryDesugaringEnabled true
|
||||||
targetCompatibility JavaVersion.VERSION_17
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||||
freeCompilerArgs += [
|
freeCompilerArgs += [
|
||||||
'-opt-in=kotlin.ExperimentalStdlibApi',
|
'-opt-in=kotlin.ExperimentalStdlibApi',
|
||||||
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
||||||
@@ -81,24 +82,25 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
//noinspection GradleDependency
|
//noinspection GradleDependency
|
||||||
implementation('com.github.KotatsuApp:kotatsu-parsers:a61e441e79') {
|
implementation('com.github.KotatsuApp:kotatsu-parsers:c3613f3ba4') {
|
||||||
exclude group: 'org.json', module: 'json'
|
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 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.core:core-ktx:1.12.0'
|
implementation 'androidx.core:core-ktx:1.12.0'
|
||||||
implementation 'androidx.activity:activity-ktx:1.8.0'
|
implementation 'androidx.activity:activity-ktx:1.8.1'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.6.1'
|
implementation 'androidx.fragment:fragment-ktx:1.6.2'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
|
||||||
implementation 'androidx.lifecycle:lifecycle-service:2.6.2'
|
implementation 'androidx.lifecycle:lifecycle-service:2.6.2'
|
||||||
implementation 'androidx.lifecycle:lifecycle-process:2.6.2'
|
implementation 'androidx.lifecycle:lifecycle-process:2.6.2'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.3.1'
|
implementation 'androidx.recyclerview:recyclerview:1.3.2'
|
||||||
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta02'
|
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta02'
|
||||||
implementation 'androidx.preference:preference-ktx:1.2.1'
|
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||||
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
||||||
@@ -114,12 +116,12 @@ dependencies {
|
|||||||
exclude group: 'com.google.j2objc', module: 'j2objc-annotations'
|
exclude group: 'com.google.j2objc', module: 'j2objc-annotations'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation 'androidx.room:room-runtime:2.5.2'
|
implementation 'androidx.room:room-runtime:2.6.0'
|
||||||
implementation 'androidx.room:room-ktx:2.5.2'
|
implementation 'androidx.room:room-ktx:2.6.0'
|
||||||
ksp 'androidx.room:room-compiler:2.5.2'
|
ksp 'androidx.room:room-compiler:2.6.0'
|
||||||
|
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
|
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
||||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.11.0'
|
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.12.0'
|
||||||
implementation 'com.squareup.okio:okio:3.6.0'
|
implementation 'com.squareup.okio:okio:3.6.0'
|
||||||
|
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
||||||
@@ -127,22 +129,22 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'com.google.dagger:hilt-android:2.48.1'
|
implementation 'com.google.dagger:hilt-android:2.48.1'
|
||||||
kapt 'com.google.dagger:hilt-compiler:2.48.1'
|
kapt 'com.google.dagger:hilt-compiler:2.48.1'
|
||||||
implementation 'androidx.hilt:hilt-work:1.0.0'
|
implementation 'androidx.hilt:hilt-work:1.1.0'
|
||||||
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
kapt 'androidx.hilt:hilt-compiler:1.1.0'
|
||||||
|
|
||||||
implementation 'io.coil-kt:coil-base:2.4.0'
|
implementation 'io.coil-kt:coil-base:2.5.0'
|
||||||
implementation 'io.coil-kt:coil-svg:2.4.0'
|
implementation 'io.coil-kt:coil-svg:2.5.0'
|
||||||
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:cf089a264d'
|
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:cf089a264d'
|
||||||
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
||||||
implementation 'io.noties.markwon:core:4.6.2'
|
implementation 'io.noties.markwon:core:4.6.2'
|
||||||
|
|
||||||
implementation 'ch.acra:acra-http:5.11.2'
|
implementation 'ch.acra:acra-http:5.11.3'
|
||||||
implementation 'ch.acra:acra-dialog:5.11.2'
|
implementation 'ch.acra:acra-dialog:5.11.3'
|
||||||
|
|
||||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
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'
|
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.test:runner:1.5.2'
|
androidTestImplementation 'androidx.test:runner:1.5.2'
|
||||||
@@ -152,7 +154,7 @@ dependencies {
|
|||||||
|
|
||||||
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
|
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.room:room-testing:2.5.2'
|
androidTestImplementation 'androidx.room:room-testing:2.6.0'
|
||||||
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.15.0'
|
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.15.0'
|
||||||
|
|
||||||
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.48.1'
|
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.48.1'
|
||||||
|
|||||||
3
app/proguard-rules.pro
vendored
3
app/proguard-rules.pro
vendored
@@ -18,3 +18,6 @@
|
|||||||
-keep class org.koitharu.kotatsu.core.exceptions.* { *; }
|
-keep class org.koitharu.kotatsu.core.exceptions.* { *; }
|
||||||
-keep class org.koitharu.kotatsu.settings.NotificationSettingsLegacyFragment
|
-keep class org.koitharu.kotatsu.settings.NotificationSettingsLegacyFragment
|
||||||
-keep class org.koitharu.kotatsu.core.prefs.ScreenshotsPolicy { *; }
|
-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
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class AppBackupAgentTest {
|
|||||||
assertEquals(history, historyRepository.getOne(SampleData.manga))
|
assertEquals(history, historyRepository.getOne(SampleData.manga))
|
||||||
assertEquals(listOf(SampleData.manga), favouritesRepository.getManga(category.id))
|
assertEquals(listOf(SampleData.manga), favouritesRepository.getManga(category.id))
|
||||||
|
|
||||||
val allTags = database.tagsDao.findTags(SampleData.tag.source.name).toMangaTags()
|
val allTags = database.getTagsDao().findTags(SampleData.tag.source.name).toMangaTags()
|
||||||
assertTrue(SampleData.tag in allTags)
|
assertTrue(SampleData.tag in allTags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.koitharu.kotatsu.parsers.MangaParser
|
|||||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
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.MangaPage
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
@@ -19,19 +20,14 @@ class DummyParser(context: MangaLoaderContext) : MangaParser(context, MangaSourc
|
|||||||
override val configKeyDomain: ConfigKey.Domain
|
override val configKeyDomain: ConfigKey.Domain
|
||||||
get() = ConfigKey.Domain("")
|
get() = ConfigKey.Domain("")
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder>
|
override val availableSortOrders: Set<SortOrder>
|
||||||
get() = EnumSet.allOf(SortOrder::class.java)
|
get() = EnumSet.allOf(SortOrder::class.java)
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
override suspend fun getDetails(manga: Manga): Manga {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getList(
|
override suspend fun getList(offset: Int, filter: MangaListFilter?): List<Manga> {
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder,
|
|
||||||
): List<Manga> {
|
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +35,7 @@ class DummyParser(context: MangaLoaderContext) : MangaParser(context, MangaSourc
|
|||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
override suspend fun getAvailableTags(): Set<MangaTag> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,16 @@
|
|||||||
<data android:host="kotatsu.app" />
|
<data android:host="kotatsu.app" />
|
||||||
<data android:path="/manga" />
|
<data android:path="/manga" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data android:scheme="kotatsu" />
|
||||||
|
<data android:host="manga" />
|
||||||
|
<data android:host="kotatsu.app" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.reader.ui.ReaderActivity"
|
android:name="org.koitharu.kotatsu.reader.ui.ReaderActivity"
|
||||||
@@ -211,6 +221,9 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.settings.sources.catalog.SourcesCatalogActivity"
|
||||||
|
android:label="@string/sources_catalog" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name="androidx.work.impl.foreground.SystemForegroundService"
|
android:name="androidx.work.impl.foreground.SystemForegroundService"
|
||||||
@@ -327,6 +340,13 @@
|
|||||||
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
|
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
<receiver
|
||||||
|
android:name="org.koitharu.kotatsu.core.ErrorReporterReceiver"
|
||||||
|
android:exported="false">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="${applicationId}.action.REPORT_ERROR" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.webkit.WebView.EnableSafeBrowsing"
|
android:name="android.webkit.WebView.EnableSafeBrowsing"
|
||||||
|
|||||||
@@ -25,15 +25,15 @@ class BookmarksRepository @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
fun observeBookmark(manga: Manga, chapterId: Long, page: Int): Flow<Bookmark?> {
|
fun observeBookmark(manga: Manga, chapterId: Long, page: Int): Flow<Bookmark?> {
|
||||||
return db.bookmarksDao.observe(manga.id, chapterId, page).map { it?.toBookmark(manga) }
|
return db.getBookmarksDao().observe(manga.id, chapterId, page).map { it?.toBookmark(manga) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeBookmarks(manga: Manga): Flow<List<Bookmark>> {
|
fun observeBookmarks(manga: Manga): Flow<List<Bookmark>> {
|
||||||
return db.bookmarksDao.observe(manga.id).mapItems { it.toBookmark(manga) }
|
return db.getBookmarksDao().observe(manga.id).mapItems { it.toBookmark(manga) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeBookmarks(): Flow<Map<Manga, List<Bookmark>>> {
|
fun observeBookmarks(): Flow<Map<Manga, List<Bookmark>>> {
|
||||||
return db.bookmarksDao.observe().map { map ->
|
return db.getBookmarksDao().observe().map { map ->
|
||||||
val res = LinkedHashMap<Manga, List<Bookmark>>(map.size)
|
val res = LinkedHashMap<Manga, List<Bookmark>>(map.size)
|
||||||
for ((k, v) in map) {
|
for ((k, v) in map) {
|
||||||
val manga = k.toManga()
|
val manga = k.toManga()
|
||||||
@@ -46,9 +46,9 @@ class BookmarksRepository @Inject constructor(
|
|||||||
suspend fun addBookmark(bookmark: Bookmark) {
|
suspend fun addBookmark(bookmark: Bookmark) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
val tags = bookmark.manga.tags.toEntities()
|
val tags = bookmark.manga.tags.toEntities()
|
||||||
db.tagsDao.upsert(tags)
|
db.getTagsDao().upsert(tags)
|
||||||
db.mangaDao.upsert(bookmark.manga.toEntity(), tags)
|
db.getMangaDao().upsert(bookmark.manga.toEntity(), tags)
|
||||||
db.bookmarksDao.insert(bookmark.toEntity())
|
db.getBookmarksDao().insert(bookmark.toEntity())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,11 +56,11 @@ class BookmarksRepository @Inject constructor(
|
|||||||
val entity = bookmark.toEntity().copy(
|
val entity = bookmark.toEntity().copy(
|
||||||
imageUrl = imageUrl,
|
imageUrl = imageUrl,
|
||||||
)
|
)
|
||||||
db.bookmarksDao.upsert(listOf(entity))
|
db.getBookmarksDao().upsert(listOf(entity))
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun removeBookmark(mangaId: Long, chapterId: Long, page: Int) {
|
suspend fun removeBookmark(mangaId: Long, chapterId: Long, page: Int) {
|
||||||
check(db.bookmarksDao.delete(mangaId, chapterId, page) != 0) {
|
check(db.getBookmarksDao().delete(mangaId, chapterId, page) != 0) {
|
||||||
"Bookmark not found"
|
"Bookmark not found"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ class BookmarksRepository @Inject constructor(
|
|||||||
suspend fun removeBookmarks(ids: Set<Long>): ReversibleHandle {
|
suspend fun removeBookmarks(ids: Set<Long>): ReversibleHandle {
|
||||||
val entities = ArrayList<BookmarkEntity>(ids.size)
|
val entities = ArrayList<BookmarkEntity>(ids.size)
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
val dao = db.bookmarksDao
|
val dao = db.getBookmarksDao()
|
||||||
for (pageId in ids) {
|
for (pageId in ids) {
|
||||||
val e = dao.find(pageId)
|
val e = dao.find(pageId)
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
@@ -92,7 +92,7 @@ class BookmarksRepository @Inject constructor(
|
|||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for (e in entities) {
|
for (e in entities) {
|
||||||
try {
|
try {
|
||||||
db.bookmarksDao.insert(e)
|
db.getBookmarksDao().insert(e)
|
||||||
} catch (e: SQLException) {
|
} catch (e: SQLException) {
|
||||||
e.printStackTraceDebug()
|
e.printStackTraceDebug()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ class BookmarksActivity :
|
|||||||
val fm = supportFragmentManager
|
val fm = supportFragmentManager
|
||||||
if (fm.findFragmentById(R.id.container) == null) {
|
if (fm.findFragmentById(R.id.container) == null) {
|
||||||
fm.commit {
|
fm.commit {
|
||||||
val fragment = BookmarksFragment.newInstance()
|
setReorderingAllowed(true)
|
||||||
replace(R.id.container, fragment)
|
replace(R.id.container, BookmarksFragment::class.java, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ class CloudFlareActivity : BaseActivity<ActivityBrowserBinding>(), CloudFlareCal
|
|||||||
if (!catchingWebViewUnavailability {
|
if (!catchingWebViewUnavailability {
|
||||||
setContentView(
|
setContentView(
|
||||||
ActivityBrowserBinding.inflate(
|
ActivityBrowserBinding.inflate(
|
||||||
layoutInflater
|
layoutInflater,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}) {
|
}) {
|
||||||
return
|
return
|
||||||
@@ -82,9 +82,11 @@ class CloudFlareActivity : BaseActivity<ActivityBrowserBinding>(), CloudFlareCal
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
viewBinding.webView.run {
|
runCatching {
|
||||||
stopLoading()
|
viewBinding.webView
|
||||||
destroy()
|
}.onSuccess {
|
||||||
|
it.stopLoading()
|
||||||
|
it.destroy()
|
||||||
}
|
}
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.koitharu.kotatsu.core
|
||||||
|
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.core.app.PendingIntentCompat
|
||||||
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.getSerializableExtraCompat
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.report
|
||||||
|
|
||||||
|
class ErrorReporterReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
|
val e = intent?.getSerializableExtraCompat<Throwable>(EXTRA_ERROR) ?: return
|
||||||
|
e.report()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private const val EXTRA_ERROR = "err"
|
||||||
|
private const val ACTION_REPORT = "${BuildConfig.APPLICATION_ID}.action.REPORT_ERROR"
|
||||||
|
|
||||||
|
fun getPendingIntent(context: Context, e: Throwable): PendingIntent {
|
||||||
|
val intent = Intent(context, ErrorReporterReceiver::class.java)
|
||||||
|
intent.setAction(ACTION_REPORT)
|
||||||
|
intent.setData(Uri.parse("err://${e.hashCode()}"))
|
||||||
|
intent.putExtra(EXTRA_ERROR, e)
|
||||||
|
return checkNotNull(PendingIntentCompat.getBroadcast(context, 0, intent, 0, false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ class BackupRepository @Inject constructor(
|
|||||||
var offset = 0
|
var offset = 0
|
||||||
val entry = BackupEntry(BackupEntry.HISTORY, JSONArray())
|
val entry = BackupEntry(BackupEntry.HISTORY, JSONArray())
|
||||||
while (true) {
|
while (true) {
|
||||||
val history = db.historyDao.findAll(offset, PAGE_SIZE)
|
val history = db.getHistoryDao().findAll(offset, PAGE_SIZE)
|
||||||
if (history.isEmpty()) {
|
if (history.isEmpty()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ class BackupRepository @Inject constructor(
|
|||||||
|
|
||||||
suspend fun dumpCategories(): BackupEntry {
|
suspend fun dumpCategories(): BackupEntry {
|
||||||
val entry = BackupEntry(BackupEntry.CATEGORIES, JSONArray())
|
val entry = BackupEntry(BackupEntry.CATEGORIES, JSONArray())
|
||||||
val categories = db.favouriteCategoriesDao.findAll()
|
val categories = db.getFavouriteCategoriesDao().findAll()
|
||||||
for (item in categories) {
|
for (item in categories) {
|
||||||
entry.data.put(JsonSerializer(item).toJson())
|
entry.data.put(JsonSerializer(item).toJson())
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ class BackupRepository @Inject constructor(
|
|||||||
var offset = 0
|
var offset = 0
|
||||||
val entry = BackupEntry(BackupEntry.FAVOURITES, JSONArray())
|
val entry = BackupEntry(BackupEntry.FAVOURITES, JSONArray())
|
||||||
while (true) {
|
while (true) {
|
||||||
val favourites = db.favouritesDao.findAll(offset, PAGE_SIZE)
|
val favourites = db.getFavouritesDao().findAll(offset, PAGE_SIZE)
|
||||||
if (favourites.isEmpty()) {
|
if (favourites.isEmpty()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ class BackupRepository @Inject constructor(
|
|||||||
|
|
||||||
suspend fun dumpBookmarks(): BackupEntry {
|
suspend fun dumpBookmarks(): BackupEntry {
|
||||||
val entry = BackupEntry(BackupEntry.BOOKMARKS, JSONArray())
|
val entry = BackupEntry(BackupEntry.BOOKMARKS, JSONArray())
|
||||||
val all = db.bookmarksDao.findAll()
|
val all = db.getBookmarksDao().findAll()
|
||||||
for ((m, b) in all) {
|
for ((m, b) in all) {
|
||||||
val json = JSONObject()
|
val json = JSONObject()
|
||||||
val manga = JsonSerializer(m.manga).toJson()
|
val manga = JsonSerializer(m.manga).toJson()
|
||||||
@@ -122,9 +122,9 @@ class BackupRepository @Inject constructor(
|
|||||||
val history = JsonDeserializer(item).toHistoryEntity()
|
val history = JsonDeserializer(item).toHistoryEntity()
|
||||||
result += runCatchingCancellable {
|
result += runCatchingCancellable {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
db.tagsDao.upsert(tags)
|
db.getTagsDao().upsert(tags)
|
||||||
db.mangaDao.upsert(manga, tags)
|
db.getMangaDao().upsert(manga, tags)
|
||||||
db.historyDao.upsert(history)
|
db.getHistoryDao().upsert(history)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ class BackupRepository @Inject constructor(
|
|||||||
for (item in entry.data.JSONIterator()) {
|
for (item in entry.data.JSONIterator()) {
|
||||||
val category = JsonDeserializer(item).toFavouriteCategoryEntity()
|
val category = JsonDeserializer(item).toFavouriteCategoryEntity()
|
||||||
result += runCatchingCancellable {
|
result += runCatchingCancellable {
|
||||||
db.favouriteCategoriesDao.upsert(category)
|
db.getFavouriteCategoriesDao().upsert(category)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@@ -153,9 +153,9 @@ class BackupRepository @Inject constructor(
|
|||||||
val favourite = JsonDeserializer(item).toFavouriteEntity()
|
val favourite = JsonDeserializer(item).toFavouriteEntity()
|
||||||
result += runCatchingCancellable {
|
result += runCatchingCancellable {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
db.tagsDao.upsert(tags)
|
db.getTagsDao().upsert(tags)
|
||||||
db.mangaDao.upsert(manga, tags)
|
db.getMangaDao().upsert(manga, tags)
|
||||||
db.favouritesDao.upsert(favourite)
|
db.getFavouritesDao().upsert(favourite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,9 +175,9 @@ class BackupRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
result += runCatchingCancellable {
|
result += runCatchingCancellable {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
db.tagsDao.upsert(tags)
|
db.getTagsDao().upsert(tags)
|
||||||
db.mangaDao.upsert(manga, tags)
|
db.getMangaDao().upsert(manga, tags)
|
||||||
db.bookmarksDao.upsert(bookmarks)
|
db.getBookmarksDao().upsert(bookmarks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class BackupZipOutput(val file: File) : Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val DIR_BACKUPS = "backups"
|
const val DIR_BACKUPS = "backups"
|
||||||
|
|
||||||
suspend fun BackupZipOutput(context: Context): BackupZipOutput = runInterruptible(Dispatchers.IO) {
|
suspend fun BackupZipOutput(context: Context): BackupZipOutput = runInterruptible(Dispatchers.IO) {
|
||||||
val dir = context.run {
|
val dir = context.run {
|
||||||
|
|||||||
@@ -66,29 +66,29 @@ const val DATABASE_VERSION = 17
|
|||||||
)
|
)
|
||||||
abstract class MangaDatabase : RoomDatabase() {
|
abstract class MangaDatabase : RoomDatabase() {
|
||||||
|
|
||||||
abstract val historyDao: HistoryDao
|
abstract fun getHistoryDao(): HistoryDao
|
||||||
|
|
||||||
abstract val tagsDao: TagsDao
|
abstract fun getTagsDao(): TagsDao
|
||||||
|
|
||||||
abstract val mangaDao: MangaDao
|
abstract fun getMangaDao(): MangaDao
|
||||||
|
|
||||||
abstract val favouritesDao: FavouritesDao
|
abstract fun getFavouritesDao(): FavouritesDao
|
||||||
|
|
||||||
abstract val preferencesDao: PreferencesDao
|
abstract fun getPreferencesDao(): PreferencesDao
|
||||||
|
|
||||||
abstract val favouriteCategoriesDao: FavouriteCategoriesDao
|
abstract fun getFavouriteCategoriesDao(): FavouriteCategoriesDao
|
||||||
|
|
||||||
abstract val tracksDao: TracksDao
|
abstract fun getTracksDao(): TracksDao
|
||||||
|
|
||||||
abstract val trackLogsDao: TrackLogsDao
|
abstract fun getTrackLogsDao(): TrackLogsDao
|
||||||
|
|
||||||
abstract val suggestionDao: SuggestionDao
|
abstract fun getSuggestionDao(): SuggestionDao
|
||||||
|
|
||||||
abstract val bookmarksDao: BookmarksDao
|
abstract fun getBookmarksDao(): BookmarksDao
|
||||||
|
|
||||||
abstract val scrobblingDao: ScrobblingDao
|
abstract fun getScrobblingDao(): ScrobblingDao
|
||||||
|
|
||||||
abstract val sourcesDao: MangaSourcesDao
|
abstract fun getSourcesDao(): MangaSourcesDao
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDatabaseMigrations(context: Context): Array<Migration> = arrayOf(
|
fun getDatabaseMigrations(context: Context): Array<Migration> = arrayOf(
|
||||||
|
|||||||
@@ -4,10 +4,15 @@ import androidx.room.Dao
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
|
import androidx.room.RawQuery
|
||||||
import androidx.room.Transaction
|
import androidx.room.Transaction
|
||||||
import androidx.room.Upsert
|
import androidx.room.Upsert
|
||||||
|
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||||
|
import androidx.sqlite.db.SupportSQLiteQuery
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import org.intellij.lang.annotations.Language
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaSourceEntity
|
import org.koitharu.kotatsu.core.db.entity.MangaSourceEntity
|
||||||
|
import org.koitharu.kotatsu.explore.data.SourcesSortOrder
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
abstract class MangaSourcesDao {
|
abstract class MangaSourcesDao {
|
||||||
@@ -15,11 +20,11 @@ abstract class MangaSourcesDao {
|
|||||||
@Query("SELECT * FROM sources ORDER BY sort_key")
|
@Query("SELECT * FROM sources ORDER BY sort_key")
|
||||||
abstract suspend fun findAll(): List<MangaSourceEntity>
|
abstract suspend fun findAll(): List<MangaSourceEntity>
|
||||||
|
|
||||||
@Query("SELECT * FROM sources WHERE enabled = 1 ORDER BY sort_key")
|
@Query("SELECT * FROM sources WHERE enabled = 0 ORDER BY sort_key")
|
||||||
abstract suspend fun findAllEnabled(): List<MangaSourceEntity>
|
abstract suspend fun findAllDisabled(): List<MangaSourceEntity>
|
||||||
|
|
||||||
@Query("SELECT * FROM sources WHERE enabled = 1 ORDER BY sort_key")
|
@Query("SELECT * FROM sources WHERE enabled = 0")
|
||||||
abstract fun observeEnabled(): Flow<List<MangaSourceEntity>>
|
abstract fun observeDisabled(): Flow<List<MangaSourceEntity>>
|
||||||
|
|
||||||
@Query("SELECT * FROM sources ORDER BY sort_key")
|
@Query("SELECT * FROM sources ORDER BY sort_key")
|
||||||
abstract fun observeAll(): Flow<List<MangaSourceEntity>>
|
abstract fun observeAll(): Flow<List<MangaSourceEntity>>
|
||||||
@@ -40,6 +45,22 @@ abstract class MangaSourcesDao {
|
|||||||
@Upsert
|
@Upsert
|
||||||
abstract suspend fun upsert(entry: MangaSourceEntity)
|
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
|
@Transaction
|
||||||
open suspend fun setEnabled(source: String, isEnabled: Boolean) {
|
open suspend fun setEnabled(source: String, isEnabled: Boolean) {
|
||||||
if (updateIsEnabled(source, isEnabled) == 0) {
|
if (updateIsEnabled(source, isEnabled) == 0) {
|
||||||
@@ -54,4 +75,16 @@ abstract class MangaSourcesDao {
|
|||||||
|
|
||||||
@Query("UPDATE sources SET enabled = :isEnabled WHERE source = :source")
|
@Query("UPDATE sources SET enabled = :isEnabled WHERE source = :source")
|
||||||
protected abstract suspend fun updateIsEnabled(source: String, isEnabled: Boolean): Int
|
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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration10To11 : Migration(10, 11) {
|
class Migration10To11 : Migration(10, 11) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE IF NOT EXISTS `bookmarks` (
|
CREATE TABLE IF NOT EXISTS `bookmarks` (
|
||||||
`manga_id` INTEGER NOT NULL,
|
`manga_id` INTEGER NOT NULL,
|
||||||
@@ -20,7 +20,7 @@ class Migration10To11 : Migration(10, 11) {
|
|||||||
FOREIGN KEY(`manga_id`) REFERENCES `manga`(`manga_id`) ON UPDATE NO ACTION ON DELETE CASCADE )
|
FOREIGN KEY(`manga_id`) REFERENCES `manga`(`manga_id`) ON UPDATE NO ACTION ON DELETE CASCADE )
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
database.execSQL("CREATE INDEX IF NOT EXISTS `index_bookmarks_manga_id` ON `bookmarks` (`manga_id`)")
|
db.execSQL("CREATE INDEX IF NOT EXISTS `index_bookmarks_manga_id` ON `bookmarks` (`manga_id`)")
|
||||||
database.execSQL("CREATE INDEX IF NOT EXISTS `index_bookmarks_page_id` ON `bookmarks` (`page_id`)")
|
db.execSQL("CREATE INDEX IF NOT EXISTS `index_bookmarks_page_id` ON `bookmarks` (`page_id`)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration11To12 : Migration(11, 12) {
|
class Migration11To12 : Migration(11, 12) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE IF NOT EXISTS `scrobblings` (
|
CREATE TABLE IF NOT EXISTS `scrobblings` (
|
||||||
`scrobbler` INTEGER NOT NULL,
|
`scrobbler` INTEGER NOT NULL,
|
||||||
@@ -21,7 +21,7 @@ class Migration11To12 : Migration(11, 12) {
|
|||||||
)
|
)
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
database.execSQL("ALTER TABLE history ADD COLUMN `percent` REAL NOT NULL DEFAULT -1")
|
db.execSQL("ALTER TABLE history ADD COLUMN `percent` REAL NOT NULL DEFAULT -1")
|
||||||
database.execSQL("ALTER TABLE bookmarks ADD COLUMN `percent` REAL NOT NULL DEFAULT -1")
|
db.execSQL("ALTER TABLE bookmarks ADD COLUMN `percent` REAL NOT NULL DEFAULT -1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration12To13 : Migration(12, 13) {
|
class Migration12To13 : Migration(12, 13) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("ALTER TABLE favourite_categories ADD COLUMN `show_in_lib` INTEGER NOT NULL DEFAULT 1")
|
db.execSQL("ALTER TABLE favourite_categories ADD COLUMN `show_in_lib` INTEGER NOT NULL DEFAULT 1")
|
||||||
database.execSQL("ALTER TABLE favourites ADD COLUMN `sort_key` INTEGER NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE favourites ADD COLUMN `sort_key` INTEGER NOT NULL DEFAULT 0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration13To14 : Migration(13, 14) {
|
class Migration13To14 : Migration(13, 14) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("ALTER TABLE favourite_categories ADD COLUMN `deleted_at` INTEGER NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE favourite_categories ADD COLUMN `deleted_at` INTEGER NOT NULL DEFAULT 0")
|
||||||
database.execSQL("ALTER TABLE favourites ADD COLUMN `deleted_at` INTEGER NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE favourites ADD COLUMN `deleted_at` INTEGER NOT NULL DEFAULT 0")
|
||||||
database.execSQL("ALTER TABLE history ADD COLUMN `deleted_at` INTEGER NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE history ADD COLUMN `deleted_at` INTEGER NOT NULL DEFAULT 0")
|
||||||
database.execSQL("ALTER TABLE preferences ADD COLUMN `cf_brightness` REAL NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE preferences ADD COLUMN `cf_brightness` REAL NOT NULL DEFAULT 0")
|
||||||
database.execSQL("ALTER TABLE preferences ADD COLUMN `cf_contrast` REAL NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE preferences ADD COLUMN `cf_contrast` REAL NOT NULL DEFAULT 0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration14To15 : Migration(14, 15) {
|
class Migration14To15 : Migration(14, 15) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) = Unit
|
override fun migrate(db: SupportSQLiteDatabase) = Unit
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration15To16 : Migration(15, 16) {
|
class Migration15To16 : Migration(15, 16) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("ALTER TABLE preferences ADD COLUMN `cf_invert` INTEGER NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE preferences ADD COLUMN `cf_invert` INTEGER NOT NULL DEFAULT 0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ class Migration16To17(context: Context) : Migration(16, 17) {
|
|||||||
|
|
||||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("CREATE TABLE `sources` (`source` TEXT NOT NULL, `enabled` INTEGER NOT NULL, `sort_key` INTEGER NOT NULL, PRIMARY KEY(`source`))")
|
db.execSQL("CREATE TABLE `sources` (`source` TEXT NOT NULL, `enabled` INTEGER NOT NULL, `sort_key` INTEGER NOT NULL, PRIMARY KEY(`source`))")
|
||||||
database.execSQL("CREATE INDEX `index_sources_sort_key` ON `sources` (`sort_key`)")
|
db.execSQL("CREATE INDEX `index_sources_sort_key` ON `sources` (`sort_key`)")
|
||||||
val hiddenSources = prefs.getStringSet("sources_hidden", null).orEmpty()
|
val hiddenSources = prefs.getStringSet("sources_hidden", null).orEmpty()
|
||||||
val order = prefs.getString("sources_order_2", null)?.split('|').orEmpty()
|
val order = prefs.getString("sources_order_2", null)?.split('|').orEmpty()
|
||||||
val sources = MangaSource.entries
|
val sources = MangaSource.entries
|
||||||
@@ -30,7 +30,7 @@ class Migration16To17(context: Context) : Migration(16, 17) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"INSERT INTO `sources` (`source`, `enabled`, `sort_key`) VALUES (?, ?, ?)",
|
"INSERT INTO `sources` (`source`, `enabled`, `sort_key`) VALUES (?, ?, ?)",
|
||||||
arrayOf(name, (!isHidden).toInt(), sortKey),
|
arrayOf(name, (!isHidden).toInt(), sortKey),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,48 +7,48 @@ class Migration1To2 : Migration(1, 2) {
|
|||||||
/**
|
/**
|
||||||
* Adding foreign keys
|
* Adding foreign keys
|
||||||
*/
|
*/
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
/* manga_tags */
|
/* manga_tags */
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"CREATE TABLE IF NOT EXISTS manga_tags_tmp (manga_id INTEGER NOT NULL, tag_id INTEGER NOT NULL, " +
|
"CREATE TABLE IF NOT EXISTS manga_tags_tmp (manga_id INTEGER NOT NULL, tag_id INTEGER NOT NULL, " +
|
||||||
"PRIMARY KEY(manga_id, tag_id), " +
|
"PRIMARY KEY(manga_id, tag_id), " +
|
||||||
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE, " +
|
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE, " +
|
||||||
"FOREIGN KEY(tag_id) REFERENCES tags(tag_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
"FOREIGN KEY(tag_id) REFERENCES tags(tag_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
||||||
)
|
)
|
||||||
database.execSQL("CREATE INDEX IF NOT EXISTS index_manga_tags_manga_id ON manga_tags_tmp (manga_id)")
|
db.execSQL("CREATE INDEX IF NOT EXISTS index_manga_tags_manga_id ON manga_tags_tmp (manga_id)")
|
||||||
database.execSQL("CREATE INDEX IF NOT EXISTS index_manga_tags_tag_id ON manga_tags_tmp (tag_id)")
|
db.execSQL("CREATE INDEX IF NOT EXISTS index_manga_tags_tag_id ON manga_tags_tmp (tag_id)")
|
||||||
database.execSQL("INSERT INTO manga_tags_tmp (manga_id, tag_id) SELECT manga_id, tag_id FROM manga_tags")
|
db.execSQL("INSERT INTO manga_tags_tmp (manga_id, tag_id) SELECT manga_id, tag_id FROM manga_tags")
|
||||||
database.execSQL("DROP TABLE manga_tags")
|
db.execSQL("DROP TABLE manga_tags")
|
||||||
database.execSQL("ALTER TABLE manga_tags_tmp RENAME TO manga_tags")
|
db.execSQL("ALTER TABLE manga_tags_tmp RENAME TO manga_tags")
|
||||||
/* favourites */
|
/* favourites */
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"CREATE TABLE IF NOT EXISTS favourites_tmp (manga_id INTEGER NOT NULL, category_id INTEGER NOT NULL, created_at INTEGER NOT NULL, " +
|
"CREATE TABLE IF NOT EXISTS favourites_tmp (manga_id INTEGER NOT NULL, category_id INTEGER NOT NULL, created_at INTEGER NOT NULL, " +
|
||||||
"PRIMARY KEY(manga_id, category_id), " +
|
"PRIMARY KEY(manga_id, category_id), " +
|
||||||
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE , " +
|
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE , " +
|
||||||
"FOREIGN KEY(category_id) REFERENCES favourite_categories(category_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
"FOREIGN KEY(category_id) REFERENCES favourite_categories(category_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
||||||
)
|
)
|
||||||
database.execSQL("CREATE INDEX IF NOT EXISTS index_favourites_manga_id ON favourites_tmp (manga_id)")
|
db.execSQL("CREATE INDEX IF NOT EXISTS index_favourites_manga_id ON favourites_tmp (manga_id)")
|
||||||
database.execSQL("CREATE INDEX IF NOT EXISTS index_favourites_category_id ON favourites_tmp (category_id)")
|
db.execSQL("CREATE INDEX IF NOT EXISTS index_favourites_category_id ON favourites_tmp (category_id)")
|
||||||
database.execSQL("INSERT INTO favourites_tmp (manga_id, category_id, created_at) SELECT manga_id, category_id, created_at FROM favourites")
|
db.execSQL("INSERT INTO favourites_tmp (manga_id, category_id, created_at) SELECT manga_id, category_id, created_at FROM favourites")
|
||||||
database.execSQL("DROP TABLE favourites")
|
db.execSQL("DROP TABLE favourites")
|
||||||
database.execSQL("ALTER TABLE favourites_tmp RENAME TO favourites")
|
db.execSQL("ALTER TABLE favourites_tmp RENAME TO favourites")
|
||||||
/* history */
|
/* history */
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"CREATE TABLE IF NOT EXISTS history_tmp (manga_id INTEGER NOT NULL, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, chapter_id INTEGER NOT NULL, page INTEGER NOT NULL, " +
|
"CREATE TABLE IF NOT EXISTS history_tmp (manga_id INTEGER NOT NULL, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, chapter_id INTEGER NOT NULL, page INTEGER NOT NULL, " +
|
||||||
"PRIMARY KEY(manga_id), " +
|
"PRIMARY KEY(manga_id), " +
|
||||||
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
||||||
)
|
)
|
||||||
database.execSQL("INSERT INTO history_tmp (manga_id, created_at, updated_at, chapter_id, page) SELECT manga_id, created_at, updated_at, chapter_id, page FROM history")
|
db.execSQL("INSERT INTO history_tmp (manga_id, created_at, updated_at, chapter_id, page) SELECT manga_id, created_at, updated_at, chapter_id, page FROM history")
|
||||||
database.execSQL("DROP TABLE history")
|
db.execSQL("DROP TABLE history")
|
||||||
database.execSQL("ALTER TABLE history_tmp RENAME TO history")
|
db.execSQL("ALTER TABLE history_tmp RENAME TO history")
|
||||||
/* preferences */
|
/* preferences */
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"CREATE TABLE IF NOT EXISTS preferences_tmp (manga_id INTEGER NOT NULL, mode INTEGER NOT NULL," +
|
"CREATE TABLE IF NOT EXISTS preferences_tmp (manga_id INTEGER NOT NULL, mode INTEGER NOT NULL," +
|
||||||
" PRIMARY KEY(manga_id), " +
|
" PRIMARY KEY(manga_id), " +
|
||||||
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
||||||
)
|
)
|
||||||
database.execSQL("INSERT INTO preferences_tmp (manga_id, mode) SELECT manga_id, mode FROM preferences")
|
db.execSQL("INSERT INTO preferences_tmp (manga_id, mode) SELECT manga_id, mode FROM preferences")
|
||||||
database.execSQL("DROP TABLE preferences")
|
db.execSQL("DROP TABLE preferences")
|
||||||
database.execSQL("ALTER TABLE preferences_tmp RENAME TO preferences")
|
db.execSQL("ALTER TABLE preferences_tmp RENAME TO preferences")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration2To3 : Migration(2, 3) {
|
class Migration2To3 : Migration(2, 3) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("ALTER TABLE history ADD COLUMN scroll REAL NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE history ADD COLUMN scroll REAL NOT NULL DEFAULT 0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration3To4 : Migration(3, 4) {
|
class Migration3To4 : Migration(3, 4) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("CREATE TABLE IF NOT EXISTS tracks (manga_id INTEGER NOT NULL, chapters_total INTEGER NOT NULL, last_chapter_id INTEGER NOT NULL, chapters_new INTEGER NOT NULL, last_check INTEGER NOT NULL, last_notified_id INTEGER NOT NULL, PRIMARY KEY(manga_id), FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )")
|
db.execSQL("CREATE TABLE IF NOT EXISTS tracks (manga_id INTEGER NOT NULL, chapters_total INTEGER NOT NULL, last_chapter_id INTEGER NOT NULL, chapters_new INTEGER NOT NULL, last_check INTEGER NOT NULL, last_notified_id INTEGER NOT NULL, PRIMARY KEY(manga_id), FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration4To5 : Migration(4, 5) {
|
class Migration4To5 : Migration(4, 5) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("ALTER TABLE favourite_categories ADD COLUMN sort_key INTEGER NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE favourite_categories ADD COLUMN sort_key INTEGER NOT NULL DEFAULT 0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration5To6 : Migration(5, 6) {
|
class Migration5To6 : Migration(5, 6) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("CREATE TABLE IF NOT EXISTS track_logs (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, manga_id INTEGER NOT NULL, chapters TEXT NOT NULL, created_at INTEGER NOT NULL, FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE)")
|
db.execSQL("CREATE TABLE IF NOT EXISTS track_logs (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, manga_id INTEGER NOT NULL, chapters TEXT NOT NULL, created_at INTEGER NOT NULL, FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE)")
|
||||||
database.execSQL("CREATE INDEX IF NOT EXISTS index_track_logs_manga_id ON track_logs (manga_id)")
|
db.execSQL("CREATE INDEX IF NOT EXISTS index_track_logs_manga_id ON track_logs (manga_id)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration6To7 : Migration(6, 7) {
|
class Migration6To7 : Migration(6, 7) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("ALTER TABLE manga ADD COLUMN public_url TEXT NOT NULL DEFAULT ''")
|
db.execSQL("ALTER TABLE manga ADD COLUMN public_url TEXT NOT NULL DEFAULT ''")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration7To8 : Migration(7, 8) {
|
class Migration7To8 : Migration(7, 8) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("ALTER TABLE manga ADD COLUMN nsfw INTEGER NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE manga ADD COLUMN nsfw INTEGER NOT NULL DEFAULT 0")
|
||||||
database.execSQL("CREATE TABLE IF NOT EXISTS suggestions (manga_id INTEGER NOT NULL, relevance REAL NOT NULL, created_at INTEGER NOT NULL, PRIMARY KEY(manga_id), FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )")
|
db.execSQL("CREATE TABLE IF NOT EXISTS suggestions (manga_id INTEGER NOT NULL, relevance REAL NOT NULL, created_at INTEGER NOT NULL, PRIMARY KEY(manga_id), FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )")
|
||||||
database.execSQL("CREATE INDEX IF NOT EXISTS index_suggestions_manga_id ON suggestions (manga_id)")
|
db.execSQL("CREATE INDEX IF NOT EXISTS index_suggestions_manga_id ON suggestions (manga_id)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import org.koitharu.kotatsu.parsers.model.SortOrder
|
|||||||
|
|
||||||
class Migration8To9 : Migration(8, 9) {
|
class Migration8To9 : Migration(8, 9) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("ALTER TABLE favourite_categories ADD COLUMN `order` TEXT NOT NULL DEFAULT ${SortOrder.NEWEST.name}")
|
db.execSQL("ALTER TABLE favourite_categories ADD COLUMN `order` TEXT NOT NULL DEFAULT ${SortOrder.NEWEST.name}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
|||||||
|
|
||||||
class Migration9To10 : Migration(9, 10) {
|
class Migration9To10 : Migration(9, 10) {
|
||||||
|
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
database.execSQL("ALTER TABLE favourite_categories ADD COLUMN `track` INTEGER NOT NULL DEFAULT 1")
|
db.execSQL("ALTER TABLE favourite_categories ADD COLUMN `track` INTEGER NOT NULL DEFAULT 1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
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.ContentType
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||||
@@ -18,3 +21,18 @@ fun MangaSource(name: String): MangaSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun MangaSource.isNsfw() = contentType == ContentType.HENTAI
|
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 {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
val response = chain.proceed(chain.request())
|
val response = chain.proceed(chain.request())
|
||||||
if (response.code == HTTP_FORBIDDEN || response.code == HTTP_UNAVAILABLE) {
|
if (response.code == HTTP_FORBIDDEN || response.code == HTTP_UNAVAILABLE) {
|
||||||
val content = response.body?.source()?.peek()?.use {
|
val content = response.body?.let { response.peekBody(Long.MAX_VALUE) }?.byteStream()?.use {
|
||||||
Jsoup.parse(it.inputStream(), Charsets.UTF_8.name(), response.request.url.toString())
|
Jsoup.parse(it, Charsets.UTF_8.name(), response.request.url.toString())
|
||||||
} ?: return response
|
} ?: return response
|
||||||
if (content.getElementById("challenge-error-title") != null) {
|
if (content.getElementById("challenge-error-title") != null) {
|
||||||
val request = response.request
|
val request = response.request
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.core.network
|
|||||||
|
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
|
import okio.IOException
|
||||||
import org.koitharu.kotatsu.core.network.CommonHeaders.CONTENT_ENCODING
|
import org.koitharu.kotatsu.core.network.CommonHeaders.CONTENT_ENCODING
|
||||||
|
|
||||||
class GZipInterceptor : Interceptor {
|
class GZipInterceptor : Interceptor {
|
||||||
@@ -9,6 +10,10 @@ class GZipInterceptor : Interceptor {
|
|||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
val newRequest = chain.request().newBuilder()
|
val newRequest = chain.request().newBuilder()
|
||||||
newRequest.addHeader(CONTENT_ENCODING, "gzip")
|
newRequest.addHeader(CONTENT_ENCODING, "gzip")
|
||||||
return chain.proceed(newRequest.build())
|
return try {
|
||||||
|
chain.proceed(newRequest.build())
|
||||||
|
} catch (e: NullPointerException) {
|
||||||
|
throw IOException(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.toEntity
|
||||||
import org.koitharu.kotatsu.core.db.entity.toManga
|
import org.koitharu.kotatsu.core.db.entity.toManga
|
||||||
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
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.core.prefs.ReaderMode
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
@@ -28,16 +29,16 @@ class MangaDataRepository @Inject constructor(
|
|||||||
suspend fun saveReaderMode(manga: Manga, mode: ReaderMode) {
|
suspend fun saveReaderMode(manga: Manga, mode: ReaderMode) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
storeManga(manga)
|
storeManga(manga)
|
||||||
val entity = db.preferencesDao.find(manga.id) ?: newEntity(manga.id)
|
val entity = db.getPreferencesDao().find(manga.id) ?: newEntity(manga.id)
|
||||||
db.preferencesDao.upsert(entity.copy(mode = mode.id))
|
db.getPreferencesDao().upsert(entity.copy(mode = mode.id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun saveColorFilter(manga: Manga, colorFilter: ReaderColorFilter?) {
|
suspend fun saveColorFilter(manga: Manga, colorFilter: ReaderColorFilter?) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
storeManga(manga)
|
storeManga(manga)
|
||||||
val entity = db.preferencesDao.find(manga.id) ?: newEntity(manga.id)
|
val entity = db.getPreferencesDao().find(manga.id) ?: newEntity(manga.id)
|
||||||
db.preferencesDao.upsert(
|
db.getPreferencesDao().upsert(
|
||||||
entity.copy(
|
entity.copy(
|
||||||
cfBrightness = colorFilter?.brightness ?: 0f,
|
cfBrightness = colorFilter?.brightness ?: 0f,
|
||||||
cfContrast = colorFilter?.contrast ?: 0f,
|
cfContrast = colorFilter?.contrast ?: 0f,
|
||||||
@@ -48,25 +49,25 @@ class MangaDataRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getReaderMode(mangaId: Long): ReaderMode? {
|
suspend fun getReaderMode(mangaId: Long): ReaderMode? {
|
||||||
return db.preferencesDao.find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
|
return db.getPreferencesDao().find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getColorFilter(mangaId: Long): ReaderColorFilter? {
|
suspend fun getColorFilter(mangaId: Long): ReaderColorFilter? {
|
||||||
return db.preferencesDao.find(mangaId)?.getColorFilterOrNull()
|
return db.getPreferencesDao().find(mangaId)?.getColorFilterOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeColorFilter(mangaId: Long): Flow<ReaderColorFilter?> {
|
fun observeColorFilter(mangaId: Long): Flow<ReaderColorFilter?> {
|
||||||
return db.preferencesDao.observe(mangaId)
|
return db.getPreferencesDao().observe(mangaId)
|
||||||
.map { it?.getColorFilterOrNull() }
|
.map { it?.getColorFilterOrNull() }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findMangaById(mangaId: Long): Manga? {
|
suspend fun findMangaById(mangaId: Long): Manga? {
|
||||||
return db.mangaDao.find(mangaId)?.toManga()
|
return db.getMangaDao().find(mangaId)?.toManga()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findMangaByPublicUrl(publicUrl: String): Manga? {
|
suspend fun findMangaByPublicUrl(publicUrl: String): Manga? {
|
||||||
return db.mangaDao.findByPublicUrl(publicUrl)?.toManga()
|
return db.getMangaDao().findByPublicUrl(publicUrl)?.toManga()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun resolveIntent(intent: MangaIntent): Manga? = when {
|
suspend fun resolveIntent(intent: MangaIntent): Manga? = when {
|
||||||
@@ -77,15 +78,23 @@ class MangaDataRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun storeManga(manga: Manga) {
|
suspend fun storeManga(manga: Manga) {
|
||||||
val tags = manga.tags.toEntities()
|
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
db.tagsDao.upsert(tags)
|
// avoid storing local manga if remote one is already stored
|
||||||
db.mangaDao.upsert(manga.toEntity(), tags)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findTags(source: MangaSource): Set<MangaTag> {
|
suspend fun findTags(source: MangaSource): Set<MangaTag> {
|
||||||
return db.tagsDao.findTags(source.name).toMangaTags()
|
return db.getTagsDao().findTags(source.name).toMangaTags()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MangaPrefsEntity.getColorFilterOrNull(): ReaderColorFilter? {
|
private fun MangaPrefsEntity.getColorFilterOrNull(): ReaderColorFilter? {
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ class MangaLinkResolver @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun resolve(uri: Uri): Manga {
|
suspend fun resolve(uri: Uri): Manga {
|
||||||
return if (uri.host == "kotatsu.app") {
|
return if (uri.scheme == "kotatsu" || uri.host == "kotatsu.app") {
|
||||||
resolveAppLink(uri)
|
resolveAppLink(uri)
|
||||||
} else {
|
} else {
|
||||||
resolveExternalLink(uri)
|
resolveExternalLink(uri)
|
||||||
} ?: throw NotFoundException("Manga not found", uri.toString())
|
} ?: throw NotFoundException("Cannot resolve link", uri.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun resolveAppLink(uri: Uri): Manga? {
|
private suspend fun resolveAppLink(uri: Uri): Manga? {
|
||||||
require(uri.pathSegments.singleOrNull() == "manga") { "Invalid url" }
|
require(uri.pathSegments.singleOrNull() == "manga") { "Invalid url" }
|
||||||
val sourceName = requireNotNull(uri.getQueryParameter("source")) { "Source is not specified" }
|
val sourceName = requireNotNull(uri.getQueryParameter("source")) { "Source is not specified" }
|
||||||
val source = MangaSource(sourceName)
|
val source = MangaSource(sourceName)
|
||||||
@@ -42,7 +42,7 @@ class MangaLinkResolver @Inject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun resolveExternalLink(uri: Uri): Manga? {
|
private suspend fun resolveExternalLink(uri: Uri): Manga? {
|
||||||
dataRepository.findMangaByPublicUrl(uri.toString())?.let {
|
dataRepository.findMangaByPublicUrl(uri.toString())?.let {
|
||||||
return it
|
return it
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,6 +128,10 @@ class RemoteMangaRepository(
|
|||||||
return details.await()
|
return details.await()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun peekDetails(manga: Manga): Manga? {
|
||||||
|
return cache.getDetails(source, manga.url)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun find(manga: Manga): Manga? {
|
suspend fun find(manga: Manga): Manga? {
|
||||||
val list = getList(0, manga.title)
|
val list = getList(0, manga.title)
|
||||||
return list.find { x -> x.id == manga.id }
|
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.putEnumValue
|
||||||
import org.koitharu.kotatsu.core.util.ext.takeIfReadable
|
import org.koitharu.kotatsu.core.util.ext.takeIfReadable
|
||||||
import org.koitharu.kotatsu.core.util.ext.toUriOrNull
|
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.list.domain.ListSortOrder
|
||||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.parsers.util.find
|
import org.koitharu.kotatsu.parsers.util.find
|
||||||
@@ -209,6 +210,10 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
return policy.isNetworkAllowed(connectivityManager)
|
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
|
var isSourcesGridMode: Boolean
|
||||||
get() = prefs.getBoolean(KEY_SOURCES_GRID, false)
|
get() = prefs.getBoolean(KEY_SOURCES_GRID, false)
|
||||||
set(value) = prefs.edit { putBoolean(KEY_SOURCES_GRID, value) }
|
set(value) = prefs.edit { putBoolean(KEY_SOURCES_GRID, value) }
|
||||||
@@ -354,6 +359,16 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val is32BitColorsEnabled: Boolean
|
val is32BitColorsEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_32BIT_COLOR, false)
|
get() = prefs.getBoolean(KEY_32BIT_COLOR, false)
|
||||||
|
|
||||||
|
val isPeriodicalBackupEnabled: Boolean
|
||||||
|
get() = prefs.getBoolean(KEY_BACKUP_PERIODICAL_ENABLED, false)
|
||||||
|
|
||||||
|
val periodicalBackupFrequency: Long
|
||||||
|
get() = prefs.getString(KEY_BACKUP_PERIODICAL_FREQUENCY, null)?.toLongOrNull() ?: 7L
|
||||||
|
|
||||||
|
var periodicalBackupOutput: Uri?
|
||||||
|
get() = prefs.getString(KEY_BACKUP_PERIODICAL_OUTPUT, null)?.toUriOrNull()
|
||||||
|
set(value) = prefs.edit { putString(KEY_BACKUP_PERIODICAL_OUTPUT, value?.toString()) }
|
||||||
|
|
||||||
fun isTipEnabled(tip: String): Boolean {
|
fun isTipEnabled(tip: String): Boolean {
|
||||||
return prefs.getStringSet(KEY_TIPS_CLOSED, emptySet())?.contains(tip) != true
|
return prefs.getStringSet(KEY_TIPS_CLOSED, emptySet())?.contains(tip) != true
|
||||||
}
|
}
|
||||||
@@ -458,6 +473,10 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val KEY_ZOOM_MODE = "zoom_mode"
|
const val KEY_ZOOM_MODE = "zoom_mode"
|
||||||
const val KEY_BACKUP = "backup"
|
const val KEY_BACKUP = "backup"
|
||||||
const val KEY_RESTORE = "restore"
|
const val KEY_RESTORE = "restore"
|
||||||
|
const val KEY_BACKUP_PERIODICAL_ENABLED = "backup_periodic"
|
||||||
|
const val KEY_BACKUP_PERIODICAL_FREQUENCY = "backup_periodic_freq"
|
||||||
|
const val KEY_BACKUP_PERIODICAL_OUTPUT = "backup_periodic_output"
|
||||||
|
const val KEY_BACKUP_PERIODICAL_LAST = "backup_periodic_last"
|
||||||
const val KEY_HISTORY_GROUPING = "history_grouping"
|
const val KEY_HISTORY_GROUPING = "history_grouping"
|
||||||
const val KEY_READING_INDICATORS = "reading_indicators"
|
const val KEY_READING_INDICATORS = "reading_indicators"
|
||||||
const val KEY_REVERSE_CHAPTERS = "reverse_chapters"
|
const val KEY_REVERSE_CHAPTERS = "reverse_chapters"
|
||||||
@@ -514,6 +533,8 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val KEY_RELATED_MANGA = "related_manga"
|
const val KEY_RELATED_MANGA = "related_manga"
|
||||||
const val KEY_NAV_MAIN = "nav_main"
|
const val KEY_NAV_MAIN = "nav_main"
|
||||||
const val KEY_32BIT_COLOR = "enhanced_colors"
|
const val KEY_32BIT_COLOR = "enhanced_colors"
|
||||||
|
const val KEY_SOURCES_ORDER = "sources_sort_order"
|
||||||
|
const val KEY_SOURCES_CATALOG = "sources_catalog"
|
||||||
|
|
||||||
// About
|
// About
|
||||||
const val KEY_APP_UPDATE = "app_update"
|
const val KEY_APP_UPDATE = "app_update"
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import android.graphics.Color
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.MenuItem
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.CallSuper
|
import androidx.annotation.CallSuper
|
||||||
@@ -96,10 +95,10 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
insetsDelegate.onViewCreated(binding.root)
|
insetsDelegate.onViewCreated(binding.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem) = if (item.itemId == android.R.id.home) {
|
override fun onSupportNavigateUp(): Boolean {
|
||||||
onBackPressed()
|
dispatchNavigateUp()
|
||||||
true
|
return true
|
||||||
} else super.onOptionsItemSelected(item)
|
}
|
||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||||
@@ -126,10 +125,10 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
val actionModeColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
val actionModeColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
ColorUtils.compositeColors(
|
ColorUtils.compositeColors(
|
||||||
ContextCompat.getColor(this, com.google.android.material.R.color.m3_appbar_overlay_color),
|
ContextCompat.getColor(this, com.google.android.material.R.color.m3_appbar_overlay_color),
|
||||||
getThemeColor(com.google.android.material.R.attr.colorSurface),
|
getThemeColor(R.attr.m3ColorBackground),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
ContextCompat.getColor(this, R.color.kotatsu_secondaryContainer)
|
ContextCompat.getColor(this, R.color.kotatsu_m3_background)
|
||||||
}
|
}
|
||||||
val insets = ViewCompat.getRootWindowInsets(viewBinding.root)
|
val insets = ViewCompat.getRootWindowInsets(viewBinding.root)
|
||||||
?.getInsets(WindowInsetsCompat.Type.systemBars()) ?: return
|
?.getInsets(WindowInsetsCompat.Type.systemBars()) ?: return
|
||||||
@@ -150,6 +149,17 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
window.statusBarColor = defaultStatusBarColor
|
window.statusBarColor = defaultStatusBarColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected open fun dispatchNavigateUp() {
|
||||||
|
val upIntent = parentActivityIntent
|
||||||
|
if (upIntent != null) {
|
||||||
|
if (!navigateUpTo(upIntent)) {
|
||||||
|
startActivity(upIntent)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
finishAfterTransition()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun putDataToExtras(intent: Intent?) {
|
private fun putDataToExtras(intent: Intent?) {
|
||||||
intent?.putExtra(EXTRA_DATA, intent.data)
|
intent?.putExtra(EXTRA_DATA, intent.data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import android.content.ClipData
|
|||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.method.LinkMovementMethod
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.HtmlCompat
|
||||||
import androidx.core.text.htmlEncode
|
import androidx.core.text.htmlEncode
|
||||||
|
import androidx.core.text.method.LinkMovementMethodCompat
|
||||||
import androidx.core.text.parseAsHtml
|
import androidx.core.text.parseAsHtml
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
@@ -37,7 +37,7 @@ class ErrorDetailsDialog : AlertDialogFragment<DialogErrorDetailsBinding>() {
|
|||||||
override fun onViewBindingCreated(binding: DialogErrorDetailsBinding, savedInstanceState: Bundle?) {
|
override fun onViewBindingCreated(binding: DialogErrorDetailsBinding, savedInstanceState: Bundle?) {
|
||||||
super.onViewBindingCreated(binding, savedInstanceState)
|
super.onViewBindingCreated(binding, savedInstanceState)
|
||||||
with(binding.textViewMessage) {
|
with(binding.textViewMessage) {
|
||||||
movementMethod = LinkMovementMethod.getInstance()
|
movementMethod = LinkMovementMethodCompat.getInstance()
|
||||||
text = context.getString(
|
text = context.getString(
|
||||||
R.string.manga_error_description_pattern,
|
R.string.manga_error_description_pattern,
|
||||||
exception.message?.htmlEncode().orEmpty(),
|
exception.message?.htmlEncode().orEmpty(),
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.koitharu.kotatsu.core.ui.list
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
||||||
|
|
||||||
|
class RecyclerScrollKeeper(
|
||||||
|
private val rv: RecyclerView,
|
||||||
|
) : AdapterDataObserver() {
|
||||||
|
|
||||||
|
private val scrollUpRunnable = Runnable {
|
||||||
|
(rv.layoutManager as? LinearLayoutManager)?.scrollToPositionWithOffset(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun attach() {
|
||||||
|
rv.adapter?.registerAdapterDataObserver(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||||
|
super.onItemRangeInserted(positionStart, itemCount)
|
||||||
|
if (positionStart == 0 && isScrolledToTop()) {
|
||||||
|
postScrollUp()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
|
||||||
|
super.onItemRangeMoved(fromPosition, toPosition, itemCount)
|
||||||
|
if (toPosition == 0 && isScrolledToTop()) {
|
||||||
|
postScrollUp()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun postScrollUp() {
|
||||||
|
rv.postDelayed(scrollUpRunnable, 500L)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isScrolledToTop(): Boolean {
|
||||||
|
return (rv.layoutManager as? LinearLayoutManager)?.findFirstVisibleItemPosition() == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 {
|
override fun isEmpty(): Boolean {
|
||||||
return state.isEmpty
|
return state.isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun iterator(): Iterator<T> {
|
override fun iterator(): Iterator<T> {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class CompositeMutex2<T : Any> : Set<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun isEmpty(): Boolean {
|
override fun isEmpty(): Boolean {
|
||||||
return delegates.isEmpty
|
return delegates.isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun iterator(): Iterator<T> {
|
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.database.ContentObserver
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
|
import dagger.hilt.android.scopes.ActivityScoped
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
import kotlinx.coroutines.channels.trySendBlocking
|
import kotlinx.coroutines.channels.trySendBlocking
|
||||||
import kotlinx.coroutines.flow.callbackFlow
|
import kotlinx.coroutines.flow.callbackFlow
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.onStart
|
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
|
val isAutoRotationEnabled: Boolean
|
||||||
get() = Settings.System.getInt(
|
get() = Settings.System.getInt(
|
||||||
@@ -31,9 +34,15 @@ class ScreenOrientationHelper(private val activity: Activity) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleOrientation() {
|
var isLocked: Boolean
|
||||||
isLandscape = !isLandscape
|
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 {
|
fun observeAutoOrientation() = callbackFlow {
|
||||||
val observer = object : ContentObserver(Handler(activity.mainLooper)) {
|
val observer = object : ContentObserver(Handler(activity.mainLooper)) {
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ fun <I> ActivityResultLauncher<I>.tryLaunch(
|
|||||||
e.printStackTraceDebug()
|
e.printStackTraceDebug()
|
||||||
}.isSuccess
|
}.isSuccess
|
||||||
|
|
||||||
fun SharedPreferences.observe() = callbackFlow<String?> {
|
fun SharedPreferences.observe(): Flow<String?> = callbackFlow {
|
||||||
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||||
trySendBlocking(key)
|
trySendBlocking(key)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ fun ImageView.newImageRequest(lifecycleOwner: LifecycleOwner, data: Any?): Image
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
disposeImageRequest()
|
// disposeImageRequest()
|
||||||
return ImageRequest.Builder(context)
|
return ImageRequest.Builder(context)
|
||||||
.data(data)
|
.data(data)
|
||||||
.lifecycle(lifecycleOwner)
|
.lifecycle(lifecycleOwner)
|
||||||
|
|||||||
@@ -26,6 +26,17 @@ fun <T> Flow<T>.onFirst(action: suspend (T) -> Unit): Flow<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> Flow<T>.onEachWhile(action: suspend (T) -> Boolean): Flow<T> {
|
||||||
|
var isCalled = false
|
||||||
|
return onEach {
|
||||||
|
if (!isCalled) {
|
||||||
|
isCalled = action(it)
|
||||||
|
}
|
||||||
|
}.onCompletion {
|
||||||
|
isCalled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline fun <T, R> Flow<List<T>>.mapItems(crossinline transform: (T) -> R): Flow<List<R>> {
|
inline fun <T, R> Flow<List<T>>.mapItems(crossinline transform: (T) -> R): Flow<List<R>> {
|
||||||
return map { list -> list.map(transform) }
|
return map { list -> list.map(transform) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import okhttp3.Response
|
|||||||
import okhttp3.internal.closeQuietly
|
import okhttp3.internal.closeQuietly
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import org.jsoup.HttpStatusException
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
|
|
||||||
private val TYPE_JSON = "application/json".toMediaType()
|
private val TYPE_JSON = "application/json".toMediaType()
|
||||||
@@ -34,9 +35,8 @@ val HttpUrl.isHttpOrHttps: Boolean
|
|||||||
|
|
||||||
fun Response.ensureSuccess() = apply {
|
fun Response.ensureSuccess() = apply {
|
||||||
if (!isSuccessful || code == HttpURLConnection.HTTP_NO_CONTENT) {
|
if (!isSuccessful || code == HttpURLConnection.HTTP_NO_CONTENT) {
|
||||||
val message = "Invalid response: $code $message at ${request.url}"
|
|
||||||
closeQuietly()
|
closeQuietly()
|
||||||
throw IllegalStateException(message)
|
throw HttpStatusException(message, code, request.url.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import androidx.core.view.children
|
|||||||
import androidx.core.view.descendants
|
import androidx.core.view.descendants
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
import com.google.android.material.progressindicator.BaseProgressIndicator
|
import com.google.android.material.progressindicator.BaseProgressIndicator
|
||||||
import com.google.android.material.slider.Slider
|
import com.google.android.material.slider.Slider
|
||||||
@@ -68,6 +69,10 @@ inline fun ViewPager2.doOnPageChanged(crossinline callback: (Int) -> Unit) {
|
|||||||
val ViewPager2.recyclerView: RecyclerView?
|
val ViewPager2.recyclerView: RecyclerView?
|
||||||
get() = children.firstNotNullOfOrNull { it as? RecyclerView }
|
get() = children.firstNotNullOfOrNull { it as? RecyclerView }
|
||||||
|
|
||||||
|
fun ViewPager2.findCurrentViewHolder(): ViewHolder? {
|
||||||
|
return recyclerView?.findViewHolderForAdapterPosition(currentItem)
|
||||||
|
}
|
||||||
|
|
||||||
fun View.resetTransformations() {
|
fun View.resetTransformations() {
|
||||||
alpha = 1f
|
alpha = 1f
|
||||||
translationX = 0f
|
translationX = 0f
|
||||||
|
|||||||
@@ -86,4 +86,6 @@ class DetailsInteractor @Inject constructor(
|
|||||||
subject
|
subject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun findRemote(seed: Manga) = localMangaRepository.getRemoteManga(seed)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import kotlinx.coroutines.async
|
|||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.channelFlow
|
import kotlinx.coroutines.flow.channelFlow
|
||||||
import kotlinx.coroutines.runInterruptible
|
import kotlinx.coroutines.runInterruptible
|
||||||
|
import okio.IOException
|
||||||
import org.koitharu.kotatsu.core.model.isLocal
|
import org.koitharu.kotatsu.core.model.isLocal
|
||||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.core.parser.MangaIntent
|
import org.koitharu.kotatsu.core.parser.MangaIntent
|
||||||
@@ -46,9 +47,15 @@ class DetailsLoadUseCase @Inject constructor(
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
send(MangaDetails(manga, null, null, false))
|
send(MangaDetails(manga, null, null, false))
|
||||||
val details = getDetails(manga)
|
try {
|
||||||
send(MangaDetails(details, local?.peek(), details.description?.parseAsHtml(withImages = false), false))
|
val details = getDetails(manga)
|
||||||
send(MangaDetails(details, local?.await(), details.description?.parseAsHtml(withImages = true), true))
|
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 {
|
private suspend fun getDetails(seed: Manga) = runCatchingCancellable {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.details.domain
|
|||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.model.findChapter
|
import org.koitharu.kotatsu.core.model.findChapter
|
||||||
import org.koitharu.kotatsu.core.model.isLocal
|
import org.koitharu.kotatsu.core.model.isLocal
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.history.data.PROGRESS_NONE
|
import org.koitharu.kotatsu.history.data.PROGRESS_NONE
|
||||||
import org.koitharu.kotatsu.local.data.LocalMangaRepository
|
import org.koitharu.kotatsu.local.data.LocalMangaRepository
|
||||||
@@ -13,15 +14,19 @@ class ProgressUpdateUseCase @Inject constructor(
|
|||||||
private val mangaRepositoryFactory: MangaRepository.Factory,
|
private val mangaRepositoryFactory: MangaRepository.Factory,
|
||||||
private val database: MangaDatabase,
|
private val database: MangaDatabase,
|
||||||
private val localMangaRepository: LocalMangaRepository,
|
private val localMangaRepository: LocalMangaRepository,
|
||||||
|
private val networkState: NetworkState,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(manga: Manga): Float {
|
suspend operator fun invoke(manga: Manga): Float {
|
||||||
val history = database.historyDao.find(manga.id) ?: return PROGRESS_NONE
|
val history = database.getHistoryDao().find(manga.id) ?: return PROGRESS_NONE
|
||||||
val seed = if (manga.isLocal) {
|
val seed = if (manga.isLocal) {
|
||||||
localMangaRepository.getRemoteManga(manga) ?: manga
|
localMangaRepository.getRemoteManga(manga) ?: manga
|
||||||
} else {
|
} else {
|
||||||
manga
|
manga
|
||||||
}
|
}
|
||||||
|
if (!seed.isLocal && !networkState.value) {
|
||||||
|
return PROGRESS_NONE
|
||||||
|
}
|
||||||
val repo = mangaRepositoryFactory.create(seed.source)
|
val repo = mangaRepositoryFactory.create(seed.source)
|
||||||
val details = if (manga.source != seed.source || seed.chapters.isNullOrEmpty()) {
|
val details = if (manga.source != seed.source || seed.chapters.isNullOrEmpty()) {
|
||||||
repo.getDetails(seed)
|
repo.getDetails(seed)
|
||||||
@@ -43,7 +48,7 @@ class ProgressUpdateUseCase @Inject constructor(
|
|||||||
val ppc = 1f / chaptersCount
|
val ppc = 1f / chaptersCount
|
||||||
val result = ppc * chapterIndex + ppc * pagePercent
|
val result = ppc * chapterIndex + ppc * pagePercent
|
||||||
if (result != history.percent) {
|
if (result != history.percent) {
|
||||||
database.historyDao.update(
|
database.getHistoryDao().update(
|
||||||
history.copy(
|
history.copy(
|
||||||
chapterId = chapter.id,
|
chapterId = chapter.id,
|
||||||
percent = result,
|
percent = result,
|
||||||
|
|||||||
@@ -137,7 +137,9 @@ class DetailsActivity :
|
|||||||
this,
|
this,
|
||||||
MenuInvalidator(viewBinding.toolbarChapters ?: this),
|
MenuInvalidator(viewBinding.toolbarChapters ?: this),
|
||||||
)
|
)
|
||||||
viewModel.favouriteCategories.observe(this, MenuInvalidator(this))
|
val menuInvalidator = MenuInvalidator(this)
|
||||||
|
viewModel.favouriteCategories.observe(this, menuInvalidator)
|
||||||
|
viewModel.remoteManga.observe(this, menuInvalidator)
|
||||||
viewModel.branches.observe(this) {
|
viewModel.branches.observe(this) {
|
||||||
viewBinding.buttonDropdown.isVisible = it.size > 1
|
viewBinding.buttonDropdown.isVisible = it.size > 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.details.ui
|
package org.koitharu.kotatsu.details.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.method.LinkMovementMethod
|
|
||||||
import android.transition.TransitionManager
|
import android.transition.TransitionManager
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -13,6 +12,7 @@ import androidx.core.content.ContextCompat
|
|||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.text.buildSpannedString
|
import androidx.core.text.buildSpannedString
|
||||||
import androidx.core.text.color
|
import androidx.core.text.color
|
||||||
|
import androidx.core.text.method.LinkMovementMethodCompat
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
@@ -81,7 +81,7 @@ class DetailsFragment :
|
|||||||
BaseFragment<FragmentDetailsBinding>(),
|
BaseFragment<FragmentDetailsBinding>(),
|
||||||
View.OnClickListener,
|
View.OnClickListener,
|
||||||
ChipsView.OnChipClickListener,
|
ChipsView.OnChipClickListener,
|
||||||
OnListItemClickListener<Bookmark>, ViewTreeObserver.OnDrawListener {
|
OnListItemClickListener<Bookmark>, ViewTreeObserver.OnDrawListener, View.OnLayoutChangeListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var coil: ImageLoader
|
lateinit var coil: ImageLoader
|
||||||
@@ -105,8 +105,9 @@ class DetailsFragment :
|
|||||||
binding.buttonScrobblingMore.setOnClickListener(this)
|
binding.buttonScrobblingMore.setOnClickListener(this)
|
||||||
binding.buttonRelatedMore.setOnClickListener(this)
|
binding.buttonRelatedMore.setOnClickListener(this)
|
||||||
binding.infoLayout.textViewSource.setOnClickListener(this)
|
binding.infoLayout.textViewSource.setOnClickListener(this)
|
||||||
|
binding.textViewDescription.addOnLayoutChangeListener(this)
|
||||||
binding.textViewDescription.viewTreeObserver.addOnDrawListener(this)
|
binding.textViewDescription.viewTreeObserver.addOnDrawListener(this)
|
||||||
binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance()
|
binding.textViewDescription.movementMethod = LinkMovementMethodCompat.getInstance()
|
||||||
binding.chipsTags.onChipClickListener = this
|
binding.chipsTags.onChipClickListener = this
|
||||||
binding.recyclerViewRelated.addItemDecoration(
|
binding.recyclerViewRelated.addItemDecoration(
|
||||||
SpacingItemDecoration(resources.getDimensionPixelOffset(R.dimen.grid_spacing)),
|
SpacingItemDecoration(resources.getDimensionPixelOffset(R.dimen.grid_spacing)),
|
||||||
@@ -150,6 +151,22 @@ class DetailsFragment :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onLayoutChange(
|
||||||
|
v: View?,
|
||||||
|
left: Int,
|
||||||
|
top: Int,
|
||||||
|
right: Int,
|
||||||
|
bottom: Int,
|
||||||
|
oldLeft: Int,
|
||||||
|
oldTop: Int,
|
||||||
|
oldRight: Int,
|
||||||
|
oldBottom: Int
|
||||||
|
) {
|
||||||
|
with(viewBinding ?: return) {
|
||||||
|
buttonDescriptionMore.isVisible = textViewDescription.isTextTruncated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun onMangaUpdated(manga: Manga) {
|
private fun onMangaUpdated(manga: Manga) {
|
||||||
with(requireViewBinding()) {
|
with(requireViewBinding()) {
|
||||||
// Main
|
// Main
|
||||||
@@ -180,6 +197,11 @@ class DetailsFragment :
|
|||||||
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_state_abandoned)
|
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
|
null -> infoLayout.textViewState.isVisible = false
|
||||||
}
|
}
|
||||||
if (manga.source == MangaSource.LOCAL) {
|
if (manga.source == MangaSource.LOCAL) {
|
||||||
@@ -228,7 +250,6 @@ class DetailsFragment :
|
|||||||
} else {
|
} else {
|
||||||
tv.text = description
|
tv.text = description
|
||||||
}
|
}
|
||||||
requireViewBinding().buttonDescriptionMore.isVisible = tv.isTextTruncated
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onLocalSizeChanged(size: Long) {
|
private fun onLocalSizeChanged(size: Long) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import org.koitharu.kotatsu.core.os.AppShortcutManager
|
|||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.core.util.ShareHelper
|
import org.koitharu.kotatsu.core.util.ShareHelper
|
||||||
import org.koitharu.kotatsu.download.ui.dialog.DownloadOption
|
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.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.scrobbling.common.ui.selector.ScrobblingSelectorSheet
|
import org.koitharu.kotatsu.scrobbling.common.ui.selector.ScrobblingSelectorSheet
|
||||||
import org.koitharu.kotatsu.search.ui.multi.MultiSearchActivity
|
import org.koitharu.kotatsu.search.ui.multi.MultiSearchActivity
|
||||||
@@ -42,6 +42,7 @@ class DetailsMenuProvider(
|
|||||||
menu.findItem(R.id.action_browser).isVisible = manga?.source != MangaSource.LOCAL
|
menu.findItem(R.id.action_browser).isVisible = manga?.source != MangaSource.LOCAL
|
||||||
menu.findItem(R.id.action_shortcut).isVisible = ShortcutManagerCompat.isRequestPinShortcutSupported(activity)
|
menu.findItem(R.id.action_shortcut).isVisible = ShortcutManagerCompat.isRequestPinShortcutSupported(activity)
|
||||||
menu.findItem(R.id.action_scrobbling).isVisible = viewModel.isScrobblingAvailable
|
menu.findItem(R.id.action_scrobbling).isVisible = viewModel.isScrobblingAvailable
|
||||||
|
menu.findItem(R.id.action_online).isVisible = viewModel.remoteManga.value != null
|
||||||
menu.findItem(R.id.action_favourite).setIcon(
|
menu.findItem(R.id.action_favourite).setIcon(
|
||||||
if (viewModel.favouriteCategories.value) R.drawable.ic_heart else R.drawable.ic_heart_outline,
|
if (viewModel.favouriteCategories.value) R.drawable.ic_heart else R.drawable.ic_heart_outline,
|
||||||
)
|
)
|
||||||
@@ -62,7 +63,7 @@ class DetailsMenuProvider(
|
|||||||
|
|
||||||
R.id.action_favourite -> {
|
R.id.action_favourite -> {
|
||||||
viewModel.manga.value?.let {
|
viewModel.manga.value?.let {
|
||||||
FavouriteSheet.show(activity.supportFragmentManager, it)
|
FavoriteSheet.show(activity.supportFragmentManager, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +89,12 @@ class DetailsMenuProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R.id.action_online -> {
|
||||||
|
viewModel.remoteManga.value?.let {
|
||||||
|
activity.startActivity(DetailsActivity.newIntent(activity, it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
R.id.action_related -> {
|
R.id.action_related -> {
|
||||||
viewModel.manga.value?.let {
|
viewModel.manga.value?.let {
|
||||||
activity.startActivity(MultiSearchActivity.newIntent(activity, it.title))
|
activity.startActivity(MultiSearchActivity.newIntent(activity, it.title))
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import org.koitharu.kotatsu.core.ui.BaseViewModel
|
|||||||
import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
|
import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
|
||||||
import org.koitharu.kotatsu.core.util.ext.call
|
import org.koitharu.kotatsu.core.util.ext.call
|
||||||
import org.koitharu.kotatsu.core.util.ext.computeSize
|
import org.koitharu.kotatsu.core.util.ext.computeSize
|
||||||
import org.koitharu.kotatsu.core.util.ext.onFirst
|
import org.koitharu.kotatsu.core.util.ext.onEachWhile
|
||||||
import org.koitharu.kotatsu.core.util.ext.requireValue
|
import org.koitharu.kotatsu.core.util.ext.requireValue
|
||||||
import org.koitharu.kotatsu.details.data.MangaDetails
|
import org.koitharu.kotatsu.details.data.MangaDetails
|
||||||
import org.koitharu.kotatsu.details.domain.BranchComparator
|
import org.koitharu.kotatsu.details.domain.BranchComparator
|
||||||
@@ -94,6 +94,8 @@ class DetailsViewModel @Inject constructor(
|
|||||||
val favouriteCategories = interactor.observeIsFavourite(mangaId)
|
val favouriteCategories = interactor.observeIsFavourite(mangaId)
|
||||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, false)
|
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, false)
|
||||||
|
|
||||||
|
val remoteManga = MutableStateFlow<Manga?>(null)
|
||||||
|
|
||||||
val newChaptersCount = details.flatMapLatest { d ->
|
val newChaptersCount = details.flatMapLatest { d ->
|
||||||
if (d?.isLocal == false) {
|
if (d?.isLocal == false) {
|
||||||
interactor.observeNewChapters(mangaId)
|
interactor.observeNewChapters(mangaId)
|
||||||
@@ -147,15 +149,13 @@ class DetailsViewModel @Inject constructor(
|
|||||||
val scrobblingInfo: StateFlow<List<ScrobblingInfo>> = interactor.observeScrobblingInfo(mangaId)
|
val scrobblingInfo: StateFlow<List<ScrobblingInfo>> = interactor.observeScrobblingInfo(mangaId)
|
||||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, emptyList())
|
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, emptyList())
|
||||||
|
|
||||||
val relatedManga: StateFlow<List<MangaItemModel>> = manga
|
val relatedManga: StateFlow<List<MangaItemModel>> = manga.mapLatest {
|
||||||
.mapLatest {
|
if (it != null && settings.isRelatedMangaEnabled) {
|
||||||
if (it != null && settings.isRelatedMangaEnabled) {
|
relatedMangaUseCase.invoke(it)?.toUi(ListMode.GRID, extraProvider).orEmpty()
|
||||||
relatedMangaUseCase.invoke(it)?.toUi(ListMode.GRID, extraProvider).orEmpty()
|
} else {
|
||||||
} else {
|
emptyList()
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.stateIn(viewModelScope, SharingStarted.Lazily, emptyList())
|
}.stateIn(viewModelScope, SharingStarted.Lazily, emptyList())
|
||||||
|
|
||||||
val branches: StateFlow<List<MangaBranch>> = combine(
|
val branches: StateFlow<List<MangaBranch>> = combine(
|
||||||
details,
|
details,
|
||||||
@@ -213,6 +213,10 @@ class DetailsViewModel @Inject constructor(
|
|||||||
progressUpdateUseCase(manga.toManga())
|
progressUpdateUseCase(manga.toManga())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
launchJob(Dispatchers.Default) {
|
||||||
|
val manga = details.firstOrNull { it != null && it.isLocal } ?: return@launchJob
|
||||||
|
remoteManga.value = interactor.findRemote(manga.toManga())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reload() {
|
fun reload() {
|
||||||
@@ -313,11 +317,15 @@ class DetailsViewModel @Inject constructor(
|
|||||||
|
|
||||||
private fun doLoad() = launchLoadingJob(Dispatchers.Default) {
|
private fun doLoad() = launchLoadingJob(Dispatchers.Default) {
|
||||||
detailsLoadUseCase.invoke(intent)
|
detailsLoadUseCase.invoke(intent)
|
||||||
.onFirst {
|
.onEachWhile {
|
||||||
|
if (it.allChapters.isEmpty()) {
|
||||||
|
return@onEachWhile false
|
||||||
|
}
|
||||||
val manga = it.toManga()
|
val manga = it.toManga()
|
||||||
// find default branch
|
// find default branch
|
||||||
val hist = historyRepository.getOne(manga)
|
val hist = historyRepository.getOne(manga)
|
||||||
selectedBranch.value = manga.getPreferredBranch(hist)
|
selectedBranch.value = manga.getPreferredBranch(hist)
|
||||||
|
true
|
||||||
}.collect {
|
}.collect {
|
||||||
details.value = it
|
details.value = it
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.koitharu.kotatsu.details.ui.scrobbling
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.method.LinkMovementMethod
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -12,6 +11,7 @@ import android.widget.RatingBar
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.widget.PopupMenu
|
import androidx.appcompat.widget.PopupMenu
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import androidx.core.text.method.LinkMovementMethodCompat
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
@@ -71,7 +71,7 @@ class ScrobblingInfoSheet :
|
|||||||
binding.ratingBar.onRatingBarChangeListener = this
|
binding.ratingBar.onRatingBarChangeListener = this
|
||||||
binding.buttonMenu.setOnClickListener(this)
|
binding.buttonMenu.setOnClickListener(this)
|
||||||
binding.imageViewCover.setOnClickListener(this)
|
binding.imageViewCover.setOnClickListener(this)
|
||||||
binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance()
|
binding.textViewDescription.movementMethod = LinkMovementMethodCompat.getInstance()
|
||||||
|
|
||||||
menu = PopupMenu(binding.root.context, binding.buttonMenu).apply {
|
menu = PopupMenu(binding.root.context, binding.buttonMenu).apply {
|
||||||
inflate(R.menu.opt_scrobbling)
|
inflate(R.menu.opt_scrobbling)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ data class DownloadState(
|
|||||||
val currentPage: Int = 0,
|
val currentPage: Int = 0,
|
||||||
val eta: Long = -1L,
|
val eta: Long = -1L,
|
||||||
val localManga: LocalManga? = null,
|
val localManga: LocalManga? = null,
|
||||||
val downloadedChapters: LongArray = LongArray(0),
|
val downloadedChapters: Int = 0,
|
||||||
val timestamp: Long = System.currentTimeMillis(),
|
val timestamp: Long = System.currentTimeMillis(),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -41,61 +41,17 @@ data class DownloadState(
|
|||||||
.putLong(DATA_ETA, eta)
|
.putLong(DATA_ETA, eta)
|
||||||
.putLong(DATA_TIMESTAMP, timestamp)
|
.putLong(DATA_TIMESTAMP, timestamp)
|
||||||
.putString(DATA_ERROR, error)
|
.putString(DATA_ERROR, error)
|
||||||
.putLongArray(DATA_CHAPTERS, downloadedChapters)
|
.putInt(DATA_CHAPTERS, downloadedChapters)
|
||||||
.putBoolean(DATA_INDETERMINATE, isIndeterminate)
|
.putBoolean(DATA_INDETERMINATE, isIndeterminate)
|
||||||
.putBoolean(DATA_PAUSED, isPaused)
|
.putBoolean(DATA_PAUSED, isPaused)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as DownloadState
|
|
||||||
|
|
||||||
if (manga != other.manga) return false
|
|
||||||
if (isIndeterminate != other.isIndeterminate) return false
|
|
||||||
if (isPaused != other.isPaused) return false
|
|
||||||
if (isStopped != other.isStopped) return false
|
|
||||||
if (error != other.error) return false
|
|
||||||
if (totalChapters != other.totalChapters) return false
|
|
||||||
if (currentChapter != other.currentChapter) return false
|
|
||||||
if (totalPages != other.totalPages) return false
|
|
||||||
if (currentPage != other.currentPage) return false
|
|
||||||
if (eta != other.eta) return false
|
|
||||||
if (localManga != other.localManga) return false
|
|
||||||
if (!downloadedChapters.contentEquals(other.downloadedChapters)) return false
|
|
||||||
if (timestamp != other.timestamp) return false
|
|
||||||
if (max != other.max) return false
|
|
||||||
if (progress != other.progress) return false
|
|
||||||
return percent == other.percent
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = manga.hashCode()
|
|
||||||
result = 31 * result + isIndeterminate.hashCode()
|
|
||||||
result = 31 * result + isPaused.hashCode()
|
|
||||||
result = 31 * result + isStopped.hashCode()
|
|
||||||
result = 31 * result + (error?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + totalChapters
|
|
||||||
result = 31 * result + currentChapter
|
|
||||||
result = 31 * result + totalPages
|
|
||||||
result = 31 * result + currentPage
|
|
||||||
result = 31 * result + eta.hashCode()
|
|
||||||
result = 31 * result + (localManga?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + downloadedChapters.contentHashCode()
|
|
||||||
result = 31 * result + timestamp.hashCode()
|
|
||||||
result = 31 * result + max
|
|
||||||
result = 31 * result + progress
|
|
||||||
result = 31 * result + percent.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val DATA_MANGA_ID = "manga_id"
|
private const val DATA_MANGA_ID = "manga_id"
|
||||||
private const val DATA_MAX = "max"
|
private const val DATA_MAX = "max"
|
||||||
private const val DATA_PROGRESS = "progress"
|
private const val DATA_PROGRESS = "progress"
|
||||||
private const val DATA_CHAPTERS = "chapter"
|
private const val DATA_CHAPTERS = "chapter_cnt"
|
||||||
private const val DATA_ETA = "eta"
|
private const val DATA_ETA = "eta"
|
||||||
private const val DATA_TIMESTAMP = "timestamp"
|
private const val DATA_TIMESTAMP = "timestamp"
|
||||||
private const val DATA_ERROR = "error"
|
private const val DATA_ERROR = "error"
|
||||||
@@ -118,6 +74,6 @@ data class DownloadState(
|
|||||||
|
|
||||||
fun getTimestamp(data: Data): Date = Date(data.getLong(DATA_TIMESTAMP, 0L))
|
fun getTimestamp(data: Data): Date = Date(data.getLong(DATA_TIMESTAMP, 0L))
|
||||||
|
|
||||||
fun getDownloadedChapters(data: Data): LongArray = data.getLongArray(DATA_CHAPTERS) ?: LongArray(0)
|
fun getDownloadedChapters(data: Data): Int = data.getInt(DATA_CHAPTERS, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
package org.koitharu.kotatsu.download.ui.list
|
package org.koitharu.kotatsu.download.ui.list
|
||||||
|
|
||||||
|
import android.transition.TransitionManager
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.work.WorkInfo
|
import androidx.work.WorkInfo
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
|
import coil.request.SuccessResult
|
||||||
|
import coil.util.CoilUtils
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
||||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||||
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
||||||
import org.koitharu.kotatsu.core.util.ext.source
|
import org.koitharu.kotatsu.core.util.ext.source
|
||||||
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
||||||
import org.koitharu.kotatsu.databinding.ItemDownloadBinding
|
import org.koitharu.kotatsu.databinding.ItemDownloadBinding
|
||||||
|
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.parsers.util.format
|
import org.koitharu.kotatsu.parsers.util.format
|
||||||
|
|
||||||
@@ -25,6 +30,7 @@ fun downloadItemAD(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
val percentPattern = context.resources.getString(R.string.percent_string_pattern)
|
val percentPattern = context.resources.getString(R.string.percent_string_pattern)
|
||||||
|
// val expandIcon = ContextCompat.getDrawable(context, R.drawable.ic_expand_collapse)
|
||||||
|
|
||||||
val clickListener = object : View.OnClickListener, View.OnLongClickListener {
|
val clickListener = object : View.OnClickListener, View.OnLongClickListener {
|
||||||
override fun onClick(v: View) {
|
override fun onClick(v: View) {
|
||||||
@@ -47,16 +53,24 @@ fun downloadItemAD(
|
|||||||
itemView.setOnLongClickListener(clickListener)
|
itemView.setOnLongClickListener(clickListener)
|
||||||
|
|
||||||
bind { payloads ->
|
bind { payloads ->
|
||||||
binding.textViewTitle.text = item.manga.title
|
if (ListModelDiffCallback.PAYLOAD_CHECKED_CHANGED in payloads && context.isAnimationsEnabled) {
|
||||||
binding.imageViewCover.newImageRequest(lifecycleOwner, item.manga.coverUrl)?.apply {
|
TransitionManager.beginDelayedTransition(binding.constraintLayout)
|
||||||
placeholder(R.drawable.ic_placeholder)
|
|
||||||
fallback(R.drawable.ic_placeholder)
|
|
||||||
error(R.drawable.ic_error_placeholder)
|
|
||||||
allowRgb565(true)
|
|
||||||
transformations(TrimTransformation())
|
|
||||||
source(item.manga.source)
|
|
||||||
enqueueWith(coil)
|
|
||||||
}
|
}
|
||||||
|
binding.textViewTitle.text = item.manga.title
|
||||||
|
if ((CoilUtils.result(binding.imageViewCover) as? SuccessResult)?.memoryCacheKey != item.coverCacheKey) {
|
||||||
|
binding.imageViewCover.newImageRequest(lifecycleOwner, item.manga.coverUrl)?.apply {
|
||||||
|
placeholder(R.drawable.ic_placeholder)
|
||||||
|
fallback(R.drawable.ic_placeholder)
|
||||||
|
error(R.drawable.ic_error_placeholder)
|
||||||
|
allowRgb565(true)
|
||||||
|
transformations(TrimTransformation())
|
||||||
|
memoryCacheKey(item.coverCacheKey)
|
||||||
|
source(item.manga.source)
|
||||||
|
enqueueWith(coil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// binding.textViewTitle.isChecked = item.isExpanded
|
||||||
|
// binding.textViewTitle.drawableEnd = if (item.isExpandable) expandIcon else null
|
||||||
when (item.workState) {
|
when (item.workState) {
|
||||||
WorkInfo.State.ENQUEUED,
|
WorkInfo.State.ENQUEUED,
|
||||||
WorkInfo.State.BLOCKED -> {
|
WorkInfo.State.BLOCKED -> {
|
||||||
@@ -94,11 +108,11 @@ fun downloadItemAD(
|
|||||||
binding.progressBar.isVisible = false
|
binding.progressBar.isVisible = false
|
||||||
binding.progressBar.isEnabled = true
|
binding.progressBar.isEnabled = true
|
||||||
binding.textViewPercent.isVisible = false
|
binding.textViewPercent.isVisible = false
|
||||||
if (item.totalChapters > 0) {
|
if (item.chaptersDownloaded > 0) {
|
||||||
binding.textViewDetails.text = context.resources.getQuantityString(
|
binding.textViewDetails.text = context.resources.getQuantityString(
|
||||||
R.plurals.chapters,
|
R.plurals.chapters,
|
||||||
item.totalChapters,
|
item.chaptersDownloaded,
|
||||||
item.totalChapters,
|
item.chaptersDownloaded,
|
||||||
)
|
)
|
||||||
binding.textViewDetails.isVisible = true
|
binding.textViewDetails.isVisible = true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package org.koitharu.kotatsu.download.ui.list
|
|||||||
|
|
||||||
import android.text.format.DateUtils
|
import android.text.format.DateUtils
|
||||||
import androidx.work.WorkInfo
|
import androidx.work.WorkInfo
|
||||||
|
import coil.memory.MemoryCache
|
||||||
|
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
@@ -15,12 +17,15 @@ data class DownloadItemModel(
|
|||||||
val manga: Manga,
|
val manga: Manga,
|
||||||
val error: String?,
|
val error: String?,
|
||||||
val max: Int,
|
val max: Int,
|
||||||
val totalChapters: Int,
|
|
||||||
val progress: Int,
|
val progress: Int,
|
||||||
val eta: Long,
|
val eta: Long,
|
||||||
val timestamp: Date,
|
val timestamp: Date,
|
||||||
|
val chaptersDownloaded: Int,
|
||||||
|
val isExpanded: Boolean,
|
||||||
) : ListModel, Comparable<DownloadItemModel> {
|
) : ListModel, Comparable<DownloadItemModel> {
|
||||||
|
|
||||||
|
val coverCacheKey = MemoryCache.Key(manga.coverUrl, mapOf("dl" to "1"))
|
||||||
|
|
||||||
val percent: Float
|
val percent: Float
|
||||||
get() = if (max > 0) progress / max.toFloat() else 0f
|
get() = if (max > 0) progress / max.toFloat() else 0f
|
||||||
|
|
||||||
@@ -33,6 +38,9 @@ data class DownloadItemModel(
|
|||||||
val canResume: Boolean
|
val canResume: Boolean
|
||||||
get() = workState == WorkInfo.State.RUNNING && isPaused
|
get() = workState == WorkInfo.State.RUNNING && isPaused
|
||||||
|
|
||||||
|
val isExpandable: Boolean
|
||||||
|
get() = false // TODO
|
||||||
|
|
||||||
fun getEtaString(): CharSequence? = if (hasEta) {
|
fun getEtaString(): CharSequence? = if (hasEta) {
|
||||||
DateUtils.getRelativeTimeSpanString(
|
DateUtils.getRelativeTimeSpanString(
|
||||||
eta,
|
eta,
|
||||||
@@ -51,17 +59,10 @@ data class DownloadItemModel(
|
|||||||
return other is DownloadItemModel && other.id == id
|
return other is DownloadItemModel && other.id == id
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChangePayload(previousState: ListModel): Any? {
|
override fun getChangePayload(previousState: ListModel): Any? = when {
|
||||||
return when (previousState) {
|
previousState !is DownloadItemModel -> super.getChangePayload(previousState)
|
||||||
is DownloadItemModel -> {
|
workState != previousState.workState -> null
|
||||||
if (workState == previousState.workState) {
|
isExpanded != previousState.isExpanded -> ListModelDiffCallback.PAYLOAD_CHECKED_CHANGED
|
||||||
Unit
|
else -> ListModelDiffCallback.PAYLOAD_ANYTHING_CHANGED
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> super.getChangePayload(previousState)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.ui.BaseActivity
|
import org.koitharu.kotatsu.core.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
||||||
|
import org.koitharu.kotatsu.core.ui.list.RecyclerScrollKeeper
|
||||||
import org.koitharu.kotatsu.core.ui.util.MenuInvalidator
|
import org.koitharu.kotatsu.core.ui.util.MenuInvalidator
|
||||||
import org.koitharu.kotatsu.core.ui.util.ReversibleActionObserver
|
import org.koitharu.kotatsu.core.ui.util.ReversibleActionObserver
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
@@ -53,6 +54,7 @@ class DownloadsActivity : BaseActivity<ActivityDownloadsBinding>(),
|
|||||||
addItemDecoration(decoration)
|
addItemDecoration(decoration)
|
||||||
adapter = downloadsAdapter
|
adapter = downloadsAdapter
|
||||||
selectionController.attachToRecyclerView(this)
|
selectionController.attachToRecyclerView(this)
|
||||||
|
RecyclerScrollKeeper(this).attach()
|
||||||
}
|
}
|
||||||
addMenuProvider(DownloadsMenuProvider(this, viewModel))
|
addMenuProvider(DownloadsMenuProvider(this, viewModel))
|
||||||
viewModel.items.observe(this) {
|
viewModel.items.observe(this) {
|
||||||
@@ -82,7 +84,11 @@ class DownloadsActivity : BaseActivity<ActivityDownloadsBinding>(),
|
|||||||
if (selectionController.onItemClick(item.id.mostSignificantBits)) {
|
if (selectionController.onItemClick(item.id.mostSignificantBits)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
startActivity(DetailsActivity.newIntent(view.context, item.manga))
|
if (item.isExpandable) {
|
||||||
|
viewModel.expandCollapse(item)
|
||||||
|
} else {
|
||||||
|
startActivity(DetailsActivity.newIntent(view.context, item.manga))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemLongClick(item: DownloadItemModel, view: View): Boolean {
|
override fun onItemLongClick(item: DownloadItemModel, view: View): Boolean {
|
||||||
|
|||||||
@@ -8,15 +8,19 @@ import androidx.work.Data
|
|||||||
import androidx.work.WorkInfo
|
import androidx.work.WorkInfo
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.mapLatest
|
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.plus
|
import kotlinx.coroutines.plus
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||||
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
||||||
import org.koitharu.kotatsu.core.ui.model.DateTimeAgo
|
import org.koitharu.kotatsu.core.ui.model.DateTimeAgo
|
||||||
import org.koitharu.kotatsu.core.ui.util.ReversibleAction
|
import org.koitharu.kotatsu.core.ui.util.ReversibleAction
|
||||||
@@ -31,6 +35,7 @@ import org.koitharu.kotatsu.list.ui.model.ListModel
|
|||||||
import org.koitharu.kotatsu.list.ui.model.LoadingState
|
import org.koitharu.kotatsu.list.ui.model.LoadingState
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||||
|
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
@@ -41,13 +46,18 @@ import javax.inject.Inject
|
|||||||
class DownloadsViewModel @Inject constructor(
|
class DownloadsViewModel @Inject constructor(
|
||||||
private val workScheduler: DownloadWorker.Scheduler,
|
private val workScheduler: DownloadWorker.Scheduler,
|
||||||
private val mangaDataRepository: MangaDataRepository,
|
private val mangaDataRepository: MangaDataRepository,
|
||||||
|
private val mangaRepositoryFactory: MangaRepository.Factory,
|
||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
|
|
||||||
private val mangaCache = LongSparseArray<Manga>()
|
private val mangaCache = LongSparseArray<Manga>()
|
||||||
private val cacheMutex = Mutex()
|
private val cacheMutex = Mutex()
|
||||||
private val works = workScheduler.observeWorks()
|
private val expanded = MutableStateFlow(emptySet<UUID>())
|
||||||
.mapLatest { it.toDownloadsList() }
|
private val works = combine(
|
||||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, null)
|
workScheduler.observeWorks(),
|
||||||
|
expanded,
|
||||||
|
) { list, exp ->
|
||||||
|
list.toDownloadsList(exp)
|
||||||
|
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, null)
|
||||||
|
|
||||||
val onActionDone = MutableEventFlow<ReversibleAction>()
|
val onActionDone = MutableEventFlow<ReversibleAction>()
|
||||||
|
|
||||||
@@ -169,11 +179,21 @@ class DownloadsViewModel @Inject constructor(
|
|||||||
it.id.mostSignificantBits
|
it.id.mostSignificantBits
|
||||||
} ?: emptySet()
|
} ?: emptySet()
|
||||||
|
|
||||||
private suspend fun List<WorkInfo>.toDownloadsList(): List<DownloadItemModel> {
|
fun expandCollapse(item: DownloadItemModel) {
|
||||||
|
expanded.update {
|
||||||
|
if (item.id in it) {
|
||||||
|
it - item.id
|
||||||
|
} else {
|
||||||
|
it + item.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun List<WorkInfo>.toDownloadsList(exp: Set<UUID>): List<DownloadItemModel> {
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
val list = mapNotNullTo(ArrayList(size)) { it.toUiModel() }
|
val list = mapNotNullTo(ArrayList(size)) { it.toUiModel(it.id in exp) }
|
||||||
list.sortByDescending { it.timestamp }
|
list.sortByDescending { it.timestamp }
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
@@ -213,7 +233,7 @@ class DownloadsViewModel @Inject constructor(
|
|||||||
return destination
|
return destination
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun WorkInfo.toUiModel(): DownloadItemModel? {
|
private suspend fun WorkInfo.toUiModel(isExpanded: Boolean): DownloadItemModel? {
|
||||||
val workData = if (outputData == Data.EMPTY) progress else outputData
|
val workData = if (outputData == Data.EMPTY) progress else outputData
|
||||||
val mangaId = DownloadState.getMangaId(workData)
|
val mangaId = DownloadState.getMangaId(workData)
|
||||||
if (mangaId == 0L) return null
|
if (mangaId == 0L) return null
|
||||||
@@ -229,7 +249,8 @@ class DownloadsViewModel @Inject constructor(
|
|||||||
progress = DownloadState.getProgress(workData),
|
progress = DownloadState.getProgress(workData),
|
||||||
eta = DownloadState.getEta(workData),
|
eta = DownloadState.getEta(workData),
|
||||||
timestamp = DownloadState.getTimestamp(workData),
|
timestamp = DownloadState.getTimestamp(workData),
|
||||||
totalChapters = DownloadState.getDownloadedChapters(workData).size,
|
chaptersDownloaded = DownloadState.getDownloadedChapters(workData),
|
||||||
|
isExpanded = isExpanded,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,8 +282,16 @@ class DownloadsViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
return cacheMutex.withLock {
|
return cacheMutex.withLock {
|
||||||
mangaCache.getOrElse(mangaId) {
|
mangaCache.getOrElse(mangaId) {
|
||||||
mangaDataRepository.findMangaById(mangaId)?.also { mangaCache[mangaId] = it } ?: return null
|
mangaDataRepository.findMangaById(mangaId)?.let {
|
||||||
|
tryLoad(it) ?: it
|
||||||
|
}?.also {
|
||||||
|
mangaCache[mangaId] = it
|
||||||
|
} ?: return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun tryLoad(manga: Manga) = runCatchingCancellable {
|
||||||
|
(mangaRepositoryFactory.create(manga.source) as RemoteMangaRepository).peekDetails(manga)
|
||||||
|
}.getOrNull()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.koitharu.kotatsu.download.ui.list.chapters
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
|
||||||
|
data class DownloadChapter(
|
||||||
|
val number: Int,
|
||||||
|
val name: String,
|
||||||
|
val isDownloaded: Boolean,
|
||||||
|
) : ListModel {
|
||||||
|
|
||||||
|
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||||
|
return other is DownloadChapter && other.name == name
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.koitharu.kotatsu.download.ui.list.chapters
|
||||||
|
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.drawableEnd
|
||||||
|
import org.koitharu.kotatsu.databinding.ItemChapterDownloadBinding
|
||||||
|
|
||||||
|
fun downloadChapterAD() = adapterDelegateViewBinding<DownloadChapter, DownloadChapter, ItemChapterDownloadBinding>(
|
||||||
|
{ layoutInflater, parent -> ItemChapterDownloadBinding.inflate(layoutInflater, parent, false) },
|
||||||
|
) {
|
||||||
|
|
||||||
|
val iconDone = ContextCompat.getDrawable(context, R.drawable.ic_check)
|
||||||
|
|
||||||
|
bind {
|
||||||
|
binding.textViewNumber.text = item.number.toString()
|
||||||
|
binding.textViewTitle.text = item.name
|
||||||
|
binding.textViewTitle.drawableEnd = if (item.isDownloaded) iconDone else null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,6 +38,7 @@ import okio.buffer
|
|||||||
import okio.sink
|
import okio.sink
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions
|
import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions
|
||||||
|
import org.koitharu.kotatsu.core.model.ids
|
||||||
import org.koitharu.kotatsu.core.network.CommonHeaders
|
import org.koitharu.kotatsu.core.network.CommonHeaders
|
||||||
import org.koitharu.kotatsu.core.network.MangaHttpClient
|
import org.koitharu.kotatsu.core.network.MangaHttpClient
|
||||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||||
@@ -46,7 +47,6 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
|
|||||||
import org.koitharu.kotatsu.core.util.Throttler
|
import org.koitharu.kotatsu.core.util.Throttler
|
||||||
import org.koitharu.kotatsu.core.util.ext.awaitFinishedWorkInfosByTag
|
import org.koitharu.kotatsu.core.util.ext.awaitFinishedWorkInfosByTag
|
||||||
import org.koitharu.kotatsu.core.util.ext.awaitUpdateWork
|
import org.koitharu.kotatsu.core.util.ext.awaitUpdateWork
|
||||||
import org.koitharu.kotatsu.core.util.ext.awaitWorkInfoById
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.awaitWorkInfosByTag
|
import org.koitharu.kotatsu.core.util.ext.awaitWorkInfosByTag
|
||||||
import org.koitharu.kotatsu.core.util.ext.deleteAwait
|
import org.koitharu.kotatsu.core.util.ext.deleteAwait
|
||||||
import org.koitharu.kotatsu.core.util.ext.deleteWork
|
import org.koitharu.kotatsu.core.util.ext.deleteWork
|
||||||
@@ -105,11 +105,12 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
setForeground(getForegroundInfo())
|
setForeground(getForegroundInfo())
|
||||||
val mangaId = inputData.getLong(MANGA_ID, 0L)
|
val mangaId = inputData.getLong(MANGA_ID, 0L)
|
||||||
val manga = mangaDataRepository.findMangaById(mangaId) ?: return Result.failure()
|
val manga = mangaDataRepository.findMangaById(mangaId) ?: return Result.failure()
|
||||||
val chaptersIds = inputData.getLongArray(CHAPTERS_IDS)?.takeUnless { it.isEmpty() }
|
|
||||||
val downloadedIds = getDoneChapters()
|
|
||||||
lastPublishedState = DownloadState(manga, isIndeterminate = true)
|
lastPublishedState = DownloadState(manga, isIndeterminate = true)
|
||||||
|
publishState(DownloadState(manga, isIndeterminate = true))
|
||||||
|
val chaptersIds = inputData.getLongArray(CHAPTERS_IDS)?.takeUnless { it.isEmpty() }
|
||||||
|
val downloadedIds = getDoneChapters(manga)
|
||||||
return try {
|
return try {
|
||||||
downloadMangaImpl(chaptersIds, downloadedIds)
|
downloadMangaImpl(manga, chaptersIds, downloadedIds)
|
||||||
Result.success(currentState.toWorkData())
|
Result.success(currentState.toWorkData())
|
||||||
} catch (e: CancellationException) {
|
} catch (e: CancellationException) {
|
||||||
withContext(NonCancellable) {
|
withContext(NonCancellable) {
|
||||||
@@ -147,10 +148,11 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun downloadMangaImpl(
|
private suspend fun downloadMangaImpl(
|
||||||
|
subject: Manga,
|
||||||
includedIds: LongArray?,
|
includedIds: LongArray?,
|
||||||
excludedIds: LongArray,
|
excludedIds: Set<Long>,
|
||||||
) {
|
) {
|
||||||
var manga = currentState.manga
|
var manga = subject
|
||||||
val chaptersToSkip = excludedIds.toMutableSet()
|
val chaptersToSkip = excludedIds.toMutableSet()
|
||||||
withMangaLock(manga) {
|
withMangaLock(manga) {
|
||||||
ContextCompat.registerReceiver(
|
ContextCompat.registerReceiver(
|
||||||
@@ -180,11 +182,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
val chapters = getChapters(mangaDetails, includedIds)
|
val chapters = getChapters(mangaDetails, includedIds)
|
||||||
for ((chapterIndex, chapter) in chapters.withIndex()) {
|
for ((chapterIndex, chapter) in chapters.withIndex()) {
|
||||||
if (chaptersToSkip.remove(chapter.id)) {
|
if (chaptersToSkip.remove(chapter.id)) {
|
||||||
publishState(
|
publishState(currentState.copy(downloadedChapters = currentState.downloadedChapters + 1))
|
||||||
currentState.copy(
|
|
||||||
downloadedChapters = currentState.downloadedChapters + chapter.id,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val pages = runFailsafe(pausingHandle) {
|
val pages = runFailsafe(pausingHandle) {
|
||||||
@@ -222,11 +220,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
localStorageChanges.emit(LocalMangaInput.of(output.rootFile).getManga())
|
localStorageChanges.emit(LocalMangaInput.of(output.rootFile).getManga())
|
||||||
}.onFailure(Throwable::printStackTraceDebug)
|
}.onFailure(Throwable::printStackTraceDebug)
|
||||||
}
|
}
|
||||||
publishState(
|
publishState(currentState.copy(downloadedChapters = currentState.downloadedChapters + 1))
|
||||||
currentState.copy(
|
|
||||||
downloadedChapters = currentState.downloadedChapters + chapter.id,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
publishState(currentState.copy(isIndeterminate = true, eta = -1L))
|
publishState(currentState.copy(isIndeterminate = true, eta = -1L))
|
||||||
output.mergeWithExisting()
|
output.mergeWithExisting()
|
||||||
@@ -333,11 +327,9 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
setProgress(state.toWorkData())
|
setProgress(state.toWorkData())
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getDoneChapters(): LongArray {
|
private suspend fun getDoneChapters(manga: Manga) = runCatchingCancellable {
|
||||||
val work = WorkManager.getInstance(applicationContext).awaitWorkInfoById(id)
|
localMangaRepository.getDetails(manga).chapters?.ids()
|
||||||
?: return LongArray(0)
|
}.getOrNull().orEmpty()
|
||||||
return DownloadState.getDownloadedChapters(work.progress)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getChapters(
|
private fun getChapters(
|
||||||
manga: Manga,
|
manga: Manga,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
|||||||
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
||||||
import org.koitharu.kotatsu.parsers.model.ContentType
|
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.EnumSet
|
import java.util.EnumSet
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -30,7 +31,7 @@ class MangaSourcesRepository @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
private val dao: MangaSourcesDao
|
private val dao: MangaSourcesDao
|
||||||
get() = db.sourcesDao
|
get() = db.getSourcesDao()
|
||||||
|
|
||||||
private val remoteSources = EnumSet.allOf(MangaSource::class.java).apply {
|
private val remoteSources = EnumSet.allOf(MangaSource::class.java).apply {
|
||||||
remove(MangaSource.LOCAL)
|
remove(MangaSource.LOCAL)
|
||||||
@@ -43,15 +44,44 @@ class MangaSourcesRepository @Inject constructor(
|
|||||||
get() = Collections.unmodifiableSet(remoteSources)
|
get() = Collections.unmodifiableSet(remoteSources)
|
||||||
|
|
||||||
suspend fun getEnabledSources(): List<MangaSource> {
|
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 ->
|
suspend fun getDisabledSources(): List<MangaSource> {
|
||||||
dao.observeEnabled().map {
|
return dao.findAllDisabled().toSources(settings.isNsfwContentDisabled, null)
|
||||||
it.toSources(skipNsfw)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ->
|
fun observeAll(): Flow<List<Pair<MangaSource, Boolean>>> = dao.observeAll().map { entities ->
|
||||||
val result = ArrayList<Pair<MangaSource, Boolean>>(entities.size)
|
val result = ArrayList<Pair<MangaSource, Boolean>>(entities.size)
|
||||||
for (entity in entities) {
|
for (entity in entities) {
|
||||||
@@ -146,7 +176,10 @@ class MangaSourcesRepository @Inject constructor(
|
|||||||
return result
|
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)
|
val result = ArrayList<MangaSource>(size)
|
||||||
for (entity in this) {
|
for (entity in this) {
|
||||||
val source = MangaSource(entity.source)
|
val source = MangaSource(entity.source)
|
||||||
@@ -157,6 +190,9 @@ class MangaSourcesRepository @Inject constructor(
|
|||||||
result.add(source)
|
result.add(source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (sortOrder == SourcesSortOrder.ALPHABETIC) {
|
||||||
|
result.sortBy { it.title }
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,4 +203,8 @@ class MangaSourcesRepository @Inject constructor(
|
|||||||
private fun observeIsNewSourcesEnabled() = settings.observeAsFlow(AppSettings.KEY_SOURCES_NEW) {
|
private fun observeIsNewSourcesEnabled() = settings.observeAsFlow(AppSettings.KEY_SOURCES_NEW) {
|
||||||
isNewSourcesTipEnabled
|
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),
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.explore.ui
|
package org.koitharu.kotatsu.explore.ui
|
||||||
|
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MenuItem
|
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.search.ui.MangaListActivity
|
||||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||||
import org.koitharu.kotatsu.settings.newsources.NewSourcesDialogFragment
|
import org.koitharu.kotatsu.settings.newsources.NewSourcesDialogFragment
|
||||||
|
import org.koitharu.kotatsu.settings.sources.catalog.SourcesCatalogActivity
|
||||||
import org.koitharu.kotatsu.suggestions.ui.SuggestionsActivity
|
import org.koitharu.kotatsu.suggestions.ui.SuggestionsActivity
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -83,7 +85,7 @@ class ExploreFragment :
|
|||||||
SpanSizeResolver(this, resources.getDimensionPixelSize(R.dimen.explore_grid_width)).attach()
|
SpanSizeResolver(this, resources.getDimensionPixelSize(R.dimen.explore_grid_width)).attach()
|
||||||
addItemDecoration(TypedListSpacingDecoration(context, false))
|
addItemDecoration(TypedListSpacingDecoration(context, false))
|
||||||
}
|
}
|
||||||
addMenuProvider(ExploreMenuProvider(binding.root.context, viewModel))
|
addMenuProvider(ExploreMenuProvider(binding.root.context))
|
||||||
viewModel.content.observe(viewLifecycleOwner) {
|
viewModel.content.observe(viewLifecycleOwner) {
|
||||||
exploreAdapter?.items = it
|
exploreAdapter?.items = it
|
||||||
}
|
}
|
||||||
@@ -109,7 +111,7 @@ class ExploreFragment :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onListHeaderClick(item: ListHeader, view: View) {
|
override fun onListHeaderClick(item: ListHeader, view: View) {
|
||||||
startActivity(SettingsActivity.newManageSourcesIntent(view.context))
|
startActivity(Intent(view.context, SourcesCatalogActivity::class.java))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrimaryButtonClick(tipView: TipView) {
|
override fun onPrimaryButtonClick(tipView: TipView) {
|
||||||
@@ -174,7 +176,6 @@ class ExploreFragment :
|
|||||||
} else {
|
} else {
|
||||||
LinearLayoutManager(requireContext())
|
LinearLayoutManager(requireContext())
|
||||||
}
|
}
|
||||||
activity?.invalidateOptionsMenu()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSuggestionsTip() {
|
private fun showSuggestionsTip() {
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import android.view.MenuInflater
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.core.view.MenuProvider
|
import androidx.core.view.MenuProvider
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||||
|
|
||||||
class ExploreMenuProvider(
|
class ExploreMenuProvider(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val viewModel: ExploreViewModel,
|
|
||||||
) : MenuProvider {
|
) : MenuProvider {
|
||||||
|
|
||||||
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||||
@@ -18,17 +18,12 @@ class ExploreMenuProvider(
|
|||||||
|
|
||||||
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||||
return when (menuItem.itemId) {
|
return when (menuItem.itemId) {
|
||||||
R.id.action_grid -> {
|
R.id.action_manage -> {
|
||||||
viewModel.setGridMode(!menuItem.isChecked)
|
context.startActivity(SettingsActivity.newSourcesSettingsIntent(context))
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
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.MutableEventFlow
|
||||||
import org.koitharu.kotatsu.core.util.ext.call
|
import org.koitharu.kotatsu.core.util.ext.call
|
||||||
import org.koitharu.kotatsu.explore.data.MangaSourcesRepository
|
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.domain.ExploreRepository
|
||||||
import org.koitharu.kotatsu.explore.ui.model.ExploreButtons
|
import org.koitharu.kotatsu.explore.ui.model.ExploreButtons
|
||||||
import org.koitharu.kotatsu.explore.ui.model.MangaSourceItem
|
import org.koitharu.kotatsu.explore.ui.model.MangaSourceItem
|
||||||
@@ -50,11 +51,13 @@ class ExploreViewModel @Inject constructor(
|
|||||||
valueProducer = { isSourcesGridMode },
|
valueProducer = { isSourcesGridMode },
|
||||||
)
|
)
|
||||||
|
|
||||||
val isSuggestionsEnabled = settings.observeAsFlow(
|
private val isSuggestionsEnabled = settings.observeAsFlow(
|
||||||
key = AppSettings.KEY_SUGGESTIONS,
|
key = AppSettings.KEY_SUGGESTIONS,
|
||||||
valueProducer = { isSuggestionsEnabled },
|
valueProducer = { isSuggestionsEnabled },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val sortOrder = MutableStateFlow(SourcesSortOrder.MANUAL) // TODO
|
||||||
|
|
||||||
val onOpenManga = MutableEventFlow<Manga>()
|
val onOpenManga = MutableEventFlow<Manga>()
|
||||||
val onActionDone = MutableEventFlow<ReversibleAction>()
|
val onActionDone = MutableEventFlow<ReversibleAction>()
|
||||||
val onShowSuggestionsTip = MutableEventFlow<Unit>()
|
val onShowSuggestionsTip = MutableEventFlow<Unit>()
|
||||||
@@ -104,10 +107,6 @@ class ExploreViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setGridMode(value: Boolean) {
|
|
||||||
settings.isSourcesGridMode = value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun respondSuggestionTip(isAccepted: Boolean) {
|
fun respondSuggestionTip(isAccepted: Boolean) {
|
||||||
settings.isSuggestionsEnabled = isAccepted
|
settings.isSuggestionsEnabled = isAccepted
|
||||||
settings.closeTip(TIP_SUGGESTIONS)
|
settings.closeTip(TIP_SUGGESTIONS)
|
||||||
@@ -137,7 +136,7 @@ class ExploreViewModel @Inject constructor(
|
|||||||
result += RecommendationsItem(recommendation)
|
result += RecommendationsItem(recommendation)
|
||||||
}
|
}
|
||||||
if (sources.isNotEmpty()) {
|
if (sources.isNotEmpty()) {
|
||||||
result += ListHeader(R.string.remote_sources, R.string.manage)
|
result += ListHeader(R.string.remote_sources, R.string.catalog)
|
||||||
if (newSources.isNotEmpty()) {
|
if (newSources.isNotEmpty()) {
|
||||||
result += TipModel(
|
result += TipModel(
|
||||||
key = TIP_NEW_SOURCES,
|
key = TIP_NEW_SOURCES,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.swiperefreshlayout.widget.CircularProgressDrawable
|
|||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
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.parser.favicon.faviconUri
|
||||||
import org.koitharu.kotatsu.core.ui.image.FaviconDrawable
|
import org.koitharu.kotatsu.core.ui.image.FaviconDrawable
|
||||||
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
||||||
@@ -48,8 +49,8 @@ fun exploreButtonsAD(
|
|||||||
icon.setColorSchemeColors(
|
icon.setColorSchemeColors(
|
||||||
context.getThemeColor(
|
context.getThemeColor(
|
||||||
materialR.attr.colorPrimary,
|
materialR.attr.colorPrimary,
|
||||||
Color.DKGRAY
|
Color.DKGRAY,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
binding.buttonRandom.icon = icon
|
binding.buttonRandom.icon = icon
|
||||||
icon.start()
|
icon.start()
|
||||||
@@ -98,7 +99,7 @@ fun exploreSourceListItemAD(
|
|||||||
ItemExploreSourceListBinding.inflate(
|
ItemExploreSourceListBinding.inflate(
|
||||||
layoutInflater,
|
layoutInflater,
|
||||||
parent,
|
parent,
|
||||||
false
|
false,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
on = { item, _, _ -> item is MangaSourceItem && !item.isGrid },
|
on = { item, _, _ -> item is MangaSourceItem && !item.isGrid },
|
||||||
@@ -112,6 +113,7 @@ fun exploreSourceListItemAD(
|
|||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.textViewTitle.text = item.source.title
|
binding.textViewTitle.text = item.source.title
|
||||||
|
binding.textViewSubtitle.text = item.source.getSummary(context)
|
||||||
val fallbackIcon = FaviconDrawable(context, R.style.FaviconDrawable_Small, item.source.name)
|
val fallbackIcon = FaviconDrawable(context, R.style.FaviconDrawable_Small, item.source.name)
|
||||||
binding.imageViewIcon.newImageRequest(lifecycleOwner, item.source.faviconUri())?.run {
|
binding.imageViewIcon.newImageRequest(lifecycleOwner, item.source.faviconUri())?.run {
|
||||||
fallback(fallbackIcon)
|
fallback(fallbackIcon)
|
||||||
@@ -132,7 +134,7 @@ fun exploreSourceGridItemAD(
|
|||||||
ItemExploreSourceGridBinding.inflate(
|
ItemExploreSourceGridBinding.inflate(
|
||||||
layoutInflater,
|
layoutInflater,
|
||||||
parent,
|
parent,
|
||||||
false
|
false,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
on = { item, _, _ -> item is MangaSourceItem && item.isGrid },
|
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")
|
@Query("SELECT DISTINCT category_id FROM favourites WHERE manga_id = :id AND deleted_at = 0")
|
||||||
abstract fun observeIds(id: Long): Flow<List<Long>>
|
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 **/
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
@@ -169,7 +172,9 @@ abstract class FavouritesDao {
|
|||||||
ListSortOrder.NEWEST -> "favourites.created_at DESC"
|
ListSortOrder.NEWEST -> "favourites.created_at DESC"
|
||||||
ListSortOrder.ALPHABETIC -> "manga.title ASC"
|
ListSortOrder.ALPHABETIC -> "manga.title ASC"
|
||||||
ListSortOrder.NEW_CHAPTERS -> "(SELECT chapters_new FROM tracks WHERE tracks.manga_id = manga.manga_id) DESC"
|
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"
|
ListSortOrder.PROGRESS -> "(SELECT percent FROM history WHERE history.manga_id = manga.manga_id) DESC"
|
||||||
|
|
||||||
else -> throw IllegalArgumentException("Sort order $sortOrder is not supported")
|
else -> throw IllegalArgumentException("Sort order $sortOrder is not supported")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,27 +31,27 @@ class FavouritesRepository @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun getAllManga(): List<Manga> {
|
suspend fun getAllManga(): List<Manga> {
|
||||||
val entities = db.favouritesDao.findAll()
|
val entities = db.getFavouritesDao().findAll()
|
||||||
return entities.toMangaList()
|
return entities.toMangaList()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getLastManga(limit: Int): List<Manga> {
|
suspend fun getLastManga(limit: Int): List<Manga> {
|
||||||
val entities = db.favouritesDao.findLast(limit)
|
val entities = db.getFavouritesDao().findLast(limit)
|
||||||
return entities.toMangaList()
|
return entities.toMangaList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeAll(order: ListSortOrder): Flow<List<Manga>> {
|
fun observeAll(order: ListSortOrder): Flow<List<Manga>> {
|
||||||
return db.favouritesDao.observeAll(order)
|
return db.getFavouritesDao().observeAll(order)
|
||||||
.mapItems { it.toManga() }
|
.mapItems { it.toManga() }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getManga(categoryId: Long): List<Manga> {
|
suspend fun getManga(categoryId: Long): List<Manga> {
|
||||||
val entities = db.favouritesDao.findAll(categoryId)
|
val entities = db.getFavouritesDao().findAll(categoryId)
|
||||||
return entities.toMangaList()
|
return entities.toMangaList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeAll(categoryId: Long, order: ListSortOrder): Flow<List<Manga>> {
|
fun observeAll(categoryId: Long, order: ListSortOrder): Flow<List<Manga>> {
|
||||||
return db.favouritesDao.observeAll(categoryId, order)
|
return db.getFavouritesDao().observeAll(categoryId, order)
|
||||||
.mapItems { it.toManga() }
|
.mapItems { it.toManga() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,25 +61,25 @@ class FavouritesRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun observeCategories(): Flow<List<FavouriteCategory>> {
|
fun observeCategories(): Flow<List<FavouriteCategory>> {
|
||||||
return db.favouriteCategoriesDao.observeAll().mapItems {
|
return db.getFavouriteCategoriesDao().observeAll().mapItems {
|
||||||
it.toFavouriteCategory()
|
it.toFavouriteCategory()
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeCategoriesForLibrary(): Flow<List<FavouriteCategory>> {
|
fun observeCategoriesForLibrary(): Flow<List<FavouriteCategory>> {
|
||||||
return db.favouriteCategoriesDao.observeAllForLibrary().mapItems {
|
return db.getFavouriteCategoriesDao().observeAllForLibrary().mapItems {
|
||||||
it.toFavouriteCategory()
|
it.toFavouriteCategory()
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeCategoriesWithCovers(): Flow<Map<FavouriteCategory, List<Cover>>> {
|
fun observeCategoriesWithCovers(): Flow<Map<FavouriteCategory, List<Cover>>> {
|
||||||
return db.favouriteCategoriesDao.observeAll()
|
return db.getFavouriteCategoriesDao().observeAll()
|
||||||
.map {
|
.map {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
val res = LinkedHashMap<FavouriteCategory, List<Cover>>()
|
val res = LinkedHashMap<FavouriteCategory, List<Cover>>()
|
||||||
for (entity in it) {
|
for (entity in it) {
|
||||||
val cat = entity.toFavouriteCategory()
|
val cat = entity.toFavouriteCategory()
|
||||||
res[cat] = db.favouritesDao.findCovers(
|
res[cat] = db.getFavouritesDao().findCovers(
|
||||||
categoryId = cat.id,
|
categoryId = cat.id,
|
||||||
order = cat.order,
|
order = cat.order,
|
||||||
)
|
)
|
||||||
@@ -90,16 +90,20 @@ class FavouritesRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun observeCategory(id: Long): Flow<FavouriteCategory?> {
|
fun observeCategory(id: Long): Flow<FavouriteCategory?> {
|
||||||
return db.favouriteCategoriesDao.observe(id)
|
return db.getFavouriteCategoriesDao().observe(id)
|
||||||
.map { it?.toFavouriteCategory() }
|
.map { it?.toFavouriteCategory() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeCategoriesIds(mangaId: Long): Flow<Set<Long>> {
|
fun observeCategoriesIds(mangaId: Long): Flow<Set<Long>> {
|
||||||
return db.favouritesDao.observeIds(mangaId).map { it.toSet() }
|
return db.getFavouritesDao().observeIds(mangaId).map { it.toSet() }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getCategory(id: Long): FavouriteCategory {
|
suspend fun getCategory(id: Long): FavouriteCategory {
|
||||||
return db.favouriteCategoriesDao.find(id.toInt()).toFavouriteCategory()
|
return db.getFavouriteCategoriesDao().find(id.toInt()).toFavouriteCategory()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getCategoriesIds(mangaIds: Collection<Long>): Set<Long> {
|
||||||
|
return db.getFavouritesDao().findCategoriesIds(mangaIds).toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun createCategory(
|
suspend fun createCategory(
|
||||||
@@ -111,14 +115,14 @@ class FavouritesRepository @Inject constructor(
|
|||||||
val entity = FavouriteCategoryEntity(
|
val entity = FavouriteCategoryEntity(
|
||||||
title = title,
|
title = title,
|
||||||
createdAt = System.currentTimeMillis(),
|
createdAt = System.currentTimeMillis(),
|
||||||
sortKey = db.favouriteCategoriesDao.getNextSortKey(),
|
sortKey = db.getFavouriteCategoriesDao().getNextSortKey(),
|
||||||
categoryId = 0,
|
categoryId = 0,
|
||||||
order = sortOrder.name,
|
order = sortOrder.name,
|
||||||
track = isTrackerEnabled,
|
track = isTrackerEnabled,
|
||||||
deletedAt = 0L,
|
deletedAt = 0L,
|
||||||
isVisibleInLibrary = isVisibleOnShelf,
|
isVisibleInLibrary = isVisibleOnShelf,
|
||||||
)
|
)
|
||||||
val id = db.favouriteCategoriesDao.insert(entity)
|
val id = db.getFavouriteCategoriesDao().insert(entity)
|
||||||
val category = entity.toFavouriteCategory(id)
|
val category = entity.toFavouriteCategory(id)
|
||||||
channels.createChannel(category)
|
channels.createChannel(category)
|
||||||
return category
|
return category
|
||||||
@@ -131,22 +135,22 @@ class FavouritesRepository @Inject constructor(
|
|||||||
isTrackerEnabled: Boolean,
|
isTrackerEnabled: Boolean,
|
||||||
isVisibleOnShelf: Boolean,
|
isVisibleOnShelf: Boolean,
|
||||||
) {
|
) {
|
||||||
db.favouriteCategoriesDao.update(id, title, sortOrder.name, isTrackerEnabled, isVisibleOnShelf)
|
db.getFavouriteCategoriesDao().update(id, title, sortOrder.name, isTrackerEnabled, isVisibleOnShelf)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun updateCategory(id: Long, isVisibleInLibrary: Boolean) {
|
suspend fun updateCategory(id: Long, isVisibleInLibrary: Boolean) {
|
||||||
db.favouriteCategoriesDao.updateLibVisibility(id, isVisibleInLibrary)
|
db.getFavouriteCategoriesDao().updateLibVisibility(id, isVisibleInLibrary)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun updateCategoryTracking(id: Long, isTrackingEnabled: Boolean) {
|
suspend fun updateCategoryTracking(id: Long, isTrackingEnabled: Boolean) {
|
||||||
db.favouriteCategoriesDao.updateTracking(id, isTrackingEnabled)
|
db.getFavouriteCategoriesDao().updateTracking(id, isTrackingEnabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun removeCategories(ids: Collection<Long>) {
|
suspend fun removeCategories(ids: Collection<Long>) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for (id in ids) {
|
for (id in ids) {
|
||||||
db.favouritesDao.deleteAll(id)
|
db.getFavouritesDao().deleteAll(id)
|
||||||
db.favouriteCategoriesDao.delete(id)
|
db.getFavouriteCategoriesDao().delete(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// run after transaction success
|
// run after transaction success
|
||||||
@@ -156,11 +160,11 @@ class FavouritesRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun setCategoryOrder(id: Long, order: ListSortOrder) {
|
suspend fun setCategoryOrder(id: Long, order: ListSortOrder) {
|
||||||
db.favouriteCategoriesDao.updateOrder(id, order.name)
|
db.getFavouriteCategoriesDao().updateOrder(id, order.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun reorderCategories(orderedIds: List<Long>) {
|
suspend fun reorderCategories(orderedIds: List<Long>) {
|
||||||
val dao = db.favouriteCategoriesDao
|
val dao = db.getFavouriteCategoriesDao()
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for ((i, id) in orderedIds.withIndex()) {
|
for ((i, id) in orderedIds.withIndex()) {
|
||||||
dao.updateSortKey(id, i)
|
dao.updateSortKey(id, i)
|
||||||
@@ -172,8 +176,8 @@ class FavouritesRepository @Inject constructor(
|
|||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for (manga in mangas) {
|
for (manga in mangas) {
|
||||||
val tags = manga.tags.toEntities()
|
val tags = manga.tags.toEntities()
|
||||||
db.tagsDao.upsert(tags)
|
db.getTagsDao().upsert(tags)
|
||||||
db.mangaDao.upsert(manga.toEntity(), tags)
|
db.getMangaDao().upsert(manga.toEntity(), tags)
|
||||||
val entity = FavouriteEntity(
|
val entity = FavouriteEntity(
|
||||||
mangaId = manga.id,
|
mangaId = manga.id,
|
||||||
categoryId = categoryId,
|
categoryId = categoryId,
|
||||||
@@ -181,7 +185,7 @@ class FavouritesRepository @Inject constructor(
|
|||||||
sortKey = 0,
|
sortKey = 0,
|
||||||
deletedAt = 0L,
|
deletedAt = 0L,
|
||||||
)
|
)
|
||||||
db.favouritesDao.insert(entity)
|
db.getFavouritesDao().insert(entity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,7 +193,7 @@ class FavouritesRepository @Inject constructor(
|
|||||||
suspend fun removeFromFavourites(ids: Collection<Long>): ReversibleHandle {
|
suspend fun removeFromFavourites(ids: Collection<Long>): ReversibleHandle {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for (id in ids) {
|
for (id in ids) {
|
||||||
db.favouritesDao.delete(mangaId = id)
|
db.getFavouritesDao().delete(mangaId = id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ReversibleHandle { recoverToFavourites(ids) }
|
return ReversibleHandle { recoverToFavourites(ids) }
|
||||||
@@ -198,14 +202,14 @@ class FavouritesRepository @Inject constructor(
|
|||||||
suspend fun removeFromCategory(categoryId: Long, ids: Collection<Long>): ReversibleHandle {
|
suspend fun removeFromCategory(categoryId: Long, ids: Collection<Long>): ReversibleHandle {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for (id in ids) {
|
for (id in ids) {
|
||||||
db.favouritesDao.delete(categoryId = categoryId, mangaId = id)
|
db.getFavouritesDao().delete(categoryId = categoryId, mangaId = id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ReversibleHandle { recoverToCategory(categoryId, ids) }
|
return ReversibleHandle { recoverToCategory(categoryId, ids) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeOrder(categoryId: Long): Flow<ListSortOrder> {
|
private fun observeOrder(categoryId: Long): Flow<ListSortOrder> {
|
||||||
return db.favouriteCategoriesDao.observe(categoryId)
|
return db.getFavouriteCategoriesDao().observe(categoryId)
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.map { x -> ListSortOrder(x.order, ListSortOrder.NEWEST) }
|
.map { x -> ListSortOrder(x.order, ListSortOrder.NEWEST) }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
@@ -214,7 +218,7 @@ class FavouritesRepository @Inject constructor(
|
|||||||
private suspend fun recoverToFavourites(ids: Collection<Long>) {
|
private suspend fun recoverToFavourites(ids: Collection<Long>) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for (id in ids) {
|
for (id in ids) {
|
||||||
db.favouritesDao.recover(mangaId = id)
|
db.getFavouritesDao().recover(mangaId = id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,7 +226,7 @@ class FavouritesRepository @Inject constructor(
|
|||||||
private suspend fun recoverToCategory(categoryId: Long, ids: Collection<Long>) {
|
private suspend fun recoverToCategory(categoryId: Long, ids: Collection<Long>) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for (id in ids) {
|
for (id in ids) {
|
||||||
db.favouritesDao.recover(mangaId = id, categoryId = categoryId)
|
db.getFavouritesDao().recover(mangaId = id, categoryId = categoryId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,17 +19,12 @@ import org.koitharu.kotatsu.core.util.ext.withArgs
|
|||||||
import org.koitharu.kotatsu.databinding.SheetFavoriteCategoriesBinding
|
import org.koitharu.kotatsu.databinding.SheetFavoriteCategoriesBinding
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.select.adapter.MangaCategoriesAdapter
|
import org.koitharu.kotatsu.favourites.ui.categories.select.adapter.MangaCategoriesAdapter
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.select.model.MangaCategoryItem
|
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
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class FavouriteSheet :
|
class FavoriteSheet : BaseAdaptiveSheet<SheetFavoriteCategoriesBinding>(), OnListItemClickListener<MangaCategoryItem> {
|
||||||
BaseAdaptiveSheet<SheetFavoriteCategoriesBinding>(),
|
|
||||||
OnListItemClickListener<MangaCategoryItem> {
|
|
||||||
|
|
||||||
private val viewModel: MangaCategoriesViewModel by viewModels()
|
private val viewModel by viewModels<FavoriteSheetViewModel>()
|
||||||
|
|
||||||
private var adapter: MangaCategoriesAdapter? = null
|
|
||||||
|
|
||||||
override fun onCreateViewBinding(
|
override fun onCreateViewBinding(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
@@ -41,44 +36,32 @@ class FavouriteSheet :
|
|||||||
savedInstanceState: Bundle?,
|
savedInstanceState: Bundle?,
|
||||||
) {
|
) {
|
||||||
super.onViewBindingCreated(binding, savedInstanceState)
|
super.onViewBindingCreated(binding, savedInstanceState)
|
||||||
adapter = MangaCategoriesAdapter(this)
|
val adapter = MangaCategoriesAdapter(this)
|
||||||
binding.recyclerViewCategories.adapter = adapter
|
binding.recyclerViewCategories.adapter = adapter
|
||||||
viewModel.content.observe(viewLifecycleOwner, this::onContentChanged)
|
viewModel.content.observe(viewLifecycleOwner, adapter)
|
||||||
viewModel.onError.observeEvent(viewLifecycleOwner, ::onError)
|
viewModel.onError.observeEvent(viewLifecycleOwner, ::onError)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
|
||||||
adapter = null
|
|
||||||
super.onDestroyView()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemClick(item: MangaCategoryItem, view: View) {
|
override fun onItemClick(item: MangaCategoryItem, view: View) {
|
||||||
viewModel.setChecked(item.category.id, !item.isChecked)
|
viewModel.setChecked(item.category.id, !item.isChecked)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onContentChanged(categories: List<ListModel>) {
|
|
||||||
adapter?.items = categories
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onError(e: Throwable) {
|
private fun onError(e: Throwable) {
|
||||||
Toast.makeText(context ?: return, e.getDisplayMessage(resources), Toast.LENGTH_SHORT).show()
|
Toast.makeText(context ?: return, e.getDisplayMessage(resources), Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val TAG = "FavouriteCategoriesDialog"
|
private const val TAG = "FavoriteSheet"
|
||||||
const val KEY_MANGA_LIST = "manga_list"
|
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>) =
|
fun show(fm: FragmentManager, manga: Collection<Manga>) = FavoriteSheet().withArgs(1) {
|
||||||
FavouriteSheet().withArgs(1) {
|
putParcelableArrayList(
|
||||||
putParcelableArrayList(
|
KEY_MANGA_LIST,
|
||||||
KEY_MANGA_LIST,
|
manga.mapTo(ArrayList(manga.size), ::ParcelableManga),
|
||||||
manga.mapTo(ArrayList(manga.size)) {
|
)
|
||||||
ParcelableManga(it)
|
}.showDistinct(fm, TAG)
|
||||||
},
|
|
||||||
)
|
|
||||||
}.showDistinct(fm, TAG)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,77 +4,70 @@ import androidx.lifecycle.SavedStateHandle
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.plus
|
import kotlinx.coroutines.plus
|
||||||
import org.koitharu.kotatsu.core.model.ids
|
import org.koitharu.kotatsu.core.model.ids
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
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.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.firstNotNull
|
||||||
import org.koitharu.kotatsu.core.util.ext.require
|
import org.koitharu.kotatsu.core.util.ext.require
|
||||||
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
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.CategoriesHeaderItem
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.select.model.MangaCategoryItem
|
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
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class MangaCategoriesViewModel @Inject constructor(
|
class FavoriteSheetViewModel @Inject constructor(
|
||||||
savedStateHandle: SavedStateHandle,
|
savedStateHandle: SavedStateHandle,
|
||||||
private val favouritesRepository: FavouritesRepository,
|
private val favouritesRepository: FavouritesRepository,
|
||||||
settings: AppSettings,
|
settings: AppSettings,
|
||||||
) : BaseViewModel() {
|
) : 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()
|
private val header = CategoriesHeaderItem()
|
||||||
|
private val checkedCategories = MutableStateFlow<Set<Long>?>(null)
|
||||||
val content: StateFlow<List<ListModel>> = combine(
|
val content = combine(
|
||||||
favouritesRepository.observeCategories(),
|
favouritesRepository.observeCategories(),
|
||||||
observeCategoriesIds(),
|
checkedCategories.filterNotNull(),
|
||||||
) { all, checked ->
|
settings.observeAsFlow(AppSettings.KEY_TRACKER_ENABLED) { isTrackerEnabled },
|
||||||
buildList(all.size + 1) {
|
) { categories, checked, tracker ->
|
||||||
|
buildList(categories.size + 1) {
|
||||||
add(header)
|
add(header)
|
||||||
all.mapTo(this) {
|
categories.mapTo(this) { cat ->
|
||||||
MangaCategoryItem(
|
MangaCategoryItem(
|
||||||
category = it,
|
category = cat,
|
||||||
isChecked = it.id in checked,
|
isChecked = cat.id in checked,
|
||||||
isTrackerEnabled = settings.isTrackerEnabled && AppSettings.TRACK_FAVOURITES in settings.trackSources,
|
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) {
|
fun setChecked(categoryId: Long, isChecked: Boolean) {
|
||||||
launchJob(Dispatchers.Default) {
|
launchJob(Dispatchers.Default) {
|
||||||
|
val checkedIds = checkedCategories.firstNotNull()
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
|
checkedCategories.value = checkedIds + categoryId
|
||||||
favouritesRepository.addToCategory(categoryId, manga)
|
favouritesRepository.addToCategory(categoryId, manga)
|
||||||
} else {
|
} else {
|
||||||
|
checkedCategories.value = checkedIds - categoryId
|
||||||
favouritesRepository.removeFromCategory(categoryId, manga.ids())
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ abstract class HistoryDao {
|
|||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM history WHERE deleted_at = 0 AND manga_id IN (:ids)")
|
@Query("SELECT * FROM history WHERE deleted_at = 0 AND manga_id IN (:ids)")
|
||||||
abstract suspend fun findAll(ids: Collection<Long>): List<HistoryEntity?>
|
abstract suspend fun findAll(ids: Collection<Long>): List<HistoryEntity>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM history WHERE deleted_at = 0 ORDER BY updated_at DESC")
|
@Query("SELECT * FROM history WHERE deleted_at = 0 ORDER BY updated_at DESC")
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import org.koitharu.kotatsu.core.db.entity.toMangaTag
|
|||||||
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||||
import org.koitharu.kotatsu.core.model.findById
|
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.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
||||||
import org.koitharu.kotatsu.core.util.ext.mapItems
|
import org.koitharu.kotatsu.core.util.ext.mapItems
|
||||||
@@ -35,39 +37,40 @@ class HistoryRepository @Inject constructor(
|
|||||||
private val trackingRepository: TrackingRepository,
|
private val trackingRepository: TrackingRepository,
|
||||||
private val settings: AppSettings,
|
private val settings: AppSettings,
|
||||||
private val scrobblers: Set<@JvmSuppressWildcards Scrobbler>,
|
private val scrobblers: Set<@JvmSuppressWildcards Scrobbler>,
|
||||||
|
private val mangaRepository: MangaDataRepository,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun getList(offset: Int, limit: Int): List<Manga> {
|
suspend fun getList(offset: Int, limit: Int): List<Manga> {
|
||||||
val entities = db.historyDao.findAll(offset, limit)
|
val entities = db.getHistoryDao().findAll(offset, limit)
|
||||||
return entities.map { it.manga.toManga(it.tags.toMangaTags()) }
|
return entities.map { it.manga.toManga(it.tags.toMangaTags()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getLastOrNull(): Manga? {
|
suspend fun getLastOrNull(): Manga? {
|
||||||
val entity = db.historyDao.findAll(0, 1).firstOrNull() ?: return null
|
val entity = db.getHistoryDao().findAll(0, 1).firstOrNull() ?: return null
|
||||||
return entity.manga.toManga(entity.tags.toMangaTags())
|
return entity.manga.toManga(entity.tags.toMangaTags())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeLast(): Flow<Manga?> {
|
fun observeLast(): Flow<Manga?> {
|
||||||
return db.historyDao.observeAll(1).map {
|
return db.getHistoryDao().observeAll(1).map {
|
||||||
val first = it.firstOrNull()
|
val first = it.firstOrNull()
|
||||||
first?.manga?.toManga(first.tags.toMangaTags())
|
first?.manga?.toManga(first.tags.toMangaTags())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeAll(): Flow<List<Manga>> {
|
fun observeAll(): Flow<List<Manga>> {
|
||||||
return db.historyDao.observeAll().mapItems {
|
return db.getHistoryDao().observeAll().mapItems {
|
||||||
it.manga.toManga(it.tags.toMangaTags())
|
it.manga.toManga(it.tags.toMangaTags())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeAll(limit: Int): Flow<List<Manga>> {
|
fun observeAll(limit: Int): Flow<List<Manga>> {
|
||||||
return db.historyDao.observeAll(limit).mapItems {
|
return db.getHistoryDao().observeAll(limit).mapItems {
|
||||||
it.manga.toManga(it.tags.toMangaTags())
|
it.manga.toManga(it.tags.toMangaTags())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeAllWithHistory(order: ListSortOrder): Flow<List<MangaWithHistory>> {
|
fun observeAllWithHistory(order: ListSortOrder): Flow<List<MangaWithHistory>> {
|
||||||
return db.historyDao.observeAll(order).mapItems {
|
return db.getHistoryDao().observeAll(order).mapItems {
|
||||||
MangaWithHistory(
|
MangaWithHistory(
|
||||||
it.manga.toManga(it.tags.toMangaTags()),
|
it.manga.toManga(it.tags.toMangaTags()),
|
||||||
it.history.toMangaHistory(),
|
it.history.toMangaHistory(),
|
||||||
@@ -76,13 +79,13 @@ class HistoryRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun observeOne(id: Long): Flow<MangaHistory?> {
|
fun observeOne(id: Long): Flow<MangaHistory?> {
|
||||||
return db.historyDao.observe(id).map {
|
return db.getHistoryDao().observe(id).map {
|
||||||
it?.toMangaHistory()
|
it?.toMangaHistory()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeHasItems(): Flow<Boolean> {
|
fun observeHasItems(): Flow<Boolean> {
|
||||||
return db.historyDao.observeCount()
|
return db.getHistoryDao().observeCount()
|
||||||
.map { it > 0 }
|
.map { it > 0 }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
@@ -91,14 +94,9 @@ class HistoryRepository @Inject constructor(
|
|||||||
if (shouldSkip(manga)) {
|
if (shouldSkip(manga)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val tags = manga.tags.toEntities()
|
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
val existing = db.mangaDao.find(manga.id)?.manga
|
mangaRepository.storeManga(manga)
|
||||||
if (existing == null || existing.source == manga.source.name) {
|
db.getHistoryDao().upsert(
|
||||||
db.tagsDao.upsert(tags)
|
|
||||||
db.mangaDao.upsert(manga.toEntity(), tags)
|
|
||||||
}
|
|
||||||
db.historyDao.upsert(
|
|
||||||
HistoryEntity(
|
HistoryEntity(
|
||||||
mangaId = manga.id,
|
mangaId = manga.id,
|
||||||
createdAt = System.currentTimeMillis(),
|
createdAt = System.currentTimeMillis(),
|
||||||
@@ -119,29 +117,29 @@ class HistoryRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getOne(manga: Manga): MangaHistory? {
|
suspend fun getOne(manga: Manga): MangaHistory? {
|
||||||
return db.historyDao.find(manga.id)?.recoverIfNeeded(manga)?.toMangaHistory()
|
return db.getHistoryDao().find(manga.id)?.recoverIfNeeded(manga)?.toMangaHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getProgress(mangaId: Long): Float {
|
suspend fun getProgress(mangaId: Long): Float {
|
||||||
return db.historyDao.findProgress(mangaId) ?: PROGRESS_NONE
|
return db.getHistoryDao().findProgress(mangaId) ?: PROGRESS_NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun clear() {
|
suspend fun clear() {
|
||||||
db.historyDao.clear()
|
db.getHistoryDao().clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun delete(manga: Manga) {
|
suspend fun delete(manga: Manga) {
|
||||||
db.historyDao.delete(manga.id)
|
db.getHistoryDao().delete(manga.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun deleteAfter(minDate: Long) {
|
suspend fun deleteAfter(minDate: Long) {
|
||||||
db.historyDao.deleteAfter(minDate)
|
db.getHistoryDao().deleteAfter(minDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun delete(ids: Collection<Long>): ReversibleHandle {
|
suspend fun delete(ids: Collection<Long>): ReversibleHandle {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for (id in ids) {
|
for (id in ids) {
|
||||||
db.historyDao.delete(id)
|
db.getHistoryDao().delete(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ReversibleHandle {
|
return ReversibleHandle {
|
||||||
@@ -154,13 +152,13 @@ class HistoryRepository @Inject constructor(
|
|||||||
* Useful for replacing saved manga on deleting it with remote source
|
* Useful for replacing saved manga on deleting it with remote source
|
||||||
*/
|
*/
|
||||||
suspend fun deleteOrSwap(manga: Manga, alternative: Manga?) {
|
suspend fun deleteOrSwap(manga: Manga, alternative: Manga?) {
|
||||||
if (alternative == null || db.mangaDao.update(alternative.toEntity()) <= 0) {
|
if (alternative == null || db.getMangaDao().update(alternative.toEntity()) <= 0) {
|
||||||
db.historyDao.delete(manga.id)
|
db.getHistoryDao().delete(manga.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getPopularTags(limit: Int): List<MangaTag> {
|
suspend fun getPopularTags(limit: Int): List<MangaTag> {
|
||||||
return db.historyDao.findPopularTags(limit).map { x -> x.toMangaTag() }
|
return db.getHistoryDao().findPopularTags(limit).map { x -> x.toMangaTag() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shouldSkip(manga: Manga): Boolean {
|
fun shouldSkip(manga: Manga): Boolean {
|
||||||
@@ -178,21 +176,21 @@ class HistoryRepository @Inject constructor(
|
|||||||
private suspend fun recover(ids: Collection<Long>) {
|
private suspend fun recover(ids: Collection<Long>) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for (id in ids) {
|
for (id in ids) {
|
||||||
db.historyDao.recover(id)
|
db.getHistoryDao().recover(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun HistoryEntity.recoverIfNeeded(manga: Manga): HistoryEntity {
|
private suspend fun HistoryEntity.recoverIfNeeded(manga: Manga): HistoryEntity {
|
||||||
val chapters = manga.chapters
|
val chapters = manga.chapters
|
||||||
if (chapters.isNullOrEmpty() || chapters.findById(chapterId) != null) {
|
if (manga.isLocal || chapters.isNullOrEmpty() || chapters.findById(chapterId) != null) {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
val newChapterId = chapters.getOrNull(
|
val newChapterId = chapters.getOrNull(
|
||||||
(chapters.size * percent).toInt(),
|
(chapters.size * percent).toInt(),
|
||||||
)?.id ?: return this
|
)?.id ?: return this
|
||||||
val newEntity = copy(chapterId = newChapterId)
|
val newEntity = copy(chapterId = newChapterId)
|
||||||
db.historyDao.update(newEntity)
|
db.getHistoryDao().update(newEntity)
|
||||||
return newEntity
|
return newEntity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.os.NetworkManageIntent
|
import org.koitharu.kotatsu.core.os.NetworkManageIntent
|
||||||
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
||||||
|
import org.koitharu.kotatsu.core.ui.list.RecyclerScrollKeeper
|
||||||
import org.koitharu.kotatsu.core.util.ext.addMenuProvider
|
import org.koitharu.kotatsu.core.util.ext.addMenuProvider
|
||||||
import org.koitharu.kotatsu.databinding.FragmentListBinding
|
import org.koitharu.kotatsu.databinding.FragmentListBinding
|
||||||
import org.koitharu.kotatsu.list.ui.MangaListFragment
|
import org.koitharu.kotatsu.list.ui.MangaListFragment
|
||||||
@@ -23,6 +24,7 @@ class HistoryListFragment : MangaListFragment() {
|
|||||||
|
|
||||||
override fun onViewBindingCreated(binding: FragmentListBinding, savedInstanceState: Bundle?) {
|
override fun onViewBindingCreated(binding: FragmentListBinding, savedInstanceState: Bundle?) {
|
||||||
super.onViewBindingCreated(binding, savedInstanceState)
|
super.onViewBindingCreated(binding, savedInstanceState)
|
||||||
|
RecyclerScrollKeeper(binding.recyclerView).attach()
|
||||||
addMenuProvider(HistoryListMenuProvider(binding.root.context, viewModel))
|
addMenuProvider(HistoryListMenuProvider(binding.root.context, viewModel))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import org.koitharu.kotatsu.core.util.ext.viewLifecycleScope
|
|||||||
import org.koitharu.kotatsu.databinding.FragmentListBinding
|
import org.koitharu.kotatsu.databinding.FragmentListBinding
|
||||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
import org.koitharu.kotatsu.download.ui.worker.DownloadStartedObserver
|
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.ListItemType
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.MangaListAdapter
|
import org.koitharu.kotatsu.list.ui.adapter.MangaListAdapter
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.MangaListListener
|
import org.koitharu.kotatsu.list.ui.adapter.MangaListListener
|
||||||
@@ -284,7 +284,7 @@ abstract class MangaListFragment :
|
|||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_favourite -> {
|
R.id.action_favourite -> {
|
||||||
FavouriteSheet.show(childFragmentManager, selectedItems)
|
FavoriteSheet.show(childFragmentManager, selectedItems)
|
||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,5 @@ enum class ListItemType {
|
|||||||
CATEGORY_LARGE,
|
CATEGORY_LARGE,
|
||||||
MANGA_SCROBBLING,
|
MANGA_SCROBBLING,
|
||||||
NAV_ITEM,
|
NAV_ITEM,
|
||||||
|
CHAPTER,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class TypedListSpacingDecoration(
|
|||||||
ListItemType.MANGA_NESTED_GROUP,
|
ListItemType.MANGA_NESTED_GROUP,
|
||||||
ListItemType.CATEGORY_LARGE,
|
ListItemType.CATEGORY_LARGE,
|
||||||
ListItemType.NAV_ITEM,
|
ListItemType.NAV_ITEM,
|
||||||
|
ListItemType.CHAPTER,
|
||||||
null,
|
null,
|
||||||
-> outRect.set(0)
|
-> outRect.set(0)
|
||||||
|
|
||||||
@@ -77,6 +78,6 @@ class TypedListSpacingDecoration(
|
|||||||
private fun Rect.set(spacing: Int) = set(spacing, spacing, spacing, spacing)
|
private fun Rect.set(spacing: Int) = set(spacing, spacing, spacing, spacing)
|
||||||
|
|
||||||
private fun ListItemType?.isEdgeToEdge() = this == ListItemType.MANGA_NESTED_GROUP
|
private fun ListItemType?.isEdgeToEdge() = this == ListItemType.MANGA_NESTED_GROUP
|
||||||
|| this == ListItemType.FILTER_SORT
|
|| this == ListItemType.FILTER_SORT
|
||||||
|| this == ListItemType.FILTER_TAG
|
|| this == ListItemType.FILTER_TAG
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.preview
|
package org.koitharu.kotatsu.list.ui.preview
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.method.LinkMovementMethod
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
|
import androidx.core.text.method.LinkMovementMethodCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
@@ -52,7 +52,7 @@ class PreviewFragment : BaseFragment<FragmentPreviewBinding>(), View.OnClickList
|
|||||||
super.onViewBindingCreated(binding, savedInstanceState)
|
super.onViewBindingCreated(binding, savedInstanceState)
|
||||||
binding.buttonClose.isVisible = activity is MangaListActivity
|
binding.buttonClose.isVisible = activity is MangaListActivity
|
||||||
binding.buttonClose.setOnClickListener(this)
|
binding.buttonClose.setOnClickListener(this)
|
||||||
binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance()
|
binding.textViewDescription.movementMethod = LinkMovementMethodCompat.getInstance()
|
||||||
binding.chipsTags.onChipClickListener = this
|
binding.chipsTags.onChipClickListener = this
|
||||||
binding.textViewAuthor.setOnClickListener(this)
|
binding.textViewAuthor.setOnClickListener(this)
|
||||||
binding.imageViewCover.setOnClickListener(this)
|
binding.imageViewCover.setOnClickListener(this)
|
||||||
|
|||||||
@@ -40,13 +40,15 @@ class LocalMangaDirInput(root: File) : LocalMangaInput(root) {
|
|||||||
val mangaUri = root.toUri().toString()
|
val mangaUri = root.toUri().toString()
|
||||||
val chapterFiles = getChaptersFiles()
|
val chapterFiles = getChaptersFiles()
|
||||||
val info = index?.getMangaInfo()
|
val info = index?.getMangaInfo()
|
||||||
|
val cover = fileUri(
|
||||||
|
root,
|
||||||
|
index?.getCoverEntry() ?: findFirstImageEntry().orEmpty(),
|
||||||
|
)
|
||||||
val manga = info?.copy2(
|
val manga = info?.copy2(
|
||||||
source = MangaSource.LOCAL,
|
source = MangaSource.LOCAL,
|
||||||
url = mangaUri,
|
url = mangaUri,
|
||||||
coverUrl = fileUri(
|
coverUrl = cover,
|
||||||
root,
|
largeCoverUrl = cover,
|
||||||
index.getCoverEntry() ?: findFirstImageEntry().orEmpty(),
|
|
||||||
),
|
|
||||||
chapters = info.chapters?.mapIndexed { i, c ->
|
chapters = info.chapters?.mapIndexed { i, c ->
|
||||||
c.copy(url = chapterFiles[i].toUri().toString(), source = MangaSource.LOCAL)
|
c.copy(url = chapterFiles[i].toUri().toString(), source = MangaSource.LOCAL)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -67,10 +67,11 @@ sealed class LocalMangaInput(
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
protected fun Manga.copy2(
|
protected fun Manga.copy2(
|
||||||
url: String = this.url,
|
url: String,
|
||||||
coverUrl: String = this.coverUrl,
|
coverUrl: String,
|
||||||
chapters: List<MangaChapter>? = this.chapters,
|
largeCoverUrl: String,
|
||||||
source: MangaSource = this.source,
|
chapters: List<MangaChapter>?,
|
||||||
|
source: MangaSource,
|
||||||
) = Manga(
|
) = Manga(
|
||||||
id = id,
|
id = id,
|
||||||
title = title,
|
title = title,
|
||||||
@@ -91,8 +92,8 @@ sealed class LocalMangaInput(
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
protected fun MangaChapter.copy(
|
protected fun MangaChapter.copy(
|
||||||
url: String = this.url,
|
url: String,
|
||||||
source: MangaSource = this.source,
|
source: MangaSource,
|
||||||
) = MangaChapter(
|
) = MangaChapter(
|
||||||
id = id,
|
id = id,
|
||||||
name = name,
|
name = name,
|
||||||
|
|||||||
@@ -41,14 +41,15 @@ class LocalMangaZipInput(root: File) : LocalMangaInput(root) {
|
|||||||
val index = entry?.let(zip::readText)?.let(::MangaIndex)
|
val index = entry?.let(zip::readText)?.let(::MangaIndex)
|
||||||
val info = index?.getMangaInfo()
|
val info = index?.getMangaInfo()
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
|
val cover = zipUri(
|
||||||
|
root,
|
||||||
|
entryName = index.getCoverEntry() ?: findFirstImageEntry(zip.entries())?.name.orEmpty(),
|
||||||
|
)
|
||||||
return@use info.copy2(
|
return@use info.copy2(
|
||||||
source = MangaSource.LOCAL,
|
source = MangaSource.LOCAL,
|
||||||
url = fileUri,
|
url = fileUri,
|
||||||
coverUrl = zipUri(
|
coverUrl = cover,
|
||||||
root,
|
largeCoverUrl = cover,
|
||||||
entryName = index.getCoverEntry()
|
|
||||||
?: findFirstImageEntry(zip.entries())?.name.orEmpty(),
|
|
||||||
),
|
|
||||||
chapters = info.chapters?.map { c ->
|
chapters = info.chapters?.map { c ->
|
||||||
c.copy(url = fileUri, source = MangaSource.LOCAL)
|
c.copy(url = fileUri, source = MangaSource.LOCAL)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import coil.request.ImageRequest
|
|||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.ErrorReporterReceiver
|
||||||
import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission
|
import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission
|
||||||
import org.koitharu.kotatsu.core.util.ext.getDisplayMessage
|
import org.koitharu.kotatsu.core.util.ext.getDisplayMessage
|
||||||
import org.koitharu.kotatsu.core.util.ext.toBitmapOrNull
|
import org.koitharu.kotatsu.core.util.ext.toBitmapOrNull
|
||||||
@@ -91,6 +92,7 @@ class ImportWorker @AssistedInject constructor(
|
|||||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
.setDefaults(0)
|
.setDefaults(0)
|
||||||
.setSilent(true)
|
.setSilent(true)
|
||||||
|
.setAutoCancel(true)
|
||||||
result.onSuccess { manga ->
|
result.onSuccess { manga ->
|
||||||
notification.setLargeIcon(
|
notification.setLargeIcon(
|
||||||
coil.execute(
|
coil.execute(
|
||||||
@@ -110,10 +112,9 @@ class ImportWorker @AssistedInject constructor(
|
|||||||
PendingIntent.FLAG_UPDATE_CURRENT,
|
PendingIntent.FLAG_UPDATE_CURRENT,
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
).setAutoCancel(true)
|
).setVisibility(
|
||||||
.setVisibility(
|
if (manga.isNsfw) NotificationCompat.VISIBILITY_SECRET else NotificationCompat.VISIBILITY_PUBLIC,
|
||||||
if (manga.isNsfw) NotificationCompat.VISIBILITY_SECRET else NotificationCompat.VISIBILITY_PUBLIC,
|
)
|
||||||
)
|
|
||||||
notification.setContentTitle(applicationContext.getString(R.string.import_completed))
|
notification.setContentTitle(applicationContext.getString(R.string.import_completed))
|
||||||
.setContentText(applicationContext.getString(R.string.import_completed_hint))
|
.setContentText(applicationContext.getString(R.string.import_completed_hint))
|
||||||
.setSmallIcon(R.drawable.ic_stat_done)
|
.setSmallIcon(R.drawable.ic_stat_done)
|
||||||
@@ -123,6 +124,11 @@ class ImportWorker @AssistedInject constructor(
|
|||||||
notification.setContentTitle(applicationContext.getString(R.string.error_occurred))
|
notification.setContentTitle(applicationContext.getString(R.string.error_occurred))
|
||||||
.setContentText(error.getDisplayMessage(applicationContext.resources))
|
.setContentText(error.getDisplayMessage(applicationContext.resources))
|
||||||
.setSmallIcon(android.R.drawable.stat_notify_error)
|
.setSmallIcon(android.R.drawable.stat_notify_error)
|
||||||
|
.addAction(
|
||||||
|
R.drawable.ic_alert_outline,
|
||||||
|
applicationContext.getString(R.string.report),
|
||||||
|
ErrorReporterReceiver.getPendingIntent(applicationContext, error),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return notification.build()
|
return notification.build()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import androidx.core.view.updatePadding
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentTransaction
|
import androidx.fragment.app.FragmentTransaction
|
||||||
import androidx.fragment.app.commit
|
import androidx.fragment.app.commit
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.withResumed
|
import androidx.lifecycle.withResumed
|
||||||
import androidx.transition.TransitionManager
|
import androidx.transition.TransitionManager
|
||||||
@@ -183,7 +184,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||||
android.R.id.home -> if (isSearchOpened()) {
|
android.R.id.home -> if (isSearchOpened()) {
|
||||||
super.onOptionsItemSelected(item)
|
closeSearchCallback.handleOnBackPressed()
|
||||||
|
true
|
||||||
} else {
|
} else {
|
||||||
viewBinding.searchView.requestFocus()
|
viewBinding.searchView.requestFocus()
|
||||||
true
|
true
|
||||||
@@ -228,6 +230,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
supportFragmentManager.commit {
|
supportFragmentManager.commit {
|
||||||
setReorderingAllowed(true)
|
setReorderingAllowed(true)
|
||||||
add(R.id.container, SearchSuggestionFragment.newInstance(), TAG_SEARCH)
|
add(R.id.container, SearchSuggestionFragment.newInstance(), TAG_SEARCH)
|
||||||
|
navigationDelegate.primaryFragment?.let {
|
||||||
|
setMaxLifecycle(it, Lifecycle.State.STARTED)
|
||||||
|
}
|
||||||
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||||
runOnCommit { onSearchOpened() }
|
runOnCommit { onSearchOpened() }
|
||||||
}
|
}
|
||||||
@@ -413,16 +418,20 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
private inner class CloseSearchCallback : OnBackPressedCallback(false) {
|
private inner class CloseSearchCallback : OnBackPressedCallback(false) {
|
||||||
|
|
||||||
override fun handleOnBackPressed() {
|
override fun handleOnBackPressed() {
|
||||||
val fragment = supportFragmentManager.findFragmentByTag(TAG_SEARCH)
|
val fm = supportFragmentManager
|
||||||
|
val fragment = fm.findFragmentByTag(TAG_SEARCH)
|
||||||
viewBinding.searchView.clearFocus()
|
viewBinding.searchView.clearFocus()
|
||||||
if (fragment == null) {
|
if (fragment == null) {
|
||||||
// this should not happen but who knows
|
// this should not happen but who knows
|
||||||
isEnabled = false
|
isEnabled = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
supportFragmentManager.commit {
|
fm.commit {
|
||||||
setReorderingAllowed(true)
|
setReorderingAllowed(true)
|
||||||
remove(fragment)
|
remove(fragment)
|
||||||
|
navigationDelegate.primaryFragment?.let {
|
||||||
|
setMaxLifecycle(it, Lifecycle.State.RESUMED)
|
||||||
|
}
|
||||||
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||||
runOnCommit { onSearchClosed() }
|
runOnCommit { onSearchClosed() }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import org.koitharu.kotatsu.core.parser.MangaIntent
|
|||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||||
import org.koitharu.kotatsu.core.ui.BaseFullscreenActivity
|
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.GridTouchHelper
|
||||||
import org.koitharu.kotatsu.core.util.IdlingDetector
|
import org.koitharu.kotatsu.core.util.IdlingDetector
|
||||||
import org.koitharu.kotatsu.core.util.ShareHelper
|
import org.koitharu.kotatsu.core.util.ShareHelper
|
||||||
@@ -52,6 +53,7 @@ import org.koitharu.kotatsu.core.util.ext.postDelayed
|
|||||||
import org.koitharu.kotatsu.core.util.ext.setValueRounded
|
import org.koitharu.kotatsu.core.util.ext.setValueRounded
|
||||||
import org.koitharu.kotatsu.core.util.ext.zipWithPrevious
|
import org.koitharu.kotatsu.core.util.ext.zipWithPrevious
|
||||||
import org.koitharu.kotatsu.databinding.ActivityReaderBinding
|
import org.koitharu.kotatsu.databinding.ActivityReaderBinding
|
||||||
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.reader.ui.config.ReaderConfigSheet
|
import org.koitharu.kotatsu.reader.ui.config.ReaderConfigSheet
|
||||||
@@ -72,7 +74,8 @@ class ReaderActivity :
|
|||||||
ReaderConfigSheet.Callback,
|
ReaderConfigSheet.Callback,
|
||||||
ReaderControlDelegate.OnInteractionListener,
|
ReaderControlDelegate.OnInteractionListener,
|
||||||
OnApplyWindowInsetsListener,
|
OnApplyWindowInsetsListener,
|
||||||
IdlingDetector.Callback {
|
IdlingDetector.Callback,
|
||||||
|
ZoomControl.ZoomControlListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var settings: AppSettings
|
lateinit var settings: AppSettings
|
||||||
@@ -110,6 +113,7 @@ class ReaderActivity :
|
|||||||
controlDelegate = ReaderControlDelegate(resources, settings, this, this)
|
controlDelegate = ReaderControlDelegate(resources, settings, this, this)
|
||||||
viewBinding.toolbarBottom.setOnMenuItemClickListener(::onOptionsItemSelected)
|
viewBinding.toolbarBottom.setOnMenuItemClickListener(::onOptionsItemSelected)
|
||||||
viewBinding.slider.setLabelFormatter(PageLabelFormatter())
|
viewBinding.slider.setLabelFormatter(PageLabelFormatter())
|
||||||
|
viewBinding.zoomControl.listener = this
|
||||||
ReaderSliderListener(this, viewModel).attachToSlider(viewBinding.slider)
|
ReaderSliderListener(this, viewModel).attachToSlider(viewBinding.slider)
|
||||||
insetsDelegate.interceptingWindowInsetsListener = this
|
insetsDelegate.interceptingWindowInsetsListener = this
|
||||||
idlingDetector.bindToLifecycle(this)
|
idlingDetector.bindToLifecycle(this)
|
||||||
@@ -145,6 +149,14 @@ class ReaderActivity :
|
|||||||
.setAnchorView(viewBinding.appbarBottom)
|
.setAnchorView(viewBinding.appbarBottom)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
viewModel.isZoomControlsEnabled.observe(this) {
|
||||||
|
viewBinding.zoomControl.isVisible = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getParentActivityIntent(): Intent? {
|
||||||
|
val manga = viewModel.manga?.toManga() ?: return null
|
||||||
|
return DetailsActivity.newIntent(this, manga)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUserInteraction() {
|
override fun onUserInteraction() {
|
||||||
@@ -157,6 +169,14 @@ class ReaderActivity :
|
|||||||
viewModel.saveCurrentState(readerManager.currentReader?.getCurrentState())
|
viewModel.saveCurrentState(readerManager.currentReader?.getCurrentState())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onZoomIn() {
|
||||||
|
readerManager.currentReader?.onZoomIn()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onZoomOut() {
|
||||||
|
readerManager.currentReader?.onZoomOut()
|
||||||
|
}
|
||||||
|
|
||||||
private fun onInitReader(mode: ReaderMode?) {
|
private fun onInitReader(mode: ReaderMode?) {
|
||||||
if (mode == null) {
|
if (mode == null) {
|
||||||
return
|
return
|
||||||
@@ -249,6 +269,7 @@ class ReaderActivity :
|
|||||||
|
|
||||||
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
||||||
touchHelper.dispatchTouchEvent(ev)
|
touchHelper.dispatchTouchEvent(ev)
|
||||||
|
scrollTimer.onTouchEvent(ev)
|
||||||
return super.dispatchTouchEvent(ev)
|
return super.dispatchTouchEvent(ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,15 +307,13 @@ class ReaderActivity :
|
|||||||
private fun onPageSaved(uri: Uri?) {
|
private fun onPageSaved(uri: Uri?) {
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
Snackbar.make(viewBinding.container, R.string.page_saved, Snackbar.LENGTH_LONG)
|
Snackbar.make(viewBinding.container, R.string.page_saved, Snackbar.LENGTH_LONG)
|
||||||
.setAnchorView(viewBinding.appbarBottom)
|
|
||||||
.setAction(R.string.share) {
|
.setAction(R.string.share) {
|
||||||
ShareHelper(this).shareImage(uri)
|
ShareHelper(this).shareImage(uri)
|
||||||
}.show()
|
}
|
||||||
} else {
|
} else {
|
||||||
Snackbar.make(viewBinding.container, R.string.error_occurred, Snackbar.LENGTH_SHORT)
|
Snackbar.make(viewBinding.container, R.string.error_occurred, Snackbar.LENGTH_SHORT)
|
||||||
.setAnchorView(viewBinding.appbarBottom)
|
}.setAnchorView(viewBinding.appbarBottom)
|
||||||
.show()
|
.show()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setWindowSecure(isSecure: Boolean) {
|
private fun setWindowSecure(isSecure: Boolean) {
|
||||||
|
|||||||
@@ -118,17 +118,16 @@ class ReaderViewModel @Inject constructor(
|
|||||||
valueProducer = { isReaderKeepScreenOn },
|
valueProducer = { isReaderKeepScreenOn },
|
||||||
)
|
)
|
||||||
|
|
||||||
val isWebtoonZoomEnabled = settings.observeAsStateFlow(
|
val isWebtoonZooEnabled = observeIsWebtoonZoomEnabled()
|
||||||
scope = viewModelScope + Dispatchers.Default,
|
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, false)
|
||||||
key = AppSettings.KEY_WEBTOON_ZOOM,
|
|
||||||
valueProducer = { isWebtoonZoomEnable },
|
|
||||||
)
|
|
||||||
|
|
||||||
val isZoomControlEnabled = settings.observeAsStateFlow(
|
val isZoomControlsEnabled = getObserveIsZoomControlEnabled().flatMapLatest { zoom ->
|
||||||
scope = viewModelScope + Dispatchers.Default,
|
if (zoom) {
|
||||||
key = AppSettings.KEY_READER_ZOOM_BUTTONS,
|
combine(readerMode, isWebtoonZooEnabled) { mode, ze -> ze || mode != ReaderMode.WEBTOON }
|
||||||
valueProducer = { isReaderZoomButtonsEnabled },
|
} else {
|
||||||
)
|
flowOf(false)
|
||||||
|
}
|
||||||
|
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, false)
|
||||||
|
|
||||||
val readerSettings = ReaderSettings(
|
val readerSettings = ReaderSettings(
|
||||||
parentScope = viewModelScope,
|
parentScope = viewModelScope,
|
||||||
@@ -259,10 +258,13 @@ class ReaderViewModel @Inject constructor(
|
|||||||
@MainThread
|
@MainThread
|
||||||
fun onCurrentPageChanged(position: Int) {
|
fun onCurrentPageChanged(position: Int) {
|
||||||
val prevJob = stateChangeJob
|
val prevJob = stateChangeJob
|
||||||
|
val pages = content.value.pages // capture immediately
|
||||||
stateChangeJob = launchJob(Dispatchers.Default) {
|
stateChangeJob = launchJob(Dispatchers.Default) {
|
||||||
prevJob?.cancelAndJoin()
|
prevJob?.cancelAndJoin()
|
||||||
loadingJob?.join()
|
loadingJob?.join()
|
||||||
val pages = content.value.pages
|
if (pages.size != content.value.pages.size) {
|
||||||
|
return@launchJob // TODO
|
||||||
|
}
|
||||||
pages.getOrNull(position)?.let { page ->
|
pages.getOrNull(position)?.let { page ->
|
||||||
currentState.update { cs ->
|
currentState.update { cs ->
|
||||||
cs?.copy(chapterId = page.chapterId, page = page.index)
|
cs?.copy(chapterId = page.chapterId, page = page.index)
|
||||||
@@ -402,4 +404,14 @@ class ReaderViewModel @Inject constructor(
|
|||||||
val ppc = 1f / chaptersCount
|
val ppc = 1f / chaptersCount
|
||||||
return ppc * chapterIndex + ppc * pagePercent
|
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 },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.reader.ui
|
package org.koitharu.kotatsu.reader.ui
|
||||||
|
|
||||||
|
import android.view.MotionEvent
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
@@ -8,11 +9,14 @@ import dagger.assisted.AssistedInject
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.yield
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
import kotlin.math.roundToLong
|
import kotlin.math.roundToLong
|
||||||
@@ -33,6 +37,7 @@ class ScrollTimer @AssistedInject constructor(
|
|||||||
private var delayMs: Long = 10L
|
private var delayMs: Long = 10L
|
||||||
private var pageSwitchDelay: Long = 100L
|
private var pageSwitchDelay: Long = 100L
|
||||||
private var resumeAt = 0L
|
private var resumeAt = 0L
|
||||||
|
private var isTouchDown = MutableStateFlow(false)
|
||||||
|
|
||||||
var isEnabled: Boolean = false
|
var isEnabled: Boolean = false
|
||||||
set(value) {
|
set(value) {
|
||||||
@@ -55,6 +60,19 @@ class ScrollTimer @AssistedInject constructor(
|
|||||||
resumeAt = System.currentTimeMillis() + INTERACTION_SKIP_MS
|
resumeAt = System.currentTimeMillis() + INTERACTION_SKIP_MS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onTouchEvent(event: MotionEvent) {
|
||||||
|
when (event.actionMasked) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
isTouchDown.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
MotionEvent.ACTION_UP,
|
||||||
|
MotionEvent.ACTION_CANCEL -> {
|
||||||
|
isTouchDown.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun onSpeedChanged(speed: Float) {
|
private fun onSpeedChanged(speed: Float) {
|
||||||
if (speed <= 0f) {
|
if (speed <= 0f) {
|
||||||
delayMs = 0L
|
delayMs = 0L
|
||||||
@@ -108,12 +126,18 @@ class ScrollTimer @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isPaused(): Boolean {
|
private fun isPaused(): Boolean {
|
||||||
return resumeAt > System.currentTimeMillis()
|
return isTouchDown.value || resumeAt > System.currentTimeMillis()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun delayUntilResumed() {
|
private suspend fun delayUntilResumed() {
|
||||||
while (isPaused()) {
|
while (isPaused()) {
|
||||||
delay(resumeAt - System.currentTimeMillis())
|
val delayTime = resumeAt - System.currentTimeMillis()
|
||||||
|
if (delayTime > 0) {
|
||||||
|
delay(delayTime)
|
||||||
|
} else {
|
||||||
|
yield()
|
||||||
|
}
|
||||||
|
isTouchDown.first { !it }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,10 @@ class ReaderConfigSheet :
|
|||||||
|
|
||||||
private val viewModel by activityViewModels<ReaderViewModel>()
|
private val viewModel by activityViewModels<ReaderViewModel>()
|
||||||
private val savePageRequest = registerForActivityResult(PageSaveContract(), this)
|
private val savePageRequest = registerForActivityResult(PageSaveContract(), this)
|
||||||
private var orientationHelper: ScreenOrientationHelper? = null
|
|
||||||
|
@Inject
|
||||||
|
lateinit var orientationHelper: ScreenOrientationHelper
|
||||||
|
|
||||||
private lateinit var mode: ReaderMode
|
private lateinit var mode: ReaderMode
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -113,7 +116,7 @@ class ReaderConfigSheet :
|
|||||||
}
|
}
|
||||||
|
|
||||||
R.id.button_screen_rotate -> {
|
R.id.button_screen_rotate -> {
|
||||||
orientationHelper?.toggleOrientation()
|
orientationHelper.isLandscape = !orientationHelper.isLandscape
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.button_color_filter -> {
|
R.id.button_color_filter -> {
|
||||||
@@ -128,9 +131,13 @@ class ReaderConfigSheet :
|
|||||||
when (buttonView.id) {
|
when (buttonView.id) {
|
||||||
R.id.switch_scroll_timer -> {
|
R.id.switch_scroll_timer -> {
|
||||||
findCallback()?.isAutoScrollEnabled = isChecked
|
findCallback()?.isAutoScrollEnabled = isChecked
|
||||||
requireViewBinding().labelTimer.isVisible = isChecked
|
requireViewBinding().layoutTimer.isVisible = isChecked
|
||||||
requireViewBinding().sliderTimer.isVisible = isChecked
|
requireViewBinding().sliderTimer.isVisible = isChecked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R.id.switch_screen_lock_rotation -> {
|
||||||
|
orientationHelper.isLocked = isChecked
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +166,7 @@ class ReaderConfigSheet :
|
|||||||
if (fromUser) {
|
if (fromUser) {
|
||||||
settings.readerAutoscrollSpeed = value
|
settings.readerAutoscrollSpeed = value
|
||||||
}
|
}
|
||||||
|
(viewBinding ?: return).labelTimerValue.text = getString(R.string.speed_value, value * 10f)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(result: Uri?) {
|
override fun onActivityResult(result: Uri?) {
|
||||||
@@ -167,14 +175,23 @@ class ReaderConfigSheet :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun observeScreenOrientation() {
|
private fun observeScreenOrientation() {
|
||||||
val helper = ScreenOrientationHelper(requireActivity())
|
orientationHelper.observeAutoOrientation()
|
||||||
orientationHelper = helper
|
|
||||||
helper.observeAutoOrientation()
|
|
||||||
.onEach {
|
.onEach {
|
||||||
requireViewBinding().buttonScreenRotate.isGone = it
|
with(requireViewBinding()) {
|
||||||
|
buttonScreenRotate.isGone = it
|
||||||
|
switchScreenLockRotation.isVisible = it
|
||||||
|
updateOrientationLockSwitch()
|
||||||
|
}
|
||||||
}.launchIn(viewLifecycleScope)
|
}.launchIn(viewLifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateOrientationLockSwitch() {
|
||||||
|
val switch = viewBinding?.switchScreenLockRotation ?: return
|
||||||
|
switch.setOnCheckedChangeListener(null)
|
||||||
|
switch.isChecked = orientationHelper.isLocked
|
||||||
|
switch.setOnCheckedChangeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
private fun findCallback(): Callback? {
|
private fun findCallback(): Callback? {
|
||||||
return (parentFragment as? Callback) ?: (activity as? Callback)
|
return (parentFragment as? Callback) ?: (activity as? Callback)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,9 +46,6 @@ class ReaderSettings(
|
|||||||
val isPagesNumbersEnabled: Boolean
|
val isPagesNumbersEnabled: Boolean
|
||||||
get() = settings.isPagesNumbersEnabled
|
get() = settings.isPagesNumbersEnabled
|
||||||
|
|
||||||
val isZoomControlsEnabled: Boolean
|
|
||||||
get() = settings.isReaderZoomButtonsEnabled
|
|
||||||
|
|
||||||
fun applyBackground(view: View) {
|
fun applyBackground(view: View) {
|
||||||
val bg = settings.readerBackground
|
val bg = settings.readerBackground
|
||||||
view.background = bg.resolve(view.context)
|
view.background = bg.resolve(view.context)
|
||||||
@@ -106,8 +103,6 @@ class ReaderSettings(
|
|||||||
if (
|
if (
|
||||||
key == AppSettings.KEY_ZOOM_MODE ||
|
key == AppSettings.KEY_ZOOM_MODE ||
|
||||||
key == AppSettings.KEY_PAGES_NUMBERS ||
|
key == AppSettings.KEY_PAGES_NUMBERS ||
|
||||||
key == AppSettings.KEY_WEBTOON_ZOOM ||
|
|
||||||
key == AppSettings.KEY_READER_ZOOM_BUTTONS ||
|
|
||||||
key == AppSettings.KEY_READER_BACKGROUND ||
|
key == AppSettings.KEY_READER_BACKGROUND ||
|
||||||
key == AppSettings.KEY_32BIT_COLOR
|
key == AppSettings.KEY_32BIT_COLOR
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import androidx.fragment.app.activityViewModels
|
|||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
|
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
|
||||||
import org.koitharu.kotatsu.core.ui.BaseFragment
|
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.getParcelableCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
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"
|
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>()
|
protected val viewModel by activityViewModels<ReaderViewModel>()
|
||||||
private var stateToSave: ReaderState? = null
|
private var stateToSave: ReaderState? = null
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.core.os.NetworkState
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
|
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
|
||||||
import org.koitharu.kotatsu.core.util.ext.doOnPageChanged
|
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.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
||||||
import org.koitharu.kotatsu.core.util.ext.resetTransformations
|
import org.koitharu.kotatsu.core.util.ext.resetTransformations
|
||||||
@@ -28,6 +29,7 @@ import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
|
|||||||
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderFragment
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
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.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.PagerEventSupplier
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -104,6 +106,15 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
|||||||
exceptionResolver = exceptionResolver,
|
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) {
|
override fun switchPageBy(delta: Int) {
|
||||||
with(requireViewBinding().pager) {
|
with(requireViewBinding().pager) {
|
||||||
setCurrentItem(currentItem - delta, isAnimationEnabled())
|
setCurrentItem(currentItem - delta, isAnimationEnabled())
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
|||||||
import android.graphics.PointF
|
import android.graphics.PointF
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.animation.DecelerateInterpolator
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import com.davemorrissey.labs.subscaleview.ImageSource
|
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.exceptions.resolve.ExceptionResolver
|
||||||
import org.koitharu.kotatsu.core.model.ZoomMode
|
import org.koitharu.kotatsu.core.model.ZoomMode
|
||||||
import org.koitharu.kotatsu.core.os.NetworkState
|
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.getDisplayMessage
|
||||||
import org.koitharu.kotatsu.core.util.ext.ifZero
|
import org.koitharu.kotatsu.core.util.ext.ifZero
|
||||||
import org.koitharu.kotatsu.core.util.ext.isLowRamDevice
|
import org.koitharu.kotatsu.core.util.ext.isLowRamDevice
|
||||||
@@ -29,7 +31,8 @@ open class PageHolder(
|
|||||||
networkState: NetworkState,
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) : BasePageHolder<ItemPageBinding>(binding, loader, settings, networkState, exceptionResolver),
|
) : BasePageHolder<ItemPageBinding>(binding, loader, settings, networkState, exceptionResolver),
|
||||||
View.OnClickListener {
|
View.OnClickListener,
|
||||||
|
ZoomControl.ZoomControlListener {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
binding.ssiv.bindToLifecycle(owner)
|
binding.ssiv.bindToLifecycle(owner)
|
||||||
@@ -40,12 +43,10 @@ open class PageHolder(
|
|||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
bindingInfo.buttonErrorDetails.setOnClickListener(this)
|
bindingInfo.buttonErrorDetails.setOnClickListener(this)
|
||||||
binding.textViewNumber.isVisible = settings.isPagesNumbersEnabled
|
binding.textViewNumber.isVisible = settings.isPagesNumbersEnabled
|
||||||
binding.zoomControl.listener = SsivZoomListener(binding.ssiv)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigChanged() {
|
override fun onConfigChanged() {
|
||||||
super.onConfigChanged()
|
super.onConfigChanged()
|
||||||
binding.zoomControl.isVisible = settings.isZoomControlsEnabled
|
|
||||||
@Suppress("SENSELESS_COMPARISON")
|
@Suppress("SENSELESS_COMPARISON")
|
||||||
if (settings.applyBitmapConfig(binding.ssiv) && delegate != null) {
|
if (settings.applyBitmapConfig(binding.ssiv) && delegate != null) {
|
||||||
delegate.reload()
|
delegate.reload()
|
||||||
@@ -141,4 +142,23 @@ open class PageHolder(
|
|||||||
bindingInfo.layoutError.isVisible = true
|
bindingInfo.layoutError.isVisible = true
|
||||||
bindingInfo.progressBar.hide()
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.core.os.NetworkState
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
|
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
|
||||||
import org.koitharu.kotatsu.core.util.ext.doOnPageChanged
|
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.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
||||||
import org.koitharu.kotatsu.core.util.ext.resetTransformations
|
import org.koitharu.kotatsu.core.util.ext.resetTransformations
|
||||||
@@ -82,6 +83,14 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>(),
|
|||||||
super.onDestroyView()
|
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 {
|
override fun onGenericMotion(v: View?, event: MotionEvent): Boolean {
|
||||||
if (event.source and InputDevice.SOURCE_CLASS_POINTER != 0) {
|
if (event.source and InputDevice.SOURCE_CLASS_POINTER != 0) {
|
||||||
if (event.actionMasked == MotionEvent.ACTION_SCROLL) {
|
if (event.actionMasked == MotionEvent.ACTION_SCROLL) {
|
||||||
|
|||||||
@@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,12 +4,10 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.animation.DecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
import androidx.core.view.isVisible
|
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.flow.combine
|
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.os.NetworkState
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
@@ -47,15 +45,9 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
|||||||
adapter = readerAdapter
|
adapter = readerAdapter
|
||||||
addOnPageScrollListener(PageScrollListener())
|
addOnPageScrollListener(PageScrollListener())
|
||||||
}
|
}
|
||||||
binding.zoomControl.listener = binding.frame
|
viewModel.isWebtoonZooEnabled.observe(viewLifecycleOwner) {
|
||||||
|
|
||||||
viewModel.isWebtoonZoomEnabled.observe(viewLifecycleOwner) {
|
|
||||||
binding.frame.isZoomEnable = it
|
binding.frame.isZoomEnable = it
|
||||||
}
|
}
|
||||||
combine(viewModel.isWebtoonZoomEnabled, viewModel.isZoomControlEnabled, Boolean::and)
|
|
||||||
.observe(viewLifecycleOwner) {
|
|
||||||
binding.zoomControl.isVisible = it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -111,6 +103,14 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onZoomIn() {
|
||||||
|
viewBinding?.frame?.onZoomIn()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onZoomOut() {
|
||||||
|
viewBinding?.frame?.onZoomOut()
|
||||||
|
}
|
||||||
|
|
||||||
private fun notifyPageChanged(page: Int) {
|
private fun notifyPageChanged(page: Int) {
|
||||||
viewModel.onCurrentPageChanged(page)
|
viewModel.onCurrentPageChanged(page)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
|||||||
private val targetHitRect = Rect()
|
private val targetHitRect = Rect()
|
||||||
private var animator: ValueAnimator? = null
|
private var animator: ValueAnimator? = null
|
||||||
|
|
||||||
var isZoomEnable = true
|
var isZoomEnable = false
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
if (scale != 1f) {
|
if (scale != 1f) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.SharingStarted
|
|||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
|
import kotlinx.coroutines.flow.getAndUpdate
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
@@ -95,7 +96,6 @@ open class RemoteListViewModel @Inject constructor(
|
|||||||
.onEach { filterState ->
|
.onEach { filterState ->
|
||||||
loadingJob?.cancelAndJoin()
|
loadingJob?.cancelAndJoin()
|
||||||
mangaList.value = null
|
mangaList.value = null
|
||||||
hasNextPage.value = false
|
|
||||||
loadList(filterState, false)
|
loadList(filterState, false)
|
||||||
}.catch { error ->
|
}.catch { error ->
|
||||||
listError.value = error
|
listError.value = error
|
||||||
@@ -134,12 +134,18 @@ open class RemoteListViewModel @Inject constructor(
|
|||||||
sortOrder = filterState.sortOrder,
|
sortOrder = filterState.sortOrder,
|
||||||
tags = filterState.tags,
|
tags = filterState.tags,
|
||||||
)
|
)
|
||||||
if (!append) {
|
val oldList = mangaList.getAndUpdate { oldList ->
|
||||||
mangaList.value = list
|
if (!append || oldList.isNullOrEmpty()) {
|
||||||
} else if (list.isNotEmpty()) {
|
list
|
||||||
mangaList.value = mangaList.value?.plus(list) ?: list
|
} else {
|
||||||
|
oldList + list
|
||||||
|
}
|
||||||
|
}.orEmpty()
|
||||||
|
hasNextPage.value = if (append) {
|
||||||
|
list.isNotEmpty()
|
||||||
|
} else {
|
||||||
|
list.size > oldList.size || hasNextPage.value
|
||||||
}
|
}
|
||||||
hasNextPage.value = list.isNotEmpty() // TODO check if new ids added
|
|
||||||
} catch (e: CancellationException) {
|
} catch (e: CancellationException) {
|
||||||
throw e
|
throw e
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
@@ -148,6 +154,7 @@ open class RemoteListViewModel @Inject constructor(
|
|||||||
if (!mangaList.value.isNullOrEmpty()) {
|
if (!mangaList.value.isNullOrEmpty()) {
|
||||||
errorEvent.call(e)
|
errorEvent.call(e)
|
||||||
}
|
}
|
||||||
|
hasNextPage.value = false
|
||||||
}
|
}
|
||||||
}.also { loadingJob = it }
|
}.also { loadingJob = it }
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user