Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5436c65b76 | |||
| c590813a1a | |||
| 1cf36e1b41 | |||
| 5895a20af1 | |||
| fd5fd43b72 |
3
.weblate
@@ -1,3 +0,0 @@
|
|||||||
[weblate]
|
|
||||||
url = https://hosted.weblate.org/api/
|
|
||||||
translation = kotatsu/strings
|
|
||||||
11
README.md
@@ -2,12 +2,17 @@
|
|||||||
|
|
||||||
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/) [](https://t.me/kotatsuapp) [](https://discord.gg/NNJ5RgVBC5)
|
   [](https://hosted.weblate.org/engage/kotatsu/) [](http://4pda.ru/forum/index.php?showtopic=697669) [](https://discord.gg/NNJ5RgVBC5)
|
||||||
|
|
||||||
### Download
|
### Download
|
||||||
|
|
||||||
- **Recommended:** Download and install APK from **[GitHub Releases](https://github.com/KotatsuApp/Kotatsu/releases/latest)**. Application has a built-in self-updating feature.
|
[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png"
|
||||||
- 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.
|
alt="Get it on F-Droid"
|
||||||
|
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
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ android {
|
|||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 33
|
targetSdkVersion 33
|
||||||
versionCode 556
|
versionCode 525
|
||||||
versionName '5.3'
|
versionName '4.4.9'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
@@ -42,25 +42,25 @@ android {
|
|||||||
}
|
}
|
||||||
sourceSets {
|
sourceSets {
|
||||||
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
|
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
|
||||||
main.java.srcDirs += 'src/main/kotlin/'
|
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_17
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_17
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||||
freeCompilerArgs += [
|
freeCompilerArgs += [
|
||||||
'-opt-in=kotlin.ExperimentalStdlibApi',
|
'-opt-in=kotlin.ExperimentalStdlibApi',
|
||||||
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
||||||
'-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 true
|
abortOnError true
|
||||||
disable 'MissingTranslation', 'PrivateResource', 'NotifyDataSetChanged', 'SetJavaScriptEnabled'
|
disable 'MissingTranslation', 'PrivateResource', 'NotifyDataSetChanged'
|
||||||
}
|
}
|
||||||
testOptions {
|
testOptions {
|
||||||
unitTests.includeAndroidResources true
|
unitTests.includeAndroidResources true
|
||||||
@@ -79,59 +79,50 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
//noinspection GradleDependency
|
//noinspection GradleDependency
|
||||||
implementation('com.github.KotatsuApp:kotatsu-parsers:c2b79b55f8') {
|
implementation('com.github.KotatsuApp:kotatsu-parsers:1b6d1456f3') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.22'
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.10'
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.core:core-ktx:1.10.1'
|
implementation 'androidx.core:core-ktx:1.9.0'
|
||||||
implementation 'androidx.activity:activity-ktx:1.7.2'
|
implementation 'androidx.activity:activity-ktx:1.6.1'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.6.0'
|
implementation 'androidx.fragment:fragment-ktx:1.5.5'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-service:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-service:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-process:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-process:2.5.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.3.0'
|
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||||
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta02'
|
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.8.0'
|
||||||
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
||||||
implementation 'com.google.android.material:material:1.9.0'
|
implementation 'com.google.android.material:material:1.8.0'
|
||||||
//noinspection LifecycleAnnotationProcessorWithJava8
|
//noinspection LifecycleAnnotationProcessorWithJava8
|
||||||
kapt 'androidx.lifecycle:lifecycle-compiler:2.6.1'
|
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.1'
|
||||||
|
|
||||||
// TODO https://issuetracker.google.com/issues/254846063
|
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:32.0.0-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.2'
|
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||||
implementation 'androidx.room:room-ktx:2.5.2'
|
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
|
||||||
//noinspection KaptUsageInsteadOfKsp
|
|
||||||
kapt 'androidx.room:room-compiler:2.5.2'
|
|
||||||
|
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
|
|
||||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.11.0'
|
|
||||||
implementation 'com.squareup.okio:okio:3.3.0'
|
implementation 'com.squareup.okio:okio:3.3.0'
|
||||||
|
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
||||||
|
|
||||||
implementation 'com.google.dagger:hilt-android:2.46.1'
|
implementation 'com.google.dagger:hilt-android:2.45'
|
||||||
kapt 'com.google.dagger:hilt-compiler:2.46.1'
|
kapt 'com.google.dagger:hilt-compiler:2.45'
|
||||||
implementation 'androidx.hilt:hilt-work:1.0.0'
|
implementation 'androidx.hilt:hilt-work:1.0.0'
|
||||||
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
||||||
|
|
||||||
implementation 'io.coil-kt:coil-base:2.4.0'
|
implementation 'io.coil-kt:coil-base:2.2.2'
|
||||||
implementation 'io.coil-kt:coil-svg:2.4.0'
|
implementation 'io.coil-kt:coil-svg:2.2.2'
|
||||||
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'
|
||||||
@@ -139,22 +130,22 @@ dependencies {
|
|||||||
implementation 'ch.acra:acra-http:5.9.7'
|
implementation 'ch.acra:acra-http:5.9.7'
|
||||||
implementation 'ch.acra:acra-dialog:5.9.7'
|
implementation 'ch.acra:acra-dialog:5.9.7'
|
||||||
|
|
||||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.11'
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
testImplementation 'org.json:json:20230618'
|
testImplementation 'org.json:json:20230227'
|
||||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1'
|
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
||||||
|
|
||||||
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.7.1'
|
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.room:room-testing:2.5.1'
|
androidTestImplementation 'androidx.room:room-testing:2.5.0'
|
||||||
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.15.0'
|
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
|
||||||
|
|
||||||
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.46.1'
|
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.45'
|
||||||
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.46.1'
|
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.45'
|
||||||
}
|
}
|
||||||
|
|||||||
7
app/proguard-rules.pro
vendored
@@ -8,12 +8,9 @@
|
|||||||
public static void checkParameterIsNotNull(...);
|
public static void checkParameterIsNotNull(...);
|
||||||
public static void checkNotNullParameter(...);
|
public static void checkNotNullParameter(...);
|
||||||
}
|
}
|
||||||
-keep public class ** extends org.koitharu.kotatsu.core.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.**
|
-dontwarn okhttp3.internal.platform.ConscryptPlatform
|
||||||
-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
|
||||||
|
|||||||
BIN
app/sampledata/covers/Forget-me-not Volume 1.jpg
Normal file
|
After Width: | Height: | Size: 213 KiB |
BIN
app/sampledata/covers/Forget-me-not Volume 2.jpg
Normal file
|
After Width: | Height: | Size: 131 KiB |
BIN
app/sampledata/covers/La Pomme Prisoinniere.jpg
Normal file
|
After Width: | Height: | Size: 439 KiB |
BIN
app/sampledata/covers/Momo Kanchou no Himitsu Kichi.jpg
Normal file
|
After Width: | Height: | Size: 495 KiB |
BIN
app/sampledata/covers/Omoide Emanon.jpg
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
app/sampledata/covers/Sasurai Emanon Volume 1.jpg
Normal file
|
After Width: | Height: | Size: 791 KiB |
BIN
app/sampledata/covers/Sasurai Emanon Volume 2.jpg
Normal file
|
After Width: | Height: | Size: 844 KiB |
BIN
app/sampledata/covers/Sasurai Emanon Volume 3.jpg
Normal file
|
After Width: | Height: | Size: 386 KiB |
BIN
app/sampledata/covers/Wandering Island Volume 1.jpg
Normal file
|
After Width: | Height: | Size: 375 KiB |
BIN
app/sampledata/covers/Wandering Island Volume 2.jpg
Normal file
|
After Width: | Height: | Size: 398 KiB |
10
app/sampledata/genres
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
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
|
||||||
10
app/sampledata/titles
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
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
|
||||||
@@ -8,6 +8,7 @@ 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 javax.inject.Inject
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
@@ -18,12 +19,11 @@ import org.junit.runner.RunWith
|
|||||||
import org.koitharu.kotatsu.SampleData
|
import org.koitharu.kotatsu.SampleData
|
||||||
import org.koitharu.kotatsu.awaitForIdle
|
import org.koitharu.kotatsu.awaitForIdle
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.history.data.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@HiltAndroidTest
|
@HiltAndroidTest
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class AppShortcutManagerTest {
|
class ShortcutsUpdaterTest {
|
||||||
|
|
||||||
@get:Rule
|
@get:Rule
|
||||||
var hiltRule = HiltAndroidRule(this)
|
var hiltRule = HiltAndroidRule(this)
|
||||||
@@ -32,7 +32,7 @@ class AppShortcutManagerTest {
|
|||||||
lateinit var historyRepository: HistoryRepository
|
lateinit var historyRepository: HistoryRepository
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var appShortcutManager: AppShortcutManager
|
lateinit var shortcutsUpdater: ShortcutsUpdater
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var database: MangaDatabase
|
lateinit var database: MangaDatabase
|
||||||
@@ -72,6 +72,6 @@ class AppShortcutManagerTest {
|
|||||||
private suspend fun awaitUpdate() {
|
private suspend fun awaitUpdate() {
|
||||||
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||||
instrumentation.awaitForIdle()
|
instrumentation.awaitForIdle()
|
||||||
appShortcutManager.await()
|
shortcutsUpdater.await()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@ 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.*
|
||||||
@@ -17,9 +19,7 @@ import org.koitharu.kotatsu.core.backup.BackupRepository
|
|||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
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.data.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,7 +52,6 @@ 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(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.tracker.domain
|
|||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
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 javax.inject.Inject
|
||||||
import junit.framework.TestCase.*
|
import junit.framework.TestCase.*
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
@@ -10,9 +11,8 @@ import org.junit.Rule
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.koitharu.kotatsu.SampleData
|
import org.koitharu.kotatsu.SampleData
|
||||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@HiltAndroidTest
|
@HiltAndroidTest
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import java.util.EnumSet
|
|||||||
class DummyParser(context: MangaLoaderContext) : MangaParser(context, MangaSource.DUMMY) {
|
class DummyParser(context: MangaLoaderContext) : MangaParser(context, MangaSource.DUMMY) {
|
||||||
|
|
||||||
override val configKeyDomain: ConfigKey.Domain
|
override val configKeyDomain: ConfigKey.Domain
|
||||||
get() = ConfigKey.Domain()
|
get() = ConfigKey.Domain("", null)
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder>
|
override val sortOrders: Set<SortOrder>
|
||||||
get() = EnumSet.allOf(SortOrder::class.java)
|
get() = EnumSet.allOf(SortOrder::class.java)
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.util
|
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
|
||||||
|
|
||||||
class LoggingAdapterDataObserver(
|
|
||||||
private val tag: String,
|
|
||||||
) : AdapterDataObserver() {
|
|
||||||
|
|
||||||
override fun onChanged() {
|
|
||||||
Log.d(tag, "onChanged()")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemRangeChanged(positionStart: Int, itemCount: Int) {
|
|
||||||
Log.d(tag, "onItemRangeChanged(positionStart=$positionStart, itemCount=$itemCount)")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?) {
|
|
||||||
Log.d(tag, "onItemRangeChanged(positionStart=$positionStart, itemCount=$itemCount, payload=$payload)")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
|
||||||
Log.d(tag, "onItemRangeInserted(positionStart=$positionStart, itemCount=$itemCount)")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
|
||||||
Log.d(tag, "onItemRangeRemoved(positionStart=$positionStart, itemCount=$itemCount)")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
|
|
||||||
Log.d(tag, "onItemRangeMoved(fromPosition=$fromPosition, toPosition=$toPosition, itemCount=$itemCount)")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStateRestorationPolicyChanged() {
|
|
||||||
Log.d(tag, "onStateRestorationPolicyChanged()")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.util.ext
|
|
||||||
|
|
||||||
fun Throwable.printStackTraceDebug() = printStackTrace()
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package org.koitharu.kotatsu.utils.ext
|
||||||
|
|
||||||
|
fun Throwable.printStackTraceDebug() = printStackTrace()
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
<bool name="leak_canary_add_launcher_icon" tools:node="replace">false</bool>
|
<bool name="leak_canary_add_launcher_icon" tools:node="replace">false</bool>
|
||||||
|
<bool name="is_sync_enabled">true</bool>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<?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>
|
|
||||||
@@ -18,22 +18,6 @@
|
|||||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<uses-permission
|
|
||||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
|
||||||
android:maxSdkVersion="29" />
|
|
||||||
<uses-permission
|
|
||||||
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
|
|
||||||
tools:ignore="ScopedStorage" />
|
|
||||||
|
|
||||||
<queries>
|
|
||||||
<intent>
|
|
||||||
<action android:name="android.intent.action.PROCESS_TEXT" />
|
|
||||||
<data android:mimeType="text/plain" />
|
|
||||||
</intent>
|
|
||||||
<intent>
|
|
||||||
<action android:name="android.speech.action.RECOGNIZE_SPEECH" />
|
|
||||||
</intent>
|
|
||||||
</queries>
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="org.koitharu.kotatsu.KotatsuApp"
|
android:name="org.koitharu.kotatsu.KotatsuApp"
|
||||||
@@ -48,7 +32,6 @@
|
|||||||
android:largeHeap="true"
|
android:largeHeap="true"
|
||||||
android:localeConfig="@xml/locales"
|
android:localeConfig="@xml/locales"
|
||||||
android:networkSecurityConfig="@xml/network_security_config"
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:requestLegacyExternalStorage="true"
|
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.Kotatsu"
|
android:theme="@style/Theme.Kotatsu"
|
||||||
@@ -103,29 +86,11 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.settings.SettingsActivity"
|
android:name="org.koitharu.kotatsu.settings.SettingsActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/settings">
|
android:label="@string/settings" />
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
|
||||||
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
|
||||||
|
|
||||||
<data android:scheme="kotatsu" />
|
|
||||||
<data android:host="about" />
|
|
||||||
<data android:host="sync-settings" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity
|
|
||||||
android:name="org.koitharu.kotatsu.settings.storage.directories.MangaDirectoriesActivity"
|
|
||||||
android:label="@string/local_manga_directories" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.browser.BrowserActivity"
|
android:name="org.koitharu.kotatsu.browser.BrowserActivity"
|
||||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
<activity
|
|
||||||
android:name="org.koitharu.kotatsu.browser.cloudflare.CloudFlareActivity"
|
|
||||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
|
||||||
android:windowSoftInputMode="adjustResize" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.settings.sources.auth.SourceAuthActivity"
|
android:name="org.koitharu.kotatsu.settings.sources.auth.SourceAuthActivity"
|
||||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
||||||
@@ -153,7 +118,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.list.DownloadsActivity"
|
android:name="org.koitharu.kotatsu.download.ui.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" />
|
||||||
@@ -180,14 +145,16 @@
|
|||||||
<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="shikimori-auth" />
|
|
||||||
<data android:host="anilist-auth" />
|
|
||||||
<data android:host="mal-auth" />
|
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
</activity>
|
</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" />
|
||||||
@@ -208,7 +175,8 @@
|
|||||||
<service
|
<service
|
||||||
android:name="org.koitharu.kotatsu.sync.ui.favourites.FavouritesSyncService"
|
android:name="org.koitharu.kotatsu.sync.ui.favourites.FavouritesSyncService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/favourites">
|
android:label="@string/favourites"
|
||||||
|
android:process=":sync">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.content.SyncAdapter" />
|
<action android:name="android.content.SyncAdapter" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@@ -219,7 +187,8 @@
|
|||||||
<service
|
<service
|
||||||
android:name="org.koitharu.kotatsu.sync.ui.history.HistorySyncService"
|
android:name="org.koitharu.kotatsu.sync.ui.history.HistorySyncService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/history">
|
android:label="@string/history"
|
||||||
|
android:process=":sync">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.content.SyncAdapter" />
|
<action android:name="android.content.SyncAdapter" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@@ -246,26 +215,20 @@
|
|||||||
</provider>
|
</provider>
|
||||||
<provider
|
<provider
|
||||||
android:name="org.koitharu.kotatsu.sync.ui.favourites.FavouritesSyncProvider"
|
android:name="org.koitharu.kotatsu.sync.ui.favourites.FavouritesSyncProvider"
|
||||||
android:authorities="@string/sync_authority_favourites"
|
android:authorities="org.koitharu.kotatsu.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="@string/sync_authority_history"
|
android:authorities="org.koitharu.kotatsu.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"
|
||||||
android:exported="false"
|
tools:node="remove" />
|
||||||
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"
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import androidx.work.Configuration
|
|||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.acra.ACRA
|
|
||||||
import org.acra.ReportField
|
import org.acra.ReportField
|
||||||
import org.acra.config.dialog
|
import org.acra.config.dialog
|
||||||
import org.acra.config.httpSender
|
import org.acra.config.httpSender
|
||||||
@@ -20,15 +19,11 @@ import org.acra.data.StringFormat
|
|||||||
import org.acra.ktx.initAcra
|
import org.acra.ktx.initAcra
|
||||||
import org.acra.sender.HttpSender
|
import org.acra.sender.HttpSender
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.os.AppValidator
|
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.util.WorkServiceStopHelper
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.processLifecycleScope
|
|
||||||
import org.koitharu.kotatsu.local.data.LocalMangaRepository
|
|
||||||
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.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.settings.work.WorkScheduleManager
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltAndroidApp
|
@HiltAndroidApp
|
||||||
@@ -49,15 +44,8 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var workerFactory: HiltWorkerFactory
|
lateinit var workerFactory: HiltWorkerFactory
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var appValidator: AppValidator
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var workScheduleManager: WorkScheduleManager
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
ACRA.errorReporter.putCustomData("isOriginalApp", appValidator.isOriginalApp.toString())
|
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
enableStrictMode()
|
enableStrictMode()
|
||||||
}
|
}
|
||||||
@@ -67,8 +55,6 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
processLifecycleScope.launch(Dispatchers.Default) {
|
processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
setupDatabaseObservers()
|
setupDatabaseObservers()
|
||||||
}
|
}
|
||||||
workScheduleManager.init()
|
|
||||||
WorkServiceStopHelper(applicationContext).setup()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun attachBaseContext(base: Context?) {
|
override fun attachBaseContext(base: Context?) {
|
||||||
@@ -78,10 +64,6 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
reportFormat = StringFormat.JSON
|
reportFormat = StringFormat.JSON
|
||||||
excludeMatchingSharedPreferencesKeys = listOf(
|
excludeMatchingSharedPreferencesKeys = listOf(
|
||||||
"sources_\\w+",
|
"sources_\\w+",
|
||||||
AppSettings.KEY_APP_PASSWORD,
|
|
||||||
AppSettings.KEY_PROXY_LOGIN,
|
|
||||||
AppSettings.KEY_PROXY_ADDRESS,
|
|
||||||
AppSettings.KEY_PROXY_PASSWORD,
|
|
||||||
)
|
)
|
||||||
httpSender {
|
httpSender {
|
||||||
uri = getString(R.string.url_error_report)
|
uri = getString(R.string.url_error_report)
|
||||||
@@ -98,10 +80,8 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
ReportField.PHONE_MODEL,
|
ReportField.PHONE_MODEL,
|
||||||
ReportField.STACK_TRACE,
|
ReportField.STACK_TRACE,
|
||||||
ReportField.CRASH_CONFIGURATION,
|
ReportField.CRASH_CONFIGURATION,
|
||||||
ReportField.CUSTOM_DATA,
|
|
||||||
ReportField.SHARED_PREFERENCES,
|
ReportField.SHARED_PREFERENCES,
|
||||||
)
|
)
|
||||||
|
|
||||||
dialog {
|
dialog {
|
||||||
text = getString(R.string.crash_text)
|
text = getString(R.string.crash_text)
|
||||||
title = getString(R.string.error_occurred)
|
title = getString(R.string.error_occurred)
|
||||||
@@ -145,7 +125,6 @@ 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(),
|
||||||
)
|
)
|
||||||
@@ -1,25 +1,41 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import android.net.Uri
|
||||||
|
import android.util.Size
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import dagger.Reusable
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.runInterruptible
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
|
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
|
||||||
import org.koitharu.kotatsu.core.db.entity.toEntities
|
import org.koitharu.kotatsu.core.db.entity.toEntities
|
||||||
import org.koitharu.kotatsu.core.db.entity.toEntity
|
import org.koitharu.kotatsu.core.db.entity.toEntity
|
||||||
import org.koitharu.kotatsu.core.db.entity.toManga
|
import org.koitharu.kotatsu.core.db.entity.toManga
|
||||||
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||||
|
import org.koitharu.kotatsu.core.network.CommonHeaders
|
||||||
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
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 javax.inject.Inject
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
private const val MIN_WEBTOON_RATIO = 2
|
||||||
|
|
||||||
@Reusable
|
|
||||||
class MangaDataRepository @Inject constructor(
|
class MangaDataRepository @Inject constructor(
|
||||||
|
private val okHttpClient: OkHttpClient,
|
||||||
private val db: MangaDatabase,
|
private val db: MangaDatabase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -39,7 +55,6 @@ class MangaDataRepository @Inject constructor(
|
|||||||
entity.copy(
|
entity.copy(
|
||||||
cfBrightness = colorFilter?.brightness ?: 0f,
|
cfBrightness = colorFilter?.brightness ?: 0f,
|
||||||
cfContrast = colorFilter?.contrast ?: 0f,
|
cfContrast = colorFilter?.contrast ?: 0f,
|
||||||
cfInvert = colorFilter?.isInverted ?: false,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -82,18 +97,72 @@ class MangaDataRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun MangaPrefsEntity.getColorFilterOrNull(): ReaderColorFilter? {
|
private fun MangaPrefsEntity.getColorFilterOrNull(): ReaderColorFilter? {
|
||||||
return if (cfBrightness != 0f || cfContrast != 0f || cfInvert) {
|
return if (cfBrightness != 0f || cfContrast != 0f) {
|
||||||
ReaderColorFilter(cfBrightness, cfContrast, cfInvert)
|
ReaderColorFilter(cfBrightness, cfContrast)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatic determine type of manga by page size
|
||||||
|
* @return ReaderMode.WEBTOON if page is wide
|
||||||
|
*/
|
||||||
|
suspend fun determineMangaIsWebtoon(repository: MangaRepository, pages: List<MangaPage>): Boolean {
|
||||||
|
val pageIndex = (pages.size * 0.3).roundToInt()
|
||||||
|
val page = requireNotNull(pages.getOrNull(pageIndex)) { "No pages" }
|
||||||
|
val url = repository.getPageUrl(page)
|
||||||
|
val uri = Uri.parse(url)
|
||||||
|
val size = if (uri.scheme == "cbz") {
|
||||||
|
runInterruptible(Dispatchers.IO) {
|
||||||
|
val zip = ZipFile(uri.schemeSpecificPart)
|
||||||
|
val entry = zip.getEntry(uri.fragment)
|
||||||
|
zip.getInputStream(entry).use {
|
||||||
|
getBitmapSize(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.get()
|
||||||
|
.tag(MangaSource::class.java, page.source)
|
||||||
|
.cacheControl(CommonHeaders.CACHE_CONTROL_DISABLED)
|
||||||
|
.build()
|
||||||
|
okHttpClient.newCall(request).await().use {
|
||||||
|
runInterruptible(Dispatchers.IO) {
|
||||||
|
getBitmapSize(it.body?.byteStream())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return size.width * MIN_WEBTOON_RATIO < size.height
|
||||||
|
}
|
||||||
|
|
||||||
private fun newEntity(mangaId: Long) = MangaPrefsEntity(
|
private fun newEntity(mangaId: Long) = MangaPrefsEntity(
|
||||||
mangaId = mangaId,
|
mangaId = mangaId,
|
||||||
mode = -1,
|
mode = -1,
|
||||||
cfBrightness = 0f,
|
cfBrightness = 0f,
|
||||||
cfContrast = 0f,
|
cfContrast = 0f,
|
||||||
cfInvert = false,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
suspend fun getImageMimeType(file: File): String? = runInterruptible(Dispatchers.IO) {
|
||||||
|
val options = BitmapFactory.Options().apply {
|
||||||
|
inJustDecodeBounds = true
|
||||||
|
}
|
||||||
|
BitmapFactory.decodeFile(file.path, options)?.recycle()
|
||||||
|
options.outMimeType
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getBitmapSize(input: InputStream?): Size {
|
||||||
|
val options = BitmapFactory.Options().apply {
|
||||||
|
inJustDecodeBounds = true
|
||||||
|
}
|
||||||
|
BitmapFactory.decodeStream(input, null, options)?.recycle()
|
||||||
|
val imageHeight: Int = options.outHeight
|
||||||
|
val imageWidth: Int = options.outWidth
|
||||||
|
check(imageHeight > 0 && imageWidth > 0)
|
||||||
|
return Size(imageWidth, imageHeight)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
|
||||||
|
class MangaIntent private constructor(
|
||||||
|
val manga: Manga?,
|
||||||
|
val mangaId: Long,
|
||||||
|
val uri: Uri?,
|
||||||
|
) {
|
||||||
|
|
||||||
|
constructor(intent: Intent?) : this(
|
||||||
|
manga = intent?.getParcelableExtraCompat<ParcelableManga>(KEY_MANGA)?.manga,
|
||||||
|
mangaId = intent?.getLongExtra(KEY_ID, ID_NONE) ?: ID_NONE,
|
||||||
|
uri = intent?.data,
|
||||||
|
)
|
||||||
|
|
||||||
|
constructor(args: Bundle?) : this(
|
||||||
|
manga = args?.getParcelableCompat<ParcelableManga>(KEY_MANGA)?.manga,
|
||||||
|
mangaId = args?.getLong(KEY_ID, ID_NONE) ?: ID_NONE,
|
||||||
|
uri = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
const val ID_NONE = 0L
|
||||||
|
|
||||||
|
const val KEY_MANGA = "manga"
|
||||||
|
const val KEY_ID = "id"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.NonCancellable
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koitharu.kotatsu.core.util.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
fun interface ReversibleHandle {
|
fun interface ReversibleHandle {
|
||||||
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.core.ui
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.CallSuper
|
import androidx.annotation.CallSuper
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
@@ -13,21 +12,18 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
|
|
||||||
abstract class AlertDialogFragment<B : ViewBinding> : DialogFragment() {
|
abstract class AlertDialogFragment<B : ViewBinding> : DialogFragment() {
|
||||||
|
|
||||||
var viewBinding: B? = null
|
private var viewBinding: B? = null
|
||||||
private set
|
|
||||||
|
|
||||||
@Deprecated("", ReplaceWith("requireViewBinding()"))
|
|
||||||
protected val binding: B
|
protected val binding: B
|
||||||
get() = requireViewBinding()
|
get() = checkNotNull(viewBinding)
|
||||||
|
|
||||||
final override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
final override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val binding = onCreateViewBinding(layoutInflater, null)
|
val binding = onInflateView(layoutInflater, null)
|
||||||
viewBinding = binding
|
viewBinding = binding
|
||||||
return MaterialAlertDialogBuilder(requireContext(), theme)
|
return MaterialAlertDialogBuilder(requireContext(), theme)
|
||||||
.setView(binding.root)
|
.setView(binding.root)
|
||||||
.run(::onBuildDialog)
|
.run(::onBuildDialog)
|
||||||
.create()
|
.create()
|
||||||
.also(::onDialogCreated)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun onCreateView(
|
final override fun onCreateView(
|
||||||
@@ -36,11 +32,6 @@ abstract class AlertDialogFragment<B : ViewBinding> : DialogFragment() {
|
|||||||
savedInstanceState: Bundle?,
|
savedInstanceState: Bundle?,
|
||||||
) = viewBinding?.root
|
) = viewBinding?.root
|
||||||
|
|
||||||
final override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
onViewBindingCreated(requireViewBinding(), savedInstanceState)
|
|
||||||
}
|
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
viewBinding = null
|
viewBinding = null
|
||||||
@@ -51,14 +42,7 @@ abstract class AlertDialogFragment<B : ViewBinding> : DialogFragment() {
|
|||||||
|
|
||||||
open fun onDialogCreated(dialog: AlertDialog) = Unit
|
open fun onDialogCreated(dialog: AlertDialog) = Unit
|
||||||
|
|
||||||
@Deprecated("", ReplaceWith("viewBinding"))
|
protected fun bindingOrNull(): B? = viewBinding
|
||||||
protected fun bindingOrNull() = viewBinding
|
|
||||||
|
|
||||||
fun requireViewBinding(): B = checkNotNull(viewBinding) {
|
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
||||||
"Fragment $this did not return a ViewBinding from onCreateView() or this was called before onCreateView()."
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract fun onCreateViewBinding(inflater: LayoutInflater, container: ViewGroup?): B
|
|
||||||
|
|
||||||
protected open fun onViewBindingCreated(binding: B, savedInstanceState: Bundle?) = Unit
|
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.core.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
|
||||||
@@ -14,6 +12,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.appcompat.widget.ActionBarContextView
|
import androidx.appcompat.widget.ActionBarContextView
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
@@ -24,55 +23,42 @@ import androidx.viewbinding.ViewBinding
|
|||||||
import dagger.hilt.android.EntryPointAccessors
|
import dagger.hilt.android.EntryPointAccessors
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.BaseActivityEntryPoint
|
||||||
|
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.ui.util.ActionModeDelegate
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.ui.util.BaseActivityEntryPoint
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
import org.koitharu.kotatsu.core.ui.util.WindowInsetsDelegate
|
import javax.inject.Inject
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
|
||||||
abstract class BaseActivity<B : ViewBinding> :
|
abstract class BaseActivity<B : ViewBinding> :
|
||||||
AppCompatActivity(),
|
AppCompatActivity(),
|
||||||
WindowInsetsDelegate.WindowInsetsListener {
|
WindowInsetsDelegate.WindowInsetsListener {
|
||||||
|
|
||||||
private var isAmoledTheme = false
|
@Inject
|
||||||
|
lateinit var settings: AppSettings
|
||||||
|
|
||||||
lateinit var viewBinding: B
|
protected lateinit var binding: B
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@JvmField
|
@Suppress("LeakingThis")
|
||||||
protected val exceptionResolver = ExceptionResolver(this)
|
protected val exceptionResolver = ExceptionResolver(this)
|
||||||
|
|
||||||
@JvmField
|
@Suppress("LeakingThis")
|
||||||
protected val insetsDelegate = WindowInsetsDelegate()
|
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?) {
|
||||||
val settings = EntryPointAccessors.fromApplication(this, BaseActivityEntryPoint::class.java).settings
|
EntryPointAccessors.fromApplication(this, BaseActivityEntryPoint::class.java).inject(this)
|
||||||
isAmoledTheme = settings.isAmoledTheme
|
|
||||||
setTheme(settings.colorScheme.styleResId)
|
setTheme(settings.colorScheme.styleResId)
|
||||||
if (isAmoledTheme) {
|
if (settings.isAmoledTheme) {
|
||||||
setTheme(R.style.ThemeOverlay_Kotatsu_Amoled)
|
setTheme(R.style.ThemeOverlay_Kotatsu_Amoled)
|
||||||
}
|
}
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
insetsDelegate.handleImeInsets = true
|
insetsDelegate.handleImeInsets = true
|
||||||
insetsDelegate.addInsetsListener(this)
|
|
||||||
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)
|
||||||
@@ -88,7 +74,7 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun setContentView(binding: B) {
|
protected fun setContentView(binding: B) {
|
||||||
this.viewBinding = binding
|
this.binding = binding
|
||||||
super.setContentView(binding.root)
|
super.setContentView(binding.root)
|
||||||
val toolbar = (binding.root.findViewById<View>(R.id.toolbar) as? Toolbar)
|
val toolbar = (binding.root.findViewById<View>(R.id.toolbar) as? Toolbar)
|
||||||
toolbar?.let(this::setSupportActionBar)
|
toolbar?.let(this::setSupportActionBar)
|
||||||
@@ -103,8 +89,7 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||||
// ActivityCompat.recreate(this)
|
ActivityCompat.recreate(this)
|
||||||
error("Test")
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event)
|
return super.onKeyDown(keyCode, event)
|
||||||
@@ -117,22 +102,18 @@ 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 && isAmoledTheme
|
return isNight && settings.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 = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
val actionModeColor = ColorUtils.compositeColors(
|
||||||
ColorUtils.compositeColors(
|
ContextCompat.getColor(this, com.google.android.material.R.color.m3_appbar_overlay_color),
|
||||||
ContextCompat.getColor(this, com.google.android.material.R.color.m3_appbar_overlay_color),
|
getThemeColor(com.google.android.material.R.attr.colorSurface),
|
||||||
getThemeColor(com.google.android.material.R.attr.colorSurface),
|
)
|
||||||
)
|
val insets = ViewCompat.getRootWindowInsets(binding.root)
|
||||||
} else {
|
|
||||||
ContextCompat.getColor(this, R.color.kotatsu_secondaryContainer)
|
|
||||||
}
|
|
||||||
val insets = ViewCompat.getRootWindowInsets(viewBinding.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 {
|
||||||
setBackgroundColor(actionModeColor)
|
setBackgroundColor(actionModeColor)
|
||||||
@@ -140,7 +121,6 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
topMargin = insets.top
|
topMargin = insets.top
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defaultStatusBarColor = window.statusBarColor
|
|
||||||
window.statusBarColor = actionModeColor
|
window.statusBarColor = actionModeColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,15 +128,20 @@ 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 = defaultStatusBarColor
|
window.statusBarColor = getThemeColor(android.R.attr.statusBarColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun putDataToExtras(intent: Intent?) {
|
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
|
||||||
intent?.putExtra(EXTRA_DATA, intent.data)
|
@Deprecated("Should not be used")
|
||||||
}
|
override fun onBackPressed() {
|
||||||
|
if ( // https://issuetracker.google.com/issues/139738913
|
||||||
companion object {
|
Build.VERSION.SDK_INT == Build.VERSION_CODES.Q &&
|
||||||
|
isTaskRoot &&
|
||||||
const val EXTRA_DATA = "data"
|
supportFragmentManager.backStackEntryCount == 0
|
||||||
|
) {
|
||||||
|
finishAfterTransition()
|
||||||
|
} else {
|
||||||
|
super.onBackPressed()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.core.ui
|
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
|
||||||
@@ -13,23 +14,16 @@ 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.core.ui.dialog.AppBottomSheetDialog
|
import org.koitharu.kotatsu.base.ui.dialog.AppBottomSheetDialog
|
||||||
import org.koitharu.kotatsu.core.util.ext.findActivity
|
import org.koitharu.kotatsu.utils.ext.displayCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.getDisplaySize
|
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
@Deprecated(
|
|
||||||
"Use BaseAdaptiveSheet",
|
|
||||||
replaceWith = ReplaceWith("BaseAdaptiveSheet<B>", "org.koitharu.kotatsu.core.ui.sheet.BaseAdaptiveSheet"),
|
|
||||||
)
|
|
||||||
abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
||||||
|
|
||||||
var viewBinding: B? = null
|
private var viewBinding: B? = null
|
||||||
private set
|
|
||||||
|
|
||||||
@Deprecated("", ReplaceWith("requireViewBinding()"))
|
|
||||||
protected val binding: B
|
protected val binding: B
|
||||||
get() = requireViewBinding()
|
get() = checkNotNull(viewBinding)
|
||||||
|
|
||||||
protected val behavior: BottomSheetBehavior<*>?
|
protected val behavior: BottomSheetBehavior<*>?
|
||||||
get() = (dialog as? BottomSheetDialog)?.behavior
|
get() = (dialog as? BottomSheetDialog)?.behavior
|
||||||
@@ -45,24 +39,23 @@ abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
|||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?,
|
savedInstanceState: Bundle?,
|
||||||
): View {
|
): View {
|
||||||
val binding = onCreateViewBinding(inflater, container)
|
val binding = onInflateView(inflater, container)
|
||||||
viewBinding = binding
|
viewBinding = binding
|
||||||
return binding.root
|
|
||||||
}
|
|
||||||
|
|
||||||
final override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
val binding = requireViewBinding()
|
|
||||||
// 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
|
|
||||||
binding.root.context.findActivity()?.getDisplaySize()?.let {
|
// Set peek height to 50% display height
|
||||||
behavior?.peekHeight = (it.height() * 0.4).toInt()
|
requireContext().displayCompat?.let {
|
||||||
|
val metrics = DisplayMetrics()
|
||||||
|
it.getRealMetrics(metrics)
|
||||||
|
behavior?.peekHeight = (metrics.heightPixels * 0.4).toInt()
|
||||||
}
|
}
|
||||||
onViewBindingCreated(binding, savedInstanceState)
|
|
||||||
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -83,9 +76,7 @@ abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun onCreateViewBinding(inflater: LayoutInflater, container: ViewGroup?): B
|
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
||||||
|
|
||||||
protected open fun onViewBindingCreated(binding: B, savedInstanceState: Bundle?) = Unit
|
|
||||||
|
|
||||||
protected fun setExpanded(isExpanded: Boolean, isLocked: Boolean) {
|
protected fun setExpanded(isExpanded: Boolean, isLocked: Boolean) {
|
||||||
val b = behavior ?: return
|
val b = behavior ?: return
|
||||||
@@ -99,8 +90,4 @@ abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
|||||||
}
|
}
|
||||||
b.isDraggable = !isLocked
|
b.isDraggable = !isLocked
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requireViewBinding(): B = checkNotNull(viewBinding) {
|
|
||||||
"Fragment $this did not return a ViewBinding from onCreateView() or this was called before onCreateView()."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.viewbinding.ViewBinding
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
||||||
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
|
||||||
|
abstract class BaseFragment<B : ViewBinding> :
|
||||||
|
Fragment(),
|
||||||
|
WindowInsetsDelegate.WindowInsetsListener {
|
||||||
|
|
||||||
|
private var viewBinding: B? = null
|
||||||
|
|
||||||
|
protected val binding: B
|
||||||
|
get() = checkNotNull(viewBinding)
|
||||||
|
|
||||||
|
@Suppress("LeakingThis")
|
||||||
|
protected val exceptionResolver = ExceptionResolver(this)
|
||||||
|
|
||||||
|
@Suppress("LeakingThis")
|
||||||
|
protected val insetsDelegate = WindowInsetsDelegate(this)
|
||||||
|
|
||||||
|
protected val actionModeDelegate: ActionModeDelegate
|
||||||
|
get() = (requireActivity() as BaseActivity<*>).actionModeDelegate
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
val binding = onInflateView(inflater, container)
|
||||||
|
viewBinding = binding
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
insetsDelegate.onViewCreated(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
viewBinding = null
|
||||||
|
insetsDelegate.onDestroyView()
|
||||||
|
super.onDestroyView()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun bindingOrNull() = viewBinding
|
||||||
|
|
||||||
|
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
|
import androidx.viewbinding.ViewBinding
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
private const val SYSTEM_UI_FLAGS_SHOWN = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
private const val SYSTEM_UI_FLAGS_HIDDEN = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
|
||||||
|
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
|
||||||
|
View.SYSTEM_UI_FLAG_FULLSCREEN or
|
||||||
|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
|
|
||||||
|
abstract class BaseFullscreenActivity<B : ViewBinding> :
|
||||||
|
BaseActivity<B>(),
|
||||||
|
View.OnSystemUiVisibilityChangeListener {
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
with(window) {
|
||||||
|
statusBarColor = Color.TRANSPARENT
|
||||||
|
navigationBarColor = Color.TRANSPARENT
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
attributes.layoutInDisplayCutoutMode =
|
||||||
|
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||||
|
}
|
||||||
|
decorView.setOnSystemUiVisibilityChangeListener(this@BaseFullscreenActivity)
|
||||||
|
}
|
||||||
|
showSystemUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
|
final override fun onSystemUiVisibilityChange(visibility: Int) {
|
||||||
|
onSystemUiVisibilityChanged(visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO WindowInsetsControllerCompat works incorrect
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
protected fun hideSystemUI() {
|
||||||
|
window.decorView.systemUiVisibility = SYSTEM_UI_FLAGS_HIDDEN
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
protected fun showSystemUI() {
|
||||||
|
window.decorView.systemUiVisibility = SYSTEM_UI_FLAGS_SHOWN
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun onSystemUiVisibilityChanged(isVisible: Boolean) = Unit
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -9,12 +9,11 @@ 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 org.koitharu.kotatsu.core.prefs.AppSettings
|
|
||||||
import org.koitharu.kotatsu.core.ui.util.RecyclerViewOwner
|
|
||||||
import org.koitharu.kotatsu.core.ui.util.WindowInsetsDelegate
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
|
||||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.settings.SettingsHeadersFragment
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
||||||
@@ -25,29 +24,28 @@ abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var settings: AppSettings
|
lateinit var settings: AppSettings
|
||||||
|
|
||||||
@JvmField
|
@Suppress("LeakingThis")
|
||||||
protected val insetsDelegate = WindowInsetsDelegate()
|
protected val insetsDelegate = WindowInsetsDelegate(this)
|
||||||
|
|
||||||
override val recyclerView: RecyclerView
|
override val recyclerView: RecyclerView
|
||||||
get() = listView
|
get() = listView
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
view.setBackgroundColor(view.context.getThemeColor(android.R.attr.colorBackground))
|
|
||||||
listView.clipToPadding = false
|
listView.clipToPadding = false
|
||||||
insetsDelegate.onViewCreated(view)
|
insetsDelegate.onViewCreated(view)
|
||||||
insetsDelegate.addInsetsListener(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
insetsDelegate.removeInsetsListener(this)
|
|
||||||
insetsDelegate.onDestroyView()
|
insetsDelegate.onDestroyView()
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
setTitle(if (titleId != 0) getString(titleId) else null)
|
if (titleId != 0) {
|
||||||
|
setTitle(getString(titleId))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@@ -57,7 +55,9 @@ abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun setTitle(title: CharSequence?) {
|
@Suppress("UsePropertyAccessSyntax")
|
||||||
(activity as? SettingsActivity)?.setSectionTitle(title)
|
protected fun setTitle(title: CharSequence) {
|
||||||
|
(parentFragment as? SettingsHeadersFragment)?.setTitle(title)
|
||||||
|
?: activity?.setTitle(title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
|
import androidx.lifecycle.LifecycleService
|
||||||
|
|
||||||
|
abstract class BaseService : LifecycleService()
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.CountedBooleanLiveData
|
||||||
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
|
abstract class BaseViewModel : ViewModel() {
|
||||||
|
|
||||||
|
protected val loadingCounter = CountedBooleanLiveData()
|
||||||
|
protected val errorEvent = SingleLiveEvent<Throwable>()
|
||||||
|
|
||||||
|
val onError: LiveData<Throwable>
|
||||||
|
get() = errorEvent
|
||||||
|
|
||||||
|
val isLoading: LiveData<Boolean>
|
||||||
|
get() = loadingCounter
|
||||||
|
|
||||||
|
protected fun launchJob(
|
||||||
|
context: CoroutineContext = EmptyCoroutineContext,
|
||||||
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
|
block: suspend CoroutineScope.() -> Unit
|
||||||
|
): Job = viewModelScope.launch(context + createErrorHandler(), start, block)
|
||||||
|
|
||||||
|
protected fun launchLoadingJob(
|
||||||
|
context: CoroutineContext = EmptyCoroutineContext,
|
||||||
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
|
block: suspend CoroutineScope.() -> Unit
|
||||||
|
): Job = viewModelScope.launch(context + createErrorHandler(), start) {
|
||||||
|
loadingCounter.increment()
|
||||||
|
try {
|
||||||
|
block()
|
||||||
|
} finally {
|
||||||
|
loadingCounter.decrement()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createErrorHandler() = CoroutineExceptionHandler { _, throwable ->
|
||||||
|
throwable.printStackTraceDebug()
|
||||||
|
if (throwable !is CancellationException) {
|
||||||
|
errorEvent.postCall(throwable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.core.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
|
||||||
@@ -9,7 +10,7 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
abstract class CoroutineIntentService : BaseService() {
|
abstract class CoroutineIntentService : BaseService() {
|
||||||
|
|
||||||
@@ -19,7 +20,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 START_REDELIVER_INTENT
|
return Service.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)) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.Application.ActivityLifecycleCallbacks
|
import android.app.Application.ActivityLifecycleCallbacks
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.dialog
|
package org.koitharu.kotatsu.base.ui.dialog
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
@@ -26,4 +26,4 @@ class AppBottomSheetDialog(context: Context, theme: Int) : BottomSheetDialog(con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.dialog
|
package org.koitharu.kotatsu.base.ui.dialog
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
@@ -77,4 +77,4 @@ class CheckBoxAlertDialog private constructor(private val delegate: AlertDialog)
|
|||||||
fun create() = CheckBoxAlertDialog(delegate.create())
|
fun create() = CheckBoxAlertDialog(delegate.create())
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.dialog
|
package org.koitharu.kotatsu.base.ui.dialog
|
||||||
|
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
|
|
||||||
@@ -10,4 +10,4 @@ class RememberSelectionDialogListener(initialValue: Int) : DialogInterface.OnCli
|
|||||||
override fun onClick(dialog: DialogInterface?, which: Int) {
|
override fun onClick(dialog: DialogInterface?, which: Int) {
|
||||||
selection = which
|
selection = which
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.dialog
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.BaseAdapter
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.databinding.ItemStorageBinding
|
||||||
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class StorageSelectDialog private constructor(private val delegate: AlertDialog) :
|
||||||
|
DialogInterface by delegate {
|
||||||
|
|
||||||
|
fun show() = delegate.show()
|
||||||
|
|
||||||
|
class Builder(context: Context, storageManager: LocalStorageManager, listener: OnStorageSelectListener) {
|
||||||
|
|
||||||
|
private val adapter = VolumesAdapter(storageManager)
|
||||||
|
private val delegate = MaterialAlertDialogBuilder(context)
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (adapter.isEmpty) {
|
||||||
|
delegate.setMessage(R.string.cannot_find_available_storage)
|
||||||
|
} else {
|
||||||
|
val defaultValue = runBlocking {
|
||||||
|
storageManager.getDefaultWriteableDir()
|
||||||
|
}
|
||||||
|
adapter.selectedItemPosition = adapter.volumes.indexOfFirst {
|
||||||
|
it.first.canonicalPath == defaultValue?.canonicalPath
|
||||||
|
}
|
||||||
|
delegate.setAdapter(adapter) { d, i ->
|
||||||
|
listener.onStorageSelected(adapter.getItem(i).first)
|
||||||
|
d.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setTitle(@StringRes titleResId: Int): Builder {
|
||||||
|
delegate.setTitle(titleResId)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setTitle(title: CharSequence): Builder {
|
||||||
|
delegate.setTitle(title)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setNegativeButton(@StringRes textId: Int): Builder {
|
||||||
|
delegate.setNegativeButton(textId, null)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun create() = StorageSelectDialog(delegate.create())
|
||||||
|
}
|
||||||
|
|
||||||
|
private class VolumesAdapter(storageManager: LocalStorageManager) : BaseAdapter() {
|
||||||
|
|
||||||
|
var selectedItemPosition: Int = -1
|
||||||
|
val volumes = getAvailableVolumes(storageManager)
|
||||||
|
|
||||||
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
|
val view = convertView ?: LayoutInflater.from(parent.context).inflate(R.layout.item_storage, parent, false)
|
||||||
|
val binding = (view.tag as? ItemStorageBinding) ?: ItemStorageBinding.bind(view).also {
|
||||||
|
view.tag = it
|
||||||
|
}
|
||||||
|
val item = volumes[position]
|
||||||
|
binding.imageViewIndicator.isChecked = selectedItemPosition == position
|
||||||
|
binding.textViewTitle.text = item.second
|
||||||
|
binding.textViewSubtitle.text = item.first.path
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItem(position: Int): Pair<File, String> = volumes[position]
|
||||||
|
|
||||||
|
override fun getItemId(position: Int) = position.toLong()
|
||||||
|
|
||||||
|
override fun getCount() = volumes.size
|
||||||
|
|
||||||
|
override fun hasStableIds() = true
|
||||||
|
|
||||||
|
private fun getAvailableVolumes(storageManager: LocalStorageManager): List<Pair<File, String>> {
|
||||||
|
return runBlocking {
|
||||||
|
storageManager.getWriteableDirs().map {
|
||||||
|
it to storageManager.getStorageDisplayName(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun interface OnStorageSelectListener {
|
||||||
|
|
||||||
|
fun onStorageSelected(file: File)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.View.OnClickListener
|
import android.view.View.OnClickListener
|
||||||
@@ -1,41 +1,31 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
abstract class BoundsScrollListener(
|
abstract class BoundsScrollListener(private val offsetTop: Int, private val offsetBottom: Int) :
|
||||||
@JvmField protected val offsetTop: Int,
|
RecyclerView.OnScrollListener() {
|
||||||
@JvmField protected val offsetBottom: Int
|
|
||||||
) : 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)
|
|
||||||
}
|
|
||||||
onPostScrolled(recyclerView, firstVisibleItemPosition, visibleItemCount)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun onScrolledToStart(recyclerView: RecyclerView)
|
abstract fun onScrolledToStart(recyclerView: RecyclerView)
|
||||||
|
|
||||||
abstract fun onScrolledToEnd(recyclerView: RecyclerView)
|
abstract fun onScrolledToEnd(recyclerView: RecyclerView)
|
||||||
|
}
|
||||||
protected open fun onPostScrolled(
|
|
||||||
recyclerView: RecyclerView,
|
|
||||||
firstVisibleItemPosition: Int,
|
|
||||||
visibleItemCount: Int
|
|
||||||
) = Unit
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@@ -34,4 +34,4 @@ class FitHeightGridLayoutManager : GridLayoutManager {
|
|||||||
super.layoutDecoratedWithMargins(child, left, top, right, bottom)
|
super.layoutDecoratedWithMargins(child, left, top, right, bottom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@@ -34,4 +34,4 @@ class FitHeightLinearLayoutManager : LinearLayoutManager {
|
|||||||
super.layoutDecoratedWithMargins(child, left, top, right, bottom)
|
super.layoutDecoratedWithMargins(child, left, top, right, bottom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -12,9 +12,9 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.savedstate.SavedStateRegistry
|
import androidx.savedstate.SavedStateRegistry
|
||||||
import androidx.savedstate.SavedStateRegistryOwner
|
import androidx.savedstate.SavedStateRegistryOwner
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.decor.AbstractSelectionItemDecoration
|
|
||||||
import kotlin.coroutines.EmptyCoroutineContext
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
||||||
|
|
||||||
private const val KEY_SELECTION = "selection"
|
private const val KEY_SELECTION = "selection"
|
||||||
private const val PROVIDER_NAME = "selection_decoration"
|
private const val PROVIDER_NAME = "selection_decoration"
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
||||||
fun interface OnListItemClickListener<I> {
|
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
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
@@ -15,4 +15,4 @@ class PaginationScrollListener(offset: Int, private val callback: Callback) :
|
|||||||
|
|
||||||
fun onScrolledToEnd()
|
fun onScrolledToEnd()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -14,7 +14,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import androidx.savedstate.SavedStateRegistry
|
import androidx.savedstate.SavedStateRegistry
|
||||||
import androidx.savedstate.SavedStateRegistryOwner
|
import androidx.savedstate.SavedStateRegistryOwner
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import org.koitharu.kotatsu.core.ui.list.decor.AbstractSelectionItemDecoration
|
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
||||||
import kotlin.coroutines.EmptyCoroutineContext
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
private const val PROVIDER_NAME = "selection_decoration_sectioned"
|
private const val PROVIDER_NAME = "selection_decoration_sectioned"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list.decor
|
package org.koitharu.kotatsu.base.ui.list.decor
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -59,7 +59,7 @@ abstract class AbstractDividerItemDecoration(context: Context) : RecyclerView.It
|
|||||||
left,
|
left,
|
||||||
parent.paddingTop.toFloat(),
|
parent.paddingTop.toFloat(),
|
||||||
right,
|
right,
|
||||||
(parent.height - parent.paddingBottom).toFloat(),
|
(parent.height - parent.paddingBottom).toFloat()
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
left = 0f
|
left = 0f
|
||||||
@@ -84,4 +84,4 @@ abstract class AbstractDividerItemDecoration(context: Context) : RecyclerView.It
|
|||||||
above: RecyclerView.ViewHolder,
|
above: RecyclerView.ViewHolder,
|
||||||
below: RecyclerView.ViewHolder,
|
below: RecyclerView.ViewHolder,
|
||||||
): Boolean
|
): Boolean
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list.decor
|
package org.koitharu.kotatsu.base.ui.list.decor
|
||||||
|
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
@@ -67,7 +67,7 @@ abstract class AbstractSelectionItemDecoration : RecyclerView.ItemDecoration() {
|
|||||||
if (parent.clipToPadding) {
|
if (parent.clipToPadding) {
|
||||||
canvas.clipRect(
|
canvas.clipRect(
|
||||||
parent.paddingLeft, parent.paddingTop, parent.width - parent.paddingRight,
|
parent.paddingLeft, parent.paddingTop, parent.width - parent.paddingRight,
|
||||||
parent.height - parent.paddingBottom,
|
parent.height - parent.paddingBottom
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,4 +108,4 @@ abstract class AbstractSelectionItemDecoration : RecyclerView.ItemDecoration() {
|
|||||||
bounds: RectF,
|
bounds: RectF,
|
||||||
state: RecyclerView.State,
|
state: RecyclerView.State,
|
||||||
) = Unit
|
) = Unit
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list.decor
|
package org.koitharu.kotatsu.base.ui.list.decor
|
||||||
|
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list.decor
|
package org.koitharu.kotatsu.base.ui.list.decor
|
||||||
|
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.util.SparseIntArray
|
import android.util.SparseIntArray
|
||||||
@@ -13,7 +13,7 @@ class TypedSpacingItemDecoration(
|
|||||||
) : RecyclerView.ItemDecoration() {
|
) : RecyclerView.ItemDecoration() {
|
||||||
|
|
||||||
private val mapping = SparseIntArray(spacingMapping.size)
|
private val mapping = SparseIntArray(spacingMapping.size)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
spacingMapping.forEach { (k, v) -> mapping[k] = v }
|
spacingMapping.forEach { (k, v) -> mapping[k] = v }
|
||||||
}
|
}
|
||||||
@@ -32,4 +32,4 @@ class TypedSpacingItemDecoration(
|
|||||||
}
|
}
|
||||||
outRect.set(spacing, spacing, spacing, spacing)
|
outRect.set(spacing, spacing, spacing, spacing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list.fastscroll
|
package org.koitharu.kotatsu.base.ui.list.fastscroll
|
||||||
|
|
||||||
import android.animation.Animator
|
import android.animation.Animator
|
||||||
import android.animation.AnimatorListenerAdapter
|
import android.animation.AnimatorListenerAdapter
|
||||||
@@ -8,9 +8,9 @@ import android.view.animation.AccelerateInterpolator
|
|||||||
import android.view.animation.DecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
import androidx.core.view.isInvisible
|
import androidx.core.view.isInvisible
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import org.koitharu.kotatsu.core.util.ext.animatorDurationScale
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.measureWidth
|
|
||||||
import kotlin.math.hypot
|
import kotlin.math.hypot
|
||||||
|
import org.koitharu.kotatsu.utils.ext.animatorDurationScale
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureWidth
|
||||||
|
|
||||||
class BubbleAnimator(
|
class BubbleAnimator(
|
||||||
private val bubble: View,
|
private val bubble: View,
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list.fastscroll
|
package org.koitharu.kotatsu.base.ui.list.fastscroll
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import androidx.core.view.isVisible
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
@@ -16,12 +15,6 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
|||||||
|
|
||||||
val fastScroller = FastScroller(context, attrs)
|
val fastScroller = FastScroller(context, attrs)
|
||||||
|
|
||||||
var isFastScrollerEnabled: Boolean = true
|
|
||||||
set(value) {
|
|
||||||
field = value
|
|
||||||
fastScroller.isVisible = value && isVisible
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
fastScroller.id = R.id.fast_scroller
|
fastScroller.id = R.id.fast_scroller
|
||||||
fastScroller.layoutParams = ViewGroup.LayoutParams(
|
fastScroller.layoutParams = ViewGroup.LayoutParams(
|
||||||
@@ -37,7 +30,7 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
|||||||
|
|
||||||
override fun setVisibility(visibility: Int) {
|
override fun setVisibility(visibility: Int) {
|
||||||
super.setVisibility(visibility)
|
super.setVisibility(visibility)
|
||||||
fastScroller.visibility = if (isFastScrollerEnabled) visibility else GONE
|
fastScroller.visibility = visibility
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
@@ -49,4 +42,4 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
|||||||
fastScroller.detachRecyclerView()
|
fastScroller.detachRecyclerView()
|
||||||
super.onDetachedFromWindow()
|
super.onDetachedFromWindow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list.fastscroll
|
package org.koitharu.kotatsu.base.ui.list.fastscroll
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -9,7 +9,6 @@ import android.util.AttributeSet
|
|||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
import androidx.annotation.*
|
import androidx.annotation.*
|
||||||
@@ -23,10 +22,9 @@ import androidx.core.view.isGone
|
|||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.isLayoutReversed
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.parents
|
|
||||||
import org.koitharu.kotatsu.databinding.FastScrollerBinding
|
import org.koitharu.kotatsu.databinding.FastScrollerBinding
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import org.koitharu.kotatsu.utils.ext.isLayoutReversed
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
@@ -58,7 +56,6 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
private var bubbleHeight = 0
|
private var bubbleHeight = 0
|
||||||
private var handleHeight = 0
|
private var handleHeight = 0
|
||||||
private var viewHeight = 0
|
private var viewHeight = 0
|
||||||
private var offset = 0
|
|
||||||
private var hideScrollbar = true
|
private var hideScrollbar = true
|
||||||
private var showBubble = true
|
private var showBubble = true
|
||||||
private var showBubbleAlways = false
|
private var showBubbleAlways = false
|
||||||
@@ -101,7 +98,6 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
showScrollbar()
|
showScrollbar()
|
||||||
if (showBubbleAlways && sectionIndexer != null) showBubble()
|
if (showBubbleAlways && sectionIndexer != null) showBubble()
|
||||||
}
|
}
|
||||||
|
|
||||||
RecyclerView.SCROLL_STATE_IDLE -> if (hideScrollbar && !binding.thumb.isSelected) {
|
RecyclerView.SCROLL_STATE_IDLE -> if (hideScrollbar && !binding.thumb.isSelected) {
|
||||||
handler.postDelayed(scrollbarHider, SCROLLBAR_HIDE_DELAY)
|
handler.postDelayed(scrollbarHider, SCROLLBAR_HIDE_DELAY)
|
||||||
}
|
}
|
||||||
@@ -117,9 +113,6 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
return viewHeight * proportion
|
return viewHeight * proportion
|
||||||
}
|
}
|
||||||
|
|
||||||
val isScrollbarVisible: Boolean
|
|
||||||
get() = binding.scrollbar.isVisible
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
clipChildren = false
|
clipChildren = false
|
||||||
orientation = HORIZONTAL
|
orientation = HORIZONTAL
|
||||||
@@ -143,7 +136,6 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
bubbleSize = getBubbleSize(R.styleable.FastScroller_bubbleSize, BubbleSize.NORMAL)
|
bubbleSize = getBubbleSize(R.styleable.FastScroller_bubbleSize, BubbleSize.NORMAL)
|
||||||
val textSize = getDimension(R.styleable.FastScroller_bubbleTextSize, bubbleSize.textSize)
|
val textSize = getDimension(R.styleable.FastScroller_bubbleTextSize, bubbleSize.textSize)
|
||||||
binding.bubble.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
|
binding.bubble.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
|
||||||
offset = getDimensionPixelOffset(R.styleable.FastScroller_scrollerOffset, offset)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setTrackColor(trackColor)
|
setTrackColor(trackColor)
|
||||||
@@ -170,9 +162,7 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
|
|
||||||
when (event.actionMasked) {
|
when (event.actionMasked) {
|
||||||
MotionEvent.ACTION_DOWN -> {
|
MotionEvent.ACTION_DOWN -> {
|
||||||
if (!isScrollbarVisible || event.x.toInt() !in binding.scrollbar.left..binding.scrollbar.right) {
|
if (event.x.toInt() !in binding.scrollbar.left..binding.scrollbar.right) return false
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
requestDisallowInterceptTouchEvent(true)
|
requestDisallowInterceptTouchEvent(true)
|
||||||
setHandleSelected(true)
|
setHandleSelected(true)
|
||||||
@@ -186,12 +176,10 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
setYPositions()
|
setYPositions()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_MOVE -> {
|
MotionEvent.ACTION_MOVE -> {
|
||||||
setYPositions()
|
setYPositions()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||||
requestDisallowInterceptTouchEvent(false)
|
requestDisallowInterceptTouchEvent(false)
|
||||||
setHandleSelected(false)
|
setHandleSelected(false)
|
||||||
@@ -257,31 +245,27 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
|
|
||||||
layoutParams = (layoutParams as ConstraintLayout.LayoutParams).apply {
|
layoutParams = (layoutParams as ConstraintLayout.LayoutParams).apply {
|
||||||
height = 0
|
height = 0
|
||||||
setMargins(offset, marginTop, offset, marginBottom)
|
setMargins(0, marginTop, 0, marginBottom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is CoordinatorLayout -> layoutParams = (layoutParams as CoordinatorLayout.LayoutParams).apply {
|
is CoordinatorLayout -> layoutParams = (layoutParams as CoordinatorLayout.LayoutParams).apply {
|
||||||
height = LayoutParams.MATCH_PARENT
|
height = LayoutParams.MATCH_PARENT
|
||||||
anchorGravity = GravityCompat.END
|
anchorGravity = GravityCompat.END
|
||||||
anchorId = recyclerViewId
|
anchorId = recyclerViewId
|
||||||
setMargins(offset, marginTop, offset, marginBottom)
|
setMargins(0, marginTop, 0, marginBottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
is FrameLayout -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply {
|
is FrameLayout -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply {
|
||||||
height = LayoutParams.MATCH_PARENT
|
height = LayoutParams.MATCH_PARENT
|
||||||
gravity = GravityCompat.END
|
gravity = GravityCompat.END
|
||||||
setMargins(offset, marginTop, offset, marginBottom)
|
setMargins(0, marginTop, 0, marginBottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
is RelativeLayout -> layoutParams = (layoutParams as RelativeLayout.LayoutParams).apply {
|
is RelativeLayout -> layoutParams = (layoutParams as RelativeLayout.LayoutParams).apply {
|
||||||
height = 0
|
height = 0
|
||||||
addRule(RelativeLayout.ALIGN_TOP, recyclerViewId)
|
addRule(RelativeLayout.ALIGN_TOP, recyclerViewId)
|
||||||
addRule(RelativeLayout.ALIGN_BOTTOM, recyclerViewId)
|
addRule(RelativeLayout.ALIGN_BOTTOM, recyclerViewId)
|
||||||
addRule(RelativeLayout.ALIGN_END, recyclerViewId)
|
addRule(RelativeLayout.ALIGN_END, recyclerViewId)
|
||||||
setMargins(offset, marginTop, offset, marginBottom)
|
setMargins(0, marginTop, 0, marginBottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> throw IllegalArgumentException("Parent ViewGroup must be a ConstraintLayout, CoordinatorLayout, FrameLayout, or RelativeLayout")
|
else -> throw IllegalArgumentException("Parent ViewGroup must be a ConstraintLayout, CoordinatorLayout, FrameLayout, or RelativeLayout")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,12 +287,10 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
|
|
||||||
if (parent is ViewGroup) {
|
if (parent is ViewGroup) {
|
||||||
setLayoutParams(parent as ViewGroup)
|
setLayoutParams(parent as ViewGroup)
|
||||||
} else {
|
} else if (recyclerView.parent is ViewGroup) {
|
||||||
val viewGroup = findValidParent(recyclerView)
|
val viewGroup = recyclerView.parent as ViewGroup
|
||||||
if (viewGroup != null) {
|
viewGroup.addView(this)
|
||||||
viewGroup.addView(this)
|
setLayoutParams(viewGroup)
|
||||||
setLayoutParams(viewGroup)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
recyclerView.addOnScrollListener(scrollListener)
|
recyclerView.addOnScrollListener(scrollListener)
|
||||||
@@ -522,14 +504,6 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
return BubbleSize.values().getOrNull(ordinal) ?: defaultValue
|
return BubbleSize.values().getOrNull(ordinal) ?: defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findValidParent(view: View): ViewGroup? = view.parents.firstNotNullOfOrNull { p ->
|
|
||||||
if (p is FrameLayout || p is ConstraintLayout || p is CoordinatorLayout || p is RelativeLayout) {
|
|
||||||
p as ViewGroup
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val BubbleSize.textSize
|
private val BubbleSize.textSize
|
||||||
@Px get() = resources.getDimension(textSizeId)
|
@Px get() = resources.getDimension(textSizeId)
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.list.fastscroll
|
package org.koitharu.kotatsu.base.ui.list.fastscroll
|
||||||
|
|
||||||
import android.animation.Animator
|
import android.animation.Animator
|
||||||
import android.animation.AnimatorListenerAdapter
|
import android.animation.AnimatorListenerAdapter
|
||||||
@@ -7,7 +7,7 @@ import android.view.ViewPropertyAnimator
|
|||||||
import androidx.core.view.isInvisible
|
import androidx.core.view.isInvisible
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.animatorDurationScale
|
import org.koitharu.kotatsu.utils.ext.animatorDurationScale
|
||||||
|
|
||||||
class ScrollbarAnimator(
|
class ScrollbarAnimator(
|
||||||
private val scrollbar: View,
|
private val scrollbar: View,
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
package org.koitharu.kotatsu.core.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 : OnBackPressedCallback(false) {
|
class ActionModeDelegate {
|
||||||
|
|
||||||
private var activeActionMode: ActionMode? = null
|
private var activeActionMode: ActionMode? = null
|
||||||
private var listeners: MutableList<ActionModeListener>? = null
|
private var listeners: MutableList<ActionModeListener>? = null
|
||||||
@@ -13,19 +12,13 @@ class ActionModeDelegate : OnBackPressedCallback(false) {
|
|||||||
val isActionModeStarted: Boolean
|
val isActionModeStarted: Boolean
|
||||||
get() = activeActionMode != null
|
get() = activeActionMode != null
|
||||||
|
|
||||||
override fun handleOnBackPressed() {
|
|
||||||
finishActionMode()
|
|
||||||
}
|
|
||||||
|
|
||||||
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) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,10 +38,6 @@ class ActionModeDelegate : OnBackPressedCallback(false) {
|
|||||||
owner.lifecycle.addObserver(ListenerLifecycleObserver(listener))
|
owner.lifecycle.addObserver(ListenerLifecycleObserver(listener))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun finishActionMode() {
|
|
||||||
activeActionMode?.finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
private inner class ListenerLifecycleObserver(
|
private inner class ListenerLifecycleObserver(
|
||||||
private val listener: ActionModeListener,
|
private val listener: ActionModeListener,
|
||||||
) : DefaultLifecycleObserver {
|
) : DefaultLifecycleObserver {
|
||||||
@@ -58,4 +47,4 @@ class ActionModeDelegate : OnBackPressedCallback(false) {
|
|||||||
removeListener(listener)
|
removeListener(listener)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
|
|
||||||
@@ -7,4 +7,4 @@ interface ActionModeListener {
|
|||||||
fun onActionModeStarted(mode: ActionMode)
|
fun onActionModeStarted(mode: ActionMode)
|
||||||
|
|
||||||
fun onActionModeFinished(mode: ActionMode)
|
fun onActionModeFinished(mode: ActionMode)
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
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.core.ui.DefaultActivityLifecycleCallbacks
|
|
||||||
import java.util.WeakHashMap
|
import java.util.WeakHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@@ -23,6 +22,6 @@ class ActivityRecreationHandle @Inject constructor() : DefaultActivityLifecycleC
|
|||||||
|
|
||||||
fun recreateAll() {
|
fun recreateAll() {
|
||||||
val snapshot = activities.keys.toList()
|
val snapshot = activities.keys.toList()
|
||||||
snapshot.forEach { ActivityCompat.recreate(it) }
|
snapshot.forEach { it.recreate() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
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
|
||||||
@@ -10,3 +11,8 @@ 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
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.MenuItem.OnActionExpandListener
|
import android.view.MenuItem.OnActionExpandListener
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import androidx.annotation.AnyThread
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
|
class CountedBooleanLiveData : LiveData<Boolean>(false) {
|
||||||
|
|
||||||
|
private val counter = AtomicInteger(0)
|
||||||
|
|
||||||
|
@AnyThread
|
||||||
|
fun increment() {
|
||||||
|
if (counter.getAndIncrement() == 0) {
|
||||||
|
postValue(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AnyThread
|
||||||
|
fun decrement() {
|
||||||
|
if (counter.decrementAndGet() == 0) {
|
||||||
|
postValue(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AnyThread
|
||||||
|
fun reset() {
|
||||||
|
if (counter.getAndSet(0) != 0) {
|
||||||
|
postValue(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
interface RecyclerViewOwner {
|
interface RecyclerViewOwner {
|
||||||
|
|
||||||
val recyclerView: RecyclerView
|
val recyclerView: RecyclerView
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
|
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
||||||
|
|
||||||
class ReversibleAction(
|
class ReversibleAction(
|
||||||
@StringRes val stringResId: Int,
|
@StringRes val stringResId: Int,
|
||||||
val handle: ReversibleHandle?,
|
val handle: ReversibleHandle?,
|
||||||
)
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@@ -10,7 +10,9 @@ 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(
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.annotation.Px
|
import androidx.annotation.Px
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.view.animation.AccelerateDecelerateInterpolator
|
import android.view.animation.AccelerateDecelerateInterpolator
|
||||||
|
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.shape.MaterialShapeDrawable
|
import com.google.android.material.shape.MaterialShapeDrawable
|
||||||
import org.koitharu.kotatsu.core.util.ext.getAnimationDuration
|
import org.koitharu.kotatsu.utils.ext.getAnimationDuration
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
|
|
||||||
class StatusBarDimHelper : AppBarLayout.OnOffsetChangedListener {
|
class StatusBarDimHelper : AppBarLayout.OnOffsetChangedListener {
|
||||||
|
|
||||||
@@ -1,21 +1,19 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.OnApplyWindowInsetsListener
|
import androidx.core.view.OnApplyWindowInsetsListener
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import java.util.LinkedList
|
|
||||||
|
|
||||||
class WindowInsetsDelegate : OnApplyWindowInsetsListener, View.OnLayoutChangeListener {
|
class WindowInsetsDelegate(
|
||||||
|
private val listener: WindowInsetsListener,
|
||||||
|
) : OnApplyWindowInsetsListener, View.OnLayoutChangeListener {
|
||||||
|
|
||||||
@JvmField
|
|
||||||
var handleImeInsets: Boolean = false
|
var handleImeInsets: Boolean = false
|
||||||
|
|
||||||
@JvmField
|
|
||||||
var interceptingWindowInsetsListener: OnApplyWindowInsetsListener? = null
|
var interceptingWindowInsetsListener: OnApplyWindowInsetsListener? = null
|
||||||
|
|
||||||
private val listeners = LinkedList<WindowInsetsListener>()
|
|
||||||
private var lastInsets: Insets? = null
|
private var lastInsets: Insets? = null
|
||||||
|
|
||||||
override fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat {
|
override fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat {
|
||||||
@@ -29,7 +27,7 @@ class WindowInsetsDelegate : OnApplyWindowInsetsListener, View.OnLayoutChangeLis
|
|||||||
handledInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
handledInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
}
|
}
|
||||||
if (newInsets != lastInsets) {
|
if (newInsets != lastInsets) {
|
||||||
listeners.forEach { it.onWindowInsetsChanged(newInsets) }
|
listener.onWindowInsetsChanged(newInsets)
|
||||||
lastInsets = newInsets
|
lastInsets = newInsets
|
||||||
}
|
}
|
||||||
return handledInsets
|
return handledInsets
|
||||||
@@ -52,15 +50,6 @@ class WindowInsetsDelegate : OnApplyWindowInsetsListener, View.OnLayoutChangeLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addInsetsListener(listener: WindowInsetsListener) {
|
|
||||||
listeners.add(listener)
|
|
||||||
lastInsets?.let { listener.onWindowInsetsChanged(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeInsetsListener(listener: WindowInsetsListener) {
|
|
||||||
listeners.remove(listener)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onViewCreated(view: View) {
|
fun onViewCreated(view: View) {
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(view, this)
|
ViewCompat.setOnApplyWindowInsetsListener(view, this)
|
||||||
view.addOnLayoutChangeListener(this)
|
view.addOnLayoutChangeListener(this)
|
||||||
@@ -74,4 +63,4 @@ class WindowInsetsDelegate : OnApplyWindowInsetsListener, View.OnLayoutChangeLis
|
|||||||
|
|
||||||
fun onWindowInsetsChanged(insets: Insets)
|
fun onWindowInsetsChanged(insets: Insets)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.animation.LayoutTransition
|
import android.animation.LayoutTransition
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -21,16 +21,15 @@ 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 org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.getAnimationDuration
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeDrawable
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.parents
|
|
||||||
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.getThemeDrawable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.parents
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
private const val THROTTLE_DELAY = 200L
|
private const val THROTTLE_DELAY = 200L
|
||||||
|
|
||||||
@Deprecated("")
|
|
||||||
class BottomSheetHeaderBar @JvmOverloads constructor(
|
class BottomSheetHeaderBar @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
attrs: AttributeSet? = null,
|
attrs: AttributeSet? = null,
|
||||||
@@ -71,9 +70,6 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
binding.toolbar.subtitle = value
|
binding.toolbar.subtitle = value
|
||||||
}
|
}
|
||||||
|
|
||||||
val isExpanded: Boolean
|
|
||||||
get() = binding.dragHandle.isGone
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setBackgroundResource(R.drawable.sheet_toolbar_background)
|
setBackgroundResource(R.drawable.sheet_toolbar_background)
|
||||||
layoutTransition = LayoutTransition().apply {
|
layoutTransition = LayoutTransition().apply {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Parcel
|
import android.os.Parcel
|
||||||
@@ -101,4 +101,4 @@ class CheckableImageView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,17 @@
|
|||||||
package org.koitharu.kotatsu.core.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.ColorRes
|
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
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.core.util.ext.castOrNull
|
import org.koitharu.kotatsu.utils.ext.castOrNull
|
||||||
import com.google.android.material.R as materialR
|
import org.koitharu.kotatsu.utils.ext.getThemeColorStateList
|
||||||
|
|
||||||
class ChipsView @JvmOverloads constructor(
|
class ChipsView @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
@@ -31,9 +27,6 @@ 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
|
||||||
@@ -47,15 +40,6 @@ 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
|
||||||
@@ -91,24 +75,14 @@ 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
|
||||||
val tint = if (model.tint == 0) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
ContextCompat.getColorStateList(context, model.tint)
|
|
||||||
}
|
|
||||||
chip.chipIconTint = tint ?: defaultChipIconTint
|
|
||||||
chip.checkedIconTint = tint ?: defaultChipIconTint
|
|
||||||
chip.chipStrokeColor = tint ?: defaultChipStrokeColor
|
|
||||||
chip.setTextColor(tint ?: defaultChipTextColor)
|
|
||||||
chip.isClickable = onChipClickListener != null || model.isCheckable
|
|
||||||
chip.isCheckable = model.isCheckable
|
|
||||||
if (model.icon == 0) {
|
if (model.icon == 0) {
|
||||||
chip.chipIcon = null
|
|
||||||
chip.isChipIconVisible = false
|
chip.isChipIconVisible = false
|
||||||
} else {
|
} else {
|
||||||
chip.setChipIconResource(model.icon)
|
|
||||||
chip.isChipIconVisible = true
|
chip.isChipIconVisible = true
|
||||||
|
chip.setChipIconResource(model.icon)
|
||||||
}
|
}
|
||||||
|
chip.isClickable = onChipClickListener != null || model.isCheckable
|
||||||
|
chip.isCheckable = model.isCheckable
|
||||||
chip.isChecked = model.isChecked
|
chip.isChecked = model.isChecked
|
||||||
chip.tag = model.data
|
chip.tag = model.data
|
||||||
}
|
}
|
||||||
@@ -118,9 +92,8 @@ 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 = defaultChipIconTint
|
chip.checkedIconTint = context.getThemeColorStateList(materialR.attr.colorControlNormal)
|
||||||
chip.isCloseIconVisible = onChipCloseClickListener != null
|
chip.isCloseIconVisible = onChipCloseClickListener != null
|
||||||
chip.setOnCloseIconClickListener(chipOnCloseListener)
|
chip.setOnCloseIconClickListener(chipOnCloseListener)
|
||||||
chip.setEnsureMinTouchTargetSize(false)
|
chip.setEnsureMinTouchTargetSize(false)
|
||||||
@@ -140,9 +113,8 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ChipModel(
|
class ChipModel(
|
||||||
@ColorRes val tint: Int,
|
|
||||||
val title: CharSequence,
|
|
||||||
@DrawableRes val icon: Int,
|
@DrawableRes val icon: Int,
|
||||||
|
val title: CharSequence,
|
||||||
val isCheckable: Boolean,
|
val isCheckable: Boolean,
|
||||||
val isChecked: Boolean,
|
val isChecked: Boolean,
|
||||||
val data: Any? = null,
|
val data: Any? = null,
|
||||||
@@ -154,18 +126,18 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
|
|
||||||
other as ChipModel
|
other as ChipModel
|
||||||
|
|
||||||
if (tint != other.tint) return false
|
|
||||||
if (title != other.title) return false
|
|
||||||
if (icon != other.icon) return false
|
if (icon != other.icon) 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
|
||||||
return data == other.data
|
if (data != other.data) return false
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
var result = tint.hashCode()
|
var result = icon
|
||||||
result = 31 * result + title.hashCode()
|
result = 31 * result + title.hashCode()
|
||||||
result = 31 * result + icon.hashCode()
|
|
||||||
result = 31 * result + isCheckable.hashCode()
|
result = 31 * result + isCheckable.hashCode()
|
||||||
result = 31 * result + isChecked.hashCode()
|
result = 31 * result + isChecked.hashCode()
|
||||||
result = 31 * result + (data?.hashCode() ?: 0)
|
result = 31 * result + (data?.hashCode() ?: 0)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@@ -40,4 +40,4 @@ class CoverImageView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
setMeasuredDimension(desiredWidth, desiredHeight)
|
setMeasuredDimension(desiredWidth, desiredHeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -10,8 +10,8 @@ import androidx.core.view.ViewCompat
|
|||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.getAnimationDuration
|
import org.koitharu.kotatsu.utils.ext.getAnimationDuration
|
||||||
import org.koitharu.kotatsu.core.util.ext.measureHeight
|
import org.koitharu.kotatsu.utils.ext.measureHeight
|
||||||
|
|
||||||
class HideBottomNavigationOnScrollBehavior @JvmOverloads constructor(
|
class HideBottomNavigationOnScrollBehavior @JvmOverloads constructor(
|
||||||
context: Context? = null,
|
context: Context? = null,
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -19,7 +19,7 @@ import com.google.android.material.ripple.RippleUtils
|
|||||||
import com.google.android.material.shape.MaterialShapeDrawable
|
import com.google.android.material.shape.MaterialShapeDrawable
|
||||||
import com.google.android.material.shape.ShapeAppearanceModel
|
import com.google.android.material.shape.ShapeAppearanceModel
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.resolveDp
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
class ListItemTextView @JvmOverloads constructor(
|
class ListItemTextView @JvmOverloads constructor(
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.koitharu.kotatsu.core.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
|
||||||
@@ -9,34 +7,48 @@ 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 org.koitharu.kotatsu.core.util.ext.getAnimationDuration
|
import androidx.core.graphics.ColorUtils
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.resolveDp
|
|
||||||
import org.koitharu.kotatsu.parsers.util.replaceWith
|
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
|
import kotlin.random.Random
|
||||||
|
import org.koitharu.kotatsu.parsers.util.replaceWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
|
||||||
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), ValueAnimator.AnimatorUpdateListener, Animator.AnimatorListener {
|
) : View(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
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
|
|
||||||
private var scaleAnimator: ValueAnimator? = null
|
var segments: List<Segment>
|
||||||
|
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) {
|
||||||
@@ -67,56 +79,12 @@ 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()
|
||||||
val maxScale = (scaleFactor * (segmentsData.size - 1)).coerceAtLeast(1f)
|
for (segment in segmentsData) {
|
||||||
for ((index, segment) in segmentsData.withIndex()) {
|
val segmentWidth = (w * segment.percent).coerceAtLeast(cornerSize)
|
||||||
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
|
||||||
}
|
}
|
||||||
@@ -135,7 +103,9 @@ class SegmentedBarView @JvmOverloads constructor(
|
|||||||
other as Segment
|
other as Segment
|
||||||
|
|
||||||
if (percent != other.percent) return false
|
if (percent != other.percent) return false
|
||||||
return color == other.color
|
if (color != other.color) return false
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.text.Selection
|
import android.text.Selection
|
||||||
@@ -26,4 +26,4 @@ class SelectableTextView @JvmOverloads constructor(
|
|||||||
Selection.setSelection(spannableText, text.length)
|
Selection.setSelection(spannableText, text.length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.animation.Animator
|
import android.animation.Animator
|
||||||
import android.animation.AnimatorListenerAdapter
|
import android.animation.AnimatorListenerAdapter
|
||||||
@@ -14,10 +14,10 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|||||||
import androidx.customview.view.AbsSavedState
|
import androidx.customview.view.AbsSavedState
|
||||||
import androidx.interpolator.view.animation.FastOutLinearInInterpolator
|
import androidx.interpolator.view.animation.FastOutLinearInInterpolator
|
||||||
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator
|
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.applySystemAnimatorScale
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.measureHeight
|
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
|
import org.koitharu.kotatsu.utils.ext.applySystemAnimatorScale
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureHeight
|
||||||
|
|
||||||
private const val STATE_DOWN = 1
|
private const val STATE_DOWN = 1
|
||||||
private const val STATE_UP = 2
|
private const val STATE_UP = 2
|
||||||
@@ -92,14 +92,6 @@ class SlidingBottomNavigationView @JvmOverloads constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showOrHide(show: Boolean) {
|
|
||||||
if (show) {
|
|
||||||
show()
|
|
||||||
} else {
|
|
||||||
hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun animateTranslation(targetY: Float, duration: Long, interpolator: TimeInterpolator) {
|
private fun animateTranslation(targetY: Float, duration: Long, interpolator: TimeInterpolator) {
|
||||||
currentAnimator = animate()
|
currentAnimator = animate()
|
||||||
.translationY(targetY)
|
.translationY(targetY)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.data
|
package org.koitharu.kotatsu.bookmarks.data
|
||||||
|
|
||||||
import androidx.room.Dao
|
import androidx.room.*
|
||||||
import androidx.room.Delete
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.Query
|
|
||||||
import androidx.room.Transaction
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaWithTags
|
import org.koitharu.kotatsu.core.db.entity.MangaWithTags
|
||||||
|
|
||||||
@@ -22,7 +18,7 @@ abstract class BookmarksDao {
|
|||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT * FROM manga JOIN bookmarks ON bookmarks.manga_id = manga.manga_id ORDER BY bookmarks.created_at",
|
"SELECT * FROM manga JOIN bookmarks ON bookmarks.manga_id = manga.manga_id ORDER BY bookmarks.created_at"
|
||||||
)
|
)
|
||||||
abstract fun observe(): Flow<Map<MangaWithTags, List<BookmarkEntity>>>
|
abstract fun observe(): Flow<Map<MangaWithTags, List<BookmarkEntity>>>
|
||||||
|
|
||||||
@@ -33,8 +29,5 @@ abstract class BookmarksDao {
|
|||||||
abstract suspend fun delete(entity: BookmarkEntity)
|
abstract suspend fun delete(entity: BookmarkEntity)
|
||||||
|
|
||||||
@Query("DELETE FROM bookmarks WHERE manga_id = :mangaId AND page_id = :pageId")
|
@Query("DELETE FROM bookmarks WHERE manga_id = :mangaId AND page_id = :pageId")
|
||||||
abstract suspend fun delete(mangaId: Long, pageId: Long): Int
|
abstract suspend fun delete(mangaId: Long, pageId: Long)
|
||||||
|
}
|
||||||
@Query("DELETE FROM bookmarks WHERE manga_id = :mangaId AND chapter_id = :chapterId AND page = :page")
|
|
||||||
abstract suspend fun delete(mangaId: Long, chapterId: Long, page: Int): Int
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.domain
|
package org.koitharu.kotatsu.bookmarks.domain
|
||||||
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
import java.util.*
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
class Bookmark(
|
class Bookmark(
|
||||||
val manga: Manga,
|
val manga: Manga,
|
||||||
@@ -15,20 +14,6 @@ class Bookmark(
|
|||||||
val percent: Float,
|
val percent: Float,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val directImageUrl: String?
|
|
||||||
get() = if (isImageUrlDirect()) imageUrl else null
|
|
||||||
|
|
||||||
fun toMangaPage() = MangaPage(
|
|
||||||
id = pageId,
|
|
||||||
url = imageUrl,
|
|
||||||
preview = null,
|
|
||||||
source = manga.source,
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun isImageUrlDirect(): Boolean {
|
|
||||||
return imageUrl.substringAfterLast('.').length in 2..4
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (javaClass != other?.javaClass) return false
|
if (javaClass != other?.javaClass) return false
|
||||||
@@ -42,7 +27,9 @@ class Bookmark(
|
|||||||
if (scroll != other.scroll) return false
|
if (scroll != other.scroll) return false
|
||||||
if (imageUrl != other.imageUrl) return false
|
if (imageUrl != other.imageUrl) return false
|
||||||
if (createdAt != other.createdAt) return false
|
if (createdAt != other.createdAt) return false
|
||||||
return percent == other.percent
|
if (percent != other.percent) return false
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
@@ -56,4 +43,4 @@ class Bookmark(
|
|||||||
result = 31 * result + percent.hashCode()
|
result = 31 * result + percent.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,10 @@ package org.koitharu.kotatsu.bookmarks.domain
|
|||||||
|
|
||||||
import android.database.SQLException
|
import android.database.SQLException
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import dagger.Reusable
|
import javax.inject.Inject
|
||||||
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.bookmarks.data.BookmarkEntity
|
import org.koitharu.kotatsu.bookmarks.data.BookmarkEntity
|
||||||
import org.koitharu.kotatsu.bookmarks.data.toBookmark
|
import org.koitharu.kotatsu.bookmarks.data.toBookmark
|
||||||
import org.koitharu.kotatsu.bookmarks.data.toBookmarks
|
import org.koitharu.kotatsu.bookmarks.data.toBookmarks
|
||||||
@@ -13,13 +14,10 @@ import org.koitharu.kotatsu.core.db.MangaDatabase
|
|||||||
import org.koitharu.kotatsu.core.db.entity.toEntities
|
import org.koitharu.kotatsu.core.db.entity.toEntities
|
||||||
import org.koitharu.kotatsu.core.db.entity.toEntity
|
import org.koitharu.kotatsu.core.db.entity.toEntity
|
||||||
import org.koitharu.kotatsu.core.db.entity.toManga
|
import org.koitharu.kotatsu.core.db.entity.toManga
|
||||||
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.mapItems
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import javax.inject.Inject
|
import org.koitharu.kotatsu.utils.ext.mapItems
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
@Reusable
|
|
||||||
class BookmarksRepository @Inject constructor(
|
class BookmarksRepository @Inject constructor(
|
||||||
private val db: MangaDatabase,
|
private val db: MangaDatabase,
|
||||||
) {
|
) {
|
||||||
@@ -52,14 +50,8 @@ class BookmarksRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun removeBookmark(mangaId: Long, chapterId: Long, page: Int) {
|
suspend fun removeBookmark(mangaId: Long, pageId: Long) {
|
||||||
check(db.bookmarksDao.delete(mangaId, chapterId, page) != 0) {
|
db.bookmarksDao.delete(mangaId, pageId)
|
||||||
"Bookmark not found"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun removeBookmark(bookmark: Bookmark) {
|
|
||||||
removeBookmark(bookmark.manga.id, bookmark.chapterId, bookmark.page)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun removeBookmarks(ids: Map<Manga, Set<Long>>): ReversibleHandle {
|
suspend fun removeBookmarks(ids: Map<Manga, Set<Long>>): ReversibleHandle {
|
||||||
@@ -3,14 +3,16 @@ package org.koitharu.kotatsu.bookmarks.ui
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.ViewGroup
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.fragment.app.commit
|
import androidx.fragment.app.commit
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.ui.BaseActivity
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
||||||
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
||||||
import org.koitharu.kotatsu.main.ui.owners.SnackbarOwner
|
import org.koitharu.kotatsu.main.ui.owners.SnackbarOwner
|
||||||
@@ -22,10 +24,10 @@ class BookmarksActivity :
|
|||||||
SnackbarOwner {
|
SnackbarOwner {
|
||||||
|
|
||||||
override val appBar: AppBarLayout
|
override val appBar: AppBarLayout
|
||||||
get() = viewBinding.appbar
|
get() = binding.appbar
|
||||||
|
|
||||||
override val snackbarHost: CoordinatorLayout
|
override val snackbarHost: CoordinatorLayout
|
||||||
get() = viewBinding.root
|
get() = binding.root
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -41,7 +43,7 @@ class BookmarksActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onWindowInsetsChanged(insets: Insets) {
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
viewBinding.root.updatePadding(
|
binding.root.updatePadding(
|
||||||
left = insets.left,
|
left = insets.left,
|
||||||
right = insets.right,
|
right = insets.right,
|
||||||
)
|
)
|
||||||
@@ -1,12 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.ui
|
package org.koitharu.kotatsu.bookmarks.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.*
|
||||||
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
|
||||||
@@ -15,24 +10,20 @@ 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.ui.BaseFragment
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.decor.SpacingItemDecoration
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.fastscroll.FastScroller
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
||||||
import org.koitharu.kotatsu.bookmarks.data.ids
|
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.core.ui.BaseFragment
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.SectionedSelectionController
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.decor.AbstractSelectionItemDecoration
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.decor.SpacingItemDecoration
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.fastscroll.FastScroller
|
|
||||||
import org.koitharu.kotatsu.core.ui.util.ReversibleAction
|
|
||||||
import org.koitharu.kotatsu.core.ui.util.reverseAsync
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.invalidateNestedItemDecorations
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.scaleUpActivityOptionsOf
|
|
||||||
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
|
||||||
@@ -41,7 +32,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 javax.inject.Inject
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.invalidateNestedItemDecorations
|
||||||
|
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class BookmarksFragment :
|
class BookmarksFragment :
|
||||||
@@ -58,12 +51,12 @@ class BookmarksFragment :
|
|||||||
private var adapter: BookmarksGroupAdapter? = null
|
private var adapter: BookmarksGroupAdapter? = null
|
||||||
private var selectionController: SectionedSelectionController<Manga>? = null
|
private var selectionController: SectionedSelectionController<Manga>? = null
|
||||||
|
|
||||||
override fun onCreateViewBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentListSimpleBinding {
|
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): FragmentListSimpleBinding {
|
||||||
return FragmentListSimpleBinding.inflate(inflater, container, false)
|
return FragmentListSimpleBinding.inflate(inflater, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewBindingCreated(binding: FragmentListSimpleBinding, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewBindingCreated(binding, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
selectionController = SectionedSelectionController(
|
selectionController = SectionedSelectionController(
|
||||||
activity = requireActivity(),
|
activity = requireActivity(),
|
||||||
owner = this,
|
owner = this,
|
||||||
@@ -79,12 +72,12 @@ class BookmarksFragment :
|
|||||||
)
|
)
|
||||||
binding.recyclerView.adapter = adapter
|
binding.recyclerView.adapter = adapter
|
||||||
binding.recyclerView.setHasFixedSize(true)
|
binding.recyclerView.setHasFixedSize(true)
|
||||||
val spacingDecoration = SpacingItemDecoration(resources.getDimensionPixelOffset(R.dimen.grid_spacing))
|
val spacingDecoration = SpacingItemDecoration(view.resources.getDimensionPixelOffset(R.dimen.grid_spacing))
|
||||||
binding.recyclerView.addItemDecoration(spacingDecoration)
|
binding.recyclerView.addItemDecoration(spacingDecoration)
|
||||||
|
|
||||||
viewModel.content.observe(viewLifecycleOwner, ::onListChanged)
|
viewModel.content.observe(viewLifecycleOwner, ::onListChanged)
|
||||||
viewModel.onError.observeEvent(viewLifecycleOwner, SnackbarErrorObserver(binding.recyclerView, this))
|
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
||||||
viewModel.onActionDone.observeEvent(viewLifecycleOwner, ::onActionDone)
|
viewModel.onActionDone.observe(viewLifecycleOwner, ::onActionDone)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -95,12 +88,8 @@ class BookmarksFragment :
|
|||||||
|
|
||||||
override fun onItemClick(item: Bookmark, view: View) {
|
override fun onItemClick(item: Bookmark, view: View) {
|
||||||
if (selectionController?.onItemClick(item.manga, item.pageId) != true) {
|
if (selectionController?.onItemClick(item.manga, item.pageId) != true) {
|
||||||
val intent = ReaderActivity.IntentBuilder(view.context)
|
val intent = ReaderActivity.newIntent(view.context, item)
|
||||||
.bookmark(item)
|
startActivity(intent, scaleUpActivityOptionsOf(view).toBundle())
|
||||||
.incognito(true)
|
|
||||||
.build()
|
|
||||||
startActivity(intent, scaleUpActivityOptionsOf(view))
|
|
||||||
Toast.makeText(view.context, R.string.incognito_mode, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +108,7 @@ class BookmarksFragment :
|
|||||||
override fun onFastScrollStop(fastScroller: FastScroller) = Unit
|
override fun onFastScrollStop(fastScroller: FastScroller) = Unit
|
||||||
|
|
||||||
override fun onSelectionChanged(controller: SectionedSelectionController<Manga>, count: Int) {
|
override fun onSelectionChanged(controller: SectionedSelectionController<Manga>, count: Int) {
|
||||||
requireViewBinding().recyclerView.invalidateNestedItemDecorations()
|
binding.recyclerView.invalidateNestedItemDecorations()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateActionMode(
|
override fun onCreateActionMode(
|
||||||
@@ -143,7 +132,6 @@ class BookmarksFragment :
|
|||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,10 +142,10 @@ class BookmarksFragment :
|
|||||||
): AbstractSelectionItemDecoration = BookmarksSelectionDecoration(requireContext())
|
): AbstractSelectionItemDecoration = BookmarksSelectionDecoration(requireContext())
|
||||||
|
|
||||||
override fun onWindowInsetsChanged(insets: Insets) {
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
requireViewBinding().recyclerView.updatePadding(
|
binding.recyclerView.updatePadding(
|
||||||
bottom = insets.bottom,
|
bottom = insets.bottom,
|
||||||
)
|
)
|
||||||
requireViewBinding().recyclerView.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
binding.recyclerView.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
bottomMargin = insets.bottom
|
bottomMargin = insets.bottom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,6 +154,14 @@ 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
|
||||||
@@ -4,8 +4,8 @@ import android.content.Context
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.core.util.ext.getItem
|
|
||||||
import org.koitharu.kotatsu.list.ui.MangaSelectionDecoration
|
import org.koitharu.kotatsu.list.ui.MangaSelectionDecoration
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getItem
|
||||||
|
|
||||||
class BookmarksSelectionDecoration(context: Context) : MangaSelectionDecoration(context) {
|
class BookmarksSelectionDecoration(context: Context) : MangaSelectionDecoration(context) {
|
||||||
|
|
||||||
@@ -14,4 +14,5 @@ class BookmarksSelectionDecoration(context: Context) : MangaSelectionDecoration(
|
|||||||
val item = holder.getItem(Bookmark::class.java) ?: return RecyclerView.NO_ID
|
val item = holder.getItem(Bookmark::class.java) ?: return RecyclerView.NO_ID
|
||||||
return item.pageId
|
return item.pageId
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
@@ -1,36 +1,33 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.ui
|
package org.koitharu.kotatsu.bookmarks.ui
|
||||||
|
|
||||||
|
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.SharingStarted
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.stateIn
|
|
||||||
import kotlinx.coroutines.plus
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
||||||
import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
||||||
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
|
||||||
import org.koitharu.kotatsu.core.ui.util.ReversibleAction
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.call
|
|
||||||
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.list.ui.model.LoadingState
|
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 javax.inject.Inject
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class BookmarksViewModel @Inject constructor(
|
class BookmarksViewModel @Inject constructor(
|
||||||
private val repository: BookmarksRepository,
|
private val repository: BookmarksRepository,
|
||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
|
|
||||||
val onActionDone = MutableEventFlow<ReversibleAction>()
|
val onActionDone = SingleLiveEvent<ReversibleAction>()
|
||||||
|
|
||||||
val content: StateFlow<List<ListModel>> = repository.observeBookmarks()
|
val content: LiveData<List<ListModel>> = repository.observeBookmarks()
|
||||||
.map { list ->
|
.map { list ->
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
listOf(
|
listOf(
|
||||||
@@ -46,12 +43,12 @@ class BookmarksViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.catch { e -> emit(listOf(e.toErrorState(canRetry = false))) }
|
.catch { e -> emit(listOf(e.toErrorState(canRetry = false))) }
|
||||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, listOf(LoadingState))
|
.asLiveDataDistinct(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.call(ReversibleAction(R.string.bookmarks_removed, handle))
|
onActionDone.postCall(ReversibleAction(R.string.bookmarks_removed, handle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,16 +4,13 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.AdapterDelegateClickListenerAdapter
|
||||||
|
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.core.ui.image.CoverSizeResolver
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.decodeRegion
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.source
|
|
||||||
import org.koitharu.kotatsu.databinding.ItemBookmarkBinding
|
import org.koitharu.kotatsu.databinding.ItemBookmarkBinding
|
||||||
|
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
|
|
||||||
fun bookmarkListAD(
|
fun bookmarkListAD(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -28,15 +25,12 @@ fun bookmarkListAD(
|
|||||||
binding.root.setOnLongClickListener(listener)
|
binding.root.setOnLongClickListener(listener)
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
val data: Any = item.directImageUrl ?: item.toMangaPage()
|
binding.imageViewThumb.newImageRequest(item.imageUrl, item.manga.source)?.run {
|
||||||
binding.imageViewThumb.newImageRequest(lifecycleOwner, data)?.run {
|
|
||||||
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)
|
||||||
decodeRegion(item.scroll)
|
lifecycle(lifecycleOwner)
|
||||||
source(item.manga.source)
|
|
||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,8 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
|
||||||
|
|
||||||
class BookmarksAdapter(
|
class BookmarksAdapter(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -13,15 +13,13 @@ class BookmarksAdapter(
|
|||||||
clickListener: OnListItemClickListener<Bookmark>,
|
clickListener: OnListItemClickListener<Bookmark>,
|
||||||
) : AsyncListDifferDelegationAdapter<Bookmark>(
|
) : AsyncListDifferDelegationAdapter<Bookmark>(
|
||||||
DiffCallback(),
|
DiffCallback(),
|
||||||
bookmarkListAD(coil, lifecycleOwner, clickListener),
|
bookmarkListAD(coil, lifecycleOwner, clickListener)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private class DiffCallback : DiffUtil.ItemCallback<Bookmark>() {
|
private class DiffCallback : DiffUtil.ItemCallback<Bookmark>() {
|
||||||
|
|
||||||
override fun areItemsTheSame(oldItem: Bookmark, newItem: Bookmark): Boolean {
|
override fun areItemsTheSame(oldItem: Bookmark, newItem: Bookmark): Boolean {
|
||||||
return oldItem.manga.id == newItem.manga.id &&
|
return oldItem.manga.id == newItem.manga.id && oldItem.pageId == newItem.pageId
|
||||||
oldItem.chapterId == newItem.chapterId &&
|
|
||||||
oldItem.page == newItem.page
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: Bookmark, newItem: Bookmark): Boolean {
|
override fun areContentsTheSame(oldItem: Bookmark, newItem: Bookmark): Boolean {
|
||||||
@@ -29,4 +27,4 @@ class BookmarksAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,20 +6,18 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.decor.SpacingItemDecoration
|
||||||
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.core.ui.image.CoverSizeResolver
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.SectionedSelectionController
|
|
||||||
import org.koitharu.kotatsu.core.ui.list.decor.SpacingItemDecoration
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.clearItemDecorations
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.source
|
|
||||||
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.clearItemDecorations
|
||||||
|
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
|
|
||||||
fun bookmarksGroupAD(
|
fun bookmarksGroupAD(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -50,13 +48,12 @@ 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(lifecycleOwner, item.manga.coverUrl)?.run {
|
binding.imageViewCover.newImageRequest(item.manga.coverUrl, item.manga.source)?.run {
|
||||||
placeholder(R.drawable.ic_placeholder)
|
placeholder(R.drawable.ic_placeholder)
|
||||||
fallback(R.drawable.ic_placeholder)
|
fallback(R.drawable.ic_placeholder)
|
||||||
error(R.drawable.ic_error_placeholder)
|
error(R.drawable.ic_error_placeholder)
|
||||||
allowRgb565(true)
|
allowRgb565(true)
|
||||||
size(CoverSizeResolver(binding.imageViewCover))
|
lifecycle(lifecycleOwner)
|
||||||
source(item.manga.source)
|
|
||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
binding.textViewTitle.text = item.manga.title
|
binding.textViewTitle.text = item.manga.title
|
||||||
@@ -5,19 +5,14 @@ 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.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.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.list.ui.adapter.*
|
||||||
import org.koitharu.kotatsu.core.ui.list.SectionedSelectionController
|
|
||||||
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.list.ui.model.LoadingFooter
|
|
||||||
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,
|
||||||
@@ -43,7 +38,7 @@ class BookmarksGroupAdapter(
|
|||||||
)
|
)
|
||||||
.addDelegate(loadingStateAD())
|
.addDelegate(loadingStateAD())
|
||||||
.addDelegate(loadingFooterAD())
|
.addDelegate(loadingFooterAD())
|
||||||
.addDelegate(emptyStateListAD(coil, lifecycleOwner, listener))
|
.addDelegate(emptyStateListAD(coil, listener))
|
||||||
.addDelegate(errorStateListAD(listener))
|
.addDelegate(errorStateListAD(listener))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,11 +49,6 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
oldItem is LoadingFooter && newItem is LoadingFooter -> {
|
|
||||||
oldItem.key == newItem.key
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> oldItem.javaClass == newItem.javaClass
|
else -> oldItem.javaClass == newItem.javaClass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,14 +8,12 @@ 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.webkit.CookieManager
|
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.core.network.CommonHeadersInterceptor
|
import org.koitharu.kotatsu.core.network.CommonHeadersInterceptor
|
||||||
import org.koitharu.kotatsu.core.ui.BaseActivity
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.catchingWebViewUnavailability
|
|
||||||
import org.koitharu.kotatsu.databinding.ActivityBrowserBinding
|
import org.koitharu.kotatsu.databinding.ActivityBrowserBinding
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
@@ -26,21 +24,18 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
if (!catchingWebViewUnavailability { setContentView(ActivityBrowserBinding.inflate(layoutInflater)) }) {
|
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(viewBinding.webView.settings) {
|
with(binding.webView.settings) {
|
||||||
javaScriptEnabled = true
|
javaScriptEnabled = true
|
||||||
userAgentString = CommonHeadersInterceptor.userAgentChrome
|
userAgentString = CommonHeadersInterceptor.userAgentChrome
|
||||||
}
|
}
|
||||||
CookieManager.getInstance().setAcceptThirdPartyCookies(viewBinding.webView, true)
|
binding.webView.webViewClient = BrowserClient(this)
|
||||||
viewBinding.webView.webViewClient = BrowserClient(this)
|
binding.webView.webChromeClient = ProgressChromeClient(binding.progressBar)
|
||||||
viewBinding.webView.webChromeClient = ProgressChromeClient(viewBinding.progressBar)
|
onBackPressedCallback = WebViewBackPressedCallback(binding.webView)
|
||||||
onBackPressedCallback = WebViewBackPressedCallback(viewBinding.webView)
|
|
||||||
onBackPressedDispatcher.addCallback(onBackPressedCallback)
|
onBackPressedDispatcher.addCallback(onBackPressedCallback)
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
return
|
return
|
||||||
@@ -53,18 +48,18 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
intent?.getStringExtra(EXTRA_TITLE) ?: getString(R.string.loading_),
|
intent?.getStringExtra(EXTRA_TITLE) ?: getString(R.string.loading_),
|
||||||
url,
|
url,
|
||||||
)
|
)
|
||||||
viewBinding.webView.loadUrl(url)
|
binding.webView.loadUrl(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
viewBinding.webView.saveState(outState)
|
binding.webView.saveState(outState)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onRestoreInstanceState(savedInstanceState)
|
super.onRestoreInstanceState(savedInstanceState)
|
||||||
viewBinding.webView.restoreState(savedInstanceState)
|
binding.webView.restoreState(savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
@@ -75,14 +70,14 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
viewBinding.webView.stopLoading()
|
binding.webView.stopLoading()
|
||||||
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(viewBinding.webView.url)
|
intent.data = Uri.parse(binding.webView.url)
|
||||||
try {
|
try {
|
||||||
startActivity(Intent.createChooser(intent, item.title))
|
startActivity(Intent.createChooser(intent, item.title))
|
||||||
} catch (_: ActivityNotFoundException) {
|
} catch (_: ActivityNotFoundException) {
|
||||||
@@ -94,23 +89,22 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
viewBinding.webView.onPause()
|
binding.webView.onPause()
|
||||||
super.onPause()
|
super.onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
viewBinding.webView.onResume()
|
binding.webView.onResume()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
viewBinding.webView.stopLoading()
|
binding.webView.destroy()
|
||||||
viewBinding.webView.destroy()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLoadingStateChanged(isLoading: Boolean) {
|
override fun onLoadingStateChanged(isLoading: Boolean) {
|
||||||
viewBinding.progressBar.isVisible = isLoading
|
binding.progressBar.isVisible = isLoading
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTitleChanged(title: CharSequence, subtitle: CharSequence?) {
|
override fun onTitleChanged(title: CharSequence, subtitle: CharSequence?) {
|
||||||
@@ -123,10 +117,10 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onWindowInsetsChanged(insets: Insets) {
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
viewBinding.appbar.updatePadding(
|
binding.appbar.updatePadding(
|
||||||
top = insets.top,
|
top = insets.top,
|
||||||
)
|
)
|
||||||
viewBinding.root.updatePadding(
|
binding.root.updatePadding(
|
||||||
left = insets.left,
|
left = insets.left,
|
||||||
right = insets.right,
|
right = insets.right,
|
||||||
bottom = insets.bottom,
|
bottom = insets.bottom,
|
||||||