Compare commits
331 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5cd92fb5f | ||
|
|
08e5c148fd | ||
|
|
8323d399ff | ||
|
|
5108f45111 | ||
|
|
bf0d34e9cf | ||
|
|
3778a9e1d4 | ||
|
|
71ecd9d8e2 | ||
|
|
7cba8d2dc7 | ||
|
|
79c2927da2 | ||
|
|
a4a28c7342 | ||
|
|
43a92bdf08 | ||
|
|
51ff1ff7b7 | ||
|
|
2e0eb5de54 | ||
|
|
4f68e7d0e6 | ||
|
|
c6d303980b | ||
|
|
18e6ee1453 | ||
|
|
09144d7f55 | ||
|
|
05583504ee | ||
|
|
8dc02967fc | ||
|
|
4c206746c9 | ||
|
|
e9b0e9f740 | ||
|
|
6d0cd49db3 | ||
|
|
e69964d1f5 | ||
|
|
f368277d73 | ||
|
|
f3a8eb3216 | ||
|
|
f7a585ef55 | ||
|
|
96d6f8d8e6 | ||
|
|
67bbd3e6d3 | ||
|
|
e7afe1c802 | ||
|
|
f63beba8af | ||
|
|
4ddeb1acce | ||
|
|
10b178aed3 | ||
|
|
514594edb0 | ||
|
|
b2a9f7d594 | ||
|
|
f38220eefb | ||
|
|
30ad67ef52 | ||
|
|
810434fef5 | ||
|
|
26a7a7a2e8 | ||
|
|
4d8da40885 | ||
|
|
248bf8ed03 | ||
|
|
090f7a5858 | ||
|
|
5f38b01fd1 | ||
|
|
2169ee7a5b | ||
|
|
d633204efa | ||
|
|
2b12dbd8d7 | ||
|
|
8bfdc73072 | ||
|
|
be666b7854 | ||
|
|
52655cad2c | ||
|
|
8e856211aa | ||
|
|
e1f82d147c | ||
|
|
023605e246 | ||
|
|
c0544e25af | ||
|
|
235b02870b | ||
|
|
25e7ab2d8e | ||
|
|
2d171657dc | ||
|
|
ac9680b5c0 | ||
|
|
42df607f52 | ||
|
|
fc1755612b | ||
|
|
1ead369ee2 | ||
|
|
07aa04aa4d | ||
|
|
7b8bbf9fe1 | ||
|
|
8883e73971 | ||
|
|
0cb1238143 | ||
|
|
f4628f7ab5 | ||
|
|
3d0b69024d | ||
|
|
12e9fb5aab | ||
|
|
5fc08d9ecb | ||
|
|
e7eb61e3e5 | ||
|
|
dae3982e67 | ||
|
|
45b2d2bebe | ||
|
|
77fa34835f | ||
|
|
cee68069d6 | ||
|
|
48afc8624b | ||
|
|
b9b41ed491 | ||
|
|
632b42ea86 | ||
|
|
427272aac1 | ||
|
|
41ac50c76a | ||
|
|
f05bb20428 | ||
|
|
78f417ebe1 | ||
|
|
3fd6bec433 | ||
|
|
262e26a0cc | ||
|
|
1b64c2a330 | ||
|
|
5ea0ecbd12 | ||
|
|
f9a1d1617e | ||
|
|
10d8365fc1 | ||
|
|
85065c57a1 | ||
|
|
75e130b97c | ||
|
|
df99eec429 | ||
|
|
3a40820991 | ||
|
|
27bd2e74ca | ||
|
|
a308688a2e | ||
|
|
259c845912 | ||
|
|
a89ff4d15d | ||
|
|
3ed9ed8cab | ||
|
|
40b9577e69 | ||
|
|
b87ae19712 | ||
|
|
1dc7e61dbd | ||
|
|
7bd1affe5e | ||
|
|
068196b48b | ||
|
|
89ed09fd09 | ||
|
|
f9b233d8c0 | ||
|
|
9017dae834 | ||
|
|
aabae06515 | ||
|
|
ad530fe55d | ||
|
|
703a5358c2 | ||
|
|
4824a95375 | ||
|
|
d266ffddd3 | ||
|
|
fd7e7eb974 | ||
|
|
ca3e789340 | ||
|
|
94ca2aae89 | ||
|
|
0aad55eea0 | ||
|
|
ee95679c60 | ||
|
|
21bcb293f5 | ||
|
|
648ee3c763 | ||
|
|
ac8283d4af | ||
|
|
ae460720e3 | ||
|
|
e66eedf0a1 | ||
|
|
e6891cc3ba | ||
|
|
5b047b616a | ||
|
|
d3c0d89fe0 | ||
|
|
ccebe2660f | ||
|
|
2efe739a43 | ||
|
|
3919884723 | ||
|
|
5407587de2 | ||
|
|
29ead727bb | ||
|
|
cfbe394bfb | ||
|
|
9914b9a312 | ||
|
|
6548a6f1fe | ||
|
|
5a22e9b0e6 | ||
|
|
85ce118141 | ||
|
|
d4c3a815a1 | ||
|
|
e1b9f41fe3 | ||
|
|
55f2f80486 | ||
|
|
628944a4f2 | ||
|
|
7d0c50d58e | ||
|
|
c989061576 | ||
|
|
5896d7abe7 | ||
|
|
1999f6f1a1 | ||
|
|
745f0adf5b | ||
|
|
32b1ee9e7b | ||
|
|
85710acb3a | ||
|
|
ffd31dbea9 | ||
|
|
c4d8cd81b2 | ||
|
|
c4ba311087 | ||
|
|
277d575485 | ||
|
|
f32ff00b68 | ||
|
|
bd5b6beb72 | ||
|
|
c8053b2eb6 | ||
|
|
938be67cd3 | ||
|
|
f608dd3078 | ||
|
|
72169e71ce | ||
|
|
8ce5e7eccf | ||
|
|
cfd39e615a | ||
|
|
8718b8781d | ||
|
|
d18c90c31a | ||
|
|
16c3e61984 | ||
|
|
dba506cb42 | ||
|
|
0186517175 | ||
|
|
f63ccf2e90 | ||
|
|
dfb88feaf0 | ||
|
|
c53ee01af5 | ||
|
|
149b171eda | ||
|
|
c70a2487d9 | ||
|
|
2e56fcb5da | ||
|
|
04533aa347 | ||
|
|
d258f479b3 | ||
|
|
b81ecda43e | ||
|
|
f42e3d7912 | ||
|
|
e1780b71ae | ||
|
|
57bad3814d | ||
|
|
07de0c9c84 | ||
|
|
d8a7280b3b | ||
|
|
7bea3caa07 | ||
|
|
bd27eb9f59 | ||
|
|
056538a341 | ||
|
|
865f335b25 | ||
|
|
6b1e89eda8 | ||
|
|
0dbaf919e2 | ||
|
|
c2508bbae8 | ||
|
|
4c347862f8 | ||
|
|
21f6a0a8b9 | ||
|
|
7431f46117 | ||
|
|
48ac417189 | ||
|
|
98453c34a7 | ||
|
|
7bec47b4d8 | ||
|
|
c62e29d995 | ||
|
|
4d0bd9538b | ||
|
|
fdb4e5098e | ||
|
|
758d3c55d4 | ||
|
|
f40ff12250 | ||
|
|
43d55cedae | ||
|
|
bc4dd1c507 | ||
|
|
b45147563a | ||
|
|
527e11e65b | ||
|
|
9b8b6d789e | ||
|
|
0e4575356a | ||
|
|
4744a0a162 | ||
|
|
b1a94c0f34 | ||
|
|
f38ff55aea | ||
|
|
efc4bbacb5 | ||
|
|
b4e0704a3a | ||
|
|
8294eb4ecd | ||
|
|
28e3f1c063 | ||
|
|
072cdc35e8 | ||
|
|
1ad64f2710 | ||
|
|
b2266d47df | ||
|
|
c8141c6046 | ||
|
|
cc698cc82d | ||
|
|
472a8d9d72 | ||
|
|
4f3721beea | ||
|
|
346526267e | ||
|
|
6c82c6e9f5 | ||
|
|
11dabd7426 | ||
|
|
056a26b55c | ||
|
|
f1863ddc71 | ||
|
|
437ae4cdae | ||
|
|
98f5615d77 | ||
|
|
44ce3ce66d | ||
|
|
080c2724cd | ||
|
|
43872ffe01 | ||
|
|
5cfad9ab8a | ||
|
|
866f9272ef | ||
|
|
c6446afab1 | ||
|
|
f5a6e1e124 | ||
|
|
5595bc6971 | ||
|
|
e6ed353211 | ||
|
|
4e10908015 | ||
|
|
087ececfdd | ||
|
|
c090018acd | ||
|
|
5f6256a5c6 | ||
|
|
9e6be12707 | ||
|
|
737ca4a916 | ||
|
|
b2958d03e4 | ||
|
|
af8550744f | ||
|
|
2f5fd71bb1 | ||
|
|
271750ad93 | ||
|
|
0281c09dde | ||
|
|
c50fa8f10c | ||
|
|
f2ac3c331c | ||
|
|
4fc56f9786 | ||
|
|
da47dac3f7 | ||
|
|
d2afd36656 | ||
|
|
1316d71d3e | ||
|
|
a13c498d00 | ||
|
|
e15934bdc6 | ||
|
|
4ec50f83d2 | ||
|
|
d0b9412559 | ||
|
|
a3b22e050f | ||
|
|
9adf209445 | ||
|
|
5d2395b569 | ||
|
|
672a1e9b2a | ||
|
|
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 | ||
|
|
80be0e403d | ||
|
|
ee2538ba7f | ||
|
|
6ca6ec28ac | ||
|
|
94203785f1 | ||
|
|
3f538d9b78 | ||
|
|
e6a0578884 | ||
|
|
2c71110fa5 | ||
|
|
46786e32a3 | ||
|
|
eef449af49 | ||
|
|
0c4c7489e9 | ||
|
|
743098d0b0 | ||
|
|
2b2042807b |
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
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
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
@@ -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.8.0" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
15
README.md
@@ -2,21 +2,16 @@
|
|||||||
|
|
||||||
Kotatsu is a free and open source manga reader for Android.
|
Kotatsu is a free and open source manga reader for Android.
|
||||||
|
|
||||||
   [](https://hosted.weblate.org/engage/kotatsu/) [](http://4pda.ru/forum/index.php?showtopic=697669) [](https://discord.gg/NNJ5RgVBC5)
|
   [](https://hosted.weblate.org/engage/kotatsu/) [](https://t.me/kotatsuapp) [](https://discord.gg/NNJ5RgVBC5)
|
||||||
|
|
||||||
### Download
|
### Download
|
||||||
|
|
||||||
[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png"
|
- **Recommended:** Download and install APK from **[GitHub Releases](https://github.com/KotatsuApp/Kotatsu/releases/latest)**. Application has a built-in self-updating feature.
|
||||||
alt="Get it on F-Droid"
|
- Get it on **[F-Droid](https://f-droid.org/packages/org.koitharu.kotatsu)**. The F-Droid build may be a bit outdated and some fixes might be missing.
|
||||||
height="80">](https://f-droid.org/packages/org.koitharu.kotatsu)
|
|
||||||
|
|
||||||
Download APK directly from GitHub:
|
|
||||||
|
|
||||||
- **[Latest release](https://github.com/KotatsuApp/Kotatsu/releases/latest)**
|
|
||||||
|
|
||||||
### 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,7 +19,7 @@ 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](https://github.com/KotatsuApp/kotatsu-syncserver) across devices
|
* History and favourites [synchronization](https://github.com/KotatsuApp/kotatsu-syncserver) across devices
|
||||||
|
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ plugins {
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdk = 33
|
compileSdk = 33
|
||||||
buildToolsVersion = '33.0.1'
|
buildToolsVersion = '33.0.2'
|
||||||
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 513
|
versionCode 546
|
||||||
versionName '4.3.2'
|
versionName '5.1.2'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
@@ -25,12 +25,6 @@ android {
|
|||||||
arg 'room.schemaLocation', "$projectDir/schemas".toString()
|
arg 'room.schemaLocation', "$projectDir/schemas".toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// define this values in your local.properties file
|
|
||||||
buildConfigField 'String', 'SHIKIMORI_CLIENT_ID', "\"${localProperty('shikimori.clientId')}\""
|
|
||||||
buildConfigField 'String', 'SHIKIMORI_CLIENT_SECRET', "\"${localProperty('shikimori.clientSecret')}\""
|
|
||||||
resValue "string", "acra_login", "${localProperty('acra.login')}"
|
|
||||||
resValue "string", "acra_password", "${localProperty('acra.password')}"
|
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
debug {
|
debug {
|
||||||
@@ -50,22 +44,21 @@ android {
|
|||||||
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
|
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_17
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||||
freeCompilerArgs += [
|
freeCompilerArgs += [
|
||||||
'-opt-in=kotlin.ExperimentalStdlibApi',
|
'-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',
|
||||||
'-opt-in=coil.annotation.ExperimentalCoilApi',
|
'-opt-in=coil.annotation.ExperimentalCoilApi',
|
||||||
'-opt-in=com.google.android.material.badge.ExperimentalBadgeUtils',
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
lint {
|
lint {
|
||||||
abortOnError false
|
abortOnError true
|
||||||
disable 'MissingTranslation', 'PrivateResource', 'NotifyDataSetChanged'
|
disable 'MissingTranslation', 'PrivateResource', 'NotifyDataSetChanged'
|
||||||
}
|
}
|
||||||
testOptions {
|
testOptions {
|
||||||
@@ -84,35 +77,43 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation('com.github.KotatsuApp:kotatsu-parsers:7f630184c0') {
|
//noinspection GradleDependency
|
||||||
|
implementation('com.github.KotatsuApp:kotatsu-parsers:ebcc6391d6') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.0'
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.21'
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1'
|
||||||
|
|
||||||
implementation "androidx.appcompat:appcompat:1.6.0"
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.core:core-ktx:1.9.0'
|
implementation 'androidx.core:core-ktx:1.10.1'
|
||||||
implementation 'androidx.activity:activity-ktx:1.6.1'
|
implementation 'androidx.activity:activity-ktx:1.7.1'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.5.5'
|
implementation 'androidx.fragment:fragment-ktx:1.5.7'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-service:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-service:2.6.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-process:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-process:2.6.1'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
implementation 'androidx.recyclerview:recyclerview:1.3.0'
|
||||||
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.biometric:biometric-ktx:1.2.0-alpha05'
|
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
||||||
implementation 'com.google.android.material:material:1.8.0'
|
implementation 'com.google.android.material:material:1.9.0'
|
||||||
//noinspection LifecycleAnnotationProcessorWithJava8
|
//noinspection LifecycleAnnotationProcessorWithJava8
|
||||||
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.1'
|
kapt 'androidx.lifecycle:lifecycle-compiler:2.6.1'
|
||||||
|
|
||||||
implementation 'androidx.room:room-runtime:2.5.0'
|
implementation 'androidx.work:work-runtime-ktx:2.8.1'
|
||||||
implementation 'androidx.room:room-ktx:2.5.0'
|
//noinspection GradleDependency
|
||||||
kapt 'androidx.room:room-compiler:2.5.0'
|
implementation('com.google.guava:guava:31.1-android') {
|
||||||
|
exclude group: 'com.google.guava', module: 'failureaccess'
|
||||||
|
exclude group: 'org.checkerframework', module: 'checker-qual'
|
||||||
|
exclude group: 'com.google.j2objc', module: 'j2objc-annotations'
|
||||||
|
}
|
||||||
|
|
||||||
|
implementation 'androidx.room:room-runtime:2.5.1'
|
||||||
|
implementation 'androidx.room:room-ktx:2.5.1'
|
||||||
|
kapt 'androidx.room:room-compiler:2.5.1'
|
||||||
|
|
||||||
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'
|
||||||
@@ -121,13 +122,13 @@ dependencies {
|
|||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
||||||
|
|
||||||
implementation 'com.google.dagger:hilt-android:2.44.2'
|
implementation 'com.google.dagger:hilt-android:2.46.1'
|
||||||
kapt 'com.google.dagger:hilt-compiler:2.44.2'
|
kapt 'com.google.dagger:hilt-compiler:2.46.1'
|
||||||
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.3.0'
|
||||||
implementation 'io.coil-kt:coil-svg:2.2.2'
|
implementation 'io.coil-kt:coil-svg:2.3.0'
|
||||||
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:1b19231b2f'
|
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 'io.noties.markwon:core:4.6.2'
|
||||||
@@ -138,19 +139,19 @@ dependencies {
|
|||||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
|
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:20230227'
|
||||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.test:runner:1.5.2'
|
androidTestImplementation 'androidx.test:runner:1.5.2'
|
||||||
androidTestImplementation 'androidx.test:rules:1.5.0'
|
androidTestImplementation 'androidx.test:rules:1.5.0'
|
||||||
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
|
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
|
||||||
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5'
|
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.7.1'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.room:room-testing:2.5.0'
|
androidTestImplementation 'androidx.room:room-testing:2.5.1'
|
||||||
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
|
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.15.0'
|
||||||
|
|
||||||
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.44.2'
|
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.46.1'
|
||||||
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.44.2'
|
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.46.1'
|
||||||
}
|
}
|
||||||
|
|||||||
5
app/proguard-rules.pro
vendored
@@ -10,7 +10,10 @@
|
|||||||
}
|
}
|
||||||
-keep public class ** extends org.koitharu.kotatsu.base.ui.BaseFragment
|
-keep public class ** extends org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
-keep class org.koitharu.kotatsu.core.db.entity.* { *; }
|
-keep class org.koitharu.kotatsu.core.db.entity.* { *; }
|
||||||
-dontwarn okhttp3.internal.platform.ConscryptPlatform
|
-dontwarn okhttp3.internal.platform.**
|
||||||
|
-dontwarn org.conscrypt.**
|
||||||
|
-dontwarn org.bouncycastle.**
|
||||||
|
-dontwarn org.openjsse.**
|
||||||
|
|
||||||
-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
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 213 KiB |
|
Before Width: | Height: | Size: 131 KiB |
|
Before Width: | Height: | Size: 439 KiB |
|
Before Width: | Height: | Size: 495 KiB |
|
Before Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 791 KiB |
|
Before Width: | Height: | Size: 844 KiB |
|
Before Width: | Height: | Size: 386 KiB |
|
Before Width: | Height: | Size: 375 KiB |
|
Before Width: | Height: | Size: 398 KiB |
@@ -1,10 +0,0 @@
|
|||||||
Slice of Life, Mystery
|
|
||||||
Slice of Life, Mystery
|
|
||||||
Psychological, Romance, Comedy, Slice of Life, Supernatural
|
|
||||||
Sci-Fi, Comedy
|
|
||||||
Reincarnation, Sci-Fi, Historical, Psychological, Drama, Slice of Life, Supernatural, Mystery
|
|
||||||
Reincarnation, Sci-Fi, Historical, Psychological, Drama, Slice of Life, Supernatural, Mystery
|
|
||||||
Reincarnation, Sci-Fi, Historical, Psychological, Drama, Slice of Life, Supernatural, Mystery
|
|
||||||
Reincarnation, Sci-Fi, Historical, Psychological, Drama, Slice of Life, Supernatural, Mystery
|
|
||||||
Adventure, Slice of Life, Mystery
|
|
||||||
Adventure, Slice of Life, Mystery
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
Forget-me-not Vol. 1
|
|
||||||
Forget-me-not Vol. 2
|
|
||||||
La Pomme Prisoinniere
|
|
||||||
Momo Kanchou no Himitsu Kichi
|
|
||||||
Omoide Emanon
|
|
||||||
Sasurai Emanon Vol. 1
|
|
||||||
Sasurai Emanon Vol. 2
|
|
||||||
Sasurai Emanon Vol. 3
|
|
||||||
Wandering Island Vol. 1
|
|
||||||
Wandering Island Vol. 2
|
|
||||||
@@ -5,8 +5,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
|
|||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import dagger.hilt.android.testing.HiltAndroidRule
|
import dagger.hilt.android.testing.HiltAndroidRule
|
||||||
import dagger.hilt.android.testing.HiltAndroidTest
|
import dagger.hilt.android.testing.HiltAndroidTest
|
||||||
import java.io.File
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
@@ -20,6 +18,8 @@ import org.koitharu.kotatsu.core.db.MangaDatabase
|
|||||||
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||||
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
|
import java.io.File
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltAndroidTest
|
@HiltAndroidTest
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@@ -52,6 +52,7 @@ class AppBackupAgentTest {
|
|||||||
title = SampleData.favouriteCategory.title,
|
title = SampleData.favouriteCategory.title,
|
||||||
sortOrder = SampleData.favouriteCategory.order,
|
sortOrder = SampleData.favouriteCategory.order,
|
||||||
isTrackerEnabled = SampleData.favouriteCategory.isTrackingEnabled,
|
isTrackerEnabled = SampleData.favouriteCategory.isTrackingEnabled,
|
||||||
|
isVisibleOnShelf = SampleData.favouriteCategory.isVisibleInLibrary,
|
||||||
)
|
)
|
||||||
favouritesRepository.addToCategory(categoryId = category.id, mangas = listOf(SampleData.manga))
|
favouritesRepository.addToCategory(categoryId = category.id, mangas = listOf(SampleData.manga))
|
||||||
historyRepository.addOrUpdate(
|
historyRepository.addOrUpdate(
|
||||||
|
|||||||
@@ -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,4 @@
|
|||||||
<?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>
|
</resources>
|
||||||
|
|||||||
6
app/src/debug/res/values/constants.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="account_type_sync" translatable="false">org.kotatsu.debug.sync</string>
|
||||||
|
<string name="sync_authority_history" translatable="false">org.koitharu.kotatsu.debug.history</string>
|
||||||
|
<string name="sync_authority_favourites" translatable="false">org.koitharu.kotatsu.debug.favourites</string>
|
||||||
|
</resources>
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
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"
|
||||||
@@ -93,6 +94,8 @@
|
|||||||
<category android:name="android.intent.category.BROWSABLE" />
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
<data android:scheme="kotatsu" />
|
<data android:scheme="kotatsu" />
|
||||||
|
<data android:host="about" />
|
||||||
|
<data android:host="sync-settings" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
@@ -126,7 +129,7 @@
|
|||||||
android:name="org.koitharu.kotatsu.settings.protect.ProtectSetupActivity"
|
android:name="org.koitharu.kotatsu.settings.protect.ProtectSetupActivity"
|
||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.download.ui.DownloadsActivity"
|
android:name="org.koitharu.kotatsu.download.ui.list.DownloadsActivity"
|
||||||
android:label="@string/downloads"
|
android:label="@string/downloads"
|
||||||
android:launchMode="singleTop" />
|
android:launchMode="singleTop" />
|
||||||
<activity android:name="org.koitharu.kotatsu.image.ui.ImageActivity" />
|
<activity android:name="org.koitharu.kotatsu.image.ui.ImageActivity" />
|
||||||
@@ -140,13 +143,27 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.shelf.ui.config.ShelfSettingsActivity"
|
android:name="org.koitharu.kotatsu.shelf.ui.config.ShelfSettingsActivity"
|
||||||
android:label="@string/settings" />
|
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" />
|
||||||
|
<data android:host="shikimori-auth" />
|
||||||
|
<data android:host="anilist-auth" />
|
||||||
|
<data android:host="mal-auth" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
</activity>
|
||||||
|
|
||||||
<service
|
|
||||||
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"
|
|
||||||
android:foregroundServiceType="dataSync"
|
|
||||||
android:stopWithTask="false" />
|
|
||||||
<service android:name="org.koitharu.kotatsu.local.ui.LocalChaptersRemoveService" />
|
<service android:name="org.koitharu.kotatsu.local.ui.LocalChaptersRemoveService" />
|
||||||
<service android:name="org.koitharu.kotatsu.local.ui.ImportService" />
|
|
||||||
<service
|
<service
|
||||||
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetService"
|
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetService"
|
||||||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||||
@@ -207,20 +224,26 @@
|
|||||||
</provider>
|
</provider>
|
||||||
<provider
|
<provider
|
||||||
android:name="org.koitharu.kotatsu.sync.ui.favourites.FavouritesSyncProvider"
|
android:name="org.koitharu.kotatsu.sync.ui.favourites.FavouritesSyncProvider"
|
||||||
android:authorities="org.koitharu.kotatsu.favourites"
|
android:authorities="@string/sync_authority_favourites"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/favourites"
|
android:label="@string/favourites"
|
||||||
android:syncable="true" />
|
android:syncable="true" />
|
||||||
<provider
|
<provider
|
||||||
android:name="org.koitharu.kotatsu.sync.ui.history.HistorySyncProvider"
|
android:name="org.koitharu.kotatsu.sync.ui.history.HistorySyncProvider"
|
||||||
android:authorities="org.koitharu.kotatsu.history"
|
android:authorities="@string/sync_authority_history"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/history"
|
android:label="@string/history"
|
||||||
android:syncable="true" />
|
android:syncable="true" />
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.startup.InitializationProvider"
|
android:name="androidx.startup.InitializationProvider"
|
||||||
android:authorities="${applicationId}.androidx-startup"
|
android:authorities="${applicationId}.androidx-startup"
|
||||||
tools:node="remove" />
|
android:exported="false"
|
||||||
|
tools:node="remove">
|
||||||
|
<meta-data
|
||||||
|
android:name="androidx.work.WorkManagerInitializer"
|
||||||
|
android:value="androidx.startup"
|
||||||
|
tools:node="remove" />
|
||||||
|
</provider>
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetProvider"
|
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetProvider"
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
|
|||||||
import org.koitharu.kotatsu.local.data.PagesCache
|
import org.koitharu.kotatsu.local.data.PagesCache
|
||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
|
import org.koitharu.kotatsu.utils.WorkServiceStopHelper
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -55,6 +57,7 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
processLifecycleScope.launch(Dispatchers.Default) {
|
processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
setupDatabaseObservers()
|
setupDatabaseObservers()
|
||||||
}
|
}
|
||||||
|
WorkServiceStopHelper(applicationContext).setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun attachBaseContext(base: Context?) {
|
override fun attachBaseContext(base: Context?) {
|
||||||
@@ -125,6 +128,7 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
.setClassInstanceLimit(LocalMangaRepository::class.java, 1)
|
.setClassInstanceLimit(LocalMangaRepository::class.java, 1)
|
||||||
.setClassInstanceLimit(PagesCache::class.java, 1)
|
.setClassInstanceLimit(PagesCache::class.java, 1)
|
||||||
.setClassInstanceLimit(MangaLoaderContext::class.java, 1)
|
.setClassInstanceLimit(MangaLoaderContext::class.java, 1)
|
||||||
|
.setClassInstanceLimit(PageLoader::class.java, 1)
|
||||||
.penaltyLog()
|
.penaltyLog()
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,11 +4,7 @@ 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 dagger.Reusable
|
||||||
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 +13,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,9 +27,15 @@ 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
|
||||||
|
|
||||||
|
@Reusable
|
||||||
class MangaDataRepository @Inject constructor(
|
class MangaDataRepository @Inject constructor(
|
||||||
private val okHttpClient: OkHttpClient,
|
private val okHttpClient: OkHttpClient,
|
||||||
private val db: MangaDatabase,
|
private val db: MangaDatabase,
|
||||||
@@ -121,8 +127,8 @@ 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_NO_STORE)
|
||||||
.build()
|
.build()
|
||||||
okHttpClient.newCall(request).await().use {
|
okHttpClient.newCall(request).await().use {
|
||||||
runInterruptible(Dispatchers.IO) {
|
runInterruptible(Dispatchers.IO) {
|
||||||
|
|||||||
@@ -3,15 +3,17 @@ package org.koitharu.kotatsu.base.domain
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.lifecycle.SavedStateHandle
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.utils.ext.getParcelableCompat
|
import org.koitharu.kotatsu.utils.ext.getParcelableCompat
|
||||||
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
|
||||||
class MangaIntent private constructor(
|
class MangaIntent private constructor(
|
||||||
val manga: Manga?,
|
@JvmField val manga: Manga?,
|
||||||
val mangaId: Long,
|
@JvmField val mangaId: Long,
|
||||||
val uri: Uri?,
|
@JvmField val uri: Uri?,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
constructor(intent: Intent?) : this(
|
constructor(intent: Intent?) : this(
|
||||||
@@ -20,6 +22,12 @@ class MangaIntent private constructor(
|
|||||||
uri = intent?.data,
|
uri = intent?.data,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
constructor(savedStateHandle: SavedStateHandle) : this(
|
||||||
|
manga = savedStateHandle.get<ParcelableManga>(KEY_MANGA)?.manga,
|
||||||
|
mangaId = savedStateHandle[KEY_ID] ?: ID_NONE,
|
||||||
|
uri = savedStateHandle[BaseActivity.EXTRA_DATA],
|
||||||
|
)
|
||||||
|
|
||||||
constructor(args: Bundle?) : this(
|
constructor(args: Bundle?) : this(
|
||||||
manga = args?.getParcelableCompat<ParcelableManga>(KEY_MANGA)?.manga,
|
manga = args?.getParcelableCompat<ParcelableManga>(KEY_MANGA)?.manga,
|
||||||
mangaId = args?.getLong(KEY_ID, ID_NONE) ?: ID_NONE,
|
mangaId = args?.getLong(KEY_ID, ID_NONE) ?: ID_NONE,
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.base.ui
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
import android.graphics.Color
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
@@ -12,6 +14,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
|
||||||
@@ -25,42 +28,51 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
||||||
import org.koitharu.kotatsu.base.ui.util.BaseActivityEntryPoint
|
import org.koitharu.kotatsu.base.ui.util.BaseActivityEntryPoint
|
||||||
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
||||||
import org.koitharu.kotatsu.base.ui.util.inject
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
|
@Suppress("LeakingThis")
|
||||||
abstract class BaseActivity<B : ViewBinding> :
|
abstract class BaseActivity<B : ViewBinding> :
|
||||||
AppCompatActivity(),
|
AppCompatActivity(),
|
||||||
WindowInsetsDelegate.WindowInsetsListener {
|
WindowInsetsDelegate.WindowInsetsListener {
|
||||||
|
|
||||||
@Inject
|
private var isAmoledTheme = false
|
||||||
lateinit var settings: AppSettings
|
|
||||||
|
|
||||||
protected lateinit var binding: B
|
protected lateinit var binding: B
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@JvmField
|
||||||
protected val exceptionResolver = ExceptionResolver(this)
|
protected val exceptionResolver = ExceptionResolver(this)
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@JvmField
|
||||||
protected val insetsDelegate = WindowInsetsDelegate(this)
|
protected val insetsDelegate = WindowInsetsDelegate(this)
|
||||||
|
|
||||||
|
@JvmField
|
||||||
val actionModeDelegate = ActionModeDelegate()
|
val actionModeDelegate = ActionModeDelegate()
|
||||||
|
|
||||||
|
private var defaultStatusBarColor = Color.TRANSPARENT
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
EntryPointAccessors.fromApplication(this, BaseActivityEntryPoint::class.java).inject(this)
|
val settings = EntryPointAccessors.fromApplication(this, BaseActivityEntryPoint::class.java).settings
|
||||||
val isAmoled = settings.isAmoledTheme
|
isAmoledTheme = settings.isAmoledTheme
|
||||||
val isDynamic = settings.isDynamicTheme
|
setTheme(settings.colorScheme.styleResId)
|
||||||
when {
|
if (isAmoledTheme) {
|
||||||
isAmoled && isDynamic -> setTheme(R.style.Theme_Kotatsu_Monet_Amoled)
|
setTheme(R.style.ThemeOverlay_Kotatsu_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)
|
||||||
insetsDelegate.handleImeInsets = true
|
insetsDelegate.handleImeInsets = true
|
||||||
|
putDataToExtras(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onPostCreate(savedInstanceState)
|
||||||
|
onBackPressedDispatcher.addCallback(actionModeDelegate)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent?) {
|
||||||
|
putDataToExtras(intent)
|
||||||
|
super.onNewIntent(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Use ViewBinding", level = DeprecationLevel.ERROR)
|
@Deprecated("Use ViewBinding", level = DeprecationLevel.ERROR)
|
||||||
@@ -84,14 +96,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)
|
||||||
@@ -104,17 +116,21 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
protected fun isDarkAmoledTheme(): Boolean {
|
protected fun isDarkAmoledTheme(): Boolean {
|
||||||
val uiMode = resources.configuration.uiMode
|
val uiMode = resources.configuration.uiMode
|
||||||
val isNight = uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
val isNight = uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
||||||
return isNight && settings.isAmoledTheme
|
return isNight && isAmoledTheme
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onSupportActionModeStarted(mode: ActionMode) {
|
override fun onSupportActionModeStarted(mode: ActionMode) {
|
||||||
super.onSupportActionModeStarted(mode)
|
super.onSupportActionModeStarted(mode)
|
||||||
actionModeDelegate.onSupportActionModeStarted(mode)
|
actionModeDelegate.onSupportActionModeStarted(mode)
|
||||||
val actionModeColor = ColorUtils.compositeColors(
|
val actionModeColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
ContextCompat.getColor(this, com.google.android.material.R.color.m3_appbar_overlay_color),
|
ColorUtils.compositeColors(
|
||||||
getThemeColor(com.google.android.material.R.attr.colorSurface),
|
ContextCompat.getColor(this, com.google.android.material.R.color.m3_appbar_overlay_color),
|
||||||
)
|
getThemeColor(com.google.android.material.R.attr.colorSurface),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
ContextCompat.getColor(this, R.color.kotatsu_secondaryContainer)
|
||||||
|
}
|
||||||
val insets = ViewCompat.getRootWindowInsets(binding.root)
|
val insets = ViewCompat.getRootWindowInsets(binding.root)
|
||||||
?.getInsets(WindowInsetsCompat.Type.systemBars()) ?: return
|
?.getInsets(WindowInsetsCompat.Type.systemBars()) ?: return
|
||||||
findViewById<ActionBarContextView?>(androidx.appcompat.R.id.action_mode_bar).apply {
|
findViewById<ActionBarContextView?>(androidx.appcompat.R.id.action_mode_bar).apply {
|
||||||
@@ -123,6 +139,7 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
topMargin = insets.top
|
topMargin = insets.top
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
defaultStatusBarColor = window.statusBarColor
|
||||||
window.statusBarColor = actionModeColor
|
window.statusBarColor = actionModeColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,19 +147,15 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
override fun onSupportActionModeFinished(mode: ActionMode) {
|
override fun onSupportActionModeFinished(mode: ActionMode) {
|
||||||
super.onSupportActionModeFinished(mode)
|
super.onSupportActionModeFinished(mode)
|
||||||
actionModeDelegate.onSupportActionModeFinished(mode)
|
actionModeDelegate.onSupportActionModeFinished(mode)
|
||||||
window.statusBarColor = getThemeColor(android.R.attr.statusBarColor)
|
window.statusBarColor = defaultStatusBarColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
|
private fun putDataToExtras(intent: Intent?) {
|
||||||
override fun onBackPressed() {
|
intent?.putExtra(EXTRA_DATA, intent.data)
|
||||||
if ( // https://issuetracker.google.com/issues/139738913
|
}
|
||||||
Build.VERSION.SDK_INT == Build.VERSION_CODES.Q &&
|
|
||||||
isTaskRoot &&
|
companion object {
|
||||||
supportFragmentManager.backStackEntryCount == 0
|
|
||||||
) {
|
const val EXTRA_DATA = "data"
|
||||||
finishAfterTransition()
|
|
||||||
} else {
|
|
||||||
super.onBackPressed()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,21 @@ package org.koitharu.kotatsu.base.ui
|
|||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.DisplayMetrics
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.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.findActivity
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplaySize
|
||||||
|
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?,
|
||||||
@@ -34,21 +41,20 @@ abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
|||||||
): View {
|
): View {
|
||||||
val binding = onInflateView(inflater, container)
|
val binding = onInflateView(inflater, container)
|
||||||
viewBinding = binding
|
viewBinding = binding
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
// Enforce max width for tablets
|
// Enforce max width for tablets
|
||||||
val width = resources.getDimensionPixelSize(R.dimen.bottom_sheet_width)
|
val width = resources.getDimensionPixelSize(R.dimen.bottom_sheet_width)
|
||||||
if (width > 0) {
|
if (width > 0) {
|
||||||
behavior?.maxWidth = width
|
behavior?.maxWidth = width
|
||||||
}
|
}
|
||||||
|
// Set peek height to 40% display height
|
||||||
// Set peek height to 50% display height
|
binding.root.context.findActivity()?.getDisplaySize()?.let {
|
||||||
requireContext().displayCompat?.let {
|
behavior?.peekHeight = (it.height() * 0.4).toInt()
|
||||||
val metrics = DisplayMetrics()
|
|
||||||
it.getRealMetrics(metrics)
|
|
||||||
behavior?.peekHeight = (metrics.heightPixels * 0.4).toInt()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return binding.root
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
|||||||
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
|
||||||
|
@Suppress("LeakingThis")
|
||||||
abstract class BaseFragment<B : ViewBinding> :
|
abstract class BaseFragment<B : ViewBinding> :
|
||||||
Fragment(),
|
Fragment(),
|
||||||
WindowInsetsDelegate.WindowInsetsListener {
|
WindowInsetsDelegate.WindowInsetsListener {
|
||||||
@@ -19,10 +20,10 @@ abstract class BaseFragment<B : ViewBinding> :
|
|||||||
protected val binding: B
|
protected val binding: B
|
||||||
get() = checkNotNull(viewBinding)
|
get() = checkNotNull(viewBinding)
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@JvmField
|
||||||
protected val exceptionResolver = ExceptionResolver(this)
|
protected val exceptionResolver = ExceptionResolver(this)
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@JvmField
|
||||||
protected val insetsDelegate = WindowInsetsDelegate(this)
|
protected val insetsDelegate = WindowInsetsDelegate(this)
|
||||||
|
|
||||||
protected val actionModeDelegate: ActionModeDelegate
|
protected val actionModeDelegate: ActionModeDelegate
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ import androidx.core.view.updatePadding
|
|||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
||||||
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.settings.SettingsHeadersFragment
|
import org.koitharu.kotatsu.settings.SettingsHeadersFragment
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@Suppress("LeakingThis")
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
||||||
PreferenceFragmentCompat(),
|
PreferenceFragmentCompat(),
|
||||||
@@ -24,7 +25,7 @@ abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var settings: AppSettings
|
lateinit var settings: AppSettings
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@JvmField
|
||||||
protected val insetsDelegate = WindowInsetsDelegate(this)
|
protected val insetsDelegate = WindowInsetsDelegate(this)
|
||||||
|
|
||||||
override val recyclerView: RecyclerView
|
override val recyclerView: RecyclerView
|
||||||
@@ -55,7 +56,6 @@ abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UsePropertyAccessSyntax")
|
|
||||||
protected fun setTitle(title: CharSequence) {
|
protected fun setTitle(title: CharSequence) {
|
||||||
(parentFragment as? SettingsHeadersFragment)?.setTitle(title)
|
(parentFragment as? SettingsHeadersFragment)?.setTitle(title)
|
||||||
?: activity?.setTitle(title)
|
?: activity?.setTitle(title)
|
||||||
|
|||||||
@@ -3,16 +3,24 @@ package org.koitharu.kotatsu.base.ui
|
|||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlin.coroutines.EmptyCoroutineContext
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.CoroutineStart
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.base.ui.util.CountedBooleanLiveData
|
import org.koitharu.kotatsu.base.ui.util.CountedBooleanLiveData
|
||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
abstract class BaseViewModel : ViewModel() {
|
abstract class BaseViewModel : ViewModel() {
|
||||||
|
|
||||||
|
@JvmField
|
||||||
protected val loadingCounter = CountedBooleanLiveData()
|
protected val loadingCounter = CountedBooleanLiveData()
|
||||||
|
|
||||||
|
@JvmField
|
||||||
protected val errorEvent = SingleLiveEvent<Throwable>()
|
protected val errorEvent = SingleLiveEvent<Throwable>()
|
||||||
|
|
||||||
val onError: LiveData<Throwable>
|
val onError: LiveData<Throwable>
|
||||||
@@ -46,4 +54,4 @@ abstract class BaseViewModel : ViewModel() {
|
|||||||
errorEvent.postCall(throwable)
|
errorEvent.postCall(throwable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.koitharu.kotatsu.base.ui
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
import android.app.Service
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -20,7 +19,7 @@ abstract class CoroutineIntentService : BaseService() {
|
|||||||
final override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
final override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
launchCoroutine(intent, startId)
|
launchCoroutine(intent, startId)
|
||||||
return Service.START_REDELIVER_INTENT
|
return START_REDELIVER_INTENT
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchCoroutine(intent: Intent?, startId: Int) = lifecycleScope.launch(errorHandler(startId)) {
|
private fun launchCoroutine(intent: Intent?, startId: Int) = lifecycleScope.launch(errorHandler(startId)) {
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.dialog
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.AdapterDelegate
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.AdapterDelegatesManager
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.ListDelegationAdapter
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
class RecyclerViewAlertDialog private constructor(
|
||||||
|
private val delegate: AlertDialog
|
||||||
|
) : DialogInterface by delegate {
|
||||||
|
|
||||||
|
fun show() = delegate.show()
|
||||||
|
|
||||||
|
class Builder<T>(context: Context) {
|
||||||
|
|
||||||
|
private val recyclerView = RecyclerView(context)
|
||||||
|
private val delegatesManager = AdapterDelegatesManager<List<T>>()
|
||||||
|
private var items: List<T>? = null
|
||||||
|
|
||||||
|
private val delegate = MaterialAlertDialogBuilder(context)
|
||||||
|
.setView(recyclerView)
|
||||||
|
|
||||||
|
init {
|
||||||
|
recyclerView.layoutManager = LinearLayoutManager(context)
|
||||||
|
recyclerView.updatePadding(
|
||||||
|
top = context.resources.getDimensionPixelOffset(R.dimen.list_spacing),
|
||||||
|
)
|
||||||
|
recyclerView.clipToPadding = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setTitle(@StringRes titleResId: Int): Builder<T> {
|
||||||
|
delegate.setTitle(titleResId)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setTitle(title: CharSequence): Builder<T> {
|
||||||
|
delegate.setTitle(title)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setIcon(@DrawableRes iconId: Int): Builder<T> {
|
||||||
|
delegate.setIcon(iconId)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setPositiveButton(
|
||||||
|
@StringRes textId: Int,
|
||||||
|
listener: DialogInterface.OnClickListener,
|
||||||
|
): Builder<T> {
|
||||||
|
delegate.setPositiveButton(textId, listener)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setNegativeButton(
|
||||||
|
@StringRes textId: Int,
|
||||||
|
listener: DialogInterface.OnClickListener? = null
|
||||||
|
): Builder<T> {
|
||||||
|
delegate.setNegativeButton(textId, listener)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setCancelable(isCancelable: Boolean): Builder<T> {
|
||||||
|
delegate.setCancelable(isCancelable)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addAdapterDelegate(subject: AdapterDelegate<List<T>>): Builder<T> {
|
||||||
|
delegatesManager.addDelegate(subject)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setItems(list: List<T>): Builder<T> {
|
||||||
|
items = list
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun create(): RecyclerViewAlertDialog {
|
||||||
|
recyclerView.adapter = ListDelegationAdapter(delegatesManager).also {
|
||||||
|
it.items = items
|
||||||
|
}
|
||||||
|
return RecyclerViewAlertDialog(delegate.create())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.dialog
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import com.google.android.material.button.MaterialButton
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import org.koitharu.kotatsu.databinding.DialogTwoButtonsBinding
|
||||||
|
|
||||||
|
class TwoButtonsAlertDialog private constructor(
|
||||||
|
private val delegate: AlertDialog
|
||||||
|
) : DialogInterface by delegate {
|
||||||
|
|
||||||
|
fun show() = delegate.show()
|
||||||
|
|
||||||
|
class Builder(context: Context) {
|
||||||
|
|
||||||
|
private val binding = DialogTwoButtonsBinding.inflate(LayoutInflater.from(context))
|
||||||
|
|
||||||
|
private val delegate = MaterialAlertDialogBuilder(context)
|
||||||
|
.setView(binding.root)
|
||||||
|
|
||||||
|
fun setTitle(@StringRes titleResId: Int): Builder {
|
||||||
|
binding.title.setText(titleResId)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setTitle(title: CharSequence): Builder {
|
||||||
|
binding.title.text = title
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setIcon(@DrawableRes iconId: Int): Builder {
|
||||||
|
binding.icon.setImageResource(iconId)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setPositiveButton(
|
||||||
|
@StringRes textId: Int,
|
||||||
|
listener: DialogInterface.OnClickListener,
|
||||||
|
): Builder {
|
||||||
|
initButton(binding.button1, DialogInterface.BUTTON_POSITIVE, textId, listener)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setNegativeButton(
|
||||||
|
@StringRes textId: Int,
|
||||||
|
listener: DialogInterface.OnClickListener? = null
|
||||||
|
): Builder {
|
||||||
|
initButton(binding.button2, DialogInterface.BUTTON_NEGATIVE, textId, listener)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun create(): TwoButtonsAlertDialog {
|
||||||
|
val dialog = delegate.create()
|
||||||
|
binding.root.tag = dialog
|
||||||
|
return TwoButtonsAlertDialog(dialog)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initButton(
|
||||||
|
button: MaterialButton,
|
||||||
|
which: Int,
|
||||||
|
@StringRes textId: Int,
|
||||||
|
listener: DialogInterface.OnClickListener?,
|
||||||
|
) {
|
||||||
|
button.setText(textId)
|
||||||
|
button.isVisible = true
|
||||||
|
button.setOnClickListener {
|
||||||
|
val dialog = binding.root.tag as DialogInterface
|
||||||
|
listener?.onClick(dialog, which)
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,26 +6,27 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
abstract class BoundsScrollListener(private val offsetTop: Int, private val offsetBottom: Int) :
|
abstract class BoundsScrollListener(private val offsetTop: Int, private val offsetBottom: Int) :
|
||||||
RecyclerView.OnScrollListener() {
|
RecyclerView.OnScrollListener() {
|
||||||
|
|
||||||
constructor(offset: Int = 0) : this(offset, offset)
|
|
||||||
|
|
||||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
super.onScrolled(recyclerView, dx, dy)
|
super.onScrolled(recyclerView, dx, dy)
|
||||||
|
if (recyclerView.hasPendingAdapterUpdates()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
val layoutManager = (recyclerView.layoutManager as? LinearLayoutManager) ?: return
|
val layoutManager = (recyclerView.layoutManager as? LinearLayoutManager) ?: return
|
||||||
val firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition()
|
val firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition()
|
||||||
if (firstVisibleItemPosition == RecyclerView.NO_POSITION) {
|
if (firstVisibleItemPosition == RecyclerView.NO_POSITION) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (firstVisibleItemPosition <= offsetTop) {
|
|
||||||
onScrolledToStart(recyclerView)
|
|
||||||
}
|
|
||||||
val visibleItemCount = layoutManager.childCount
|
val visibleItemCount = layoutManager.childCount
|
||||||
val totalItemCount = layoutManager.itemCount
|
val totalItemCount = layoutManager.itemCount
|
||||||
if (visibleItemCount + firstVisibleItemPosition >= totalItemCount - offsetBottom) {
|
if (visibleItemCount + firstVisibleItemPosition >= totalItemCount - offsetBottom) {
|
||||||
onScrolledToEnd(recyclerView)
|
onScrolledToEnd(recyclerView)
|
||||||
}
|
}
|
||||||
|
if (firstVisibleItemPosition <= offsetTop) {
|
||||||
|
onScrolledToStart(recyclerView)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun onScrolledToStart(recyclerView: RecyclerView)
|
abstract fun onScrolledToStart(recyclerView: RecyclerView)
|
||||||
|
|
||||||
abstract fun onScrolledToEnd(recyclerView: RecyclerView)
|
abstract fun onScrolledToEnd(recyclerView: RecyclerView)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.Parcelable
|
||||||
|
import android.util.SparseArray
|
||||||
|
import androidx.core.os.BundleCompat
|
||||||
|
import androidx.core.view.doOnNextLayout
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import java.util.Collections
|
||||||
|
import java.util.WeakHashMap
|
||||||
|
|
||||||
|
class NestedScrollStateHandle(
|
||||||
|
savedInstanceState: Bundle?,
|
||||||
|
private val key: String,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val storage: SparseArray<Parcelable?> = savedInstanceState?.let {
|
||||||
|
BundleCompat.getSparseParcelableArray(it, key, Parcelable::class.java)
|
||||||
|
} ?: SparseArray<Parcelable?>()
|
||||||
|
private val controllers = Collections.newSetFromMap<Controller>(WeakHashMap())
|
||||||
|
|
||||||
|
fun attach(recycler: RecyclerView) = Controller(recycler).also(controllers::add)
|
||||||
|
|
||||||
|
fun onSaveInstanceState(outState: Bundle) {
|
||||||
|
controllers.forEach {
|
||||||
|
it.saveState()
|
||||||
|
}
|
||||||
|
outState.putSparseParcelableArray(key, storage)
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class Controller(
|
||||||
|
private val recycler: RecyclerView
|
||||||
|
) {
|
||||||
|
|
||||||
|
private var lastPosition: Int = -1
|
||||||
|
|
||||||
|
fun onBind(position: Int) {
|
||||||
|
if (position != lastPosition) {
|
||||||
|
saveState()
|
||||||
|
lastPosition = position
|
||||||
|
storage[position]?.let {
|
||||||
|
restoreState(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onRecycled() {
|
||||||
|
saveState()
|
||||||
|
lastPosition = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveState() {
|
||||||
|
if (lastPosition != -1) {
|
||||||
|
storage[lastPosition] = recycler.layoutManager?.onSaveInstanceState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun restoreState(state: Parcelable) {
|
||||||
|
recycler.doOnNextLayout {
|
||||||
|
recycler.layoutManager?.onRestoreInstanceState(state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,9 @@ package org.koitharu.kotatsu.base.ui.list
|
|||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
||||||
interface OnListItemClickListener<I> {
|
fun interface OnListItemClickListener<I> {
|
||||||
|
|
||||||
fun onItemClick(item: I, view: View)
|
fun onItemClick(item: I, view: View)
|
||||||
|
|
||||||
fun onItemLongClick(item: I, view: View) = false
|
fun onItemLongClick(item: I, view: View) = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
|
interface OnTipCloseListener<T> {
|
||||||
|
|
||||||
|
fun onCloseTip(tip: T)
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
|
class ScrollListenerInvalidationObserver(
|
||||||
|
private val recyclerView: RecyclerView,
|
||||||
|
private val scrollListener: RecyclerView.OnScrollListener,
|
||||||
|
) : RecyclerView.AdapterDataObserver() {
|
||||||
|
|
||||||
|
override fun onChanged() {
|
||||||
|
super.onChanged()
|
||||||
|
invalidateScroll()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||||
|
super.onItemRangeInserted(positionStart, itemCount)
|
||||||
|
invalidateScroll()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||||
|
super.onItemRangeRemoved(positionStart, itemCount)
|
||||||
|
invalidateScroll()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun invalidateScroll() {
|
||||||
|
recyclerView.post {
|
||||||
|
scrollListener.onScrolled(recyclerView, 0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
|
||||||
class ActionModeDelegate {
|
class ActionModeDelegate : OnBackPressedCallback(false) {
|
||||||
|
|
||||||
private var activeActionMode: ActionMode? = null
|
private var activeActionMode: ActionMode? = null
|
||||||
private var listeners: MutableList<ActionModeListener>? = null
|
private var listeners: MutableList<ActionModeListener>? = null
|
||||||
@@ -12,13 +13,19 @@ class ActionModeDelegate {
|
|||||||
val isActionModeStarted: Boolean
|
val isActionModeStarted: Boolean
|
||||||
get() = activeActionMode != null
|
get() = activeActionMode != null
|
||||||
|
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
activeActionMode?.finish()
|
||||||
|
}
|
||||||
|
|
||||||
fun onSupportActionModeStarted(mode: ActionMode) {
|
fun onSupportActionModeStarted(mode: ActionMode) {
|
||||||
activeActionMode = mode
|
activeActionMode = mode
|
||||||
|
isEnabled = true
|
||||||
listeners?.forEach { it.onActionModeStarted(mode) }
|
listeners?.forEach { it.onActionModeStarted(mode) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onSupportActionModeFinished(mode: ActionMode) {
|
fun onSupportActionModeFinished(mode: ActionMode) {
|
||||||
activeActionMode = null
|
activeActionMode = null
|
||||||
|
isEnabled = false
|
||||||
listeners?.forEach { it.onActionModeFinished(mode) }
|
listeners?.forEach { it.onActionModeFinished(mode) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,4 +54,4 @@ class ActionModeDelegate {
|
|||||||
removeListener(listener)
|
removeListener(listener)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.base.ui.util
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
import org.koitharu.kotatsu.base.ui.DefaultActivityLifecycleCallbacks
|
import org.koitharu.kotatsu.base.ui.DefaultActivityLifecycleCallbacks
|
||||||
import java.util.WeakHashMap
|
import java.util.WeakHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -22,6 +23,6 @@ class ActivityRecreationHandle @Inject constructor() : DefaultActivityLifecycleC
|
|||||||
|
|
||||||
fun recreateAll() {
|
fun recreateAll() {
|
||||||
val snapshot = activities.keys.toList()
|
val snapshot = activities.keys.toList()
|
||||||
snapshot.forEach { it.recreate() }
|
snapshot.forEach { ActivityCompat.recreate(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.koitharu.kotatsu.base.ui.util
|
|||||||
import dagger.hilt.EntryPoint
|
import dagger.hilt.EntryPoint
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import org.koitharu.kotatsu.base.ui.BaseActivity
|
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
|
||||||
@EntryPoint
|
@EntryPoint
|
||||||
@@ -11,8 +10,3 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
|
|||||||
interface BaseActivityEntryPoint {
|
interface BaseActivityEntryPoint {
|
||||||
val settings: AppSettings
|
val settings: AppSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hilt cannot inject into parametrized classes
|
|
||||||
fun BaseActivityEntryPoint.inject(activity: BaseActivity<*>) {
|
|
||||||
activity.settings = settings
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import android.text.Editable
|
||||||
|
import android.text.TextWatcher
|
||||||
|
|
||||||
|
interface DefaultTextWatcher : TextWatcher {
|
||||||
|
|
||||||
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit
|
||||||
|
|
||||||
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) = Unit
|
||||||
|
|
||||||
|
override fun afterTextChanged(s: Editable?) = Unit
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.domain.reverseAsync
|
||||||
|
|
||||||
|
class ReversibleActionObserver(
|
||||||
|
private val snackbarHost: View,
|
||||||
|
) : Observer<ReversibleAction?> {
|
||||||
|
|
||||||
|
override fun onChanged(value: ReversibleAction?) {
|
||||||
|
if (value == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val handle = value.handle
|
||||||
|
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
||||||
|
val snackbar = Snackbar.make(snackbarHost, value.stringResId, length)
|
||||||
|
if (handle != null) {
|
||||||
|
snackbar.setAction(R.string.undo) { handle.reverseAsync() }
|
||||||
|
}
|
||||||
|
snackbar.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,9 +10,7 @@ import com.google.android.material.floatingactionbutton.ExtendedFloatingActionBu
|
|||||||
|
|
||||||
open class ShrinkOnScrollBehavior : Behavior<ExtendedFloatingActionButton> {
|
open class ShrinkOnScrollBehavior : Behavior<ExtendedFloatingActionButton> {
|
||||||
|
|
||||||
@Suppress("unused")
|
|
||||||
constructor() : super()
|
constructor() : super()
|
||||||
@Suppress("unused")
|
|
||||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
||||||
|
|
||||||
override fun onStartNestedScroll(
|
override fun onStartNestedScroll(
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,8 +10,10 @@ class WindowInsetsDelegate(
|
|||||||
private val listener: WindowInsetsListener,
|
private val listener: WindowInsetsListener,
|
||||||
) : OnApplyWindowInsetsListener, View.OnLayoutChangeListener {
|
) : OnApplyWindowInsetsListener, View.OnLayoutChangeListener {
|
||||||
|
|
||||||
|
@JvmField
|
||||||
var handleImeInsets: Boolean = false
|
var handleImeInsets: Boolean = false
|
||||||
|
|
||||||
|
@JvmField
|
||||||
var interceptingWindowInsetsListener: OnApplyWindowInsetsListener? = null
|
var interceptingWindowInsetsListener: OnApplyWindowInsetsListener? = null
|
||||||
|
|
||||||
private var lastInsets: Insets? = null
|
private var lastInsets: Insets? = null
|
||||||
@@ -63,4 +65,4 @@ class WindowInsetsDelegate(
|
|||||||
|
|
||||||
fun onWindowInsetsChanged(insets: Insets)
|
fun onWindowInsetsChanged(insets: Insets)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,17 +1,20 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.res.ColorStateList
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View.OnClickListener
|
import android.view.View.OnClickListener
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.ColorRes
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.content.res.getColorStateListOrThrow
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.google.android.material.chip.ChipDrawable
|
import com.google.android.material.chip.ChipDrawable
|
||||||
import com.google.android.material.chip.ChipGroup
|
import com.google.android.material.chip.ChipGroup
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.utils.ext.castOrNull
|
import org.koitharu.kotatsu.utils.ext.castOrNull
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeColorStateList
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
class ChipsView @JvmOverloads constructor(
|
class ChipsView @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
@@ -27,6 +30,9 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
private val chipOnCloseListener = OnClickListener {
|
private val chipOnCloseListener = OnClickListener {
|
||||||
onChipCloseClickListener?.onChipCloseClick(it as Chip, it.tag)
|
onChipCloseClickListener?.onChipCloseClick(it as Chip, it.tag)
|
||||||
}
|
}
|
||||||
|
private val defaultChipStrokeColor: ColorStateList
|
||||||
|
private val defaultChipTextColor: ColorStateList
|
||||||
|
private val defaultChipIconTint: ColorStateList
|
||||||
var onChipClickListener: OnChipClickListener? = null
|
var onChipClickListener: OnChipClickListener? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
@@ -40,6 +46,15 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
children.forEach { (it as? Chip)?.isCloseIconVisible = isCloseIconVisible }
|
children.forEach { (it as? Chip)?.isCloseIconVisible = isCloseIconVisible }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
@SuppressLint("CustomViewStyleable")
|
||||||
|
val a = context.obtainStyledAttributes(null, materialR.styleable.Chip, 0, R.style.Widget_Kotatsu_Chip)
|
||||||
|
defaultChipStrokeColor = a.getColorStateListOrThrow(materialR.styleable.Chip_chipStrokeColor)
|
||||||
|
defaultChipTextColor = a.getColorStateListOrThrow(materialR.styleable.Chip_android_textColor)
|
||||||
|
defaultChipIconTint = a.getColorStateListOrThrow(materialR.styleable.Chip_chipIconTint)
|
||||||
|
a.recycle()
|
||||||
|
}
|
||||||
|
|
||||||
override fun requestLayout() {
|
override fun requestLayout() {
|
||||||
if (isLayoutSuppressedCompat) {
|
if (isLayoutSuppressedCompat) {
|
||||||
isLayoutCalledOnSuppressed = true
|
isLayoutCalledOnSuppressed = true
|
||||||
@@ -75,12 +90,15 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
|
|
||||||
private fun bindChip(chip: Chip, model: ChipModel) {
|
private fun bindChip(chip: Chip, model: ChipModel) {
|
||||||
chip.text = model.title
|
chip.text = model.title
|
||||||
if (model.icon == 0) {
|
val tint = if (model.tint == 0) {
|
||||||
chip.isChipIconVisible = false
|
null
|
||||||
} else {
|
} else {
|
||||||
chip.isChipIconVisible = true
|
ContextCompat.getColorStateList(context, model.tint)
|
||||||
chip.setChipIconResource(model.icon)
|
|
||||||
}
|
}
|
||||||
|
chip.chipIconTint = tint ?: defaultChipIconTint
|
||||||
|
chip.checkedIconTint = tint ?: defaultChipIconTint
|
||||||
|
chip.chipStrokeColor = tint ?: defaultChipStrokeColor
|
||||||
|
chip.setTextColor(tint ?: defaultChipTextColor)
|
||||||
chip.isClickable = onChipClickListener != null || model.isCheckable
|
chip.isClickable = onChipClickListener != null || model.isCheckable
|
||||||
chip.isCheckable = model.isCheckable
|
chip.isCheckable = model.isCheckable
|
||||||
chip.isChecked = model.isChecked
|
chip.isChecked = model.isChecked
|
||||||
@@ -92,8 +110,9 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
val drawable = ChipDrawable.createFromAttributes(context, null, 0, R.style.Widget_Kotatsu_Chip)
|
val drawable = ChipDrawable.createFromAttributes(context, null, 0, R.style.Widget_Kotatsu_Chip)
|
||||||
chip.setChipDrawable(drawable)
|
chip.setChipDrawable(drawable)
|
||||||
chip.isCheckedIconVisible = true
|
chip.isCheckedIconVisible = true
|
||||||
|
chip.isChipIconVisible = false
|
||||||
chip.setCheckedIconResource(R.drawable.ic_check)
|
chip.setCheckedIconResource(R.drawable.ic_check)
|
||||||
chip.checkedIconTint = context.getThemeColorStateList(materialR.attr.colorControlNormal)
|
chip.checkedIconTint = defaultChipIconTint
|
||||||
chip.isCloseIconVisible = onChipCloseClickListener != null
|
chip.isCloseIconVisible = onChipCloseClickListener != null
|
||||||
chip.setOnCloseIconClickListener(chipOnCloseListener)
|
chip.setOnCloseIconClickListener(chipOnCloseListener)
|
||||||
chip.setEnsureMinTouchTargetSize(false)
|
chip.setEnsureMinTouchTargetSize(false)
|
||||||
@@ -113,7 +132,7 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ChipModel(
|
class ChipModel(
|
||||||
@DrawableRes val icon: Int,
|
@ColorRes val tint: Int,
|
||||||
val title: CharSequence,
|
val title: CharSequence,
|
||||||
val isCheckable: Boolean,
|
val isCheckable: Boolean,
|
||||||
val isChecked: Boolean,
|
val isChecked: Boolean,
|
||||||
@@ -126,7 +145,7 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
|
|
||||||
other as ChipModel
|
other as ChipModel
|
||||||
|
|
||||||
if (icon != other.icon) return false
|
if (tint != other.tint) return false
|
||||||
if (title != other.title) return false
|
if (title != other.title) return false
|
||||||
if (isCheckable != other.isCheckable) return false
|
if (isCheckable != other.isCheckable) return false
|
||||||
if (isChecked != other.isChecked) return false
|
if (isChecked != other.isChecked) return false
|
||||||
@@ -136,7 +155,7 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
var result = icon
|
var result = tint.hashCode()
|
||||||
result = 31 * result + title.hashCode()
|
result = 31 * result + title.hashCode()
|
||||||
result = 31 * result + isCheckable.hashCode()
|
result = 31 * result + isCheckable.hashCode()
|
||||||
result = 31 * result + isChecked.hashCode()
|
result = 31 * result + isChecked.hashCode()
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.animation.Animator
|
||||||
|
import android.animation.ValueAnimator
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Outline
|
import android.graphics.Outline
|
||||||
@@ -7,48 +9,34 @@ import android.graphics.Paint
|
|||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewOutlineProvider
|
import android.view.ViewOutlineProvider
|
||||||
|
import android.view.animation.DecelerateInterpolator
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.annotation.FloatRange
|
import androidx.annotation.FloatRange
|
||||||
import androidx.core.graphics.ColorUtils
|
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
import kotlin.random.Random
|
|
||||||
import org.koitharu.kotatsu.parsers.util.replaceWith
|
import org.koitharu.kotatsu.parsers.util.replaceWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getAnimationDuration
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import org.koitharu.kotatsu.utils.ext.isAnimationsEnabled
|
||||||
import org.koitharu.kotatsu.utils.ext.resolveDp
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
class SegmentedBarView @JvmOverloads constructor(
|
class SegmentedBarView @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
attrs: AttributeSet? = null,
|
attrs: AttributeSet? = null,
|
||||||
defStyleAttr: Int = 0,
|
defStyleAttr: Int = 0,
|
||||||
) : View(context, attrs, defStyleAttr) {
|
) : View(context, attrs, defStyleAttr), ValueAnimator.AnimatorUpdateListener, Animator.AnimatorListener {
|
||||||
|
|
||||||
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
private val segmentsData = ArrayList<Segment>()
|
private val segmentsData = ArrayList<Segment>()
|
||||||
private val segmentsSizes = ArrayList<Float>()
|
private val segmentsSizes = ArrayList<Float>()
|
||||||
private val outlineColor = context.getThemeColor(materialR.attr.colorOutline)
|
private val outlineColor = context.getThemeColor(materialR.attr.colorOutline)
|
||||||
private var cornerSize = 0f
|
private var cornerSize = 0f
|
||||||
|
private var scaleFactor = 1f
|
||||||
var segments: List<Segment>
|
private var scaleAnimator: ValueAnimator? = null
|
||||||
get() = segmentsData
|
|
||||||
set(value) {
|
|
||||||
segmentsData.replaceWith(value)
|
|
||||||
updateSizes()
|
|
||||||
invalidate()
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
paint.strokeWidth = context.resources.resolveDp(1f)
|
paint.strokeWidth = context.resources.resolveDp(1f)
|
||||||
outlineProvider = OutlineProvider()
|
outlineProvider = OutlineProvider()
|
||||||
clipToOutline = true
|
clipToOutline = true
|
||||||
|
|
||||||
if (isInEditMode) {
|
|
||||||
segments = List(Random.nextInt(3, 5)) {
|
|
||||||
Segment(
|
|
||||||
percent = Random.nextFloat(),
|
|
||||||
color = ColorUtils.HSLToColor(floatArrayOf(Random.nextInt(0, 360).toFloat(), 0.5f, 0.5f)),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||||
@@ -79,12 +67,56 @@ class SegmentedBarView @JvmOverloads constructor(
|
|||||||
canvas.drawRoundRect(0f, 0f, w, height.toFloat(), cornerSize, cornerSize, paint)
|
canvas.drawRoundRect(0f, 0f, w, height.toFloat(), cornerSize, cornerSize, paint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onAnimationStart(animation: Animator) = Unit
|
||||||
|
|
||||||
|
override fun onAnimationEnd(animation: Animator) {
|
||||||
|
if (scaleAnimator === animation) {
|
||||||
|
scaleAnimator = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAnimationUpdate(animation: ValueAnimator) {
|
||||||
|
scaleFactor = animation.animatedValue as Float
|
||||||
|
updateSizes()
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAnimationCancel(animation: Animator) = Unit
|
||||||
|
|
||||||
|
override fun onAnimationRepeat(animation: Animator) = Unit
|
||||||
|
|
||||||
|
fun animateSegments(value: List<Segment>) {
|
||||||
|
scaleAnimator?.cancel()
|
||||||
|
segmentsData.replaceWith(value)
|
||||||
|
if (!context.isAnimationsEnabled) {
|
||||||
|
scaleAnimator = null
|
||||||
|
scaleFactor = 1f
|
||||||
|
updateSizes()
|
||||||
|
invalidate()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
scaleFactor = 0f
|
||||||
|
updateSizes()
|
||||||
|
invalidate()
|
||||||
|
val animator = ValueAnimator.ofFloat(0f, 1f)
|
||||||
|
animator.duration = context.getAnimationDuration(android.R.integer.config_longAnimTime)
|
||||||
|
animator.interpolator = DecelerateInterpolator()
|
||||||
|
animator.addUpdateListener(this@SegmentedBarView)
|
||||||
|
animator.addListener(this@SegmentedBarView)
|
||||||
|
scaleAnimator = animator
|
||||||
|
animator.start()
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateSizes() {
|
private fun updateSizes() {
|
||||||
segmentsSizes.clear()
|
segmentsSizes.clear()
|
||||||
segmentsSizes.ensureCapacity(segmentsData.size + 1)
|
segmentsSizes.ensureCapacity(segmentsData.size + 1)
|
||||||
var w = width.toFloat()
|
var w = width.toFloat()
|
||||||
for (segment in segmentsData) {
|
val maxScale = (scaleFactor * (segmentsData.size - 1)).coerceAtLeast(1f)
|
||||||
val segmentWidth = (w * segment.percent).coerceAtLeast(cornerSize)
|
for ((index, segment) in segmentsData.withIndex()) {
|
||||||
|
val scale = (scaleFactor * (index + 1) / maxScale).coerceAtMost(1f)
|
||||||
|
val segmentWidth = (w * segment.percent).coerceAtLeast(
|
||||||
|
if (index == 0) height.toFloat() else cornerSize,
|
||||||
|
) * scale
|
||||||
segmentsSizes.add(segmentWidth)
|
segmentsSizes.add(segmentWidth)
|
||||||
w -= segmentWidth
|
w -= segmentWidth
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.ColorStateList
|
||||||
|
import android.content.res.TypedArray
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.InsetDrawable
|
||||||
|
import android.graphics.drawable.RippleDrawable
|
||||||
|
import android.graphics.drawable.ShapeDrawable
|
||||||
|
import android.graphics.drawable.shapes.RoundRectShape
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import androidx.annotation.AttrRes
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.content.withStyledAttributes
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.core.widget.ImageViewCompat
|
||||||
|
import androidx.core.widget.TextViewCompat
|
||||||
|
import com.google.android.material.ripple.RippleUtils
|
||||||
|
import com.google.android.material.shape.MaterialShapeDrawable
|
||||||
|
import com.google.android.material.shape.ShapeAppearanceModel
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.databinding.ViewTwoLinesItemBinding
|
||||||
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
|
class TwoLinesItemView @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
@AttrRes defStyleAttr: Int = 0,
|
||||||
|
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
private val binding = ViewTwoLinesItemBinding.inflate(LayoutInflater.from(context), this)
|
||||||
|
|
||||||
|
init {
|
||||||
|
var textColors: ColorStateList? = null
|
||||||
|
context.withStyledAttributes(
|
||||||
|
set = attrs,
|
||||||
|
attrs = R.styleable.TwoLinesItemView,
|
||||||
|
defStyleAttr = defStyleAttr,
|
||||||
|
defStyleRes = R.style.Widget_Kotatsu_TwoLinesItemView,
|
||||||
|
) {
|
||||||
|
val itemRippleColor = getRippleColor(context)
|
||||||
|
val shape = createShapeDrawable(this)
|
||||||
|
val roundCorners = FloatArray(8) { resources.resolveDp(16f) }
|
||||||
|
background = RippleDrawable(
|
||||||
|
RippleUtils.sanitizeRippleDrawableColor(itemRippleColor),
|
||||||
|
shape,
|
||||||
|
ShapeDrawable(RoundRectShape(roundCorners, null, null)),
|
||||||
|
)
|
||||||
|
val drawablePadding = getDimensionPixelOffset(R.styleable.TwoLinesItemView_android_drawablePadding, 0)
|
||||||
|
binding.layoutText.updateLayoutParams<MarginLayoutParams> { marginStart = drawablePadding }
|
||||||
|
setIconResource(getResourceId(R.styleable.TwoLinesItemView_icon, 0))
|
||||||
|
binding.title.text = getText(R.styleable.TwoLinesItemView_title)
|
||||||
|
binding.subtitle.text = getText(R.styleable.TwoLinesItemView_subtitle)
|
||||||
|
textColors = getColorStateList(R.styleable.TwoLinesItemView_android_textColor)
|
||||||
|
val textAppearanceFallback = androidx.appcompat.R.style.TextAppearance_AppCompat
|
||||||
|
TextViewCompat.setTextAppearance(
|
||||||
|
binding.title,
|
||||||
|
getResourceId(R.styleable.TwoLinesItemView_titleTextAppearance, textAppearanceFallback),
|
||||||
|
)
|
||||||
|
TextViewCompat.setTextAppearance(
|
||||||
|
binding.subtitle,
|
||||||
|
getResourceId(R.styleable.TwoLinesItemView_subtitleTextAppearance, textAppearanceFallback),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (textColors == null) {
|
||||||
|
textColors = binding.title.textColors
|
||||||
|
}
|
||||||
|
binding.title.setTextColor(textColors)
|
||||||
|
binding.subtitle.setTextColor(textColors)
|
||||||
|
ImageViewCompat.setImageTintList(binding.icon, textColors)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setIconResource(@DrawableRes resId: Int) {
|
||||||
|
val icon = if (resId != 0) ContextCompat.getDrawable(context, resId) else null
|
||||||
|
binding.icon.setImageDrawable(icon)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createShapeDrawable(ta: TypedArray): InsetDrawable {
|
||||||
|
val shapeAppearance = ShapeAppearanceModel.builder(
|
||||||
|
context,
|
||||||
|
ta.getResourceId(R.styleable.TwoLinesItemView_shapeAppearance, 0),
|
||||||
|
ta.getResourceId(R.styleable.TwoLinesItemView_shapeAppearanceOverlay, 0),
|
||||||
|
).build()
|
||||||
|
val shapeDrawable = MaterialShapeDrawable(shapeAppearance)
|
||||||
|
shapeDrawable.fillColor = ta.getColorStateList(R.styleable.TwoLinesItemView_backgroundFillColor)
|
||||||
|
return InsetDrawable(
|
||||||
|
shapeDrawable,
|
||||||
|
ta.getDimensionPixelOffset(R.styleable.TwoLinesItemView_android_insetLeft, 0),
|
||||||
|
ta.getDimensionPixelOffset(R.styleable.TwoLinesItemView_android_insetTop, 0),
|
||||||
|
ta.getDimensionPixelOffset(R.styleable.TwoLinesItemView_android_insetRight, 0),
|
||||||
|
ta.getDimensionPixelOffset(R.styleable.TwoLinesItemView_android_insetBottom, 0),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getRippleColor(context: Context): ColorStateList {
|
||||||
|
return ContextCompat.getColorStateList(context, R.color.selector_overlay)
|
||||||
|
?: ColorStateList.valueOf(Color.TRANSPARENT)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ package org.koitharu.kotatsu.bookmarks.domain
|
|||||||
|
|
||||||
import android.database.SQLException
|
import android.database.SQLException
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import javax.inject.Inject
|
import dagger.Reusable
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
||||||
@@ -17,7 +17,9 @@ import org.koitharu.kotatsu.core.db.entity.toManga
|
|||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.utils.ext.mapItems
|
import org.koitharu.kotatsu.utils.ext.mapItems
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@Reusable
|
||||||
class BookmarksRepository @Inject constructor(
|
class BookmarksRepository @Inject constructor(
|
||||||
private val db: MangaDatabase,
|
private val db: MangaDatabase,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.ui
|
package org.koitharu.kotatsu.bookmarks.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 android.widget.Toast
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
@@ -10,7 +15,6 @@ import androidx.fragment.app.viewModels
|
|||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.domain.reverseAsync
|
import org.koitharu.kotatsu.base.domain.reverseAsync
|
||||||
import org.koitharu.kotatsu.base.ui.BaseFragment
|
import org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
@@ -24,6 +28,7 @@ import org.koitharu.kotatsu.bookmarks.data.ids
|
|||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.bookmarks.ui.adapter.BookmarksGroupAdapter
|
import org.koitharu.kotatsu.bookmarks.ui.adapter.BookmarksGroupAdapter
|
||||||
import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
||||||
|
import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver
|
||||||
import org.koitharu.kotatsu.databinding.FragmentListSimpleBinding
|
import org.koitharu.kotatsu.databinding.FragmentListSimpleBinding
|
||||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
||||||
@@ -32,9 +37,9 @@ import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
|||||||
import org.koitharu.kotatsu.main.ui.owners.SnackbarOwner
|
import org.koitharu.kotatsu.main.ui.owners.SnackbarOwner
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
|
||||||
import org.koitharu.kotatsu.utils.ext.invalidateNestedItemDecorations
|
import org.koitharu.kotatsu.utils.ext.invalidateNestedItemDecorations
|
||||||
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class BookmarksFragment :
|
class BookmarksFragment :
|
||||||
@@ -76,7 +81,7 @@ class BookmarksFragment :
|
|||||||
binding.recyclerView.addItemDecoration(spacingDecoration)
|
binding.recyclerView.addItemDecoration(spacingDecoration)
|
||||||
|
|
||||||
viewModel.content.observe(viewLifecycleOwner, ::onListChanged)
|
viewModel.content.observe(viewLifecycleOwner, ::onListChanged)
|
||||||
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
viewModel.onError.observe(viewLifecycleOwner, SnackbarErrorObserver(binding.recyclerView, this))
|
||||||
viewModel.onActionDone.observe(viewLifecycleOwner, ::onActionDone)
|
viewModel.onActionDone.observe(viewLifecycleOwner, ::onActionDone)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +95,7 @@ class BookmarksFragment :
|
|||||||
if (selectionController?.onItemClick(item.manga, item.pageId) != true) {
|
if (selectionController?.onItemClick(item.manga, item.pageId) != true) {
|
||||||
val intent = ReaderActivity.newIntent(view.context, item)
|
val intent = ReaderActivity.newIntent(view.context, item)
|
||||||
startActivity(intent, scaleUpActivityOptionsOf(view).toBundle())
|
startActivity(intent, scaleUpActivityOptionsOf(view).toBundle())
|
||||||
|
Toast.makeText(view.context, R.string.incognito_mode, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +138,7 @@ class BookmarksFragment :
|
|||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,14 +161,6 @@ class BookmarksFragment :
|
|||||||
adapter?.items = list
|
adapter?.items = list
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onError(e: Throwable) {
|
|
||||||
Snackbar.make(
|
|
||||||
binding.recyclerView,
|
|
||||||
e.getDisplayMessage(resources),
|
|
||||||
Snackbar.LENGTH_SHORT,
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onActionDone(action: ReversibleAction) {
|
private fun onActionDone(action: ReversibleAction) {
|
||||||
val handle = action.handle
|
val handle = action.handle
|
||||||
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.koitharu.kotatsu.bookmarks.ui
|
|||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
@@ -18,7 +17,8 @@ import org.koitharu.kotatsu.list.ui.model.LoadingState
|
|||||||
import org.koitharu.kotatsu.list.ui.model.toErrorState
|
import org.koitharu.kotatsu.list.ui.model.toErrorState
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class BookmarksViewModel @Inject constructor(
|
class BookmarksViewModel @Inject constructor(
|
||||||
@@ -43,12 +43,12 @@ class BookmarksViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.catch { e -> emit(listOf(e.toErrorState(canRetry = false))) }
|
.catch { e -> emit(listOf(e.toErrorState(canRetry = false))) }
|
||||||
.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
||||||
|
|
||||||
fun removeBookmarks(ids: Map<Manga, Set<Long>>) {
|
fun removeBookmarks(ids: Map<Manga, Set<Long>>) {
|
||||||
launchJob(Dispatchers.Default) {
|
launchJob(Dispatchers.Default) {
|
||||||
val handle = repository.removeBookmarks(ids)
|
val handle = repository.removeBookmarks(ids)
|
||||||
onActionDone.postCall(ReversibleAction(R.string.bookmarks_removed, handle))
|
onActionDone.emitCall(ReversibleAction(R.string.bookmarks_removed, handle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,12 @@ import org.koitharu.kotatsu.base.ui.list.AdapterDelegateClickListenerAdapter
|
|||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.databinding.ItemBookmarkBinding
|
import org.koitharu.kotatsu.databinding.ItemBookmarkBinding
|
||||||
|
import org.koitharu.kotatsu.utils.ext.decodeRegion
|
||||||
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
|
import org.koitharu.kotatsu.utils.ext.source
|
||||||
|
import org.koitharu.kotatsu.utils.image.CoverSizeResolver
|
||||||
|
|
||||||
fun bookmarkListAD(
|
fun bookmarkListAD(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -26,13 +28,14 @@ fun bookmarkListAD(
|
|||||||
binding.root.setOnLongClickListener(listener)
|
binding.root.setOnLongClickListener(listener)
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.imageViewThumb.newImageRequest(item.imageUrl)?.run {
|
binding.imageViewThumb.newImageRequest(lifecycleOwner, item.imageUrl)?.run {
|
||||||
referer(item.manga.publicUrl)
|
size(CoverSizeResolver(binding.imageViewThumb))
|
||||||
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)
|
||||||
allowRgb565(true)
|
allowRgb565(true)
|
||||||
lifecycle(lifecycleOwner)
|
decodeRegion(item.scroll)
|
||||||
|
source(item.manga.source)
|
||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,12 @@ 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
|
||||||
|
import org.koitharu.kotatsu.utils.ext.source
|
||||||
|
import org.koitharu.kotatsu.utils.image.CoverSizeResolver
|
||||||
|
|
||||||
fun bookmarksGroupAD(
|
fun bookmarksGroupAD(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -45,13 +50,13 @@ 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(lifecycleOwner, item.manga.coverUrl)?.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)
|
||||||
allowRgb565(true)
|
allowRgb565(true)
|
||||||
lifecycle(lifecycleOwner)
|
size(CoverSizeResolver(binding.imageViewCover))
|
||||||
|
source(item.manga.source)
|
||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
binding.textViewTitle.text = item.manga.title
|
binding.textViewTitle.text = item.manga.title
|
||||||
|
|||||||
@@ -5,14 +5,18 @@ import androidx.recyclerview.widget.DiffUtil
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
import kotlin.jvm.internal.Intrinsics
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.*
|
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
||||||
|
import org.koitharu.kotatsu.list.ui.adapter.emptyStateListAD
|
||||||
|
import org.koitharu.kotatsu.list.ui.adapter.errorStateListAD
|
||||||
|
import org.koitharu.kotatsu.list.ui.adapter.loadingFooterAD
|
||||||
|
import org.koitharu.kotatsu.list.ui.adapter.loadingStateAD
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import kotlin.jvm.internal.Intrinsics
|
||||||
|
|
||||||
class BookmarksGroupAdapter(
|
class BookmarksGroupAdapter(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -38,7 +42,7 @@ class BookmarksGroupAdapter(
|
|||||||
)
|
)
|
||||||
.addDelegate(loadingStateAD())
|
.addDelegate(loadingStateAD())
|
||||||
.addDelegate(loadingFooterAD())
|
.addDelegate(loadingFooterAD())
|
||||||
.addDelegate(emptyStateListAD(coil, listener))
|
.addDelegate(emptyStateListAD(coil, lifecycleOwner, listener))
|
||||||
.addDelegate(errorStateListAD(listener))
|
.addDelegate(errorStateListAD(listener))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +53,7 @@ class BookmarksGroupAdapter(
|
|||||||
oldItem is BookmarksGroup && newItem is BookmarksGroup -> {
|
oldItem is BookmarksGroup && newItem is BookmarksGroup -> {
|
||||||
oldItem.manga.id == newItem.manga.id
|
oldItem.manga.id == newItem.manga.id
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> oldItem.javaClass == newItem.javaClass
|
else -> oldItem.javaClass == newItem.javaClass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,33 +8,38 @@ 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 org.koitharu.kotatsu.utils.ext.catchingWebViewUnavailability
|
||||||
|
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))
|
if (!catchingWebViewUnavailability { setContentView(ActivityBrowserBinding.inflate(layoutInflater)) }) {
|
||||||
|
return
|
||||||
|
}
|
||||||
supportActionBar?.run {
|
supportActionBar?.run {
|
||||||
setDisplayHomeAsUpEnabled(true)
|
setDisplayHomeAsUpEnabled(true)
|
||||||
setHomeAsUpIndicator(materialR.drawable.abc_ic_clear_material)
|
setHomeAsUpIndicator(materialR.drawable.abc_ic_clear_material)
|
||||||
}
|
}
|
||||||
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 +77,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 +87,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 +115,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()
|
||||||
|
}
|
||||||
@@ -2,14 +2,13 @@ package org.koitharu.kotatsu.browser
|
|||||||
|
|
||||||
import android.webkit.WebChromeClient
|
import android.webkit.WebChromeClient
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.widget.ProgressBar
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import org.koitharu.kotatsu.utils.ext.setProgressCompat
|
import com.google.android.material.progressindicator.BaseProgressIndicator
|
||||||
|
|
||||||
private const val PROGRESS_MAX = 100
|
private const val PROGRESS_MAX = 100
|
||||||
|
|
||||||
class ProgressChromeClient(
|
class ProgressChromeClient(
|
||||||
private val progressIndicator: ProgressBar,
|
private val progressIndicator: BaseProgressIndicator<*>,
|
||||||
) : WebChromeClient() {
|
) : WebChromeClient() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -28,4 +27,4 @@ class ProgressChromeClient(
|
|||||||
progressIndicator.isIndeterminate = true
|
progressIndicator.isIndeterminate = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,8 +2,8 @@ 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.browser.BrowserClient
|
||||||
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||||
|
|
||||||
private const val CF_CLEARANCE = "cf_clearance"
|
private const val CF_CLEARANCE = "cf_clearance"
|
||||||
@@ -12,22 +12,22 @@ class CloudFlareClient(
|
|||||||
private val cookieJar: MutableCookieJar,
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,27 +8,37 @@ 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 okhttp3.Headers
|
||||||
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
||||||
import org.koitharu.kotatsu.core.network.UserAgentInterceptor
|
import org.koitharu.kotatsu.browser.WebViewBackPressedCallback
|
||||||
|
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.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.withArgs
|
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), CloudFlareCallback {
|
class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), CloudFlareCallback {
|
||||||
|
|
||||||
private val url by stringArgument(ARG_URL)
|
private lateinit var url: String
|
||||||
private val pendingResult = Bundle(1)
|
private val pendingResult = Bundle(1)
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var cookieJar: MutableCookieJar
|
lateinit var cookieJar: MutableCookieJar
|
||||||
|
|
||||||
|
private var onBackPressedCallback: WebViewBackPressedCallback? = null
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
url = requireArguments().getString(ARG_URL).orEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onInflateView(
|
override fun onInflateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
@@ -42,20 +52,21 @@ 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)
|
||||||
CookieManager.getInstance().setAcceptThirdPartyCookies(binding.webView, true)
|
CookieManager.getInstance().setAcceptThirdPartyCookies(binding.webView, true)
|
||||||
if (url.isNullOrEmpty()) {
|
if (url.isEmpty()) {
|
||||||
dismissAllowingStateLoss()
|
dismissAllowingStateLoss()
|
||||||
} else {
|
} else {
|
||||||
binding.webView.loadUrl(url.orEmpty())
|
binding.webView.loadUrl(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +74,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 +105,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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
|||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import dagger.multibindings.ElementsIntoSet
|
import dagger.multibindings.ElementsIntoSet
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
|
import okhttp3.Cache
|
||||||
import okhttp3.CookieJar
|
import okhttp3.CookieJar
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
@@ -40,6 +44,8 @@ import org.koitharu.kotatsu.core.parser.favicon.FaviconFetcher
|
|||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.local.data.CacheDir
|
import org.koitharu.kotatsu.local.data.CacheDir
|
||||||
import org.koitharu.kotatsu.local.data.CbzFetcher
|
import org.koitharu.kotatsu.local.data.CbzFetcher
|
||||||
|
import org.koitharu.kotatsu.local.data.LocalManga
|
||||||
|
import org.koitharu.kotatsu.local.data.LocalStorageChanges
|
||||||
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
||||||
import org.koitharu.kotatsu.main.ui.protect.AppProtectHelper
|
import org.koitharu.kotatsu.main.ui.protect.AppProtectHelper
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
@@ -83,22 +89,37 @@ interface AppModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideOkHttpClient(
|
fun provideHttpCache(
|
||||||
localStorageManager: LocalStorageManager,
|
localStorageManager: LocalStorageManager,
|
||||||
|
): Cache = localStorageManager.createHttpCache()
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideOkHttpClient(
|
||||||
|
cache: Cache,
|
||||||
|
commonHeadersInterceptor: CommonHeadersInterceptor,
|
||||||
|
mirrorSwitchInterceptor: MirrorSwitchInterceptor,
|
||||||
cookieJar: CookieJar,
|
cookieJar: CookieJar,
|
||||||
settings: AppSettings,
|
settings: AppSettings,
|
||||||
): OkHttpClient {
|
): OkHttpClient {
|
||||||
val cache = localStorageManager.createHttpCache()
|
|
||||||
return OkHttpClient.Builder().apply {
|
return OkHttpClient.Builder().apply {
|
||||||
connectTimeout(20, TimeUnit.SECONDS)
|
connectTimeout(20, TimeUnit.SECONDS)
|
||||||
readTimeout(60, TimeUnit.SECONDS)
|
readTimeout(60, TimeUnit.SECONDS)
|
||||||
writeTimeout(20, TimeUnit.SECONDS)
|
writeTimeout(20, TimeUnit.SECONDS)
|
||||||
cookieJar(cookieJar)
|
cookieJar(cookieJar)
|
||||||
dns(DoHManager(cache, settings))
|
dns(DoHManager(cache, settings))
|
||||||
|
if (settings.isSSLBypassEnabled) {
|
||||||
|
bypassSSLErrors()
|
||||||
|
}
|
||||||
cache(cache)
|
cache(cache)
|
||||||
|
addNetworkInterceptor(CacheLimitInterceptor())
|
||||||
addInterceptor(GZipInterceptor())
|
addInterceptor(GZipInterceptor())
|
||||||
addInterceptor(UserAgentInterceptor())
|
addInterceptor(commonHeadersInterceptor)
|
||||||
addInterceptor(CloudFlareInterceptor())
|
addInterceptor(CloudFlareInterceptor())
|
||||||
|
addInterceptor(mirrorSwitchInterceptor)
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
addInterceptor(CurlLoggingInterceptor())
|
||||||
|
}
|
||||||
}.build()
|
}.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +181,6 @@ interface AppModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
|
||||||
@ElementsIntoSet
|
@ElementsIntoSet
|
||||||
fun provideDatabaseObservers(
|
fun provideDatabaseObservers(
|
||||||
widgetUpdater: WidgetUpdater,
|
widgetUpdater: WidgetUpdater,
|
||||||
@@ -175,7 +195,6 @@ interface AppModule {
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
|
||||||
@ElementsIntoSet
|
@ElementsIntoSet
|
||||||
fun provideActivityLifecycleCallbacks(
|
fun provideActivityLifecycleCallbacks(
|
||||||
appProtectHelper: AppProtectHelper,
|
appProtectHelper: AppProtectHelper,
|
||||||
@@ -198,5 +217,16 @@ interface AppModule {
|
|||||||
MemoryContentCache(application)
|
MemoryContentCache(application)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
@LocalStorageChanges
|
||||||
|
fun provideMutableLocalStorageChangesFlow(): MutableSharedFlow<LocalManga?> = MutableSharedFlow()
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@LocalStorageChanges
|
||||||
|
fun provideLocalStorageChangesFlow(
|
||||||
|
@LocalStorageChanges flow: MutableSharedFlow<LocalManga?>,
|
||||||
|
): SharedFlow<LocalManga?> = flow.asSharedFlow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.cache
|
|
||||||
|
|
||||||
import androidx.collection.LruCache
|
|
||||||
|
|
||||||
class DeferredLruCache<T>(maxSize: Int) : LruCache<ContentCache.Key, SafeDeferred<T>>(maxSize)
|
|
||||||
33
app/src/main/java/org/koitharu/kotatsu/core/cache/ExpiringLruCache.kt
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import androidx.collection.LruCache
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class ExpiringLruCache<T>(
|
||||||
|
val maxSize: Int,
|
||||||
|
private val lifetime: Long,
|
||||||
|
private val timeUnit: TimeUnit,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val cache = LruCache<ContentCache.Key, ExpiringValue<T>>(maxSize)
|
||||||
|
|
||||||
|
operator fun get(key: ContentCache.Key): T? {
|
||||||
|
val value = cache.get(key) ?: return null
|
||||||
|
if (value.isExpired) {
|
||||||
|
cache.remove(key)
|
||||||
|
}
|
||||||
|
return value.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun set(key: ContentCache.Key, value: T) {
|
||||||
|
cache.put(key, ExpiringValue(value, lifetime, timeUnit))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
cache.evictAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun trimToSize(size: Int) {
|
||||||
|
cache.trimToSize(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/src/main/java/org/koitharu/kotatsu/core/cache/ExpiringValue.kt
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import android.os.SystemClock
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class ExpiringValue<T>(
|
||||||
|
private val value: T,
|
||||||
|
lifetime: Long,
|
||||||
|
timeUnit: TimeUnit,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val expiresAt = SystemClock.elapsedRealtime() + timeUnit.toMillis(lifetime)
|
||||||
|
|
||||||
|
val isExpired: Boolean
|
||||||
|
get() = SystemClock.elapsedRealtime() >= expiresAt
|
||||||
|
|
||||||
|
fun get(): T? = if (isExpired) null else value
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as ExpiringValue<*>
|
||||||
|
|
||||||
|
if (value != other.value) return false
|
||||||
|
return expiresAt == other.expiresAt
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = value?.hashCode() ?: 0
|
||||||
|
result = 31 * result + expiresAt.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import android.content.res.Configuration
|
|||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class MemoryContentCache(application: Application) : ContentCache, ComponentCallbacks2 {
|
class MemoryContentCache(application: Application) : ContentCache, ComponentCallbacks2 {
|
||||||
|
|
||||||
@@ -13,8 +14,8 @@ class MemoryContentCache(application: Application) : ContentCache, ComponentCall
|
|||||||
application.registerComponentCallbacks(this)
|
application.registerComponentCallbacks(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val detailsCache = DeferredLruCache<Manga>(4)
|
private val detailsCache = ExpiringLruCache<SafeDeferred<Manga>>(4, 5, TimeUnit.MINUTES)
|
||||||
private val pagesCache = DeferredLruCache<List<MangaPage>>(4)
|
private val pagesCache = ExpiringLruCache<SafeDeferred<List<MangaPage>>>(4, 10, TimeUnit.MINUTES)
|
||||||
|
|
||||||
override val isCachingEnabled: Boolean = true
|
override val isCachingEnabled: Boolean = true
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ class MemoryContentCache(application: Application) : ContentCache, ComponentCall
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun putDetails(source: MangaSource, url: String, details: SafeDeferred<Manga>) {
|
override fun putDetails(source: MangaSource, url: String, details: SafeDeferred<Manga>) {
|
||||||
detailsCache.put(ContentCache.Key(source, url), details)
|
detailsCache[ContentCache.Key(source, url)] = details
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getPages(source: MangaSource, url: String): List<MangaPage>? {
|
override suspend fun getPages(source: MangaSource, url: String): List<MangaPage>? {
|
||||||
@@ -31,7 +32,7 @@ class MemoryContentCache(application: Application) : ContentCache, ComponentCall
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun putPages(source: MangaSource, url: String, pages: SafeDeferred<List<MangaPage>>) {
|
override fun putPages(source: MangaSource, url: String, pages: SafeDeferred<List<MangaPage>>) {
|
||||||
pagesCache.put(ContentCache.Key(source, url), pages)
|
pagesCache[ContentCache.Key(source, url)] = pages
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) = Unit
|
override fun onConfigurationChanged(newConfig: Configuration) = Unit
|
||||||
@@ -43,17 +44,17 @@ class MemoryContentCache(application: Application) : ContentCache, ComponentCall
|
|||||||
trimCache(pagesCache, level)
|
trimCache(pagesCache, level)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun trimCache(cache: DeferredLruCache<*>, level: Int) {
|
private fun trimCache(cache: ExpiringLruCache<*>, level: Int) {
|
||||||
when (level) {
|
when (level) {
|
||||||
ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL,
|
ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL,
|
||||||
ComponentCallbacks2.TRIM_MEMORY_COMPLETE,
|
ComponentCallbacks2.TRIM_MEMORY_COMPLETE,
|
||||||
ComponentCallbacks2.TRIM_MEMORY_MODERATE -> cache.evictAll()
|
ComponentCallbacks2.TRIM_MEMORY_MODERATE -> cache.clear()
|
||||||
|
|
||||||
ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN,
|
ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN,
|
||||||
ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW,
|
ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW,
|
||||||
ComponentCallbacks2.TRIM_MEMORY_BACKGROUND -> cache.trimToSize(1)
|
ComponentCallbacks2.TRIM_MEMORY_BACKGROUND -> cache.trimToSize(1)
|
||||||
|
|
||||||
else -> cache.trimToSize(cache.maxSize() / 2)
|
else -> cache.trimToSize(cache.maxSize / 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.koitharu.kotatsu.core.db.entity
|
package org.koitharu.kotatsu.core.db.entity
|
||||||
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaState
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||||
import org.koitharu.kotatsu.utils.ext.longHashCode
|
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||||
@@ -66,7 +69,6 @@ fun SortOrder(name: String, fallback: SortOrder): SortOrder = runCatching {
|
|||||||
SortOrder.valueOf(name)
|
SortOrder.valueOf(name)
|
||||||
}.getOrDefault(fallback)
|
}.getOrDefault(fallback)
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
|
||||||
fun MangaState(name: String): MangaState? = runCatching {
|
fun MangaState(name: String): MangaState? = runCatching {
|
||||||
MangaState.valueOf(name)
|
MangaState.valueOf(name)
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
|
|||||||
@@ -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")
|
@Transient val headers: Headers,
|
||||||
|
) : IOException("Protected by CloudFlare")
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions
|
package org.koitharu.kotatsu.core.exceptions
|
||||||
|
|
||||||
class WrongPasswordException : SecurityException()
|
class WrongPasswordException : IllegalArgumentException()
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package org.koitharu.kotatsu.core.exceptions.resolve
|
||||||
|
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.view.View
|
||||||
|
import androidx.core.util.Consumer
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.ui.ErrorDetailsDialog
|
||||||
|
import org.koitharu.kotatsu.parsers.exception.ParseException
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
|
||||||
|
class DialogErrorObserver(
|
||||||
|
host: View,
|
||||||
|
fragment: Fragment?,
|
||||||
|
resolver: ExceptionResolver?,
|
||||||
|
private val onResolved: Consumer<Boolean>?,
|
||||||
|
) : ErrorObserver(host, fragment, resolver, onResolved) {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
host: View,
|
||||||
|
fragment: Fragment?,
|
||||||
|
) : this(host, fragment, null, null)
|
||||||
|
|
||||||
|
override fun onChanged(value: Throwable?) {
|
||||||
|
if (value == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val listener = DialogListener(value)
|
||||||
|
val dialogBuilder = MaterialAlertDialogBuilder(activity ?: host.context)
|
||||||
|
.setMessage(value.getDisplayMessage(host.context.resources))
|
||||||
|
.setNegativeButton(R.string.close, listener)
|
||||||
|
.setOnCancelListener(listener)
|
||||||
|
if (canResolve(value)) {
|
||||||
|
dialogBuilder.setPositiveButton(ExceptionResolver.getResolveStringId(value), listener)
|
||||||
|
} else if (value is ParseException) {
|
||||||
|
val fm = fragmentManager
|
||||||
|
if (fm != null) {
|
||||||
|
dialogBuilder.setPositiveButton(R.string.details) { _, _ ->
|
||||||
|
ErrorDetailsDialog.show(fm, value, value.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val dialog = dialogBuilder.create()
|
||||||
|
if (activity != null) {
|
||||||
|
dialog.setOwnerActivity(activity)
|
||||||
|
}
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class DialogListener(
|
||||||
|
private val error: Throwable,
|
||||||
|
) : DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
|
||||||
|
|
||||||
|
override fun onClick(dialog: DialogInterface?, which: Int) {
|
||||||
|
when (which) {
|
||||||
|
DialogInterface.BUTTON_NEGATIVE -> onResolved?.accept(false)
|
||||||
|
DialogInterface.BUTTON_POSITIVE -> resolve(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCancel(dialog: DialogInterface?) {
|
||||||
|
onResolved?.accept(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package org.koitharu.kotatsu.core.exceptions.resolve
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.util.Consumer
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import androidx.lifecycle.LifecycleCoroutineScope
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import androidx.lifecycle.coroutineScope
|
||||||
|
import kotlinx.coroutines.isActive
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koitharu.kotatsu.utils.ext.findActivity
|
||||||
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||||
|
|
||||||
|
abstract class ErrorObserver(
|
||||||
|
protected val host: View,
|
||||||
|
protected val fragment: Fragment?,
|
||||||
|
private val resolver: ExceptionResolver?,
|
||||||
|
private val onResolved: Consumer<Boolean>?,
|
||||||
|
) : Observer<Throwable?> {
|
||||||
|
|
||||||
|
protected val activity = host.context.findActivity()
|
||||||
|
|
||||||
|
private val lifecycleScope: LifecycleCoroutineScope
|
||||||
|
get() = checkNotNull(fragment?.viewLifecycleScope ?: (activity as? LifecycleOwner)?.lifecycle?.coroutineScope)
|
||||||
|
|
||||||
|
protected val fragmentManager: FragmentManager?
|
||||||
|
get() = fragment?.childFragmentManager ?: (activity as? AppCompatActivity)?.supportFragmentManager
|
||||||
|
|
||||||
|
protected fun canResolve(error: Throwable): Boolean {
|
||||||
|
return resolver != null && ExceptionResolver.canResolve(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun resolve(error: Throwable) {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
val isResolved = resolver?.resolve(error) ?: false
|
||||||
|
if (isActive) {
|
||||||
|
onResolved?.accept(isResolved)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,10 +7,12 @@ import androidx.collection.ArrayMap
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
|
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
|
||||||
import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
|
import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
|
||||||
|
import org.koitharu.kotatsu.core.ui.ErrorDetailsDialog
|
||||||
import org.koitharu.kotatsu.parsers.exception.AuthRequiredException
|
import org.koitharu.kotatsu.parsers.exception.AuthRequiredException
|
||||||
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
@@ -37,13 +39,16 @@ class ExceptionResolver private constructor(
|
|||||||
sourceAuthContract = fragment.registerForActivityResult(SourceAuthActivity.Contract(), this)
|
sourceAuthContract = fragment.registerForActivityResult(SourceAuthActivity.Contract(), this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(result: TaggedActivityResult?) {
|
override fun onActivityResult(result: TaggedActivityResult) {
|
||||||
result ?: return
|
|
||||||
continuations.remove(result.tag)?.resume(result.isSuccess)
|
continuations.remove(result.tag)?.resume(result.isSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showDetails(e: Throwable, url: String?) {
|
||||||
|
ErrorDetailsDialog.show(getFragmentManager(), e, url)
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -53,8 +58,8 @@ class ExceptionResolver private constructor(
|
|||||||
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)
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package org.koitharu.kotatsu.core.exceptions.resolve
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.core.util.Consumer
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.ui.ErrorDetailsDialog
|
||||||
|
import org.koitharu.kotatsu.main.ui.owners.BottomNavOwner
|
||||||
|
import org.koitharu.kotatsu.parsers.exception.ParseException
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
|
||||||
|
class SnackbarErrorObserver(
|
||||||
|
host: View,
|
||||||
|
fragment: Fragment?,
|
||||||
|
resolver: ExceptionResolver?,
|
||||||
|
onResolved: Consumer<Boolean>?,
|
||||||
|
) : ErrorObserver(host, fragment, resolver, onResolved) {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
host: View,
|
||||||
|
fragment: Fragment?,
|
||||||
|
) : this(host, fragment, null, null)
|
||||||
|
|
||||||
|
override fun onChanged(value: Throwable?) {
|
||||||
|
if (value == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val snackbar = Snackbar.make(host, value.getDisplayMessage(host.context.resources), Snackbar.LENGTH_SHORT)
|
||||||
|
if (activity is BottomNavOwner) {
|
||||||
|
snackbar.anchorView = activity.bottomNav
|
||||||
|
}
|
||||||
|
if (canResolve(value)) {
|
||||||
|
snackbar.setAction(ExceptionResolver.getResolveStringId(value)) {
|
||||||
|
resolve(value)
|
||||||
|
}
|
||||||
|
} else if (value is ParseException) {
|
||||||
|
val fm = fragmentManager
|
||||||
|
if (fm != null) {
|
||||||
|
snackbar.setAction(R.string.details) {
|
||||||
|
ErrorDetailsDialog.show(fm, value, value.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
snackbar.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,10 @@ import kotlinx.coroutines.flow.asStateFlow
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
import org.json.JSONArray
|
||||||
|
import org.json.JSONObject
|
||||||
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
|
||||||
@@ -27,10 +30,12 @@ import javax.inject.Inject
|
|||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
private const val CERT_SHA1 = "2C:19:C7:E8:07:61:2B:8E:94:51:1B:FD:72:67:07:64:5D:C2:58:AE"
|
private const val CERT_SHA1 = "2C:19:C7:E8:07:61:2B:8E:94:51:1B:FD:72:67:07:64:5D:C2:58:AE"
|
||||||
|
private const val CONTENT_TYPE_APK = "application/vnd.android.package-archive"
|
||||||
|
|
||||||
@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,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -44,7 +49,9 @@ class AppUpdateRepository @Inject constructor(
|
|||||||
.url("https://api.github.com/repos/KotatsuApp/Kotatsu/releases?page=1&per_page=10")
|
.url("https://api.github.com/repos/KotatsuApp/Kotatsu/releases?page=1&per_page=10")
|
||||||
val jsonArray = okHttp.newCall(request.build()).await().parseJsonArray()
|
val jsonArray = okHttp.newCall(request.build()).await().parseJsonArray()
|
||||||
return jsonArray.mapJSONNotNull { json ->
|
return jsonArray.mapJSONNotNull { json ->
|
||||||
val asset = json.optJSONArray("assets")?.optJSONObject(0) ?: return@mapJSONNotNull null
|
val asset = json.optJSONArray("assets")?.find { jo ->
|
||||||
|
jo.optString("content_type") == CONTENT_TYPE_APK
|
||||||
|
} ?: return@mapJSONNotNull null
|
||||||
AppVersion(
|
AppVersion(
|
||||||
id = json.getLong("id"),
|
id = json.getLong("id"),
|
||||||
url = json.getString("html_url"),
|
url = json.getString("html_url"),
|
||||||
@@ -64,7 +71,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 }
|
||||||
@@ -101,4 +108,15 @@ class AppUpdateRepository @Inject constructor(
|
|||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
error.printStackTraceDebug()
|
error.printStackTraceDebug()
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
|
|
||||||
|
private inline fun JSONArray.find(predicate: (JSONObject) -> Boolean): JSONObject? {
|
||||||
|
val size = length()
|
||||||
|
for (i in 0 until size) {
|
||||||
|
val jo = getJSONObject(i)
|
||||||
|
if (predicate(jo)) {
|
||||||
|
return jo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,15 @@ import android.content.Context
|
|||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.cancelAndJoin
|
import kotlinx.coroutines.cancelAndJoin
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.runInterruptible
|
import kotlinx.coroutines.runInterruptible
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
@@ -68,6 +71,12 @@ class FileLogger(
|
|||||||
postFlush()
|
postFlush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun log(messageProducer: () -> String) {
|
||||||
|
if (isEnabled) {
|
||||||
|
log(messageProducer())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun flush() {
|
suspend fun flush() {
|
||||||
if (!isEnabled) {
|
if (!isEnabled) {
|
||||||
return
|
return
|
||||||
@@ -76,6 +85,15 @@ class FileLogger(
|
|||||||
flushImpl()
|
flushImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
fun flushBlocking() {
|
||||||
|
if (!isEnabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
runBlockingSafe { flushJob?.cancelAndJoin() }
|
||||||
|
runBlockingSafe { flushImpl() }
|
||||||
|
}
|
||||||
|
|
||||||
private fun postFlush() {
|
private fun postFlush() {
|
||||||
if (flushJob?.isActive == true) {
|
if (flushJob?.isActive == true) {
|
||||||
return
|
return
|
||||||
@@ -90,10 +108,10 @@ class FileLogger(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun flushImpl() {
|
private suspend fun flushImpl() = withContext(NonCancellable) {
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
if (buffer.isEmpty()) {
|
if (buffer.isEmpty()) {
|
||||||
return
|
return@withContext
|
||||||
}
|
}
|
||||||
runInterruptible(Dispatchers.IO) {
|
runInterruptible(Dispatchers.IO) {
|
||||||
if (file.length() > MAX_SIZE_BYTES) {
|
if (file.length() > MAX_SIZE_BYTES) {
|
||||||
@@ -125,4 +143,9 @@ class FileLogger(
|
|||||||
}
|
}
|
||||||
bakFile.delete()
|
bakFile.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inline fun runBlockingSafe(crossinline block: suspend () -> Unit) = try {
|
||||||
|
runBlocking(NonCancellable) { block() }
|
||||||
|
} catch (_: InterruptedException) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,3 +5,7 @@ import javax.inject.Qualifier
|
|||||||
@Qualifier
|
@Qualifier
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
annotation class TrackerLogger
|
annotation class TrackerLogger
|
||||||
|
|
||||||
|
@Qualifier
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
annotation class SyncLogger
|
||||||
|
|||||||
@@ -21,11 +21,20 @@ object LoggersModule {
|
|||||||
settings: AppSettings,
|
settings: AppSettings,
|
||||||
) = FileLogger(context, settings, "tracker")
|
) = FileLogger(context, settings, "tracker")
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@SyncLogger
|
||||||
|
fun provideSyncLogger(
|
||||||
|
@ApplicationContext context: Context,
|
||||||
|
settings: AppSettings,
|
||||||
|
) = FileLogger(context, settings, "sync")
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@ElementsIntoSet
|
@ElementsIntoSet
|
||||||
fun provideAllLoggers(
|
fun provideAllLoggers(
|
||||||
@TrackerLogger trackerLogger: FileLogger,
|
@TrackerLogger trackerLogger: FileLogger,
|
||||||
|
@SyncLogger syncLogger: FileLogger,
|
||||||
): Set<@JvmSuppressWildcards FileLogger> = arraySetOf(
|
): Set<@JvmSuppressWildcards FileLogger> = arraySetOf(
|
||||||
trackerLogger,
|
trackerLogger,
|
||||||
|
syncLogger,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,28 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
import androidx.core.os.LocaleListCompat
|
import androidx.core.os.LocaleListCompat
|
||||||
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
|
||||||
import org.koitharu.kotatsu.utils.ext.iterator
|
import org.koitharu.kotatsu.utils.ext.iterator
|
||||||
|
|
||||||
fun Collection<Manga>.ids() = mapToSet { it.id }
|
fun Collection<Manga>.ids() = mapToSet { it.id }
|
||||||
|
|
||||||
|
fun Collection<Manga>.distinctById() = distinctBy { it.id }
|
||||||
|
|
||||||
|
fun Collection<ChapterListItem>.countChaptersByBranch(): Int {
|
||||||
|
if (size <= 1) {
|
||||||
|
return size
|
||||||
|
}
|
||||||
|
val acc = HashMap<String?, Int>()
|
||||||
|
for (item in this) {
|
||||||
|
val branch = item.chapter.branch
|
||||||
|
acc[branch] = (acc[branch] ?: 0) + 1
|
||||||
|
}
|
||||||
|
return acc.values.max()
|
||||||
|
}
|
||||||
|
|
||||||
fun Manga.getPreferredBranch(history: MangaHistory?): String? {
|
fun Manga.getPreferredBranch(history: MangaHistory?): String? {
|
||||||
val ch = chapters
|
val ch = chapters
|
||||||
if (ch.isNullOrEmpty()) {
|
if (ch.isNullOrEmpty()) {
|
||||||
@@ -20,15 +35,22 @@ fun Manga.getPreferredBranch(history: MangaHistory?): String? {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val groups = ch.groupBy { it.branch }
|
val groups = ch.groupBy { it.branch }
|
||||||
|
if (groups.size == 1) {
|
||||||
|
return groups.keys.first()
|
||||||
|
}
|
||||||
|
val candidates = HashMap<String?, List<MangaChapter>>(groups.size)
|
||||||
for (locale in LocaleListCompat.getAdjustedDefault()) {
|
for (locale in LocaleListCompat.getAdjustedDefault()) {
|
||||||
var language = locale.getDisplayLanguage(locale).toTitleCase(locale)
|
val displayLanguage = locale.getDisplayLanguage(locale)
|
||||||
if (groups.containsKey(language)) {
|
val displayName = locale.getDisplayName(locale)
|
||||||
return language
|
for (branch in groups.keys) {
|
||||||
}
|
if (branch != null && (
|
||||||
language = locale.getDisplayName(locale).toTitleCase(locale)
|
branch.contains(displayLanguage, ignoreCase = true) ||
|
||||||
if (groups.containsKey(language)) {
|
branch.contains(displayName, ignoreCase = true)
|
||||||
return language
|
)
|
||||||
|
) {
|
||||||
|
candidates[branch] = groups[branch] ?: continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return groups.maxByOrNull { it.value.size }?.key
|
return candidates.ifEmpty { groups }.maxByOrNull { it.value.size }?.key
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ fun Parcel.readManga() = Manga(
|
|||||||
fun MangaPage.writeToParcel(out: Parcel) {
|
fun MangaPage.writeToParcel(out: Parcel) {
|
||||||
out.writeLong(id)
|
out.writeLong(id)
|
||||||
out.writeString(url)
|
out.writeString(url)
|
||||||
out.writeString(referer)
|
|
||||||
out.writeString(preview)
|
out.writeString(preview)
|
||||||
out.writeSerializable(source)
|
out.writeSerializable(source)
|
||||||
}
|
}
|
||||||
@@ -60,7 +59,6 @@ fun MangaPage.writeToParcel(out: Parcel) {
|
|||||||
fun Parcel.readMangaPage() = MangaPage(
|
fun Parcel.readMangaPage() = MangaPage(
|
||||||
id = readLong(),
|
id = readLong(),
|
||||||
url = requireNotNull(readString()),
|
url = requireNotNull(readString()),
|
||||||
referer = requireNotNull(readString()),
|
|
||||||
preview = readString(),
|
preview = readString(),
|
||||||
source = checkNotNull(readSerializableCompat()),
|
source = checkNotNull(readSerializableCompat()),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
|
import okhttp3.CacheControl
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Response
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class CacheLimitInterceptor : Interceptor {
|
||||||
|
|
||||||
|
private val defaultMaxAge = TimeUnit.HOURS.toSeconds(1)
|
||||||
|
private val defaultCacheControl = CacheControl.Builder()
|
||||||
|
.maxAge(defaultMaxAge.toInt(), TimeUnit.SECONDS)
|
||||||
|
.build()
|
||||||
|
.toString()
|
||||||
|
|
||||||
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
|
val response = chain.proceed(chain.request())
|
||||||
|
val responseCacheControl = CacheControl.parse(response.headers)
|
||||||
|
if (responseCacheControl.noStore || responseCacheControl.maxAgeSeconds <= defaultMaxAge) {
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
return response.newBuilder()
|
||||||
|
.header(CommonHeaders.CACHE_CONTROL, defaultCacheControl)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,11 +7,14 @@ 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"
|
||||||
|
const val CACHE_CONTROL = "Cache-Control"
|
||||||
|
|
||||||
val CACHE_CONTROL_DISABLED: CacheControl
|
val CACHE_CONTROL_NO_STORE: CacheControl
|
||||||
get() = CacheControl.Builder().noStore().build()
|
get() = CacheControl.Builder().noStore().build()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
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.net.IDN
|
||||||
|
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) {
|
||||||
|
val idn = IDN.toASCII(repository.domain)
|
||||||
|
headersBuilder.trySet(CommonHeaders.REFERER, "https://$idn/")
|
||||||
|
}
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
|
import dagger.Lazy
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||||
|
import okhttp3.internal.canParseAsIpAddress
|
||||||
|
import okhttp3.internal.closeQuietly
|
||||||
|
import okhttp3.internal.publicsuffix.PublicSuffixDatabase
|
||||||
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class MirrorSwitchInterceptor @Inject constructor(
|
||||||
|
private val mangaRepositoryFactoryLazy: Lazy<MangaRepository.Factory>,
|
||||||
|
private val settings: AppSettings,
|
||||||
|
) : Interceptor {
|
||||||
|
|
||||||
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
|
val request = chain.request()
|
||||||
|
if (!settings.isMirrorSwitchingAvailable) {
|
||||||
|
return chain.proceed(request)
|
||||||
|
}
|
||||||
|
return try {
|
||||||
|
val response = chain.proceed(request)
|
||||||
|
if (response.isFailed) {
|
||||||
|
val responseCopy = response.copy()
|
||||||
|
response.closeQuietly()
|
||||||
|
trySwitchMirror(request, chain)?.also {
|
||||||
|
responseCopy.closeQuietly()
|
||||||
|
} ?: responseCopy
|
||||||
|
} else {
|
||||||
|
response
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
trySwitchMirror(request, chain) ?: throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun trySwitchMirror(request: Request, chain: Interceptor.Chain): Response? {
|
||||||
|
val source = request.tag(MangaSource::class.java) ?: return null
|
||||||
|
val repository = mangaRepositoryFactoryLazy.get().create(source) as? RemoteMangaRepository ?: return null
|
||||||
|
val mirrors = repository.getAvailableMirrors()
|
||||||
|
if (mirrors.isEmpty()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return tryMirrors(repository, mirrors, chain, request)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun tryMirrors(
|
||||||
|
repository: RemoteMangaRepository,
|
||||||
|
mirrors: List<String>,
|
||||||
|
chain: Interceptor.Chain,
|
||||||
|
request: Request,
|
||||||
|
): Response? {
|
||||||
|
val url = request.url
|
||||||
|
val currentDomain = url.topPrivateDomain()
|
||||||
|
if (currentDomain !in mirrors) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val urlBuilder = url.newBuilder()
|
||||||
|
for (mirror in mirrors) {
|
||||||
|
if (mirror == currentDomain) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
val newHost = hostOf(url.host, mirror) ?: continue
|
||||||
|
val newRequest = request.newBuilder()
|
||||||
|
.url(urlBuilder.host(newHost).build())
|
||||||
|
.build()
|
||||||
|
val response = chain.proceed(newRequest)
|
||||||
|
if (response.isFailed) {
|
||||||
|
response.closeQuietly()
|
||||||
|
} else {
|
||||||
|
repository.domain = mirror
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private val Response.isFailed: Boolean
|
||||||
|
get() = code in 400..599
|
||||||
|
|
||||||
|
private fun hostOf(host: String, newDomain: String): String? {
|
||||||
|
if (newDomain.canParseAsIpAddress()) {
|
||||||
|
return newDomain
|
||||||
|
}
|
||||||
|
val domain = PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: return null
|
||||||
|
return host.removeSuffix(domain) + newDomain
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Response.copy(): Response {
|
||||||
|
return newBuilder()
|
||||||
|
.body(body?.copy())
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ResponseBody.copy(): ResponseBody {
|
||||||
|
return source().readByteArray().toResponseBody(contentType())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import java.security.SecureRandom
|
||||||
|
import java.security.cert.X509Certificate
|
||||||
|
import javax.net.ssl.SSLContext
|
||||||
|
import javax.net.ssl.SSLSocketFactory
|
||||||
|
import javax.net.ssl.X509TrustManager
|
||||||
|
|
||||||
|
@SuppressLint("CustomX509TrustManager")
|
||||||
|
fun OkHttpClient.Builder.bypassSSLErrors() = also { builder ->
|
||||||
|
runCatching {
|
||||||
|
val trustAllCerts = object : X509TrustManager {
|
||||||
|
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) = Unit
|
||||||
|
|
||||||
|
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) = Unit
|
||||||
|
|
||||||
|
override fun getAcceptedIssuers(): Array<X509Certificate> = emptyArray()
|
||||||
|
}
|
||||||
|
val sslContext = SSLContext.getInstance("SSL")
|
||||||
|
sslContext.init(null, arrayOf(trustAllCerts), SecureRandom())
|
||||||
|
val sslSocketFactory: SSLSocketFactory = sslContext.socketFactory
|
||||||
|
builder.sslSocketFactory(sslSocketFactory, trustAllCerts)
|
||||||
|
builder.hostnameVerifier { _, _ -> true }
|
||||||
|
}.onFailure {
|
||||||
|
it.printStackTraceDebug()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||