Compare commits
194 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ec50f83d2 | ||
|
|
d0b9412559 | ||
|
|
9adf209445 | ||
|
|
5d2395b569 | ||
|
|
29114ae8a7 | ||
|
|
47f80085d1 | ||
|
|
73c1d2a616 | ||
|
|
35366ac660 | ||
|
|
dc2dd4e3c9 | ||
|
|
66817ae545 | ||
|
|
b6e3cb929b | ||
|
|
6f29259395 | ||
|
|
c520699f9f | ||
|
|
c09b0150ac | ||
|
|
d7c31f3b3b | ||
|
|
362629bb9a | ||
|
|
4ec4421f69 | ||
|
|
029815e0d7 | ||
|
|
019b41a9f9 | ||
|
|
a56e977058 | ||
|
|
f436a49e5f | ||
|
|
652351f79a | ||
|
|
b6bfef6b50 | ||
|
|
c119db67e9 | ||
|
|
08e036f9fb | ||
|
|
07519b82f3 | ||
|
|
2644756a01 | ||
|
|
f6c715c5a7 | ||
|
|
81f3a40ba8 | ||
|
|
736be6249c | ||
|
|
0add49f32c | ||
|
|
1e2be37fd6 | ||
|
|
529c6c7a08 | ||
|
|
03251cbf9a | ||
|
|
4ab9ace2f2 | ||
|
|
c55be4efc5 | ||
|
|
48b01d0706 | ||
|
|
e2e0d7a53d | ||
|
|
e3a67940d0 | ||
|
|
5ce2bc92d6 | ||
|
|
d05e777b2c | ||
|
|
206673a417 | ||
|
|
95e46249c5 | ||
|
|
ea9ae2263c | ||
|
|
2acbff487e | ||
|
|
26b852365a | ||
|
|
c2e56f7ba6 | ||
|
|
68e8876288 | ||
|
|
5c44a4dbb3 | ||
|
|
7a7ba802f6 | ||
|
|
c5ae9fb087 | ||
|
|
e0f23d2e6d | ||
|
|
e9a972eec9 | ||
|
|
155af8889b | ||
|
|
61b7117b97 | ||
|
|
0f4de329e5 | ||
|
|
9b290bea40 | ||
|
|
fd3c83cb13 | ||
|
|
ec137d2513 | ||
|
|
9da5bdaad4 | ||
|
|
eec1850712 | ||
|
|
802ab4c6c1 | ||
|
|
85d09dc48c | ||
|
|
1daa02af52 | ||
|
|
1729505bfe | ||
|
|
00617d5c64 | ||
|
|
35b8003cf9 | ||
|
|
56ed8a787a | ||
|
|
fd26de7619 | ||
|
|
205a2e10a5 | ||
|
|
8514cc3da7 | ||
|
|
8bc8df7625 | ||
|
|
7ffa15d2d7 | ||
|
|
80be0e403d | ||
|
|
ee2538ba7f | ||
|
|
6ca6ec28ac | ||
|
|
94203785f1 | ||
|
|
3f538d9b78 | ||
|
|
e6a0578884 | ||
|
|
e11e890818 | ||
|
|
3e7a48d27a | ||
|
|
eeba959ba5 | ||
|
|
e7fa1036be | ||
|
|
542a7e1141 | ||
|
|
5951f4438a | ||
|
|
1fbae6bd7b | ||
|
|
b73924aea8 | ||
|
|
005443f4ae | ||
|
|
abb55d4424 | ||
|
|
e0538da079 | ||
|
|
665bf5a034 | ||
|
|
dc7e1282c6 | ||
|
|
3a877d4f4a | ||
|
|
8a23c9a327 | ||
|
|
452c0edfc7 | ||
|
|
2b9307aa17 | ||
|
|
f91d5e1c29 | ||
|
|
2fbfd14252 | ||
|
|
c09dd92cff | ||
|
|
6b08074a70 | ||
|
|
9cb5971182 | ||
|
|
6f37d95c24 | ||
|
|
d290ba24b7 | ||
|
|
f57d23026b | ||
|
|
1a70ccff55 | ||
|
|
bd6a51e58d | ||
|
|
a9c122b144 | ||
|
|
ed56170809 | ||
|
|
a36e5fce29 | ||
|
|
760bfaf4d7 | ||
|
|
24463720b1 | ||
|
|
516470e8ae | ||
|
|
7f530d0476 | ||
|
|
8a2706d70b | ||
|
|
27f09480a0 | ||
|
|
c03dcf6d2e | ||
|
|
bdb2ae9c2f | ||
|
|
3413fe6943 | ||
|
|
e6ae9e8bd6 | ||
|
|
8d9426f257 | ||
|
|
30247e3def | ||
|
|
084dc32d2d | ||
|
|
3393f1397b | ||
|
|
61784bcfc4 | ||
|
|
bd692fc60c | ||
|
|
2c71110fa5 | ||
|
|
738299e8d3 | ||
|
|
c8b6dc27b2 | ||
|
|
1493aa39a3 | ||
|
|
f115031846 | ||
|
|
571b85dfd8 | ||
|
|
75cc9e9030 | ||
|
|
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 | ||
|
|
46786e32a3 | ||
|
|
eef449af49 | ||
|
|
b4eb8d56a6 | ||
|
|
c896ac72e8 | ||
|
|
b599cb33ff | ||
|
|
b3eab1a2a0 | ||
|
|
79d9dc7b24 | ||
|
|
7b573f8e6b | ||
|
|
7bd769e294 | ||
|
|
fde5f86313 | ||
|
|
3c23bf7ec9 | ||
|
|
4665f8b74e | ||
|
|
0c4c7489e9 | ||
|
|
5a43e677c5 | ||
|
|
38d4274ece | ||
|
|
743098d0b0 | ||
|
|
0e5221fa6e | ||
|
|
b458bde8a1 | ||
|
|
c663d10515 | ||
|
|
cec19c3db3 | ||
|
|
ff58539e2e | ||
|
|
d8e7689a94 | ||
|
|
32cfbb327c | ||
|
|
2b2042807b |
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,2 +1,2 @@
|
|||||||
|
ko_fi: xtimms
|
||||||
custom: ["https://yoomoney.ru/to/410012543938752"]
|
custom: ["https://yoomoney.ru/to/410012543938752"]
|
||||||
ko_fi: koitharu
|
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -12,9 +12,11 @@
|
|||||||
/.idea/navEditor.xml
|
/.idea/navEditor.xml
|
||||||
/.idea/assetWizardSettings.xml
|
/.idea/assetWizardSettings.xml
|
||||||
/.idea/kotlinScripting.xml
|
/.idea/kotlinScripting.xml
|
||||||
|
/.idea/kotlinc.xml
|
||||||
/.idea/deploymentTargetDropDown.xml
|
/.idea/deploymentTargetDropDown.xml
|
||||||
/.idea/androidTestResultsUserPreferences.xml
|
/.idea/androidTestResultsUserPreferences.xml
|
||||||
/.idea/render.experimental.xml
|
/.idea/render.experimental.xml
|
||||||
|
/.idea/inspectionProfiles/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/build
|
/build
|
||||||
/captures
|
/captures
|
||||||
|
|||||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
@@ -7,7 +7,7 @@
|
|||||||
<option name="testRunner" value="GRADLE" />
|
<option name="testRunner" value="GRADLE" />
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="Embedded JDK" />
|
<option name="gradleJvm" value="jbr-17" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
|||||||
17
.idea/inspectionProfiles/Project_Default.xml
generated
17
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,17 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="BooleanLiteralArgument" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
|
||||||
<inspection_tool class="Destructure" enabled="true" level="INFO" enabled_by_default="true" />
|
|
||||||
<inspection_tool class="FillClass" enabled="true" level="INFORMATION" enabled_by_default="true">
|
|
||||||
<option name="withoutDefaultValues" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="KeySetIterationMayUseEntrySet" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
||||||
<inspection_tool class="KotlinFunctionArgumentsHelper" enabled="true" level="INFORMATION" enabled_by_default="true">
|
|
||||||
<option name="withoutDefaultValues" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="ReplaceCollectionCountWithSize" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
|
||||||
<inspection_tool class="TrailingComma" enabled="true" level="INFORMATION" enabled_by_default="true" />
|
|
||||||
<inspection_tool class="ZeroLengthArrayInitialization" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
||||||
9
.idea/kotlinc.xml
generated
9
.idea/kotlinc.xml
generated
@@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Kotlin2JvmCompilerArguments">
|
|
||||||
<option name="jvmTarget" value="1.8" />
|
|
||||||
</component>
|
|
||||||
<component name="KotlinJpsPluginSettings">
|
|
||||||
<option name="version" value="1.7.20" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -16,7 +16,7 @@ Download APK directly from GitHub:
|
|||||||
|
|
||||||
### Main Features
|
### Main Features
|
||||||
|
|
||||||
* Online manga catalogues
|
* Online [manga catalogues](https://github.com/KotatsuApp/kotatsu-parsers)
|
||||||
* Search manga by name and genres
|
* Search manga by name and genres
|
||||||
* Reading history and bookmarks
|
* Reading history and bookmarks
|
||||||
* Favourites organized by user-defined categories
|
* Favourites organized by user-defined categories
|
||||||
@@ -24,9 +24,9 @@ Download APK directly from GitHub:
|
|||||||
* Tablet-optimized Material You UI
|
* Tablet-optimized Material You UI
|
||||||
* Standard and Webtoon-optimized reader
|
* Standard and Webtoon-optimized reader
|
||||||
* Notifications about new chapters with updates feed
|
* Notifications about new chapters with updates feed
|
||||||
* Shikimori integration (manga tracking)
|
* Integration with manga tracking services: Shikimori, AniList, MyAnimeList
|
||||||
* 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
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 33
|
compileSdk = 33
|
||||||
buildToolsVersion '33.0.0'
|
buildToolsVersion = '33.0.1'
|
||||||
namespace 'org.koitharu.kotatsu'
|
namespace = 'org.koitharu.kotatsu'
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 33
|
targetSdkVersion 33
|
||||||
versionCode 500
|
versionCode 518
|
||||||
versionName '4.0'
|
versionName '4.4.2'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
@@ -29,6 +29,9 @@ android {
|
|||||||
// define this values in your local.properties file
|
// define this values in your local.properties file
|
||||||
buildConfigField 'String', 'SHIKIMORI_CLIENT_ID', "\"${localProperty('shikimori.clientId')}\""
|
buildConfigField 'String', 'SHIKIMORI_CLIENT_ID', "\"${localProperty('shikimori.clientId')}\""
|
||||||
buildConfigField 'String', 'SHIKIMORI_CLIENT_SECRET', "\"${localProperty('shikimori.clientSecret')}\""
|
buildConfigField 'String', 'SHIKIMORI_CLIENT_SECRET', "\"${localProperty('shikimori.clientSecret')}\""
|
||||||
|
buildConfigField 'String', 'ANILIST_CLIENT_ID', "\"${localProperty('anilist.clientId')}\""
|
||||||
|
buildConfigField 'String', 'ANILIST_CLIENT_SECRET', "\"${localProperty('anilist.clientSecret')}\""
|
||||||
|
buildConfigField 'String', 'MAL_CLIENT_ID', "\"${localProperty('mal.clientId')}\""
|
||||||
resValue "string", "acra_login", "${localProperty('acra.login')}"
|
resValue "string", "acra_login", "${localProperty('acra.login')}"
|
||||||
resValue "string", "acra_password", "${localProperty('acra.password')}"
|
resValue "string", "acra_password", "${localProperty('acra.password')}"
|
||||||
}
|
}
|
||||||
@@ -56,6 +59,7 @@ android {
|
|||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||||
freeCompilerArgs += [
|
freeCompilerArgs += [
|
||||||
|
'-opt-in=kotlin.ExperimentalStdlibApi',
|
||||||
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
||||||
'-opt-in=kotlinx.coroutines.FlowPreview',
|
'-opt-in=kotlinx.coroutines.FlowPreview',
|
||||||
'-opt-in=kotlin.contracts.ExperimentalContracts',
|
'-opt-in=kotlin.contracts.ExperimentalContracts',
|
||||||
@@ -83,15 +87,17 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation('com.github.KotatsuApp:kotatsu-parsers:a1441e7ed7') {
|
implementation('com.github.KotatsuApp:kotatsu-parsers:1093584202') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.10'
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
||||||
|
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.core:core-ktx:1.9.0'
|
implementation 'androidx.core:core-ktx:1.9.0'
|
||||||
implementation 'androidx.activity:activity-ktx:1.6.0'
|
implementation 'androidx.activity:activity-ktx:1.6.1'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.5.3'
|
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,52 +107,53 @@ dependencies {
|
|||||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||||
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.8.0'
|
||||||
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
||||||
implementation 'com.google.android.material:material:1.7.0'
|
implementation 'com.google.android.material:material:1.8.0'
|
||||||
//noinspection LifecycleAnnotationProcessorWithJava8
|
//noinspection LifecycleAnnotationProcessorWithJava8
|
||||||
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.1'
|
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.1'
|
||||||
|
|
||||||
implementation 'androidx.room:room-runtime:2.4.3'
|
implementation 'androidx.room:room-runtime:2.5.0'
|
||||||
implementation 'androidx.room:room-ktx:2.4.3'
|
implementation 'androidx.room:room-ktx:2.5.0'
|
||||||
kapt 'androidx.room:room-compiler:2.4.3'
|
kapt 'androidx.room:room-compiler:2.5.0'
|
||||||
|
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
|
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
|
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
|
||||||
implementation 'com.squareup.okio:okio:3.2.0'
|
implementation 'com.squareup.okio:okio:3.3.0'
|
||||||
|
|
||||||
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.44"
|
implementation 'com.google.dagger:hilt-android:2.45'
|
||||||
kapt "com.google.dagger:hilt-compiler:2.44"
|
kapt 'com.google.dagger:hilt-compiler:2.45'
|
||||||
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.2'
|
implementation 'io.coil-kt:coil-base:2.2.2'
|
||||||
implementation 'io.coil-kt:coil-svg:2.2.2'
|
implementation 'io.coil-kt:coil-svg:2.2.2'
|
||||||
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:0ff0278f0f'
|
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 'io.noties.markwon:core:4.6.2'
|
||||||
|
|
||||||
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:20220924'
|
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.2'
|
||||||
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.5'
|
||||||
|
|
||||||
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.5.0'
|
||||||
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
|
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
|
||||||
|
|
||||||
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.44'
|
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.45'
|
||||||
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.44'
|
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.45'
|
||||||
}
|
}
|
||||||
|
|||||||
1
app/proguard-rules.pro
vendored
1
app/proguard-rules.pro
vendored
@@ -14,3 +14,4 @@
|
|||||||
|
|
||||||
-keep class org.koitharu.kotatsu.core.exceptions.* { *; }
|
-keep class org.koitharu.kotatsu.core.exceptions.* { *; }
|
||||||
-keep class org.koitharu.kotatsu.settings.NotificationSettingsLegacyFragment
|
-keep class org.koitharu.kotatsu.settings.NotificationSettingsLegacyFragment
|
||||||
|
-keep class org.koitharu.kotatsu.core.prefs.ScreenshotsPolicy { *; }
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Response
|
||||||
|
import okio.Buffer
|
||||||
|
import org.koitharu.kotatsu.core.network.CommonHeaders.ACCEPT_ENCODING
|
||||||
|
|
||||||
|
class CurlLoggingInterceptor(
|
||||||
|
private val curlOptions: String? = null
|
||||||
|
) : Interceptor {
|
||||||
|
|
||||||
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
|
val request = chain.request()
|
||||||
|
var isCompressed = false
|
||||||
|
|
||||||
|
val curlCmd = StringBuilder()
|
||||||
|
curlCmd.append("curl")
|
||||||
|
if (curlOptions != null) {
|
||||||
|
curlCmd.append(' ').append(curlOptions)
|
||||||
|
}
|
||||||
|
curlCmd.append(" -X ").append(request.method)
|
||||||
|
|
||||||
|
for ((name, value) in request.headers) {
|
||||||
|
if (name.equals(ACCEPT_ENCODING, ignoreCase = true) && value.equals("gzip", ignoreCase = true)) {
|
||||||
|
isCompressed = true
|
||||||
|
}
|
||||||
|
curlCmd.append(" -H \"").append(name).append(": ").append(value.escape()).append('\"')
|
||||||
|
}
|
||||||
|
|
||||||
|
val body = request.body
|
||||||
|
if (body != null) {
|
||||||
|
val buffer = Buffer()
|
||||||
|
body.writeTo(buffer)
|
||||||
|
val charset = body.contentType()?.charset() ?: Charsets.UTF_8
|
||||||
|
curlCmd.append(" --data-raw '")
|
||||||
|
.append(buffer.readString(charset).replace("\n", "\\n"))
|
||||||
|
.append("'")
|
||||||
|
}
|
||||||
|
if (isCompressed) {
|
||||||
|
curlCmd.append(" --compressed")
|
||||||
|
}
|
||||||
|
curlCmd.append(" \"").append(request.url).append('"')
|
||||||
|
|
||||||
|
log("---cURL (" + request.url + ")")
|
||||||
|
log(curlCmd.toString())
|
||||||
|
|
||||||
|
return chain.proceed(request)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun String.escape() = replace("\"", "\\\"")
|
||||||
|
|
||||||
|
private fun log(msg: String) {
|
||||||
|
Log.d("CURL", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,20 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.parsers.MangaParser
|
import org.koitharu.kotatsu.parsers.MangaParser
|
||||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
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 java.util.EnumSet
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This parser is just for parser development, it should not be used in releases
|
* This parser is just for parser development, it should not be used in releases
|
||||||
*/
|
*/
|
||||||
class DummyParser(override val context: MangaLoaderContext) : MangaParser(MangaSource.DUMMY) {
|
class DummyParser(context: MangaLoaderContext) : MangaParser(context, MangaSource.DUMMY) {
|
||||||
|
|
||||||
override val configKeyDomain: ConfigKey.Domain
|
override val configKeyDomain: ConfigKey.Domain
|
||||||
get() = ConfigKey.Domain("", null)
|
get() = ConfigKey.Domain("", null)
|
||||||
@@ -37,4 +42,4 @@ class DummyParser(override val context: MangaLoaderContext) : MangaParser(MangaS
|
|||||||
override suspend fun getTags(): Set<MangaTag> {
|
override suspend fun getTags(): Set<MangaTag> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
<bool name="leak_canary_add_launcher_icon" tools:node="replace">false</bool>
|
<bool name="leak_canary_add_launcher_icon" tools:node="replace">false</bool>
|
||||||
</resources>
|
<bool name="is_sync_enabled">true</bool>
|
||||||
|
</resources>
|
||||||
|
|||||||
@@ -24,10 +24,13 @@
|
|||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:backupAgent="org.koitharu.kotatsu.settings.backup.AppBackupAgent"
|
android:backupAgent="org.koitharu.kotatsu.settings.backup.AppBackupAgent"
|
||||||
android:dataExtractionRules="@xml/backup_rules"
|
android:dataExtractionRules="@xml/backup_rules"
|
||||||
|
android:enableOnBackInvokedCallback="true"
|
||||||
android:fullBackupContent="@xml/backup_content"
|
android:fullBackupContent="@xml/backup_content"
|
||||||
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"
|
||||||
@@ -83,16 +86,7 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.settings.SettingsActivity"
|
android:name="org.koitharu.kotatsu.settings.SettingsActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/settings">
|
android:label="@string/settings" />
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
|
||||||
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
|
||||||
|
|
||||||
<data android:scheme="kotatsu" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.browser.BrowserActivity"
|
android:name="org.koitharu.kotatsu.browser.BrowserActivity"
|
||||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
||||||
@@ -108,8 +102,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>
|
||||||
@@ -127,18 +120,34 @@
|
|||||||
<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" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.scrobbling.common.ui.config.ScrobblerConfigActivity"
|
||||||
|
android:exported="true"
|
||||||
|
android:label="@string/settings"
|
||||||
|
android:launchMode="singleTop">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data android:scheme="kotatsu" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"
|
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"
|
||||||
@@ -187,6 +196,9 @@
|
|||||||
android:name="android.content.SyncAdapter"
|
android:name="android.content.SyncAdapter"
|
||||||
android:resource="@xml/sync_history" />
|
android:resource="@xml/sync_history" />
|
||||||
</service>
|
</service>
|
||||||
|
<service
|
||||||
|
android:name="org.koitharu.kotatsu.details.service.MangaPrefetchService"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider"
|
android:name="org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider"
|
||||||
@@ -247,6 +259,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>
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
enableStrictMode()
|
enableStrictMode()
|
||||||
}
|
}
|
||||||
AppCompatDelegate.setDefaultNightMode(settings.theme)
|
AppCompatDelegate.setDefaultNightMode(settings.theme)
|
||||||
|
AppCompatDelegate.setApplicationLocales(settings.appLocales)
|
||||||
setupActivityLifecycleCallbacks()
|
setupActivityLifecycleCallbacks()
|
||||||
processLifecycleScope.launch(Dispatchers.Default) {
|
processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
setupDatabaseObservers()
|
setupDatabaseObservers()
|
||||||
|
|||||||
@@ -4,11 +4,6 @@ import android.graphics.BitmapFactory
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.util.Size
|
import android.util.Size
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import java.io.File
|
|
||||||
import java.io.InputStream
|
|
||||||
import java.util.zip.ZipFile
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.math.roundToInt
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
@@ -17,7 +12,11 @@ import kotlinx.coroutines.runInterruptible
|
|||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.db.entity.*
|
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toEntities
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toManga
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||||
import org.koitharu.kotatsu.core.network.CommonHeaders
|
import org.koitharu.kotatsu.core.network.CommonHeaders
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||||
@@ -27,6 +26,11 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
import org.koitharu.kotatsu.parsers.util.await
|
import org.koitharu.kotatsu.parsers.util.await
|
||||||
import org.koitharu.kotatsu.reader.domain.ReaderColorFilter
|
import org.koitharu.kotatsu.reader.domain.ReaderColorFilter
|
||||||
|
import java.io.File
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.util.zip.ZipFile
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
private const val MIN_WEBTOON_RATIO = 2
|
private const val MIN_WEBTOON_RATIO = 2
|
||||||
|
|
||||||
@@ -121,7 +125,7 @@ class MangaDataRepository @Inject constructor(
|
|||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.get()
|
.get()
|
||||||
.header(CommonHeaders.REFERER, page.referer)
|
.tag(MangaSource::class.java, page.source)
|
||||||
.cacheControl(CommonHeaders.CACHE_CONTROL_DISABLED)
|
.cacheControl(CommonHeaders.CACHE_CONTROL_DISABLED)
|
||||||
.build()
|
.build()
|
||||||
okHttpClient.newCall(request).await().use {
|
okHttpClient.newCall(request).await().use {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.CallSuper
|
import androidx.annotation.CallSuper
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
@@ -39,6 +40,8 @@ abstract class AlertDialogFragment<B : ViewBinding> : DialogFragment() {
|
|||||||
|
|
||||||
open fun onBuildDialog(builder: MaterialAlertDialogBuilder): MaterialAlertDialogBuilder = builder
|
open fun onBuildDialog(builder: MaterialAlertDialogBuilder): MaterialAlertDialogBuilder = builder
|
||||||
|
|
||||||
|
open fun onDialogCreated(dialog: AlertDialog) = Unit
|
||||||
|
|
||||||
protected fun bindingOrNull(): B? = viewBinding
|
protected fun bindingOrNull(): B? = viewBinding
|
||||||
|
|
||||||
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ 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
|
||||||
@@ -51,13 +52,9 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
EntryPointAccessors.fromApplication(this, BaseActivityEntryPoint::class.java).inject(this)
|
EntryPointAccessors.fromApplication(this, BaseActivityEntryPoint::class.java).inject(this)
|
||||||
val isAmoled = settings.isAmoledTheme
|
setTheme(settings.colorScheme.styleResId)
|
||||||
val isDynamic = settings.isDynamicTheme
|
if (settings.isAmoledTheme) {
|
||||||
// TODO support DialogWhenLarge theme
|
setTheme(R.style.ThemeOverlay_Kotatsu_Amoled)
|
||||||
when {
|
|
||||||
isAmoled && isDynamic -> setTheme(R.style.Theme_Kotatsu_Monet_Amoled)
|
|
||||||
isAmoled -> setTheme(R.style.Theme_Kotatsu_Amoled)
|
|
||||||
isDynamic -> setTheme(R.style.Theme_Kotatsu_Monet)
|
|
||||||
}
|
}
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
@@ -85,14 +82,14 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem) = if (item.itemId == android.R.id.home) {
|
override fun onOptionsItemSelected(item: MenuItem) = if (item.itemId == android.R.id.home) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
onBackPressed()
|
onBackPressed()
|
||||||
true
|
true
|
||||||
} else super.onOptionsItemSelected(item)
|
} else super.onOptionsItemSelected(item)
|
||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) { // TODO remove
|
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||||
// ActivityCompat.recreate(this)
|
ActivityCompat.recreate(this)
|
||||||
TODO("Test error")
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event)
|
return super.onKeyDown(keyCode, event)
|
||||||
@@ -134,7 +131,8 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
window.statusBarColor = getThemeColor(android.R.attr.statusBarColor)
|
window.statusBarColor = getThemeColor(android.R.attr.statusBarColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
|
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
|
||||||
|
@Deprecated("Should not be used")
|
||||||
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 &&
|
||||||
|
|||||||
@@ -7,15 +7,16 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewGroup.LayoutParams
|
import android.view.ViewGroup.LayoutParams
|
||||||
|
import androidx.activity.OnBackPressedDispatcher
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.dialog.AppBottomSheetDialog
|
import org.koitharu.kotatsu.base.ui.dialog.AppBottomSheetDialog
|
||||||
import org.koitharu.kotatsu.utils.ext.displayCompat
|
import org.koitharu.kotatsu.utils.ext.displayCompat
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
||||||
|
|
||||||
@@ -27,6 +28,12 @@ abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
|||||||
protected val behavior: BottomSheetBehavior<*>?
|
protected val behavior: BottomSheetBehavior<*>?
|
||||||
get() = (dialog as? BottomSheetDialog)?.behavior
|
get() = (dialog as? BottomSheetDialog)?.behavior
|
||||||
|
|
||||||
|
val isExpanded: Boolean
|
||||||
|
get() = behavior?.state == BottomSheetBehavior.STATE_EXPANDED
|
||||||
|
|
||||||
|
val onBackPressedDispatcher: OnBackPressedDispatcher
|
||||||
|
get() = (requireDialog() as AppBottomSheetDialog).onBackPressedDispatcher
|
||||||
|
|
||||||
final override fun onCreateView(
|
final override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ abstract class CoroutineIntentService : BaseService() {
|
|||||||
processIntent(startId, intent)
|
processIntent(startId, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
onError(startId, e)
|
||||||
} finally {
|
} finally {
|
||||||
stopSelf(startId)
|
stopSelf(startId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
|
|||||||
@@ -516,6 +516,6 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
|
|
||||||
interface SectionIndexer {
|
interface SectionIndexer {
|
||||||
|
|
||||||
fun getSectionText(context: Context, position: Int): CharSequence
|
fun getSectionText(context: Context, position: Int): CharSequence?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.MenuItem.OnActionExpandListener
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
|
|
||||||
|
class CollapseActionViewCallback(
|
||||||
|
private val menuItem: MenuItem
|
||||||
|
) : OnBackPressedCallback(menuItem.isActionViewExpanded), OnActionExpandListener {
|
||||||
|
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
menuItem.collapseActionView()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||||
|
isEnabled = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
|
||||||
|
isEnabled = false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,10 +8,12 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior
|
|||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
|
|
||||||
class ShrinkOnScrollBehavior : Behavior<ExtendedFloatingActionButton> {
|
open class ShrinkOnScrollBehavior : Behavior<ExtendedFloatingActionButton> {
|
||||||
|
|
||||||
@Suppress("unused") constructor() : super()
|
@Suppress("unused")
|
||||||
@Suppress("unused") constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
constructor() : super()
|
||||||
|
@Suppress("unused")
|
||||||
|
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
||||||
|
|
||||||
override fun onStartNestedScroll(
|
override fun onStartNestedScroll(
|
||||||
coordinatorLayout: CoordinatorLayout,
|
coordinatorLayout: CoordinatorLayout,
|
||||||
@@ -45,4 +47,4 @@ class ShrinkOnScrollBehavior : Behavior<ExtendedFloatingActionButton> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.annotation.Px
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.koitharu.kotatsu.parsers.util.toIntUp
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
class SpanSizeResolver(
|
||||||
|
private val recyclerView: RecyclerView,
|
||||||
|
@Px private val minItemWidth: Int,
|
||||||
|
) : View.OnLayoutChangeListener {
|
||||||
|
|
||||||
|
fun attach() {
|
||||||
|
recyclerView.addOnLayoutChangeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun detach() {
|
||||||
|
recyclerView.removeOnLayoutChangeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLayoutChange(
|
||||||
|
v: View?,
|
||||||
|
left: Int,
|
||||||
|
top: Int,
|
||||||
|
right: Int,
|
||||||
|
bottom: Int,
|
||||||
|
oldLeft: Int,
|
||||||
|
oldTop: Int,
|
||||||
|
oldRight: Int,
|
||||||
|
oldBottom: Int,
|
||||||
|
) {
|
||||||
|
invalidateInternal(abs(right - left))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun invalidate() {
|
||||||
|
invalidateInternal(recyclerView.width)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun invalidateInternal(width: Int) {
|
||||||
|
if (width <= 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val lm = recyclerView.layoutManager as? GridLayoutManager ?: return
|
||||||
|
val estimatedCount = (width / minItemWidth.toFloat()).toIntUp()
|
||||||
|
if (lm.spanCount != estimatedCount) {
|
||||||
|
lm.spanCount = estimatedCount
|
||||||
|
lm.spanSizeLookup?.run {
|
||||||
|
invalidateSpanGroupIndexCache()
|
||||||
|
invalidateSpanIndexCache()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,12 @@ import android.animation.LayoutTransition
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.Menu
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.WindowInsets
|
import android.view.WindowInsets
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
|
import androidx.annotation.MenuRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
@@ -15,16 +17,16 @@ import androidx.core.content.withStyledAttributes
|
|||||||
import androidx.core.view.*
|
import androidx.core.view.*
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
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.MaterialToolbar
|
import com.google.android.material.appbar.MaterialToolbar
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import java.util.*
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.databinding.LayoutSheetHeaderBinding
|
import org.koitharu.kotatsu.databinding.LayoutSheetHeaderBinding
|
||||||
import org.koitharu.kotatsu.utils.ext.getAnimationDuration
|
import org.koitharu.kotatsu.utils.ext.getAnimationDuration
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeDrawable
|
import org.koitharu.kotatsu.utils.ext.getThemeDrawable
|
||||||
import org.koitharu.kotatsu.utils.ext.parents
|
import org.koitharu.kotatsu.utils.ext.parents
|
||||||
|
import java.util.*
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
private const val THROTTLE_DELAY = 200L
|
private const val THROTTLE_DELAY = 200L
|
||||||
|
|
||||||
@@ -53,6 +55,9 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
val toolbar: MaterialToolbar
|
val toolbar: MaterialToolbar
|
||||||
get() = binding.toolbar
|
get() = binding.toolbar
|
||||||
|
|
||||||
|
val menu: Menu
|
||||||
|
get() = binding.toolbar.menu
|
||||||
|
|
||||||
var title: CharSequence?
|
var title: CharSequence?
|
||||||
get() = binding.toolbar.title
|
get() = binding.toolbar.title
|
||||||
set(value) {
|
set(value) {
|
||||||
@@ -140,6 +145,10 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
binding.toolbar.invalidateMenu()
|
binding.toolbar.invalidateMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun inflateMenu(@MenuRes resId: Int) {
|
||||||
|
binding.toolbar.inflateMenu(resId)
|
||||||
|
}
|
||||||
|
|
||||||
fun setNavigationOnClickListener(onClickListener: OnClickListener) {
|
fun setNavigationOnClickListener(onClickListener: OnClickListener) {
|
||||||
binding.toolbar.setNavigationOnClickListener(onClickListener)
|
binding.toolbar.setNavigationOnClickListener(onClickListener)
|
||||||
}
|
}
|
||||||
@@ -258,6 +267,7 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
lp
|
lp
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> Toolbar.LayoutParams(params)
|
else -> Toolbar.LayoutParams(params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -282,7 +292,7 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
suppressLayoutCompat(false)
|
suppressLayoutCompat(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class Callback : BottomSheetBehavior.BottomSheetCallback(), View.OnClickListener {
|
private inner class Callback : BottomSheetBehavior.BottomSheetCallback(), OnClickListener {
|
||||||
|
|
||||||
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
||||||
onBottomSheetStateChanged(newState)
|
onBottomSheetStateChanged(newState)
|
||||||
|
|||||||
@@ -1,119 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.widgets
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.AttributeSet
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.LinearLayout
|
|
||||||
import androidx.annotation.AttrRes
|
|
||||||
import androidx.annotation.IdRes
|
|
||||||
import androidx.core.view.children
|
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
import com.google.android.material.button.MaterialButton
|
|
||||||
import com.google.android.material.shape.ShapeAppearanceModel
|
|
||||||
|
|
||||||
class CheckableButtonGroup @JvmOverloads constructor(
|
|
||||||
context: Context,
|
|
||||||
attrs: AttributeSet? = null,
|
|
||||||
@AttrRes defStyleAttr: Int = materialR.attr.materialButtonToggleGroupStyle,
|
|
||||||
) : LinearLayout(context, attrs, defStyleAttr, materialR.style.Widget_MaterialComponents_MaterialButtonToggleGroup),
|
|
||||||
View.OnClickListener {
|
|
||||||
|
|
||||||
private val originalCornerData = ArrayList<CornerData>()
|
|
||||||
|
|
||||||
var onCheckedChangeListener: OnCheckedChangeListener? = null
|
|
||||||
|
|
||||||
override fun addView(child: View?, index: Int, params: ViewGroup.LayoutParams?) {
|
|
||||||
if (child is MaterialButton) {
|
|
||||||
setupButton(child)
|
|
||||||
}
|
|
||||||
super.addView(child, index, params)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFinishInflate() {
|
|
||||||
super.onFinishInflate()
|
|
||||||
updateChildShapes()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
|
||||||
setCheckedId(v.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setCheckedId(@IdRes viewRes: Int) {
|
|
||||||
children.forEach {
|
|
||||||
(it as? MaterialButton)?.isChecked = it.id == viewRes
|
|
||||||
}
|
|
||||||
onCheckedChangeListener?.onCheckedChanged(this, viewRes)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateChildShapes() {
|
|
||||||
val childCount = childCount
|
|
||||||
val firstVisibleChildIndex = 0
|
|
||||||
val lastVisibleChildIndex = childCount - 1
|
|
||||||
for (i in 0 until childCount) {
|
|
||||||
val button: MaterialButton = getChildAt(i) as? MaterialButton ?: continue
|
|
||||||
if (button.visibility == GONE) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val builder = button.shapeAppearanceModel.toBuilder()
|
|
||||||
val newCornerData: CornerData? =
|
|
||||||
getNewCornerData(i, firstVisibleChildIndex, lastVisibleChildIndex)
|
|
||||||
updateBuilderWithCornerData(builder, newCornerData)
|
|
||||||
button.shapeAppearanceModel = builder.build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupButton(button: MaterialButton) {
|
|
||||||
button.setOnClickListener(this)
|
|
||||||
button.isElegantTextHeight = false
|
|
||||||
// Saves original corner data
|
|
||||||
val shapeAppearanceModel: ShapeAppearanceModel = button.shapeAppearanceModel
|
|
||||||
originalCornerData.add(
|
|
||||||
CornerData(
|
|
||||||
shapeAppearanceModel.topLeftCornerSize,
|
|
||||||
shapeAppearanceModel.bottomLeftCornerSize,
|
|
||||||
shapeAppearanceModel.topRightCornerSize,
|
|
||||||
shapeAppearanceModel.bottomRightCornerSize,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getNewCornerData(
|
|
||||||
index: Int,
|
|
||||||
firstVisibleChildIndex: Int,
|
|
||||||
lastVisibleChildIndex: Int,
|
|
||||||
): CornerData? {
|
|
||||||
val cornerData: CornerData = originalCornerData.get(index)
|
|
||||||
|
|
||||||
// If only one (visible) child exists, use its original corners
|
|
||||||
if (firstVisibleChildIndex == lastVisibleChildIndex) {
|
|
||||||
return cornerData
|
|
||||||
}
|
|
||||||
val isHorizontal = orientation == HORIZONTAL
|
|
||||||
if (index == firstVisibleChildIndex) {
|
|
||||||
return if (isHorizontal) cornerData.start(this) else cornerData.top()
|
|
||||||
}
|
|
||||||
return if (index == lastVisibleChildIndex) {
|
|
||||||
if (isHorizontal) cornerData.end(this) else cornerData.bottom()
|
|
||||||
} else null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateBuilderWithCornerData(
|
|
||||||
shapeAppearanceModelBuilder: ShapeAppearanceModel.Builder,
|
|
||||||
cornerData: CornerData?,
|
|
||||||
) {
|
|
||||||
if (cornerData == null) {
|
|
||||||
shapeAppearanceModelBuilder.setAllCornerSizes(0f)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
shapeAppearanceModelBuilder
|
|
||||||
.setTopLeftCornerSize(cornerData.topLeft)
|
|
||||||
.setBottomLeftCornerSize(cornerData.bottomLeft)
|
|
||||||
.setTopRightCornerSize(cornerData.topRight)
|
|
||||||
.setBottomRightCornerSize(cornerData.bottomRight)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun interface OnCheckedChangeListener {
|
|
||||||
fun onCheckedChanged(group: CheckableButtonGroup, checkedId: Int)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.widgets
|
|
||||||
|
|
||||||
import android.view.View
|
|
||||||
import androidx.core.view.ViewCompat
|
|
||||||
import com.google.android.material.shape.AbsoluteCornerSize
|
|
||||||
import com.google.android.material.shape.CornerSize
|
|
||||||
|
|
||||||
class CornerData(
|
|
||||||
var topLeft: CornerSize,
|
|
||||||
var bottomLeft: CornerSize,
|
|
||||||
var topRight: CornerSize,
|
|
||||||
var bottomRight: CornerSize,
|
|
||||||
) {
|
|
||||||
|
|
||||||
fun start(view: View): CornerData {
|
|
||||||
return if (isLayoutRtl(view)) right() else left()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun end(view: View): CornerData {
|
|
||||||
return if (isLayoutRtl(view)) left() else right()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun left(): CornerData {
|
|
||||||
return CornerData(topLeft, bottomLeft, noCorner, noCorner)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun right(): CornerData {
|
|
||||||
return CornerData(noCorner, noCorner, topRight, bottomRight)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun top(): CornerData {
|
|
||||||
return CornerData(topLeft, noCorner, topRight, noCorner)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bottom(): CornerData {
|
|
||||||
return CornerData(noCorner, bottomLeft, noCorner, bottomRight)
|
|
||||||
}
|
|
||||||
|
|
||||||
private companion object {
|
|
||||||
|
|
||||||
val noCorner: CornerSize = AbsoluteCornerSize(0f)
|
|
||||||
|
|
||||||
fun isLayoutRtl(view: View): Boolean {
|
|
||||||
return ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.Outline
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.graphics.Path
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewOutlineProvider
|
||||||
|
import androidx.core.content.withStyledAttributes
|
||||||
|
import androidx.core.graphics.withClip
|
||||||
|
import com.google.android.material.drawable.DrawableUtils
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
class ShapeView @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
defStyleAttr: Int = 0,
|
||||||
|
) : View(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
private val corners = FloatArray(8)
|
||||||
|
private val outlinePath = Path()
|
||||||
|
private val strokePaint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
|
|
||||||
|
init {
|
||||||
|
context.withStyledAttributes(attrs, R.styleable.ShapeView, defStyleAttr) {
|
||||||
|
val cornerSize = getDimension(R.styleable.ShapeView_cornerSize, 0f)
|
||||||
|
corners[0] = getDimension(R.styleable.ShapeView_cornerSizeTopLeft, cornerSize)
|
||||||
|
corners[1] = corners[0]
|
||||||
|
corners[2] = getDimension(R.styleable.ShapeView_cornerSizeTopRight, cornerSize)
|
||||||
|
corners[3] = corners[2]
|
||||||
|
corners[4] = getDimension(R.styleable.ShapeView_cornerSizeBottomRight, cornerSize)
|
||||||
|
corners[5] = corners[4]
|
||||||
|
corners[6] = getDimension(R.styleable.ShapeView_cornerSizeBottomLeft, cornerSize)
|
||||||
|
corners[7] = corners[6]
|
||||||
|
strokePaint.color = getColor(R.styleable.ShapeView_strokeColor, Color.TRANSPARENT)
|
||||||
|
strokePaint.strokeWidth = getDimension(R.styleable.ShapeView_strokeWidth, 0f)
|
||||||
|
strokePaint.style = Paint.Style.STROKE
|
||||||
|
}
|
||||||
|
outlineProvider = OutlineProvider()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh)
|
||||||
|
if (w != oldw || h != oldh) {
|
||||||
|
rebuildPath()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun draw(canvas: Canvas) {
|
||||||
|
canvas.withClip(outlinePath) {
|
||||||
|
super.draw(canvas)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas) {
|
||||||
|
super.onDraw(canvas)
|
||||||
|
if (strokePaint.strokeWidth > 0f) {
|
||||||
|
canvas.drawPath(outlinePath, strokePaint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun rebuildPath() {
|
||||||
|
outlinePath.reset()
|
||||||
|
val w = width
|
||||||
|
val h = height
|
||||||
|
if (w > 0 && h > 0) {
|
||||||
|
outlinePath.addRoundRect(0f, 0f, w.toFloat(), h.toFloat(), corners, Path.Direction.CW)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class OutlineProvider : ViewOutlineProvider() {
|
||||||
|
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
|
override fun getOutline(view: View?, outline: Outline) {
|
||||||
|
val corner = corners[0]
|
||||||
|
var isRoundRect = true
|
||||||
|
for (item in corners) {
|
||||||
|
if (item != corner) {
|
||||||
|
isRoundRect = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isRoundRect) {
|
||||||
|
outline.setRoundRect(0, 0, width, height, corner)
|
||||||
|
} else {
|
||||||
|
DrawableUtils.setOutlineToPath(outline, outlinePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,6 @@ import org.koitharu.kotatsu.databinding.ItemBookmarkBinding
|
|||||||
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
||||||
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
import org.koitharu.kotatsu.utils.ext.referer
|
|
||||||
|
|
||||||
fun bookmarkListAD(
|
fun bookmarkListAD(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -26,8 +25,7 @@ fun bookmarkListAD(
|
|||||||
binding.root.setOnLongClickListener(listener)
|
binding.root.setOnLongClickListener(listener)
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.imageViewThumb.newImageRequest(item.imageUrl)?.run {
|
binding.imageViewThumb.newImageRequest(item.imageUrl, item.manga.source)?.run {
|
||||||
referer(item.manga.publicUrl)
|
|
||||||
placeholder(R.drawable.ic_placeholder)
|
placeholder(R.drawable.ic_placeholder)
|
||||||
fallback(R.drawable.ic_placeholder)
|
fallback(R.drawable.ic_placeholder)
|
||||||
error(R.drawable.ic_error_placeholder)
|
error(R.drawable.ic_error_placeholder)
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
|||||||
import org.koitharu.kotatsu.databinding.ItemBookmarksGroupBinding
|
import org.koitharu.kotatsu.databinding.ItemBookmarksGroupBinding
|
||||||
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 org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.clearItemDecorations
|
||||||
|
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
|
|
||||||
fun bookmarksGroupAD(
|
fun bookmarksGroupAD(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -45,8 +48,7 @@ fun bookmarksGroupAD(
|
|||||||
binding.recyclerView.addItemDecoration(spacingDecoration)
|
binding.recyclerView.addItemDecoration(spacingDecoration)
|
||||||
selectionController.attachToRecyclerView(item.manga, binding.recyclerView)
|
selectionController.attachToRecyclerView(item.manga, binding.recyclerView)
|
||||||
}
|
}
|
||||||
binding.imageViewCover.newImageRequest(item.manga.coverUrl)?.run {
|
binding.imageViewCover.newImageRequest(item.manga.coverUrl, item.manga.source)?.run {
|
||||||
referer(item.manga.publicUrl)
|
|
||||||
placeholder(R.drawable.ic_placeholder)
|
placeholder(R.drawable.ic_placeholder)
|
||||||
fallback(R.drawable.ic_placeholder)
|
fallback(R.drawable.ic_placeholder)
|
||||||
error(R.drawable.ic_error_placeholder)
|
error(R.drawable.ic_error_placeholder)
|
||||||
|
|||||||
@@ -8,20 +8,20 @@ import android.net.Uri
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.ViewGroup
|
|
||||||
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.core.view.updatePadding
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
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.core.network.UserAgentInterceptor
|
import org.koitharu.kotatsu.core.network.CommonHeadersInterceptor
|
||||||
import org.koitharu.kotatsu.databinding.ActivityBrowserBinding
|
import org.koitharu.kotatsu.databinding.ActivityBrowserBinding
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback {
|
class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback {
|
||||||
|
|
||||||
|
private lateinit var onBackPressedCallback: WebViewBackPressedCallback
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(ActivityBrowserBinding.inflate(layoutInflater))
|
setContentView(ActivityBrowserBinding.inflate(layoutInflater))
|
||||||
@@ -31,10 +31,12 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
}
|
}
|
||||||
with(binding.webView.settings) {
|
with(binding.webView.settings) {
|
||||||
javaScriptEnabled = true
|
javaScriptEnabled = true
|
||||||
userAgentString = UserAgentInterceptor.userAgent
|
userAgentString = CommonHeadersInterceptor.userAgentChrome
|
||||||
}
|
}
|
||||||
binding.webView.webViewClient = BrowserClient(this)
|
binding.webView.webViewClient = BrowserClient(this)
|
||||||
binding.webView.webChromeClient = ProgressChromeClient(binding.progressBar)
|
binding.webView.webChromeClient = ProgressChromeClient(binding.progressBar)
|
||||||
|
onBackPressedCallback = WebViewBackPressedCallback(binding.webView)
|
||||||
|
onBackPressedDispatcher.addCallback(onBackPressedCallback)
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -72,6 +74,7 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
finishAfterTransition()
|
finishAfterTransition()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_browser -> {
|
R.id.action_browser -> {
|
||||||
val intent = Intent(Intent.ACTION_VIEW)
|
val intent = Intent(Intent.ACTION_VIEW)
|
||||||
intent.data = Uri.parse(binding.webView.url)
|
intent.data = Uri.parse(binding.webView.url)
|
||||||
@@ -81,15 +84,8 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> super.onOptionsItemSelected(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBackPressed() {
|
else -> super.onOptionsItemSelected(item)
|
||||||
if (binding.webView.canGoBack()) {
|
|
||||||
binding.webView.goBack()
|
|
||||||
} else {
|
|
||||||
super.onBackPressed()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
@@ -116,6 +112,10 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
supportActionBar?.subtitle = subtitle
|
supportActionBar?.subtitle = subtitle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onHistoryChanged() {
|
||||||
|
onBackPressedCallback.onHistoryChanged()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onWindowInsetsChanged(insets: Insets) {
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
binding.appbar.updatePadding(
|
binding.appbar.updatePadding(
|
||||||
top = insets.top,
|
top = insets.top,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.browser
|
package org.koitharu.kotatsu.browser
|
||||||
|
|
||||||
interface BrowserCallback {
|
interface BrowserCallback : OnHistoryChangedListener {
|
||||||
|
|
||||||
fun onLoadingStateChanged(isLoading: Boolean)
|
fun onLoadingStateChanged(isLoading: Boolean)
|
||||||
|
|
||||||
fun onTitleChanged(title: CharSequence, subtitle: CharSequence?)
|
fun onTitleChanged(title: CharSequence, subtitle: CharSequence?)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import android.graphics.Bitmap
|
|||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.webkit.WebViewClient
|
import android.webkit.WebViewClient
|
||||||
|
|
||||||
class BrowserClient(private val callback: BrowserCallback) : WebViewClient() {
|
open class BrowserClient(private val callback: BrowserCallback) : WebViewClient() {
|
||||||
|
|
||||||
override fun onPageFinished(webView: WebView, url: String) {
|
override fun onPageFinished(webView: WebView, url: String) {
|
||||||
super.onPageFinished(webView, url)
|
super.onPageFinished(webView, url)
|
||||||
@@ -20,4 +20,9 @@ class BrowserClient(private val callback: BrowserCallback) : WebViewClient() {
|
|||||||
super.onPageCommitVisible(view, url)
|
super.onPageCommitVisible(view, url)
|
||||||
callback.onTitleChanged(view.title.orEmpty(), url)
|
callback.onTitleChanged(view.title.orEmpty(), url)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) {
|
||||||
|
super.doUpdateVisitedHistory(view, url, isReload)
|
||||||
|
callback.onHistoryChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package org.koitharu.kotatsu.browser
|
||||||
|
|
||||||
|
fun interface OnHistoryChangedListener {
|
||||||
|
|
||||||
|
fun onHistoryChanged()
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.koitharu.kotatsu.browser
|
||||||
|
|
||||||
|
import android.webkit.WebView
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
|
|
||||||
|
class WebViewBackPressedCallback(
|
||||||
|
private val webView: WebView,
|
||||||
|
) : OnBackPressedCallback(false), OnHistoryChangedListener {
|
||||||
|
|
||||||
|
init {
|
||||||
|
onHistoryChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
webView.goBack()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onHistoryChanged() {
|
||||||
|
isEnabled = webView.canGoBack()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
package org.koitharu.kotatsu.browser.cloudflare
|
package org.koitharu.kotatsu.browser.cloudflare
|
||||||
|
|
||||||
interface CloudFlareCallback {
|
import org.koitharu.kotatsu.browser.BrowserCallback
|
||||||
|
|
||||||
|
interface CloudFlareCallback : BrowserCallback {
|
||||||
|
|
||||||
|
override fun onLoadingStateChanged(isLoading: Boolean) = Unit
|
||||||
|
|
||||||
|
override fun onTitleChanged(title: CharSequence, subtitle: CharSequence?) = Unit
|
||||||
|
|
||||||
fun onPageLoaded()
|
fun onPageLoaded()
|
||||||
|
|
||||||
fun onCheckPassed()
|
fun onCheckPassed()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,32 +2,32 @@ package org.koitharu.kotatsu.browser.cloudflare
|
|||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.webkit.WebViewClient
|
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
import org.koitharu.kotatsu.browser.BrowserClient
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||||
|
|
||||||
private const val CF_CLEARANCE = "cf_clearance"
|
private const val CF_CLEARANCE = "cf_clearance"
|
||||||
|
|
||||||
class CloudFlareClient(
|
class CloudFlareClient(
|
||||||
private val cookieJar: AndroidCookieJar,
|
private val cookieJar: MutableCookieJar,
|
||||||
private val callback: CloudFlareCallback,
|
private val callback: CloudFlareCallback,
|
||||||
private val targetUrl: String,
|
private val targetUrl: String,
|
||||||
) : WebViewClient() {
|
) : BrowserClient(callback) {
|
||||||
|
|
||||||
private val oldClearance = getClearance()
|
private val oldClearance = getClearance()
|
||||||
|
|
||||||
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
|
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||||
super.onPageStarted(view, url, favicon)
|
super.onPageStarted(view, url, favicon)
|
||||||
checkClearance()
|
checkClearance()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageCommitVisible(view: WebView?, url: String?) {
|
override fun onPageCommitVisible(view: WebView, url: String?) {
|
||||||
super.onPageCommitVisible(view, url)
|
super.onPageCommitVisible(view, url)
|
||||||
callback.onPageLoaded()
|
callback.onPageLoaded()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageFinished(view: WebView?, url: String?) {
|
override fun onPageFinished(webView: WebView, url: String) {
|
||||||
super.onPageFinished(view, url)
|
super.onPageFinished(webView, url)
|
||||||
callback.onPageLoaded()
|
callback.onPageLoaded()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,4 +42,4 @@ class CloudFlareClient(
|
|||||||
return cookieJar.loadForRequest(targetUrl.toHttpUrl())
|
return cookieJar.loadForRequest(targetUrl.toHttpUrl())
|
||||||
.find { it.name == CF_CLEARANCE }?.value
|
.find { it.name == CF_CLEARANCE }?.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,17 +8,21 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import android.webkit.WebSettings
|
import android.webkit.WebSettings
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.view.isInvisible
|
import androidx.core.view.isInvisible
|
||||||
import androidx.fragment.app.setFragmentResult
|
import androidx.fragment.app.setFragmentResult
|
||||||
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 javax.inject.Inject
|
import okhttp3.Headers
|
||||||
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
||||||
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
import org.koitharu.kotatsu.browser.WebViewBackPressedCallback
|
||||||
import org.koitharu.kotatsu.core.network.UserAgentInterceptor
|
import org.koitharu.kotatsu.core.network.CommonHeaders
|
||||||
|
import org.koitharu.kotatsu.core.network.CommonHeadersInterceptor
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||||
import org.koitharu.kotatsu.databinding.FragmentCloudflareBinding
|
import org.koitharu.kotatsu.databinding.FragmentCloudflareBinding
|
||||||
import org.koitharu.kotatsu.utils.ext.stringArgument
|
import org.koitharu.kotatsu.utils.ext.stringArgument
|
||||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), CloudFlareCallback {
|
class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), CloudFlareCallback {
|
||||||
@@ -27,7 +31,9 @@ class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), Cloud
|
|||||||
private val pendingResult = Bundle(1)
|
private val pendingResult = Bundle(1)
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var cookieJar: AndroidCookieJar
|
lateinit var cookieJar: MutableCookieJar
|
||||||
|
|
||||||
|
private var onBackPressedCallback: WebViewBackPressedCallback? = null
|
||||||
|
|
||||||
override fun onInflateView(
|
override fun onInflateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
@@ -42,7 +48,7 @@ class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), Cloud
|
|||||||
cacheMode = WebSettings.LOAD_DEFAULT
|
cacheMode = WebSettings.LOAD_DEFAULT
|
||||||
domStorageEnabled = true
|
domStorageEnabled = true
|
||||||
databaseEnabled = true
|
databaseEnabled = true
|
||||||
userAgentString = UserAgentInterceptor.userAgent
|
userAgentString = arguments?.getString(ARG_UA) ?: CommonHeadersInterceptor.userAgentChrome
|
||||||
}
|
}
|
||||||
binding.webView.webViewClient = CloudFlareClient(cookieJar, this, url.orEmpty())
|
binding.webView.webViewClient = CloudFlareClient(cookieJar, this, url.orEmpty())
|
||||||
CookieManager.getInstance().setAcceptThirdPartyCookies(binding.webView, true)
|
CookieManager.getInstance().setAcceptThirdPartyCookies(binding.webView, true)
|
||||||
@@ -56,6 +62,7 @@ class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), Cloud
|
|||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
binding.webView.stopLoading()
|
binding.webView.stopLoading()
|
||||||
binding.webView.destroy()
|
binding.webView.destroy()
|
||||||
|
onBackPressedCallback = null
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +70,13 @@ class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), Cloud
|
|||||||
return super.onBuildDialog(builder).setNegativeButton(android.R.string.cancel, null)
|
return super.onBuildDialog(builder).setNegativeButton(android.R.string.cancel, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDialogCreated(dialog: AlertDialog) {
|
||||||
|
super.onDialogCreated(dialog)
|
||||||
|
onBackPressedCallback = WebViewBackPressedCallback(binding.webView).also {
|
||||||
|
dialog.onBackPressedDispatcher.addCallback(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
binding.webView.onResume()
|
binding.webView.onResume()
|
||||||
@@ -87,14 +101,22 @@ class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), Cloud
|
|||||||
dismissAllowingStateLoss()
|
dismissAllowingStateLoss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onHistoryChanged() {
|
||||||
|
onBackPressedCallback?.onHistoryChanged()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val TAG = "CloudFlareDialog"
|
const val TAG = "CloudFlareDialog"
|
||||||
const val EXTRA_RESULT = "result"
|
const val EXTRA_RESULT = "result"
|
||||||
private const val ARG_URL = "url"
|
private const val ARG_URL = "url"
|
||||||
|
private const val ARG_UA = "ua"
|
||||||
|
|
||||||
fun newInstance(url: String) = CloudFlareDialog().withArgs(1) {
|
fun newInstance(url: String, headers: Headers?) = CloudFlareDialog().withArgs(2) {
|
||||||
putString(ARG_URL, url)
|
putString(ARG_URL, url)
|
||||||
|
headers?.get(CommonHeaders.USER_AGENT)?.let {
|
||||||
|
putString(ARG_UA, it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.app.Application
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.provider.SearchRecentSuggestions
|
import android.provider.SearchRecentSuggestions
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
|
import android.util.AndroidRuntimeException
|
||||||
import androidx.collection.arraySetOf
|
import androidx.collection.arraySetOf
|
||||||
import androidx.room.InvalidationTracker
|
import androidx.room.InvalidationTracker
|
||||||
import coil.ComponentRegistry
|
import coil.ComponentRegistry
|
||||||
@@ -23,8 +24,15 @@ import okhttp3.CookieJar
|
|||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
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.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.core.cache.MemoryContentCache
|
||||||
|
import org.koitharu.kotatsu.core.cache.StubContentCache
|
||||||
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.network.cookies.AndroidCookieJar
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.PreferencesCookieJar
|
||||||
|
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
|
||||||
@@ -39,6 +47,8 @@ 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.IncognitoModeIndicator
|
||||||
|
import org.koitharu.kotatsu.utils.ext.activityManager
|
||||||
|
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
|
||||||
@@ -50,7 +60,7 @@ import javax.inject.Singleton
|
|||||||
interface AppModule {
|
interface AppModule {
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
fun bindCookieJar(androidCookieJar: AndroidCookieJar): CookieJar
|
fun bindCookieJar(androidCookieJar: MutableCookieJar): CookieJar
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
fun bindMangaLoaderContext(mangaLoaderContextImpl: MangaLoaderContextImpl): MangaLoaderContext
|
fun bindMangaLoaderContext(mangaLoaderContextImpl: MangaLoaderContextImpl): MangaLoaderContext
|
||||||
@@ -60,10 +70,22 @@ interface AppModule {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideCookieJar(
|
||||||
|
@ApplicationContext context: Context
|
||||||
|
): MutableCookieJar = try {
|
||||||
|
AndroidCookieJar()
|
||||||
|
} catch (e: AndroidRuntimeException) {
|
||||||
|
// WebView is not available
|
||||||
|
PreferencesCookieJar(context)
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideOkHttpClient(
|
fun provideOkHttpClient(
|
||||||
localStorageManager: LocalStorageManager,
|
localStorageManager: LocalStorageManager,
|
||||||
|
commonHeadersInterceptor: CommonHeadersInterceptor,
|
||||||
cookieJar: CookieJar,
|
cookieJar: CookieJar,
|
||||||
settings: AppSettings,
|
settings: AppSettings,
|
||||||
): OkHttpClient {
|
): OkHttpClient {
|
||||||
@@ -76,11 +98,20 @@ interface AppModule {
|
|||||||
dns(DoHManager(cache, settings))
|
dns(DoHManager(cache, settings))
|
||||||
cache(cache)
|
cache(cache)
|
||||||
addInterceptor(GZipInterceptor())
|
addInterceptor(GZipInterceptor())
|
||||||
addInterceptor(UserAgentInterceptor())
|
addInterceptor(commonHeadersInterceptor)
|
||||||
addInterceptor(CloudFlareInterceptor())
|
addInterceptor(CloudFlareInterceptor())
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
addInterceptor(CurlLoggingInterceptor())
|
||||||
|
}
|
||||||
}.build()
|
}.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideNetworkState(
|
||||||
|
@ApplicationContext context: Context
|
||||||
|
) = NetworkState(context.connectivityManager)
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideMangaDatabase(
|
fun provideMangaDatabase(
|
||||||
@@ -159,5 +190,17 @@ interface AppModule {
|
|||||||
activityRecreationHandle,
|
activityRecreationHandle,
|
||||||
incognitoModeIndicator,
|
incognitoModeIndicator,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideContentCache(
|
||||||
|
application: Application,
|
||||||
|
): ContentCache {
|
||||||
|
return if (application.activityManager?.isLowRamDevice == true) {
|
||||||
|
StubContentCache()
|
||||||
|
} else {
|
||||||
|
MemoryContentCache(application)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
app/src/main/java/org/koitharu/kotatsu/core/cache/ContentCache.kt
vendored
Normal file
23
app/src/main/java/org/koitharu/kotatsu/core/cache/ContentCache.kt
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
|
||||||
|
interface ContentCache {
|
||||||
|
|
||||||
|
val isCachingEnabled: Boolean
|
||||||
|
|
||||||
|
suspend fun getDetails(source: MangaSource, url: String): Manga?
|
||||||
|
|
||||||
|
fun putDetails(source: MangaSource, url: String, details: SafeDeferred<Manga>)
|
||||||
|
|
||||||
|
suspend fun getPages(source: MangaSource, url: String): List<MangaPage>?
|
||||||
|
|
||||||
|
fun putPages(source: MangaSource, url: String, pages: SafeDeferred<List<MangaPage>>)
|
||||||
|
|
||||||
|
data class Key(
|
||||||
|
val source: MangaSource,
|
||||||
|
val url: String,
|
||||||
|
)
|
||||||
|
}
|
||||||
5
app/src/main/java/org/koitharu/kotatsu/core/cache/DeferredLruCache.kt
vendored
Normal file
5
app/src/main/java/org/koitharu/kotatsu/core/cache/DeferredLruCache.kt
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import androidx.collection.LruCache
|
||||||
|
|
||||||
|
class DeferredLruCache<T>(maxSize: Int) : LruCache<ContentCache.Key, SafeDeferred<T>>(maxSize)
|
||||||
59
app/src/main/java/org/koitharu/kotatsu/core/cache/MemoryContentCache.kt
vendored
Normal file
59
app/src/main/java/org/koitharu/kotatsu/core/cache/MemoryContentCache.kt
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import android.content.ComponentCallbacks2
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
|
||||||
|
class MemoryContentCache(application: Application) : ContentCache, ComponentCallbacks2 {
|
||||||
|
|
||||||
|
init {
|
||||||
|
application.registerComponentCallbacks(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val detailsCache = DeferredLruCache<Manga>(4)
|
||||||
|
private val pagesCache = DeferredLruCache<List<MangaPage>>(4)
|
||||||
|
|
||||||
|
override val isCachingEnabled: Boolean = true
|
||||||
|
|
||||||
|
override suspend fun getDetails(source: MangaSource, url: String): Manga? {
|
||||||
|
return detailsCache[ContentCache.Key(source, url)]?.awaitOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun putDetails(source: MangaSource, url: String, details: SafeDeferred<Manga>) {
|
||||||
|
detailsCache.put(ContentCache.Key(source, url), details)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getPages(source: MangaSource, url: String): List<MangaPage>? {
|
||||||
|
return pagesCache[ContentCache.Key(source, url)]?.awaitOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun putPages(source: MangaSource, url: String, pages: SafeDeferred<List<MangaPage>>) {
|
||||||
|
pagesCache.put(ContentCache.Key(source, url), pages)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration) = Unit
|
||||||
|
|
||||||
|
override fun onLowMemory() = Unit
|
||||||
|
|
||||||
|
override fun onTrimMemory(level: Int) {
|
||||||
|
trimCache(detailsCache, level)
|
||||||
|
trimCache(pagesCache, level)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun trimCache(cache: DeferredLruCache<*>, level: Int) {
|
||||||
|
when (level) {
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL,
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_COMPLETE,
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_MODERATE -> cache.evictAll()
|
||||||
|
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN,
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW,
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_BACKGROUND -> cache.trimToSize(1)
|
||||||
|
|
||||||
|
else -> cache.trimToSize(cache.maxSize() / 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
app/src/main/java/org/koitharu/kotatsu/core/cache/SafeDeferred.kt
vendored
Normal file
20
app/src/main/java/org/koitharu/kotatsu/core/cache/SafeDeferred.kt
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import kotlinx.coroutines.Deferred
|
||||||
|
|
||||||
|
class SafeDeferred<T>(
|
||||||
|
private val delegate: Deferred<Result<T>>,
|
||||||
|
) {
|
||||||
|
|
||||||
|
suspend fun await(): T {
|
||||||
|
return delegate.await().getOrThrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun awaitOrNull(): T? {
|
||||||
|
return delegate.await().getOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cancel() {
|
||||||
|
delegate.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/src/main/java/org/koitharu/kotatsu/core/cache/StubContentCache.kt
vendored
Normal file
18
app/src/main/java/org/koitharu/kotatsu/core/cache/StubContentCache.kt
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
|
||||||
|
class StubContentCache : ContentCache {
|
||||||
|
|
||||||
|
override val isCachingEnabled: Boolean = false
|
||||||
|
|
||||||
|
override suspend fun getDetails(source: MangaSource, url: String): Manga? = null
|
||||||
|
|
||||||
|
override fun putDetails(source: MangaSource, url: String, details: SafeDeferred<Manga>) = Unit
|
||||||
|
|
||||||
|
override suspend fun getPages(source: MangaSource, url: String): List<MangaPage>? = null
|
||||||
|
|
||||||
|
override fun putPages(source: MangaSource, url: String, pages: SafeDeferred<List<MangaPage>>) = Unit
|
||||||
|
}
|
||||||
@@ -19,15 +19,28 @@ import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
|||||||
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
|
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaTagsEntity
|
import org.koitharu.kotatsu.core.db.entity.MangaTagsEntity
|
||||||
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
||||||
import org.koitharu.kotatsu.core.db.migrations.*
|
import org.koitharu.kotatsu.core.db.migrations.Migration10To11
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration11To12
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration12To13
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration13To14
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration14To15
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration1To2
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration2To3
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration3To4
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration4To5
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration5To6
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration6To7
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration7To8
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration8To9
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.Migration9To10
|
||||||
import org.koitharu.kotatsu.favourites.data.FavouriteCategoriesDao
|
import org.koitharu.kotatsu.favourites.data.FavouriteCategoriesDao
|
||||||
import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
|
import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
|
||||||
import org.koitharu.kotatsu.favourites.data.FavouriteEntity
|
import org.koitharu.kotatsu.favourites.data.FavouriteEntity
|
||||||
import org.koitharu.kotatsu.favourites.data.FavouritesDao
|
import org.koitharu.kotatsu.favourites.data.FavouritesDao
|
||||||
import org.koitharu.kotatsu.history.data.HistoryDao
|
import org.koitharu.kotatsu.history.data.HistoryDao
|
||||||
import org.koitharu.kotatsu.history.data.HistoryEntity
|
import org.koitharu.kotatsu.history.data.HistoryEntity
|
||||||
import org.koitharu.kotatsu.scrobbling.data.ScrobblingDao
|
import org.koitharu.kotatsu.scrobbling.common.data.ScrobblingDao
|
||||||
import org.koitharu.kotatsu.scrobbling.data.ScrobblingEntity
|
import org.koitharu.kotatsu.scrobbling.common.data.ScrobblingEntity
|
||||||
import org.koitharu.kotatsu.suggestions.data.SuggestionDao
|
import org.koitharu.kotatsu.suggestions.data.SuggestionDao
|
||||||
import org.koitharu.kotatsu.suggestions.data.SuggestionEntity
|
import org.koitharu.kotatsu.suggestions.data.SuggestionEntity
|
||||||
import org.koitharu.kotatsu.tracker.data.TrackEntity
|
import org.koitharu.kotatsu.tracker.data.TrackEntity
|
||||||
|
|||||||
@@ -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 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,16 +13,6 @@ abstract class PreferencesDao {
|
|||||||
@Query("SELECT * FROM preferences WHERE manga_id = :mangaId")
|
@Query("SELECT * FROM preferences WHERE manga_id = :mangaId")
|
||||||
abstract fun observe(mangaId: Long): Flow<MangaPrefsEntity?>
|
abstract fun observe(mangaId: Long): Flow<MangaPrefsEntity?>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Upsert
|
||||||
abstract suspend fun insert(pref: MangaPrefsEntity): Long
|
abstract suspend fun upsert(pref: MangaPrefsEntity)
|
||||||
|
|
||||||
@Update
|
|
||||||
abstract suspend fun update(pref: MangaPrefsEntity): Int
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
open suspend fun upsert(pref: MangaPrefsEntity) {
|
|
||||||
if (update(pref) == 0) {
|
|
||||||
insert(pref)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ abstract class TagsDao {
|
|||||||
LEFT JOIN manga_tags ON tags.tag_id = manga_tags.tag_id
|
LEFT JOIN manga_tags ON tags.tag_id = manga_tags.tag_id
|
||||||
GROUP BY tags.title
|
GROUP BY tags.title
|
||||||
ORDER BY COUNT(manga_id) DESC
|
ORDER BY COUNT(manga_id) DESC
|
||||||
LIMIT :limit"""
|
LIMIT :limit""",
|
||||||
)
|
)
|
||||||
abstract suspend fun findPopularTags(limit: Int): List<TagEntity>
|
abstract suspend fun findPopularTags(limit: Int): List<TagEntity>
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ abstract class TagsDao {
|
|||||||
WHERE tags.source = :source
|
WHERE tags.source = :source
|
||||||
GROUP BY tags.title
|
GROUP BY tags.title
|
||||||
ORDER BY COUNT(manga_id) DESC
|
ORDER BY COUNT(manga_id) DESC
|
||||||
LIMIT :limit"""
|
LIMIT :limit""",
|
||||||
)
|
)
|
||||||
abstract suspend fun findPopularTags(source: String, limit: Int): List<TagEntity>
|
abstract suspend fun findPopularTags(source: String, limit: Int): List<TagEntity>
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ abstract class TagsDao {
|
|||||||
WHERE tags.source = :source AND title LIKE :query
|
WHERE tags.source = :source AND title LIKE :query
|
||||||
GROUP BY tags.title
|
GROUP BY tags.title
|
||||||
ORDER BY COUNT(manga_id) DESC
|
ORDER BY COUNT(manga_id) DESC
|
||||||
LIMIT :limit"""
|
LIMIT :limit""",
|
||||||
)
|
)
|
||||||
abstract suspend fun findTags(source: String, query: String, limit: Int): List<TagEntity>
|
abstract suspend fun findTags(source: String, query: String, limit: Int): List<TagEntity>
|
||||||
|
|
||||||
@@ -44,22 +44,10 @@ abstract class TagsDao {
|
|||||||
WHERE title LIKE :query
|
WHERE title LIKE :query
|
||||||
GROUP BY tags.title
|
GROUP BY tags.title
|
||||||
ORDER BY COUNT(manga_id) DESC
|
ORDER BY COUNT(manga_id) DESC
|
||||||
LIMIT :limit"""
|
LIMIT :limit""",
|
||||||
)
|
)
|
||||||
abstract suspend fun findTags(query: String, limit: Int): List<TagEntity>
|
abstract suspend fun findTags(query: String, limit: Int): List<TagEntity>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Upsert
|
||||||
abstract suspend fun insert(tag: TagEntity): Long
|
abstract suspend fun upsert(tags: Iterable<TagEntity>)
|
||||||
|
}
|
||||||
@Update(onConflict = OnConflictStrategy.IGNORE)
|
|
||||||
abstract suspend fun update(tag: TagEntity): Int
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
open suspend fun upsert(tags: Iterable<TagEntity>) {
|
|
||||||
tags.forEach { tag ->
|
|
||||||
if (update(tag) <= 0) {
|
|
||||||
insert(tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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,7 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions
|
package org.koitharu.kotatsu.core.exceptions
|
||||||
|
|
||||||
|
import okhttp3.Headers
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
|
|
||||||
class CloudFlareProtectedException(
|
class CloudFlareProtectedException(
|
||||||
val url: String
|
val url: String,
|
||||||
) : IOException("Protected by CloudFlare")
|
val headers: Headers,
|
||||||
|
) : IOException("Protected by CloudFlare")
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions.resolve
|
package org.koitharu.kotatsu.core.exceptions.resolve
|
||||||
|
|
||||||
import android.util.ArrayMap
|
import android.content.ClipData
|
||||||
|
import android.content.ClipboardManager
|
||||||
|
import android.content.Context
|
||||||
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 kotlin.coroutines.Continuation
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
|
import okhttp3.Headers
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.browser.BrowserActivity
|
import org.koitharu.kotatsu.browser.BrowserActivity
|
||||||
import org.koitharu.kotatsu.browser.cloudflare.CloudFlareDialog
|
import org.koitharu.kotatsu.browser.cloudflare.CloudFlareDialog
|
||||||
@@ -19,7 +21,11 @@ import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.settings.sources.auth.SourceAuthActivity
|
import org.koitharu.kotatsu.settings.sources.auth.SourceAuthActivity
|
||||||
import org.koitharu.kotatsu.utils.TaggedActivityResult
|
import org.koitharu.kotatsu.utils.TaggedActivityResult
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
import org.koitharu.kotatsu.utils.isSuccess
|
import org.koitharu.kotatsu.utils.isSuccess
|
||||||
|
import kotlin.coroutines.Continuation
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
class ExceptionResolver private constructor(
|
class ExceptionResolver private constructor(
|
||||||
private val activity: FragmentActivity?,
|
private val activity: FragmentActivity?,
|
||||||
@@ -43,17 +49,18 @@ class ExceptionResolver private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun resolve(e: Throwable): Boolean = when (e) {
|
suspend fun resolve(e: Throwable): Boolean = when (e) {
|
||||||
is CloudFlareProtectedException -> resolveCF(e.url)
|
is CloudFlareProtectedException -> resolveCF(e.url, e.headers)
|
||||||
is AuthRequiredException -> resolveAuthException(e.source)
|
is AuthRequiredException -> resolveAuthException(e.source)
|
||||||
is NotFoundException -> {
|
is NotFoundException -> {
|
||||||
openInBrowser(e.url)
|
openInBrowser(e.url)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun resolveCF(url: String): Boolean {
|
private suspend fun resolveCF(url: String, headers: Headers): Boolean {
|
||||||
val dialog = CloudFlareDialog.newInstance(url)
|
val dialog = CloudFlareDialog.newInstance(url, headers)
|
||||||
val fm = getFragmentManager()
|
val fm = getFragmentManager()
|
||||||
return suspendCancellableCoroutine { cont ->
|
return suspendCancellableCoroutine { cont ->
|
||||||
fm.clearFragmentResult(CloudFlareDialog.TAG)
|
fm.clearFragmentResult(CloudFlareDialog.TAG)
|
||||||
@@ -93,5 +100,21 @@ class ExceptionResolver private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun canResolve(e: Throwable) = getResolveStringId(e) != 0
|
fun canResolve(e: Throwable) = getResolveStringId(e) != 0
|
||||||
|
|
||||||
|
fun showDetails(context: Context, e: Throwable) {
|
||||||
|
val stackTrace = e.stackTraceToString()
|
||||||
|
val dialog = MaterialAlertDialogBuilder(context)
|
||||||
|
.setTitle(e.getDisplayMessage(context.resources))
|
||||||
|
.setMessage(stackTrace)
|
||||||
|
.setPositiveButton(androidx.preference.R.string.copy) { _, _ ->
|
||||||
|
val clipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
|
clipboardManager.setPrimaryClip(
|
||||||
|
ClipData.newPlainText(context.getString(R.string.error), stackTrace),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.close, null)
|
||||||
|
.create()
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import kotlinx.coroutines.withContext
|
|||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.parsers.util.await
|
import org.koitharu.kotatsu.parsers.util.await
|
||||||
import org.koitharu.kotatsu.parsers.util.byte2HexFormatted
|
import org.koitharu.kotatsu.parsers.util.byte2HexFormatted
|
||||||
import org.koitharu.kotatsu.parsers.util.json.mapJSONNotNull
|
import org.koitharu.kotatsu.parsers.util.json.mapJSONNotNull
|
||||||
@@ -31,6 +32,7 @@ private const val CERT_SHA1 = "2C:19:C7:E8:07:61:2B:8E:94:51:1B:FD:72:67:07:64:5
|
|||||||
@Singleton
|
@Singleton
|
||||||
class AppUpdateRepository @Inject constructor(
|
class AppUpdateRepository @Inject constructor(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
|
private val settings: AppSettings,
|
||||||
private val okHttp: OkHttpClient,
|
private val okHttp: OkHttpClient,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -64,7 +66,7 @@ class AppUpdateRepository @Inject constructor(
|
|||||||
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 }
|
||||||
if (currentVersion.isStable) {
|
if (currentVersion.isStable && !settings.isUnstableUpdatesAllowed) {
|
||||||
available.retainAll { it.versionId.isStable }
|
available.retainAll { it.versionId.isStable }
|
||||||
}
|
}
|
||||||
available.maxByOrNull { it.versionId }
|
available.maxByOrNull { it.versionId }
|
||||||
@@ -80,6 +82,12 @@ class AppUpdateRepository @Inject constructor(
|
|||||||
return BuildConfig.DEBUG || getCertificateSHA1Fingerprint() == CERT_SHA1
|
return BuildConfig.DEBUG || getCertificateSHA1Fingerprint() == CERT_SHA1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getCurrentVersionChangelog(): String? {
|
||||||
|
val currentVersion = VersionId(BuildConfig.VERSION_NAME)
|
||||||
|
val available = getAvailableVersions()
|
||||||
|
return available.find { x -> x.versionId == currentVersion }?.description
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@SuppressLint("PackageManagerGetSignatures")
|
@SuppressLint("PackageManagerGetSignatures")
|
||||||
private fun getCertificateSHA1Fingerprint(): String? = runCatching {
|
private fun getCertificateSHA1Fingerprint(): String? = runCatching {
|
||||||
|
|||||||
134
app/src/main/java/org/koitharu/kotatsu/core/logs/FileLogger.kt
Normal file
134
app/src/main/java/org/koitharu/kotatsu/core/logs/FileLogger.kt
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
package org.koitharu.kotatsu.core.logs
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.annotation.WorkerThread
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.cancelAndJoin
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runInterruptible
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.subdir
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue
|
||||||
|
|
||||||
|
private const val DIR = "logs"
|
||||||
|
private const val FLUSH_DELAY = 2_000L
|
||||||
|
private const val MAX_SIZE_BYTES = 1024 * 1024 // 1 MB
|
||||||
|
|
||||||
|
class FileLogger(
|
||||||
|
context: Context,
|
||||||
|
private val settings: AppSettings,
|
||||||
|
name: String,
|
||||||
|
) {
|
||||||
|
|
||||||
|
val file by lazy {
|
||||||
|
val dir = context.getExternalFilesDir(DIR) ?: context.filesDir.subdir(DIR)
|
||||||
|
File(dir, "$name.log")
|
||||||
|
}
|
||||||
|
val isEnabled: Boolean
|
||||||
|
get() = settings.isLoggingEnabled
|
||||||
|
private val dateFormat = SimpleDateFormat.getDateTimeInstance(
|
||||||
|
SimpleDateFormat.SHORT,
|
||||||
|
SimpleDateFormat.SHORT,
|
||||||
|
Locale.ROOT,
|
||||||
|
)
|
||||||
|
private val buffer = ConcurrentLinkedQueue<String>()
|
||||||
|
private val mutex = Mutex()
|
||||||
|
private var flushJob: Job? = null
|
||||||
|
|
||||||
|
fun log(message: String, e: Throwable? = null) {
|
||||||
|
if (!isEnabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val text = buildString {
|
||||||
|
append(dateFormat.format(Date()))
|
||||||
|
append(": ")
|
||||||
|
if (e != null) {
|
||||||
|
append("E!")
|
||||||
|
}
|
||||||
|
append(message)
|
||||||
|
if (e != null) {
|
||||||
|
append(' ')
|
||||||
|
append(e.stackTraceToString())
|
||||||
|
appendLine()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffer.add(text)
|
||||||
|
postFlush()
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun log(messageProducer: () -> String) {
|
||||||
|
if (isEnabled) {
|
||||||
|
log(messageProducer())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun flush() {
|
||||||
|
if (!isEnabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
flushJob?.cancelAndJoin()
|
||||||
|
flushImpl()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun postFlush() {
|
||||||
|
if (flushJob?.isActive == true) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
flushJob = processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
|
delay(FLUSH_DELAY)
|
||||||
|
runCatchingCancellable {
|
||||||
|
flushImpl()
|
||||||
|
}.onFailure {
|
||||||
|
it.printStackTraceDebug()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun flushImpl() {
|
||||||
|
mutex.withLock {
|
||||||
|
if (buffer.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
runInterruptible(Dispatchers.IO) {
|
||||||
|
if (file.length() > MAX_SIZE_BYTES) {
|
||||||
|
rotate()
|
||||||
|
}
|
||||||
|
FileOutputStream(file, true).use {
|
||||||
|
while (true) {
|
||||||
|
val message = buffer.poll() ?: break
|
||||||
|
it.write(message.toByteArray())
|
||||||
|
it.write('\n'.code)
|
||||||
|
}
|
||||||
|
it.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
private fun rotate() {
|
||||||
|
val length = file.length()
|
||||||
|
val bakFile = File(file.parentFile, file.name + ".bak")
|
||||||
|
file.renameTo(bakFile)
|
||||||
|
bakFile.inputStream().use { input ->
|
||||||
|
input.skip(length - MAX_SIZE_BYTES / 2)
|
||||||
|
file.outputStream().use { output ->
|
||||||
|
input.copyTo(output)
|
||||||
|
output.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bakFile.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
11
app/src/main/java/org/koitharu/kotatsu/core/logs/Loggers.kt
Normal file
11
app/src/main/java/org/koitharu/kotatsu/core/logs/Loggers.kt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package org.koitharu.kotatsu.core.logs
|
||||||
|
|
||||||
|
import javax.inject.Qualifier
|
||||||
|
|
||||||
|
@Qualifier
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
annotation class TrackerLogger
|
||||||
|
|
||||||
|
@Qualifier
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
annotation class SyncLogger
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.koitharu.kotatsu.core.logs
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.collection.arraySetOf
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import dagger.multibindings.ElementsIntoSet
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
object LoggersModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@TrackerLogger
|
||||||
|
fun provideTrackerLogger(
|
||||||
|
@ApplicationContext context: Context,
|
||||||
|
settings: AppSettings,
|
||||||
|
) = FileLogger(context, settings, "tracker")
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@SyncLogger
|
||||||
|
fun provideSyncLogger(
|
||||||
|
@ApplicationContext context: Context,
|
||||||
|
settings: AppSettings,
|
||||||
|
) = FileLogger(context, settings, "sync")
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@ElementsIntoSet
|
||||||
|
fun provideAllLoggers(
|
||||||
|
@TrackerLogger trackerLogger: FileLogger,
|
||||||
|
@SyncLogger syncLogger: FileLogger,
|
||||||
|
): Set<@JvmSuppressWildcards FileLogger> = arraySetOf(
|
||||||
|
trackerLogger,
|
||||||
|
syncLogger,
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import android.os.Parcelable
|
|||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
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 * 100 // Assume that 100 kb is safe parcel size
|
||||||
private const val MAX_SAFE_CHAPTERS_COUNT = 32 // this is 100% safe
|
private const val MAX_SAFE_CHAPTERS_COUNT = 24 // this is 100% safe
|
||||||
|
|
||||||
class ParcelableManga(
|
class ParcelableManga(
|
||||||
val manga: Manga,
|
val manga: Manga,
|
||||||
|
|||||||
@@ -13,13 +13,17 @@ private const val SERVER_CLOUDFLARE = "cloudflare"
|
|||||||
class CloudFlareInterceptor : Interceptor {
|
class CloudFlareInterceptor : Interceptor {
|
||||||
|
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
val response = chain.proceed(chain.request())
|
val request = chain.request()
|
||||||
|
val response = chain.proceed(request)
|
||||||
if (response.code == HTTP_FORBIDDEN || response.code == HTTP_UNAVAILABLE) {
|
if (response.code == HTTP_FORBIDDEN || response.code == HTTP_UNAVAILABLE) {
|
||||||
if (response.header(HEADER_SERVER)?.startsWith(SERVER_CLOUDFLARE) == true) {
|
if (response.header(HEADER_SERVER)?.startsWith(SERVER_CLOUDFLARE) == true) {
|
||||||
response.closeQuietly()
|
response.closeQuietly()
|
||||||
throw CloudFlareProtectedException(response.request.url.toString())
|
throw CloudFlareProtectedException(
|
||||||
|
url = response.request.url.toString(),
|
||||||
|
headers = request.headers,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ object CommonHeaders {
|
|||||||
const val REFERER = "Referer"
|
const val REFERER = "Referer"
|
||||||
const val USER_AGENT = "User-Agent"
|
const val USER_AGENT = "User-Agent"
|
||||||
const val ACCEPT = "Accept"
|
const val ACCEPT = "Accept"
|
||||||
|
const val CONTENT_TYPE = "Content-Type"
|
||||||
const val CONTENT_DISPOSITION = "Content-Disposition"
|
const val CONTENT_DISPOSITION = "Content-Disposition"
|
||||||
const val COOKIE = "Cookie"
|
const val COOKIE = "Cookie"
|
||||||
const val CONTENT_ENCODING = "Content-Encoding"
|
const val CONTENT_ENCODING = "Content-Encoding"
|
||||||
|
const val ACCEPT_ENCODING = "Accept-Encoding"
|
||||||
const val AUTHORIZATION = "Authorization"
|
const val AUTHORIZATION = "Authorization"
|
||||||
|
|
||||||
val CACHE_CONTROL_DISABLED: CacheControl
|
val CACHE_CONTROL_DISABLED: CacheControl
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import android.util.Log
|
||||||
|
import dagger.Lazy
|
||||||
|
import okhttp3.Headers
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.util.mergeWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import java.util.Locale
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class CommonHeadersInterceptor @Inject constructor(
|
||||||
|
private val mangaRepositoryFactoryLazy: Lazy<MangaRepository.Factory>,
|
||||||
|
) : Interceptor {
|
||||||
|
|
||||||
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
|
val request = chain.request()
|
||||||
|
val source = request.tag(MangaSource::class.java)
|
||||||
|
val repository = if (source != null) {
|
||||||
|
mangaRepositoryFactoryLazy.get().create(source) as? RemoteMangaRepository
|
||||||
|
} else {
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
Log.w("Http", "Request without source tag: ${request.url}")
|
||||||
|
}
|
||||||
|
null
|
||||||
|
}
|
||||||
|
val headersBuilder = request.headers.newBuilder()
|
||||||
|
repository?.headers?.let {
|
||||||
|
headersBuilder.mergeWith(it, replaceExisting = false)
|
||||||
|
}
|
||||||
|
if (headersBuilder[CommonHeaders.USER_AGENT] == null) {
|
||||||
|
headersBuilder[CommonHeaders.USER_AGENT] = userAgentFallback
|
||||||
|
}
|
||||||
|
if (headersBuilder[CommonHeaders.REFERER] == null && repository != null) {
|
||||||
|
headersBuilder.trySet(CommonHeaders.REFERER, "https://${repository.domain}/")
|
||||||
|
}
|
||||||
|
val newRequest = request.newBuilder().headers(headersBuilder.build()).build()
|
||||||
|
return repository?.intercept(ProxyChain(chain, newRequest)) ?: chain.proceed(newRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Headers.Builder.trySet(name: String, value: String) = try {
|
||||||
|
set(name, value)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ProxyChain(
|
||||||
|
private val delegate: Interceptor.Chain,
|
||||||
|
private val request: Request,
|
||||||
|
) : Interceptor.Chain by delegate {
|
||||||
|
|
||||||
|
override fun request(): Request = request
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
val userAgentFallback
|
||||||
|
get() = "Kotatsu/%s (Android %s; %s; %s %s; %s)".format(
|
||||||
|
BuildConfig.VERSION_NAME,
|
||||||
|
Build.VERSION.RELEASE,
|
||||||
|
Build.MODEL,
|
||||||
|
Build.BRAND,
|
||||||
|
Build.DEVICE,
|
||||||
|
Locale.getDefault().language,
|
||||||
|
)
|
||||||
|
|
||||||
|
val userAgentChrome
|
||||||
|
get() = (
|
||||||
|
"Mozilla/5.0 (Linux; Android %s; %s) AppleWebKit/537.36 (KHTML, like Gecko) " +
|
||||||
|
"Chrome/100.0.4896.127 Mobile Safari/537.36"
|
||||||
|
).format(
|
||||||
|
Build.VERSION.RELEASE,
|
||||||
|
Build.MODEL,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.network
|
|
||||||
|
|
||||||
import android.os.Build
|
|
||||||
import java.util.*
|
|
||||||
import okhttp3.Interceptor
|
|
||||||
import okhttp3.Response
|
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
|
||||||
|
|
||||||
class UserAgentInterceptor : Interceptor {
|
|
||||||
|
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
|
||||||
val request = chain.request()
|
|
||||||
return chain.proceed(
|
|
||||||
if (request.header(CommonHeaders.USER_AGENT) == null) {
|
|
||||||
request.newBuilder()
|
|
||||||
.addHeader(CommonHeaders.USER_AGENT, userAgent)
|
|
||||||
.build()
|
|
||||||
} else request
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
val userAgent
|
|
||||||
get() = "Kotatsu/%s (Android %s; %s; %s %s; %s)".format(
|
|
||||||
BuildConfig.VERSION_NAME,
|
|
||||||
Build.VERSION.RELEASE,
|
|
||||||
Build.MODEL,
|
|
||||||
Build.BRAND,
|
|
||||||
Build.DEVICE,
|
|
||||||
Locale.getDefault().language
|
|
||||||
)
|
|
||||||
|
|
||||||
val userAgentChrome
|
|
||||||
get() = (
|
|
||||||
"Mozilla/5.0 (Linux; Android %s; %s) AppleWebKit/537.36 (KHTML, like Gecko) " +
|
|
||||||
"Chrome/100.0.4896.127 Mobile Safari/537.36"
|
|
||||||
).format(
|
|
||||||
Build.VERSION.RELEASE,
|
|
||||||
Build.MODEL,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +1,17 @@
|
|||||||
package org.koitharu.kotatsu.core.network
|
package org.koitharu.kotatsu.core.network.cookies
|
||||||
|
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import javax.inject.Inject
|
import androidx.annotation.WorkerThread
|
||||||
import javax.inject.Singleton
|
import okhttp3.Cookie
|
||||||
|
import okhttp3.HttpUrl
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
import okhttp3.Cookie
|
|
||||||
import okhttp3.CookieJar
|
|
||||||
import okhttp3.HttpUrl
|
|
||||||
|
|
||||||
@Singleton
|
class AndroidCookieJar : MutableCookieJar {
|
||||||
class AndroidCookieJar @Inject constructor() : CookieJar {
|
|
||||||
|
|
||||||
private val cookieManager = CookieManager.getInstance()
|
private val cookieManager = CookieManager.getInstance()
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
override fun loadForRequest(url: HttpUrl): List<Cookie> {
|
override fun loadForRequest(url: HttpUrl): List<Cookie> {
|
||||||
val rawCookie = cookieManager.getCookie(url.toString()) ?: return emptyList()
|
val rawCookie = cookieManager.getCookie(url.toString()) ?: return emptyList()
|
||||||
return rawCookie.split(';').mapNotNull {
|
return rawCookie.split(';').mapNotNull {
|
||||||
@@ -21,6 +19,7 @@ class AndroidCookieJar @Inject constructor() : CookieJar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||||
if (cookies.isEmpty()) {
|
if (cookies.isEmpty()) {
|
||||||
return
|
return
|
||||||
@@ -31,7 +30,7 @@ class AndroidCookieJar @Inject constructor() : CookieJar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun clear() = suspendCoroutine<Boolean> { continuation ->
|
override suspend fun clear() = suspendCoroutine<Boolean> { continuation ->
|
||||||
cookieManager.removeAllCookies(continuation::resume)
|
cookieManager.removeAllCookies(continuation::resume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network.cookies
|
||||||
|
|
||||||
|
import android.util.Base64
|
||||||
|
import okhttp3.Cookie
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.ObjectInputStream
|
||||||
|
import java.io.ObjectOutputStream
|
||||||
|
|
||||||
|
|
||||||
|
class CookieWrapper(
|
||||||
|
val cookie: Cookie,
|
||||||
|
) {
|
||||||
|
|
||||||
|
constructor(encodedString: String) : this(
|
||||||
|
ObjectInputStream(ByteArrayInputStream(Base64.decode(encodedString, Base64.NO_WRAP))).use {
|
||||||
|
val name = it.readUTF()
|
||||||
|
val value = it.readUTF()
|
||||||
|
val expiresAt = it.readLong()
|
||||||
|
val domain = it.readUTF()
|
||||||
|
val path = it.readUTF()
|
||||||
|
val secure = it.readBoolean()
|
||||||
|
val httpOnly = it.readBoolean()
|
||||||
|
val persistent = it.readBoolean()
|
||||||
|
val hostOnly = it.readBoolean()
|
||||||
|
Cookie.Builder().also { c ->
|
||||||
|
c.name(name)
|
||||||
|
c.value(value)
|
||||||
|
if (persistent) {
|
||||||
|
c.expiresAt(expiresAt)
|
||||||
|
}
|
||||||
|
if (hostOnly) {
|
||||||
|
c.hostOnlyDomain(domain)
|
||||||
|
} else {
|
||||||
|
c.domain(domain)
|
||||||
|
}
|
||||||
|
c.path(path)
|
||||||
|
if (secure) {
|
||||||
|
c.secure()
|
||||||
|
}
|
||||||
|
if (httpOnly) {
|
||||||
|
c.httpOnly()
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
fun encode(): String {
|
||||||
|
val output = ByteArrayOutputStream()
|
||||||
|
ObjectOutputStream(output).use {
|
||||||
|
it.writeUTF(cookie.name)
|
||||||
|
it.writeUTF(cookie.value)
|
||||||
|
it.writeLong(cookie.expiresAt)
|
||||||
|
it.writeUTF(cookie.domain)
|
||||||
|
it.writeUTF(cookie.path)
|
||||||
|
it.writeBoolean(cookie.secure)
|
||||||
|
it.writeBoolean(cookie.httpOnly)
|
||||||
|
it.writeBoolean(cookie.persistent)
|
||||||
|
it.writeBoolean(cookie.hostOnly)
|
||||||
|
}
|
||||||
|
return Base64.encodeToString(output.toByteArray(), Base64.NO_WRAP)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isExpired() = cookie.expiresAt < System.currentTimeMillis()
|
||||||
|
|
||||||
|
fun key(): String {
|
||||||
|
return (if (cookie.secure) "https" else "http") + "://" + cookie.domain + cookie.path + "|" + cookie.name
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as CookieWrapper
|
||||||
|
|
||||||
|
if (cookie != other.cookie) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return cookie.hashCode()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network.cookies
|
||||||
|
|
||||||
|
import androidx.annotation.WorkerThread
|
||||||
|
import okhttp3.Cookie
|
||||||
|
import okhttp3.CookieJar
|
||||||
|
import okhttp3.HttpUrl
|
||||||
|
|
||||||
|
interface MutableCookieJar : CookieJar {
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
override fun loadForRequest(url: HttpUrl): List<Cookie>
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>)
|
||||||
|
|
||||||
|
suspend fun clear(): Boolean
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network.cookies
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.annotation.WorkerThread
|
||||||
|
import androidx.collection.ArrayMap
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import okhttp3.Cookie
|
||||||
|
import okhttp3.HttpUrl
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
|
private const val PREFS_NAME = "cookies"
|
||||||
|
|
||||||
|
class PreferencesCookieJar(
|
||||||
|
context: Context,
|
||||||
|
) : MutableCookieJar {
|
||||||
|
|
||||||
|
private val cache = ArrayMap<String, CookieWrapper>()
|
||||||
|
private val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
|
private var isLoaded = false
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
override fun loadForRequest(url: HttpUrl): List<Cookie> {
|
||||||
|
loadPersistent()
|
||||||
|
val expired = HashSet<String>()
|
||||||
|
val result = ArrayList<Cookie>()
|
||||||
|
for ((key, cookie) in cache) {
|
||||||
|
if (cookie.isExpired()) {
|
||||||
|
expired += key
|
||||||
|
} else if (cookie.cookie.matches(url)) {
|
||||||
|
result += cookie.cookie
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (expired.isNotEmpty()) {
|
||||||
|
cache.removeAll(expired)
|
||||||
|
removePersistent(expired)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||||
|
val wrapped = cookies.map { CookieWrapper(it) }
|
||||||
|
prefs.edit(commit = true) {
|
||||||
|
for (cookie in wrapped) {
|
||||||
|
val key = cookie.key()
|
||||||
|
cache[key] = cookie
|
||||||
|
if (cookie.cookie.persistent) {
|
||||||
|
putString(key, cookie.encode())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun clear(): Boolean {
|
||||||
|
cache.clear()
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
prefs.edit(commit = true) { clear() }
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
private fun loadPersistent() {
|
||||||
|
if (!isLoaded) {
|
||||||
|
val map = prefs.all
|
||||||
|
cache.ensureCapacity(map.size)
|
||||||
|
for ((k, v) in map) {
|
||||||
|
val cookie = try {
|
||||||
|
CookieWrapper(v as String)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cache[k] = cookie
|
||||||
|
}
|
||||||
|
isLoaded = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun removePersistent(keys: Collection<String>) {
|
||||||
|
prefs.edit(commit = true) {
|
||||||
|
for (key in keys) {
|
||||||
|
remove(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.os
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.net.ConnectivityManager.NetworkCallback
|
|
||||||
import android.net.Network
|
|
||||||
import android.net.NetworkRequest
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import kotlinx.coroutines.channels.ProducerScope
|
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
|
||||||
import kotlinx.coroutines.channels.trySendBlocking
|
|
||||||
import kotlinx.coroutines.flow.FlowCollector
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.flow.callbackFlow
|
|
||||||
import org.koitharu.kotatsu.utils.ext.connectivityManager
|
|
||||||
import org.koitharu.kotatsu.utils.ext.isNetworkAvailable
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
class NetworkStateObserver @Inject constructor(
|
|
||||||
@ApplicationContext context: Context,
|
|
||||||
) : StateFlow<Boolean> {
|
|
||||||
|
|
||||||
private val connectivityManager = context.connectivityManager
|
|
||||||
|
|
||||||
override val replayCache: List<Boolean>
|
|
||||||
get() = listOf(value)
|
|
||||||
|
|
||||||
override var value: Boolean = connectivityManager.isNetworkAvailable
|
|
||||||
|
|
||||||
override suspend fun collect(collector: FlowCollector<Boolean>): Nothing {
|
|
||||||
collector.emit(value)
|
|
||||||
while (true) {
|
|
||||||
observeImpl().collect(collector)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun observeImpl() = callbackFlow<Boolean> {
|
|
||||||
val request = NetworkRequest.Builder().build()
|
|
||||||
val callback = FlowNetworkCallback(this)
|
|
||||||
connectivityManager.registerNetworkCallback(request, callback)
|
|
||||||
awaitClose {
|
|
||||||
connectivityManager.unregisterNetworkCallback(callback)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inner class FlowNetworkCallback(
|
|
||||||
private val producerScope: ProducerScope<Boolean>,
|
|
||||||
) : NetworkCallback() {
|
|
||||||
override fun onAvailable(network: Network) = update()
|
|
||||||
|
|
||||||
override fun onLost(network: Network) = update()
|
|
||||||
|
|
||||||
override fun onUnavailable() = update()
|
|
||||||
|
|
||||||
private fun update() {
|
|
||||||
val newValue = connectivityManager.isNetworkAvailable
|
|
||||||
if (value != newValue) {
|
|
||||||
value = newValue
|
|
||||||
producerScope.trySendBlocking(newValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -118,6 +118,7 @@ class ShortcutsUpdater @Inject constructor(
|
|||||||
ImageRequest.Builder(context)
|
ImageRequest.Builder(context)
|
||||||
.data(manga.coverUrl)
|
.data(manga.coverUrl)
|
||||||
.size(iconSize.width, iconSize.height)
|
.size(iconSize.width, iconSize.height)
|
||||||
|
.tag(manga.source)
|
||||||
.precision(Precision.EXACT)
|
.precision(Precision.EXACT)
|
||||||
.scale(Scale.FILL)
|
.scale(Scale.FILL)
|
||||||
.build(),
|
.build(),
|
||||||
|
|||||||
@@ -6,25 +6,25 @@ import android.util.Base64
|
|||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import androidx.core.os.LocaleListCompat
|
import androidx.core.os.LocaleListCompat
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.parsers.config.MangaSourceConfig
|
import org.koitharu.kotatsu.parsers.config.MangaSourceConfig
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.utils.ext.toList
|
import org.koitharu.kotatsu.utils.ext.toList
|
||||||
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class MangaLoaderContextImpl @Inject constructor(
|
class MangaLoaderContextImpl @Inject constructor(
|
||||||
override val httpClient: OkHttpClient,
|
override val httpClient: OkHttpClient,
|
||||||
override val cookieJar: AndroidCookieJar,
|
override val cookieJar: MutableCookieJar,
|
||||||
@ApplicationContext private val androidContext: Context,
|
@ApplicationContext private val androidContext: Context,
|
||||||
) : MangaLoaderContext() {
|
) : MangaLoaderContext() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
import java.util.*
|
import java.util.EnumMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
|
||||||
|
|
||||||
interface MangaRepository {
|
interface MangaRepository {
|
||||||
|
|
||||||
@@ -31,6 +37,7 @@ interface MangaRepository {
|
|||||||
class Factory @Inject constructor(
|
class Factory @Inject constructor(
|
||||||
private val localMangaRepository: LocalMangaRepository,
|
private val localMangaRepository: LocalMangaRepository,
|
||||||
private val loaderContext: MangaLoaderContext,
|
private val loaderContext: MangaLoaderContext,
|
||||||
|
private val contentCache: ContentCache,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val cache = EnumMap<MangaSource, WeakReference<RemoteMangaRepository>>(MangaSource::class.java)
|
private val cache = EnumMap<MangaSource, WeakReference<RemoteMangaRepository>>(MangaSource::class.java)
|
||||||
@@ -42,7 +49,7 @@ interface MangaRepository {
|
|||||||
cache[source]?.get()?.let { return it }
|
cache[source]?.get()?.let { return it }
|
||||||
return synchronized(cache) {
|
return synchronized(cache) {
|
||||||
cache[source]?.get()?.let { return it }
|
cache[source]?.get()?.let { return it }
|
||||||
val repository = RemoteMangaRepository(MangaParser(source, loaderContext))
|
val repository = RemoteMangaRepository(MangaParser(source, loaderContext), contentCache)
|
||||||
cache[source] = WeakReference(repository)
|
cache[source] = WeakReference(repository)
|
||||||
repository
|
repository
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,35 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.MainCoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
|
import okhttp3.Headers
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Response
|
||||||
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.core.cache.SafeDeferred
|
||||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||||
import org.koitharu.kotatsu.parsers.MangaParser
|
import org.koitharu.kotatsu.parsers.MangaParser
|
||||||
import org.koitharu.kotatsu.parsers.MangaParserAuthProvider
|
import org.koitharu.kotatsu.parsers.MangaParserAuthProvider
|
||||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
import org.koitharu.kotatsu.parsers.model.Favicons
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.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.domain
|
||||||
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
class RemoteMangaRepository(private val parser: MangaParser) : MangaRepository {
|
class RemoteMangaRepository(
|
||||||
|
private val parser: MangaParser,
|
||||||
|
private val cache: ContentCache,
|
||||||
|
) : MangaRepository, Interceptor {
|
||||||
|
|
||||||
override val source: MangaSource
|
override val source: MangaSource
|
||||||
get() = parser.source
|
get() = parser.source
|
||||||
@@ -20,6 +43,20 @@ class RemoteMangaRepository(private val parser: MangaParser) : MangaRepository {
|
|||||||
getConfig().defaultSortOrder = value
|
getConfig().defaultSortOrder = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val domain: String
|
||||||
|
get() = parser.domain
|
||||||
|
|
||||||
|
val headers: Headers?
|
||||||
|
get() = parser.headers
|
||||||
|
|
||||||
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
|
return if (parser is Interceptor) {
|
||||||
|
parser.intercept(chain)
|
||||||
|
} else {
|
||||||
|
chain.proceed(chain.request())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getList(offset: Int, query: String): List<Manga> {
|
override suspend fun getList(offset: Int, query: String): List<Manga> {
|
||||||
return parser.getList(offset, query)
|
return parser.getList(offset, query)
|
||||||
}
|
}
|
||||||
@@ -28,9 +65,23 @@ class RemoteMangaRepository(private val parser: MangaParser) : MangaRepository {
|
|||||||
return parser.getList(offset, tags, sortOrder)
|
return parser.getList(offset, tags, sortOrder)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga = parser.getDetails(manga)
|
override suspend fun getDetails(manga: Manga): Manga {
|
||||||
|
cache.getDetails(source, manga.url)?.let { return it }
|
||||||
|
val details = asyncSafe {
|
||||||
|
parser.getDetails(manga)
|
||||||
|
}
|
||||||
|
cache.putDetails(source, manga.url, details)
|
||||||
|
return details.await()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> = parser.getPages(chapter)
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
||||||
|
cache.getPages(source, chapter.url)?.let { return it }
|
||||||
|
val pages = asyncSafe {
|
||||||
|
parser.getPages(chapter)
|
||||||
|
}
|
||||||
|
cache.putPages(source, chapter.url, pages)
|
||||||
|
return pages.await()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getPageUrl(page: MangaPage): String = parser.getPageUrl(page)
|
override suspend fun getPageUrl(page: MangaPage): String = parser.getPageUrl(page)
|
||||||
|
|
||||||
@@ -45,4 +96,16 @@ class RemoteMangaRepository(private val parser: MangaParser) : MangaRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getConfig() = parser.config as SourceSettings
|
private fun getConfig() = parser.config as SourceSettings
|
||||||
}
|
|
||||||
|
private suspend fun <T> asyncSafe(block: suspend CoroutineScope.() -> T): SafeDeferred<T> {
|
||||||
|
var dispatcher = currentCoroutineContext()[CoroutineDispatcher.Key]
|
||||||
|
if (dispatcher == null || dispatcher is MainCoroutineDispatcher) {
|
||||||
|
dispatcher = Dispatchers.Default
|
||||||
|
}
|
||||||
|
return SafeDeferred(
|
||||||
|
processLifecycleScope.async(dispatcher) {
|
||||||
|
runCatchingCancellable { block() }
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,19 +14,18 @@ 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
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import okhttp3.internal.closeQuietly
|
import okhttp3.internal.closeQuietly
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.core.network.CommonHeaders
|
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
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
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ class FaviconFetcher(
|
|||||||
options.size.height.pxOrElse { FALLBACK_SIZE },
|
options.size.height.pxOrElse { FALLBACK_SIZE },
|
||||||
)
|
)
|
||||||
val icon = checkNotNull(favicons.find(sizePx)) { "No favicons found" }
|
val icon = checkNotNull(favicons.find(sizePx)) { "No favicons found" }
|
||||||
val response = loadIcon(icon.url, favicons.referer)
|
val response = loadIcon(icon.url, mangaSource)
|
||||||
val responseBody = response.requireBody()
|
val responseBody = response.requireBody()
|
||||||
val source = writeToDiskCache(responseBody)?.toImageSource() ?: responseBody.toImageSource()
|
val source = writeToDiskCache(responseBody)?.toImageSource() ?: responseBody.toImageSource()
|
||||||
return SourceResult(
|
return SourceResult(
|
||||||
@@ -63,11 +62,11 @@ class FaviconFetcher(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadIcon(url: String, referer: String): Response {
|
private suspend fun loadIcon(url: String, source: MangaSource): Response {
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.get()
|
.get()
|
||||||
.header(CommonHeaders.REFERER, referer)
|
.tag(MangaSource::class.java, source)
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
options.tags.asMap().forEach { request.tag(it.key as Class<Any>, it.value) }
|
options.tags.asMap().forEach { request.tag(it.key as Class<Any>, it.value) }
|
||||||
val response = okHttpClient.newCall(request.build()).await()
|
val response = okHttpClient.newCall(request.build()).await()
|
||||||
@@ -150,7 +149,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
|
|
||||||
}
|
|
||||||
@@ -2,27 +2,27 @@ package org.koitharu.kotatsu.core.prefs
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.net.ConnectivityManager
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.collection.arraySetOf
|
import androidx.collection.arraySetOf
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
|
import androidx.core.os.LocaleListCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.google.android.material.color.DynamicColors
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
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.connectivityManager
|
||||||
|
import org.koitharu.kotatsu.utils.ext.filterToSet
|
||||||
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.io.File
|
||||||
import java.text.DateFormat
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.EnumSet
|
import java.util.EnumSet
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@@ -33,6 +33,7 @@ import javax.inject.Singleton
|
|||||||
class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||||
|
|
||||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
private val connectivityManager = context.connectivityManager
|
||||||
|
|
||||||
private val remoteSources = EnumSet.allOf(MangaSource::class.java).apply {
|
private val remoteSources = EnumSet.allOf(MangaSource::class.java).apply {
|
||||||
remove(MangaSource.LOCAL)
|
remove(MangaSource.LOCAL)
|
||||||
@@ -44,19 +45,31 @@ 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
|
||||||
|
|
||||||
val isDynamicTheme: Boolean
|
val colorScheme: ColorScheme
|
||||||
get() = DynamicColors.isDynamicColorAvailable() && prefs.getBoolean(KEY_DYNAMIC_THEME, false)
|
get() = prefs.getEnumValue(KEY_COLOR_THEME, ColorScheme.default)
|
||||||
|
|
||||||
val isAmoledTheme: Boolean
|
val isAmoledTheme: Boolean
|
||||||
get() = prefs.getBoolean(KEY_THEME_AMOLED, false)
|
get() = prefs.getBoolean(KEY_THEME_AMOLED, false)
|
||||||
@@ -65,6 +78,17 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
get() = prefs.getInt(KEY_GRID_SIZE, 100)
|
get() = prefs.getInt(KEY_GRID_SIZE, 100)
|
||||||
set(value) = prefs.edit { putInt(KEY_GRID_SIZE, value) }
|
set(value) = prefs.edit { putInt(KEY_GRID_SIZE, value) }
|
||||||
|
|
||||||
|
var appLocales: LocaleListCompat
|
||||||
|
get() {
|
||||||
|
val raw = prefs.getString(KEY_APP_LOCALE, null)
|
||||||
|
return LocaleListCompat.forLanguageTags(raw)
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
prefs.edit {
|
||||||
|
putString(KEY_APP_LOCALE, value.toLanguageTags())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val readerPageSwitch: Set<String>
|
val readerPageSwitch: Set<String>
|
||||||
get() = prefs.getStringSet(KEY_READER_SWITCHERS, null) ?: setOf(PAGE_SWITCH_TAPS)
|
get() = prefs.getStringSet(KEY_READER_SWITCHERS, null) ?: setOf(PAGE_SWITCH_TAPS)
|
||||||
|
|
||||||
@@ -133,6 +157,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
get() = prefs.getString(KEY_APP_PASSWORD, null)
|
get() = prefs.getString(KEY_APP_PASSWORD, null)
|
||||||
set(value) = prefs.edit { if (value != null) putString(KEY_APP_PASSWORD, value) else remove(KEY_APP_PASSWORD) }
|
set(value) = prefs.edit { if (value != null) putString(KEY_APP_PASSWORD, value) else remove(KEY_APP_PASSWORD) }
|
||||||
|
|
||||||
|
val isLoggingEnabled: Boolean
|
||||||
|
get() = prefs.getBoolean(KEY_LOGGING_ENABLED, false)
|
||||||
|
|
||||||
var isBiometricProtectionEnabled: Boolean
|
var isBiometricProtectionEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_PROTECT_APP_BIOMETRIC, true)
|
get() = prefs.getBoolean(KEY_PROTECT_APP_BIOMETRIC, true)
|
||||||
set(value) = prefs.edit { putBoolean(KEY_PROTECT_APP_BIOMETRIC, value) }
|
set(value) = prefs.edit { putBoolean(KEY_PROTECT_APP_BIOMETRIC, value) }
|
||||||
@@ -143,6 +170,14 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val isDynamicShortcutsEnabled: Boolean
|
val isDynamicShortcutsEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_SHORTCUTS, true)
|
get() = prefs.getBoolean(KEY_SHORTCUTS, true)
|
||||||
|
|
||||||
|
val isUnstableUpdatesAllowed: Boolean
|
||||||
|
get() = prefs.getBoolean(KEY_UPDATES_UNSTABLE, false)
|
||||||
|
|
||||||
|
fun isContentPrefetchEnabled(): Boolean {
|
||||||
|
val policy = NetworkPolicy.from(prefs.getString(KEY_PREFETCH_CONTENT, null), NetworkPolicy.NEVER)
|
||||||
|
return policy.isNetworkAllowed(connectivityManager)
|
||||||
|
}
|
||||||
|
|
||||||
var sourcesOrder: List<String>
|
var sourcesOrder: List<String>
|
||||||
get() = prefs.getString(KEY_SOURCES_ORDER, null)
|
get() = prefs.getString(KEY_SOURCES_ORDER, null)
|
||||||
?.split('|')
|
?.split('|')
|
||||||
@@ -152,7 +187,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var hiddenSources: Set<String>
|
var hiddenSources: Set<String>
|
||||||
get() = prefs.getStringSet(KEY_SOURCES_HIDDEN, null) ?: emptySet()
|
get() = prefs.getStringSet(KEY_SOURCES_HIDDEN, null)?.filterToSet { name ->
|
||||||
|
remoteSources.any { it.name == name }
|
||||||
|
}.orEmpty()
|
||||||
set(value) = prefs.edit { putStringSet(KEY_SOURCES_HIDDEN, value) }
|
set(value) = prefs.edit { putStringSet(KEY_SOURCES_HIDDEN, value) }
|
||||||
|
|
||||||
val isSourcesSelected: Boolean
|
val isSourcesSelected: Boolean
|
||||||
@@ -172,6 +209,10 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
sourcesOrder = (sourcesOrder + sources.map { it.name }).distinct()
|
sourcesOrder = (sourcesOrder + sources.map { it.name }).distinct()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isSourcesGridMode: Boolean
|
||||||
|
get() = prefs.getBoolean(KEY_SOURCES_GRID, false)
|
||||||
|
set(value) = prefs.edit { putBoolean(KEY_SOURCES_GRID, value) }
|
||||||
|
|
||||||
val isPagesNumbersEnabled: Boolean
|
val isPagesNumbersEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_PAGES_NUMBERS, false)
|
get() = prefs.getBoolean(KEY_PAGES_NUMBERS, false)
|
||||||
|
|
||||||
@@ -221,20 +262,11 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val isWebtoonZoomEnable: Boolean
|
val isWebtoonZoomEnable: Boolean
|
||||||
get() = prefs.getBoolean(KEY_WEBTOON_ZOOM, true)
|
get() = prefs.getBoolean(KEY_WEBTOON_ZOOM, true)
|
||||||
|
|
||||||
fun isPagesPreloadAllowed(cm: ConnectivityManager): Boolean {
|
fun isPagesPreloadEnabled(): Boolean {
|
||||||
return when (prefs.getString(KEY_PAGES_PRELOAD, null)?.toIntOrNull()) {
|
val policy = NetworkPolicy.from(prefs.getString(KEY_PAGES_PRELOAD, null), NetworkPolicy.NON_METERED)
|
||||||
NETWORK_ALWAYS -> true
|
return policy.isNetworkAllowed(connectivityManager)
|
||||||
NETWORK_NEVER -> false
|
|
||||||
else -> cm.isActiveNetworkMetered
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDateFormat(format: String = prefs.getString(KEY_DATE_FORMAT, "").orEmpty()): DateFormat =
|
|
||||||
when (format) {
|
|
||||||
"" -> DateFormat.getDateInstance(DateFormat.SHORT)
|
|
||||||
else -> SimpleDateFormat(format, Locale.getDefault())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getSuggestionsTagsBlacklistRegex(): Regex? {
|
fun getSuggestionsTagsBlacklistRegex(): Regex? {
|
||||||
val string = prefs.getString(KEY_SUGGESTIONS_EXCLUDE_TAGS, null)?.trimEnd(' ', ',')
|
val string = prefs.getString(KEY_SUGGESTIONS_EXCLUDE_TAGS, null)?.trimEnd(' ', ',')
|
||||||
if (string.isNullOrEmpty()) {
|
if (string.isNullOrEmpty()) {
|
||||||
@@ -280,11 +312,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val TRACK_FAVOURITES = "favourites"
|
const val TRACK_FAVOURITES = "favourites"
|
||||||
|
|
||||||
const val KEY_LIST_MODE = "list_mode_2"
|
const val KEY_LIST_MODE = "list_mode_2"
|
||||||
const val KEY_APP_SECTION = "app_section_2"
|
|
||||||
const val KEY_THEME = "theme"
|
const val KEY_THEME = "theme"
|
||||||
const val KEY_DYNAMIC_THEME = "dynamic_theme"
|
const val KEY_COLOR_THEME = "color_theme"
|
||||||
const val KEY_THEME_AMOLED = "amoled_theme"
|
const val KEY_THEME_AMOLED = "amoled_theme"
|
||||||
const val KEY_DATE_FORMAT = "date_format"
|
|
||||||
const val KEY_SOURCES_ORDER = "sources_order_2"
|
const val KEY_SOURCES_ORDER = "sources_order_2"
|
||||||
const val KEY_SOURCES_HIDDEN = "sources_hidden"
|
const val KEY_SOURCES_HIDDEN = "sources_hidden"
|
||||||
const val KEY_TRAFFIC_WARNING = "traffic_warning"
|
const val KEY_TRAFFIC_WARNING = "traffic_warning"
|
||||||
@@ -328,6 +358,8 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val KEY_SUGGESTIONS_EXCLUDE_NSFW = "suggestions_exclude_nsfw"
|
const val KEY_SUGGESTIONS_EXCLUDE_NSFW = "suggestions_exclude_nsfw"
|
||||||
const val KEY_SUGGESTIONS_EXCLUDE_TAGS = "suggestions_exclude_tags"
|
const val KEY_SUGGESTIONS_EXCLUDE_TAGS = "suggestions_exclude_tags"
|
||||||
const val KEY_SHIKIMORI = "shikimori"
|
const val KEY_SHIKIMORI = "shikimori"
|
||||||
|
const val KEY_ANILIST = "anilist"
|
||||||
|
const val KEY_MAL = "mal"
|
||||||
const val KEY_DOWNLOADS_PARALLELISM = "downloads_parallelism"
|
const val KEY_DOWNLOADS_PARALLELISM = "downloads_parallelism"
|
||||||
const val KEY_DOWNLOADS_SLOWDOWN = "downloads_slowdown"
|
const val KEY_DOWNLOADS_SLOWDOWN = "downloads_slowdown"
|
||||||
const val KEY_ALL_FAVOURITES_VISIBLE = "all_favourites_visible"
|
const val KEY_ALL_FAVOURITES_VISIBLE = "all_favourites_visible"
|
||||||
@@ -341,13 +373,16 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
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_WEBTOON_ZOOM = "webtoon_zoom"
|
||||||
|
const val KEY_SHELF_SECTIONS = "shelf_sections_2"
|
||||||
|
const val KEY_PREFETCH_CONTENT = "prefetch_content"
|
||||||
|
const val KEY_APP_LOCALE = "app_locale"
|
||||||
|
const val KEY_LOGGING_ENABLED = "logging"
|
||||||
|
const val KEY_LOGS_SHARE = "logs_share"
|
||||||
|
const val KEY_SOURCES_GRID = "sources_grid"
|
||||||
|
const val KEY_UPDATES_UNSTABLE = "updates_unstable"
|
||||||
|
|
||||||
// About
|
// About
|
||||||
const val KEY_APP_UPDATE = "app_update"
|
const val KEY_APP_UPDATE = "app_update"
|
||||||
const val KEY_APP_TRANSLATION = "about_app_translation"
|
const val KEY_APP_TRANSLATION = "about_app_translation"
|
||||||
|
|
||||||
private const val NETWORK_NEVER = 0
|
|
||||||
private const val NETWORK_ALWAYS = 1
|
|
||||||
private const val NETWORK_NON_METERED = 2
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package org.koitharu.kotatsu.core.prefs
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
import androidx.lifecycle.liveData
|
import androidx.lifecycle.liveData
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.flow.transform
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
fun <T> AppSettings.observeAsFlow(key: String, valueProducer: AppSettings.() -> T) = flow {
|
fun <T> AppSettings.observeAsFlow(key: String, valueProducer: AppSettings.() -> T) = flow {
|
||||||
var lastValue: T = valueProducer()
|
var lastValue: T = valueProducer()
|
||||||
@@ -33,3 +38,13 @@ fun <T> AppSettings.observeAsLiveData(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> AppSettings.observeAsStateFlow(
|
||||||
|
key: String,
|
||||||
|
scope: CoroutineScope,
|
||||||
|
valueProducer: AppSettings.() -> T,
|
||||||
|
): StateFlow<T> = observe().transform {
|
||||||
|
if (it == key) {
|
||||||
|
emit(valueProducer())
|
||||||
|
}
|
||||||
|
}.stateIn(scope, SharingStarted.Eagerly, valueProducer())
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.annotation.StyleRes
|
||||||
|
import com.google.android.material.color.DynamicColors
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
enum class ColorScheme(
|
||||||
|
@StyleRes val styleResId: Int,
|
||||||
|
@StringRes val titleResId: Int,
|
||||||
|
) {
|
||||||
|
|
||||||
|
DEFAULT(R.style.Theme_Kotatsu, R.string.system_default),
|
||||||
|
MONET(R.style.Theme_Kotatsu_Monet, R.string.theme_name_dynamic),
|
||||||
|
MIKU(R.style.Theme_Kotatsu_Miku, R.string.theme_name_miku),
|
||||||
|
RENA(R.style.Theme_Kotatsu_Asuka, R.string.theme_name_asuka),
|
||||||
|
FROG(R.style.Theme_Kotatsu_Mion, R.string.theme_name_mion),
|
||||||
|
BLUEBERRY(R.style.Theme_Kotatsu_Rikka, R.string.theme_name_rikka),
|
||||||
|
NAME2(R.style.Theme_Kotatsu_Sakura, R.string.theme_name_sakura),
|
||||||
|
MAMIMI(R.style.Theme_Kotatsu_Mamimi, R.string.theme_name_mamimi),
|
||||||
|
KANADE(R.style.Theme_Kotatsu_Kanade, R.string.theme_name_kanade)
|
||||||
|
;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
val default: ColorScheme
|
||||||
|
get() = if (DynamicColors.isDynamicColorAvailable()) {
|
||||||
|
MONET
|
||||||
|
} else {
|
||||||
|
DEFAULT
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAvailableList(): List<ColorScheme> {
|
||||||
|
val list = enumValues<ColorScheme>().toMutableList()
|
||||||
|
if (!DynamicColors.isDynamicColorAvailable()) {
|
||||||
|
list.remove(MONET)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
fun safeValueOf(name: String): ColorScheme? {
|
||||||
|
return enumValues<ColorScheme>().find { it.name == name }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
|
||||||
|
enum class NetworkPolicy(
|
||||||
|
private val key: Int,
|
||||||
|
) {
|
||||||
|
|
||||||
|
NEVER(0),
|
||||||
|
ALWAYS(1),
|
||||||
|
NON_METERED(2);
|
||||||
|
|
||||||
|
fun isNetworkAllowed(cm: ConnectivityManager) = when (this) {
|
||||||
|
NEVER -> false
|
||||||
|
ALWAYS -> true
|
||||||
|
NON_METERED -> !cm.isActiveNetworkMetered
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun from(key: String?, default: NetworkPolicy): NetworkPolicy {
|
||||||
|
val intKey = key?.toIntOrNull() ?: return default
|
||||||
|
return enumValues<NetworkPolicy>().find { it.key == intKey } ?: default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,9 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
override fun <T> get(key: ConfigKey<T>): T {
|
override fun <T> get(key: ConfigKey<T>): T {
|
||||||
return when (key) {
|
return when (key) {
|
||||||
|
is ConfigKey.UserAgent -> prefs.getString(key.key, key.defaultValue).ifNullOrEmpty { key.defaultValue }
|
||||||
is ConfigKey.Domain -> prefs.getString(key.key, key.defaultValue).ifNullOrEmpty { key.defaultValue }
|
is ConfigKey.Domain -> prefs.getString(key.key, key.defaultValue).ifNullOrEmpty { key.defaultValue }
|
||||||
|
is ConfigKey.ShowSuspiciousContent -> prefs.getBoolean(key.key, key.defaultValue)
|
||||||
} as T
|
} as T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.utils.ext.daysDiff
|
import org.koitharu.kotatsu.utils.ext.daysDiff
|
||||||
import org.koitharu.kotatsu.utils.ext.format
|
import org.koitharu.kotatsu.utils.ext.format
|
||||||
import java.util.*
|
import java.util.Date
|
||||||
|
|
||||||
sealed class DateTimeAgo : ListModel {
|
sealed class DateTimeAgo : ListModel {
|
||||||
|
|
||||||
@@ -17,6 +17,8 @@ sealed class DateTimeAgo : ListModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = "just_now"
|
override fun toString() = "just_now"
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean = other === JustNow
|
||||||
}
|
}
|
||||||
|
|
||||||
class MinutesAgo(val minutes: Int) : DateTimeAgo() {
|
class MinutesAgo(val minutes: Int) : DateTimeAgo() {
|
||||||
@@ -60,6 +62,8 @@ sealed class DateTimeAgo : ListModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = "today"
|
override fun toString() = "today"
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean = other === Today
|
||||||
}
|
}
|
||||||
|
|
||||||
object Yesterday : DateTimeAgo() {
|
object Yesterday : DateTimeAgo() {
|
||||||
@@ -68,6 +72,8 @@ sealed class DateTimeAgo : ListModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = "yesterday"
|
override fun toString() = "yesterday"
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean = other === Yesterday
|
||||||
}
|
}
|
||||||
|
|
||||||
class DaysAgo(val days: Int) : DateTimeAgo() {
|
class DaysAgo(val days: Int) : DateTimeAgo() {
|
||||||
@@ -119,5 +125,7 @@ sealed class DateTimeAgo : ListModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = "long_ago"
|
override fun toString() = "long_ago"
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean = other === LongAgo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,10 +52,13 @@ class ZipOutput(
|
|||||||
return if (entryNames.add(entry.name)) {
|
return if (entryNames.add(entry.name)) {
|
||||||
val zipEntry = ZipEntry(entry.name)
|
val zipEntry = ZipEntry(entry.name)
|
||||||
output.putNextEntry(zipEntry)
|
output.putNextEntry(zipEntry)
|
||||||
other.getInputStream(entry).use { input ->
|
try {
|
||||||
input.copyTo(output)
|
other.getInputStream(entry).use { input ->
|
||||||
|
input.copyTo(output)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
output.closeEntry()
|
||||||
}
|
}
|
||||||
output.closeEntry()
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
@@ -115,4 +118,4 @@ class ZipOutput(
|
|||||||
closeEntry()
|
closeEntry()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package org.koitharu.kotatsu.details.service
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import dagger.hilt.android.EntryPointAccessors
|
||||||
|
import org.koitharu.kotatsu.base.ui.CoroutineIntentService
|
||||||
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaChapters
|
||||||
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class MangaPrefetchService : CoroutineIntentService() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mangaRepositoryFactory: MangaRepository.Factory
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var cache: ContentCache
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var historyRepository: HistoryRepository
|
||||||
|
|
||||||
|
override suspend fun processIntent(startId: Int, intent: Intent) {
|
||||||
|
when (intent.action) {
|
||||||
|
ACTION_PREFETCH_DETAILS -> prefetchDetails(
|
||||||
|
manga = intent.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga ?: return,
|
||||||
|
)
|
||||||
|
|
||||||
|
ACTION_PREFETCH_PAGES -> prefetchPages(
|
||||||
|
chapter = intent.getParcelableExtraCompat<ParcelableMangaChapters>(EXTRA_CHAPTER)
|
||||||
|
?.chapters?.singleOrNull() ?: return,
|
||||||
|
)
|
||||||
|
|
||||||
|
ACTION_PREFETCH_LAST -> prefetchLast()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(startId: Int, error: Throwable) = Unit
|
||||||
|
|
||||||
|
private suspend fun prefetchDetails(manga: Manga) {
|
||||||
|
val source = mangaRepositoryFactory.create(manga.source)
|
||||||
|
runCatchingCancellable { source.getDetails(manga) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun prefetchPages(chapter: MangaChapter) {
|
||||||
|
val source = mangaRepositoryFactory.create(chapter.source)
|
||||||
|
runCatchingCancellable { source.getPages(chapter) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun prefetchLast() {
|
||||||
|
val last = historyRepository.getLastOrNull() ?: return
|
||||||
|
if (last.source == MangaSource.LOCAL) return
|
||||||
|
val repo = mangaRepositoryFactory.create(last.source)
|
||||||
|
val details = runCatchingCancellable { repo.getDetails(last) }.getOrNull() ?: return
|
||||||
|
val chapters = details.chapters
|
||||||
|
if (chapters.isNullOrEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val history = historyRepository.getOne(last)
|
||||||
|
val chapter = if (history == null) {
|
||||||
|
chapters.firstOrNull()
|
||||||
|
} else {
|
||||||
|
chapters.find { x -> x.id == history.chapterId } ?: chapters.firstOrNull()
|
||||||
|
} ?: return
|
||||||
|
runCatchingCancellable { repo.getPages(chapter) }
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private const val EXTRA_MANGA = "manga"
|
||||||
|
private const val EXTRA_CHAPTER = "manga"
|
||||||
|
private const val ACTION_PREFETCH_DETAILS = "details"
|
||||||
|
private const val ACTION_PREFETCH_PAGES = "pages"
|
||||||
|
private const val ACTION_PREFETCH_LAST = "last"
|
||||||
|
|
||||||
|
fun prefetchDetails(context: Context, manga: Manga) {
|
||||||
|
if (!isPrefetchAvailable(context, manga.source)) return
|
||||||
|
val intent = Intent(context, MangaPrefetchService::class.java)
|
||||||
|
intent.action = ACTION_PREFETCH_DETAILS
|
||||||
|
intent.putExtra(EXTRA_MANGA, ParcelableManga(manga, withChapters = false))
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun prefetchPages(context: Context, chapter: MangaChapter) {
|
||||||
|
if (!isPrefetchAvailable(context, chapter.source)) return
|
||||||
|
val intent = Intent(context, MangaPrefetchService::class.java)
|
||||||
|
intent.action = ACTION_PREFETCH_PAGES
|
||||||
|
intent.putExtra(EXTRA_CHAPTER, ParcelableMangaChapters(listOf(chapter)))
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun prefetchLast(context: Context) {
|
||||||
|
if (!isPrefetchAvailable(context, null)) return
|
||||||
|
val intent = Intent(context, MangaPrefetchService::class.java)
|
||||||
|
intent.action = ACTION_PREFETCH_LAST
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isPrefetchAvailable(context: Context, source: MangaSource?): Boolean {
|
||||||
|
if (source == MangaSource.LOCAL) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val entryPoint = EntryPointAccessors.fromApplication(context, PrefetchCompanionEntryPoint::class.java)
|
||||||
|
return entryPoint.contentCache.isCachingEnabled && entryPoint.settings.isContentPrefetchEnabled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.koitharu.kotatsu.details.service
|
||||||
|
|
||||||
|
import dagger.hilt.EntryPoint
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
|
||||||
|
@EntryPoint
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
interface PrefetchCompanionEntryPoint {
|
||||||
|
val settings: AppSettings
|
||||||
|
val contentCache: ContentCache
|
||||||
|
}
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
package org.koitharu.kotatsu.details.ui
|
package org.koitharu.kotatsu.details.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.*
|
import android.view.LayoutInflater
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
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.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import kotlin.math.roundToInt
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BaseFragment
|
import org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
import org.koitharu.kotatsu.base.ui.list.ListSelectionController
|
import org.koitharu.kotatsu.base.ui.list.ListSelectionController
|
||||||
@@ -24,8 +25,8 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
|||||||
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.RecyclerViewScrollCallback
|
import org.koitharu.kotatsu.utils.RecyclerViewScrollCallback
|
||||||
import org.koitharu.kotatsu.utils.ext.parents
|
|
||||||
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
class ChaptersFragment :
|
class ChaptersFragment :
|
||||||
BaseFragment<FragmentChaptersBinding>(),
|
BaseFragment<FragmentChaptersBinding>(),
|
||||||
@@ -95,13 +96,14 @@ class ChaptersFragment :
|
|||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.action_save -> {
|
R.id.action_save -> {
|
||||||
DownloadService.start(
|
DownloadService.start(
|
||||||
context ?: return false,
|
binding.recyclerViewChapters,
|
||||||
viewModel.getRemoteManga() ?: viewModel.manga.value ?: return false,
|
viewModel.getRemoteManga() ?: viewModel.manga.value ?: return false,
|
||||||
selectionController?.snapshot(),
|
selectionController?.snapshot(),
|
||||||
)
|
)
|
||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_delete -> {
|
R.id.action_delete -> {
|
||||||
val ids = selectionController?.peekCheckedIds()
|
val ids = selectionController?.peekCheckedIds()
|
||||||
val manga = viewModel.manga.value
|
val manga = viewModel.manga.value
|
||||||
@@ -120,6 +122,7 @@ class ChaptersFragment :
|
|||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_select_range -> {
|
R.id.action_select_range -> {
|
||||||
val items = chaptersAdapter?.items ?: return false
|
val items = chaptersAdapter?.items ?: return false
|
||||||
val ids = HashSet(controller.peekCheckedIds())
|
val ids = HashSet(controller.peekCheckedIds())
|
||||||
@@ -139,11 +142,20 @@ class ChaptersFragment :
|
|||||||
controller.addAll(ids)
|
controller.addAll(ids)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_select_all -> {
|
R.id.action_select_all -> {
|
||||||
val ids = chaptersAdapter?.items?.map { it.chapter.id } ?: return false
|
val ids = chaptersAdapter?.items?.map { it.chapter.id } ?: return false
|
||||||
selectionController?.addAll(ids)
|
controller.addAll(ids)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R.id.action_mark_current -> {
|
||||||
|
val id = controller.peekCheckedIds().singleOrNull() ?: return false
|
||||||
|
viewModel.markChapterAsCurrent(id)
|
||||||
|
mode.finish()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,6 +176,7 @@ class ChaptersFragment :
|
|||||||
x.chapter.source == MangaSource.LOCAL
|
x.chapter.source == MangaSource.LOCAL
|
||||||
}
|
}
|
||||||
menu.findItem(R.id.action_select_all).isVisible = items.size < allItems.size
|
menu.findItem(R.id.action_select_all).isVisible = items.size < allItems.size
|
||||||
|
menu.findItem(R.id.action_mark_current).isVisible = items.size == 1
|
||||||
mode.title = items.size.toString()
|
mode.title = items.size.toString()
|
||||||
var hasGap = false
|
var hasGap = false
|
||||||
for (i in 0 until items.size - 1) {
|
for (i in 0 until items.size - 1) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import androidx.core.graphics.Insets
|
|||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
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.BaseTransientBottomBar
|
import com.google.android.material.snackbar.BaseTransientBottomBar
|
||||||
@@ -33,6 +34,8 @@ import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
|||||||
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
||||||
import org.koitharu.kotatsu.core.ui.MangaErrorDialog
|
import org.koitharu.kotatsu.core.ui.MangaErrorDialog
|
||||||
import org.koitharu.kotatsu.databinding.ActivityDetailsBinding
|
import org.koitharu.kotatsu.databinding.ActivityDetailsBinding
|
||||||
|
import org.koitharu.kotatsu.details.service.MangaPrefetchService
|
||||||
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
||||||
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.main.ui.owners.NoModalBottomSheetOwner
|
import org.koitharu.kotatsu.main.ui.owners.NoModalBottomSheetOwner
|
||||||
@@ -120,6 +123,7 @@ class DetailsActivity :
|
|||||||
viewModel.branches.observe(this) {
|
viewModel.branches.observe(this) {
|
||||||
binding.buttonDropdown.isVisible = it.size > 1
|
binding.buttonDropdown.isVisible = it.size > 1
|
||||||
}
|
}
|
||||||
|
viewModel.chapters.observe(this, PrefetchObserver(this))
|
||||||
|
|
||||||
registerReceiver(downloadReceiver, IntentFilter(DownloadService.ACTION_DOWNLOAD_COMPLETE))
|
registerReceiver(downloadReceiver, IntentFilter(DownloadService.ACTION_DOWNLOAD_COMPLETE))
|
||||||
addMenuProvider(
|
addMenuProvider(
|
||||||
@@ -228,18 +232,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)
|
||||||
@@ -273,7 +277,7 @@ class DetailsActivity :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
setNeutralButton(R.string.download) { _, _ ->
|
setNeutralButton(R.string.download) { _, _ ->
|
||||||
DownloadService.start(this@DetailsActivity, remoteManga, setOf(chapterId))
|
DownloadService.start(binding.appbar, remoteManga, setOf(chapterId))
|
||||||
}
|
}
|
||||||
setCancelable(true)
|
setCancelable(true)
|
||||||
}.show()
|
}.show()
|
||||||
@@ -325,6 +329,24 @@ class DetailsActivity :
|
|||||||
return sb
|
return sb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class PrefetchObserver(
|
||||||
|
private val context: Context,
|
||||||
|
) : Observer<List<ChapterListItem>> {
|
||||||
|
|
||||||
|
private var isCalled = false
|
||||||
|
|
||||||
|
override fun onChanged(t: List<ChapterListItem>?) {
|
||||||
|
if (t.isNullOrEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!isCalled) {
|
||||||
|
isCalled = true
|
||||||
|
val item = t.find { it.hasFlag(ChapterListItem.FLAG_CURRENT) } ?: t.first()
|
||||||
|
MangaPrefetchService.prefetchPages(context, item.chapter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newIntent(context: Context, manga: Manga): Intent {
|
fun newIntent(context: Context, manga: Manga): Intent {
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -41,12 +40,23 @@ import org.koitharu.kotatsu.parsers.model.MangaState
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
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.scrobbling.domain.model.ScrobblingInfo
|
import org.koitharu.kotatsu.scrobbling.common.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.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 +85,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 +133,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 +190,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 +241,7 @@ class DetailsFragment :
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.textView_source -> {
|
R.id.textView_source -> {
|
||||||
startActivity(
|
startActivity(
|
||||||
MangaListActivity.newIntent(
|
MangaListActivity.newIntent(
|
||||||
@@ -237,9 +250,14 @@ 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 },
|
||||||
|
manga.source,
|
||||||
|
),
|
||||||
scaleUpActivityOptionsOf(v).toBundle(),
|
scaleUpActivityOptionsOf(v).toBundle(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -249,7 +267,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 +289,14 @@ class DetailsFragment :
|
|||||||
)
|
)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu.show()
|
menu.show()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,8 +340,8 @@ class DetailsFragment :
|
|||||||
.target(binding.imageViewCover)
|
.target(binding.imageViewCover)
|
||||||
.size(CoverSizeResolver(binding.imageViewCover))
|
.size(CoverSizeResolver(binding.imageViewCover))
|
||||||
.data(imageUrl)
|
.data(imageUrl)
|
||||||
|
.tag(manga.source)
|
||||||
.crossfade(context)
|
.crossfade(context)
|
||||||
.referer(manga.publicUrl)
|
|
||||||
.lifecycle(viewLifecycleOwner)
|
.lifecycle(viewLifecycleOwner)
|
||||||
.placeholderMemoryCacheKey(manga.coverUrl)
|
.placeholderMemoryCacheKey(manga.coverUrl)
|
||||||
val previousDrawable = lastResult?.drawable
|
val previousDrawable = lastResult?.drawable
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import org.koitharu.kotatsu.favourites.ui.categories.select.FavouriteCategoriesB
|
|||||||
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.mapNotNullToSet
|
import org.koitharu.kotatsu.parsers.util.mapNotNullToSet
|
||||||
import org.koitharu.kotatsu.scrobbling.ui.selector.ScrobblingSelectorBottomSheet
|
import org.koitharu.kotatsu.scrobbling.common.ui.selector.ScrobblingSelectorBottomSheet
|
||||||
import org.koitharu.kotatsu.search.ui.multi.MultiSearchActivity
|
import org.koitharu.kotatsu.search.ui.multi.MultiSearchActivity
|
||||||
import org.koitharu.kotatsu.utils.ShareHelper
|
import org.koitharu.kotatsu.utils.ShareHelper
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ class DetailsMenuProvider(
|
|||||||
menu.findItem(R.id.action_delete).isVisible = manga?.source == MangaSource.LOCAL
|
menu.findItem(R.id.action_delete).isVisible = manga?.source == MangaSource.LOCAL
|
||||||
menu.findItem(R.id.action_browser).isVisible = manga?.source != MangaSource.LOCAL
|
menu.findItem(R.id.action_browser).isVisible = manga?.source != MangaSource.LOCAL
|
||||||
menu.findItem(R.id.action_shortcut).isVisible = ShortcutManagerCompat.isRequestPinShortcutSupported(activity)
|
menu.findItem(R.id.action_shortcut).isVisible = ShortcutManagerCompat.isRequestPinShortcutSupported(activity)
|
||||||
menu.findItem(R.id.action_shiki_track).isVisible = viewModel.isScrobblingAvailable
|
menu.findItem(R.id.action_scrobbling).isVisible = viewModel.isScrobblingAvailable
|
||||||
menu.findItem(R.id.action_favourite).setIcon(
|
menu.findItem(R.id.action_favourite).setIcon(
|
||||||
if (viewModel.favouriteCategories.value == true) R.drawable.ic_heart else R.drawable.ic_heart_outline,
|
if (viewModel.favouriteCategories.value == true) R.drawable.ic_heart else R.drawable.ic_heart_outline,
|
||||||
)
|
)
|
||||||
@@ -60,11 +60,13 @@ class DetailsMenuProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_favourite -> {
|
R.id.action_favourite -> {
|
||||||
viewModel.manga.value?.let {
|
viewModel.manga.value?.let {
|
||||||
FavouriteCategoriesBottomSheet.show(activity.supportFragmentManager, it)
|
FavouriteCategoriesBottomSheet.show(activity.supportFragmentManager, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_delete -> {
|
R.id.action_delete -> {
|
||||||
val title = viewModel.manga.value?.title.orEmpty()
|
val title = viewModel.manga.value?.title.orEmpty()
|
||||||
MaterialAlertDialogBuilder(activity)
|
MaterialAlertDialogBuilder(activity)
|
||||||
@@ -76,6 +78,7 @@ class DetailsMenuProvider(
|
|||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_save -> {
|
R.id.action_save -> {
|
||||||
viewModel.manga.value?.let {
|
viewModel.manga.value?.let {
|
||||||
val chaptersCount = it.chapters?.size ?: 0
|
val chaptersCount = it.chapters?.size ?: 0
|
||||||
@@ -83,25 +86,29 @@ class DetailsMenuProvider(
|
|||||||
if (chaptersCount > 5 || branches.size > 1) {
|
if (chaptersCount > 5 || branches.size > 1) {
|
||||||
showSaveConfirmation(it, chaptersCount, branches)
|
showSaveConfirmation(it, chaptersCount, branches)
|
||||||
} else {
|
} else {
|
||||||
DownloadService.start(activity, it)
|
DownloadService.start(snackbarHost, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_browser -> {
|
R.id.action_browser -> {
|
||||||
viewModel.manga.value?.let {
|
viewModel.manga.value?.let {
|
||||||
activity.startActivity(BrowserActivity.newIntent(activity, it.publicUrl, it.title))
|
activity.startActivity(BrowserActivity.newIntent(activity, it.publicUrl, it.title))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_related -> {
|
R.id.action_related -> {
|
||||||
viewModel.manga.value?.let {
|
viewModel.manga.value?.let {
|
||||||
activity.startActivity(MultiSearchActivity.newIntent(activity, it.title))
|
activity.startActivity(MultiSearchActivity.newIntent(activity, it.title))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
R.id.action_shiki_track -> {
|
|
||||||
|
R.id.action_scrobbling -> {
|
||||||
viewModel.manga.value?.let {
|
viewModel.manga.value?.let {
|
||||||
ScrobblingSelectorBottomSheet.show(activity.supportFragmentManager, it)
|
ScrobblingSelectorBottomSheet.show(activity.supportFragmentManager, it, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_shortcut -> {
|
R.id.action_shortcut -> {
|
||||||
viewModel.manga.value?.let {
|
viewModel.manga.value?.let {
|
||||||
activity.lifecycleScope.launch {
|
activity.lifecycleScope.launch {
|
||||||
@@ -112,6 +119,7 @@ class DetailsMenuProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -132,7 +140,7 @@ class DetailsMenuProvider(
|
|||||||
val chaptersIds = manga.chapters?.mapNotNullToSet { c ->
|
val chaptersIds = manga.chapters?.mapNotNullToSet { c ->
|
||||||
if (c.branch in selectedBranches) c.id else null
|
if (c.branch in selectedBranches) c.id else null
|
||||||
}
|
}
|
||||||
DownloadService.start(activity, manga, chaptersIds)
|
DownloadService.start(snackbarHost, manga, chaptersIds)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dialogBuilder.setMessage(
|
dialogBuilder.setMessage(
|
||||||
@@ -141,7 +149,7 @@ class DetailsMenuProvider(
|
|||||||
activity.resources.getQuantityString(R.plurals.chapters, chaptersCount, chaptersCount),
|
activity.resources.getQuantityString(R.plurals.chapters, chaptersCount, chaptersCount),
|
||||||
),
|
),
|
||||||
).setPositiveButton(R.string.save) { _, _ ->
|
).setPositiveButton(R.string.save) { _, _ ->
|
||||||
DownloadService.start(activity, manga)
|
DownloadService.start(snackbarHost, manga)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dialogBuilder.show()
|
dialogBuilder.show()
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -37,15 +45,16 @@ 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.mapToSet
|
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||||
import org.koitharu.kotatsu.scrobbling.domain.Scrobbler
|
import org.koitharu.kotatsu.scrobbling.common.domain.Scrobbler
|
||||||
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingInfo
|
import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblingInfo
|
||||||
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingStatus
|
import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblingStatus
|
||||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
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 org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
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,
|
||||||
@@ -63,7 +72,6 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
private val delegate = MangaDetailsDelegate(
|
private val delegate = MangaDetailsDelegate(
|
||||||
intent = intent,
|
intent = intent,
|
||||||
settings = settings,
|
|
||||||
mangaDataRepository = mangaDataRepository,
|
mangaDataRepository = mangaDataRepository,
|
||||||
historyRepository = historyRepository,
|
historyRepository = historyRepository,
|
||||||
localMangaRepository = localMangaRepository,
|
localMangaRepository = localMangaRepository,
|
||||||
@@ -80,8 +88,14 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
private val favourite = favouritesRepository.observeCategoriesIds(delegate.mangaId).map { it.isNotEmpty() }
|
private val favourite = favouritesRepository.observeCategoriesIds(delegate.mangaId).map { it.isNotEmpty() }
|
||||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, false)
|
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, false)
|
||||||
|
|
||||||
private val newChapters = trackingRepository.observeNewChaptersCount(delegate.mangaId)
|
private val newChapters = settings.observeAsFlow(AppSettings.KEY_TRACKER_ENABLED) { isTrackerEnabled }
|
||||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, 0)
|
.flatMapLatest { isEnabled ->
|
||||||
|
if (isEnabled) {
|
||||||
|
trackingRepository.observeNewChaptersCount(delegate.mangaId)
|
||||||
|
} else {
|
||||||
|
flowOf(0)
|
||||||
|
}
|
||||||
|
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, 0)
|
||||||
|
|
||||||
private val chaptersQuery = MutableStateFlow("")
|
private val chaptersQuery = MutableStateFlow("")
|
||||||
|
|
||||||
@@ -91,17 +105,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 ->
|
historyRepository.observeShouldSkip(delegate.manga),
|
||||||
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())
|
||||||
@@ -240,28 +255,35 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateScrobbling(rating: Float, status: ScrobblingStatus?) {
|
fun updateScrobbling(index: Int, rating: Float, status: ScrobblingStatus?) {
|
||||||
for (scrobbler in scrobblers) {
|
val scrobbler = getScrobbler(index) ?: return
|
||||||
if (!scrobbler.isAvailable) continue
|
launchJob(Dispatchers.Default) {
|
||||||
launchJob(Dispatchers.Default) {
|
scrobbler.updateScrobblingInfo(
|
||||||
scrobbler.updateScrobblingInfo(
|
mangaId = delegate.mangaId,
|
||||||
mangaId = delegate.mangaId,
|
rating = rating,
|
||||||
rating = rating,
|
status = status,
|
||||||
status = status,
|
comment = null,
|
||||||
comment = null,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unregisterScrobbling() {
|
fun unregisterScrobbling(index: Int) {
|
||||||
for (scrobbler in scrobblers) {
|
val scrobbler = getScrobbler(index) ?: return
|
||||||
if (!scrobbler.isAvailable) continue
|
launchJob(Dispatchers.Default) {
|
||||||
launchJob(Dispatchers.Default) {
|
scrobbler.unregisterScrobbling(
|
||||||
scrobbler.unregisterScrobbling(
|
mangaId = delegate.mangaId,
|
||||||
mangaId = delegate.mangaId,
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun markChapterAsCurrent(chapterId: Long) {
|
||||||
|
launchJob(Dispatchers.Default) {
|
||||||
|
val manga = checkNotNull(delegate.manga.value)
|
||||||
|
val chapters = checkNotNull(manga.chapters)
|
||||||
|
val chapterIndex = chapters.indexOfFirst { it.id == chapterId }
|
||||||
|
check(chapterIndex in chapters.indices) { "Chapter not found" }
|
||||||
|
val percent = chapterIndex / chapters.size.toFloat()
|
||||||
|
historyRepository.addOrUpdate(manga = manga, chapterId = chapterId, page = 0, scroll = 0, percent = percent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,6 +309,19 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
return spannable.trim()
|
return spannable.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getScrobbler(index: Int): Scrobbler? {
|
||||||
|
val info = scrobblingInfo.value?.getOrNull(index)
|
||||||
|
val scrobbler = if (info != null) {
|
||||||
|
scrobblers.find { it.scrobblerService == info.scrobbler && it.isAvailable }
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
if (scrobbler == null) {
|
||||||
|
errorEvent.call(IllegalStateException("Scrobbler [$index] is not available"))
|
||||||
|
}
|
||||||
|
return scrobbler
|
||||||
|
}
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import org.koitharu.kotatsu.base.domain.MangaIntent
|
|||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||||
import org.koitharu.kotatsu.core.model.getPreferredBranch
|
import org.koitharu.kotatsu.core.model.getPreferredBranch
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
||||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
||||||
import org.koitharu.kotatsu.details.ui.model.toListItem
|
import org.koitharu.kotatsu.details.ui.model.toListItem
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
@@ -21,7 +20,6 @@ import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
|||||||
|
|
||||||
class MangaDetailsDelegate(
|
class MangaDetailsDelegate(
|
||||||
private val intent: MangaIntent,
|
private val intent: MangaIntent,
|
||||||
private val settings: AppSettings,
|
|
||||||
private val mangaDataRepository: MangaDataRepository,
|
private val mangaDataRepository: MangaDataRepository,
|
||||||
private val historyRepository: HistoryRepository,
|
private val historyRepository: HistoryRepository,
|
||||||
private val localMangaRepository: LocalMangaRepository,
|
private val localMangaRepository: LocalMangaRepository,
|
||||||
@@ -82,7 +80,6 @@ class MangaDetailsDelegate(
|
|||||||
branch: String?,
|
branch: String?,
|
||||||
): List<ChapterListItem> {
|
): List<ChapterListItem> {
|
||||||
val result = ArrayList<ChapterListItem>(chapters.size)
|
val result = ArrayList<ChapterListItem>(chapters.size)
|
||||||
val dateFormat = settings.getDateFormat()
|
|
||||||
val currentIndex = chapters.indexOfFirst { it.id == currentId }
|
val currentIndex = chapters.indexOfFirst { it.id == currentId }
|
||||||
val firstNewIndex = chapters.size - newCount
|
val firstNewIndex = chapters.size - newCount
|
||||||
val downloadedIds = downloadedChapters?.mapTo(HashSet(downloadedChapters.size)) { it.id }
|
val downloadedIds = downloadedChapters?.mapTo(HashSet(downloadedChapters.size)) { it.id }
|
||||||
@@ -97,7 +94,6 @@ class MangaDetailsDelegate(
|
|||||||
isNew = i >= firstNewIndex,
|
isNew = i >= firstNewIndex,
|
||||||
isMissing = false,
|
isMissing = false,
|
||||||
isDownloaded = downloadedIds?.contains(chapter.id) == true,
|
isDownloaded = downloadedIds?.contains(chapter.id) == true,
|
||||||
dateFormat = dateFormat,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (result.size < chapters.size / 2) {
|
if (result.size < chapters.size / 2) {
|
||||||
@@ -117,7 +113,6 @@ class MangaDetailsDelegate(
|
|||||||
val result = ArrayList<ChapterListItem>(sourceChapters.size)
|
val result = ArrayList<ChapterListItem>(sourceChapters.size)
|
||||||
val currentIndex = sourceChapters.indexOfFirst { it.id == currentId }
|
val currentIndex = sourceChapters.indexOfFirst { it.id == currentId }
|
||||||
val firstNewIndex = sourceChapters.size - newCount
|
val firstNewIndex = sourceChapters.size - newCount
|
||||||
val dateFormat = settings.getDateFormat()
|
|
||||||
for (i in sourceChapters.indices) {
|
for (i in sourceChapters.indices) {
|
||||||
val chapter = sourceChapters[i]
|
val chapter = sourceChapters[i]
|
||||||
val localChapter = chaptersMap.remove(chapter.id)
|
val localChapter = chaptersMap.remove(chapter.id)
|
||||||
@@ -130,14 +125,12 @@ class MangaDetailsDelegate(
|
|||||||
isNew = i >= firstNewIndex,
|
isNew = i >= firstNewIndex,
|
||||||
isMissing = false,
|
isMissing = false,
|
||||||
isDownloaded = false,
|
isDownloaded = false,
|
||||||
dateFormat = dateFormat,
|
|
||||||
) ?: chapter.toListItem(
|
) ?: chapter.toListItem(
|
||||||
isCurrent = i == currentIndex,
|
isCurrent = i == currentIndex,
|
||||||
isUnread = i > currentIndex,
|
isUnread = i > currentIndex,
|
||||||
isNew = i >= firstNewIndex,
|
isNew = i >= firstNewIndex,
|
||||||
isMissing = true,
|
isMissing = true,
|
||||||
isDownloaded = false,
|
isDownloaded = false,
|
||||||
dateFormat = dateFormat,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (chaptersMap.isNotEmpty()) { // some chapters on device but not online source
|
if (chaptersMap.isNotEmpty()) { // some chapters on device but not online source
|
||||||
@@ -150,7 +143,6 @@ class MangaDetailsDelegate(
|
|||||||
isNew = false,
|
isNew = false,
|
||||||
isMissing = false,
|
isMissing = false,
|
||||||
isDownloaded = false,
|
isDownloaded = false,
|
||||||
dateFormat = dateFormat,
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ class ChaptersAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSectionText(context: Context, position: Int): CharSequence {
|
override fun getSectionText(context: Context, position: Int): CharSequence? {
|
||||||
return items[position].chapter.number.toString()
|
val item = items.getOrNull(position) ?: return null
|
||||||
|
return item.chapter.number.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
package org.koitharu.kotatsu.details.ui.model
|
package org.koitharu.kotatsu.details.ui.model
|
||||||
|
|
||||||
import java.text.DateFormat
|
import android.text.format.DateUtils
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
|
||||||
class ChapterListItem(
|
class ChapterListItem(
|
||||||
val chapter: MangaChapter,
|
val chapter: MangaChapter,
|
||||||
val flags: Int,
|
val flags: Int,
|
||||||
private val uploadDateMs: Long,
|
private val uploadDateMs: Long,
|
||||||
private val dateFormat: DateFormat,
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var uploadDate: String? = null
|
var uploadDate: CharSequence? = null
|
||||||
private set
|
private set
|
||||||
get() {
|
get() {
|
||||||
if (field != null) return field
|
if (field != null) return field
|
||||||
if (uploadDateMs == 0L) return null
|
if (uploadDateMs == 0L) return null
|
||||||
field = dateFormat.format(uploadDateMs)
|
field = DateUtils.getRelativeTimeSpanString(
|
||||||
|
uploadDateMs,
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
DateUtils.DAY_IN_MILLIS,
|
||||||
|
)
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +47,6 @@ class ChapterListItem(
|
|||||||
if (chapter != other.chapter) return false
|
if (chapter != other.chapter) return false
|
||||||
if (flags != other.flags) return false
|
if (flags != other.flags) return false
|
||||||
if (uploadDateMs != other.uploadDateMs) return false
|
if (uploadDateMs != other.uploadDateMs) return false
|
||||||
if (dateFormat != other.dateFormat) return false
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -53,7 +55,6 @@ class ChapterListItem(
|
|||||||
var result = chapter.hashCode()
|
var result = chapter.hashCode()
|
||||||
result = 31 * result + flags
|
result = 31 * result + flags
|
||||||
result = 31 * result + uploadDateMs.hashCode()
|
result = 31 * result + uploadDateMs.hashCode()
|
||||||
result = 31 * result + dateFormat.hashCode()
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.koitharu.kotatsu.details.ui.model
|
package org.koitharu.kotatsu.details.ui.model
|
||||||
|
|
||||||
import java.text.DateFormat
|
|
||||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_CURRENT
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_CURRENT
|
||||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_DOWNLOADED
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_DOWNLOADED
|
||||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_MISSING
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_MISSING
|
||||||
@@ -14,7 +13,6 @@ fun MangaChapter.toListItem(
|
|||||||
isNew: Boolean,
|
isNew: Boolean,
|
||||||
isMissing: Boolean,
|
isMissing: Boolean,
|
||||||
isDownloaded: Boolean,
|
isDownloaded: Boolean,
|
||||||
dateFormat: DateFormat,
|
|
||||||
): ChapterListItem {
|
): ChapterListItem {
|
||||||
var flags = 0
|
var flags = 0
|
||||||
if (isCurrent) flags = flags or FLAG_CURRENT
|
if (isCurrent) flags = flags or FLAG_CURRENT
|
||||||
@@ -26,6 +24,5 @@ fun MangaChapter.toListItem(
|
|||||||
chapter = this,
|
chapter = this,
|
||||||
flags = flags,
|
flags = flags,
|
||||||
uploadDateMs = uploadDate,
|
uploadDateMs = uploadDate,
|
||||||
dateFormat = dateFormat,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import coil.ImageLoader
|
|||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.databinding.ItemScrobblingInfoBinding
|
import org.koitharu.kotatsu.databinding.ItemScrobblingInfoBinding
|
||||||
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingInfo
|
import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblingInfo
|
||||||
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
||||||
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
@@ -23,7 +23,7 @@ fun scrobblingInfoAD(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.imageViewCover.newImageRequest(item.coverUrl)?.run {
|
binding.imageViewCover.newImageRequest(item.coverUrl /* TODO */, null)?.run {
|
||||||
placeholder(R.drawable.ic_placeholder)
|
placeholder(R.drawable.ic_placeholder)
|
||||||
fallback(R.drawable.ic_placeholder)
|
fallback(R.drawable.ic_placeholder)
|
||||||
error(R.drawable.ic_error_placeholder)
|
error(R.drawable.ic_error_placeholder)
|
||||||
|
|||||||
@@ -15,18 +15,21 @@ import androidx.core.net.toUri
|
|||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import coil.request.ImageRequest
|
|
||||||
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.BaseBottomSheet
|
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
||||||
import org.koitharu.kotatsu.databinding.SheetScrobblingBinding
|
import org.koitharu.kotatsu.databinding.SheetScrobblingBinding
|
||||||
import org.koitharu.kotatsu.details.ui.DetailsViewModel
|
import org.koitharu.kotatsu.details.ui.DetailsViewModel
|
||||||
import org.koitharu.kotatsu.image.ui.ImageActivity
|
import org.koitharu.kotatsu.image.ui.ImageActivity
|
||||||
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingInfo
|
import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblingInfo
|
||||||
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingStatus
|
import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblingStatus
|
||||||
import org.koitharu.kotatsu.scrobbling.ui.selector.ScrobblingSelectorBottomSheet
|
import org.koitharu.kotatsu.scrobbling.common.ui.selector.ScrobblingSelectorBottomSheet
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
|
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
||||||
|
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ScrobblingInfoBottomSheet :
|
class ScrobblingInfoBottomSheet :
|
||||||
@@ -41,6 +44,7 @@ class ScrobblingInfoBottomSheet :
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var coil: ImageLoader
|
lateinit var coil: ImageLoader
|
||||||
|
|
||||||
private var menu: PopupMenu? = null
|
private var menu: PopupMenu? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@@ -78,6 +82,7 @@ class ScrobblingInfoBottomSheet :
|
|||||||
|
|
||||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
viewModel.updateScrobbling(
|
viewModel.updateScrobbling(
|
||||||
|
index = scrobblerIndex,
|
||||||
rating = binding.ratingBar.rating / binding.ratingBar.numStars,
|
rating = binding.ratingBar.rating / binding.ratingBar.numStars,
|
||||||
status = enumValues<ScrobblingStatus>().getOrNull(position),
|
status = enumValues<ScrobblingStatus>().getOrNull(position),
|
||||||
)
|
)
|
||||||
@@ -88,6 +93,7 @@ class ScrobblingInfoBottomSheet :
|
|||||||
override fun onRatingChanged(ratingBar: RatingBar, rating: Float, fromUser: Boolean) {
|
override fun onRatingChanged(ratingBar: RatingBar, rating: Float, fromUser: Boolean) {
|
||||||
if (fromUser) {
|
if (fromUser) {
|
||||||
viewModel.updateScrobbling(
|
viewModel.updateScrobbling(
|
||||||
|
index = scrobblerIndex,
|
||||||
rating = rating / ratingBar.numStars,
|
rating = rating / ratingBar.numStars,
|
||||||
status = enumValues<ScrobblingStatus>().getOrNull(binding.spinnerStatus.selectedItemPosition),
|
status = enumValues<ScrobblingStatus>().getOrNull(binding.spinnerStatus.selectedItemPosition),
|
||||||
)
|
)
|
||||||
@@ -100,7 +106,7 @@ class ScrobblingInfoBottomSheet :
|
|||||||
R.id.imageView_cover -> {
|
R.id.imageView_cover -> {
|
||||||
val coverUrl = viewModel.scrobblingInfo.value?.getOrNull(scrobblerIndex)?.coverUrl ?: return
|
val coverUrl = viewModel.scrobblingInfo.value?.getOrNull(scrobblerIndex)?.coverUrl ?: return
|
||||||
val options = scaleUpActivityOptionsOf(v)
|
val options = scaleUpActivityOptionsOf(v)
|
||||||
startActivity(ImageActivity.newIntent(v.context, coverUrl), options.toBundle())
|
startActivity(ImageActivity.newIntent(v.context, coverUrl, null), options.toBundle())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,15 +121,15 @@ class ScrobblingInfoBottomSheet :
|
|||||||
binding.ratingBar.rating = scrobbling.rating * binding.ratingBar.numStars
|
binding.ratingBar.rating = scrobbling.rating * binding.ratingBar.numStars
|
||||||
binding.textViewDescription.text = scrobbling.description
|
binding.textViewDescription.text = scrobbling.description
|
||||||
binding.spinnerStatus.setSelection(scrobbling.status?.ordinal ?: -1)
|
binding.spinnerStatus.setSelection(scrobbling.status?.ordinal ?: -1)
|
||||||
ImageRequest.Builder(context ?: return)
|
binding.imageViewLogo.contentDescription = getString(scrobbling.scrobbler.titleResId)
|
||||||
.target(binding.imageViewCover)
|
binding.imageViewLogo.setImageResource(scrobbling.scrobbler.iconResId)
|
||||||
.data(scrobbling.coverUrl)
|
binding.imageViewCover.newImageRequest(scrobbling.coverUrl)?.apply {
|
||||||
.crossfade(context)
|
lifecycle(viewLifecycleOwner)
|
||||||
.lifecycle(viewLifecycleOwner)
|
placeholder(R.drawable.ic_placeholder)
|
||||||
.placeholder(R.drawable.ic_placeholder)
|
fallback(R.drawable.ic_placeholder)
|
||||||
.fallback(R.drawable.ic_placeholder)
|
error(R.drawable.ic_error_placeholder)
|
||||||
.error(R.drawable.ic_error_placeholder)
|
enqueueWith(coil)
|
||||||
.enqueueWith(coil)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||||
@@ -135,13 +141,16 @@ class ScrobblingInfoBottomSheet :
|
|||||||
Intent.createChooser(intent, getString(R.string.open_in_browser)),
|
Intent.createChooser(intent, getString(R.string.open_in_browser)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_unregister -> {
|
R.id.action_unregister -> {
|
||||||
viewModel.unregisterScrobbling()
|
viewModel.unregisterScrobbling(scrobblerIndex)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_edit -> {
|
R.id.action_edit -> {
|
||||||
val manga = viewModel.manga.value ?: return false
|
val manga = viewModel.manga.value ?: return false
|
||||||
ScrobblingSelectorBottomSheet.show(parentFragmentManager, manga)
|
val scrobblerService = viewModel.scrobblingInfo.value?.getOrNull(scrobblerIndex)?.scrobbler
|
||||||
|
ScrobblingSelectorBottomSheet.show(parentFragmentManager, manga, scrobblerService)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ 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 org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingInfo
|
import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblingInfo
|
||||||
|
|
||||||
class ScrollingInfoAdapter(
|
class ScrollingInfoAdapter(
|
||||||
lifecycleOwner: LifecycleOwner,
|
lifecycleOwner: LifecycleOwner,
|
||||||
@@ -27,7 +27,7 @@ class ScrollingInfoAdapter(
|
|||||||
return oldItem == newItem
|
return oldItem == newItem
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChangePayload(oldItem: ScrobblingInfo, newItem: ScrobblingInfo): Any? {
|
override fun getChangePayload(oldItem: ScrobblingInfo, newItem: ScrobblingInfo): Any {
|
||||||
return Unit
|
return Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import kotlinx.coroutines.NonCancellable
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runInterruptible
|
|
||||||
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 kotlinx.coroutines.withContext
|
||||||
@@ -36,9 +35,9 @@ 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.runCatchingCancellable
|
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
|
import java.io.File
|
||||||
@@ -118,7 +117,7 @@ class DownloadManager @AssistedInject constructor(
|
|||||||
val data = if (manga.chapters.isNullOrEmpty()) repo.getDetails(manga) else manga
|
val data = if (manga.chapters.isNullOrEmpty()) repo.getDetails(manga) else manga
|
||||||
output = CbzMangaOutput.get(destination, data)
|
output = CbzMangaOutput.get(destination, data)
|
||||||
val coverUrl = data.largeCoverUrl ?: data.coverUrl
|
val coverUrl = data.largeCoverUrl ?: data.coverUrl
|
||||||
downloadFile(coverUrl, data.publicUrl, destination, tempFileName).let { file ->
|
downloadFile(coverUrl, data.publicUrl, destination, tempFileName, repo.source).let { file ->
|
||||||
output.addCover(file, MimeTypeMap.getFileExtensionFromUrl(coverUrl))
|
output.addCover(file, MimeTypeMap.getFileExtensionFromUrl(coverUrl))
|
||||||
}
|
}
|
||||||
val chapters = checkNotNull(
|
val chapters = checkNotNull(
|
||||||
@@ -139,7 +138,8 @@ class DownloadManager @AssistedInject constructor(
|
|||||||
for ((pageIndex, page) in pages.withIndex()) {
|
for ((pageIndex, page) in pages.withIndex()) {
|
||||||
runFailsafe(outState, pausingHandle) {
|
runFailsafe(outState, pausingHandle) {
|
||||||
val url = repo.getPageUrl(page)
|
val url = repo.getPageUrl(page)
|
||||||
val file = cache[url] ?: downloadFile(url, page.referer, destination, tempFileName)
|
val file = cache[url]
|
||||||
|
?: downloadFile(url, page.referer, destination, tempFileName, repo.source)
|
||||||
output.addPage(
|
output.addPage(
|
||||||
chapter = chapter,
|
chapter = chapter,
|
||||||
file = file,
|
file = file,
|
||||||
@@ -209,20 +209,25 @@ class DownloadManager @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun downloadFile(url: String, referer: String, destination: File, tempFileName: String): File {
|
private suspend fun downloadFile(
|
||||||
|
url: String,
|
||||||
|
referer: String,
|
||||||
|
destination: File,
|
||||||
|
tempFileName: String,
|
||||||
|
source: MangaSource,
|
||||||
|
): File {
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.header(CommonHeaders.REFERER, referer)
|
.header(CommonHeaders.REFERER, referer)
|
||||||
|
.tag(MangaSource::class.java, source)
|
||||||
.cacheControl(CommonHeaders.CACHE_CONTROL_DISABLED)
|
.cacheControl(CommonHeaders.CACHE_CONTROL_DISABLED)
|
||||||
.get()
|
.get()
|
||||||
.build()
|
.build()
|
||||||
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
|
||||||
}
|
}
|
||||||
@@ -244,7 +249,7 @@ class DownloadManager @AssistedInject constructor(
|
|||||||
imageLoader.execute(
|
imageLoader.execute(
|
||||||
ImageRequest.Builder(context)
|
ImageRequest.Builder(context)
|
||||||
.data(manga.coverUrl)
|
.data(manga.coverUrl)
|
||||||
.referer(manga.publicUrl)
|
.tag(manga.source)
|
||||||
.size(coverWidth, coverHeight)
|
.size(coverWidth, coverHeight)
|
||||||
.scale(Scale.FILL)
|
.scale(Scale.FILL)
|
||||||
.build(),
|
.build(),
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ sealed interface DownloadState {
|
|||||||
val manga: Manga
|
val manga: Manga
|
||||||
val cover: Drawable?
|
val cover: Drawable?
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean
|
||||||
|
|
||||||
|
override fun hashCode(): Int
|
||||||
|
|
||||||
|
val isTerminal: Boolean
|
||||||
|
get() = this is Done || this is Cancelled || (this is Error && !canRetry)
|
||||||
|
|
||||||
class Queued(
|
class Queued(
|
||||||
override val startId: Int,
|
override val startId: Int,
|
||||||
override val manga: Manga,
|
override val manga: Manga,
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ import org.koitharu.kotatsu.databinding.ItemDownloadBinding
|
|||||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
import org.koitharu.kotatsu.download.domain.DownloadState
|
import org.koitharu.kotatsu.download.domain.DownloadState
|
||||||
import org.koitharu.kotatsu.parsers.util.format
|
import org.koitharu.kotatsu.parsers.util.format
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
|
import org.koitharu.kotatsu.utils.ext.onFirst
|
||||||
|
|
||||||
fun downloadItemAD(
|
fun downloadItemAD(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
@@ -40,8 +43,7 @@ fun downloadItemAD(
|
|||||||
bind {
|
bind {
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
job = item.progressAsFlow().onFirst { state ->
|
job = item.progressAsFlow().onFirst { state ->
|
||||||
binding.imageViewCover.newImageRequest(state.manga.coverUrl)?.run {
|
binding.imageViewCover.newImageRequest(state.manga.coverUrl, state.manga.source)?.run {
|
||||||
referer(state.manga.publicUrl)
|
|
||||||
placeholder(state.cover)
|
placeholder(state.cover)
|
||||||
fallback(R.drawable.ic_placeholder)
|
fallback(R.drawable.ic_placeholder)
|
||||||
error(R.drawable.ic_error_placeholder)
|
error(R.drawable.ic_error_placeholder)
|
||||||
@@ -60,6 +62,7 @@ fun downloadItemAD(
|
|||||||
binding.buttonCancel.isVisible = false
|
binding.buttonCancel.isVisible = false
|
||||||
binding.buttonResume.isVisible = false
|
binding.buttonResume.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
is DownloadState.Done -> {
|
is DownloadState.Done -> {
|
||||||
binding.textViewStatus.setText(R.string.download_complete)
|
binding.textViewStatus.setText(R.string.download_complete)
|
||||||
binding.progressBar.isIndeterminate = false
|
binding.progressBar.isIndeterminate = false
|
||||||
@@ -69,6 +72,7 @@ fun downloadItemAD(
|
|||||||
binding.buttonCancel.isVisible = false
|
binding.buttonCancel.isVisible = false
|
||||||
binding.buttonResume.isVisible = false
|
binding.buttonResume.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
is DownloadState.Error -> {
|
is DownloadState.Error -> {
|
||||||
binding.textViewStatus.setText(R.string.error_occurred)
|
binding.textViewStatus.setText(R.string.error_occurred)
|
||||||
binding.progressBar.isIndeterminate = false
|
binding.progressBar.isIndeterminate = false
|
||||||
@@ -79,6 +83,7 @@ fun downloadItemAD(
|
|||||||
binding.buttonCancel.isVisible = state.canRetry
|
binding.buttonCancel.isVisible = state.canRetry
|
||||||
binding.buttonResume.isVisible = state.canRetry
|
binding.buttonResume.isVisible = state.canRetry
|
||||||
}
|
}
|
||||||
|
|
||||||
is DownloadState.PostProcessing -> {
|
is DownloadState.PostProcessing -> {
|
||||||
binding.textViewStatus.setText(R.string.processing_)
|
binding.textViewStatus.setText(R.string.processing_)
|
||||||
binding.progressBar.isIndeterminate = true
|
binding.progressBar.isIndeterminate = true
|
||||||
@@ -88,6 +93,7 @@ fun downloadItemAD(
|
|||||||
binding.buttonCancel.isVisible = false
|
binding.buttonCancel.isVisible = false
|
||||||
binding.buttonResume.isVisible = false
|
binding.buttonResume.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
is DownloadState.Preparing -> {
|
is DownloadState.Preparing -> {
|
||||||
binding.textViewStatus.setText(R.string.preparing_)
|
binding.textViewStatus.setText(R.string.preparing_)
|
||||||
binding.progressBar.isIndeterminate = true
|
binding.progressBar.isIndeterminate = true
|
||||||
@@ -97,6 +103,7 @@ fun downloadItemAD(
|
|||||||
binding.buttonCancel.isVisible = true
|
binding.buttonCancel.isVisible = true
|
||||||
binding.buttonResume.isVisible = false
|
binding.buttonResume.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
is DownloadState.Progress -> {
|
is DownloadState.Progress -> {
|
||||||
binding.textViewStatus.setText(R.string.manga_downloading_)
|
binding.textViewStatus.setText(R.string.manga_downloading_)
|
||||||
binding.progressBar.isIndeterminate = false
|
binding.progressBar.isIndeterminate = false
|
||||||
@@ -109,6 +116,7 @@ fun downloadItemAD(
|
|||||||
binding.buttonCancel.isVisible = true
|
binding.buttonCancel.isVisible = true
|
||||||
binding.buttonResume.isVisible = false
|
binding.buttonResume.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
is DownloadState.Queued -> {
|
is DownloadState.Queued -> {
|
||||||
binding.textViewStatus.setText(R.string.queued)
|
binding.textViewStatus.setText(R.string.queued)
|
||||||
binding.progressBar.isIndeterminate = false
|
binding.progressBar.isIndeterminate = false
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user