Compare commits
172 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 656a707b4c | |||
| 04afe7a934 | |||
| 689670b3ff | |||
| 6273a9decb | |||
|
|
72336d4f71 | ||
|
|
731e998eb2 | ||
|
|
9bf53114de | ||
| 0e1b8db688 | |||
| 3a62e2e6c0 | |||
| 08764cb3cb | |||
|
|
9c52545f63 | ||
|
|
a6c30d33d4 | ||
|
|
25974af229 | ||
|
|
607dfc9be3 | ||
|
|
560e669700 | ||
|
|
ba403c9360 | ||
|
|
0f1c9ff05d | ||
|
|
662f08e115 | ||
|
|
d647a32e9f | ||
| 375e72cb98 | |||
| 34c7cafdfe | |||
|
|
03e0eefe4d | ||
| f41425f03d | |||
| 400b91278f | |||
| 9088f77ae5 | |||
| 86da3217d1 | |||
| 24908e52af | |||
| 1261a6790d | |||
| 59fa61864a | |||
| 1cbfe017ea | |||
| f469369b14 | |||
| 1ddcaed483 | |||
|
|
7bb7736f18 | ||
|
|
d1e7e7a2a6 | ||
| 0c4b7b0586 | |||
| f320f22863 | |||
| d224cd99bb | |||
|
|
b955d31770 | ||
| b4eb8d56a6 | |||
| c896ac72e8 | |||
| b599cb33ff | |||
| b3eab1a2a0 | |||
| 79d9dc7b24 | |||
| 7b573f8e6b | |||
|
|
7bd769e294 | ||
|
|
fde5f86313 | ||
| 3c23bf7ec9 | |||
| 4665f8b74e | |||
| 5a43e677c5 | |||
| 38d4274ece | |||
| 0e5221fa6e | |||
| b458bde8a1 | |||
| c663d10515 | |||
| cec19c3db3 | |||
|
|
ff58539e2e | ||
| d8e7689a94 | |||
| 32cfbb327c | |||
| 245e87256b | |||
| ed8c69037f | |||
|
|
3f76d22d67 | ||
| 980988e684 | |||
|
|
347811abb6 | ||
|
|
ccb8b0c8e7 | ||
|
|
18137ab48e | ||
|
|
a9f435ae3d | ||
| 0758cfef64 | |||
| 06d1d56448 | |||
| 07c70eaccc | |||
| 5ad6413952 | |||
|
|
0b9d9ac7f2 | ||
| 3ab87027ab | |||
|
|
7545a774ba | ||
| db16eb8e29 | |||
|
|
e5a27a7c6f | ||
|
|
d26bc102d1 | ||
|
|
fc6a8afd93 | ||
| 5a9d401446 | |||
| 77ac40b445 | |||
| a29454f672 | |||
| 80ee7c8e54 | |||
| fb202f80a5 | |||
| 45dbd5aa44 | |||
| ee65251bf5 | |||
| eaeb11f9ce | |||
| 2f74633abb | |||
| 0f346dc725 | |||
| 1b92848964 | |||
| 3d91583585 | |||
| f76d9fa3e4 | |||
| b00b2e406e | |||
| 74717e2b93 | |||
| 9b54ed6bc7 | |||
| 7b36c64b34 | |||
| da09884136 | |||
| 64aaf37556 | |||
| 11104223eb | |||
| 0c119bc137 | |||
| 5c058e626b | |||
| 2005ae2bf3 | |||
| d0650c7cf4 | |||
|
|
2df4e6480a | ||
|
|
017a1686dc | ||
|
|
279dc03695 | ||
|
|
c8c482f692 | ||
|
|
02a0e3ebcd | ||
|
|
fc0b3f3b38 | ||
|
|
2925900214 | ||
|
|
eae370e41c | ||
|
|
d0338a604a | ||
|
|
e22b98b476 | ||
| 4d838d290d | |||
| 048efdf59f | |||
| 65dbc6b8e5 | |||
| 627a00beb4 | |||
| e00ed13ad1 | |||
| af2adeba13 | |||
| 893fa6bd90 | |||
| 512188c8dd | |||
| aae6761809 | |||
| c3f055d0c4 | |||
| 93c6bec452 | |||
|
|
04d5df20d1 | ||
|
|
665eca0699 | ||
|
|
9a1534464f | ||
|
|
f856fc6fac | ||
| 4af8e73303 | |||
| 23239f1fec | |||
| 853e4d6fde | |||
| 14a37ad16e | |||
| c944044465 | |||
| 8a63ca2310 | |||
| 12e5e3b35e | |||
| 553a85ef86 | |||
| d604ff3c24 | |||
|
|
4f9eee7d46 | ||
|
|
fe673a94ed | ||
| bcd891d653 | |||
| 1e75edf262 | |||
| 73478d6a81 | |||
| 982080a930 | |||
| 66cd5070dc | |||
|
|
c05b0eaa59 | ||
|
|
29a073d844 | ||
| a0e69428e4 | |||
| de7012cabf | |||
| 3f6a103915 | |||
| 734765dbdd | |||
|
|
117c4c5978 | ||
|
|
13e33a6614 | ||
|
|
affb495136 | ||
|
|
9b2dafd668 | ||
| 5f32c0401f | |||
| f35f40ed27 | |||
| 46f0d3ef74 | |||
| c27c785ac2 | |||
| 6e844e8c3b | |||
| 4186c36f30 | |||
| 2d727a0da8 | |||
| 39e574e9dc | |||
| efb94cbd67 | |||
| 757e33dfb4 | |||
| ab9bdf9f07 | |||
| a68632a888 | |||
| 9b0dc8b413 | |||
| f43fe5830e | |||
| ce616b328c | |||
| 824a8ff97a | |||
|
|
ef9018b92f | ||
|
|
a088d10935 | ||
| 2e561697ac | |||
| d242acd502 | |||
| d37b44d3f6 |
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
@@ -1 +1,2 @@
|
|||||||
|
ko_fi: xtimms
|
||||||
custom: ["https://yoomoney.ru/to/410012543938752"]
|
custom: ["https://yoomoney.ru/to/410012543938752"]
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,6 +7,7 @@
|
|||||||
/.idea/modules.xml
|
/.idea/modules.xml
|
||||||
/.idea/misc.xml
|
/.idea/misc.xml
|
||||||
/.idea/discord.xml
|
/.idea/discord.xml
|
||||||
|
/.idea/compiler.xml
|
||||||
/.idea/workspace.xml
|
/.idea/workspace.xml
|
||||||
/.idea/navEditor.xml
|
/.idea/navEditor.xml
|
||||||
/.idea/assetWizardSettings.xml
|
/.idea/assetWizardSettings.xml
|
||||||
|
|||||||
6
.idea/compiler.xml
generated
6
.idea/compiler.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<bytecodeTargetLevel target="11" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
3
.idea/kotlinc.xml
generated
3
.idea/kotlinc.xml
generated
@@ -3,4 +3,7 @@
|
|||||||
<component name="Kotlin2JvmCompilerArguments">
|
<component name="Kotlin2JvmCompilerArguments">
|
||||||
<option name="jvmTarget" value="1.8" />
|
<option name="jvmTarget" value="1.8" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="KotlinJpsPluginSettings">
|
||||||
|
<option name="version" value="1.7.20" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
6
.idea/ktlint.xml
generated
6
.idea/ktlint.xml
generated
@@ -1,7 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="KtlintProjectConfiguration">
|
<component name="KtlintProjectConfiguration">
|
||||||
|
<enableKtlint>false</enableKtlint>
|
||||||
<androidMode>true</androidMode>
|
<androidMode>true</androidMode>
|
||||||
<treatAsErrors>false</treatAsErrors>
|
<treatAsErrors>false</treatAsErrors>
|
||||||
|
<disabledRules>
|
||||||
|
<list>
|
||||||
|
<option value="no-empty-first-line-in-method-block" />
|
||||||
|
</list>
|
||||||
|
</disabledRules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -26,7 +26,7 @@ Download APK directly from GitHub:
|
|||||||
* Notifications about new chapters with updates feed
|
* Notifications about new chapters with updates feed
|
||||||
* Shikimori integration (manga tracking)
|
* Shikimori integration (manga tracking)
|
||||||
* Password/fingerprint protect access to the app
|
* Password/fingerprint protect access to the app
|
||||||
* History and favourites synchronization across devices (coming soon)
|
* History and favourites [synchronization](https://github.com/KotatsuApp/kotatsu-syncserver) across devices
|
||||||
|
|
||||||
### Screenshots
|
### Screenshots
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ android {
|
|||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 33
|
targetSdkVersion 33
|
||||||
versionCode 495
|
versionCode 508
|
||||||
versionName '4.0-a6'
|
versionName '4.1.1'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
@@ -60,6 +60,7 @@ android {
|
|||||||
'-opt-in=kotlinx.coroutines.FlowPreview',
|
'-opt-in=kotlinx.coroutines.FlowPreview',
|
||||||
'-opt-in=kotlin.contracts.ExperimentalContracts',
|
'-opt-in=kotlin.contracts.ExperimentalContracts',
|
||||||
'-opt-in=coil.annotation.ExperimentalCoilApi',
|
'-opt-in=coil.annotation.ExperimentalCoilApi',
|
||||||
|
'-opt-in=com.google.android.material.badge.ExperimentalBadgeUtils',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
lint {
|
lint {
|
||||||
@@ -82,15 +83,15 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation('com.github.KotatsuApp:kotatsu-parsers:551a1d70ae') {
|
implementation('com.github.KotatsuApp:kotatsu-parsers:c4acb9725f') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
||||||
|
|
||||||
implementation 'androidx.core:core-ktx:1.8.0'
|
implementation 'androidx.core:core-ktx:1.9.0'
|
||||||
implementation 'androidx.activity:activity-ktx:1.5.1'
|
implementation 'androidx.activity:activity-ktx:1.6.1'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.5.2'
|
implementation 'androidx.fragment:fragment-ktx:1.5.5'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-service:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-service:2.5.1'
|
||||||
@@ -101,8 +102,8 @@ dependencies {
|
|||||||
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
|
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
|
||||||
implementation 'androidx.preference:preference-ktx:1.2.0'
|
implementation 'androidx.preference:preference-ktx:1.2.0'
|
||||||
implementation 'androidx.work:work-runtime-ktx:2.7.1'
|
implementation 'androidx.work:work-runtime-ktx:2.7.1'
|
||||||
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha04'
|
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
||||||
implementation 'com.google.android.material:material:1.7.0-rc01'
|
implementation 'com.google.android.material:material:1.7.0'
|
||||||
//noinspection LifecycleAnnotationProcessorWithJava8
|
//noinspection LifecycleAnnotationProcessorWithJava8
|
||||||
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.1'
|
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.1'
|
||||||
|
|
||||||
@@ -117,35 +118,35 @@ dependencies {
|
|||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
||||||
|
|
||||||
implementation "com.google.dagger:hilt-android:2.43.2"
|
implementation 'com.google.dagger:hilt-android:2.44.2'
|
||||||
kapt "com.google.dagger:hilt-compiler:2.43.2"
|
kapt 'com.google.dagger:hilt-compiler:2.44.2'
|
||||||
implementation 'androidx.hilt:hilt-work:1.0.0'
|
implementation 'androidx.hilt:hilt-work:1.0.0'
|
||||||
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
||||||
|
|
||||||
implementation 'io.coil-kt:coil-base:2.2.0'
|
implementation 'io.coil-kt:coil-base:2.2.2'
|
||||||
implementation 'io.coil-kt:coil-svg:2.2.0'
|
implementation 'io.coil-kt:coil-svg:2.2.2'
|
||||||
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:2942b797a2'
|
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:1b19231b2f'
|
||||||
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
||||||
|
|
||||||
implementation 'ch.acra:acra-http:5.9.6'
|
implementation 'ch.acra:acra-http:5.9.7'
|
||||||
implementation 'ch.acra:acra-dialog:5.9.6'
|
implementation 'ch.acra:acra-dialog:5.9.7'
|
||||||
|
|
||||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
testImplementation 'org.json:json:20220320'
|
testImplementation 'org.json:json:20220924'
|
||||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.test:runner:1.4.0'
|
androidTestImplementation 'androidx.test:runner:1.5.1'
|
||||||
androidTestImplementation 'androidx.test:rules:1.4.0'
|
androidTestImplementation 'androidx.test:rules:1.5.0'
|
||||||
androidTestImplementation 'androidx.test:core-ktx:1.4.0'
|
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
|
||||||
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.4'
|
||||||
|
|
||||||
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.room:room-testing:2.4.3'
|
androidTestImplementation 'androidx.room:room-testing:2.4.3'
|
||||||
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.13.0'
|
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
|
||||||
|
|
||||||
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.43.2'
|
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.44.2'
|
||||||
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.43.2'
|
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.44.2'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
android:fullBackupOnly="true"
|
android:fullBackupOnly="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
android:largeHeap="true"
|
||||||
|
android:localeConfig="@xml/locales"
|
||||||
android:networkSecurityConfig="@xml/network_security_config"
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
@@ -68,6 +70,9 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.history.ui.HistoryActivity"
|
android:name="org.koitharu.kotatsu.history.ui.HistoryActivity"
|
||||||
android:label="@string/history" />
|
android:label="@string/history" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.tracker.ui.updates.UpdatesActivity"
|
||||||
|
android:label="@string/updates" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.favourites.ui.FavouritesActivity"
|
android:name="org.koitharu.kotatsu.favourites.ui.FavouritesActivity"
|
||||||
android:label="@string/favourites" />
|
android:label="@string/favourites" />
|
||||||
@@ -105,8 +110,7 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.widget.shelf.ShelfConfigActivity"
|
android:name="org.koitharu.kotatsu.widget.shelf.ShelfConfigActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/manga_shelf"
|
android:label="@string/manga_shelf">
|
||||||
android:theme="@style/Theme.Kotatsu.DialogWhenLarge">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@@ -124,18 +128,18 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.download.ui.DownloadsActivity"
|
android:name="org.koitharu.kotatsu.download.ui.DownloadsActivity"
|
||||||
android:label="@string/downloads"
|
android:label="@string/downloads"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop" />
|
||||||
android:theme="@style/Theme.Kotatsu.DialogWhenLarge" />
|
|
||||||
<activity android:name="org.koitharu.kotatsu.image.ui.ImageActivity" />
|
<activity android:name="org.koitharu.kotatsu.image.ui.ImageActivity" />
|
||||||
<activity
|
<activity android:name="org.koitharu.kotatsu.favourites.ui.categories.edit.FavouritesCategoryEditActivity" />
|
||||||
android:name="org.koitharu.kotatsu.favourites.ui.categories.edit.FavouritesCategoryEditActivity"
|
|
||||||
android:theme="@style/Theme.Kotatsu.DialogWhenLarge" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.sync.ui.SyncAuthActivity"
|
android:name="org.koitharu.kotatsu.sync.ui.SyncAuthActivity"
|
||||||
android:label="@string/sync" />
|
android:label="@string/sync" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity"
|
android:name="org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity"
|
||||||
android:label="@string/color_correction" />
|
android:label="@string/color_correction" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.shelf.ui.config.ShelfSettingsActivity"
|
||||||
|
android:label="@string/settings" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"
|
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"
|
||||||
@@ -244,6 +248,9 @@
|
|||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.webkit.WebView.MetricsOptOut"
|
android:name="android.webkit.WebView.MetricsOptOut"
|
||||||
android:value="true" />
|
android:value="true" />
|
||||||
|
<meta-data
|
||||||
|
android:name="com.samsung.android.icon_container.has_icon_container"
|
||||||
|
android:value="@bool/com_samsung_android_icon_container_has_icon_container"/>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import androidx.hilt.work.HiltWorkerFactory
|
|||||||
import androidx.room.InvalidationTracker
|
import androidx.room.InvalidationTracker
|
||||||
import androidx.work.Configuration
|
import androidx.work.Configuration
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.acra.ReportField
|
import org.acra.ReportField
|
||||||
@@ -25,6 +24,7 @@ import org.koitharu.kotatsu.local.data.PagesCache
|
|||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltAndroidApp
|
@HiltAndroidApp
|
||||||
class KotatsuApp : Application(), Configuration.Provider {
|
class KotatsuApp : Application(), Configuration.Provider {
|
||||||
@@ -72,6 +72,7 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
}
|
}
|
||||||
reportContent = listOf(
|
reportContent = listOf(
|
||||||
ReportField.PACKAGE_NAME,
|
ReportField.PACKAGE_NAME,
|
||||||
|
ReportField.INSTALLATION_ID,
|
||||||
ReportField.APP_VERSION_CODE,
|
ReportField.APP_VERSION_CODE,
|
||||||
ReportField.APP_VERSION_NAME,
|
ReportField.APP_VERSION_NAME,
|
||||||
ReportField.ANDROID_VERSION,
|
ReportField.ANDROID_VERSION,
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package org.koitharu.kotatsu.base.domain
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
fun interface ReversibleHandle {
|
fun interface ReversibleHandle {
|
||||||
|
|
||||||
@@ -11,8 +14,10 @@ fun interface ReversibleHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ReversibleHandle.reverseAsync() = processLifecycleScope.launch(Dispatchers.Default) {
|
fun ReversibleHandle.reverseAsync() = processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
reverse()
|
withContext(NonCancellable) {
|
||||||
|
reverse()
|
||||||
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
it.printStackTraceDebug()
|
it.printStackTraceDebug()
|
||||||
}
|
}
|
||||||
@@ -21,4 +26,4 @@ fun ReversibleHandle.reverseAsync() = processLifecycleScope.launch(Dispatchers.D
|
|||||||
operator fun ReversibleHandle.plus(other: ReversibleHandle) = ReversibleHandle {
|
operator fun ReversibleHandle.plus(other: ReversibleHandle) = ReversibleHandle {
|
||||||
this.reverse()
|
this.reverse()
|
||||||
other.reverse()
|
other.reverse()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.appcompat.widget.ActionBarContextView
|
import androidx.appcompat.widget.ActionBarContextView
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.app.ActivityCompat
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
@@ -21,7 +20,6 @@ import androidx.core.view.WindowInsetsCompat
|
|||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import dagger.hilt.android.EntryPointAccessors
|
import dagger.hilt.android.EntryPointAccessors
|
||||||
import javax.inject.Inject
|
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
||||||
@@ -31,6 +29,7 @@ import org.koitharu.kotatsu.base.ui.util.inject
|
|||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
abstract class BaseActivity<B : ViewBinding> :
|
abstract class BaseActivity<B : ViewBinding> :
|
||||||
AppCompatActivity(),
|
AppCompatActivity(),
|
||||||
@@ -54,7 +53,6 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
EntryPointAccessors.fromApplication(this, BaseActivityEntryPoint::class.java).inject(this)
|
EntryPointAccessors.fromApplication(this, BaseActivityEntryPoint::class.java).inject(this)
|
||||||
val isAmoled = settings.isAmoledTheme
|
val isAmoled = settings.isAmoledTheme
|
||||||
val isDynamic = settings.isDynamicTheme
|
val isDynamic = settings.isDynamicTheme
|
||||||
// TODO support DialogWhenLarge theme
|
|
||||||
when {
|
when {
|
||||||
isAmoled && isDynamic -> setTheme(R.style.Theme_Kotatsu_Monet_Amoled)
|
isAmoled && isDynamic -> setTheme(R.style.Theme_Kotatsu_Monet_Amoled)
|
||||||
isAmoled -> setTheme(R.style.Theme_Kotatsu_Amoled)
|
isAmoled -> setTheme(R.style.Theme_Kotatsu_Amoled)
|
||||||
@@ -92,7 +90,8 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) { // TODO remove
|
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) { // TODO remove
|
||||||
ActivityCompat.recreate(this)
|
// ActivityCompat.recreate(this)
|
||||||
|
TODO("Test error")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event)
|
return super.onKeyDown(keyCode, event)
|
||||||
@@ -134,6 +133,7 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
window.statusBarColor = getThemeColor(android.R.attr.statusBarColor)
|
window.statusBarColor = getThemeColor(android.R.attr.statusBarColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if ( // https://issuetracker.google.com/issues/139738913
|
if ( // https://issuetracker.google.com/issues/139738913
|
||||||
Build.VERSION.SDK_INT == Build.VERSION_CODES.Q &&
|
Build.VERSION.SDK_INT == Build.VERSION_CODES.Q &&
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import android.app.Service
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
abstract class CoroutineIntentService : BaseService() {
|
abstract class CoroutineIntentService : BaseService() {
|
||||||
|
|
||||||
@@ -21,11 +23,13 @@ abstract class CoroutineIntentService : BaseService() {
|
|||||||
return Service.START_REDELIVER_INTENT
|
return Service.START_REDELIVER_INTENT
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchCoroutine(intent: Intent?, startId: Int) = lifecycleScope.launch {
|
private fun launchCoroutine(intent: Intent?, startId: Int) = lifecycleScope.launch(errorHandler(startId)) {
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
try {
|
try {
|
||||||
withContext(dispatcher) {
|
if (intent != null) {
|
||||||
processIntent(intent)
|
withContext(dispatcher) {
|
||||||
|
processIntent(startId, intent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
stopSelf(startId)
|
stopSelf(startId)
|
||||||
@@ -33,5 +37,12 @@ abstract class CoroutineIntentService : BaseService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract suspend fun processIntent(intent: Intent?)
|
protected abstract suspend fun processIntent(startId: Int, intent: Intent)
|
||||||
|
|
||||||
|
protected abstract fun onError(startId: Int, error: Throwable)
|
||||||
|
|
||||||
|
private fun errorHandler(startId: Int) = CoroutineExceptionHandler { _, throwable ->
|
||||||
|
throwable.printStackTraceDebug()
|
||||||
|
onError(startId, throwable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.app.Application.ActivityLifecycleCallbacks
|
||||||
|
import android.os.Bundle
|
||||||
|
|
||||||
|
interface DefaultActivityLifecycleCallbacks : ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
|
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) = Unit
|
||||||
|
|
||||||
|
override fun onActivityStarted(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivityResumed(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivityPaused(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivityStopped(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit
|
||||||
|
|
||||||
|
override fun onActivityDestroyed(activity: Activity) = Unit
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import android.view.View.OnLongClickListener
|
|||||||
import com.hannesdorfmann.adapterdelegates4.dsl.AdapterDelegateViewBindingViewHolder
|
import com.hannesdorfmann.adapterdelegates4.dsl.AdapterDelegateViewBindingViewHolder
|
||||||
|
|
||||||
class AdapterDelegateClickListenerAdapter<I>(
|
class AdapterDelegateClickListenerAdapter<I>(
|
||||||
private val adapterDelegate: AdapterDelegateViewBindingViewHolder<I, *>,
|
private val adapterDelegate: AdapterDelegateViewBindingViewHolder<out I, *>,
|
||||||
private val clickListener: OnListItemClickListener<I>,
|
private val clickListener: OnListItemClickListener<I>,
|
||||||
) : OnClickListener, OnLongClickListener {
|
) : OnClickListener, OnLongClickListener {
|
||||||
|
|
||||||
@@ -17,4 +17,4 @@ class AdapterDelegateClickListenerAdapter<I>(
|
|||||||
override fun onLongClick(v: View): Boolean {
|
override fun onLongClick(v: View): Boolean {
|
||||||
return clickListener.onItemLongClick(adapterDelegate.item, v)
|
return clickListener.onItemLongClick(adapterDelegate.item, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,20 @@ package org.koitharu.kotatsu.base.ui.list
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.ArrayMap
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
|
import androidx.collection.ArrayMap
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleEventObserver
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.savedstate.SavedStateRegistry
|
import androidx.savedstate.SavedStateRegistry
|
||||||
import androidx.savedstate.SavedStateRegistryOwner
|
import androidx.savedstate.SavedStateRegistryOwner
|
||||||
import kotlin.coroutines.EmptyCoroutineContext
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
private const val PROVIDER_NAME = "selection_decoration_sectioned"
|
private const val PROVIDER_NAME = "selection_decoration_sectioned"
|
||||||
|
|
||||||
@@ -60,7 +60,19 @@ class SectionedSelectionController<T : Any>(
|
|||||||
startActionMode()
|
startActionMode()
|
||||||
notifySelectionChanged()
|
notifySelectionChanged()
|
||||||
}
|
}
|
||||||
recyclerView.addItemDecoration(decoration)
|
var shouldAddDecoration = true
|
||||||
|
for (i in (0 until recyclerView.itemDecorationCount).reversed()) {
|
||||||
|
val decor = recyclerView.getItemDecorationAt(i)
|
||||||
|
if (decor === decoration) {
|
||||||
|
shouldAddDecoration = false
|
||||||
|
break
|
||||||
|
} else if (decor.javaClass == decoration.javaClass) {
|
||||||
|
recyclerView.removeItemDecorationAt(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shouldAddDecoration) {
|
||||||
|
recyclerView.addItemDecoration(decoration)
|
||||||
|
}
|
||||||
if (pendingData?.isEmpty() == true) {
|
if (pendingData?.isEmpty() == true) {
|
||||||
pendingData = null
|
pendingData = null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class ScrollbarAnimator(
|
|||||||
.animate()
|
.animate()
|
||||||
.translationX(0f)
|
.translationX(0f)
|
||||||
.alpha(1f)
|
.alpha(1f)
|
||||||
|
.setListener(null)
|
||||||
.setDuration(animationDuration)
|
.setDuration(animationDuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.Application.ActivityLifecycleCallbacks
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import java.util.*
|
import org.koitharu.kotatsu.base.ui.DefaultActivityLifecycleCallbacks
|
||||||
|
import java.util.WeakHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ActivityRecreationHandle @Inject constructor() : ActivityLifecycleCallbacks {
|
class ActivityRecreationHandle @Inject constructor() : DefaultActivityLifecycleCallbacks {
|
||||||
|
|
||||||
private val activities = WeakHashMap<Activity, Unit>()
|
private val activities = WeakHashMap<Activity, Unit>()
|
||||||
|
|
||||||
@@ -16,16 +16,6 @@ class ActivityRecreationHandle @Inject constructor() : ActivityLifecycleCallback
|
|||||||
activities[activity] = Unit
|
activities[activity] = Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityStarted(activity: Activity) = Unit
|
|
||||||
|
|
||||||
override fun onActivityResumed(activity: Activity) = Unit
|
|
||||||
|
|
||||||
override fun onActivityPaused(activity: Activity) = Unit
|
|
||||||
|
|
||||||
override fun onActivityStopped(activity: Activity) = Unit
|
|
||||||
|
|
||||||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit
|
|
||||||
|
|
||||||
override fun onActivityDestroyed(activity: Activity) {
|
override fun onActivityDestroyed(activity: Activity) {
|
||||||
activities.remove(activity)
|
activities.remove(activity)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.recyclerview.widget.DiffUtil
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
|
import kotlin.jvm.internal.Intrinsics
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
@@ -12,7 +13,6 @@ import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
|||||||
import org.koitharu.kotatsu.list.ui.adapter.*
|
import org.koitharu.kotatsu.list.ui.adapter.*
|
||||||
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 kotlin.jvm.internal.Intrinsics
|
|
||||||
|
|
||||||
class BookmarksGroupAdapter(
|
class BookmarksGroupAdapter(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -34,11 +34,11 @@ class BookmarksGroupAdapter(
|
|||||||
selectionController = selectionController,
|
selectionController = selectionController,
|
||||||
bookmarkClickListener = bookmarkClickListener,
|
bookmarkClickListener = bookmarkClickListener,
|
||||||
groupClickListener = groupClickListener,
|
groupClickListener = groupClickListener,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
.addDelegate(loadingStateAD())
|
.addDelegate(loadingStateAD())
|
||||||
.addDelegate(loadingFooterAD())
|
.addDelegate(loadingFooterAD())
|
||||||
.addDelegate(emptyStateListAD(listener))
|
.addDelegate(emptyStateListAD(coil, listener))
|
||||||
.addDelegate(errorStateListAD(listener))
|
.addDelegate(errorStateListAD(listener))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,4 +64,4 @@ class BookmarksGroupAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ import dagger.hilt.InstallIn
|
|||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import dagger.multibindings.ElementsIntoSet
|
import dagger.multibindings.ElementsIntoSet
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import okhttp3.CookieJar
|
import okhttp3.CookieJar
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@@ -27,6 +25,7 @@ import org.koitharu.kotatsu.BuildConfig
|
|||||||
import org.koitharu.kotatsu.base.ui.util.ActivityRecreationHandle
|
import org.koitharu.kotatsu.base.ui.util.ActivityRecreationHandle
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.network.*
|
import org.koitharu.kotatsu.core.network.*
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
||||||
import org.koitharu.kotatsu.core.parser.MangaLoaderContextImpl
|
import org.koitharu.kotatsu.core.parser.MangaLoaderContextImpl
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
@@ -40,9 +39,13 @@ import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
|||||||
import org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider
|
import org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider
|
||||||
import org.koitharu.kotatsu.settings.backup.BackupObserver
|
import org.koitharu.kotatsu.settings.backup.BackupObserver
|
||||||
import org.koitharu.kotatsu.sync.domain.SyncController
|
import org.koitharu.kotatsu.sync.domain.SyncController
|
||||||
|
import org.koitharu.kotatsu.utils.IncognitoModeIndicator
|
||||||
|
import org.koitharu.kotatsu.utils.ext.connectivityManager
|
||||||
import org.koitharu.kotatsu.utils.ext.isLowRamDevice
|
import org.koitharu.kotatsu.utils.ext.isLowRamDevice
|
||||||
import org.koitharu.kotatsu.utils.image.CoilImageGetter
|
import org.koitharu.kotatsu.utils.image.CoilImageGetter
|
||||||
import org.koitharu.kotatsu.widget.WidgetUpdater
|
import org.koitharu.kotatsu.widget.WidgetUpdater
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
@@ -80,6 +83,12 @@ interface AppModule {
|
|||||||
}.build()
|
}.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideNetworkState(
|
||||||
|
@ApplicationContext context: Context
|
||||||
|
) = NetworkState(context.connectivityManager)
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideMangaDatabase(
|
fun provideMangaDatabase(
|
||||||
@@ -152,9 +161,11 @@ interface AppModule {
|
|||||||
fun provideActivityLifecycleCallbacks(
|
fun provideActivityLifecycleCallbacks(
|
||||||
appProtectHelper: AppProtectHelper,
|
appProtectHelper: AppProtectHelper,
|
||||||
activityRecreationHandle: ActivityRecreationHandle,
|
activityRecreationHandle: ActivityRecreationHandle,
|
||||||
|
incognitoModeIndicator: IncognitoModeIndicator,
|
||||||
): Set<@JvmSuppressWildcards Application.ActivityLifecycleCallbacks> = arraySetOf(
|
): Set<@JvmSuppressWildcards Application.ActivityLifecycleCallbacks> = arraySetOf(
|
||||||
appProtectHelper,
|
appProtectHelper,
|
||||||
activityRecreationHandle,
|
activityRecreationHandle,
|
||||||
|
incognitoModeIndicator,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package org.koitharu.kotatsu.core.backup
|
package org.koitharu.kotatsu.core.backup
|
||||||
|
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import javax.inject.Inject
|
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.parsers.util.json.JSONIterator
|
import org.koitharu.kotatsu.parsers.util.json.JSONIterator
|
||||||
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val PAGE_SIZE = 10
|
private const val PAGE_SIZE = 10
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ class BackupRepository @Inject constructor(private val db: MangaDatabase) {
|
|||||||
JsonDeserializer(it).toTagEntity()
|
JsonDeserializer(it).toTagEntity()
|
||||||
}
|
}
|
||||||
val history = JsonDeserializer(item).toHistoryEntity()
|
val history = JsonDeserializer(item).toHistoryEntity()
|
||||||
result += runCatching {
|
result += runCatchingCancellable {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
db.tagsDao.upsert(tags)
|
db.tagsDao.upsert(tags)
|
||||||
db.mangaDao.upsert(manga, tags)
|
db.mangaDao.upsert(manga, tags)
|
||||||
@@ -100,7 +101,7 @@ class BackupRepository @Inject constructor(private val db: MangaDatabase) {
|
|||||||
val result = CompositeResult()
|
val result = CompositeResult()
|
||||||
for (item in entry.data.JSONIterator()) {
|
for (item in entry.data.JSONIterator()) {
|
||||||
val category = JsonDeserializer(item).toFavouriteCategoryEntity()
|
val category = JsonDeserializer(item).toFavouriteCategoryEntity()
|
||||||
result += runCatching {
|
result += runCatchingCancellable {
|
||||||
db.favouriteCategoriesDao.upsert(category)
|
db.favouriteCategoriesDao.upsert(category)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,7 +117,7 @@ class BackupRepository @Inject constructor(private val db: MangaDatabase) {
|
|||||||
JsonDeserializer(it).toTagEntity()
|
JsonDeserializer(it).toTagEntity()
|
||||||
}
|
}
|
||||||
val favourite = JsonDeserializer(item).toFavouriteEntity()
|
val favourite = JsonDeserializer(item).toFavouriteEntity()
|
||||||
result += runCatching {
|
result += runCatchingCancellable {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
db.tagsDao.upsert(tags)
|
db.tagsDao.upsert(tags)
|
||||||
db.mangaDao.upsert(manga, tags)
|
db.mangaDao.upsert(manga, tags)
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ abstract class MangaDao {
|
|||||||
abstract suspend fun find(id: Long): MangaWithTags?
|
abstract suspend fun find(id: Long): MangaWithTags?
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM manga WHERE title LIKE :query OR alt_title LIKE :query LIMIT :limit")
|
@Query("SELECT * FROM manga WHERE (title LIKE :query OR alt_title LIKE :query) AND manga_id IN (SELECT manga_id FROM favourites UNION SELECT manga_id FROM history) LIMIT :limit")
|
||||||
abstract suspend fun searchByTitle(query: String, limit: Int): List<MangaWithTags>
|
abstract suspend fun searchByTitle(query: String, limit: Int): List<MangaWithTags>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM manga WHERE (title LIKE :query OR alt_title LIKE :query) AND source = :source LIMIT :limit")
|
@Query("SELECT * FROM manga WHERE (title LIKE :query OR alt_title LIKE :query) AND source = :source AND manga_id IN (SELECT manga_id FROM favourites UNION SELECT manga_id FROM history) LIMIT :limit")
|
||||||
abstract suspend fun searchByTitle(query: String, source: String, limit: Int): List<MangaWithTags>
|
abstract suspend fun searchByTitle(query: String, source: String, limit: Int): List<MangaWithTags>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
@@ -47,4 +47,4 @@ abstract class MangaDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.koitharu.kotatsu.utils.ext.longHashCode
|
|||||||
fun TagEntity.toMangaTag() = MangaTag(
|
fun TagEntity.toMangaTag() = MangaTag(
|
||||||
key = this.key,
|
key = this.key,
|
||||||
title = this.title.toTitleCase(),
|
title = this.title.toTitleCase(),
|
||||||
source = MangaSource(this.source) ?: MangaSource.DUMMY,
|
source = MangaSource(this.source),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Collection<TagEntity>.toMangaTags() = mapToSet(TagEntity::toMangaTag)
|
fun Collection<TagEntity>.toMangaTags() = mapToSet(TagEntity::toMangaTag)
|
||||||
@@ -28,7 +28,7 @@ fun MangaEntity.toManga(tags: Set<MangaTag>) = Manga(
|
|||||||
coverUrl = this.coverUrl,
|
coverUrl = this.coverUrl,
|
||||||
largeCoverUrl = this.largeCoverUrl,
|
largeCoverUrl = this.largeCoverUrl,
|
||||||
author = this.author,
|
author = this.author,
|
||||||
source = MangaSource(this.source) ?: MangaSource.DUMMY,
|
source = MangaSource(this.source),
|
||||||
tags = tags,
|
tags = tags,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions.resolve
|
package org.koitharu.kotatsu.core.exceptions.resolve
|
||||||
|
|
||||||
import android.util.ArrayMap
|
|
||||||
import androidx.activity.result.ActivityResultCallback
|
import androidx.activity.result.ActivityResultCallback
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.collection.ArrayMap
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
@@ -49,6 +49,7 @@ class ExceptionResolver private constructor(
|
|||||||
openInBrowser(e.url)
|
openInBrowser(e.url)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ class ExceptionResolver private constructor(
|
|||||||
cont.invokeOnCancellation {
|
cont.invokeOnCancellation {
|
||||||
continuations.remove(CloudFlareDialog.TAG, cont)
|
continuations.remove(CloudFlareDialog.TAG, cont)
|
||||||
fm.clearFragmentResultListener(CloudFlareDialog.TAG)
|
fm.clearFragmentResultListener(CloudFlareDialog.TAG)
|
||||||
dialog.dismiss()
|
dialog.dismissAllowingStateLoss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,4 +95,4 @@ class ExceptionResolver private constructor(
|
|||||||
|
|
||||||
fun canResolve(e: Throwable) = getResolveStringId(e) != 0
|
fun canResolve(e: Throwable) = getResolveStringId(e) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,6 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.io.ByteArrayInputStream
|
|
||||||
import java.io.InputStream
|
|
||||||
import java.security.MessageDigest
|
|
||||||
import java.security.cert.CertificateFactory
|
|
||||||
import java.security.cert.X509Certificate
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
@@ -24,6 +17,14 @@ import org.koitharu.kotatsu.parsers.util.json.mapJSONNotNull
|
|||||||
import org.koitharu.kotatsu.parsers.util.parseJsonArray
|
import org.koitharu.kotatsu.parsers.util.parseJsonArray
|
||||||
import org.koitharu.kotatsu.utils.ext.asArrayList
|
import org.koitharu.kotatsu.utils.ext.asArrayList
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.security.MessageDigest
|
||||||
|
import java.security.cert.CertificateFactory
|
||||||
|
import java.security.cert.X509Certificate
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
private const val CERT_SHA1 = "2C:19:C7:E8:07:61:2B:8E:94:51:1B:FD:72:67:07:64:5D:C2:58:AE"
|
private const val CERT_SHA1 = "2C:19:C7:E8:07:61:2B:8E:94:51:1B:FD:72:67:07:64:5D:C2:58:AE"
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ class AppUpdateRepository @Inject constructor(
|
|||||||
if (!isUpdateSupported()) {
|
if (!isUpdateSupported()) {
|
||||||
return@withContext null
|
return@withContext null
|
||||||
}
|
}
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
val currentVersion = VersionId(BuildConfig.VERSION_NAME)
|
val currentVersion = VersionId(BuildConfig.VERSION_NAME)
|
||||||
val available = getAvailableVersions().asArrayList()
|
val available = getAvailableVersions().asArrayList()
|
||||||
available.sortBy { it.versionId }
|
available.sortBy { it.versionId }
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
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
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
fun MangaSource.getLocaleTitle(): String? {
|
fun MangaSource.getLocaleTitle(): String? {
|
||||||
val lc = Locale(locale ?: return null)
|
val lc = Locale(locale ?: return null)
|
||||||
return lc.getDisplayLanguage(lc).toTitleCase(lc)
|
return lc.getDisplayLanguage(lc).toTitleCase(lc)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
fun MangaSource(name: String): MangaSource {
|
||||||
fun MangaSource(name: String): MangaSource? {
|
|
||||||
MangaSource.values().forEach {
|
MangaSource.values().forEach {
|
||||||
if (it.name == name) return it
|
if (it.name == name) return it
|
||||||
}
|
}
|
||||||
return null
|
return MangaSource.DUMMY
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ package org.koitharu.kotatsu.core.model.parcelable
|
|||||||
|
|
||||||
import android.os.Parcel
|
import android.os.Parcel
|
||||||
import androidx.core.os.ParcelCompat
|
import androidx.core.os.ParcelCompat
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.utils.ext.readParcelableCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.readSerializableCompat
|
||||||
|
|
||||||
fun Manga.writeToParcel(out: Parcel, flags: Int, withChapters: Boolean) {
|
fun Manga.writeToParcel(out: Parcel, flags: Int, withChapters: Boolean) {
|
||||||
out.writeLong(id)
|
out.writeLong(id)
|
||||||
@@ -37,11 +42,11 @@ fun Parcel.readManga() = Manga(
|
|||||||
coverUrl = requireNotNull(readString()),
|
coverUrl = requireNotNull(readString()),
|
||||||
largeCoverUrl = readString(),
|
largeCoverUrl = readString(),
|
||||||
description = readString(),
|
description = readString(),
|
||||||
tags = requireNotNull(readParcelable<ParcelableMangaTags>(ParcelableMangaTags::class.java.classLoader)).tags,
|
tags = requireNotNull(readParcelableCompat<ParcelableMangaTags>()).tags,
|
||||||
state = readSerializable() as MangaState?,
|
state = readSerializableCompat(),
|
||||||
author = readString(),
|
author = readString(),
|
||||||
chapters = readParcelable<ParcelableMangaChapters>(ParcelableMangaChapters::class.java.classLoader)?.chapters,
|
chapters = readParcelableCompat<ParcelableMangaChapters>()?.chapters,
|
||||||
source = readSerializable() as MangaSource,
|
source = checkNotNull(readSerializableCompat()),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun MangaPage.writeToParcel(out: Parcel) {
|
fun MangaPage.writeToParcel(out: Parcel) {
|
||||||
@@ -57,7 +62,7 @@ fun Parcel.readMangaPage() = MangaPage(
|
|||||||
url = requireNotNull(readString()),
|
url = requireNotNull(readString()),
|
||||||
referer = requireNotNull(readString()),
|
referer = requireNotNull(readString()),
|
||||||
preview = readString(),
|
preview = readString(),
|
||||||
source = readSerializable() as MangaSource,
|
source = checkNotNull(readSerializableCompat()),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun MangaChapter.writeToParcel(out: Parcel) {
|
fun MangaChapter.writeToParcel(out: Parcel) {
|
||||||
@@ -79,7 +84,7 @@ fun Parcel.readMangaChapter() = MangaChapter(
|
|||||||
scanlator = readString(),
|
scanlator = readString(),
|
||||||
uploadDate = readLong(),
|
uploadDate = readLong(),
|
||||||
branch = readString(),
|
branch = readString(),
|
||||||
source = readSerializable() as MangaSource,
|
source = checkNotNull(readSerializableCompat()),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun MangaTag.writeToParcel(out: Parcel) {
|
fun MangaTag.writeToParcel(out: Parcel) {
|
||||||
@@ -91,5 +96,5 @@ fun MangaTag.writeToParcel(out: Parcel) {
|
|||||||
fun Parcel.readMangaTag() = MangaTag(
|
fun Parcel.readMangaTag() = MangaTag(
|
||||||
title = requireNotNull(readString()),
|
title = requireNotNull(readString()),
|
||||||
key = requireNotNull(readString()),
|
key = requireNotNull(readString()),
|
||||||
source = readSerializable() as MangaSource,
|
source = checkNotNull(readSerializableCompat()),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import org.koitharu.kotatsu.parsers.model.Manga
|
|||||||
|
|
||||||
// Limits to avoid TransactionTooLargeException
|
// Limits to avoid TransactionTooLargeException
|
||||||
private const val MAX_SAFE_SIZE = 1024 * 512 // Assume that 512 kb is safe parcel size
|
private const val MAX_SAFE_SIZE = 1024 * 512 // Assume that 512 kb is safe parcel size
|
||||||
private const val MAX_SAFE_CHAPTERS_COUNT = 40 // this is 100% safe
|
private const val MAX_SAFE_CHAPTERS_COUNT = 32 // this is 100% safe
|
||||||
|
|
||||||
class ParcelableManga(
|
class ParcelableManga(
|
||||||
val manga: Manga,
|
val manga: Manga,
|
||||||
@@ -50,4 +50,4 @@ class ParcelableManga(
|
|||||||
return arrayOfNulls(size)
|
return arrayOfNulls(size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package org.koitharu.kotatsu.core.os
|
||||||
|
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.ConnectivityManager.NetworkCallback
|
||||||
|
import android.net.Network
|
||||||
|
import android.net.NetworkRequest
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import org.koitharu.kotatsu.utils.MediatorStateFlow
|
||||||
|
import org.koitharu.kotatsu.utils.ext.isNetworkAvailable
|
||||||
|
|
||||||
|
class NetworkState(
|
||||||
|
private val connectivityManager: ConnectivityManager,
|
||||||
|
) : MediatorStateFlow<Boolean>(connectivityManager.isNetworkAvailable) {
|
||||||
|
|
||||||
|
private val callback = NetworkCallbackImpl()
|
||||||
|
|
||||||
|
override fun onActive() {
|
||||||
|
invalidate()
|
||||||
|
val request = NetworkRequest.Builder().build()
|
||||||
|
connectivityManager.registerNetworkCallback(request, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onInactive() {
|
||||||
|
connectivityManager.unregisterNetworkCallback(callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun awaitForConnection() {
|
||||||
|
if (value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
first { it }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun invalidate() {
|
||||||
|
publishValue(connectivityManager.isNetworkAvailable)
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class NetworkCallbackImpl : NetworkCallback() {
|
||||||
|
|
||||||
|
override fun onAvailable(network: Network) = invalidate()
|
||||||
|
|
||||||
|
override fun onLost(network: Network) = invalidate()
|
||||||
|
|
||||||
|
override fun onUnavailable() = invalidate()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import android.app.ActivityManager
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.content.pm.ShortcutManager
|
import android.content.pm.ShortcutManager
|
||||||
import android.media.ThumbnailUtils
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Size
|
import android.util.Size
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
@@ -15,9 +14,9 @@ import androidx.core.graphics.drawable.IconCompat
|
|||||||
import androidx.room.InvalidationTracker
|
import androidx.room.InvalidationTracker
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
|
import coil.size.Precision
|
||||||
|
import coil.size.Scale
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -31,6 +30,9 @@ import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
|||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.utils.ext.requireBitmap
|
import org.koitharu.kotatsu.utils.ext.requireBitmap
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ShortcutsUpdater @Inject constructor(
|
class ShortcutsUpdater @Inject constructor(
|
||||||
@@ -91,7 +93,7 @@ class ShortcutsUpdater @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||||
private suspend fun updateShortcutsImpl() = runCatching {
|
private suspend fun updateShortcutsImpl() = runCatchingCancellable {
|
||||||
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
||||||
val shortcuts = historyRepository.getList(0, manager.maxShortcutCountPerActivity)
|
val shortcuts = historyRepository.getList(0, manager.maxShortcutCountPerActivity)
|
||||||
.filter { x -> x.title.isNotEmpty() }
|
.filter { x -> x.title.isNotEmpty() }
|
||||||
@@ -111,14 +113,15 @@ class ShortcutsUpdater @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun buildShortcutInfo(manga: Manga): ShortcutInfoCompat.Builder {
|
private suspend fun buildShortcutInfo(manga: Manga): ShortcutInfoCompat.Builder {
|
||||||
val icon = runCatching {
|
val icon = runCatchingCancellable {
|
||||||
val bmp = coil.execute(
|
coil.execute(
|
||||||
ImageRequest.Builder(context)
|
ImageRequest.Builder(context)
|
||||||
.data(manga.coverUrl)
|
.data(manga.coverUrl)
|
||||||
.size(iconSize.width, iconSize.height)
|
.size(iconSize.width, iconSize.height)
|
||||||
|
.precision(Precision.EXACT)
|
||||||
|
.scale(Scale.FILL)
|
||||||
.build(),
|
.build(),
|
||||||
).requireBitmap()
|
).requireBitmap()
|
||||||
ThumbnailUtils.extractThumbnail(bmp, iconSize.width, iconSize.height, 0)
|
|
||||||
}.fold(
|
}.fold(
|
||||||
onSuccess = { IconCompat.createWithAdaptiveBitmap(it) },
|
onSuccess = { IconCompat.createWithAdaptiveBitmap(it) },
|
||||||
onFailure = { IconCompat.createWithResource(context, R.drawable.ic_shortcut_default) },
|
onFailure = { IconCompat.createWithResource(context, R.drawable.ic_shortcut_default) },
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import coil.network.HttpException
|
|||||||
import coil.request.Options
|
import coil.request.Options
|
||||||
import coil.size.Size
|
import coil.size.Size
|
||||||
import coil.size.pxOrElse
|
import coil.size.pxOrElse
|
||||||
import java.net.HttpURLConnection
|
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
@@ -27,6 +26,7 @@ import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|||||||
import org.koitharu.kotatsu.local.data.CacheDir
|
import org.koitharu.kotatsu.local.data.CacheDir
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.util.await
|
import org.koitharu.kotatsu.parsers.util.await
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
|
||||||
private const val FALLBACK_SIZE = 9999 // largest icon
|
private const val FALLBACK_SIZE = 9999 // largest icon
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ class FaviconFetcher(
|
|||||||
|
|
||||||
override fun create(data: Uri, options: Options, imageLoader: ImageLoader): Fetcher? {
|
override fun create(data: Uri, options: Options, imageLoader: ImageLoader): Fetcher? {
|
||||||
return if (data.scheme == URI_SCHEME_FAVICON) {
|
return if (data.scheme == URI_SCHEME_FAVICON) {
|
||||||
val mangaSource = MangaSource(data.schemeSpecificPart) ?: return null
|
val mangaSource = MangaSource(data.schemeSpecificPart)
|
||||||
FaviconFetcher(okHttpClient, diskCache, mangaSource, options, mangaRepositoryFactory)
|
FaviconFetcher(okHttpClient, diskCache, mangaSource, options, mangaRepositoryFactory)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.prefs
|
|
||||||
|
|
||||||
enum class AppSection {
|
|
||||||
|
|
||||||
LOCAL, FAVOURITES, HISTORY, FEED, SUGGESTIONS
|
|
||||||
}
|
|
||||||
@@ -11,21 +11,24 @@ import androidx.core.content.edit
|
|||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.google.android.material.color.DynamicColors
|
import com.google.android.material.color.DynamicColors
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.io.File
|
|
||||||
import java.text.DateFormat
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.core.model.ZoomMode
|
import org.koitharu.kotatsu.core.model.ZoomMode
|
||||||
import org.koitharu.kotatsu.core.network.DoHProvider
|
import org.koitharu.kotatsu.core.network.DoHProvider
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
import org.koitharu.kotatsu.shelf.domain.ShelfSection
|
||||||
import org.koitharu.kotatsu.utils.ext.getEnumValue
|
import org.koitharu.kotatsu.utils.ext.getEnumValue
|
||||||
import org.koitharu.kotatsu.utils.ext.observe
|
import org.koitharu.kotatsu.utils.ext.observe
|
||||||
import org.koitharu.kotatsu.utils.ext.putEnumValue
|
import org.koitharu.kotatsu.utils.ext.putEnumValue
|
||||||
import org.koitharu.kotatsu.utils.ext.toUriOrNull
|
import org.koitharu.kotatsu.utils.ext.toUriOrNull
|
||||||
|
import java.io.File
|
||||||
|
import java.text.DateFormat
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Collections
|
||||||
|
import java.util.EnumSet
|
||||||
|
import java.util.Locale
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||||
@@ -42,14 +45,26 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val remoteMangaSources: Set<MangaSource>
|
val remoteMangaSources: Set<MangaSource>
|
||||||
get() = Collections.unmodifiableSet(remoteSources)
|
get() = Collections.unmodifiableSet(remoteSources)
|
||||||
|
|
||||||
|
var shelfSections: List<ShelfSection>
|
||||||
|
get() {
|
||||||
|
val raw = prefs.getString(KEY_SHELF_SECTIONS, null)
|
||||||
|
val values = enumValues<ShelfSection>()
|
||||||
|
if (raw.isNullOrEmpty()) {
|
||||||
|
return values.toList()
|
||||||
|
}
|
||||||
|
return raw.split('|')
|
||||||
|
.mapNotNull { values.getOrNull(it.toIntOrNull() ?: -1) }
|
||||||
|
.distinct()
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
val raw = value.joinToString("|") { it.ordinal.toString() }
|
||||||
|
prefs.edit { putString(KEY_SHELF_SECTIONS, raw) }
|
||||||
|
}
|
||||||
|
|
||||||
var listMode: ListMode
|
var listMode: ListMode
|
||||||
get() = prefs.getEnumValue(KEY_LIST_MODE, ListMode.GRID)
|
get() = prefs.getEnumValue(KEY_LIST_MODE, ListMode.GRID)
|
||||||
set(value) = prefs.edit { putEnumValue(KEY_LIST_MODE, value) }
|
set(value) = prefs.edit { putEnumValue(KEY_LIST_MODE, value) }
|
||||||
|
|
||||||
var defaultSection: AppSection
|
|
||||||
get() = prefs.getEnumValue(KEY_APP_SECTION, AppSection.HISTORY)
|
|
||||||
set(value) = prefs.edit { putEnumValue(KEY_APP_SECTION, value) }
|
|
||||||
|
|
||||||
val theme: Int
|
val theme: Int
|
||||||
get() = prefs.getString(KEY_THEME, null)?.toIntOrNull() ?: AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
get() = prefs.getString(KEY_THEME, null)?.toIntOrNull() ?: AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||||
|
|
||||||
@@ -206,6 +221,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val isReaderBarEnabled: Boolean
|
val isReaderBarEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_READER_BAR, true)
|
get() = prefs.getBoolean(KEY_READER_BAR, true)
|
||||||
|
|
||||||
|
val isReaderSliderEnabled: Boolean
|
||||||
|
get() = prefs.getBoolean(KEY_READER_SLIDER, true)
|
||||||
|
|
||||||
val dnsOverHttps: DoHProvider
|
val dnsOverHttps: DoHProvider
|
||||||
get() = prefs.getEnumValue(KEY_DOH, DoHProvider.NONE)
|
get() = prefs.getEnumValue(KEY_DOH, DoHProvider.NONE)
|
||||||
|
|
||||||
@@ -213,6 +231,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
get() = prefs.getEnumValue(KEY_LOCAL_LIST_ORDER, SortOrder.NEWEST)
|
get() = prefs.getEnumValue(KEY_LOCAL_LIST_ORDER, SortOrder.NEWEST)
|
||||||
set(value) = prefs.edit { putEnumValue(KEY_LOCAL_LIST_ORDER, value) }
|
set(value) = prefs.edit { putEnumValue(KEY_LOCAL_LIST_ORDER, value) }
|
||||||
|
|
||||||
|
val isWebtoonZoomEnable: Boolean
|
||||||
|
get() = prefs.getBoolean(KEY_WEBTOON_ZOOM, true)
|
||||||
|
|
||||||
fun isPagesPreloadAllowed(cm: ConnectivityManager): Boolean {
|
fun isPagesPreloadAllowed(cm: ConnectivityManager): Boolean {
|
||||||
return when (prefs.getString(KEY_PAGES_PRELOAD, null)?.toIntOrNull()) {
|
return when (prefs.getString(KEY_PAGES_PRELOAD, null)?.toIntOrNull()) {
|
||||||
NETWORK_ALWAYS -> true
|
NETWORK_ALWAYS -> true
|
||||||
@@ -328,9 +349,12 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val KEY_INCOGNITO_MODE = "incognito"
|
const val KEY_INCOGNITO_MODE = "incognito"
|
||||||
const val KEY_SYNC = "sync"
|
const val KEY_SYNC = "sync"
|
||||||
const val KEY_READER_BAR = "reader_bar"
|
const val KEY_READER_BAR = "reader_bar"
|
||||||
|
const val KEY_READER_SLIDER = "reader_slider"
|
||||||
const val KEY_SHORTCUTS = "dynamic_shortcuts"
|
const val KEY_SHORTCUTS = "dynamic_shortcuts"
|
||||||
const val KEY_READER_TAPS_LTR = "reader_taps_ltr"
|
const val KEY_READER_TAPS_LTR = "reader_taps_ltr"
|
||||||
const val KEY_LOCAL_LIST_ORDER = "local_order"
|
const val KEY_LOCAL_LIST_ORDER = "local_order"
|
||||||
|
const val KEY_WEBTOON_ZOOM = "webtoon_zoom"
|
||||||
|
const val KEY_SHELF_SECTIONS = "shelf_sections_2"
|
||||||
|
|
||||||
// About
|
// About
|
||||||
const val KEY_APP_UPDATE = "app_update"
|
const val KEY_APP_UPDATE = "app_update"
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class MangaErrorDialog : AlertDialogFragment<DialogMangaErrorBinding>() {
|
|||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
.setPositiveButton(R.string.report) { _, _ ->
|
.setPositiveButton(R.string.report) { _, _ ->
|
||||||
dismiss()
|
dismiss()
|
||||||
error.report(TAG)
|
error.report()
|
||||||
}.setTitle(R.string.error_occurred)
|
}.setTitle(R.string.error_occurred)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,4 +115,4 @@ class ZipOutput(
|
|||||||
closeEntry()
|
closeEntry()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import androidx.appcompat.view.ActionMode
|
|||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
|
||||||
import androidx.core.view.updatePadding
|
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
@@ -202,18 +200,4 @@ class ChaptersFragment :
|
|||||||
private fun onLoadingStateChanged(isLoading: Boolean) {
|
private fun onLoadingStateChanged(isLoading: Boolean) {
|
||||||
binding.progressBar.isVisible = isLoading
|
binding.progressBar.isVisible = isLoading
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findBottomSheetBehavior(): BottomSheetBehavior<*>? {
|
|
||||||
val v = view ?: return null
|
|
||||||
for (p in v.parents) {
|
|
||||||
val layoutParams = (p as? View)?.layoutParams
|
|
||||||
if (layoutParams is CoordinatorLayout.LayoutParams) {
|
|
||||||
val behavior = layoutParams.behavior
|
|
||||||
if (behavior is BottomSheetBehavior<*>) {
|
|
||||||
return behavior
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ class ChaptersMenuProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareMenu(menu: Menu) {
|
override fun onPrepareMenu(menu: Menu) {
|
||||||
menu.findItem(R.id.action_reversed).isChecked = viewModel.isChaptersReversed.value == true
|
menu.findItem(R.id.action_reversed)?.isChecked = viewModel.isChaptersReversed.value == true
|
||||||
menu.findItem(R.id.action_search).isVisible = viewModel.isChaptersEmpty.value == false
|
menu.findItem(R.id.action_search)?.isVisible = viewModel.isChaptersEmpty.value == false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemSelected(menuItem: MenuItem): Boolean = when (menuItem.itemId) {
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean = when (menuItem.itemId) {
|
||||||
|
|||||||
@@ -19,12 +19,10 @@ 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
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.google.android.material.badge.BadgeDrawable
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.snackbar.BaseTransientBottomBar
|
import com.google.android.material.snackbar.BaseTransientBottomBar
|
||||||
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 javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.domain.MangaIntent
|
import org.koitharu.kotatsu.base.domain.MangaIntent
|
||||||
@@ -37,12 +35,17 @@ import org.koitharu.kotatsu.core.ui.MangaErrorDialog
|
|||||||
import org.koitharu.kotatsu.databinding.ActivityDetailsBinding
|
import org.koitharu.kotatsu.databinding.ActivityDetailsBinding
|
||||||
import org.koitharu.kotatsu.details.ui.model.HistoryInfo
|
import org.koitharu.kotatsu.details.ui.model.HistoryInfo
|
||||||
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.bindBadge
|
|
||||||
import org.koitharu.kotatsu.main.ui.owners.NoModalBottomSheetOwner
|
import org.koitharu.kotatsu.main.ui.owners.NoModalBottomSheetOwner
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderState
|
import org.koitharu.kotatsu.reader.ui.ReaderState
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ViewBadge
|
||||||
|
import org.koitharu.kotatsu.utils.ext.assistedViewModels
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.isReportable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setNavigationBarTransparentCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DetailsActivity :
|
class DetailsActivity :
|
||||||
@@ -60,7 +63,7 @@ class DetailsActivity :
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var shortcutsUpdater: ShortcutsUpdater
|
lateinit var shortcutsUpdater: ShortcutsUpdater
|
||||||
|
|
||||||
private var badge: BadgeDrawable? = null
|
private lateinit var viewBadge: ViewBadge
|
||||||
|
|
||||||
private val viewModel: DetailsViewModel by assistedViewModels {
|
private val viewModel: DetailsViewModel by assistedViewModels {
|
||||||
viewModelFactory.create(MangaIntent(intent))
|
viewModelFactory.create(MangaIntent(intent))
|
||||||
@@ -83,6 +86,7 @@ class DetailsActivity :
|
|||||||
}
|
}
|
||||||
binding.buttonRead.setOnClickListener(this)
|
binding.buttonRead.setOnClickListener(this)
|
||||||
binding.buttonDropdown.setOnClickListener(this)
|
binding.buttonDropdown.setOnClickListener(this)
|
||||||
|
viewBadge = ViewBadge(binding.buttonRead, this)
|
||||||
|
|
||||||
chaptersMenuProvider = if (binding.layoutBottom != null) {
|
chaptersMenuProvider = if (binding.layoutBottom != null) {
|
||||||
val bsMediator = ChaptersBottomSheetMediator(checkNotNull(binding.layoutBottom))
|
val bsMediator = ChaptersBottomSheetMediator(checkNotNull(binding.layoutBottom))
|
||||||
@@ -151,6 +155,7 @@ class DetailsActivity :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.button_dropdown -> showBranchPopupMenu()
|
R.id.button_dropdown -> showBranchPopupMenu()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,10 +193,12 @@ class DetailsActivity :
|
|||||||
ExceptionResolver.canResolve(e) -> {
|
ExceptionResolver.canResolve(e) -> {
|
||||||
resolveError(e)
|
resolveError(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
manga == null -> {
|
manga == null -> {
|
||||||
Toast.makeText(this, e.getDisplayMessage(resources), Toast.LENGTH_LONG).show()
|
Toast.makeText(this, e.getDisplayMessage(resources), Toast.LENGTH_LONG).show()
|
||||||
finishAfterTransition()
|
finishAfterTransition()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
val snackbar = makeSnackbar(
|
val snackbar = makeSnackbar(
|
||||||
e.getDisplayMessage(resources),
|
e.getDisplayMessage(resources),
|
||||||
@@ -221,18 +228,18 @@ class DetailsActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onHistoryChanged(info: HistoryInfo?) {
|
private fun onHistoryChanged(info: HistoryInfo) {
|
||||||
with(binding.buttonRead) {
|
with(binding.buttonRead) {
|
||||||
if (info?.history != null) {
|
if (info.history != null) {
|
||||||
setText(R.string._continue)
|
setText(R.string._continue)
|
||||||
setIconResource(R.drawable.ic_play)
|
setIconResource(if (info.isIncognitoMode) R.drawable.ic_incognito else R.drawable.ic_play)
|
||||||
} else {
|
} else {
|
||||||
setText(R.string.read)
|
setText(R.string.read)
|
||||||
setIconResource(R.drawable.ic_read)
|
setIconResource(if (info.isIncognitoMode) R.drawable.ic_incognito else R.drawable.ic_play)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val text = when {
|
val text = when {
|
||||||
info == null -> getString(R.string.loading_)
|
!info.isValid -> getString(R.string.loading_)
|
||||||
info.currentChapter >= 0 -> getString(R.string.chapter_d_of_d, info.currentChapter + 1, info.totalChapters)
|
info.currentChapter >= 0 -> getString(R.string.chapter_d_of_d, info.currentChapter + 1, info.totalChapters)
|
||||||
info.totalChapters == 0 -> getString(R.string.no_chapters)
|
info.totalChapters == 0 -> getString(R.string.no_chapters)
|
||||||
else -> resources.getQuantityString(R.plurals.chapters, info.totalChapters, info.totalChapters)
|
else -> resources.getQuantityString(R.plurals.chapters, info.totalChapters, info.totalChapters)
|
||||||
@@ -242,7 +249,7 @@ class DetailsActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onNewChaptersChanged(newChapters: Int) {
|
private fun onNewChaptersChanged(newChapters: Int) {
|
||||||
badge = binding.buttonRead.bindBadge(badge, newChapters)
|
viewBadge.counter = newChapters
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showChapterMissingDialog(chapterId: Long) {
|
fun showChapterMissingDialog(chapterId: Long) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import coil.request.ImageRequest
|
|||||||
import coil.util.CoilUtils
|
import coil.util.CoilUtils
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BaseFragment
|
import org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
@@ -27,9 +26,9 @@ import org.koitharu.kotatsu.base.ui.list.decor.SpacingItemDecoration
|
|||||||
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.bookmarks.ui.adapter.BookmarksAdapter
|
import org.koitharu.kotatsu.bookmarks.ui.adapter.BookmarksAdapter
|
||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
|
||||||
import org.koitharu.kotatsu.databinding.FragmentDetailsBinding
|
import org.koitharu.kotatsu.databinding.FragmentDetailsBinding
|
||||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
||||||
|
import org.koitharu.kotatsu.details.ui.model.HistoryInfo
|
||||||
import org.koitharu.kotatsu.details.ui.scrobbling.ScrobblingItemDecoration
|
import org.koitharu.kotatsu.details.ui.scrobbling.ScrobblingItemDecoration
|
||||||
import org.koitharu.kotatsu.details.ui.scrobbling.ScrollingInfoAdapter
|
import org.koitharu.kotatsu.details.ui.scrobbling.ScrollingInfoAdapter
|
||||||
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
||||||
@@ -45,8 +44,20 @@ import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingInfo
|
|||||||
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
||||||
import org.koitharu.kotatsu.search.ui.SearchActivity
|
import org.koitharu.kotatsu.search.ui.SearchActivity
|
||||||
import org.koitharu.kotatsu.utils.FileSize
|
import org.koitharu.kotatsu.utils.FileSize
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.computeSize
|
||||||
|
import org.koitharu.kotatsu.utils.ext.crossfade
|
||||||
|
import org.koitharu.kotatsu.utils.ext.drawableTop
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.ifNullOrEmpty
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureHeight
|
||||||
|
import org.koitharu.kotatsu.utils.ext.referer
|
||||||
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
||||||
|
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||||
|
import org.koitharu.kotatsu.utils.ext.toFileOrNull
|
||||||
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||||
import org.koitharu.kotatsu.utils.image.CoverSizeResolver
|
import org.koitharu.kotatsu.utils.image.CoverSizeResolver
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DetailsFragment :
|
class DetailsFragment :
|
||||||
@@ -75,7 +86,7 @@ class DetailsFragment :
|
|||||||
binding.chipsTags.onChipClickListener = this
|
binding.chipsTags.onChipClickListener = this
|
||||||
viewModel.manga.observe(viewLifecycleOwner, ::onMangaUpdated)
|
viewModel.manga.observe(viewLifecycleOwner, ::onMangaUpdated)
|
||||||
viewModel.isLoading.observe(viewLifecycleOwner, ::onLoadingStateChanged)
|
viewModel.isLoading.observe(viewLifecycleOwner, ::onLoadingStateChanged)
|
||||||
viewModel.readingHistory.observe(viewLifecycleOwner, ::onHistoryChanged)
|
viewModel.historyInfo.observe(viewLifecycleOwner, ::onHistoryChanged)
|
||||||
viewModel.bookmarks.observe(viewLifecycleOwner, ::onBookmarksChanged)
|
viewModel.bookmarks.observe(viewLifecycleOwner, ::onBookmarksChanged)
|
||||||
viewModel.scrobblingInfo.observe(viewLifecycleOwner, ::onScrobblingInfoChanged)
|
viewModel.scrobblingInfo.observe(viewLifecycleOwner, ::onScrobblingInfoChanged)
|
||||||
viewModel.description.observe(viewLifecycleOwner, ::onDescriptionChanged)
|
viewModel.description.observe(viewLifecycleOwner, ::onDescriptionChanged)
|
||||||
@@ -123,12 +134,14 @@ class DetailsFragment :
|
|||||||
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_state_finished)
|
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_state_finished)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MangaState.ONGOING -> {
|
MangaState.ONGOING -> {
|
||||||
infoLayout.textViewState.apply {
|
infoLayout.textViewState.apply {
|
||||||
textAndVisible = resources.getString(R.string.state_ongoing)
|
textAndVisible = resources.getString(R.string.state_ongoing)
|
||||||
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_state_ongoing)
|
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_state_ongoing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> infoLayout.textViewState.isVisible = false
|
else -> infoLayout.textViewState.isVisible = false
|
||||||
}
|
}
|
||||||
if (manga.source == MangaSource.LOCAL) {
|
if (manga.source == MangaSource.LOCAL) {
|
||||||
@@ -178,8 +191,8 @@ class DetailsFragment :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onHistoryChanged(history: MangaHistory?) {
|
private fun onHistoryChanged(history: HistoryInfo) {
|
||||||
binding.progressView.setPercent(history?.percent ?: PROGRESS_NONE, animate = true)
|
binding.progressView.setPercent(history.history?.percent ?: PROGRESS_NONE, animate = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onLoadingStateChanged(isLoading: Boolean) {
|
private fun onLoadingStateChanged(isLoading: Boolean) {
|
||||||
@@ -229,6 +242,7 @@ class DetailsFragment :
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.textView_source -> {
|
R.id.textView_source -> {
|
||||||
startActivity(
|
startActivity(
|
||||||
MangaListActivity.newIntent(
|
MangaListActivity.newIntent(
|
||||||
@@ -237,6 +251,7 @@ class DetailsFragment :
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.imageView_cover -> {
|
R.id.imageView_cover -> {
|
||||||
startActivity(
|
startActivity(
|
||||||
ImageActivity.newIntent(v.context, manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }),
|
ImageActivity.newIntent(v.context, manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }),
|
||||||
@@ -249,7 +264,7 @@ class DetailsFragment :
|
|||||||
override fun onLongClick(v: View): Boolean {
|
override fun onLongClick(v: View): Boolean {
|
||||||
when (v.id) {
|
when (v.id) {
|
||||||
R.id.button_read -> {
|
R.id.button_read -> {
|
||||||
if (viewModel.readingHistory.value == null) {
|
if (viewModel.historyInfo.value?.history == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val menu = PopupMenu(v.context, v)
|
val menu = PopupMenu(v.context, v)
|
||||||
@@ -271,12 +286,14 @@ class DetailsFragment :
|
|||||||
)
|
)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu.show()
|
menu.show()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,18 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import java.io.IOException
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||||
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.flow.transformLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.plus
|
import kotlinx.coroutines.plus
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
@@ -45,6 +53,8 @@ import org.koitharu.kotatsu.utils.SingleLiveEvent
|
|||||||
import org.koitharu.kotatsu.utils.asFlowLiveData
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class DetailsViewModel @AssistedInject constructor(
|
class DetailsViewModel @AssistedInject constructor(
|
||||||
@Assisted intent: MangaIntent,
|
@Assisted intent: MangaIntent,
|
||||||
@@ -90,17 +100,18 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
val manga = delegate.manga.filterNotNull().asLiveData(viewModelScope.coroutineContext)
|
val manga = delegate.manga.filterNotNull().asLiveData(viewModelScope.coroutineContext)
|
||||||
val favouriteCategories = favourite.asLiveData(viewModelScope.coroutineContext)
|
val favouriteCategories = favourite.asLiveData(viewModelScope.coroutineContext)
|
||||||
val newChaptersCount = newChapters.asLiveData(viewModelScope.coroutineContext)
|
val newChaptersCount = newChapters.asLiveData(viewModelScope.coroutineContext)
|
||||||
|
|
||||||
@Deprecated("")
|
|
||||||
val readingHistory = history.asLiveData(viewModelScope.coroutineContext)
|
|
||||||
val isChaptersReversed = chaptersReversed.asLiveData(viewModelScope.coroutineContext)
|
val isChaptersReversed = chaptersReversed.asLiveData(viewModelScope.coroutineContext)
|
||||||
|
|
||||||
val historyInfo = combine(
|
val historyInfo: LiveData<HistoryInfo> = combine(
|
||||||
delegate.manga,
|
delegate.manga,
|
||||||
history,
|
history,
|
||||||
) { m, h ->
|
settings.observeAsFlow(AppSettings.KEY_INCOGNITO_MODE) { isIncognitoModeEnabled },
|
||||||
HistoryInfo(m, h)
|
) { m, h, im ->
|
||||||
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, null)
|
HistoryInfo(m, h, im)
|
||||||
|
}.asFlowLiveData(
|
||||||
|
context = viewModelScope.coroutineContext + Dispatchers.Default,
|
||||||
|
defaultValue = HistoryInfo(null, null, false),
|
||||||
|
)
|
||||||
|
|
||||||
val bookmarks = delegate.manga.flatMapLatest {
|
val bookmarks = delegate.manga.flatMapLatest {
|
||||||
if (it != null) bookmarksRepository.observeBookmarks(it) else flowOf(emptyList())
|
if (it != null) bookmarksRepository.observeBookmarks(it) else flowOf(emptyList())
|
||||||
@@ -189,7 +200,7 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
checkNotNull(manga) { "Cannot find saved manga for ${m.title}" }
|
checkNotNull(manga) { "Cannot find saved manga for ${m.title}" }
|
||||||
val original = localMangaRepository.getRemoteManga(manga)
|
val original = localMangaRepository.getRemoteManga(manga)
|
||||||
localMangaRepository.delete(manga) || throw IOException("Unable to delete file")
|
localMangaRepository.delete(manga) || throw IOException("Unable to delete file")
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
historyRepository.deleteOrSwap(manga, original)
|
historyRepository.deleteOrSwap(manga, original)
|
||||||
}
|
}
|
||||||
onMangaRemoved.postCall(manga)
|
onMangaRemoved.postCall(manga)
|
||||||
@@ -228,7 +239,7 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
reload()
|
reload()
|
||||||
} else {
|
} else {
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
localMangaRepository.getDetails(downloadedManga)
|
localMangaRepository.getDetails(downloadedManga)
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
delegate.relatedManga.value = it
|
delegate.relatedManga.value = it
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ 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.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
class MangaDetailsDelegate(
|
class MangaDetailsDelegate(
|
||||||
private val intent: MangaIntent,
|
private val intent: MangaIntent,
|
||||||
@@ -45,9 +46,9 @@ class MangaDetailsDelegate(
|
|||||||
val hist = historyRepository.getOne(manga)
|
val hist = historyRepository.getOne(manga)
|
||||||
selectedBranch.value = manga.getPreferredBranch(hist)
|
selectedBranch.value = manga.getPreferredBranch(hist)
|
||||||
mangaData.value = manga
|
mangaData.value = manga
|
||||||
relatedManga.value = runCatching {
|
relatedManga.value = runCatchingCancellable {
|
||||||
if (manga.source == MangaSource.LOCAL) {
|
if (manga.source == MangaSource.LOCAL) {
|
||||||
val m = localMangaRepository.getRemoteManga(manga) ?: return@runCatching null
|
val m = localMangaRepository.getRemoteManga(manga) ?: return@runCatchingCancellable null
|
||||||
mangaRepositoryFactory.create(m.source).getDetails(m)
|
mangaRepositoryFactory.create(m.source).getDetails(m)
|
||||||
} else {
|
} else {
|
||||||
localMangaRepository.findSavedManga(manga)
|
localMangaRepository.findSavedManga(manga)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ fun chapterListItemAD(
|
|||||||
when (item.status) {
|
when (item.status) {
|
||||||
FLAG_UNREAD -> {
|
FLAG_UNREAD -> {
|
||||||
binding.textViewNumber.setBackgroundResource(R.drawable.bg_badge_default)
|
binding.textViewNumber.setBackgroundResource(R.drawable.bg_badge_default)
|
||||||
binding.textViewNumber.setTextColor(context.getThemeColor(android.R.attr.textColorSecondaryInverse))
|
binding.textViewNumber.setTextColor(context.getThemeColor(com.google.android.material.R.attr.colorOnTertiary))
|
||||||
}
|
}
|
||||||
FLAG_CURRENT -> {
|
FLAG_CURRENT -> {
|
||||||
binding.textViewNumber.setBackgroundResource(R.drawable.bg_badge_accent)
|
binding.textViewNumber.setBackgroundResource(R.drawable.bg_badge_accent)
|
||||||
@@ -53,4 +53,4 @@ fun chapterListItemAD(
|
|||||||
binding.imageViewDownloaded.isVisible = item.hasFlag(FLAG_DOWNLOADED)
|
binding.imageViewDownloaded.isVisible = item.hasFlag(FLAG_DOWNLOADED)
|
||||||
binding.imageViewNew.isVisible = item.hasFlag(FLAG_NEW)
|
binding.imageViewNew.isVisible = item.hasFlag(FLAG_NEW)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,12 @@ class HistoryInfo(
|
|||||||
val totalChapters: Int,
|
val totalChapters: Int,
|
||||||
val currentChapter: Int,
|
val currentChapter: Int,
|
||||||
val history: MangaHistory?,
|
val history: MangaHistory?,
|
||||||
|
val isIncognitoMode: Boolean,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
val isValid: Boolean
|
||||||
|
get() = totalChapters >= 0
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (javaClass != other?.javaClass) return false
|
if (javaClass != other?.javaClass) return false
|
||||||
@@ -18,6 +22,7 @@ class HistoryInfo(
|
|||||||
if (totalChapters != other.totalChapters) return false
|
if (totalChapters != other.totalChapters) return false
|
||||||
if (currentChapter != other.currentChapter) return false
|
if (currentChapter != other.currentChapter) return false
|
||||||
if (history != other.history) return false
|
if (history != other.history) return false
|
||||||
|
if (isIncognitoMode != other.isIncognitoMode) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -26,20 +31,21 @@ class HistoryInfo(
|
|||||||
var result = totalChapters
|
var result = totalChapters
|
||||||
result = 31 * result + currentChapter
|
result = 31 * result + currentChapter
|
||||||
result = 31 * result + (history?.hashCode() ?: 0)
|
result = 31 * result + (history?.hashCode() ?: 0)
|
||||||
|
result = 31 * result + isIncognitoMode.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
fun HistoryInfo(manga: Manga?, history: MangaHistory?, isIncognitoMode: Boolean): HistoryInfo {
|
||||||
fun HistoryInfo(manga: Manga?, history: MangaHistory?): HistoryInfo? {
|
val chapters = manga?.chapters
|
||||||
val chapters = manga?.chapters ?: return null
|
|
||||||
return HistoryInfo(
|
return HistoryInfo(
|
||||||
totalChapters = chapters.size,
|
totalChapters = chapters?.size ?: -1,
|
||||||
currentChapter = if (history != null) {
|
currentChapter = if (history != null && !chapters.isNullOrEmpty()) {
|
||||||
chapters.indexOfFirst { it.id == history.chapterId }
|
chapters.indexOfFirst { it.id == history.chapterId }
|
||||||
} else {
|
} else {
|
||||||
-1
|
-1
|
||||||
},
|
},
|
||||||
history = history,
|
history = history,
|
||||||
|
isIncognitoMode = isIncognitoMode,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,17 @@ import dagger.assisted.Assisted
|
|||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.io.File
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.NonCancellable
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.sync.Semaphore
|
import kotlinx.coroutines.sync.Semaphore
|
||||||
import kotlinx.coroutines.sync.withPermit
|
import kotlinx.coroutines.sync.withPermit
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.internal.closeQuietly
|
import okhttp3.internal.closeQuietly
|
||||||
@@ -29,10 +35,13 @@ import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
|||||||
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
|
||||||
import org.koitharu.kotatsu.parsers.util.await
|
import org.koitharu.kotatsu.parsers.util.await
|
||||||
|
import org.koitharu.kotatsu.utils.ext.copyToSuspending
|
||||||
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.referer
|
import org.koitharu.kotatsu.utils.ext.referer
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
import org.koitharu.kotatsu.utils.progress.PausingProgressJob
|
import org.koitharu.kotatsu.utils.progress.PausingProgressJob
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
private const val MAX_FAILSAFE_ATTEMPTS = 2
|
private const val MAX_FAILSAFE_ATTEMPTS = 2
|
||||||
private const val DOWNLOAD_ERROR_DELAY = 500L
|
private const val DOWNLOAD_ERROR_DELAY = 500L
|
||||||
@@ -155,7 +164,7 @@ class DownloadManager @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
outState.value = DownloadState.PostProcessing(startId, data, cover)
|
outState.value = DownloadState.PostProcessing(startId, data, cover)
|
||||||
output.mergeWithExisting()
|
output.mergeWithExisting()
|
||||||
output.finalize()
|
output.finish()
|
||||||
val localManga = localMangaRepository.getFromFile(output.file)
|
val localManga = localMangaRepository.getFromFile(output.file)
|
||||||
outState.value = DownloadState.Done(startId, data, cover, localManga)
|
outState.value = DownloadState.Done(startId, data, cover, localManga)
|
||||||
} catch (e: CancellationException) {
|
} catch (e: CancellationException) {
|
||||||
@@ -210,10 +219,8 @@ class DownloadManager @AssistedInject constructor(
|
|||||||
val call = okHttp.newCall(request)
|
val call = okHttp.newCall(request)
|
||||||
val file = File(destination, tempFileName)
|
val file = File(destination, tempFileName)
|
||||||
val response = call.clone().await()
|
val response = call.clone().await()
|
||||||
runInterruptible(Dispatchers.IO) {
|
file.outputStream().use { out ->
|
||||||
file.outputStream().use { out ->
|
checkNotNull(response.body).byteStream().copyToSuspending(out)
|
||||||
checkNotNull(response.body).byteStream().copyTo(out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
@@ -231,7 +238,7 @@ class DownloadManager @AssistedInject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadCover(manga: Manga) = runCatching {
|
private suspend fun loadCover(manga: Manga) = runCatchingCancellable {
|
||||||
imageLoader.execute(
|
imageLoader.execute(
|
||||||
ImageRequest.Builder(context)
|
ImageRequest.Builder(context)
|
||||||
.data(manga.coverUrl)
|
.data(manga.coverUrl)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class DownloadsActivity : BaseActivity<ActivityDownloadsBinding>() {
|
|||||||
setContentView(ActivityDownloadsBinding.inflate(layoutInflater))
|
setContentView(ActivityDownloadsBinding.inflate(layoutInflater))
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
val adapter = DownloadsAdapter(lifecycleScope, coil)
|
val adapter = DownloadsAdapter(lifecycleScope, coil)
|
||||||
val spacing = resources.getDimensionPixelOffset(R.dimen.grid_spacing)
|
val spacing = resources.getDimensionPixelOffset(R.dimen.list_spacing)
|
||||||
binding.recyclerView.addItemDecoration(SpacingItemDecoration(spacing))
|
binding.recyclerView.addItemDecoration(SpacingItemDecoration(spacing))
|
||||||
binding.recyclerView.setHasFixedSize(true)
|
binding.recyclerView.setHasFixedSize(true)
|
||||||
binding.recyclerView.adapter = adapter
|
binding.recyclerView.adapter = adapter
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import java.util.concurrent.TimeUnit
|
import kotlinx.coroutines.flow.Flow
|
||||||
import javax.inject.Inject
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlin.collections.set
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.flow.transformWhile
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
@@ -28,10 +30,14 @@ import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
|||||||
import org.koitharu.kotatsu.download.domain.DownloadManager
|
import org.koitharu.kotatsu.download.domain.DownloadManager
|
||||||
import org.koitharu.kotatsu.download.domain.DownloadState
|
import org.koitharu.kotatsu.download.domain.DownloadState
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
import org.koitharu.kotatsu.utils.ext.throttle
|
import org.koitharu.kotatsu.utils.ext.throttle
|
||||||
import org.koitharu.kotatsu.utils.progress.PausingProgressJob
|
import org.koitharu.kotatsu.utils.progress.PausingProgressJob
|
||||||
import org.koitharu.kotatsu.utils.progress.ProgressJob
|
import org.koitharu.kotatsu.utils.progress.ProgressJob
|
||||||
import org.koitharu.kotatsu.utils.progress.TimeLeftEstimator
|
import org.koitharu.kotatsu.utils.progress.TimeLeftEstimator
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.collections.set
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DownloadService : BaseService() {
|
class DownloadService : BaseService() {
|
||||||
@@ -65,7 +71,7 @@ class DownloadService : BaseService() {
|
|||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
val manga = intent?.getParcelableExtra<ParcelableManga>(EXTRA_MANGA)?.manga
|
val manga = intent?.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga
|
||||||
val chapters = intent?.getLongArrayExtra(EXTRA_CHAPTERS_IDS)
|
val chapters = intent?.getLongArrayExtra(EXTRA_CHAPTERS_IDS)
|
||||||
return if (manga != null) {
|
return if (manga != null) {
|
||||||
jobs[startId] = downloadManga(startId, manga, chapters)
|
jobs[startId] = downloadManga(startId, manga, chapters)
|
||||||
@@ -84,7 +90,9 @@ class DownloadService : BaseService() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
unregisterReceiver(controlReceiver)
|
unregisterReceiver(controlReceiver)
|
||||||
wakeLock.release()
|
if (wakeLock.isHeld) {
|
||||||
|
wakeLock.release()
|
||||||
|
}
|
||||||
isRunning = false
|
isRunning = false
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
@@ -168,6 +176,7 @@ class DownloadService : BaseService() {
|
|||||||
val cancelId = intent.getIntExtra(EXTRA_CANCEL_ID, 0)
|
val cancelId = intent.getIntExtra(EXTRA_CANCEL_ID, 0)
|
||||||
jobs[cancelId]?.cancel()
|
jobs[cancelId]?.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
ACTION_DOWNLOAD_RESUME -> {
|
ACTION_DOWNLOAD_RESUME -> {
|
||||||
val cancelId = intent.getIntExtra(EXTRA_CANCEL_ID, 0)
|
val cancelId = intent.getIntExtra(EXTRA_CANCEL_ID, 0)
|
||||||
jobs[cancelId]?.resume()
|
jobs[cancelId]?.resume()
|
||||||
@@ -254,7 +263,7 @@ class DownloadService : BaseService() {
|
|||||||
|
|
||||||
fun getDownloadedManga(intent: Intent?): Manga? {
|
fun getDownloadedManga(intent: Intent?): Manga? {
|
||||||
if (intent?.action == ACTION_DOWNLOAD_COMPLETE) {
|
if (intent?.action == ACTION_DOWNLOAD_COMPLETE) {
|
||||||
return intent.getParcelableExtra<ParcelableManga>(EXTRA_MANGA)?.manga
|
return intent.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package org.koitharu.kotatsu.explore.ui
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.widget.PopupMenu
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
@@ -11,11 +13,12 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
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 javax.inject.Inject
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.domain.reverseAsync
|
||||||
import org.koitharu.kotatsu.base.ui.BaseFragment
|
import org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
||||||
import org.koitharu.kotatsu.bookmarks.ui.BookmarksActivity
|
import org.koitharu.kotatsu.bookmarks.ui.BookmarksActivity
|
||||||
import org.koitharu.kotatsu.databinding.FragmentExploreBinding
|
import org.koitharu.kotatsu.databinding.FragmentExploreBinding
|
||||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
@@ -31,6 +34,7 @@ import org.koitharu.kotatsu.search.ui.MangaListActivity
|
|||||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||||
import org.koitharu.kotatsu.suggestions.ui.SuggestionsActivity
|
import org.koitharu.kotatsu.suggestions.ui.SuggestionsActivity
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ExploreFragment :
|
class ExploreFragment :
|
||||||
@@ -67,6 +71,7 @@ class ExploreFragment :
|
|||||||
}
|
}
|
||||||
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
||||||
viewModel.onOpenManga.observe(viewLifecycleOwner, ::onOpenManga)
|
viewModel.onOpenManga.observe(viewLifecycleOwner, ::onOpenManga)
|
||||||
|
viewModel.onActionDone.observe(viewLifecycleOwner, ::onActionDone)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -95,6 +100,7 @@ class ExploreFragment :
|
|||||||
viewModel.openRandom()
|
viewModel.openRandom()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return
|
else -> return
|
||||||
}
|
}
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
@@ -105,6 +111,14 @@ class ExploreFragment :
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onItemLongClick(item: ExploreItem.Source, view: View): Boolean {
|
||||||
|
val menu = PopupMenu(view.context, view)
|
||||||
|
menu.inflate(R.menu.popup_source)
|
||||||
|
menu.setOnMenuItemClickListener(SourceMenuListener(item))
|
||||||
|
menu.show()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRetryClick(error: Throwable) = Unit
|
override fun onRetryClick(error: Throwable) = Unit
|
||||||
|
|
||||||
override fun onEmptyActionClick() = onManageClick(requireView())
|
override fun onEmptyActionClick() = onManageClick(requireView())
|
||||||
@@ -124,6 +138,37 @@ class ExploreFragment :
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun onActionDone(action: ReversibleAction) {
|
||||||
|
val handle = action.handle
|
||||||
|
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
||||||
|
val snackbar = Snackbar.make(binding.recyclerView, action.stringResId, length)
|
||||||
|
if (handle != null) {
|
||||||
|
snackbar.setAction(R.string.undo) { handle.reverseAsync() }
|
||||||
|
}
|
||||||
|
snackbar.anchorView = (activity as? BottomNavOwner)?.bottomNav
|
||||||
|
snackbar.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class SourceMenuListener(
|
||||||
|
private val sourceItem: ExploreItem.Source,
|
||||||
|
) : PopupMenu.OnMenuItemClickListener {
|
||||||
|
|
||||||
|
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||||
|
when (item.itemId) {
|
||||||
|
R.id.action_settings -> {
|
||||||
|
startActivity(SettingsActivity.newSourceSettingsIntent(requireContext(), sourceItem.source))
|
||||||
|
}
|
||||||
|
|
||||||
|
R.id.action_hide -> {
|
||||||
|
viewModel.hideSource(sourceItem.source)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newInstance() = ExploreFragment()
|
fun newInstance() = ExploreFragment()
|
||||||
|
|||||||
@@ -4,11 +4,17 @@ import androidx.lifecycle.LiveData
|
|||||||
import androidx.lifecycle.asFlow
|
import androidx.lifecycle.asFlow
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.onStart
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
||||||
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.explore.domain.ExploreRepository
|
import org.koitharu.kotatsu.explore.domain.ExploreRepository
|
||||||
import org.koitharu.kotatsu.explore.ui.model.ExploreItem
|
import org.koitharu.kotatsu.explore.ui.model.ExploreItem
|
||||||
@@ -16,6 +22,7 @@ import org.koitharu.kotatsu.parsers.model.Manga
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class ExploreViewModel @Inject constructor(
|
class ExploreViewModel @Inject constructor(
|
||||||
@@ -24,6 +31,7 @@ class ExploreViewModel @Inject constructor(
|
|||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
|
|
||||||
val onOpenManga = SingleLiveEvent<Manga>()
|
val onOpenManga = SingleLiveEvent<Manga>()
|
||||||
|
val onActionDone = SingleLiveEvent<ReversibleAction>()
|
||||||
|
|
||||||
val content: LiveData<List<ExploreItem>> = isLoading.asFlow().flatMapLatest { loading ->
|
val content: LiveData<List<ExploreItem>> = isLoading.asFlow().flatMapLatest { loading ->
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@@ -40,6 +48,16 @@ class ExploreViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hideSource(source: MangaSource) {
|
||||||
|
launchJob(Dispatchers.Default) {
|
||||||
|
settings.hiddenSources += source.name
|
||||||
|
val rollback = ReversibleHandle {
|
||||||
|
settings.hiddenSources -= source.name
|
||||||
|
}
|
||||||
|
onActionDone.postCall(ReversibleAction(R.string.source_disabled, rollback))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createContentFlow() = settings.observe()
|
private fun createContentFlow() = settings.observe()
|
||||||
.filter {
|
.filter {
|
||||||
it == AppSettings.KEY_SOURCES_HIDDEN ||
|
it == AppSettings.KEY_SOURCES_HIDDEN ||
|
||||||
@@ -61,7 +79,7 @@ class ExploreViewModel @Inject constructor(
|
|||||||
sources.mapTo(result) { ExploreItem.Source(it) }
|
sources.mapTo(result) { ExploreItem.Source(it) }
|
||||||
} else {
|
} else {
|
||||||
result += ExploreItem.EmptyHint(
|
result += ExploreItem.EmptyHint(
|
||||||
icon = R.drawable.ic_empty_search,
|
icon = R.drawable.ic_empty_common,
|
||||||
textPrimary = R.string.no_manga_sources,
|
textPrimary = R.string.no_manga_sources,
|
||||||
textSecondary = R.string.no_manga_sources_text,
|
textSecondary = R.string.no_manga_sources_text,
|
||||||
actionStringRes = R.string.manage,
|
actionStringRes = R.string.manage,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.koitharu.kotatsu.explore.ui.model
|
package org.koitharu.kotatsu.explore.ui.model
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
||||||
@@ -73,6 +72,7 @@ sealed interface ExploreItem : ListModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
class EmptyHint(
|
class EmptyHint(
|
||||||
@DrawableRes icon: Int,
|
@DrawableRes icon: Int,
|
||||||
@StringRes textPrimary: Int,
|
@StringRes textPrimary: Int,
|
||||||
@@ -81,4 +81,4 @@ sealed interface ExploreItem : ListModel {
|
|||||||
) : EmptyState(icon, textPrimary, textSecondary, actionStringRes), ExploreItem
|
) : EmptyState(icon, textPrimary, textSecondary, actionStringRes), ExploreItem
|
||||||
|
|
||||||
object Loading : ExploreItem
|
object Loading : ExploreItem
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|||||||
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
||||||
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment
|
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment
|
||||||
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment.Companion.NO_ID
|
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment.Companion.NO_ID
|
||||||
|
import kotlin.text.Typography.dagger
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class FavouritesActivity : BaseActivity<ActivityContainerBinding>() {
|
class FavouritesActivity : BaseActivity<ActivityContainerBinding>() {
|
||||||
@@ -28,6 +29,7 @@ class FavouritesActivity : BaseActivity<ActivityContainerBinding>() {
|
|||||||
val fm = supportFragmentManager
|
val fm = supportFragmentManager
|
||||||
if (fm.findFragmentById(R.id.container) == null) {
|
if (fm.findFragmentById(R.id.container) == null) {
|
||||||
fm.commit {
|
fm.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
val fragment = FavouritesListFragment.newInstance(intent.getLongExtra(EXTRA_CATEGORY_ID, NO_ID))
|
val fragment = FavouritesListFragment.newInstance(intent.getLongExtra(EXTRA_CATEGORY_ID, NO_ID))
|
||||||
replace(R.id.container, fragment)
|
replace(R.id.container, fragment)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
|
import kotlin.jvm.internal.Intrinsics
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesListListener
|
import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesListListener
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.emptyStateListAD
|
import org.koitharu.kotatsu.list.ui.adapter.emptyStateListAD
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.loadingStateAD
|
import org.koitharu.kotatsu.list.ui.adapter.loadingStateAD
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import kotlin.jvm.internal.Intrinsics
|
|
||||||
|
|
||||||
class CategoriesAdapter(
|
class CategoriesAdapter(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -20,7 +20,7 @@ class CategoriesAdapter(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
delegatesManager.addDelegate(categoryAD(coil, lifecycleOwner, onItemClickListener))
|
delegatesManager.addDelegate(categoryAD(coil, lifecycleOwner, onItemClickListener))
|
||||||
.addDelegate(emptyStateListAD(listListener))
|
.addDelegate(emptyStateListAD(coil, listListener))
|
||||||
.addDelegate(loadingStateAD())
|
.addDelegate(loadingStateAD())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,4 +56,4 @@ class CategoriesAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.koitharu.kotatsu.parsers.model.SortOrder
|
|||||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||||
import org.koitharu.kotatsu.utils.asFlowLiveData
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
class FavouritesListViewModel @AssistedInject constructor(
|
class FavouritesListViewModel @AssistedInject constructor(
|
||||||
@Assisted private val categoryId: Long,
|
@Assisted private val categoryId: Long,
|
||||||
@@ -69,6 +70,7 @@ class FavouritesListViewModel @AssistedInject constructor(
|
|||||||
actionStringRes = 0,
|
actionStringRes = 0,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> list.toUi(mode, this)
|
else -> list.toUi(mode, this)
|
||||||
}
|
}
|
||||||
}.catch {
|
}.catch {
|
||||||
@@ -79,7 +81,7 @@ class FavouritesListViewModel @AssistedInject constructor(
|
|||||||
if (categoryId != NO_ID) {
|
if (categoryId != NO_ID) {
|
||||||
launchJob {
|
launchJob {
|
||||||
categoryName = withContext(Dispatchers.Default) {
|
categoryName = withContext(Dispatchers.Default) {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
repository.getCategory(categoryId).title
|
repository.getCategory(categoryId).title
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.base.ui.BaseActivity
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
||||||
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
||||||
|
import kotlin.text.Typography.dagger
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class HistoryActivity :
|
class HistoryActivity :
|
||||||
@@ -28,6 +29,7 @@ class HistoryActivity :
|
|||||||
val fm = supportFragmentManager
|
val fm = supportFragmentManager
|
||||||
if (fm.findFragmentById(R.id.container) == null) {
|
if (fm.findFragmentById(R.id.container) == null) {
|
||||||
fm.commit {
|
fm.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
val fragment = HistoryListFragment.newInstance()
|
val fragment = HistoryListFragment.newInstance()
|
||||||
replace(R.id.container, fragment)
|
replace(R.id.container, fragment)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import android.view.Menu
|
|||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.core.view.MenuProvider
|
import androidx.core.view.MenuProvider
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
|
|
||||||
class HistoryListMenuProvider(
|
class HistoryListMenuProvider(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@@ -38,6 +38,6 @@ class HistoryListMenuProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareMenu(menu: Menu) {
|
override fun onPrepareMenu(menu: Menu) {
|
||||||
menu.findItem(R.id.action_history_grouping).isChecked = viewModel.isGroupingEnabled.value == true
|
menu.findItem(R.id.action_history_grouping)?.isChecked = viewModel.isGroupingEnabled.value == true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ class ImageActivity : BaseActivity<ActivityImageBinding>() {
|
|||||||
|
|
||||||
private fun setDrawable(drawable: Drawable?) {
|
private fun setDrawable(drawable: Drawable?) {
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
view.setImage(ImageSource.bitmap(drawable.toBitmap()))
|
view.setImage(ImageSource.Bitmap(drawable.toBitmap()))
|
||||||
} else {
|
} else {
|
||||||
view.recycle()
|
view.recycle()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.library.domain
|
|
||||||
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.flow.*
|
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.toManga
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
|
|
||||||
import org.koitharu.kotatsu.favourites.data.toFavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
|
||||||
|
|
||||||
class LibraryRepository @Inject constructor(
|
|
||||||
private val db: MangaDatabase,
|
|
||||||
) {
|
|
||||||
|
|
||||||
fun observeFavourites(): Flow<Map<FavouriteCategory, List<Manga>>> {
|
|
||||||
return db.favouriteCategoriesDao.observeAll()
|
|
||||||
.flatMapLatest { categories ->
|
|
||||||
val cats = categories.filter { it.isVisibleInLibrary }
|
|
||||||
if (cats.isEmpty()) {
|
|
||||||
flowOf(emptyMap())
|
|
||||||
} else {
|
|
||||||
observeCategoriesContent(cats)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun observeCategoriesContent(
|
|
||||||
categories: List<FavouriteCategoryEntity>,
|
|
||||||
) = combine<Pair<FavouriteCategory, List<Manga>>, Map<FavouriteCategory, List<Manga>>>(
|
|
||||||
categories.map { cat ->
|
|
||||||
val category = cat.toFavouriteCategory()
|
|
||||||
db.favouritesDao.observeAll(category.id, category.order)
|
|
||||||
.map { category to it.map { x -> x.manga.toManga(x.tags.toMangaTags()) } }
|
|
||||||
},
|
|
||||||
) { array -> array.toMap() }
|
|
||||||
}
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.library.ui
|
|
||||||
|
|
||||||
import androidx.collection.ArraySet
|
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.catch
|
|
||||||
import kotlinx.coroutines.flow.combine
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
|
||||||
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
||||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
|
||||||
import org.koitharu.kotatsu.core.ui.DateTimeAgo
|
|
||||||
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
|
||||||
import org.koitharu.kotatsu.history.domain.MangaWithHistory
|
|
||||||
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
|
||||||
import org.koitharu.kotatsu.library.domain.LibraryRepository
|
|
||||||
import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel
|
|
||||||
import org.koitharu.kotatsu.list.domain.ListExtraProvider
|
|
||||||
import org.koitharu.kotatsu.list.ui.model.*
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
|
||||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
|
||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
|
||||||
import org.koitharu.kotatsu.utils.asFlowLiveData
|
|
||||||
import org.koitharu.kotatsu.utils.ext.daysDiff
|
|
||||||
|
|
||||||
private const val HISTORY_MAX_SEGMENTS = 2
|
|
||||||
|
|
||||||
@HiltViewModel
|
|
||||||
class LibraryViewModel @Inject constructor(
|
|
||||||
repository: LibraryRepository,
|
|
||||||
private val historyRepository: HistoryRepository,
|
|
||||||
private val favouritesRepository: FavouritesRepository,
|
|
||||||
private val trackingRepository: TrackingRepository,
|
|
||||||
private val settings: AppSettings,
|
|
||||||
) : BaseViewModel(), ListExtraProvider {
|
|
||||||
|
|
||||||
val onActionDone = SingleLiveEvent<ReversibleAction>()
|
|
||||||
|
|
||||||
val content: LiveData<List<ListModel>> = combine(
|
|
||||||
historyRepository.observeAllWithHistory(),
|
|
||||||
repository.observeFavourites(),
|
|
||||||
) { history, favourites ->
|
|
||||||
mapList(history, favourites)
|
|
||||||
}.catch { e ->
|
|
||||||
emit(listOf(e.toErrorState(canRetry = false)))
|
|
||||||
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
|
||||||
|
|
||||||
override suspend fun getCounter(mangaId: Long): Int {
|
|
||||||
return trackingRepository.getNewChaptersCount(mangaId)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getProgress(mangaId: Long): Float {
|
|
||||||
return if (settings.isReadingIndicatorsEnabled) {
|
|
||||||
historyRepository.getProgress(mangaId)
|
|
||||||
} else {
|
|
||||||
PROGRESS_NONE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeFromFavourites(category: FavouriteCategory, ids: Set<Long>) {
|
|
||||||
if (ids.isEmpty()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
launchJob(Dispatchers.Default) {
|
|
||||||
val handle = favouritesRepository.removeFromCategory(category.id, ids)
|
|
||||||
onActionDone.postCall(ReversibleAction(R.string.removed_from_favourites, handle))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeFromHistory(ids: Set<Long>) {
|
|
||||||
if (ids.isEmpty()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
launchJob(Dispatchers.Default) {
|
|
||||||
val handle = historyRepository.delete(ids)
|
|
||||||
onActionDone.postCall(ReversibleAction(R.string.removed_from_history, handle))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clearHistory(minDate: Long) {
|
|
||||||
launchJob(Dispatchers.Default) {
|
|
||||||
val stringRes = if (minDate <= 0) {
|
|
||||||
historyRepository.clear()
|
|
||||||
R.string.history_cleared
|
|
||||||
} else {
|
|
||||||
historyRepository.deleteAfter(minDate)
|
|
||||||
R.string.removed_from_history
|
|
||||||
}
|
|
||||||
onActionDone.postCall(ReversibleAction(stringRes, null))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getManga(ids: Set<Long>): Set<Manga> {
|
|
||||||
val snapshot = content.value ?: return emptySet()
|
|
||||||
val result = ArraySet<Manga>(ids.size)
|
|
||||||
for (section in snapshot) {
|
|
||||||
if (section !is LibrarySectionModel) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for (item in section.items) {
|
|
||||||
if (item.id in ids) {
|
|
||||||
result.add(item.manga)
|
|
||||||
if (result.size == ids.size) {
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun mapList(
|
|
||||||
history: List<MangaWithHistory>,
|
|
||||||
favourites: Map<FavouriteCategory, List<Manga>>,
|
|
||||||
): List<ListModel> {
|
|
||||||
val result = ArrayList<ListModel>(favourites.keys.size + 1)
|
|
||||||
if (history.isNotEmpty()) {
|
|
||||||
mapHistory(result, history)
|
|
||||||
}
|
|
||||||
if (favourites.isNotEmpty()) {
|
|
||||||
mapFavourites(result, favourites)
|
|
||||||
}
|
|
||||||
if (result.isEmpty()) {
|
|
||||||
result += EmptyState(
|
|
||||||
icon = R.drawable.ic_empty_history,
|
|
||||||
textPrimary = R.string.text_shelf_holder_primary,
|
|
||||||
textSecondary = R.string.text_shelf_holder_secondary,
|
|
||||||
actionStringRes = 0,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
result.trimToSize()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun mapHistory(
|
|
||||||
destination: MutableList<in LibrarySectionModel.History>,
|
|
||||||
list: List<MangaWithHistory>,
|
|
||||||
) {
|
|
||||||
val showPercent = settings.isReadingIndicatorsEnabled
|
|
||||||
val groups = list.groupByTo(LinkedHashMap()) { timeAgo(it.history.updatedAt) }
|
|
||||||
while (groups.size > HISTORY_MAX_SEGMENTS) {
|
|
||||||
val lastKey = groups.keys.last()
|
|
||||||
val subList = groups.remove(lastKey) ?: continue
|
|
||||||
groups[groups.keys.last()]?.addAll(subList)
|
|
||||||
}
|
|
||||||
for ((timeAgo, subList) in groups) {
|
|
||||||
destination += LibrarySectionModel.History(
|
|
||||||
items = subList.map { (manga, history) ->
|
|
||||||
val counter = trackingRepository.getNewChaptersCount(manga.id)
|
|
||||||
val percent = if (showPercent) history.percent else PROGRESS_NONE
|
|
||||||
manga.toGridModel(counter, percent)
|
|
||||||
},
|
|
||||||
timeAgo = timeAgo,
|
|
||||||
showAllButtonText = R.string.show_all,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun mapFavourites(
|
|
||||||
destination: MutableList<in LibrarySectionModel.Favourites>,
|
|
||||||
favourites: Map<FavouriteCategory, List<Manga>>,
|
|
||||||
) {
|
|
||||||
for ((category, list) in favourites) {
|
|
||||||
if (list.isNotEmpty()) {
|
|
||||||
destination += LibrarySectionModel.Favourites(
|
|
||||||
items = list.toUi(ListMode.GRID, this),
|
|
||||||
category = category,
|
|
||||||
showAllButtonText = R.string.show_all,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun timeAgo(date: Date): DateTimeAgo {
|
|
||||||
val diffDays = -date.daysDiff(System.currentTimeMillis())
|
|
||||||
return when {
|
|
||||||
diffDays < 1 -> DateTimeAgo.Today
|
|
||||||
diffDays == 1 -> DateTimeAgo.Yesterday
|
|
||||||
diffDays <= 3 -> DateTimeAgo.DaysAgo(diffDays)
|
|
||||||
else -> DateTimeAgo.LongAgo
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.library.ui.adapter
|
|
||||||
|
|
||||||
import android.view.View
|
|
||||||
import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel
|
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
|
||||||
|
|
||||||
interface LibraryListEventListener : ListStateHolderListener {
|
|
||||||
|
|
||||||
fun onItemClick(item: Manga, section: LibrarySectionModel, view: View)
|
|
||||||
|
|
||||||
fun onItemLongClick(item: Manga, section: LibrarySectionModel, view: View): Boolean
|
|
||||||
|
|
||||||
fun onSectionClick(section: LibrarySectionModel, view: View)
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.library.ui.config.categories
|
|
||||||
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
|
|
||||||
class LibraryCategoriesConfigAdapter(
|
|
||||||
listener: OnListItemClickListener<FavouriteCategory>,
|
|
||||||
) : AsyncListDifferDelegationAdapter<FavouriteCategory>(DiffCallback()) {
|
|
||||||
|
|
||||||
init {
|
|
||||||
delegatesManager.addDelegate(libraryCategoryAD(listener))
|
|
||||||
}
|
|
||||||
|
|
||||||
class DiffCallback : DiffUtil.ItemCallback<FavouriteCategory>() {
|
|
||||||
|
|
||||||
override fun areItemsTheSame(oldItem: FavouriteCategory, newItem: FavouriteCategory): Boolean {
|
|
||||||
return oldItem.id == newItem.id
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: FavouriteCategory, newItem: FavouriteCategory): Boolean {
|
|
||||||
return oldItem.isVisibleInLibrary == newItem.isVisibleInLibrary && oldItem.title == newItem.title
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getChangePayload(oldItem: FavouriteCategory, newItem: FavouriteCategory): Any? {
|
|
||||||
return if (oldItem.isVisibleInLibrary == newItem.isVisibleInLibrary) {
|
|
||||||
super.getChangePayload(oldItem, newItem)
|
|
||||||
} else Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.library.ui.config.categories
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.core.view.isVisible
|
|
||||||
import androidx.fragment.app.FragmentManager
|
|
||||||
import androidx.fragment.app.viewModels
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.databinding.SheetBaseBinding
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class LibraryCategoriesConfigSheet :
|
|
||||||
BaseBottomSheet<SheetBaseBinding>(),
|
|
||||||
OnListItemClickListener<FavouriteCategory>,
|
|
||||||
View.OnClickListener {
|
|
||||||
|
|
||||||
private val viewModel by viewModels<LibraryCategoriesConfigViewModel>()
|
|
||||||
|
|
||||||
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetBaseBinding {
|
|
||||||
return SheetBaseBinding.inflate(inflater, container, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
binding.headerBar.toolbar.setTitle(R.string.favourites_categories)
|
|
||||||
binding.buttonDone.isVisible = true
|
|
||||||
binding.buttonDone.setOnClickListener(this)
|
|
||||||
val adapter = LibraryCategoriesConfigAdapter(this)
|
|
||||||
binding.recyclerView.adapter = adapter
|
|
||||||
|
|
||||||
viewModel.content.observe(viewLifecycleOwner) { adapter.items = it }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemClick(item: FavouriteCategory, view: View) {
|
|
||||||
viewModel.toggleItem(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick(v: View?) {
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
private const val TAG = "LibraryCategoriesConfigSheet"
|
|
||||||
|
|
||||||
fun show(fm: FragmentManager) = LibraryCategoriesConfigSheet().show(fm, TAG)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.library.ui.config.categories
|
|
||||||
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
|
||||||
|
|
||||||
@HiltViewModel
|
|
||||||
class LibraryCategoriesConfigViewModel @Inject constructor(
|
|
||||||
private val favouritesRepository: FavouritesRepository,
|
|
||||||
) : BaseViewModel() {
|
|
||||||
|
|
||||||
val content = favouritesRepository.observeCategories()
|
|
||||||
.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, emptyList())
|
|
||||||
|
|
||||||
private var updateJob: Job? = null
|
|
||||||
|
|
||||||
fun toggleItem(category: FavouriteCategory) {
|
|
||||||
val prevJob = updateJob
|
|
||||||
updateJob = launchJob(Dispatchers.Default) {
|
|
||||||
prevJob?.join()
|
|
||||||
favouritesRepository.updateCategory(category.id, !category.isVisibleInLibrary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.library.ui.config.categories
|
|
||||||
|
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.AdapterDelegateClickListenerAdapter
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.databinding.ItemCategoryCheckableMultipleBinding
|
|
||||||
|
|
||||||
fun libraryCategoryAD(
|
|
||||||
listener: OnListItemClickListener<FavouriteCategory>,
|
|
||||||
) = adapterDelegateViewBinding<FavouriteCategory, FavouriteCategory, ItemCategoryCheckableMultipleBinding>(
|
|
||||||
{ layoutInflater, parent -> ItemCategoryCheckableMultipleBinding.inflate(layoutInflater, parent, false) },
|
|
||||||
) {
|
|
||||||
val eventListener = AdapterDelegateClickListenerAdapter(this, listener)
|
|
||||||
itemView.setOnClickListener(eventListener)
|
|
||||||
|
|
||||||
bind {
|
|
||||||
binding.root.text = item.title
|
|
||||||
binding.root.isChecked = item.isVisibleInLibrary
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.library.ui.model
|
|
||||||
|
|
||||||
import android.content.res.Resources
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.core.ui.DateTimeAgo
|
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
|
||||||
import org.koitharu.kotatsu.list.ui.model.MangaItemModel
|
|
||||||
|
|
||||||
sealed class LibrarySectionModel(
|
|
||||||
val items: List<MangaItemModel>,
|
|
||||||
@StringRes val showAllButtonText: Int,
|
|
||||||
) : ListModel {
|
|
||||||
|
|
||||||
abstract val key: Any
|
|
||||||
abstract fun getTitle(resources: Resources): CharSequence
|
|
||||||
|
|
||||||
class History(
|
|
||||||
items: List<MangaItemModel>,
|
|
||||||
val timeAgo: DateTimeAgo?,
|
|
||||||
showAllButtonText: Int,
|
|
||||||
) : LibrarySectionModel(items, showAllButtonText) {
|
|
||||||
|
|
||||||
override val key: Any
|
|
||||||
get() = timeAgo?.javaClass ?: this::class.java
|
|
||||||
|
|
||||||
override fun getTitle(resources: Resources): CharSequence {
|
|
||||||
return timeAgo?.format(resources) ?: resources.getString(R.string.history)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as History
|
|
||||||
|
|
||||||
if (timeAgo != other.timeAgo) return false
|
|
||||||
if (showAllButtonText != other.showAllButtonText) return false
|
|
||||||
if (items != other.items) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = items.hashCode()
|
|
||||||
result = 31 * result + (timeAgo?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + showAllButtonText.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
return "hist_$timeAgo"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Favourites(
|
|
||||||
items: List<MangaItemModel>,
|
|
||||||
val category: FavouriteCategory,
|
|
||||||
showAllButtonText: Int,
|
|
||||||
) : LibrarySectionModel(items, showAllButtonText) {
|
|
||||||
|
|
||||||
override val key: Any
|
|
||||||
get() = category.id
|
|
||||||
|
|
||||||
override fun getTitle(resources: Resources): CharSequence {
|
|
||||||
return category.title
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as Favourites
|
|
||||||
|
|
||||||
if (category != other.category) return false
|
|
||||||
if (showAllButtonText != other.showAllButtonText) return false
|
|
||||||
if (items != other.items) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = items.hashCode()
|
|
||||||
result = 31 * result + category.hashCode()
|
|
||||||
result = 31 * result + showAllButtonText.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
return "fav_${category.id}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,24 +6,23 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.button.MaterialButtonToggleGroup
|
||||||
import com.google.android.material.slider.Slider
|
import com.google.android.material.slider.Slider
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
||||||
import org.koitharu.kotatsu.base.ui.widgets.CheckableButtonGroup
|
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
import org.koitharu.kotatsu.core.prefs.ListMode
|
||||||
import org.koitharu.kotatsu.databinding.DialogListModeBinding
|
import org.koitharu.kotatsu.databinding.DialogListModeBinding
|
||||||
import org.koitharu.kotatsu.utils.ext.setValueRounded
|
import org.koitharu.kotatsu.utils.ext.setValueRounded
|
||||||
import org.koitharu.kotatsu.utils.progress.IntPercentLabelFormatter
|
import org.koitharu.kotatsu.utils.progress.IntPercentLabelFormatter
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ListModeSelectDialog :
|
class ListModeBottomSheet :
|
||||||
AlertDialogFragment<DialogListModeBinding>(),
|
BaseBottomSheet<DialogListModeBinding>(),
|
||||||
CheckableButtonGroup.OnCheckedChangeListener,
|
Slider.OnChangeListener,
|
||||||
Slider.OnChangeListener {
|
MaterialButtonToggleGroup.OnButtonCheckedListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var settings: AppSettings
|
lateinit var settings: AppSettings
|
||||||
@@ -33,13 +32,6 @@ class ListModeSelectDialog :
|
|||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
) = DialogListModeBinding.inflate(inflater, container, false)
|
) = DialogListModeBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
override fun onBuildDialog(builder: MaterialAlertDialogBuilder): MaterialAlertDialogBuilder {
|
|
||||||
return super.onBuildDialog(builder)
|
|
||||||
.setTitle(R.string.list_mode)
|
|
||||||
.setPositiveButton(R.string.done, null)
|
|
||||||
.setCancelable(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val mode = settings.listMode
|
val mode = settings.listMode
|
||||||
@@ -53,10 +45,10 @@ class ListModeSelectDialog :
|
|||||||
binding.sliderGrid.setValueRounded(settings.gridSize.toFloat())
|
binding.sliderGrid.setValueRounded(settings.gridSize.toFloat())
|
||||||
binding.sliderGrid.addOnChangeListener(this)
|
binding.sliderGrid.addOnChangeListener(this)
|
||||||
|
|
||||||
binding.checkableGroup.onCheckedChangeListener = this
|
binding.checkableGroup.addOnButtonCheckedListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCheckedChanged(group: CheckableButtonGroup, checkedId: Int) {
|
override fun onButtonChecked(group: MaterialButtonToggleGroup?, checkedId: Int, isChecked: Boolean) {
|
||||||
val mode = when (checkedId) {
|
val mode = when (checkedId) {
|
||||||
R.id.button_list -> ListMode.LIST
|
R.id.button_list -> ListMode.LIST
|
||||||
R.id.button_list_detailed -> ListMode.DETAILED_LIST
|
R.id.button_list_detailed -> ListMode.DETAILED_LIST
|
||||||
@@ -78,6 +70,6 @@ class ListModeSelectDialog :
|
|||||||
|
|
||||||
private const val TAG = "ListModeSelectDialog"
|
private const val TAG = "ListModeSelectDialog"
|
||||||
|
|
||||||
fun show(fm: FragmentManager) = ListModeSelectDialog().show(fm, TAG)
|
fun show(fm: FragmentManager) = ListModeBottomSheet().show(fm, TAG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,9 +17,10 @@ class MangaListMenuProvider(
|
|||||||
|
|
||||||
override fun onMenuItemSelected(menuItem: MenuItem): Boolean = when (menuItem.itemId) {
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean = when (menuItem.itemId) {
|
||||||
R.id.action_list_mode -> {
|
R.id.action_list_mode -> {
|
||||||
ListModeSelectDialog.show(fragment.childFragmentManager)
|
ListModeBottomSheet.show(fragment.childFragmentManager)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
@file:SuppressLint("UnsafeOptInUsageError")
|
|
||||||
package org.koitharu.kotatsu.list.ui.adapter
|
package org.koitharu.kotatsu.list.ui.adapter
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.annotation.CheckResult
|
||||||
import androidx.core.view.doOnNextLayout
|
import androidx.core.view.doOnNextLayout
|
||||||
import com.google.android.material.badge.BadgeDrawable
|
import com.google.android.material.badge.BadgeDrawable
|
||||||
import com.google.android.material.badge.BadgeUtils
|
import com.google.android.material.badge.BadgeUtils
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
@CheckResult
|
||||||
fun View.bindBadge(badge: BadgeDrawable?, counter: Int): BadgeDrawable? {
|
fun View.bindBadge(badge: BadgeDrawable?, counter: Int): BadgeDrawable? {
|
||||||
return if (counter > 0) {
|
return if (counter > 0) {
|
||||||
val badgeDrawable = badge ?: initBadge(this)
|
val badgeDrawable = badge ?: initBadge(this)
|
||||||
@@ -39,4 +39,4 @@ private fun initBadge(anchor: View): BadgeDrawable {
|
|||||||
private fun BadgeDrawable.align() {
|
private fun BadgeDrawable.align() {
|
||||||
horizontalOffset = intrinsicWidth
|
horizontalOffset = intrinsicWidth
|
||||||
verticalOffset = intrinsicHeight
|
verticalOffset = intrinsicHeight
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.koitharu.kotatsu.list.ui.adapter
|
||||||
|
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
|
import org.koitharu.kotatsu.databinding.ItemEmptyCardBinding
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.EmptyHint
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setTextAndVisible
|
||||||
|
|
||||||
|
fun emptyHintAD(
|
||||||
|
listener: ListStateHolderListener,
|
||||||
|
) = adapterDelegateViewBinding<EmptyHint, ListModel, ItemEmptyCardBinding>(
|
||||||
|
{ inflater, parent -> ItemEmptyCardBinding.inflate(inflater, parent, false) },
|
||||||
|
) {
|
||||||
|
|
||||||
|
binding.buttonRetry.setOnClickListener { listener.onEmptyActionClick() }
|
||||||
|
|
||||||
|
bind {
|
||||||
|
binding.icon.setImageResource(item.icon)
|
||||||
|
binding.textPrimary.setText(item.textPrimary)
|
||||||
|
binding.textSecondary.setTextAndVisible(item.textSecondary)
|
||||||
|
binding.buttonRetry.setTextAndVisible(item.actionStringRes)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,31 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.adapter
|
package org.koitharu.kotatsu.list.ui.adapter
|
||||||
|
|
||||||
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.databinding.ItemEmptyStateBinding
|
import org.koitharu.kotatsu.databinding.ItemEmptyStateBinding
|
||||||
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
import org.koitharu.kotatsu.utils.ext.setTextAndVisible
|
import org.koitharu.kotatsu.utils.ext.setTextAndVisible
|
||||||
|
|
||||||
fun emptyStateListAD(
|
fun emptyStateListAD(
|
||||||
|
coil: ImageLoader,
|
||||||
listener: ListStateHolderListener,
|
listener: ListStateHolderListener,
|
||||||
) = adapterDelegateViewBinding<EmptyState, ListModel, ItemEmptyStateBinding>(
|
) = adapterDelegateViewBinding<EmptyState, ListModel, ItemEmptyStateBinding>(
|
||||||
{ inflater, parent -> ItemEmptyStateBinding.inflate(inflater, parent, false) }
|
{ inflater, parent -> ItemEmptyStateBinding.inflate(inflater, parent, false) },
|
||||||
) {
|
) {
|
||||||
|
|
||||||
binding.buttonRetry.setOnClickListener { listener.onEmptyActionClick() }
|
binding.buttonRetry.setOnClickListener { listener.onEmptyActionClick() }
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.icon.setImageResource(item.icon)
|
binding.icon.newImageRequest(item.icon)?.enqueueWith(coil)
|
||||||
binding.textPrimary.setText(item.textPrimary)
|
binding.textPrimary.setText(item.textPrimary)
|
||||||
binding.textSecondary.setTextAndVisible(item.textSecondary)
|
binding.textSecondary.setTextAndVisible(item.textSecondary)
|
||||||
binding.buttonRetry.setTextAndVisible(item.actionStringRes)
|
binding.buttonRetry.setTextAndVisible(item.actionStringRes)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
onViewRecycled {
|
||||||
|
binding.icon.disposeImageRequest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
|
import kotlin.jvm.internal.Intrinsics
|
||||||
import org.koitharu.kotatsu.core.ui.DateTimeAgo
|
import org.koitharu.kotatsu.core.ui.DateTimeAgo
|
||||||
import org.koitharu.kotatsu.list.ui.model.*
|
import org.koitharu.kotatsu.list.ui.model.*
|
||||||
import kotlin.jvm.internal.Intrinsics
|
|
||||||
|
|
||||||
open class MangaListAdapter(
|
open class MangaListAdapter(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -24,7 +24,7 @@ open class MangaListAdapter(
|
|||||||
.addDelegate(ITEM_TYPE_DATE, relatedDateItemAD())
|
.addDelegate(ITEM_TYPE_DATE, relatedDateItemAD())
|
||||||
.addDelegate(ITEM_TYPE_ERROR_STATE, errorStateListAD(listener))
|
.addDelegate(ITEM_TYPE_ERROR_STATE, errorStateListAD(listener))
|
||||||
.addDelegate(ITEM_TYPE_ERROR_FOOTER, errorFooterAD(listener))
|
.addDelegate(ITEM_TYPE_ERROR_FOOTER, errorFooterAD(listener))
|
||||||
.addDelegate(ITEM_TYPE_EMPTY, emptyStateListAD(listener))
|
.addDelegate(ITEM_TYPE_EMPTY, emptyStateListAD(coil, listener))
|
||||||
.addDelegate(ITEM_TYPE_HEADER, listHeaderAD(listener))
|
.addDelegate(ITEM_TYPE_HEADER, listHeaderAD(listener))
|
||||||
.addDelegate(ITEM_TYPE_HEADER_2, listHeader2AD(listener))
|
.addDelegate(ITEM_TYPE_HEADER_2, listHeader2AD(listener))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ fun mangaListDetailedItemAD(
|
|||||||
}
|
}
|
||||||
binding.textViewRating.textAndVisible = item.rating
|
binding.textViewRating.textAndVisible = item.rating
|
||||||
binding.textViewTags.text = item.tags
|
binding.textViewTags.text = item.tags
|
||||||
itemView.bindBadge(badge, item.counter)
|
badge = itemView.bindBadge(badge, item.counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
onViewRecycled {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ fun mangaListItemAD(
|
|||||||
lifecycle(lifecycleOwner)
|
lifecycle(lifecycleOwner)
|
||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
itemView.bindBadge(badge, item.counter)
|
badge = itemView.bindBadge(badge, item.counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
onViewRecycled {
|
||||||
|
|||||||
@@ -6,15 +6,22 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.CoroutineStart
|
import kotlinx.coroutines.CoroutineStart
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.*
|
import java.util.Locale
|
||||||
|
import java.util.TreeSet
|
||||||
|
|
||||||
class FilterCoordinator(
|
class FilterCoordinator(
|
||||||
private val repository: RemoteMangaRepository,
|
private val repository: RemoteMangaRepository,
|
||||||
@@ -153,7 +160,7 @@ class FilterCoordinator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun loadTagsAsync() = coroutineScope.async(Dispatchers.Default, CoroutineStart.LAZY) {
|
private fun loadTagsAsync() = coroutineScope.async(Dispatchers.Default, CoroutineStart.LAZY) {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
repository.getTags()
|
repository.getTags()
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
error.printStackTraceDebug()
|
error.printStackTraceDebug()
|
||||||
@@ -204,4 +211,4 @@ class FilterCoordinator(
|
|||||||
return collator?.compare(t1, t2) ?: compareValues(t1, t2)
|
return collator?.compare(t1, t2) ?: compareValues(t1, t2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.koitharu.kotatsu.list.ui.model
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
|
||||||
|
class EmptyHint(
|
||||||
|
@DrawableRes icon: Int,
|
||||||
|
@StringRes textPrimary: Int,
|
||||||
|
@StringRes textSecondary: Int,
|
||||||
|
@StringRes actionStringRes: Int,
|
||||||
|
) : EmptyState(icon, textPrimary, textSecondary, actionStringRes) {
|
||||||
|
|
||||||
|
fun toState() = EmptyState(icon, textPrimary, textSecondary, actionStringRes)
|
||||||
|
}
|
||||||
@@ -3,22 +3,30 @@ package org.koitharu.kotatsu.local.data
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.tomclaw.cache.DiskLruCache
|
import com.tomclaw.cache.DiskLruCache
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.koitharu.kotatsu.utils.FileSize
|
||||||
|
import org.koitharu.kotatsu.utils.ext.copyToSuspending
|
||||||
|
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||||
|
import org.koitharu.kotatsu.utils.ext.subdir
|
||||||
|
import org.koitharu.kotatsu.utils.ext.takeIfReadable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.takeIfWriteable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
|
||||||
import org.koitharu.kotatsu.utils.FileSize
|
|
||||||
import org.koitharu.kotatsu.utils.ext.longHashCode
|
|
||||||
import org.koitharu.kotatsu.utils.ext.subdir
|
|
||||||
import org.koitharu.kotatsu.utils.ext.takeIfReadable
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class PagesCache @Inject constructor(@ApplicationContext context: Context) {
|
class PagesCache @Inject constructor(@ApplicationContext context: Context) {
|
||||||
|
|
||||||
private val cacheDir = context.externalCacheDir ?: context.cacheDir
|
private val cacheDir = checkNotNull(findSuitableDir(context)) {
|
||||||
|
val dirs = (context.externalCacheDirs + context.cacheDir).joinToString(";") {
|
||||||
|
it.absolutePath
|
||||||
|
}
|
||||||
|
"Cannot find any suitable directory for PagesCache: [$dirs]"
|
||||||
|
}
|
||||||
private val lruCache = createDiskLruCacheSafe(
|
private val lruCache = createDiskLruCacheSafe(
|
||||||
dir = cacheDir.subdir(CacheDir.PAGES.dir),
|
dir = cacheDir,
|
||||||
size = FileSize.MEGABYTES.convert(200, FileSize.BYTES),
|
size = FileSize.MEGABYTES.convert(200, FileSize.BYTES),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,42 +34,15 @@ class PagesCache @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
return lruCache.get(url)?.takeIfReadable()
|
return lruCache.get(url)?.takeIfReadable()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun put(url: String, inputStream: InputStream): File {
|
suspend fun put(url: String, inputStream: InputStream): File = withContext(Dispatchers.IO) {
|
||||||
val file = File(cacheDir, url.longHashCode().toString())
|
val file = File(cacheDir.parentFile, url.longHashCode().toString())
|
||||||
file.outputStream().use { out ->
|
try {
|
||||||
inputStream.copyTo(out)
|
file.outputStream().use { out ->
|
||||||
}
|
inputStream.copyToSuspending(out)
|
||||||
val res = lruCache.put(url, file)
|
|
||||||
file.delete()
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
fun put(
|
|
||||||
url: String,
|
|
||||||
inputStream: InputStream,
|
|
||||||
contentLength: Long,
|
|
||||||
progress: MutableStateFlow<Float>,
|
|
||||||
): File {
|
|
||||||
val file = File(cacheDir, url.longHashCode().toString())
|
|
||||||
file.outputStream().use { out ->
|
|
||||||
var bytesCopied: Long = 0
|
|
||||||
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
|
|
||||||
var bytes = inputStream.read(buffer)
|
|
||||||
while (bytes >= 0) {
|
|
||||||
out.write(buffer, 0, bytes)
|
|
||||||
bytesCopied += bytes
|
|
||||||
publishProgress(contentLength, bytesCopied, progress)
|
|
||||||
bytes = inputStream.read(buffer)
|
|
||||||
}
|
}
|
||||||
}
|
lruCache.put(url, file)
|
||||||
val res = lruCache.put(url, file)
|
} finally {
|
||||||
file.delete()
|
file.delete()
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun publishProgress(contentLength: Long, bytesCopied: Long, progress: MutableStateFlow<Float>) {
|
|
||||||
if (contentLength > 0) {
|
|
||||||
progress.value = (bytesCopied.toDouble() / contentLength.toDouble()).toFloat()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,3 +56,10 @@ private fun createDiskLruCacheSafe(dir: File, size: Long): DiskLruCache {
|
|||||||
DiskLruCache.create(dir, size)
|
DiskLruCache.create(dir, size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun findSuitableDir(context: Context): File? {
|
||||||
|
val dirs = context.externalCacheDirs + context.cacheDir
|
||||||
|
return dirs.firstNotNullOfOrNull {
|
||||||
|
it.subdir(CacheDir.PAGES.dir).takeIfWriteable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class CbzMangaOutput(
|
|||||||
index.addChapter(chapter)
|
index.addChapter(chapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun finalize() {
|
suspend fun finish() {
|
||||||
runInterruptible(Dispatchers.IO) {
|
runInterruptible(Dispatchers.IO) {
|
||||||
output.put(ENTRY_NAME_INDEX, index.toString())
|
output.put(ENTRY_NAME_INDEX, index.toString())
|
||||||
output.finish()
|
output.finish()
|
||||||
|
|||||||
@@ -7,28 +7,40 @@ import androidx.annotation.WorkerThread
|
|||||||
import androidx.collection.ArraySet
|
import androidx.collection.ArraySet
|
||||||
import androidx.core.net.toFile
|
import androidx.core.net.toFile
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import java.io.File
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import java.util.*
|
import kotlinx.coroutines.Deferred
|
||||||
import java.util.zip.ZipEntry
|
import kotlinx.coroutines.Dispatchers
|
||||||
import java.util.zip.ZipFile
|
import kotlinx.coroutines.async
|
||||||
import javax.inject.Inject
|
import kotlinx.coroutines.awaitAll
|
||||||
import javax.inject.Singleton
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlin.coroutines.CoroutineContext
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.filterNot
|
import kotlinx.coroutines.flow.filterNot
|
||||||
|
import kotlinx.coroutines.runInterruptible
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.local.data.CbzFilter
|
import org.koitharu.kotatsu.local.data.CbzFilter
|
||||||
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
||||||
import org.koitharu.kotatsu.local.data.MangaIndex
|
import org.koitharu.kotatsu.local.data.MangaIndex
|
||||||
import org.koitharu.kotatsu.local.data.TempFileFilter
|
import org.koitharu.kotatsu.local.data.TempFileFilter
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.parsers.util.toCamelCase
|
import org.koitharu.kotatsu.parsers.util.toCamelCase
|
||||||
import org.koitharu.kotatsu.utils.AlphanumComparator
|
import org.koitharu.kotatsu.utils.AlphanumComparator
|
||||||
import org.koitharu.kotatsu.utils.CompositeMutex
|
import org.koitharu.kotatsu.utils.CompositeMutex
|
||||||
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
||||||
import org.koitharu.kotatsu.utils.ext.longHashCode
|
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||||
import org.koitharu.kotatsu.utils.ext.readText
|
import org.koitharu.kotatsu.utils.ext.readText
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import java.io.File
|
||||||
|
import java.util.Enumeration
|
||||||
|
import java.util.zip.ZipEntry
|
||||||
|
import java.util.zip.ZipFile
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
private const val MAX_PARALLELISM = 4
|
private const val MAX_PARALLELISM = 4
|
||||||
|
|
||||||
@@ -58,13 +70,14 @@ class LocalMangaRepository @Inject constructor(private val storageManager: Local
|
|||||||
if (!tags.isNullOrEmpty()) {
|
if (!tags.isNullOrEmpty()) {
|
||||||
list.retainAll { x -> x.containsTags(tags) }
|
list.retainAll { x -> x.containsTags(tags) }
|
||||||
}
|
}
|
||||||
@Suppress("NON_EXHAUSTIVE_WHEN_STATEMENT")
|
|
||||||
when (sortOrder) {
|
when (sortOrder) {
|
||||||
SortOrder.ALPHABETICAL -> list.sortWith(compareBy(AlphanumComparator()) { x -> x.manga.title })
|
SortOrder.ALPHABETICAL -> list.sortWith(compareBy(AlphanumComparator()) { x -> x.manga.title })
|
||||||
SortOrder.RATING -> list.sortByDescending { it.manga.rating }
|
SortOrder.RATING -> list.sortByDescending { it.manga.rating }
|
||||||
SortOrder.NEWEST,
|
SortOrder.NEWEST,
|
||||||
SortOrder.UPDATED,
|
SortOrder.UPDATED,
|
||||||
-> list.sortByDescending { it.createdAt }
|
-> list.sortByDescending { it.createdAt }
|
||||||
|
|
||||||
|
else -> Unit
|
||||||
}
|
}
|
||||||
return list.unwrap()
|
return list.unwrap()
|
||||||
}
|
}
|
||||||
@@ -73,6 +86,7 @@ class LocalMangaRepository @Inject constructor(private val storageManager: Local
|
|||||||
manga.source != MangaSource.LOCAL -> requireNotNull(findSavedManga(manga)) {
|
manga.source != MangaSource.LOCAL -> requireNotNull(findSavedManga(manga)) {
|
||||||
"Manga is not local or saved"
|
"Manga is not local or saved"
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> getFromFile(Uri.parse(manga.url).toFile())
|
else -> getFromFile(Uri.parse(manga.url).toFile())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,7 +250,7 @@ class LocalMangaRepository @Inject constructor(private val storageManager: Local
|
|||||||
context: CoroutineContext,
|
context: CoroutineContext,
|
||||||
): Deferred<LocalManga?> = async(context) {
|
): Deferred<LocalManga?> = async(context) {
|
||||||
runInterruptible {
|
runInterruptible {
|
||||||
runCatching { LocalManga(getFromFile(file), file) }.getOrNull()
|
runCatchingCancellable { LocalManga(getFromFile(file), file) }.getOrNull()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.content.Context
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import java.io.File
|
|
||||||
import kotlinx.coroutines.NonCancellable
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
||||||
@@ -14,8 +13,11 @@ 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.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.model.RATING_UNKNOWN
|
import org.koitharu.kotatsu.parsers.model.RATING_UNKNOWN
|
||||||
|
import org.koitharu.kotatsu.utils.AlphanumComparator
|
||||||
|
import org.koitharu.kotatsu.utils.ext.copyToSuspending
|
||||||
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
||||||
import org.koitharu.kotatsu.utils.ext.longOf
|
import org.koitharu.kotatsu.utils.ext.longOf
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
// TODO: Add support for chapters in cbz
|
// TODO: Add support for chapters in cbz
|
||||||
// https://github.com/KotatsuApp/Kotatsu/issues/31
|
// https://github.com/KotatsuApp/Kotatsu/issues/31
|
||||||
@@ -43,7 +45,7 @@ class DirMangaImporter(
|
|||||||
)
|
)
|
||||||
it.sortChaptersByName()
|
it.sortChaptersByName()
|
||||||
it.mergeWithExisting()
|
it.mergeWithExisting()
|
||||||
it.finalize()
|
it.finish()
|
||||||
it.file
|
it.file
|
||||||
}
|
}
|
||||||
return localMangaRepository.getFromFile(dest)
|
return localMangaRepository.getFromFile(dest)
|
||||||
@@ -57,11 +59,12 @@ class DirMangaImporter(
|
|||||||
|
|
||||||
private suspend fun addPages(output: CbzMangaOutput, root: DocumentFile, path: String, state: State) {
|
private suspend fun addPages(output: CbzMangaOutput, root: DocumentFile, path: String, state: State) {
|
||||||
var number = 0
|
var number = 0
|
||||||
for (file in root.listFiles()) {
|
for (file in root.listFiles().sortedWith(compareBy(AlphanumComparator()) { it.name.orEmpty() })) {
|
||||||
when {
|
when {
|
||||||
file.isDirectory -> {
|
file.isDirectory -> {
|
||||||
addPages(output, file, path + "/" + file.name, state)
|
addPages(output, file, path + "/" + file.name, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
file.isFile -> {
|
file.isFile -> {
|
||||||
val tempFile = file.asTempFile()
|
val tempFile = file.asTempFile()
|
||||||
if (!state.hasCover) {
|
if (!state.hasCover) {
|
||||||
@@ -86,7 +89,7 @@ class DirMangaImporter(
|
|||||||
"Cannot open input stream for $uri"
|
"Cannot open input stream for $uri"
|
||||||
}.use { input ->
|
}.use { input ->
|
||||||
file.outputStream().use { output ->
|
file.outputStream().use { output ->
|
||||||
input.copyTo(output)
|
input.copyToSuspending(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return file
|
return file
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.local.domain.importer
|
package org.koitharu.kotatsu.local.domain.importer
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import java.io.File
|
|
||||||
import java.io.IOException
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runInterruptible
|
import kotlinx.coroutines.runInterruptible
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -11,7 +9,10 @@ import org.koitharu.kotatsu.local.data.CbzFilter
|
|||||||
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.copyToSuspending
|
||||||
import org.koitharu.kotatsu.utils.ext.resolveName
|
import org.koitharu.kotatsu.utils.ext.resolveName
|
||||||
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class ZipMangaImporter(
|
class ZipMangaImporter(
|
||||||
storageManager: LocalStorageManager,
|
storageManager: LocalStorageManager,
|
||||||
@@ -27,10 +28,10 @@ class ZipMangaImporter(
|
|||||||
}
|
}
|
||||||
val dest = File(getOutputDir(), name)
|
val dest = File(getOutputDir(), name)
|
||||||
runInterruptible {
|
runInterruptible {
|
||||||
contentResolver.openInputStream(uri)?.use { source ->
|
contentResolver.openInputStream(uri)
|
||||||
dest.outputStream().use { output ->
|
}?.use { source ->
|
||||||
source.copyTo(output)
|
dest.outputStream().use { output ->
|
||||||
}
|
source.copyToSuspending(output)
|
||||||
}
|
}
|
||||||
} ?: throw IOException("Cannot open input stream: $uri")
|
} ?: throw IOException("Cannot open input stream: $uri")
|
||||||
localMangaRepository.getFromFile(dest)
|
localMangaRepository.getFromFile(dest)
|
||||||
|
|||||||
@@ -23,7 +23,12 @@ import org.koitharu.kotatsu.download.ui.service.DownloadService
|
|||||||
import org.koitharu.kotatsu.local.domain.importer.MangaImporter
|
import org.koitharu.kotatsu.local.domain.importer.MangaImporter
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.utils.PendingIntentCompat
|
import org.koitharu.kotatsu.utils.PendingIntentCompat
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.asArrayList
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.referer
|
||||||
|
import org.koitharu.kotatsu.utils.ext.report
|
||||||
|
import org.koitharu.kotatsu.utils.ext.toBitmapOrNull
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -48,8 +53,8 @@ class ImportService : CoroutineIntentService() {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun processIntent(intent: Intent?) {
|
override suspend fun processIntent(startId: Int, intent: Intent) {
|
||||||
val uris = intent?.getParcelableArrayListExtra<Uri>(EXTRA_URIS)
|
val uris = intent.getParcelableArrayListExtra<Uri>(EXTRA_URIS)
|
||||||
if (uris.isNullOrEmpty()) {
|
if (uris.isNullOrEmpty()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -69,6 +74,10 @@ class ImportService : CoroutineIntentService() {
|
|||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onError(startId: Int, error: Throwable) {
|
||||||
|
error.report()
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun importImpl(uri: Uri): Manga {
|
private suspend fun importImpl(uri: Uri): Manga {
|
||||||
val importer = importerFactory.create(uri)
|
val importer = importerFactory.create(uri)
|
||||||
return importer.import(uri)
|
return importer.import(uri)
|
||||||
|
|||||||
@@ -9,13 +9,15 @@ import androidx.core.app.NotificationCompat
|
|||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.CoroutineIntentService
|
import org.koitharu.kotatsu.base.ui.CoroutineIntentService
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class LocalChaptersRemoveService : CoroutineIntentService() {
|
class LocalChaptersRemoveService : CoroutineIntentService() {
|
||||||
@@ -33,8 +35,8 @@ class LocalChaptersRemoveService : CoroutineIntentService() {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun processIntent(intent: Intent?) {
|
override suspend fun processIntent(startId: Int, intent: Intent) {
|
||||||
val manga = intent?.getParcelableExtra<ParcelableManga>(EXTRA_MANGA)?.manga ?: return
|
val manga = intent.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga ?: return
|
||||||
val chaptersIds = intent.getLongArrayExtra(EXTRA_CHAPTERS_IDS)?.toSet() ?: return
|
val chaptersIds = intent.getLongArrayExtra(EXTRA_CHAPTERS_IDS)?.toSet() ?: return
|
||||||
startForeground()
|
startForeground()
|
||||||
val mangaWithChapters = localMangaRepository.getDetails(manga)
|
val mangaWithChapters = localMangaRepository.getDetails(manga)
|
||||||
@@ -46,6 +48,21 @@ class LocalChaptersRemoveService : CoroutineIntentService() {
|
|||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onError(startId: Int, error: Throwable) {
|
||||||
|
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
|
||||||
|
.setContentTitle(getString(R.string.error_occurred))
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
|
.setDefaults(0)
|
||||||
|
.setColor(ContextCompat.getColor(this, R.color.blue_primary_dark))
|
||||||
|
.setSilent(true)
|
||||||
|
.setContentText(error.getDisplayMessage(resources))
|
||||||
|
.setSmallIcon(android.R.drawable.stat_notify_error)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.build()
|
||||||
|
val nm = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
nm.notify(NOTIFICATION_ID + startId, notification)
|
||||||
|
}
|
||||||
|
|
||||||
private fun startForeground() {
|
private fun startForeground() {
|
||||||
val title = getString(R.string.local_manga_processing)
|
val title = getString(R.string.local_manga_processing)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
|||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class LocalListViewModel @Inject constructor(
|
class LocalListViewModel @Inject constructor(
|
||||||
@@ -63,6 +64,7 @@ class LocalListViewModel @Inject constructor(
|
|||||||
actionStringRes = R.string._import,
|
actionStringRes = R.string._import,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> buildList(list.size + 1) {
|
else -> buildList(list.size + 1) {
|
||||||
add(createHeader(list, tags, order))
|
add(createHeader(list, tags, order))
|
||||||
list.toUi(this, mode, this@LocalListViewModel)
|
list.toUi(this, mode, this@LocalListViewModel)
|
||||||
@@ -104,7 +106,7 @@ class LocalListViewModel @Inject constructor(
|
|||||||
for (manga in itemsToRemove) {
|
for (manga in itemsToRemove) {
|
||||||
val original = repository.getRemoteManga(manga)
|
val original = repository.getRemoteManga(manga)
|
||||||
repository.delete(manga) || throw IOException("Unable to delete file")
|
repository.delete(manga) || throw IOException("Unable to delete file")
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
historyRepository.deleteOrSwap(manga, original)
|
historyRepository.deleteOrSwap(manga, original)
|
||||||
}
|
}
|
||||||
mangaList.update { list ->
|
mangaList.update { list ->
|
||||||
@@ -120,6 +122,8 @@ class LocalListViewModel @Inject constructor(
|
|||||||
try {
|
try {
|
||||||
listError.value = null
|
listError.value = null
|
||||||
mangaList.value = repository.getList(0, selectedTags.value, sortOrder.value)
|
mangaList.value = repository.getList(0, selectedTags.value, sortOrder.value)
|
||||||
|
} catch (e: CancellationException) {
|
||||||
|
throw e
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
listError.value = e
|
listError.value = e
|
||||||
}
|
}
|
||||||
@@ -128,7 +132,7 @@ class LocalListViewModel @Inject constructor(
|
|||||||
private fun cleanup() {
|
private fun cleanup() {
|
||||||
if (!DownloadService.isRunning && !ImportService.isRunning && !LocalChaptersRemoveService.isRunning) {
|
if (!DownloadService.isRunning && !ImportService.isRunning && !LocalChaptersRemoveService.isRunning) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
repository.cleanup()
|
repository.cleanup()
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
error.printStackTraceDebug()
|
error.printStackTraceDebug()
|
||||||
|
|||||||
@@ -15,25 +15,33 @@ import androidx.core.app.ActivityOptionsCompat
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.util.size
|
import androidx.core.util.size
|
||||||
import androidx.core.view.*
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.core.view.inputmethod.EditorInfoCompat
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
|
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.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.lifecycle.whenResumed
|
||||||
import androidx.transition.TransitionManager
|
import androidx.transition.TransitionManager
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import com.google.android.material.appbar.AppBarLayout.LayoutParams.*
|
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
|
||||||
|
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL
|
||||||
|
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
|
||||||
|
import com.google.android.material.appbar.AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP
|
||||||
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.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BaseActivity
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.base.ui.widgets.SlidingBottomNavigationView
|
import org.koitharu.kotatsu.base.ui.widgets.SlidingBottomNavigationView
|
||||||
import org.koitharu.kotatsu.databinding.ActivityMainBinding
|
import org.koitharu.kotatsu.databinding.ActivityMainBinding
|
||||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
import org.koitharu.kotatsu.library.ui.LibraryFragment
|
|
||||||
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
||||||
import org.koitharu.kotatsu.main.ui.owners.BottomNavOwner
|
import org.koitharu.kotatsu.main.ui.owners.BottomNavOwner
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
@@ -47,10 +55,18 @@ import org.koitharu.kotatsu.search.ui.suggestion.SearchSuggestionListener
|
|||||||
import org.koitharu.kotatsu.search.ui.suggestion.SearchSuggestionViewModel
|
import org.koitharu.kotatsu.search.ui.suggestion.SearchSuggestionViewModel
|
||||||
import org.koitharu.kotatsu.settings.newsources.NewSourcesDialogFragment
|
import org.koitharu.kotatsu.settings.newsources.NewSourcesDialogFragment
|
||||||
import org.koitharu.kotatsu.settings.onboard.OnboardDialogFragment
|
import org.koitharu.kotatsu.settings.onboard.OnboardDialogFragment
|
||||||
|
import org.koitharu.kotatsu.shelf.ui.ShelfFragment
|
||||||
import org.koitharu.kotatsu.suggestions.ui.SuggestionsWorker
|
import org.koitharu.kotatsu.suggestions.ui.SuggestionsWorker
|
||||||
import org.koitharu.kotatsu.tracker.work.TrackWorker
|
import org.koitharu.kotatsu.tracker.work.TrackWorker
|
||||||
import org.koitharu.kotatsu.utils.VoiceInputContract
|
import org.koitharu.kotatsu.utils.VoiceInputContract
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.drawableEnd
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.hideKeyboard
|
||||||
|
import org.koitharu.kotatsu.utils.ext.resolve
|
||||||
|
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setNavigationBarTransparentCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.tryLaunch
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
private const val TAG_SEARCH = "search"
|
private const val TAG_SEARCH = "search"
|
||||||
|
|
||||||
@@ -114,6 +130,8 @@ class MainActivity :
|
|||||||
viewModel.isLoading.observe(this, this::onLoadingStateChanged)
|
viewModel.isLoading.observe(this, this::onLoadingStateChanged)
|
||||||
viewModel.isResumeEnabled.observe(this, this::onResumeEnabledChanged)
|
viewModel.isResumeEnabled.observe(this, this::onResumeEnabledChanged)
|
||||||
viewModel.counters.observe(this, ::onCountersChanged)
|
viewModel.counters.observe(this, ::onCountersChanged)
|
||||||
|
viewModel.isFeedAvailable.observe(this, ::onFeedAvailabilityChanged)
|
||||||
|
searchSuggestionViewModel.isIncognitoModeEnabled.observe(this, this::onIncognitoModeChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||||
@@ -126,20 +144,18 @@ class MainActivity :
|
|||||||
binding.searchView.clearFocus()
|
binding.searchView.clearFocus()
|
||||||
when {
|
when {
|
||||||
fragment != null -> supportFragmentManager.commit {
|
fragment != null -> supportFragmentManager.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
remove(fragment)
|
remove(fragment)
|
||||||
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||||
runOnCommit { onSearchClosed() }
|
runOnCommit { onSearchClosed() }
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> super.onBackPressed()
|
else -> super.onBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFragmentChanged(fragment: Fragment, fromUser: Boolean) {
|
override fun onFragmentChanged(fragment: Fragment, fromUser: Boolean) {
|
||||||
if (fragment is LibraryFragment) {
|
adjustFabVisibility(topFragment = fragment)
|
||||||
binding.fab?.show()
|
|
||||||
} else {
|
|
||||||
binding.fab?.hide()
|
|
||||||
}
|
|
||||||
if (fromUser) {
|
if (fromUser) {
|
||||||
binding.appbar.setExpanded(true)
|
binding.appbar.setExpanded(true)
|
||||||
}
|
}
|
||||||
@@ -172,6 +188,7 @@ class MainActivity :
|
|||||||
if (v?.id == R.id.searchView && hasFocus) {
|
if (v?.id == R.id.searchView && hasFocus) {
|
||||||
if (fragment == null) {
|
if (fragment == null) {
|
||||||
supportFragmentManager.commit {
|
supportFragmentManager.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
add(R.id.container, SearchSuggestionFragment.newInstance(), TAG_SEARCH)
|
add(R.id.container, SearchSuggestionFragment.newInstance(), TAG_SEARCH)
|
||||||
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||||
runOnCommit { onSearchOpened() }
|
runOnCommit { onSearchOpened() }
|
||||||
@@ -256,6 +273,20 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun onFeedAvailabilityChanged(isFeedAvailable: Boolean) {
|
||||||
|
navigationDelegate.setItemVisibility(R.id.nav_feed, isFeedAvailable)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onIncognitoModeChanged(isIncognito: Boolean) {
|
||||||
|
var options = binding.searchView.imeOptions
|
||||||
|
options = if (isIncognito) {
|
||||||
|
options or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING
|
||||||
|
} else {
|
||||||
|
options and EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING.inv()
|
||||||
|
}
|
||||||
|
binding.searchView.imeOptions = options
|
||||||
|
}
|
||||||
|
|
||||||
private fun onLoadingStateChanged(isLoading: Boolean) {
|
private fun onLoadingStateChanged(isLoading: Boolean) {
|
||||||
binding.fab?.isEnabled = !isLoading
|
binding.fab?.isEnabled = !isLoading
|
||||||
}
|
}
|
||||||
@@ -289,16 +320,21 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onFirstStart() {
|
private fun onFirstStart() {
|
||||||
lifecycleScope.launchWhenResumed {
|
lifecycleScope.launch(Dispatchers.Main) { // not a default `Main.immediate` dispatcher
|
||||||
|
when {
|
||||||
|
!settings.isSourcesSelected -> whenResumed {
|
||||||
|
OnboardDialogFragment.showWelcome(supportFragmentManager)
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.newSources.isNotEmpty() -> whenResumed {
|
||||||
|
NewSourcesDialogFragment.show(supportFragmentManager)
|
||||||
|
}
|
||||||
|
}
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
TrackWorker.setup(applicationContext)
|
TrackWorker.setup(applicationContext)
|
||||||
SuggestionsWorker.setup(applicationContext)
|
SuggestionsWorker.setup(applicationContext)
|
||||||
}
|
}
|
||||||
requestNotificationsPermission()
|
requestNotificationsPermission()
|
||||||
when {
|
|
||||||
!settings.isSourcesSelected -> OnboardDialogFragment.showWelcome(supportFragmentManager)
|
|
||||||
settings.newSources.isNotEmpty() -> NewSourcesDialogFragment.show(supportFragmentManager)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,18 +343,18 @@ class MainActivity :
|
|||||||
topFragment: Fragment? = navigationDelegate.primaryFragment,
|
topFragment: Fragment? = navigationDelegate.primaryFragment,
|
||||||
isSearchOpened: Boolean = isSearchOpened(),
|
isSearchOpened: Boolean = isSearchOpened(),
|
||||||
) {
|
) {
|
||||||
val fab = binding.fab
|
val fab = binding.fab ?: return
|
||||||
if (
|
if (
|
||||||
isResumeEnabled &&
|
isResumeEnabled &&
|
||||||
!actionModeDelegate.isActionModeStarted &&
|
!actionModeDelegate.isActionModeStarted &&
|
||||||
!isSearchOpened &&
|
!isSearchOpened &&
|
||||||
topFragment is LibraryFragment
|
topFragment is ShelfFragment
|
||||||
) {
|
) {
|
||||||
if (fab?.isVisible == false) {
|
if (!fab.isVisible) {
|
||||||
fab.show()
|
fab.show()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fab?.isVisible == true) {
|
if (fab.isVisible) {
|
||||||
fab.hide()
|
fab.hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.main.ui
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.annotation.IdRes
|
import androidx.annotation.IdRes
|
||||||
|
import androidx.core.view.iterator
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.fragment.app.FragmentTransaction
|
import androidx.fragment.app.FragmentTransaction
|
||||||
@@ -10,10 +11,10 @@ import com.google.android.material.navigation.NavigationBarView
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
||||||
import org.koitharu.kotatsu.explore.ui.ExploreFragment
|
import org.koitharu.kotatsu.explore.ui.ExploreFragment
|
||||||
import org.koitharu.kotatsu.library.ui.LibraryFragment
|
|
||||||
import org.koitharu.kotatsu.settings.tools.ToolsFragment
|
import org.koitharu.kotatsu.settings.tools.ToolsFragment
|
||||||
import org.koitharu.kotatsu.tracker.ui.FeedFragment
|
import org.koitharu.kotatsu.shelf.ui.ShelfFragment
|
||||||
import java.util.*
|
import org.koitharu.kotatsu.tracker.ui.feed.FeedFragment
|
||||||
|
import java.util.LinkedList
|
||||||
|
|
||||||
private const val TAG_PRIMARY = "primary"
|
private const val TAG_PRIMARY = "primary"
|
||||||
|
|
||||||
@@ -62,6 +63,14 @@ class MainNavigationDelegate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setItemVisibility(@IdRes itemId: Int, isVisible: Boolean) {
|
||||||
|
val item = navBar.menu.findItem(itemId) ?: return
|
||||||
|
item.isVisible = isVisible
|
||||||
|
if (item.isChecked && !isVisible) {
|
||||||
|
navBar.selectedItemId = firstItem()?.itemId ?: return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun addOnFragmentChangedListener(listener: OnFragmentChangedListener) {
|
fun addOnFragmentChangedListener(listener: OnFragmentChangedListener) {
|
||||||
listeners.add(listener)
|
listeners.add(listener)
|
||||||
}
|
}
|
||||||
@@ -73,7 +82,7 @@ class MainNavigationDelegate(
|
|||||||
private fun onNavigationItemSelected(@IdRes itemId: Int): Boolean {
|
private fun onNavigationItemSelected(@IdRes itemId: Int): Boolean {
|
||||||
setPrimaryFragment(
|
setPrimaryFragment(
|
||||||
when (itemId) {
|
when (itemId) {
|
||||||
R.id.nav_library -> LibraryFragment.newInstance()
|
R.id.nav_shelf -> ShelfFragment.newInstance()
|
||||||
R.id.nav_explore -> ExploreFragment.newInstance()
|
R.id.nav_explore -> ExploreFragment.newInstance()
|
||||||
R.id.nav_feed -> FeedFragment.newInstance()
|
R.id.nav_feed -> FeedFragment.newInstance()
|
||||||
R.id.nav_tools -> ToolsFragment.newInstance()
|
R.id.nav_tools -> ToolsFragment.newInstance()
|
||||||
@@ -85,6 +94,7 @@ class MainNavigationDelegate(
|
|||||||
|
|
||||||
private fun setPrimaryFragment(fragment: Fragment) {
|
private fun setPrimaryFragment(fragment: Fragment) {
|
||||||
fragmentManager.beginTransaction()
|
fragmentManager.beginTransaction()
|
||||||
|
.setReorderingAllowed(true)
|
||||||
.replace(R.id.container, fragment, TAG_PRIMARY)
|
.replace(R.id.container, fragment, TAG_PRIMARY)
|
||||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||||
.commit()
|
.commit()
|
||||||
@@ -95,6 +105,14 @@ class MainNavigationDelegate(
|
|||||||
listeners.forEach { it.onFragmentChanged(fragment, fromUser) }
|
listeners.forEach { it.onFragmentChanged(fragment, fromUser) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun firstItem(): MenuItem? {
|
||||||
|
val menu = navBar.menu
|
||||||
|
for (item in menu) {
|
||||||
|
if (item.isVisible) return item
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
interface OnFragmentChangedListener {
|
interface OnFragmentChangedListener {
|
||||||
|
|
||||||
fun onFragmentChanged(fragment: Fragment, fromUser: Boolean)
|
fun onFragmentChanged(fragment: Fragment, fromUser: Boolean)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.util.SparseIntArray
|
|||||||
import androidx.core.util.set
|
import androidx.core.util.set
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
@@ -12,6 +11,9 @@ import org.koitharu.kotatsu.base.ui.BaseViewModel
|
|||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException
|
import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException
|
||||||
import org.koitharu.kotatsu.core.github.AppUpdateRepository
|
import org.koitharu.kotatsu.core.github.AppUpdateRepository
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
|
import org.koitharu.kotatsu.core.prefs.observeAsLiveData
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.sync.domain.SyncController
|
import org.koitharu.kotatsu.sync.domain.SyncController
|
||||||
@@ -19,6 +21,7 @@ import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
|||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
import org.koitharu.kotatsu.utils.asFlowLiveData
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class MainViewModel @Inject constructor(
|
class MainViewModel @Inject constructor(
|
||||||
@@ -27,13 +30,23 @@ class MainViewModel @Inject constructor(
|
|||||||
private val trackingRepository: TrackingRepository,
|
private val trackingRepository: TrackingRepository,
|
||||||
syncController: SyncController,
|
syncController: SyncController,
|
||||||
database: MangaDatabase,
|
database: MangaDatabase,
|
||||||
|
private val settings: AppSettings,
|
||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
|
|
||||||
val onOpenReader = SingleLiveEvent<Manga>()
|
val onOpenReader = SingleLiveEvent<Manga>()
|
||||||
|
|
||||||
val isResumeEnabled = historyRepository
|
val isResumeEnabled = combine(
|
||||||
.observeHasItems()
|
historyRepository.observeHasItems(),
|
||||||
.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, false)
|
settings.observeAsFlow(AppSettings.KEY_INCOGNITO_MODE) { isIncognitoModeEnabled },
|
||||||
|
) { hasItems, incognito ->
|
||||||
|
hasItems && !incognito
|
||||||
|
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, false)
|
||||||
|
|
||||||
|
val isFeedAvailable = settings.observeAsLiveData(
|
||||||
|
context = viewModelScope.coroutineContext + Dispatchers.Default,
|
||||||
|
key = AppSettings.KEY_TRACKER_ENABLED,
|
||||||
|
valueProducer = { isTrackerEnabled },
|
||||||
|
)
|
||||||
|
|
||||||
val counters = combine(
|
val counters = combine(
|
||||||
appUpdateRepository.observeAvailableUpdate(),
|
appUpdateRepository.observeAvailableUpdate(),
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
package org.koitharu.kotatsu.main.ui.protect
|
package org.koitharu.kotatsu.main.ui.protect
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.Application
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import org.acra.dialog.CrashReportDialog
|
||||||
|
import org.koitharu.kotatsu.base.ui.DefaultActivityLifecycleCallbacks
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import org.acra.dialog.CrashReportDialog
|
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class AppProtectHelper @Inject constructor(private val settings: AppSettings) : Application.ActivityLifecycleCallbacks {
|
class AppProtectHelper @Inject constructor(private val settings: AppSettings) : DefaultActivityLifecycleCallbacks {
|
||||||
|
|
||||||
private var isUnlocked = settings.appPassword.isNullOrEmpty()
|
private var isUnlocked = settings.appPassword.isNullOrEmpty()
|
||||||
|
|
||||||
@@ -27,16 +27,6 @@ class AppProtectHelper @Inject constructor(private val settings: AppSettings) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityStarted(activity: Activity) = Unit
|
|
||||||
|
|
||||||
override fun onActivityResumed(activity: Activity) = Unit
|
|
||||||
|
|
||||||
override fun onActivityPaused(activity: Activity) = Unit
|
|
||||||
|
|
||||||
override fun onActivityStopped(activity: Activity) = Unit
|
|
||||||
|
|
||||||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit
|
|
||||||
|
|
||||||
override fun onActivityDestroyed(activity: Activity) {
|
override fun onActivityDestroyed(activity: Activity) {
|
||||||
if (activity !is ProtectActivity && activity.isFinishing && activity.isTaskRoot) {
|
if (activity !is ProtectActivity && activity.isFinishing && activity.isTaskRoot) {
|
||||||
restoreLock()
|
restoreLock()
|
||||||
|
|||||||
@@ -49,7 +49,10 @@ class ProtectActivity :
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
finishAfterTransition()
|
finishAfterTransition()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
if (!useFingerprint()) {
|
if (!useFingerprint()) {
|
||||||
binding.editPassword.requestFocus()
|
binding.editPassword.requestFocus()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,16 @@ import android.net.Uri
|
|||||||
import androidx.collection.LongSparseArray
|
import androidx.collection.LongSparseArray
|
||||||
import androidx.collection.set
|
import androidx.collection.set
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.io.File
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import java.util.*
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import java.util.zip.ZipFile
|
import kotlinx.coroutines.Dispatchers
|
||||||
import javax.inject.Inject
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.runInterruptible
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@@ -30,7 +32,16 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
|||||||
import org.koitharu.kotatsu.parsers.util.await
|
import org.koitharu.kotatsu.parsers.util.await
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
||||||
import org.koitharu.kotatsu.utils.ext.connectivityManager
|
import org.koitharu.kotatsu.utils.ext.connectivityManager
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.withProgress
|
||||||
import org.koitharu.kotatsu.utils.progress.ProgressDeferred
|
import org.koitharu.kotatsu.utils.progress.ProgressDeferred
|
||||||
|
import java.io.File
|
||||||
|
import java.util.LinkedList
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
import java.util.zip.ZipFile
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.coroutines.AbstractCoroutineContextElement
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
private const val PROGRESS_UNDEFINED = -1f
|
private const val PROGRESS_UNDEFINED = -1f
|
||||||
private const val PREFETCH_LIMIT_DEFAULT = 10
|
private const val PREFETCH_LIMIT_DEFAULT = 10
|
||||||
@@ -43,7 +54,7 @@ class PageLoader @Inject constructor(
|
|||||||
private val mangaRepositoryFactory: MangaRepository.Factory,
|
private val mangaRepositoryFactory: MangaRepository.Factory,
|
||||||
) : Closeable {
|
) : Closeable {
|
||||||
|
|
||||||
val loaderScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
val loaderScope = CoroutineScope(SupervisorJob() + InternalErrorHandler() + Dispatchers.Default)
|
||||||
|
|
||||||
private val connectivityManager = context.connectivityManager
|
private val connectivityManager = context.connectivityManager
|
||||||
private val tasks = LongSparseArray<ProgressDeferred<File, Float>>()
|
private val tasks = LongSparseArray<ProgressDeferred<File, Float>>()
|
||||||
@@ -56,7 +67,9 @@ class PageLoader @Inject constructor(
|
|||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
loaderScope.cancel()
|
loaderScope.cancel()
|
||||||
tasks.clear()
|
synchronized(tasks) {
|
||||||
|
tasks.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isPrefetchApplicable(): Boolean {
|
fun isPrefetchApplicable(): Boolean {
|
||||||
@@ -93,7 +106,9 @@ class PageLoader @Inject constructor(
|
|||||||
return task
|
return task
|
||||||
}
|
}
|
||||||
task = loadPageAsyncImpl(page)
|
task = loadPageAsyncImpl(page)
|
||||||
tasks[page.id] = task
|
synchronized(tasks) {
|
||||||
|
tasks[page.id] = task
|
||||||
|
}
|
||||||
return task
|
return task
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +140,9 @@ class PageLoader @Inject constructor(
|
|||||||
while (prefetchQueue.isNotEmpty()) {
|
while (prefetchQueue.isNotEmpty()) {
|
||||||
val page = prefetchQueue.pollFirst() ?: return
|
val page = prefetchQueue.pollFirst() ?: return
|
||||||
if (cache[page.url] == null) {
|
if (cache[page.url] == null) {
|
||||||
tasks[page.id] = loadPageAsyncImpl(page)
|
synchronized(tasks) {
|
||||||
|
tasks[page.id] = loadPageAsyncImpl(page)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,9 +180,12 @@ class PageLoader @Inject constructor(
|
|||||||
val uri = Uri.parse(pageUrl)
|
val uri = Uri.parse(pageUrl)
|
||||||
return if (uri.scheme == "cbz") {
|
return if (uri.scheme == "cbz") {
|
||||||
runInterruptible(Dispatchers.IO) {
|
runInterruptible(Dispatchers.IO) {
|
||||||
val zip = ZipFile(uri.schemeSpecificPart)
|
ZipFile(uri.schemeSpecificPart)
|
||||||
val entry = zip.getEntry(uri.fragment)
|
}.use { zip ->
|
||||||
zip.getInputStream(entry).use {
|
runInterruptible(Dispatchers.IO) {
|
||||||
|
val entry = zip.getEntry(uri.fragment)
|
||||||
|
zip.getInputStream(entry)
|
||||||
|
}.use {
|
||||||
cache.put(pageUrl, it)
|
cache.put(pageUrl, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,10 +204,8 @@ class PageLoader @Inject constructor(
|
|||||||
val body = checkNotNull(response.body) {
|
val body = checkNotNull(response.body) {
|
||||||
"Null response"
|
"Null response"
|
||||||
}
|
}
|
||||||
runInterruptible(Dispatchers.IO) {
|
body.withProgress(progress).byteStream().use {
|
||||||
body.byteStream().use {
|
cache.put(pageUrl, it)
|
||||||
cache.put(pageUrl, it, body.contentLength(), progress)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,4 +215,13 @@ class PageLoader @Inject constructor(
|
|||||||
val deferred = CompletableDeferred(file)
|
val deferred = CompletableDeferred(file)
|
||||||
return ProgressDeferred(deferred, emptyProgressFlow)
|
return ProgressDeferred(deferred, emptyProgressFlow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class InternalErrorHandler : AbstractCoroutineContextElement(CoroutineExceptionHandler),
|
||||||
|
CoroutineExceptionHandler {
|
||||||
|
|
||||||
|
override fun handleException(context: CoroutineContext, exception: Throwable) {
|
||||||
|
exception.printStackTraceDebug()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ import android.webkit.MimeTypeMap
|
|||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.io.File
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.coroutines.Continuation
|
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runInterruptible
|
import kotlinx.coroutines.runInterruptible
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
@@ -20,6 +16,11 @@ import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
import org.koitharu.kotatsu.parsers.util.toFileNameSafe
|
import org.koitharu.kotatsu.parsers.util.toFileNameSafe
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
|
import org.koitharu.kotatsu.utils.ext.copyToSuspending
|
||||||
|
import java.io.File
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.coroutines.Continuation
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
|
||||||
private const val MAX_FILENAME_LENGTH = 10
|
private const val MAX_FILENAME_LENGTH = 10
|
||||||
private const val EXTENSION_FALLBACK = "png"
|
private const val EXTENSION_FALLBACK = "png"
|
||||||
@@ -48,12 +49,12 @@ class PageSaveHelper @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
runInterruptible(Dispatchers.IO) {
|
runInterruptible(Dispatchers.IO) {
|
||||||
contentResolver.openOutputStream(destination)?.use { output ->
|
contentResolver.openOutputStream(destination)
|
||||||
pageFile.inputStream().use { input ->
|
}?.use { output ->
|
||||||
input.copyTo(output)
|
pageFile.inputStream().use { input ->
|
||||||
}
|
input.copyToSuspending(output)
|
||||||
} ?: throw IOException("Output stream is null")
|
}
|
||||||
}
|
} ?: throw IOException("Output stream is null")
|
||||||
return destination
|
return destination
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,15 +9,23 @@ import android.transition.Fade
|
|||||||
import android.transition.Slide
|
import android.transition.Slide
|
||||||
import android.transition.TransitionManager
|
import android.transition.TransitionManager
|
||||||
import android.transition.TransitionSet
|
import android.transition.TransitionSet
|
||||||
import android.view.*
|
import android.view.Gravity
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.*
|
import androidx.core.view.OnApplyWindowInsetsListener
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.core.view.isGone
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
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 java.util.concurrent.TimeUnit
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -42,7 +50,17 @@ import org.koitharu.kotatsu.settings.SettingsActivity
|
|||||||
import org.koitharu.kotatsu.utils.GridTouchHelper
|
import org.koitharu.kotatsu.utils.GridTouchHelper
|
||||||
import org.koitharu.kotatsu.utils.IdlingDetector
|
import org.koitharu.kotatsu.utils.IdlingDetector
|
||||||
import org.koitharu.kotatsu.utils.ShareHelper
|
import org.koitharu.kotatsu.utils.ShareHelper
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.assistedViewModels
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.hasGlobalPoint
|
||||||
|
import org.koitharu.kotatsu.utils.ext.isReportable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.observeWithPrevious
|
||||||
|
import org.koitharu.kotatsu.utils.ext.postDelayed
|
||||||
|
import org.koitharu.kotatsu.utils.ext.report
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setValueRounded
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ReaderActivity :
|
class ReaderActivity :
|
||||||
@@ -145,6 +163,7 @@ class ReaderActivity :
|
|||||||
R.id.action_settings -> {
|
R.id.action_settings -> {
|
||||||
startActivity(SettingsActivity.newReaderSettingsIntent(this))
|
startActivity(SettingsActivity.newReaderSettingsIntent(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_chapters -> {
|
R.id.action_chapters -> {
|
||||||
ChaptersBottomSheet.show(
|
ChaptersBottomSheet.show(
|
||||||
supportFragmentManager,
|
supportFragmentManager,
|
||||||
@@ -152,6 +171,7 @@ class ReaderActivity :
|
|||||||
viewModel.getCurrentState()?.chapterId ?: 0L,
|
viewModel.getCurrentState()?.chapterId ?: 0L,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_pages_thumbs -> {
|
R.id.action_pages_thumbs -> {
|
||||||
val pages = viewModel.getCurrentChapterPages()
|
val pages = viewModel.getCurrentChapterPages()
|
||||||
if (!pages.isNullOrEmpty()) {
|
if (!pages.isNullOrEmpty()) {
|
||||||
@@ -165,6 +185,7 @@ class ReaderActivity :
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_bookmark -> {
|
R.id.action_bookmark -> {
|
||||||
if (viewModel.isBookmarkAdded.value == true) {
|
if (viewModel.isBookmarkAdded.value == true) {
|
||||||
viewModel.removeBookmark()
|
viewModel.removeBookmark()
|
||||||
@@ -172,11 +193,13 @@ class ReaderActivity :
|
|||||||
viewModel.addBookmark()
|
viewModel.addBookmark()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_options -> {
|
R.id.action_options -> {
|
||||||
viewModel.saveCurrentState(readerManager.currentReader?.getCurrentState())
|
viewModel.saveCurrentState(readerManager.currentReader?.getCurrentState())
|
||||||
val currentMode = readerManager.currentMode ?: return false
|
val currentMode = readerManager.currentMode ?: return false
|
||||||
ReaderConfigBottomSheet.show(supportFragmentManager, currentMode)
|
ReaderConfigBottomSheet.show(supportFragmentManager, currentMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -205,7 +228,7 @@ class ReaderActivity :
|
|||||||
val resolveTextId = ExceptionResolver.getResolveStringId(e)
|
val resolveTextId = ExceptionResolver.getResolveStringId(e)
|
||||||
if (resolveTextId != 0) {
|
if (resolveTextId != 0) {
|
||||||
dialog.setPositiveButton(resolveTextId, listener)
|
dialog.setPositiveButton(resolveTextId, listener)
|
||||||
} else {
|
} else if (e.isReportable()) {
|
||||||
dialog.setPositiveButton(R.string.report, listener)
|
dialog.setPositiveButton(R.string.report, listener)
|
||||||
}
|
}
|
||||||
dialog.show()
|
dialog.show()
|
||||||
@@ -364,9 +387,9 @@ class ReaderActivity :
|
|||||||
binding.toastView.showTemporary(uiState.chapterName, TOAST_DURATION)
|
binding.toastView.showTemporary(uiState.chapterName, TOAST_DURATION)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uiState.totalPages > 1 && uiState.currentPage < uiState.totalPages) {
|
if (uiState.isSliderAvailable()) {
|
||||||
binding.slider.valueTo = uiState.totalPages.toFloat() - 1
|
binding.slider.valueTo = uiState.totalPages.toFloat() - 1
|
||||||
binding.slider.value = uiState.currentPage.toFloat()
|
binding.slider.setValueRounded(uiState.currentPage.toFloat())
|
||||||
binding.slider.isVisible = true
|
binding.slider.isVisible = true
|
||||||
} else {
|
} else {
|
||||||
binding.slider.isVisible = false
|
binding.slider.isVisible = false
|
||||||
@@ -383,7 +406,7 @@ class ReaderActivity :
|
|||||||
if (ExceptionResolver.canResolve(exception)) {
|
if (ExceptionResolver.canResolve(exception)) {
|
||||||
tryResolve(exception)
|
tryResolve(exception)
|
||||||
} else {
|
} else {
|
||||||
exception.report("ReaderActivity::onError")
|
exception.report()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
onCancel(dialog)
|
onCancel(dialog)
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.reader.ui
|
|
||||||
|
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.fragment.app.FragmentManager
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
|
||||||
import org.koitharu.kotatsu.base.ui.widgets.CheckableButtonGroup
|
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
|
||||||
import org.koitharu.kotatsu.databinding.DialogReaderConfigBinding
|
|
||||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
|
||||||
|
|
||||||
@Deprecated("Not in use")
|
|
||||||
class ReaderConfigDialog :
|
|
||||||
AlertDialogFragment<DialogReaderConfigBinding>(),
|
|
||||||
CheckableButtonGroup.OnCheckedChangeListener {
|
|
||||||
|
|
||||||
private lateinit var mode: ReaderMode
|
|
||||||
|
|
||||||
override fun onInflateView(
|
|
||||||
inflater: LayoutInflater,
|
|
||||||
container: ViewGroup?,
|
|
||||||
) = DialogReaderConfigBinding.inflate(inflater, container, false)
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
mode = arguments?.getInt(ARG_MODE)
|
|
||||||
?.let { ReaderMode.valueOf(it) }
|
|
||||||
?: ReaderMode.STANDARD
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBuildDialog(builder: MaterialAlertDialogBuilder): MaterialAlertDialogBuilder {
|
|
||||||
return super.onBuildDialog(builder)
|
|
||||||
.setTitle(R.string.read_mode)
|
|
||||||
.setPositiveButton(R.string.done, null)
|
|
||||||
.setCancelable(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
binding.buttonStandard.isChecked = mode == ReaderMode.STANDARD
|
|
||||||
binding.buttonReversed.isChecked = mode == ReaderMode.REVERSED
|
|
||||||
binding.buttonWebtoon.isChecked = mode == ReaderMode.WEBTOON
|
|
||||||
|
|
||||||
binding.checkableGroup.onCheckedChangeListener = this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDismiss(dialog: DialogInterface) {
|
|
||||||
(
|
|
||||||
(parentFragment as? Callback)
|
|
||||||
?: (activity as? Callback)
|
|
||||||
)?.onReaderModeChanged(mode)
|
|
||||||
super.onDismiss(dialog)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCheckedChanged(group: CheckableButtonGroup, checkedId: Int) {
|
|
||||||
mode = when (checkedId) {
|
|
||||||
R.id.button_standard -> ReaderMode.STANDARD
|
|
||||||
R.id.button_webtoon -> ReaderMode.WEBTOON
|
|
||||||
R.id.button_reversed -> ReaderMode.REVERSED
|
|
||||||
else -> return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Callback {
|
|
||||||
|
|
||||||
fun onReaderModeChanged(mode: ReaderMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
private const val TAG = "ReaderConfigDialog"
|
|
||||||
private const val ARG_MODE = "mode"
|
|
||||||
|
|
||||||
fun show(fm: FragmentManager, mode: ReaderMode) = ReaderConfigDialog().withArgs(1) {
|
|
||||||
putInt(ARG_MODE, mode.id)
|
|
||||||
}.show(fm, TAG)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -62,8 +62,9 @@ class ReaderInfoBarView @JvmOverloads constructor(
|
|||||||
init {
|
init {
|
||||||
paint.strokeWidth = context.resources.resolveDp(2f)
|
paint.strokeWidth = context.resources.resolveDp(2f)
|
||||||
val insetCorner = getSystemUiDimensionOffset("rounded_corner_content_padding")
|
val insetCorner = getSystemUiDimensionOffset("rounded_corner_content_padding")
|
||||||
val insetStart = getSystemUiDimensionOffset("status_bar_padding_start") + insetCorner
|
val fallbackInset = resources.getDimensionPixelOffset(R.dimen.reader_bar_inset_fallback)
|
||||||
val insetEnd = getSystemUiDimensionOffset("status_bar_padding_end") + insetCorner
|
val insetStart = getSystemUiDimensionOffset("status_bar_padding_start", fallbackInset) + insetCorner
|
||||||
|
val insetEnd = getSystemUiDimensionOffset("status_bar_padding_end", fallbackInset) + insetCorner
|
||||||
val isRtl = layoutDirection == LAYOUT_DIRECTION_RTL
|
val isRtl = layoutDirection == LAYOUT_DIRECTION_RTL
|
||||||
insetLeft = if (isRtl) insetEnd else insetStart
|
insetLeft = if (isRtl) insetEnd else insetStart
|
||||||
insetRight = if (isRtl) insetStart else insetEnd
|
insetRight = if (isRtl) insetStart else insetEnd
|
||||||
@@ -179,12 +180,12 @@ class ReaderInfoBarView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSystemUiDimensionOffset(name: String): Int = runCatching {
|
private fun getSystemUiDimensionOffset(name: String, fallback: Int = 0): Int = runCatching {
|
||||||
val manager = context.packageManager
|
val manager = context.packageManager
|
||||||
val resources = manager.getResourcesForApplication("com.android.systemui")
|
val resources = manager.getResourcesForApplication("com.android.systemui")
|
||||||
val resId = resources.getIdentifier(name, "dimen", "com.android.systemui")
|
val resId = resources.getIdentifier(name, "dimen", "com.android.systemui")
|
||||||
resources.getDimensionPixelOffset(resId)
|
resources.getDimensionPixelOffset(resId)
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
it.printStackTraceDebug()
|
it.printStackTraceDebug()
|
||||||
}.getOrDefault(0)
|
}.getOrDefault(fallback)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.koitharu.kotatsu.reader.ui.pager.BaseReader
|
|||||||
import org.koitharu.kotatsu.reader.ui.pager.reversed.ReversedReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.reversed.ReversedReaderFragment
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.webtoon.WebtoonReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.webtoon.WebtoonReaderFragment
|
||||||
import java.util.*
|
import java.util.EnumMap
|
||||||
|
|
||||||
class ReaderManager(
|
class ReaderManager(
|
||||||
private val fragmentManager: FragmentManager,
|
private val fragmentManager: FragmentManager,
|
||||||
@@ -35,11 +35,15 @@ class ReaderManager(
|
|||||||
fun replace(newMode: ReaderMode) {
|
fun replace(newMode: ReaderMode) {
|
||||||
val readerClass = requireNotNull(modeMap[newMode])
|
val readerClass = requireNotNull(modeMap[newMode])
|
||||||
fragmentManager.commit {
|
fragmentManager.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
replace(containerResId, readerClass, null, null)
|
replace(containerResId, readerClass, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun replace(reader: BaseReader<*>) {
|
fun replace(reader: BaseReader<*>) {
|
||||||
fragmentManager.commit { replace(containerResId, reader) }
|
fragmentManager.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
|
replace(containerResId, reader)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,22 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import java.util.*
|
import kotlinx.coroutines.CancellationException
|
||||||
import javax.inject.Provider
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.cancelAndJoin
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.base.domain.MangaIntent
|
import org.koitharu.kotatsu.base.domain.MangaIntent
|
||||||
@@ -21,7 +33,11 @@ import org.koitharu.kotatsu.base.ui.BaseViewModel
|
|||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.*
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||||
|
import org.koitharu.kotatsu.core.prefs.ScreenshotsPolicy
|
||||||
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
|
import org.koitharu.kotatsu.core.prefs.observeAsLiveData
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
||||||
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
||||||
@@ -38,6 +54,9 @@ import org.koitharu.kotatsu.utils.asFlowLiveData
|
|||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.utils.ext.requireValue
|
import org.koitharu.kotatsu.utils.ext.requireValue
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import java.util.Date
|
||||||
|
import javax.inject.Provider
|
||||||
|
|
||||||
private const val BOUNDS_PAGE_OFFSET = 2
|
private const val BOUNDS_PAGE_OFFSET = 2
|
||||||
private const val PREFETCH_LIMIT = 10
|
private const val PREFETCH_LIMIT = 10
|
||||||
@@ -87,6 +106,12 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
valueProducer = { isReaderBarEnabled },
|
valueProducer = { isReaderBarEnabled },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val isWebtoonZoomEnabled = settings.observeAsLiveData(
|
||||||
|
context = viewModelScope.coroutineContext + Dispatchers.Default,
|
||||||
|
key = AppSettings.KEY_WEBTOON_ZOOM,
|
||||||
|
valueProducer = { isWebtoonZoomEnable },
|
||||||
|
)
|
||||||
|
|
||||||
val readerSettings = ReaderSettings(
|
val readerSettings = ReaderSettings(
|
||||||
parentScope = viewModelScope,
|
parentScope = viewModelScope,
|
||||||
settings = settings,
|
settings = settings,
|
||||||
@@ -115,6 +140,10 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
loadImpl()
|
loadImpl()
|
||||||
|
settings.observe()
|
||||||
|
.onEach { key ->
|
||||||
|
if (key == AppSettings.KEY_READER_SLIDER) notifyStateChanged()
|
||||||
|
}.launchIn(viewModelScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
@@ -326,7 +355,7 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
?: manga.chapters?.randomOrNull()
|
?: manga.chapters?.randomOrNull()
|
||||||
?: error("There are no chapters in this manga")
|
?: error("There are no chapters in this manga")
|
||||||
val pages = repo.getPages(chapter)
|
val pages = repo.getPages(chapter)
|
||||||
return runCatching {
|
return runCatchingCancellable {
|
||||||
val isWebtoon = dataRepository.determineMangaIsWebtoon(repo, pages)
|
val isWebtoon = dataRepository.determineMangaIsWebtoon(repo, pages)
|
||||||
if (isWebtoon) ReaderMode.WEBTOON else defaultMode
|
if (isWebtoon) ReaderMode.WEBTOON else defaultMode
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
@@ -347,6 +376,7 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
chaptersTotal = chapters.size(),
|
chaptersTotal = chapters.size(),
|
||||||
totalPages = if (chapter != null) chaptersLoader.getPagesCount(chapter.id) else 0,
|
totalPages = if (chapter != null) chaptersLoader.getPagesCount(chapter.id) else 0,
|
||||||
currentPage = state?.page ?: 0,
|
currentPage = state?.page ?: 0,
|
||||||
|
isSliderEnabled = settings.isReaderSliderEnabled,
|
||||||
)
|
)
|
||||||
uiState.postValue(newState)
|
uiState.postValue(newState)
|
||||||
}
|
}
|
||||||
@@ -381,7 +411,7 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
*/
|
*/
|
||||||
private fun HistoryRepository.saveStateAsync(manga: Manga, state: ReaderState, percent: Float): Job {
|
private fun HistoryRepository.saveStateAsync(manga: Manga, state: ReaderState, percent: Float): Job {
|
||||||
return processLifecycleScope.launch(Dispatchers.Default) {
|
return processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
addOrUpdate(
|
addOrUpdate(
|
||||||
manga = manga,
|
manga = manga,
|
||||||
chapterId = state.chapterId,
|
chapterId = state.chapterId,
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ class ColorFilterConfigActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onColorFilterChanged(readerColorFilter: ReaderColorFilter?) {
|
private fun onColorFilterChanged(readerColorFilter: ReaderColorFilter?) {
|
||||||
binding.sliderBrightness.value = readerColorFilter?.brightness ?: 0f
|
binding.sliderBrightness.setValueRounded(readerColorFilter?.brightness ?: 0f)
|
||||||
binding.sliderContrast.value = readerColorFilter?.contrast ?: 0f
|
binding.sliderContrast.setValueRounded(readerColorFilter?.contrast ?: 0f)
|
||||||
binding.imageViewAfter.colorFilter = readerColorFilter?.toColorFilter()
|
binding.imageViewAfter.colorFilter = readerColorFilter?.toColorFilter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.koitharu.kotatsu.reader.ui.ReaderViewModel
|
|||||||
import org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity
|
import org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity
|
||||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||||
import org.koitharu.kotatsu.utils.ScreenOrientationHelper
|
import org.koitharu.kotatsu.utils.ScreenOrientationHelper
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setValueRounded
|
||||||
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ class ReaderConfigBottomSheet :
|
|||||||
binding.sliderTimer.setLabelFormatter(PageSwitchTimer.DelayLabelFormatter(view.resources))
|
binding.sliderTimer.setLabelFormatter(PageSwitchTimer.DelayLabelFormatter(view.resources))
|
||||||
|
|
||||||
findCallback()?.run {
|
findCallback()?.run {
|
||||||
binding.sliderTimer.value = pageSwitchDelay
|
binding.sliderTimer.setValueRounded(pageSwitchDelay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,13 +76,16 @@ class ReaderConfigBottomSheet :
|
|||||||
startActivity(SettingsActivity.newReaderSettingsIntent(v.context))
|
startActivity(SettingsActivity.newReaderSettingsIntent(v.context))
|
||||||
dismissAllowingStateLoss()
|
dismissAllowingStateLoss()
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.button_save_page -> {
|
R.id.button_save_page -> {
|
||||||
val page = viewModel.getCurrentPage() ?: return
|
val page = viewModel.getCurrentPage() ?: return
|
||||||
viewModel.saveCurrentPage(page, savePageRequest)
|
viewModel.saveCurrentPage(page, savePageRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.button_screen_rotate -> {
|
R.id.button_screen_rotate -> {
|
||||||
orientationHelper?.toggleOrientation()
|
orientationHelper?.toggleOrientation()
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.button_color_filter -> {
|
R.id.button_color_filter -> {
|
||||||
val page = viewModel.getCurrentPage() ?: return
|
val page = viewModel.getCurrentPage() ?: return
|
||||||
val manga = viewModel.manga ?: return
|
val manga = viewModel.manga ?: return
|
||||||
|
|||||||
@@ -2,9 +2,13 @@ package org.koitharu.kotatsu.reader.ui.config
|
|||||||
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import androidx.lifecycle.MediatorLiveData
|
import androidx.lifecycle.MediatorLiveData
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.FlowCollector
|
import kotlinx.coroutines.flow.FlowCollector
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.koitharu.kotatsu.core.model.ZoomMode
|
import org.koitharu.kotatsu.core.model.ZoomMode
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.reader.domain.ReaderColorFilter
|
import org.koitharu.kotatsu.reader.domain.ReaderColorFilter
|
||||||
@@ -60,7 +64,7 @@ class ReaderSettings(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||||
if (key == AppSettings.KEY_ZOOM_MODE || key == AppSettings.KEY_PAGES_NUMBERS) {
|
if (key == AppSettings.KEY_ZOOM_MODE || key == AppSettings.KEY_PAGES_NUMBERS || key == AppSettings.KEY_WEBTOON_ZOOM) {
|
||||||
notifyChanged()
|
notifyChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.annotation.CallSuper
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.databinding.LayoutPageInfoBinding
|
import org.koitharu.kotatsu.databinding.LayoutPageInfoBinding
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
@@ -13,11 +14,12 @@ abstract class BasePageHolder<B : ViewBinding>(
|
|||||||
protected val binding: B,
|
protected val binding: B,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
protected val delegate = PageHolderDelegate(loader, settings, this, exceptionResolver)
|
protected val delegate = PageHolderDelegate(loader, settings, this, networkState, exceptionResolver)
|
||||||
protected val bindingInfo = LayoutPageInfoBinding.bind(binding.root)
|
protected val bindingInfo = LayoutPageInfoBinding.bind(binding.root)
|
||||||
|
|
||||||
val context: Context
|
val context: Context
|
||||||
@@ -37,11 +39,13 @@ abstract class BasePageHolder<B : ViewBinding>(
|
|||||||
|
|
||||||
protected abstract fun onBind(data: ReaderPage)
|
protected abstract fun onBind(data: ReaderPage)
|
||||||
|
|
||||||
fun onAttachedToWindow() {
|
@CallSuper
|
||||||
|
open fun onAttachedToWindow() {
|
||||||
delegate.onAttachedToWindow()
|
delegate.onAttachedToWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDetachedFromWindow() {
|
@CallSuper
|
||||||
|
open fun onDetachedFromWindow() {
|
||||||
delegate.onDetachedFromWindow()
|
delegate.onDetachedFromWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,19 @@ import android.view.ViewGroup
|
|||||||
import androidx.recyclerview.widget.AsyncListDiffer
|
import androidx.recyclerview.widget.AsyncListDiffer
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
||||||
private val loader: PageLoader,
|
private val loader: PageLoader,
|
||||||
private val readerSettings: ReaderSettings,
|
private val readerSettings: ReaderSettings,
|
||||||
|
private val networkState: NetworkState,
|
||||||
private val exceptionResolver: ExceptionResolver,
|
private val exceptionResolver: ExceptionResolver,
|
||||||
) : RecyclerView.Adapter<H>() {
|
) : RecyclerView.Adapter<H>() {
|
||||||
|
|
||||||
@@ -56,9 +58,9 @@ abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
|||||||
final override fun onCreateViewHolder(
|
final override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int,
|
viewType: Int,
|
||||||
): H = onCreateViewHolder(parent, loader, readerSettings, exceptionResolver)
|
): H = onCreateViewHolder(parent, loader, readerSettings, networkState, exceptionResolver)
|
||||||
|
|
||||||
suspend fun setItems(items: List<ReaderPage>) = suspendCoroutine<Unit> { cont ->
|
suspend fun setItems(items: List<ReaderPage>) = suspendCoroutine { cont ->
|
||||||
differ.submitList(items) {
|
differ.submitList(items) {
|
||||||
cont.resume(Unit)
|
cont.resume(Unit)
|
||||||
}
|
}
|
||||||
@@ -68,6 +70,7 @@ abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
|||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
): H
|
): H
|
||||||
|
|
||||||
|
|||||||
@@ -3,25 +3,35 @@ package org.koitharu.kotatsu.reader.ui.pager
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import com.davemorrissey.labs.subscaleview.DefaultOnImageEventListener
|
||||||
import java.io.File
|
import kotlinx.coroutines.CancellationException
|
||||||
import java.io.IOException
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.cancelAndJoin
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class PageHolderDelegate(
|
class PageHolderDelegate(
|
||||||
private val loader: PageLoader,
|
private val loader: PageLoader,
|
||||||
private val readerSettings: ReaderSettings,
|
private val readerSettings: ReaderSettings,
|
||||||
private val callback: Callback,
|
private val callback: Callback,
|
||||||
|
private val networkState: NetworkState,
|
||||||
private val exceptionResolver: ExceptionResolver,
|
private val exceptionResolver: ExceptionResolver,
|
||||||
) : SubsamplingScaleImageView.DefaultOnImageEventListener(), Observer<ReaderSettings> {
|
) : DefaultOnImageEventListener, Observer<ReaderSettings> {
|
||||||
|
|
||||||
private val scope = loader.loaderScope + Dispatchers.Main.immediate
|
private val scope = loader.loaderScope + Dispatchers.Main.immediate
|
||||||
private var state = State.EMPTY
|
private var state = State.EMPTY
|
||||||
@@ -76,7 +86,7 @@ class PageHolderDelegate(
|
|||||||
callback.onImageShown()
|
callback.onImageShown()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onImageLoadError(e: Exception) {
|
override fun onImageLoadError(e: Throwable) {
|
||||||
val file = this.file
|
val file = this.file
|
||||||
error = e
|
error = e
|
||||||
if (state == State.LOADED && e is IOException && file != null && file.exists()) {
|
if (state == State.LOADED && e is IOException && file != null && file.exists()) {
|
||||||
@@ -102,6 +112,8 @@ class PageHolderDelegate(
|
|||||||
loader.convertInPlace(file)
|
loader.convertInPlace(file)
|
||||||
state = State.CONVERTED
|
state = State.CONVERTED
|
||||||
callback.onImageReady(file.toUri())
|
callback.onImageReady(file.toUri())
|
||||||
|
} catch (ce: CancellationException) {
|
||||||
|
throw ce
|
||||||
} catch (e2: Throwable) {
|
} catch (e2: Throwable) {
|
||||||
e.addSuppressed(e2)
|
e.addSuppressed(e2)
|
||||||
state = State.ERROR
|
state = State.ERROR
|
||||||
@@ -110,29 +122,36 @@ class PageHolderDelegate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun CoroutineScope.doLoad(data: MangaPage, force: Boolean) {
|
private suspend fun doLoad(data: MangaPage, force: Boolean) {
|
||||||
state = State.LOADING
|
state = State.LOADING
|
||||||
error = null
|
error = null
|
||||||
callback.onLoadingStarted()
|
callback.onLoadingStarted()
|
||||||
try {
|
try {
|
||||||
val task = loader.loadPageAsync(data, force)
|
val task = loader.loadPageAsync(data, force)
|
||||||
val progressObserver = observeProgress(this, task.progressAsFlow())
|
file = coroutineScope {
|
||||||
val file = task.await()
|
val progressObserver = observeProgress(this, task.progressAsFlow())
|
||||||
progressObserver.cancel()
|
val file = task.await()
|
||||||
this@PageHolderDelegate.file = file
|
progressObserver.cancel()
|
||||||
|
file
|
||||||
|
}
|
||||||
state = State.LOADED
|
state = State.LOADED
|
||||||
callback.onImageReady(file.toUri())
|
callback.onImageReady(checkNotNull(file).toUri())
|
||||||
} catch (e: CancellationException) {
|
} catch (e: CancellationException) {
|
||||||
throw e
|
throw e
|
||||||
} catch (e: Exception) {
|
} catch (e: Throwable) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
state = State.ERROR
|
state = State.ERROR
|
||||||
error = e
|
error = e
|
||||||
callback.onError(e)
|
callback.onError(e)
|
||||||
|
if (e is IOException && !networkState.value) {
|
||||||
|
networkState.awaitForConnection()
|
||||||
|
retry(data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeProgress(scope: CoroutineScope, progress: Flow<Float>) = progress
|
private fun observeProgress(scope: CoroutineScope, progress: Flow<Float>) = progress
|
||||||
.debounce(500)
|
.debounce(250)
|
||||||
.onEach { callback.onProgressChanged((100 * it).toInt()) }
|
.onEach { callback.onProgressChanged((100 * it).toInt()) }
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,13 @@ data class ReaderUiState(
|
|||||||
val chaptersTotal: Int,
|
val chaptersTotal: Int,
|
||||||
val currentPage: Int,
|
val currentPage: Int,
|
||||||
val totalPages: Int,
|
val totalPages: Int,
|
||||||
|
private val isSliderEnabled: Boolean,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
fun isSliderAvailable(): Boolean {
|
||||||
|
return isSliderEnabled && totalPages > 1 && currentPage < totalPages
|
||||||
|
}
|
||||||
|
|
||||||
fun computePercent(): Float {
|
fun computePercent(): Float {
|
||||||
val ppc = 1f / chaptersTotal
|
val ppc = 1f / chaptersTotal
|
||||||
val chapterIndex = chapterNumber - 1
|
val chapterIndex = chapterNumber - 1
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user