Compare commits
97 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 627a00beb4 | |||
| e00ed13ad1 | |||
| 893fa6bd90 | |||
| 512188c8dd | |||
| aae6761809 | |||
| c3f055d0c4 | |||
|
|
04d5df20d1 | ||
|
|
665eca0699 | ||
|
|
9a1534464f | ||
|
|
f856fc6fac | ||
| 4af8e73303 | |||
| 23239f1fec | |||
| 853e4d6fde | |||
| 14a37ad16e | |||
| d604ff3c24 | |||
|
|
4f9eee7d46 | ||
|
|
fe673a94ed | ||
| bcd891d653 | |||
| 1e75edf262 | |||
| 73478d6a81 | |||
| 982080a930 | |||
| 66cd5070dc | |||
|
|
c05b0eaa59 | ||
|
|
29a073d844 | ||
| a0e69428e4 | |||
| 3f6a103915 | |||
| 734765dbdd | |||
|
|
117c4c5978 | ||
|
|
13e33a6614 | ||
|
|
affb495136 | ||
|
|
9b2dafd668 | ||
| 5f32c0401f | |||
| f35f40ed27 | |||
| 46f0d3ef74 | |||
| c27c785ac2 | |||
| 6e844e8c3b | |||
| 4186c36f30 | |||
| 2d727a0da8 | |||
| 39e574e9dc | |||
| efb94cbd67 | |||
| 757e33dfb4 | |||
| ab9bdf9f07 | |||
| a68632a888 | |||
| 9b0dc8b413 | |||
| f43fe5830e | |||
| ce616b328c | |||
| 824a8ff97a | |||
|
|
ef9018b92f | ||
|
|
a088d10935 | ||
| 2e561697ac | |||
| d242acd502 | |||
| d37b44d3f6 | |||
| 6243fc88c9 | |||
|
|
f74e865b06 | ||
|
|
1a2bc02188 | ||
| b0153e9f61 | |||
|
|
7f3fc1b88a | ||
|
|
40bf0c75bf | ||
|
|
9407bd205c | ||
|
|
3317c8dddc | ||
| fc4b6eb1af | |||
| 2aaaf2f4a2 | |||
| 92aa96a644 | |||
| 6a0a4023ad | |||
| 8569610e52 | |||
| 51ffa4d469 | |||
| e4c4d2bbf0 | |||
| 35d6f1fb34 | |||
| edac5fda8c | |||
| 040d3e4433 | |||
| 011dd4c069 | |||
| b4f93fc0a5 | |||
| e0d74ba2a9 | |||
| 935826617e | |||
| b9f2effb86 | |||
| 5c86de555a | |||
| c4e7807d18 | |||
| 78dd0588ce | |||
| 2d73894880 | |||
| 8ac19e557b | |||
| f677a75ad1 | |||
| 8e55a4d824 | |||
| 6b5d8ff0f1 | |||
| 0c7da53349 | |||
| 2a3cc11728 | |||
| a806634bc0 | |||
| 6879d046f8 | |||
| 0248f84ca0 | |||
| ff0706dae5 | |||
| b73fe0398f | |||
| f78ae4a818 | |||
| 072f6d8c69 | |||
| 68b68eb4c5 | |||
| 7f95eead50 | |||
|
|
1935de8f20 | ||
| c1e9fde6e8 | |||
| d853bb2c62 |
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
@@ -1 +1,2 @@
|
|||||||
custom: ["https://yoomoney.ru/to/410012543938752"]
|
custom: ["https://yoomoney.ru/to/410012543938752"]
|
||||||
|
ko_fi: koitharu
|
||||||
|
|||||||
3
.idea/kotlinc.xml
generated
3
.idea/kotlinc.xml
generated
@@ -3,4 +3,7 @@
|
|||||||
<component name="Kotlin2JvmCompilerArguments">
|
<component name="Kotlin2JvmCompilerArguments">
|
||||||
<option name="jvmTarget" value="1.8" />
|
<option name="jvmTarget" value="1.8" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="KotlinJpsPluginSettings">
|
||||||
|
<option name="version" value="1.7.10" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
6
.idea/ktlint.xml
generated
6
.idea/ktlint.xml
generated
@@ -1,7 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="KtlintProjectConfiguration">
|
<component name="KtlintProjectConfiguration">
|
||||||
|
<enableKtlint>false</enableKtlint>
|
||||||
<androidMode>true</androidMode>
|
<androidMode>true</androidMode>
|
||||||
<treatAsErrors>false</treatAsErrors>
|
<treatAsErrors>false</treatAsErrors>
|
||||||
|
<disabledRules>
|
||||||
|
<list>
|
||||||
|
<option value="no-empty-first-line-in-method-block" />
|
||||||
|
</list>
|
||||||
|
</disabledRules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -7,16 +7,16 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 32
|
compileSdkVersion 33
|
||||||
buildToolsVersion '32.0.0'
|
buildToolsVersion '33.0.0'
|
||||||
namespace 'org.koitharu.kotatsu'
|
namespace 'org.koitharu.kotatsu'
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 32
|
targetSdkVersion 33
|
||||||
versionCode 490
|
versionCode 499
|
||||||
versionName '4.0-a1'
|
versionName '4.0-rc1'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
@@ -29,6 +29,8 @@ android {
|
|||||||
// define this values in your local.properties file
|
// define this values in your local.properties file
|
||||||
buildConfigField 'String', 'SHIKIMORI_CLIENT_ID', "\"${localProperty('shikimori.clientId')}\""
|
buildConfigField 'String', 'SHIKIMORI_CLIENT_ID', "\"${localProperty('shikimori.clientId')}\""
|
||||||
buildConfigField 'String', 'SHIKIMORI_CLIENT_SECRET', "\"${localProperty('shikimori.clientSecret')}\""
|
buildConfigField 'String', 'SHIKIMORI_CLIENT_SECRET', "\"${localProperty('shikimori.clientSecret')}\""
|
||||||
|
resValue "string", "acra_login", "${localProperty('acra.login')}"
|
||||||
|
resValue "string", "acra_password", "${localProperty('acra.password')}"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
debug {
|
debug {
|
||||||
@@ -58,6 +60,7 @@ android {
|
|||||||
'-opt-in=kotlinx.coroutines.FlowPreview',
|
'-opt-in=kotlinx.coroutines.FlowPreview',
|
||||||
'-opt-in=kotlin.contracts.ExperimentalContracts',
|
'-opt-in=kotlin.contracts.ExperimentalContracts',
|
||||||
'-opt-in=coil.annotation.ExperimentalCoilApi',
|
'-opt-in=coil.annotation.ExperimentalCoilApi',
|
||||||
|
'-opt-in=com.google.android.material.badge.ExperimentalBadgeUtils',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
lint {
|
lint {
|
||||||
@@ -80,15 +83,15 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation('com.github.KotatsuApp:kotatsu-parsers:8709c3dd0c') {
|
implementation('com.github.KotatsuApp:kotatsu-parsers:b1990c7918') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
||||||
|
|
||||||
implementation 'androidx.core:core-ktx:1.8.0'
|
implementation 'androidx.core:core-ktx:1.9.0'
|
||||||
implementation 'androidx.activity:activity-ktx:1.5.1'
|
implementation 'androidx.activity:activity-ktx:1.6.0'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.5.2'
|
implementation 'androidx.fragment:fragment-ktx:1.5.3'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-service:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-service:2.5.1'
|
||||||
@@ -99,8 +102,8 @@ dependencies {
|
|||||||
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
|
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
|
||||||
implementation 'androidx.preference:preference-ktx:1.2.0'
|
implementation 'androidx.preference:preference-ktx:1.2.0'
|
||||||
implementation 'androidx.work:work-runtime-ktx:2.7.1'
|
implementation 'androidx.work:work-runtime-ktx:2.7.1'
|
||||||
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha04'
|
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
||||||
implementation 'com.google.android.material:material:1.7.0-beta01'
|
implementation 'com.google.android.material:material:1.7.0-rc01'
|
||||||
//noinspection LifecycleAnnotationProcessorWithJava8
|
//noinspection LifecycleAnnotationProcessorWithJava8
|
||||||
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.1'
|
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.1'
|
||||||
|
|
||||||
@@ -115,19 +118,18 @@ dependencies {
|
|||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
||||||
|
|
||||||
implementation "com.google.dagger:hilt-android:2.42"
|
implementation "com.google.dagger:hilt-android:2.44"
|
||||||
kapt "com.google.dagger:hilt-compiler:2.42"
|
kapt "com.google.dagger:hilt-compiler:2.44"
|
||||||
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.1.0'
|
implementation 'io.coil-kt:coil-base:2.2.1'
|
||||||
implementation 'io.coil-kt:coil-svg:2.1.0'
|
implementation 'io.coil-kt:coil-svg:2.2.1'
|
||||||
// implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
|
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:0ff0278f0f'
|
||||||
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:d3aa1d2beb'
|
|
||||||
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
||||||
|
|
||||||
implementation 'ch.acra:acra-mail:5.9.5'
|
implementation 'ch.acra:acra-http:5.9.6'
|
||||||
implementation 'ch.acra:acra-dialog:5.9.5'
|
implementation 'ch.acra:acra-dialog:5.9.6'
|
||||||
|
|
||||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
|
||||||
|
|
||||||
@@ -143,8 +145,8 @@ dependencies {
|
|||||||
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.room:room-testing:2.4.3'
|
androidTestImplementation 'androidx.room:room-testing:2.4.3'
|
||||||
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.13.0'
|
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
|
||||||
|
|
||||||
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.42'
|
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.44'
|
||||||
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.42'
|
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.44'
|
||||||
}
|
}
|
||||||
|
|||||||
5
app/proguard-rules.pro
vendored
5
app/proguard-rules.pro
vendored
@@ -10,4 +10,7 @@
|
|||||||
}
|
}
|
||||||
-keep public class ** extends org.koitharu.kotatsu.base.ui.BaseFragment
|
-keep public class ** extends org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
-keep class org.koitharu.kotatsu.core.db.entity.* { *; }
|
-keep class org.koitharu.kotatsu.core.db.entity.* { *; }
|
||||||
-dontwarn okhttp3.internal.platform.ConscryptPlatform
|
-dontwarn okhttp3.internal.platform.ConscryptPlatform
|
||||||
|
|
||||||
|
-keep class org.koitharu.kotatsu.core.exceptions.* { *; }
|
||||||
|
-keep class org.koitharu.kotatsu.settings.NotificationSettingsLegacyFragment
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
|
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
|
||||||
<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" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="org.koitharu.kotatsu.KotatsuApp"
|
android:name="org.koitharu.kotatsu.KotatsuApp"
|
||||||
@@ -132,11 +133,14 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.sync.ui.SyncAuthActivity"
|
android:name="org.koitharu.kotatsu.sync.ui.SyncAuthActivity"
|
||||||
android:label="@string/sync" />
|
android:label="@string/sync" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity"
|
||||||
|
android:label="@string/color_correction" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"
|
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"
|
||||||
android:stopWithTask="false"
|
android:foregroundServiceType="dataSync"
|
||||||
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 android:name="org.koitharu.kotatsu.local.ui.ImportService" />
|
||||||
<service
|
<service
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.acra.ReportField
|
import org.acra.ReportField
|
||||||
import org.acra.config.dialog
|
import org.acra.config.dialog
|
||||||
import org.acra.config.mailSender
|
import org.acra.config.httpSender
|
||||||
import org.acra.data.StringFormat
|
import org.acra.data.StringFormat
|
||||||
import org.acra.ktx.initAcra
|
import org.acra.ktx.initAcra
|
||||||
|
import org.acra.sender.HttpSender
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.local.data.PagesCache
|
import org.koitharu.kotatsu.local.data.PagesCache
|
||||||
@@ -59,16 +60,24 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
super.attachBaseContext(base)
|
super.attachBaseContext(base)
|
||||||
initAcra {
|
initAcra {
|
||||||
buildConfigClass = BuildConfig::class.java
|
buildConfigClass = BuildConfig::class.java
|
||||||
reportFormat = StringFormat.KEY_VALUE_LIST
|
reportFormat = StringFormat.JSON
|
||||||
|
excludeMatchingSharedPreferencesKeys = listOf(
|
||||||
|
"sources_\\w+",
|
||||||
|
)
|
||||||
|
httpSender {
|
||||||
|
uri = getString(R.string.url_error_report)
|
||||||
|
basicAuthLogin = getString(R.string.acra_login)
|
||||||
|
basicAuthPassword = getString(R.string.acra_password)
|
||||||
|
httpMethod = HttpSender.Method.POST
|
||||||
|
}
|
||||||
reportContent = listOf(
|
reportContent = listOf(
|
||||||
ReportField.PACKAGE_NAME,
|
ReportField.PACKAGE_NAME,
|
||||||
ReportField.APP_VERSION_CODE,
|
ReportField.APP_VERSION_CODE,
|
||||||
ReportField.APP_VERSION_NAME,
|
ReportField.APP_VERSION_NAME,
|
||||||
ReportField.ANDROID_VERSION,
|
ReportField.ANDROID_VERSION,
|
||||||
ReportField.PHONE_MODEL,
|
ReportField.PHONE_MODEL,
|
||||||
ReportField.CRASH_CONFIGURATION,
|
|
||||||
ReportField.STACK_TRACE,
|
ReportField.STACK_TRACE,
|
||||||
ReportField.CUSTOM_DATA,
|
ReportField.CRASH_CONFIGURATION,
|
||||||
ReportField.SHARED_PREFERENCES,
|
ReportField.SHARED_PREFERENCES,
|
||||||
)
|
)
|
||||||
dialog {
|
dialog {
|
||||||
@@ -78,11 +87,6 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
resIcon = R.drawable.ic_alert_outline
|
resIcon = R.drawable.ic_alert_outline
|
||||||
resTheme = android.R.style.Theme_Material_Light_Dialog_Alert
|
resTheme = android.R.style.Theme_Material_Light_Dialog_Alert
|
||||||
}
|
}
|
||||||
mailSender {
|
|
||||||
mailTo = getString(R.string.email_error_report)
|
|
||||||
reportAsFile = true
|
|
||||||
reportFileName = "stacktrace.txt"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ import java.util.zip.ZipFile
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.runInterruptible
|
import kotlinx.coroutines.runInterruptible
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
@@ -23,6 +26,7 @@ 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.parsers.util.await
|
||||||
|
import org.koitharu.kotatsu.reader.domain.ReaderColorFilter
|
||||||
|
|
||||||
private const val MIN_WEBTOON_RATIO = 2
|
private const val MIN_WEBTOON_RATIO = 2
|
||||||
|
|
||||||
@@ -31,15 +35,22 @@ class MangaDataRepository @Inject constructor(
|
|||||||
private val db: MangaDatabase,
|
private val db: MangaDatabase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun savePreferences(manga: Manga, mode: ReaderMode) {
|
suspend fun saveReaderMode(manga: Manga, mode: ReaderMode) {
|
||||||
val tags = manga.tags.toEntities()
|
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
db.tagsDao.upsert(tags)
|
storeManga(manga)
|
||||||
db.mangaDao.upsert(manga.toEntity(), tags)
|
val entity = db.preferencesDao.find(manga.id) ?: newEntity(manga.id)
|
||||||
|
db.preferencesDao.upsert(entity.copy(mode = mode.id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun saveColorFilter(manga: Manga, colorFilter: ReaderColorFilter?) {
|
||||||
|
db.withTransaction {
|
||||||
|
storeManga(manga)
|
||||||
|
val entity = db.preferencesDao.find(manga.id) ?: newEntity(manga.id)
|
||||||
db.preferencesDao.upsert(
|
db.preferencesDao.upsert(
|
||||||
MangaPrefsEntity(
|
entity.copy(
|
||||||
mangaId = manga.id,
|
cfBrightness = colorFilter?.brightness ?: 0f,
|
||||||
mode = mode.id,
|
cfContrast = colorFilter?.contrast ?: 0f,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -49,6 +60,16 @@ class MangaDataRepository @Inject constructor(
|
|||||||
return db.preferencesDao.find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
|
return db.preferencesDao.find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getColorFilter(mangaId: Long): ReaderColorFilter? {
|
||||||
|
return db.preferencesDao.find(mangaId)?.getColorFilterOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun observeColorFilter(mangaId: Long): Flow<ReaderColorFilter?> {
|
||||||
|
return db.preferencesDao.observe(mangaId)
|
||||||
|
.map { it?.getColorFilterOrNull() }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun findMangaById(mangaId: Long): Manga? {
|
suspend fun findMangaById(mangaId: Long): Manga? {
|
||||||
return db.mangaDao.find(mangaId)?.toManga()
|
return db.mangaDao.find(mangaId)?.toManga()
|
||||||
}
|
}
|
||||||
@@ -71,6 +92,14 @@ class MangaDataRepository @Inject constructor(
|
|||||||
return db.tagsDao.findTags(source.name).toMangaTags()
|
return db.tagsDao.findTags(source.name).toMangaTags()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun MangaPrefsEntity.getColorFilterOrNull(): ReaderColorFilter? {
|
||||||
|
return if (cfBrightness != 0f || cfContrast != 0f) {
|
||||||
|
ReaderColorFilter(cfBrightness, cfContrast)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatic determine type of manga by page size
|
* Automatic determine type of manga by page size
|
||||||
* @return ReaderMode.WEBTOON if page is wide
|
* @return ReaderMode.WEBTOON if page is wide
|
||||||
@@ -104,6 +133,13 @@ class MangaDataRepository @Inject constructor(
|
|||||||
return size.width * MIN_WEBTOON_RATIO < size.height
|
return size.width * MIN_WEBTOON_RATIO < size.height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun newEntity(mangaId: Long) = MangaPrefsEntity(
|
||||||
|
mangaId = mangaId,
|
||||||
|
mode = -1,
|
||||||
|
cfBrightness = 0f,
|
||||||
|
cfContrast = 0f,
|
||||||
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
suspend fun getImageMimeType(file: File): String? = runInterruptible(Dispatchers.IO) {
|
suspend fun getImageMimeType(file: File): String? = runInterruptible(Dispatchers.IO) {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import android.net.Uri
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
|
||||||
class MangaIntent private constructor(
|
class MangaIntent private constructor(
|
||||||
val manga: Manga?,
|
val manga: Manga?,
|
||||||
@@ -13,15 +15,15 @@ class MangaIntent private constructor(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
constructor(intent: Intent?) : this(
|
constructor(intent: Intent?) : this(
|
||||||
manga = intent?.getParcelableExtra<ParcelableManga>(KEY_MANGA)?.manga,
|
manga = intent?.getParcelableExtraCompat<ParcelableManga>(KEY_MANGA)?.manga,
|
||||||
mangaId = intent?.getLongExtra(KEY_ID, ID_NONE) ?: ID_NONE,
|
mangaId = intent?.getLongExtra(KEY_ID, ID_NONE) ?: ID_NONE,
|
||||||
uri = intent?.data
|
uri = intent?.data,
|
||||||
)
|
)
|
||||||
|
|
||||||
constructor(args: Bundle?) : this(
|
constructor(args: Bundle?) : this(
|
||||||
manga = args?.getParcelable<ParcelableManga>(KEY_MANGA)?.manga,
|
manga = args?.getParcelableCompat<ParcelableManga>(KEY_MANGA)?.manga,
|
||||||
mangaId = args?.getLong(KEY_ID, ID_NONE) ?: ID_NONE,
|
mangaId = args?.getLong(KEY_ID, ID_NONE) ?: ID_NONE,
|
||||||
uri = null
|
uri = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package org.koitharu.kotatsu.base.domain
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
fun interface ReversibleHandle {
|
fun interface ReversibleHandle {
|
||||||
|
|
||||||
@@ -11,8 +14,10 @@ fun interface ReversibleHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ReversibleHandle.reverseAsync() = processLifecycleScope.launch(Dispatchers.Default) {
|
fun ReversibleHandle.reverseAsync() = processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
reverse()
|
withContext(NonCancellable) {
|
||||||
|
reverse()
|
||||||
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
it.printStackTraceDebug()
|
it.printStackTraceDebug()
|
||||||
}
|
}
|
||||||
@@ -21,4 +26,4 @@ fun ReversibleHandle.reverseAsync() = processLifecycleScope.launch(Dispatchers.D
|
|||||||
operator fun ReversibleHandle.plus(other: ReversibleHandle) = ReversibleHandle {
|
operator fun ReversibleHandle.plus(other: ReversibleHandle) = ReversibleHandle {
|
||||||
this.reverse()
|
this.reverse()
|
||||||
other.reverse()
|
other.reverse()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ abstract class AlertDialogFragment<B : ViewBinding> : DialogFragment() {
|
|||||||
viewBinding = binding
|
viewBinding = binding
|
||||||
return MaterialAlertDialogBuilder(requireContext(), theme)
|
return MaterialAlertDialogBuilder(requireContext(), theme)
|
||||||
.setView(binding.root)
|
.setView(binding.root)
|
||||||
.also(::onBuildDialog)
|
.run(::onBuildDialog)
|
||||||
.create()
|
.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun onCreateView(
|
final override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?,
|
||||||
) = viewBinding?.root
|
) = viewBinding?.root
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@@ -37,9 +37,9 @@ abstract class AlertDialogFragment<B : ViewBinding> : DialogFragment() {
|
|||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun onBuildDialog(builder: MaterialAlertDialogBuilder) = Unit
|
open fun onBuildDialog(builder: MaterialAlertDialogBuilder): MaterialAlertDialogBuilder = builder
|
||||||
|
|
||||||
protected fun bindingOrNull(): B? = viewBinding
|
protected fun bindingOrNull(): B? = viewBinding
|
||||||
|
|
||||||
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.appcompat.widget.ActionBarContextView
|
import androidx.appcompat.widget.ActionBarContextView
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.app.ActivityCompat
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
@@ -21,7 +20,6 @@ import androidx.core.view.WindowInsetsCompat
|
|||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import dagger.hilt.android.EntryPointAccessors
|
import dagger.hilt.android.EntryPointAccessors
|
||||||
import javax.inject.Inject
|
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
||||||
@@ -31,6 +29,7 @@ import org.koitharu.kotatsu.base.ui.util.inject
|
|||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
abstract class BaseActivity<B : ViewBinding> :
|
abstract class BaseActivity<B : ViewBinding> :
|
||||||
AppCompatActivity(),
|
AppCompatActivity(),
|
||||||
@@ -92,7 +91,8 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) { // TODO remove
|
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) { // TODO remove
|
||||||
ActivityCompat.recreate(this)
|
// ActivityCompat.recreate(this)
|
||||||
|
TODO("Test error")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event)
|
return super.onKeyDown(keyCode, event)
|
||||||
@@ -134,6 +134,7 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
window.statusBarColor = getThemeColor(android.R.attr.statusBarColor)
|
window.statusBarColor = getThemeColor(android.R.attr.statusBarColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if ( // https://issuetracker.google.com/issues/139738913
|
if ( // https://issuetracker.google.com/issues/139738913
|
||||||
Build.VERSION.SDK_INT == Build.VERSION_CODES.Q &&
|
Build.VERSION.SDK_INT == Build.VERSION_CODES.Q &&
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import android.app.Service
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
abstract class CoroutineIntentService : BaseService() {
|
abstract class CoroutineIntentService : BaseService() {
|
||||||
|
|
||||||
@@ -21,11 +23,13 @@ abstract class CoroutineIntentService : BaseService() {
|
|||||||
return Service.START_REDELIVER_INTENT
|
return Service.START_REDELIVER_INTENT
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchCoroutine(intent: Intent?, startId: Int) = lifecycleScope.launch {
|
private fun launchCoroutine(intent: Intent?, startId: Int) = lifecycleScope.launch(errorHandler(startId)) {
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
try {
|
try {
|
||||||
withContext(dispatcher) {
|
if (intent != null) {
|
||||||
processIntent(intent)
|
withContext(dispatcher) {
|
||||||
|
processIntent(startId, intent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
stopSelf(startId)
|
stopSelf(startId)
|
||||||
@@ -33,5 +37,12 @@ abstract class CoroutineIntentService : BaseService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract suspend fun processIntent(intent: Intent?)
|
protected abstract suspend fun processIntent(startId: Int, intent: Intent)
|
||||||
|
|
||||||
|
protected abstract fun onError(startId: Int, error: Throwable)
|
||||||
|
|
||||||
|
private fun errorHandler(startId: Int) = CoroutineExceptionHandler { _, throwable ->
|
||||||
|
throwable.printStackTraceDebug()
|
||||||
|
onError(startId, throwable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,19 @@ class SectionedSelectionController<T : Any>(
|
|||||||
startActionMode()
|
startActionMode()
|
||||||
notifySelectionChanged()
|
notifySelectionChanged()
|
||||||
}
|
}
|
||||||
recyclerView.addItemDecoration(decoration)
|
var shouldAddDecoration = true
|
||||||
|
for (i in (0 until recyclerView.itemDecorationCount).reversed()) {
|
||||||
|
val decor = recyclerView.getItemDecorationAt(i)
|
||||||
|
if (decor === decoration) {
|
||||||
|
shouldAddDecoration = false
|
||||||
|
break
|
||||||
|
} else if (decor.javaClass == decoration.javaClass) {
|
||||||
|
recyclerView.removeItemDecorationAt(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shouldAddDecoration) {
|
||||||
|
recyclerView.addItemDecoration(decoration)
|
||||||
|
}
|
||||||
if (pendingData?.isEmpty() == true) {
|
if (pendingData?.isEmpty() == true) {
|
||||||
pendingData = null
|
pendingData = null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,16 +8,18 @@ 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 kotlin.math.hypot
|
||||||
import org.koitharu.kotatsu.utils.ext.animatorDurationScale
|
import org.koitharu.kotatsu.utils.ext.animatorDurationScale
|
||||||
import org.koitharu.kotatsu.utils.ext.measureWidth
|
import org.koitharu.kotatsu.utils.ext.measureWidth
|
||||||
import kotlin.math.hypot
|
|
||||||
|
|
||||||
class BubbleAnimator(
|
class BubbleAnimator(
|
||||||
private val bubble: View,
|
private val bubble: View,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val animationDuration = (bubble.resources.getInteger(android.R.integer.config_shortAnimTime) *
|
private val animationDuration = (
|
||||||
bubble.context.animatorDurationScale).toLong()
|
bubble.resources.getInteger(android.R.integer.config_shortAnimTime) *
|
||||||
|
bubble.context.animatorDurationScale
|
||||||
|
).toLong()
|
||||||
private var animator: Animator? = null
|
private var animator: Animator? = null
|
||||||
private var isHiding = false
|
private var isHiding = false
|
||||||
|
|
||||||
@@ -65,12 +67,12 @@ class BubbleAnimator(
|
|||||||
|
|
||||||
private var isCancelled = false
|
private var isCancelled = false
|
||||||
|
|
||||||
override fun onAnimationCancel(animation: Animator?) {
|
override fun onAnimationCancel(animation: Animator) {
|
||||||
super.onAnimationCancel(animation)
|
super.onAnimationCancel(animation)
|
||||||
isCancelled = true
|
isCancelled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAnimationEnd(animation: Animator?) {
|
override fun onAnimationEnd(animation: Animator) {
|
||||||
super.onAnimationEnd(animation)
|
super.onAnimationEnd(animation)
|
||||||
if (!isCancelled && animation === this@BubbleAnimator.animator) {
|
if (!isCancelled && animation === this@BubbleAnimator.animator) {
|
||||||
bubble.isInvisible = true
|
bubble.isInvisible = true
|
||||||
@@ -79,4 +81,4 @@ class BubbleAnimator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ class ScrollbarAnimator(
|
|||||||
private val scrollbarPaddingEnd: Float,
|
private val scrollbarPaddingEnd: Float,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val animationDuration = (scrollbar.resources.getInteger(R.integer.config_defaultAnimTime) *
|
private val animationDuration = (
|
||||||
scrollbar.context.animatorDurationScale).toLong()
|
scrollbar.resources.getInteger(R.integer.config_defaultAnimTime) *
|
||||||
|
scrollbar.context.animatorDurationScale
|
||||||
|
).toLong()
|
||||||
private var animator: ViewPropertyAnimator? = null
|
private var animator: ViewPropertyAnimator? = null
|
||||||
private var isHiding = false
|
private var isHiding = false
|
||||||
|
|
||||||
@@ -31,6 +33,7 @@ class ScrollbarAnimator(
|
|||||||
.animate()
|
.animate()
|
||||||
.translationX(0f)
|
.translationX(0f)
|
||||||
.alpha(1f)
|
.alpha(1f)
|
||||||
|
.setListener(null)
|
||||||
.setDuration(animationDuration)
|
.setDuration(animationDuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,30 +43,32 @@ class ScrollbarAnimator(
|
|||||||
}
|
}
|
||||||
animator?.cancel()
|
animator?.cancel()
|
||||||
isHiding = true
|
isHiding = true
|
||||||
animator = scrollbar
|
animator = scrollbar.animate().apply {
|
||||||
.animate()
|
translationX(scrollbarPaddingEnd)
|
||||||
.translationX(scrollbarPaddingEnd)
|
alpha(0f)
|
||||||
.alpha(0f)
|
duration = animationDuration
|
||||||
.setDuration(animationDuration)
|
setListener(HideListener(this))
|
||||||
.setListener(HideListener())
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class HideListener : AnimatorListenerAdapter() {
|
private inner class HideListener(
|
||||||
|
private val viewPropertyAnimator: ViewPropertyAnimator,
|
||||||
|
) : AnimatorListenerAdapter() {
|
||||||
|
|
||||||
private var isCancelled = false
|
private var isCancelled = false
|
||||||
|
|
||||||
override fun onAnimationCancel(animation: Animator?) {
|
override fun onAnimationCancel(animation: Animator) {
|
||||||
super.onAnimationCancel(animation)
|
super.onAnimationCancel(animation)
|
||||||
isCancelled = true
|
isCancelled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAnimationEnd(animation: Animator?) {
|
override fun onAnimationEnd(animation: Animator) {
|
||||||
super.onAnimationEnd(animation)
|
super.onAnimationEnd(animation)
|
||||||
if (!isCancelled && animation === this@ScrollbarAnimator.animator) {
|
if (!isCancelled && this@ScrollbarAnimator.animator === viewPropertyAnimator) {
|
||||||
scrollbar.isInvisible = true
|
scrollbar.isInvisible = true
|
||||||
isHiding = false
|
isHiding = false
|
||||||
this@ScrollbarAnimator.animator = null
|
this@ScrollbarAnimator.animator = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,11 @@ package org.koitharu.kotatsu.base.ui.widgets
|
|||||||
|
|
||||||
import android.animation.LayoutTransition
|
import android.animation.LayoutTransition
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.transition.AutoTransition
|
|
||||||
import android.transition.TransitionManager
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.WindowInsets
|
import android.view.WindowInsets
|
||||||
import android.view.animation.AccelerateDecelerateInterpolator
|
|
||||||
import android.view.animation.DecelerateInterpolator
|
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
@@ -30,6 +26,8 @@ import org.koitharu.kotatsu.utils.ext.getAnimationDuration
|
|||||||
import org.koitharu.kotatsu.utils.ext.getThemeDrawable
|
import org.koitharu.kotatsu.utils.ext.getThemeDrawable
|
||||||
import org.koitharu.kotatsu.utils.ext.parents
|
import org.koitharu.kotatsu.utils.ext.parents
|
||||||
|
|
||||||
|
private const val THROTTLE_DELAY = 200L
|
||||||
|
|
||||||
class BottomSheetHeaderBar @JvmOverloads constructor(
|
class BottomSheetHeaderBar @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
attrs: AttributeSet? = null,
|
attrs: AttributeSet? = null,
|
||||||
@@ -39,11 +37,17 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
private val binding = LayoutSheetHeaderBinding.inflate(LayoutInflater.from(context), this)
|
private val binding = LayoutSheetHeaderBinding.inflate(LayoutInflater.from(context), this)
|
||||||
private val closeDrawable = context.getThemeDrawable(materialR.attr.actionModeCloseDrawable)
|
private val closeDrawable = context.getThemeDrawable(materialR.attr.actionModeCloseDrawable)
|
||||||
private val bottomSheetCallback = Callback()
|
private val bottomSheetCallback = Callback()
|
||||||
|
private val adjustStateRunnable = Runnable { adjustState() }
|
||||||
private var bottomSheetBehavior: BottomSheetBehavior<*>? = null
|
private var bottomSheetBehavior: BottomSheetBehavior<*>? = null
|
||||||
private val locationBuffer = IntArray(2)
|
private val locationBuffer = IntArray(2)
|
||||||
private val expansionListeners = LinkedList<OnExpansionChangeListener>()
|
private val expansionListeners = LinkedList<OnExpansionChangeListener>()
|
||||||
private var fitStatusBar = false
|
private var fitStatusBar = false
|
||||||
private var transition: AutoTransition? = null
|
private val minHandleHeight = context.resources.getDimensionPixelSize(R.dimen.bottom_sheet_handle_size_min)
|
||||||
|
private val maxHandleHeight = context.resources.getDimensionPixelSize(R.dimen.bottom_sheet_handle_size_max)
|
||||||
|
private var isLayoutSuppressedCompat = false
|
||||||
|
private var isLayoutCalledWhileSuppressed = false
|
||||||
|
private var isBsExpanded = false
|
||||||
|
private var stateAdjustedAt = 0L
|
||||||
|
|
||||||
@Deprecated("")
|
@Deprecated("")
|
||||||
val toolbar: MaterialToolbar
|
val toolbar: MaterialToolbar
|
||||||
@@ -156,6 +160,14 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
binding.toolbar.setSubtitle(resId)
|
binding.toolbar.setSubtitle(resId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
|
||||||
|
if (isLayoutSuppressedCompat) {
|
||||||
|
isLayoutCalledWhileSuppressed = true
|
||||||
|
} else {
|
||||||
|
super.onLayout(changed, l, t, r, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setBottomSheetBehavior(behavior: BottomSheetBehavior<*>?) {
|
private fun setBottomSheetBehavior(behavior: BottomSheetBehavior<*>?) {
|
||||||
bottomSheetBehavior?.removeBottomSheetCallback(bottomSheetCallback)
|
bottomSheetBehavior?.removeBottomSheetCallback(bottomSheetCallback)
|
||||||
bottomSheetBehavior = behavior
|
bottomSheetBehavior = behavior
|
||||||
@@ -166,15 +178,20 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onBottomSheetStateChanged(newState: Int) {
|
private fun onBottomSheetStateChanged(newState: Int) {
|
||||||
val isExpanded = newState == BottomSheetBehavior.STATE_EXPANDED && isOnTopOfScreen()
|
val expanded = newState == BottomSheetBehavior.STATE_EXPANDED && isOnTopOfScreen()
|
||||||
if (isExpanded == binding.dragHandle.isGone) {
|
if (isBsExpanded != expanded) {
|
||||||
return
|
isBsExpanded = expanded
|
||||||
|
postAdjustState()
|
||||||
}
|
}
|
||||||
TransitionManager.beginDelayedTransition(this, getTransition())
|
}
|
||||||
binding.toolbar.navigationIcon = (if (isExpanded) closeDrawable else null)
|
|
||||||
binding.dragHandle.isGone = isExpanded
|
private fun suppressLayoutCompat(suppress: Boolean) {
|
||||||
expansionListeners.forEach { it.onExpansionStateChanged(this, isExpanded) }
|
if (suppress == isLayoutSuppressedCompat) return
|
||||||
dispatchInsets(ViewCompat.getRootWindowInsets(this))
|
isLayoutSuppressedCompat = suppress
|
||||||
|
if (!suppress && isLayoutCalledWhileSuppressed) {
|
||||||
|
requestLayout()
|
||||||
|
}
|
||||||
|
isLayoutCalledWhileSuppressed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun dispatchInsets(insets: WindowInsetsCompat?) {
|
private fun dispatchInsets(insets: WindowInsetsCompat?) {
|
||||||
@@ -182,11 +199,14 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val isExpanded = binding.dragHandle.isGone
|
val isExpanded = binding.dragHandle.isGone
|
||||||
|
val topInset = insets?.getInsets(WindowInsetsCompat.Type.systemBars())?.top ?: 0
|
||||||
if (isExpanded) {
|
if (isExpanded) {
|
||||||
val topInset = insets?.getInsets(WindowInsetsCompat.Type.systemBars())?.top ?: 0
|
|
||||||
updatePadding(top = topInset)
|
updatePadding(top = topInset)
|
||||||
} else {
|
} else {
|
||||||
updatePadding(top = 0)
|
updatePadding(top = 0)
|
||||||
|
binding.dragHandle.updateLayoutParams {
|
||||||
|
height = topInset.coerceIn(minHandleHeight, maxHandleHeight)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +245,7 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
val viewId = child.id
|
val viewId = child.id
|
||||||
return viewId == R.id.dragHandle || viewId == R.id.toolbar || viewId == R.id.frame
|
return viewId == R.id.dragHandle || viewId == R.id.toolbar
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertLayoutParams(params: ViewGroup.LayoutParams?): Toolbar.LayoutParams? {
|
private fun convertLayoutParams(params: ViewGroup.LayoutParams?): Toolbar.LayoutParams? {
|
||||||
@@ -242,13 +262,24 @@ class BottomSheetHeaderBar @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTransition(): AutoTransition {
|
private fun postAdjustState() {
|
||||||
transition?.let { return it }
|
removeCallbacks(adjustStateRunnable)
|
||||||
val t = AutoTransition()
|
val now = System.currentTimeMillis()
|
||||||
t.duration = context.getAnimationDuration(android.R.integer.config_shortAnimTime)
|
if (stateAdjustedAt + THROTTLE_DELAY < now) {
|
||||||
t.addTarget(binding.dragHandle)
|
adjustState()
|
||||||
transition = t
|
} else {
|
||||||
return t
|
postDelayed(adjustStateRunnable, THROTTLE_DELAY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun adjustState() {
|
||||||
|
suppressLayoutCompat(true)
|
||||||
|
binding.toolbar.navigationIcon = (if (isBsExpanded) closeDrawable else null)
|
||||||
|
binding.dragHandle.isGone = isBsExpanded
|
||||||
|
expansionListeners.forEach { it.onExpansionStateChanged(this, isBsExpanded) }
|
||||||
|
dispatchInsets(ViewCompat.getRootWindowInsets(this))
|
||||||
|
stateAdjustedAt = System.currentTimeMillis()
|
||||||
|
suppressLayoutCompat(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class Callback : BottomSheetBehavior.BottomSheetCallback(), View.OnClickListener {
|
private inner class Callback : BottomSheetBehavior.BottomSheetCallback(), View.OnClickListener {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class SlidingBottomNavigationView @JvmOverloads constructor(
|
|||||||
.applySystemAnimatorScale(context)
|
.applySystemAnimatorScale(context)
|
||||||
.setListener(
|
.setListener(
|
||||||
object : AnimatorListenerAdapter() {
|
object : AnimatorListenerAdapter() {
|
||||||
override fun onAnimationEnd(animation: Animator?) {
|
override fun onAnimationEnd(animation: Animator) {
|
||||||
currentAnimator = null
|
currentAnimator = null
|
||||||
postInvalidate()
|
postInvalidate()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class BookmarksViewModel @Inject constructor(
|
|||||||
BookmarksGroup(manga, bookmarks)
|
BookmarksGroup(manga, bookmarks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.catch { e -> e.toErrorState(canRetry = false) }
|
.catch { e -> emit(listOf(e.toErrorState(canRetry = false))) }
|
||||||
.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
||||||
|
|
||||||
fun removeBookmarks(ids: Map<Manga, Set<Long>>) {
|
fun removeBookmarks(ids: Map<Manga, Set<Long>>) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.recyclerview.widget.DiffUtil
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
|
import kotlin.jvm.internal.Intrinsics
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
@@ -12,7 +13,6 @@ import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
|||||||
import org.koitharu.kotatsu.list.ui.adapter.*
|
import org.koitharu.kotatsu.list.ui.adapter.*
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import kotlin.jvm.internal.Intrinsics
|
|
||||||
|
|
||||||
class BookmarksGroupAdapter(
|
class BookmarksGroupAdapter(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -34,11 +34,11 @@ class BookmarksGroupAdapter(
|
|||||||
selectionController = selectionController,
|
selectionController = selectionController,
|
||||||
bookmarkClickListener = bookmarkClickListener,
|
bookmarkClickListener = bookmarkClickListener,
|
||||||
groupClickListener = groupClickListener,
|
groupClickListener = groupClickListener,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
.addDelegate(loadingStateAD())
|
.addDelegate(loadingStateAD())
|
||||||
.addDelegate(loadingFooterAD())
|
.addDelegate(loadingFooterAD())
|
||||||
.addDelegate(emptyStateListAD(listener))
|
.addDelegate(emptyStateListAD(coil, listener))
|
||||||
.addDelegate(errorStateListAD(listener))
|
.addDelegate(errorStateListAD(listener))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,4 +64,4 @@ class BookmarksGroupAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,11 +55,12 @@ class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), Cloud
|
|||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
binding.webView.stopLoading()
|
binding.webView.stopLoading()
|
||||||
|
binding.webView.destroy()
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBuildDialog(builder: MaterialAlertDialogBuilder) {
|
override fun onBuildDialog(builder: MaterialAlertDialogBuilder): MaterialAlertDialogBuilder {
|
||||||
builder.setNegativeButton(android.R.string.cancel, null)
|
return super.onBuildDialog(builder).setNegativeButton(android.R.string.cancel, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
@@ -83,7 +84,7 @@ class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), Cloud
|
|||||||
|
|
||||||
override fun onCheckPassed() {
|
override fun onCheckPassed() {
|
||||||
pendingResult.putBoolean(EXTRA_RESULT, true)
|
pendingResult.putBoolean(EXTRA_RESULT, true)
|
||||||
dismiss()
|
dismissAllowingStateLoss()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package org.koitharu.kotatsu.core.backup
|
package org.koitharu.kotatsu.core.backup
|
||||||
|
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import javax.inject.Inject
|
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.parsers.util.json.JSONIterator
|
import org.koitharu.kotatsu.parsers.util.json.JSONIterator
|
||||||
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val PAGE_SIZE = 10
|
private const val PAGE_SIZE = 10
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ class BackupRepository @Inject constructor(private val db: MangaDatabase) {
|
|||||||
JsonDeserializer(it).toTagEntity()
|
JsonDeserializer(it).toTagEntity()
|
||||||
}
|
}
|
||||||
val history = JsonDeserializer(item).toHistoryEntity()
|
val history = JsonDeserializer(item).toHistoryEntity()
|
||||||
result += runCatching {
|
result += runCatchingCancellable {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
db.tagsDao.upsert(tags)
|
db.tagsDao.upsert(tags)
|
||||||
db.mangaDao.upsert(manga, tags)
|
db.mangaDao.upsert(manga, tags)
|
||||||
@@ -100,7 +101,7 @@ class BackupRepository @Inject constructor(private val db: MangaDatabase) {
|
|||||||
val result = CompositeResult()
|
val result = CompositeResult()
|
||||||
for (item in entry.data.JSONIterator()) {
|
for (item in entry.data.JSONIterator()) {
|
||||||
val category = JsonDeserializer(item).toFavouriteCategoryEntity()
|
val category = JsonDeserializer(item).toFavouriteCategoryEntity()
|
||||||
result += runCatching {
|
result += runCatchingCancellable {
|
||||||
db.favouriteCategoriesDao.upsert(category)
|
db.favouriteCategoriesDao.upsert(category)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,7 +117,7 @@ class BackupRepository @Inject constructor(private val db: MangaDatabase) {
|
|||||||
JsonDeserializer(it).toTagEntity()
|
JsonDeserializer(it).toTagEntity()
|
||||||
}
|
}
|
||||||
val favourite = JsonDeserializer(item).toFavouriteEntity()
|
val favourite = JsonDeserializer(item).toFavouriteEntity()
|
||||||
result += runCatching {
|
result += runCatchingCancellable {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
db.tagsDao.upsert(tags)
|
db.tagsDao.upsert(tags)
|
||||||
db.mangaDao.upsert(manga, tags)
|
db.mangaDao.upsert(manga, tags)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import org.koitharu.kotatsu.tracker.data.TrackLogEntity
|
|||||||
import org.koitharu.kotatsu.tracker.data.TracksDao
|
import org.koitharu.kotatsu.tracker.data.TracksDao
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
|
|
||||||
const val DATABASE_VERSION = 14
|
const val DATABASE_VERSION = 15
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities = [
|
entities = [
|
||||||
@@ -86,6 +86,7 @@ val databaseMigrations: Array<Migration>
|
|||||||
Migration11To12(),
|
Migration11To12(),
|
||||||
Migration12To13(),
|
Migration12To13(),
|
||||||
Migration13To14(),
|
Migration13To14(),
|
||||||
|
Migration14To15(),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun MangaDatabase(context: Context): MangaDatabase = Room
|
fun MangaDatabase(context: Context): MangaDatabase = Room
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.core.db.dao
|
package org.koitharu.kotatsu.core.db.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
|
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@@ -9,6 +10,9 @@ abstract class PreferencesDao {
|
|||||||
@Query("SELECT * FROM preferences WHERE manga_id = :mangaId")
|
@Query("SELECT * FROM preferences WHERE manga_id = :mangaId")
|
||||||
abstract suspend fun find(mangaId: Long): MangaPrefsEntity?
|
abstract suspend fun find(mangaId: Long): MangaPrefsEntity?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM preferences WHERE manga_id = :mangaId")
|
||||||
|
abstract fun observe(mangaId: Long): Flow<MangaPrefsEntity?>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
abstract suspend fun insert(pref: MangaPrefsEntity): Long
|
abstract suspend fun insert(pref: MangaPrefsEntity): Long
|
||||||
|
|
||||||
@@ -21,4 +25,4 @@ abstract class PreferencesDao {
|
|||||||
insert(pref)
|
insert(pref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.core.db.dao
|
package org.koitharu.kotatsu.core.db.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import org.koitharu.kotatsu.tracker.data.TrackLogEntity
|
import org.koitharu.kotatsu.tracker.data.TrackLogEntity
|
||||||
import org.koitharu.kotatsu.tracker.data.TrackLogWithManga
|
import org.koitharu.kotatsu.tracker.data.TrackLogWithManga
|
||||||
|
|
||||||
@@ -8,8 +9,8 @@ import org.koitharu.kotatsu.tracker.data.TrackLogWithManga
|
|||||||
interface TrackLogsDao {
|
interface TrackLogsDao {
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM track_logs ORDER BY created_at DESC LIMIT :limit OFFSET :offset")
|
@Query("SELECT * FROM track_logs ORDER BY created_at DESC LIMIT :limit OFFSET 0")
|
||||||
suspend fun findAll(offset: Int, limit: Int): List<TrackLogWithManga>
|
fun observeAll(limit: Int): Flow<List<TrackLogWithManga>>
|
||||||
|
|
||||||
@Query("DELETE FROM track_logs")
|
@Query("DELETE FROM track_logs")
|
||||||
suspend fun clear()
|
suspend fun clear()
|
||||||
@@ -25,4 +26,4 @@ interface TrackLogsDao {
|
|||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM track_logs")
|
@Query("SELECT COUNT(*) FROM track_logs")
|
||||||
suspend fun count(): Int
|
suspend fun count(): Int
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.core.db.entity
|
package org.koitharu.kotatsu.core.db.entity
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
import org.koitharu.kotatsu.parsers.model.*
|
||||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||||
@@ -10,7 +11,7 @@ import org.koitharu.kotatsu.utils.ext.longHashCode
|
|||||||
fun TagEntity.toMangaTag() = MangaTag(
|
fun TagEntity.toMangaTag() = MangaTag(
|
||||||
key = this.key,
|
key = this.key,
|
||||||
title = this.title.toTitleCase(),
|
title = this.title.toTitleCase(),
|
||||||
source = MangaSource.valueOf(this.source),
|
source = MangaSource(this.source) ?: MangaSource.DUMMY,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Collection<TagEntity>.toMangaTags() = mapToSet(TagEntity::toMangaTag)
|
fun Collection<TagEntity>.toMangaTags() = mapToSet(TagEntity::toMangaTag)
|
||||||
@@ -19,7 +20,7 @@ fun MangaEntity.toManga(tags: Set<MangaTag>) = Manga(
|
|||||||
id = this.id,
|
id = this.id,
|
||||||
title = this.title,
|
title = this.title,
|
||||||
altTitle = this.altTitle,
|
altTitle = this.altTitle,
|
||||||
state = this.state?.let { MangaState.valueOf(it) },
|
state = this.state?.let { MangaState(it) },
|
||||||
rating = this.rating,
|
rating = this.rating,
|
||||||
isNsfw = this.isNsfw,
|
isNsfw = this.isNsfw,
|
||||||
url = this.url,
|
url = this.url,
|
||||||
@@ -27,8 +28,8 @@ fun MangaEntity.toManga(tags: Set<MangaTag>) = Manga(
|
|||||||
coverUrl = this.coverUrl,
|
coverUrl = this.coverUrl,
|
||||||
largeCoverUrl = this.largeCoverUrl,
|
largeCoverUrl = this.largeCoverUrl,
|
||||||
author = this.author,
|
author = this.author,
|
||||||
source = MangaSource.valueOf(this.source),
|
source = MangaSource(this.source) ?: MangaSource.DUMMY,
|
||||||
tags = tags
|
tags = tags,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun MangaWithTags.toManga() = manga.toManga(tags.toMangaTags())
|
fun MangaWithTags.toManga() = manga.toManga(tags.toMangaTags())
|
||||||
@@ -54,14 +55,18 @@ fun MangaTag.toEntity() = TagEntity(
|
|||||||
title = title,
|
title = title,
|
||||||
key = key,
|
key = key,
|
||||||
source = source.name,
|
source = source.name,
|
||||||
id = "${key}_${source.name}".longHashCode()
|
id = "${key}_${source.name}".longHashCode(),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Collection<MangaTag>.toEntities() = map(MangaTag::toEntity)
|
fun Collection<MangaTag>.toEntities() = map(MangaTag::toEntity)
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
|
||||||
fun SortOrder(name: String, fallback: SortOrder): SortOrder = runCatching {
|
fun SortOrder(name: String, fallback: SortOrder): SortOrder = runCatching {
|
||||||
SortOrder.valueOf(name)
|
SortOrder.valueOf(name)
|
||||||
}.getOrDefault(fallback)
|
}.getOrDefault(fallback)
|
||||||
|
|
||||||
|
@Suppress("FunctionName")
|
||||||
|
fun MangaState(name: String): MangaState? = runCatching {
|
||||||
|
MangaState.valueOf(name)
|
||||||
|
}.getOrNull()
|
||||||
|
|||||||
@@ -12,12 +12,15 @@ import androidx.room.PrimaryKey
|
|||||||
entity = MangaEntity::class,
|
entity = MangaEntity::class,
|
||||||
parentColumns = ["manga_id"],
|
parentColumns = ["manga_id"],
|
||||||
childColumns = ["manga_id"],
|
childColumns = ["manga_id"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE,
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
class MangaPrefsEntity(
|
data class MangaPrefsEntity(
|
||||||
@PrimaryKey(autoGenerate = false)
|
@PrimaryKey(autoGenerate = false)
|
||||||
@ColumnInfo(name = "manga_id") val mangaId: Long,
|
@ColumnInfo(name = "manga_id")
|
||||||
@ColumnInfo(name = "mode") val mode: Int
|
val mangaId: Long,
|
||||||
)
|
@ColumnInfo(name = "mode") val mode: Int,
|
||||||
|
@ColumnInfo(name = "cf_brightness") val cfBrightness: Float,
|
||||||
|
@ColumnInfo(name = "cf_contrast") val cfContrast: Float,
|
||||||
|
)
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
class Migration14To15 : Migration(14, 15) {
|
||||||
|
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE preferences ADD COLUMN `cf_brightness` REAL NOT NULL DEFAULT 0")
|
||||||
|
database.execSQL("ALTER TABLE preferences ADD COLUMN `cf_contrast` REAL NOT NULL DEFAULT 0")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,9 @@ import androidx.activity.result.ActivityResultLauncher
|
|||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import kotlin.coroutines.Continuation
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.browser.BrowserActivity
|
import org.koitharu.kotatsu.browser.BrowserActivity
|
||||||
@@ -17,9 +20,6 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
|||||||
import org.koitharu.kotatsu.settings.sources.auth.SourceAuthActivity
|
import org.koitharu.kotatsu.settings.sources.auth.SourceAuthActivity
|
||||||
import org.koitharu.kotatsu.utils.TaggedActivityResult
|
import org.koitharu.kotatsu.utils.TaggedActivityResult
|
||||||
import org.koitharu.kotatsu.utils.isSuccess
|
import org.koitharu.kotatsu.utils.isSuccess
|
||||||
import kotlin.coroutines.Continuation
|
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
|
||||||
|
|
||||||
class ExceptionResolver private constructor(
|
class ExceptionResolver private constructor(
|
||||||
private val activity: FragmentActivity?,
|
private val activity: FragmentActivity?,
|
||||||
@@ -65,7 +65,7 @@ class ExceptionResolver private constructor(
|
|||||||
cont.invokeOnCancellation {
|
cont.invokeOnCancellation {
|
||||||
continuations.remove(CloudFlareDialog.TAG, cont)
|
continuations.remove(CloudFlareDialog.TAG, cont)
|
||||||
fm.clearFragmentResultListener(CloudFlareDialog.TAG)
|
fm.clearFragmentResultListener(CloudFlareDialog.TAG)
|
||||||
dialog.dismiss()
|
dialog.dismissAllowingStateLoss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,4 +94,4 @@ class ExceptionResolver private constructor(
|
|||||||
|
|
||||||
fun canResolve(e: Throwable) = getResolveStringId(e) != 0
|
fun canResolve(e: Throwable) = getResolveStringId(e) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,10 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.io.ByteArrayInputStream
|
import kotlinx.coroutines.Dispatchers
|
||||||
import java.io.InputStream
|
|
||||||
import java.security.MessageDigest
|
|
||||||
import java.security.cert.CertificateFactory
|
|
||||||
import java.security.cert.X509Certificate
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
@@ -22,6 +17,14 @@ import org.koitharu.kotatsu.parsers.util.json.mapJSONNotNull
|
|||||||
import org.koitharu.kotatsu.parsers.util.parseJsonArray
|
import org.koitharu.kotatsu.parsers.util.parseJsonArray
|
||||||
import org.koitharu.kotatsu.utils.ext.asArrayList
|
import org.koitharu.kotatsu.utils.ext.asArrayList
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.security.MessageDigest
|
||||||
|
import java.security.cert.CertificateFactory
|
||||||
|
import java.security.cert.X509Certificate
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
private const val CERT_SHA1 = "2C:19:C7:E8:07:61:2B:8E:94:51:1B:FD:72:67:07:64:5D:C2:58:AE"
|
private const val CERT_SHA1 = "2C:19:C7:E8:07:61:2B:8E:94:51:1B:FD:72:67:07:64:5D:C2:58:AE"
|
||||||
|
|
||||||
@@ -53,11 +56,11 @@ class AppUpdateRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun fetchUpdate(): AppVersion? {
|
suspend fun fetchUpdate(): AppVersion? = withContext(Dispatchers.Default) {
|
||||||
if (!isUpdateSupported()) {
|
if (!isUpdateSupported()) {
|
||||||
return null
|
return@withContext null
|
||||||
}
|
}
|
||||||
return runCatching {
|
runCatchingCancellable {
|
||||||
val currentVersion = VersionId(BuildConfig.VERSION_NAME)
|
val currentVersion = VersionId(BuildConfig.VERSION_NAME)
|
||||||
val available = getAvailableVersions().asArrayList()
|
val available = getAvailableVersions().asArrayList()
|
||||||
available.sortBy { it.versionId }
|
available.sortBy { it.versionId }
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ package org.koitharu.kotatsu.core.model.parcelable
|
|||||||
|
|
||||||
import android.os.Parcel
|
import android.os.Parcel
|
||||||
import androidx.core.os.ParcelCompat
|
import androidx.core.os.ParcelCompat
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.utils.ext.readParcelableCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.readSerializableCompat
|
||||||
|
|
||||||
fun Manga.writeToParcel(out: Parcel, flags: Int, withChapters: Boolean) {
|
fun Manga.writeToParcel(out: Parcel, flags: Int, withChapters: Boolean) {
|
||||||
out.writeLong(id)
|
out.writeLong(id)
|
||||||
@@ -37,11 +42,11 @@ fun Parcel.readManga() = Manga(
|
|||||||
coverUrl = requireNotNull(readString()),
|
coverUrl = requireNotNull(readString()),
|
||||||
largeCoverUrl = readString(),
|
largeCoverUrl = readString(),
|
||||||
description = readString(),
|
description = readString(),
|
||||||
tags = requireNotNull(readParcelable<ParcelableMangaTags>(ParcelableMangaTags::class.java.classLoader)).tags,
|
tags = requireNotNull(readParcelableCompat<ParcelableMangaTags>()).tags,
|
||||||
state = readSerializable() as MangaState?,
|
state = readSerializableCompat(),
|
||||||
author = readString(),
|
author = readString(),
|
||||||
chapters = readParcelable<ParcelableMangaChapters>(ParcelableMangaChapters::class.java.classLoader)?.chapters,
|
chapters = readParcelableCompat<ParcelableMangaChapters>()?.chapters,
|
||||||
source = readSerializable() as MangaSource,
|
source = checkNotNull(readSerializableCompat()),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun MangaPage.writeToParcel(out: Parcel) {
|
fun MangaPage.writeToParcel(out: Parcel) {
|
||||||
@@ -57,7 +62,7 @@ fun Parcel.readMangaPage() = MangaPage(
|
|||||||
url = requireNotNull(readString()),
|
url = requireNotNull(readString()),
|
||||||
referer = requireNotNull(readString()),
|
referer = requireNotNull(readString()),
|
||||||
preview = readString(),
|
preview = readString(),
|
||||||
source = readSerializable() as MangaSource,
|
source = checkNotNull(readSerializableCompat()),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun MangaChapter.writeToParcel(out: Parcel) {
|
fun MangaChapter.writeToParcel(out: Parcel) {
|
||||||
@@ -79,7 +84,7 @@ fun Parcel.readMangaChapter() = MangaChapter(
|
|||||||
scanlator = readString(),
|
scanlator = readString(),
|
||||||
uploadDate = readLong(),
|
uploadDate = readLong(),
|
||||||
branch = readString(),
|
branch = readString(),
|
||||||
source = readSerializable() as MangaSource,
|
source = checkNotNull(readSerializableCompat()),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun MangaTag.writeToParcel(out: Parcel) {
|
fun MangaTag.writeToParcel(out: Parcel) {
|
||||||
@@ -91,5 +96,5 @@ fun MangaTag.writeToParcel(out: Parcel) {
|
|||||||
fun Parcel.readMangaTag() = MangaTag(
|
fun Parcel.readMangaTag() = MangaTag(
|
||||||
title = requireNotNull(readString()),
|
title = requireNotNull(readString()),
|
||||||
key = requireNotNull(readString()),
|
key = requireNotNull(readString()),
|
||||||
source = readSerializable() as MangaSource,
|
source = checkNotNull(readSerializableCompat()),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import org.koitharu.kotatsu.parsers.model.Manga
|
|||||||
|
|
||||||
// Limits to avoid TransactionTooLargeException
|
// Limits to avoid TransactionTooLargeException
|
||||||
private const val MAX_SAFE_SIZE = 1024 * 512 // Assume that 512 kb is safe parcel size
|
private const val MAX_SAFE_SIZE = 1024 * 512 // Assume that 512 kb is safe parcel size
|
||||||
private const val MAX_SAFE_CHAPTERS_COUNT = 40 // this is 100% safe
|
private const val MAX_SAFE_CHAPTERS_COUNT = 32 // this is 100% safe
|
||||||
|
|
||||||
class ParcelableManga(
|
class ParcelableManga(
|
||||||
val manga: Manga,
|
val manga: Manga,
|
||||||
@@ -50,4 +50,4 @@ class ParcelableManga(
|
|||||||
return arrayOfNulls(size)
|
return arrayOfNulls(size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package org.koitharu.kotatsu.core.os
|
|||||||
|
|
||||||
import android.app.ActivityManager
|
import android.app.ActivityManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.content.pm.ShortcutManager
|
import android.content.pm.ShortcutManager
|
||||||
import android.media.ThumbnailUtils
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Size
|
import android.util.Size
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import androidx.core.content.pm.ShortcutInfoCompat
|
import androidx.core.content.pm.ShortcutInfoCompat
|
||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
import androidx.core.content.pm.ShortcutManagerCompat
|
||||||
@@ -13,21 +14,25 @@ import androidx.core.graphics.drawable.IconCompat
|
|||||||
import androidx.room.InvalidationTracker
|
import androidx.room.InvalidationTracker
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
|
import coil.size.Precision
|
||||||
|
import coil.size.Scale
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.core.db.TABLE_HISTORY
|
import org.koitharu.kotatsu.core.db.TABLE_HISTORY
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.utils.ext.requireBitmap
|
import org.koitharu.kotatsu.utils.ext.requireBitmap
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ShortcutsUpdater @Inject constructor(
|
class ShortcutsUpdater @Inject constructor(
|
||||||
@@ -35,13 +40,18 @@ class ShortcutsUpdater @Inject constructor(
|
|||||||
private val coil: ImageLoader,
|
private val coil: ImageLoader,
|
||||||
private val historyRepository: HistoryRepository,
|
private val historyRepository: HistoryRepository,
|
||||||
private val mangaRepository: MangaDataRepository,
|
private val mangaRepository: MangaDataRepository,
|
||||||
) : InvalidationTracker.Observer(TABLE_HISTORY) {
|
private val settings: AppSettings,
|
||||||
|
) : InvalidationTracker.Observer(TABLE_HISTORY), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
private val iconSize by lazy { getIconSize(context) }
|
private val iconSize by lazy { getIconSize(context) }
|
||||||
private var shortcutsUpdateJob: Job? = null
|
private var shortcutsUpdateJob: Job? = null
|
||||||
|
|
||||||
override fun onInvalidated(tables: MutableSet<String>) {
|
init {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
|
settings.subscribe(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onInvalidated(tables: Set<String>) {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1 || !settings.isDynamicShortcutsEnabled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val prevJob = shortcutsUpdateJob
|
val prevJob = shortcutsUpdateJob
|
||||||
@@ -51,6 +61,16 @@ class ShortcutsUpdater @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && key == AppSettings.KEY_SHORTCUTS) {
|
||||||
|
if (settings.isDynamicShortcutsEnabled) {
|
||||||
|
onInvalidated(emptySet())
|
||||||
|
} else {
|
||||||
|
clearShortcuts()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun requestPinShortcut(manga: Manga): Boolean {
|
suspend fun requestPinShortcut(manga: Manga): Boolean {
|
||||||
return ShortcutManagerCompat.requestPinShortcut(
|
return ShortcutManagerCompat.requestPinShortcut(
|
||||||
context,
|
context,
|
||||||
@@ -64,7 +84,16 @@ class ShortcutsUpdater @Inject constructor(
|
|||||||
return shortcutsUpdateJob?.join() != null
|
return shortcutsUpdateJob?.join() != null
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun updateShortcutsImpl() = runCatching {
|
fun isDynamicShortcutsAvailable(): Boolean {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
||||||
|
return manager.maxShortcutCountPerActivity > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||||
|
private suspend fun updateShortcutsImpl() = runCatchingCancellable {
|
||||||
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
||||||
val shortcuts = historyRepository.getList(0, manager.maxShortcutCountPerActivity)
|
val shortcuts = historyRepository.getList(0, manager.maxShortcutCountPerActivity)
|
||||||
.filter { x -> x.title.isNotEmpty() }
|
.filter { x -> x.title.isNotEmpty() }
|
||||||
@@ -74,15 +103,25 @@ class ShortcutsUpdater @Inject constructor(
|
|||||||
it.printStackTraceDebug()
|
it.printStackTraceDebug()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||||
|
private fun clearShortcuts() {
|
||||||
|
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
||||||
|
try {
|
||||||
|
manager.removeAllDynamicShortcuts()
|
||||||
|
} catch (_: IllegalStateException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun buildShortcutInfo(manga: Manga): ShortcutInfoCompat.Builder {
|
private suspend fun buildShortcutInfo(manga: Manga): ShortcutInfoCompat.Builder {
|
||||||
val icon = runCatching {
|
val icon = runCatchingCancellable {
|
||||||
val bmp = coil.execute(
|
coil.execute(
|
||||||
ImageRequest.Builder(context)
|
ImageRequest.Builder(context)
|
||||||
.data(manga.coverUrl)
|
.data(manga.coverUrl)
|
||||||
.size(iconSize.width, iconSize.height)
|
.size(iconSize.width, iconSize.height)
|
||||||
|
.precision(Precision.EXACT)
|
||||||
|
.scale(Scale.FILL)
|
||||||
.build(),
|
.build(),
|
||||||
).requireBitmap()
|
).requireBitmap()
|
||||||
ThumbnailUtils.extractThumbnail(bmp, iconSize.width, iconSize.height, 0)
|
|
||||||
}.fold(
|
}.fold(
|
||||||
onSuccess = { IconCompat.createWithAdaptiveBitmap(it) },
|
onSuccess = { IconCompat.createWithAdaptiveBitmap(it) },
|
||||||
onFailure = { IconCompat.createWithResource(context, R.drawable.ic_shortcut_default) },
|
onFailure = { IconCompat.createWithResource(context, R.drawable.ic_shortcut_default) },
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.koitharu.kotatsu.BuildConfig
|
|||||||
import org.koitharu.kotatsu.core.model.ZoomMode
|
import org.koitharu.kotatsu.core.model.ZoomMode
|
||||||
import org.koitharu.kotatsu.core.network.DoHProvider
|
import org.koitharu.kotatsu.core.network.DoHProvider
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.utils.ext.getEnumValue
|
import org.koitharu.kotatsu.utils.ext.getEnumValue
|
||||||
import org.koitharu.kotatsu.utils.ext.observe
|
import org.koitharu.kotatsu.utils.ext.observe
|
||||||
import org.koitharu.kotatsu.utils.ext.putEnumValue
|
import org.koitharu.kotatsu.utils.ext.putEnumValue
|
||||||
@@ -22,7 +23,9 @@ import org.koitharu.kotatsu.utils.ext.toUriOrNull
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.Collections
|
||||||
|
import java.util.EnumSet
|
||||||
|
import java.util.Locale
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@@ -65,6 +68,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val readerPageSwitch: Set<String>
|
val readerPageSwitch: Set<String>
|
||||||
get() = prefs.getStringSet(KEY_READER_SWITCHERS, null) ?: setOf(PAGE_SWITCH_TAPS)
|
get() = prefs.getStringSet(KEY_READER_SWITCHERS, null) ?: setOf(PAGE_SWITCH_TAPS)
|
||||||
|
|
||||||
|
val isReaderTapsAdaptive: Boolean
|
||||||
|
get() = !prefs.getBoolean(KEY_READER_TAPS_LTR, false)
|
||||||
|
|
||||||
var isTrafficWarningEnabled: Boolean
|
var isTrafficWarningEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_TRAFFIC_WARNING, true)
|
get() = prefs.getBoolean(KEY_TRAFFIC_WARNING, true)
|
||||||
set(value) = prefs.edit { putBoolean(KEY_TRAFFIC_WARNING, value) }
|
set(value) = prefs.edit { putBoolean(KEY_TRAFFIC_WARNING, value) }
|
||||||
@@ -73,13 +79,6 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
get() = prefs.getBoolean(KEY_ALL_FAVOURITES_VISIBLE, true)
|
get() = prefs.getBoolean(KEY_ALL_FAVOURITES_VISIBLE, true)
|
||||||
set(value) = prefs.edit { putBoolean(KEY_ALL_FAVOURITES_VISIBLE, value) }
|
set(value) = prefs.edit { putBoolean(KEY_ALL_FAVOURITES_VISIBLE, value) }
|
||||||
|
|
||||||
val isUpdateCheckingEnabled: Boolean
|
|
||||||
get() = prefs.getBoolean(KEY_APP_UPDATE_AUTO, true)
|
|
||||||
|
|
||||||
var lastUpdateCheckTimestamp: Long
|
|
||||||
get() = prefs.getLong(KEY_APP_UPDATE, 0L)
|
|
||||||
set(value) = prefs.edit { putLong(KEY_APP_UPDATE, value) }
|
|
||||||
|
|
||||||
val isTrackerEnabled: Boolean
|
val isTrackerEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_TRACKER_ENABLED, true)
|
get() = prefs.getBoolean(KEY_TRACKER_ENABLED, true)
|
||||||
|
|
||||||
@@ -141,6 +140,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val isExitConfirmationEnabled: Boolean
|
val isExitConfirmationEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_EXIT_CONFIRM, false)
|
get() = prefs.getBoolean(KEY_EXIT_CONFIRM, false)
|
||||||
|
|
||||||
|
val isDynamicShortcutsEnabled: Boolean
|
||||||
|
get() = prefs.getBoolean(KEY_SHORTCUTS, true)
|
||||||
|
|
||||||
var sourcesOrder: List<String>
|
var sourcesOrder: List<String>
|
||||||
get() = prefs.getString(KEY_SOURCES_ORDER, null)
|
get() = prefs.getString(KEY_SOURCES_ORDER, null)
|
||||||
?.split('|')
|
?.split('|')
|
||||||
@@ -206,9 +208,16 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val isReaderBarEnabled: Boolean
|
val isReaderBarEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_READER_BAR, true)
|
get() = prefs.getBoolean(KEY_READER_BAR, true)
|
||||||
|
|
||||||
|
val isReaderSliderEnabled: Boolean
|
||||||
|
get() = prefs.getBoolean(KEY_READER_SLIDER, true)
|
||||||
|
|
||||||
val dnsOverHttps: DoHProvider
|
val dnsOverHttps: DoHProvider
|
||||||
get() = prefs.getEnumValue(KEY_DOH, DoHProvider.NONE)
|
get() = prefs.getEnumValue(KEY_DOH, DoHProvider.NONE)
|
||||||
|
|
||||||
|
var localListOrder: SortOrder
|
||||||
|
get() = prefs.getEnumValue(KEY_LOCAL_LIST_ORDER, SortOrder.NEWEST)
|
||||||
|
set(value) = prefs.edit { putEnumValue(KEY_LOCAL_LIST_ORDER, value) }
|
||||||
|
|
||||||
fun isPagesPreloadAllowed(cm: ConnectivityManager): Boolean {
|
fun isPagesPreloadAllowed(cm: ConnectivityManager): Boolean {
|
||||||
return when (prefs.getString(KEY_PAGES_PRELOAD, null)?.toIntOrNull()) {
|
return when (prefs.getString(KEY_PAGES_PRELOAD, null)?.toIntOrNull()) {
|
||||||
NETWORK_ALWAYS -> true
|
NETWORK_ALWAYS -> true
|
||||||
@@ -324,10 +333,13 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val KEY_INCOGNITO_MODE = "incognito"
|
const val KEY_INCOGNITO_MODE = "incognito"
|
||||||
const val KEY_SYNC = "sync"
|
const val KEY_SYNC = "sync"
|
||||||
const val KEY_READER_BAR = "reader_bar"
|
const val KEY_READER_BAR = "reader_bar"
|
||||||
|
const val KEY_READER_SLIDER = "reader_slider"
|
||||||
|
const val KEY_SHORTCUTS = "dynamic_shortcuts"
|
||||||
|
const val KEY_READER_TAPS_LTR = "reader_taps_ltr"
|
||||||
|
const val KEY_LOCAL_LIST_ORDER = "local_order"
|
||||||
|
|
||||||
// About
|
// About
|
||||||
const val KEY_APP_UPDATE = "app_update"
|
const val KEY_APP_UPDATE = "app_update"
|
||||||
const val KEY_APP_UPDATE_AUTO = "app_update_auto"
|
|
||||||
const val KEY_APP_TRANSLATION = "about_app_translation"
|
const val KEY_APP_TRANSLATION = "about_app_translation"
|
||||||
|
|
||||||
private const val NETWORK_NEVER = 0
|
private const val NETWORK_NEVER = 0
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package org.koitharu.kotatsu.core.ui
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.text.method.LinkMovementMethod
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.text.HtmlCompat
|
||||||
|
import androidx.core.text.htmlEncode
|
||||||
|
import androidx.core.text.parseAsHtml
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
||||||
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
|
import org.koitharu.kotatsu.databinding.DialogMangaErrorBinding
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.report
|
||||||
|
import org.koitharu.kotatsu.utils.ext.requireParcelable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.requireSerializable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||||
|
|
||||||
|
class MangaErrorDialog : AlertDialogFragment<DialogMangaErrorBinding>() {
|
||||||
|
|
||||||
|
private lateinit var error: Throwable
|
||||||
|
private lateinit var manga: Manga
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
val args = requireArguments()
|
||||||
|
manga = args.requireParcelable<ParcelableManga>(ARG_MANGA).manga
|
||||||
|
error = args.requireSerializable(ARG_ERROR)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): DialogMangaErrorBinding {
|
||||||
|
return DialogMangaErrorBinding.inflate(inflater, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
with(binding.textViewMessage) {
|
||||||
|
movementMethod = LinkMovementMethod.getInstance()
|
||||||
|
text = context.getString(
|
||||||
|
R.string.manga_error_description_pattern,
|
||||||
|
this@MangaErrorDialog.error.message?.htmlEncode().orEmpty(),
|
||||||
|
manga.publicUrl,
|
||||||
|
).parseAsHtml(HtmlCompat.FROM_HTML_MODE_LEGACY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBuildDialog(builder: MaterialAlertDialogBuilder): MaterialAlertDialogBuilder {
|
||||||
|
return super.onBuildDialog(builder)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.setPositiveButton(R.string.report) { _, _ ->
|
||||||
|
dismiss()
|
||||||
|
error.report()
|
||||||
|
}.setTitle(R.string.error_occurred)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private const val TAG = "MangaErrorDialog"
|
||||||
|
private const val ARG_ERROR = "error"
|
||||||
|
private const val ARG_MANGA = "manga"
|
||||||
|
|
||||||
|
fun show(fm: FragmentManager, manga: Manga, error: Throwable) = MangaErrorDialog().withArgs(2) {
|
||||||
|
putParcelable(ARG_MANGA, ParcelableManga(manga, false))
|
||||||
|
putSerializable(ARG_ERROR, error)
|
||||||
|
}.show(fm, TAG)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,8 +6,6 @@ import androidx.appcompat.view.ActionMode
|
|||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
|
||||||
import androidx.core.view.updatePadding
|
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
@@ -202,18 +200,4 @@ class ChaptersFragment :
|
|||||||
private fun onLoadingStateChanged(isLoading: Boolean) {
|
private fun onLoadingStateChanged(isLoading: Boolean) {
|
||||||
binding.progressBar.isVisible = isLoading
|
binding.progressBar.isVisible = isLoading
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findBottomSheetBehavior(): BottomSheetBehavior<*>? {
|
|
||||||
val v = view ?: return null
|
|
||||||
for (p in v.parents) {
|
|
||||||
val layoutParams = (p as? View)?.layoutParams
|
|
||||||
if (layoutParams is CoordinatorLayout.LayoutParams) {
|
|
||||||
val behavior = layoutParams.behavior
|
|
||||||
if (behavior is BottomSheetBehavior<*>) {
|
|
||||||
return behavior
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ class ChaptersMenuProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareMenu(menu: Menu) {
|
override fun onPrepareMenu(menu: Menu) {
|
||||||
menu.findItem(R.id.action_reversed).isChecked = viewModel.isChaptersReversed.value == true
|
menu.findItem(R.id.action_reversed)?.isChecked = viewModel.isChaptersReversed.value == true
|
||||||
menu.findItem(R.id.action_search).isVisible = viewModel.isChaptersEmpty.value == false
|
menu.findItem(R.id.action_search)?.isVisible = viewModel.isChaptersEmpty.value == false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemSelected(menuItem: MenuItem): Boolean = when (menuItem.itemId) {
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean = when (menuItem.itemId) {
|
||||||
@@ -35,13 +35,13 @@ class ChaptersMenuProvider(
|
|||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||||
bottomSheetMediator?.lock()
|
bottomSheetMediator?.lock()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
|
||||||
(item?.actionView as? SearchView)?.setQuery("", false)
|
(item.actionView as? SearchView)?.setQuery("", false)
|
||||||
viewModel.performChapterSearch(null)
|
viewModel.performChapterSearch(null)
|
||||||
bottomSheetMediator?.unlock()
|
bottomSheetMediator?.unlock()
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -5,8 +5,13 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.transition.Slide
|
||||||
|
import android.transition.TransitionManager
|
||||||
|
import android.view.Gravity
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.view.animation.AccelerateDecelerateInterpolator
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.widget.PopupMenu
|
import androidx.appcompat.widget.PopupMenu
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
@@ -14,11 +19,10 @@ import androidx.core.view.isGone
|
|||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.google.android.material.badge.BadgeDrawable
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import com.google.android.material.snackbar.BaseTransientBottomBar
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.domain.MangaIntent
|
import org.koitharu.kotatsu.base.domain.MangaIntent
|
||||||
@@ -27,15 +31,21 @@ import org.koitharu.kotatsu.base.ui.widgets.BottomSheetHeaderBar
|
|||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
||||||
|
import org.koitharu.kotatsu.core.ui.MangaErrorDialog
|
||||||
import org.koitharu.kotatsu.databinding.ActivityDetailsBinding
|
import org.koitharu.kotatsu.databinding.ActivityDetailsBinding
|
||||||
import org.koitharu.kotatsu.details.ui.model.HistoryInfo
|
import org.koitharu.kotatsu.details.ui.model.HistoryInfo
|
||||||
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.bindBadge
|
|
||||||
import org.koitharu.kotatsu.main.ui.owners.NoModalBottomSheetOwner
|
import org.koitharu.kotatsu.main.ui.owners.NoModalBottomSheetOwner
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderState
|
import org.koitharu.kotatsu.reader.ui.ReaderState
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ViewBadge
|
||||||
|
import org.koitharu.kotatsu.utils.ext.assistedViewModels
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.isReportable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setNavigationBarTransparentCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DetailsActivity :
|
class DetailsActivity :
|
||||||
@@ -53,7 +63,7 @@ class DetailsActivity :
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var shortcutsUpdater: ShortcutsUpdater
|
lateinit var shortcutsUpdater: ShortcutsUpdater
|
||||||
|
|
||||||
private var badge: BadgeDrawable? = null
|
private lateinit var viewBadge: ViewBadge
|
||||||
|
|
||||||
private val viewModel: DetailsViewModel by assistedViewModels {
|
private val viewModel: DetailsViewModel by assistedViewModels {
|
||||||
viewModelFactory.create(MangaIntent(intent))
|
viewModelFactory.create(MangaIntent(intent))
|
||||||
@@ -76,6 +86,7 @@ class DetailsActivity :
|
|||||||
}
|
}
|
||||||
binding.buttonRead.setOnClickListener(this)
|
binding.buttonRead.setOnClickListener(this)
|
||||||
binding.buttonDropdown.setOnClickListener(this)
|
binding.buttonDropdown.setOnClickListener(this)
|
||||||
|
viewBadge = ViewBadge(binding.buttonRead, this)
|
||||||
|
|
||||||
chaptersMenuProvider = if (binding.layoutBottom != null) {
|
chaptersMenuProvider = if (binding.layoutBottom != null) {
|
||||||
val bsMediator = ChaptersBottomSheetMediator(checkNotNull(binding.layoutBottom))
|
val bsMediator = ChaptersBottomSheetMediator(checkNotNull(binding.layoutBottom))
|
||||||
@@ -93,6 +104,7 @@ class DetailsActivity :
|
|||||||
viewModel.onMangaRemoved.observe(this, ::onMangaRemoved)
|
viewModel.onMangaRemoved.observe(this, ::onMangaRemoved)
|
||||||
viewModel.onError.observe(this, ::onError)
|
viewModel.onError.observe(this, ::onError)
|
||||||
viewModel.onShowToast.observe(this) {
|
viewModel.onShowToast.observe(this) {
|
||||||
|
makeSnackbar(getString(it), Snackbar.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
viewModel.historyInfo.observe(this, ::onHistoryChanged)
|
viewModel.historyInfo.observe(this, ::onHistoryChanged)
|
||||||
viewModel.selectedBranchName.observe(this) {
|
viewModel.selectedBranchName.observe(this) {
|
||||||
@@ -143,6 +155,7 @@ class DetailsActivity :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.button_dropdown -> showBranchPopupMenu()
|
R.id.button_dropdown -> showBranchPopupMenu()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,8 +171,11 @@ class DetailsActivity :
|
|||||||
|
|
||||||
private fun onMangaUpdated(manga: Manga) {
|
private fun onMangaUpdated(manga: Manga) {
|
||||||
title = manga.title
|
title = manga.title
|
||||||
binding.buttonRead.isEnabled = !manga.chapters.isNullOrEmpty()
|
val hasChapters = !manga.chapters.isNullOrEmpty()
|
||||||
|
binding.buttonRead.isEnabled = hasChapters
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
|
showBottomSheet(manga.chapters != null)
|
||||||
|
binding.groupHeader?.isVisible = hasChapters
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onMangaRemoved(manga: Manga) {
|
private fun onMangaRemoved(manga: Manga) {
|
||||||
@@ -172,17 +188,19 @@ class DetailsActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onError(e: Throwable) {
|
private fun onError(e: Throwable) {
|
||||||
|
val manga = viewModel.manga.value
|
||||||
when {
|
when {
|
||||||
ExceptionResolver.canResolve(e) -> {
|
ExceptionResolver.canResolve(e) -> {
|
||||||
resolveError(e)
|
resolveError(e)
|
||||||
}
|
}
|
||||||
viewModel.manga.value == null -> {
|
|
||||||
|
manga == null -> {
|
||||||
Toast.makeText(this, e.getDisplayMessage(resources), Toast.LENGTH_LONG).show()
|
Toast.makeText(this, e.getDisplayMessage(resources), Toast.LENGTH_LONG).show()
|
||||||
finishAfterTransition()
|
finishAfterTransition()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
val snackbar = Snackbar.make(
|
val snackbar = makeSnackbar(
|
||||||
binding.containerDetails,
|
|
||||||
e.getDisplayMessage(resources),
|
e.getDisplayMessage(resources),
|
||||||
if (viewModel.manga.value?.chapters == null) {
|
if (viewModel.manga.value?.chapters == null) {
|
||||||
Snackbar.LENGTH_INDEFINITE
|
Snackbar.LENGTH_INDEFINITE
|
||||||
@@ -190,10 +208,9 @@ class DetailsActivity :
|
|||||||
Snackbar.LENGTH_LONG
|
Snackbar.LENGTH_LONG
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
snackbar.anchorView = binding.headerChapters
|
|
||||||
if (e.isReportable()) {
|
if (e.isReportable()) {
|
||||||
snackbar.setAction(R.string.report) {
|
snackbar.setAction(R.string.details) {
|
||||||
e.report("DetailsActivity::onError")
|
MangaErrorDialog.show(supportFragmentManager, manga, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snackbar.show()
|
snackbar.show()
|
||||||
@@ -232,14 +249,13 @@ class DetailsActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onNewChaptersChanged(newChapters: Int) {
|
private fun onNewChaptersChanged(newChapters: Int) {
|
||||||
badge = binding.buttonRead.bindBadge(badge, newChapters)
|
viewBadge.counter = newChapters
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showChapterMissingDialog(chapterId: Long) {
|
fun showChapterMissingDialog(chapterId: Long) {
|
||||||
val remoteManga = viewModel.getRemoteManga()
|
val remoteManga = viewModel.getRemoteManga()
|
||||||
if (remoteManga == null) {
|
if (remoteManga == null) {
|
||||||
val snackbar = Snackbar.make(binding.containerDetails, R.string.chapter_is_missing, Snackbar.LENGTH_SHORT)
|
val snackbar = makeSnackbar(getString(R.string.chapter_is_missing), Snackbar.LENGTH_SHORT)
|
||||||
snackbar.anchorView = binding.headerChapters
|
|
||||||
snackbar.show()
|
snackbar.show()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -291,6 +307,24 @@ class DetailsActivity :
|
|||||||
|
|
||||||
private fun isTabletLayout() = binding.layoutBottom == null
|
private fun isTabletLayout() = binding.layoutBottom == null
|
||||||
|
|
||||||
|
private fun showBottomSheet(isVisible: Boolean) {
|
||||||
|
val view = binding.layoutBottom ?: return
|
||||||
|
if (view.isVisible == isVisible) return
|
||||||
|
val transition = Slide(Gravity.BOTTOM)
|
||||||
|
transition.addTarget(view)
|
||||||
|
transition.interpolator = AccelerateDecelerateInterpolator()
|
||||||
|
TransitionManager.beginDelayedTransition(binding.root as ViewGroup, transition)
|
||||||
|
view.isVisible = isVisible
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun makeSnackbar(text: CharSequence, @BaseTransientBottomBar.Duration duration: Int): Snackbar {
|
||||||
|
val sb = Snackbar.make(binding.containerDetails, text, duration)
|
||||||
|
if (binding.layoutBottom?.isVisible == true) {
|
||||||
|
sb.anchorView = binding.headerChapters
|
||||||
|
}
|
||||||
|
return sb
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newIntent(context: Context, manga: Manga): Intent {
|
fun newIntent(context: Context, manga: Manga): Intent {
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class DetailsFragment :
|
|||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
binding.textViewAuthor.setOnClickListener(this)
|
binding.textViewAuthor.setOnClickListener(this)
|
||||||
binding.imageViewCover.setOnClickListener(this)
|
binding.imageViewCover.setOnClickListener(this)
|
||||||
|
binding.infoLayout.textViewSource.setOnClickListener(this)
|
||||||
binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance()
|
binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance()
|
||||||
binding.chipsTags.onChipClickListener = this
|
binding.chipsTags.onChipClickListener = this
|
||||||
viewModel.manga.observe(viewLifecycleOwner, ::onMangaUpdated)
|
viewModel.manga.observe(viewLifecycleOwner, ::onMangaUpdated)
|
||||||
@@ -228,6 +229,14 @@ class DetailsFragment :
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
R.id.textView_source -> {
|
||||||
|
startActivity(
|
||||||
|
MangaListActivity.newIntent(
|
||||||
|
context = v.context,
|
||||||
|
source = manga.source,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
R.id.imageView_cover -> {
|
R.id.imageView_cover -> {
|
||||||
startActivity(
|
startActivity(
|
||||||
ImageActivity.newIntent(v.context, manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }),
|
ImageActivity.newIntent(v.context, manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }),
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import org.koitharu.kotatsu.utils.SingleLiveEvent
|
|||||||
import org.koitharu.kotatsu.utils.asFlowLiveData
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
class DetailsViewModel @AssistedInject constructor(
|
class DetailsViewModel @AssistedInject constructor(
|
||||||
@Assisted intent: MangaIntent,
|
@Assisted intent: MangaIntent,
|
||||||
@@ -189,7 +190,7 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
checkNotNull(manga) { "Cannot find saved manga for ${m.title}" }
|
checkNotNull(manga) { "Cannot find saved manga for ${m.title}" }
|
||||||
val original = localMangaRepository.getRemoteManga(manga)
|
val original = localMangaRepository.getRemoteManga(manga)
|
||||||
localMangaRepository.delete(manga) || throw IOException("Unable to delete file")
|
localMangaRepository.delete(manga) || throw IOException("Unable to delete file")
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
historyRepository.deleteOrSwap(manga, original)
|
historyRepository.deleteOrSwap(manga, original)
|
||||||
}
|
}
|
||||||
onMangaRemoved.postCall(manga)
|
onMangaRemoved.postCall(manga)
|
||||||
@@ -228,7 +229,7 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
reload()
|
reload()
|
||||||
} else {
|
} else {
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
localMangaRepository.getDetails(downloadedManga)
|
localMangaRepository.getDetails(downloadedManga)
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
delegate.relatedManga.value = it
|
delegate.relatedManga.value = it
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.koitharu.kotatsu.parsers.model.Manga
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
class MangaDetailsDelegate(
|
class MangaDetailsDelegate(
|
||||||
private val intent: MangaIntent,
|
private val intent: MangaIntent,
|
||||||
@@ -45,9 +46,9 @@ class MangaDetailsDelegate(
|
|||||||
val hist = historyRepository.getOne(manga)
|
val hist = historyRepository.getOne(manga)
|
||||||
selectedBranch.value = manga.getPreferredBranch(hist)
|
selectedBranch.value = manga.getPreferredBranch(hist)
|
||||||
mangaData.value = manga
|
mangaData.value = manga
|
||||||
relatedManga.value = runCatching {
|
relatedManga.value = runCatchingCancellable {
|
||||||
if (manga.source == MangaSource.LOCAL) {
|
if (manga.source == MangaSource.LOCAL) {
|
||||||
val m = localMangaRepository.getRemoteManga(manga) ?: return@runCatching null
|
val m = localMangaRepository.getRemoteManga(manga) ?: return@runCatchingCancellable null
|
||||||
mangaRepositoryFactory.create(m.source).getDetails(m)
|
mangaRepositoryFactory.create(m.source).getDetails(m)
|
||||||
} else {
|
} else {
|
||||||
localMangaRepository.findSavedManga(manga)
|
localMangaRepository.findSavedManga(manga)
|
||||||
|
|||||||
@@ -28,4 +28,4 @@ fun MangaChapter.toListItem(
|
|||||||
uploadDateMs = uploadDate,
|
uploadDateMs = uploadDate,
|
||||||
dateFormat = dateFormat,
|
dateFormat = dateFormat,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,18 @@ import dagger.assisted.Assisted
|
|||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.io.File
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.NonCancellable
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runInterruptible
|
||||||
import kotlinx.coroutines.sync.Semaphore
|
import kotlinx.coroutines.sync.Semaphore
|
||||||
import kotlinx.coroutines.sync.withPermit
|
import kotlinx.coroutines.sync.withPermit
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.internal.closeQuietly
|
import okhttp3.internal.closeQuietly
|
||||||
@@ -32,7 +39,9 @@ import org.koitharu.kotatsu.parsers.util.await
|
|||||||
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.referer
|
import org.koitharu.kotatsu.utils.ext.referer
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
import org.koitharu.kotatsu.utils.progress.PausingProgressJob
|
import org.koitharu.kotatsu.utils.progress.PausingProgressJob
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
private const val MAX_FAILSAFE_ATTEMPTS = 2
|
private const val MAX_FAILSAFE_ATTEMPTS = 2
|
||||||
private const val DOWNLOAD_ERROR_DELAY = 500L
|
private const val DOWNLOAD_ERROR_DELAY = 500L
|
||||||
@@ -155,7 +164,7 @@ class DownloadManager @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
outState.value = DownloadState.PostProcessing(startId, data, cover)
|
outState.value = DownloadState.PostProcessing(startId, data, cover)
|
||||||
output.mergeWithExisting()
|
output.mergeWithExisting()
|
||||||
output.finalize()
|
output.finish()
|
||||||
val localManga = localMangaRepository.getFromFile(output.file)
|
val localManga = localMangaRepository.getFromFile(output.file)
|
||||||
outState.value = DownloadState.Done(startId, data, cover, localManga)
|
outState.value = DownloadState.Done(startId, data, cover, localManga)
|
||||||
} catch (e: CancellationException) {
|
} catch (e: CancellationException) {
|
||||||
@@ -231,7 +240,7 @@ class DownloadManager @AssistedInject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadCover(manga: Manga) = runCatching {
|
private suspend fun loadCover(manga: Manga) = runCatchingCancellable {
|
||||||
imageLoader.execute(
|
imageLoader.execute(
|
||||||
ImageRequest.Builder(context)
|
ImageRequest.Builder(context)
|
||||||
.data(manga.coverUrl)
|
.data(manga.coverUrl)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class DownloadsActivity : BaseActivity<ActivityDownloadsBinding>() {
|
|||||||
setContentView(ActivityDownloadsBinding.inflate(layoutInflater))
|
setContentView(ActivityDownloadsBinding.inflate(layoutInflater))
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
val adapter = DownloadsAdapter(lifecycleScope, coil)
|
val adapter = DownloadsAdapter(lifecycleScope, coil)
|
||||||
val spacing = resources.getDimensionPixelOffset(R.dimen.grid_spacing)
|
val spacing = resources.getDimensionPixelOffset(R.dimen.list_spacing)
|
||||||
binding.recyclerView.addItemDecoration(SpacingItemDecoration(spacing))
|
binding.recyclerView.addItemDecoration(SpacingItemDecoration(spacing))
|
||||||
binding.recyclerView.setHasFixedSize(true)
|
binding.recyclerView.setHasFixedSize(true)
|
||||||
binding.recyclerView.adapter = adapter
|
binding.recyclerView.adapter = adapter
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import java.util.concurrent.TimeUnit
|
import kotlinx.coroutines.flow.Flow
|
||||||
import javax.inject.Inject
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlin.collections.set
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.flow.transformWhile
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
@@ -28,10 +30,14 @@ import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
|||||||
import org.koitharu.kotatsu.download.domain.DownloadManager
|
import org.koitharu.kotatsu.download.domain.DownloadManager
|
||||||
import org.koitharu.kotatsu.download.domain.DownloadState
|
import org.koitharu.kotatsu.download.domain.DownloadState
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
import org.koitharu.kotatsu.utils.ext.throttle
|
import org.koitharu.kotatsu.utils.ext.throttle
|
||||||
import org.koitharu.kotatsu.utils.progress.PausingProgressJob
|
import org.koitharu.kotatsu.utils.progress.PausingProgressJob
|
||||||
import org.koitharu.kotatsu.utils.progress.ProgressJob
|
import org.koitharu.kotatsu.utils.progress.ProgressJob
|
||||||
import org.koitharu.kotatsu.utils.progress.TimeLeftEstimator
|
import org.koitharu.kotatsu.utils.progress.TimeLeftEstimator
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.collections.set
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DownloadService : BaseService() {
|
class DownloadService : BaseService() {
|
||||||
@@ -65,7 +71,7 @@ class DownloadService : BaseService() {
|
|||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
val manga = intent?.getParcelableExtra<ParcelableManga>(EXTRA_MANGA)?.manga
|
val manga = intent?.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga
|
||||||
val chapters = intent?.getLongArrayExtra(EXTRA_CHAPTERS_IDS)
|
val chapters = intent?.getLongArrayExtra(EXTRA_CHAPTERS_IDS)
|
||||||
return if (manga != null) {
|
return if (manga != null) {
|
||||||
jobs[startId] = downloadManga(startId, manga, chapters)
|
jobs[startId] = downloadManga(startId, manga, chapters)
|
||||||
@@ -84,7 +90,9 @@ class DownloadService : BaseService() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
unregisterReceiver(controlReceiver)
|
unregisterReceiver(controlReceiver)
|
||||||
wakeLock.release()
|
if (wakeLock.isHeld) {
|
||||||
|
wakeLock.release()
|
||||||
|
}
|
||||||
isRunning = false
|
isRunning = false
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
@@ -168,6 +176,7 @@ class DownloadService : BaseService() {
|
|||||||
val cancelId = intent.getIntExtra(EXTRA_CANCEL_ID, 0)
|
val cancelId = intent.getIntExtra(EXTRA_CANCEL_ID, 0)
|
||||||
jobs[cancelId]?.cancel()
|
jobs[cancelId]?.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
ACTION_DOWNLOAD_RESUME -> {
|
ACTION_DOWNLOAD_RESUME -> {
|
||||||
val cancelId = intent.getIntExtra(EXTRA_CANCEL_ID, 0)
|
val cancelId = intent.getIntExtra(EXTRA_CANCEL_ID, 0)
|
||||||
jobs[cancelId]?.resume()
|
jobs[cancelId]?.resume()
|
||||||
@@ -254,7 +263,7 @@ class DownloadService : BaseService() {
|
|||||||
|
|
||||||
fun getDownloadedManga(intent: Intent?): Manga? {
|
fun getDownloadedManga(intent: Intent?): Manga? {
|
||||||
if (intent?.action == ACTION_DOWNLOAD_COMPLETE) {
|
if (intent?.action == ACTION_DOWNLOAD_COMPLETE) {
|
||||||
return intent.getParcelableExtra<ParcelableManga>(EXTRA_MANGA)?.manga
|
return intent.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|||||||
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
||||||
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment
|
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment
|
||||||
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment.Companion.NO_ID
|
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment.Companion.NO_ID
|
||||||
|
import kotlin.text.Typography.dagger
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class FavouritesActivity : BaseActivity<ActivityContainerBinding>() {
|
class FavouritesActivity : BaseActivity<ActivityContainerBinding>() {
|
||||||
@@ -28,6 +29,7 @@ class FavouritesActivity : BaseActivity<ActivityContainerBinding>() {
|
|||||||
val fm = supportFragmentManager
|
val fm = supportFragmentManager
|
||||||
if (fm.findFragmentById(R.id.container) == null) {
|
if (fm.findFragmentById(R.id.container) == null) {
|
||||||
fm.commit {
|
fm.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
val fragment = FavouritesListFragment.newInstance(intent.getLongExtra(EXTRA_CATEGORY_ID, NO_ID))
|
val fragment = FavouritesListFragment.newInstance(intent.getLongExtra(EXTRA_CATEGORY_ID, NO_ID))
|
||||||
replace(R.id.container, fragment)
|
replace(R.id.container, fragment)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
|
import kotlin.jvm.internal.Intrinsics
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesListListener
|
import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesListListener
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.emptyStateListAD
|
import org.koitharu.kotatsu.list.ui.adapter.emptyStateListAD
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.loadingStateAD
|
import org.koitharu.kotatsu.list.ui.adapter.loadingStateAD
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import kotlin.jvm.internal.Intrinsics
|
|
||||||
|
|
||||||
class CategoriesAdapter(
|
class CategoriesAdapter(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -20,7 +20,7 @@ class CategoriesAdapter(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
delegatesManager.addDelegate(categoryAD(coil, lifecycleOwner, onItemClickListener))
|
delegatesManager.addDelegate(categoryAD(coil, lifecycleOwner, onItemClickListener))
|
||||||
.addDelegate(emptyStateListAD(listListener))
|
.addDelegate(emptyStateListAD(coil, listListener))
|
||||||
.addDelegate(loadingStateAD())
|
.addDelegate(loadingStateAD())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,4 +56,4 @@ class CategoriesAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import androidx.core.graphics.Insets
|
|||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
@@ -25,6 +26,7 @@ import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesActivity
|
|||||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.utils.ext.assistedViewModels
|
import org.koitharu.kotatsu.utils.ext.assistedViewModels
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getSerializableCompat
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class FavouritesCategoryEditActivity :
|
class FavouritesCategoryEditActivity :
|
||||||
@@ -46,7 +48,7 @@ class FavouritesCategoryEditActivity :
|
|||||||
setContentView(ActivityCategoryEditBinding.inflate(layoutInflater))
|
setContentView(ActivityCategoryEditBinding.inflate(layoutInflater))
|
||||||
supportActionBar?.run {
|
supportActionBar?.run {
|
||||||
setDisplayHomeAsUpEnabled(true)
|
setDisplayHomeAsUpEnabled(true)
|
||||||
setHomeAsUpIndicator(com.google.android.material.R.drawable.abc_ic_clear_material)
|
setHomeAsUpIndicator(materialR.drawable.abc_ic_clear_material)
|
||||||
}
|
}
|
||||||
initSortSpinner()
|
initSortSpinner()
|
||||||
binding.buttonDone.setOnClickListener(this)
|
binding.buttonDone.setOnClickListener(this)
|
||||||
@@ -69,8 +71,8 @@ class FavouritesCategoryEditActivity :
|
|||||||
|
|
||||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onRestoreInstanceState(savedInstanceState)
|
super.onRestoreInstanceState(savedInstanceState)
|
||||||
val order = savedInstanceState.getSerializable(KEY_SORT_ORDER)
|
val order = savedInstanceState.getSerializableCompat<SortOrder>(KEY_SORT_ORDER)
|
||||||
if (order != null && order is SortOrder) {
|
if (order != null) {
|
||||||
selectedSortOrder = order
|
selectedSortOrder = order
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ import org.koitharu.kotatsu.list.ui.model.toErrorState
|
|||||||
import org.koitharu.kotatsu.list.ui.model.toUi
|
import org.koitharu.kotatsu.list.ui.model.toUi
|
||||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||||
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
class FavouritesListViewModel @AssistedInject constructor(
|
class FavouritesListViewModel @AssistedInject constructor(
|
||||||
@Assisted private val categoryId: Long,
|
@Assisted private val categoryId: Long,
|
||||||
@@ -53,7 +55,7 @@ class FavouritesListViewModel @AssistedInject constructor(
|
|||||||
} else {
|
} else {
|
||||||
repository.observeAll(categoryId)
|
repository.observeAll(categoryId)
|
||||||
},
|
},
|
||||||
createListModeFlow()
|
createListModeFlow(),
|
||||||
) { list, mode ->
|
) { list, mode ->
|
||||||
when {
|
when {
|
||||||
list.isEmpty() -> listOf(
|
list.isEmpty() -> listOf(
|
||||||
@@ -66,19 +68,20 @@ class FavouritesListViewModel @AssistedInject constructor(
|
|||||||
R.string.favourites_category_empty
|
R.string.favourites_category_empty
|
||||||
},
|
},
|
||||||
actionStringRes = 0,
|
actionStringRes = 0,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> list.toUi(mode, this)
|
else -> list.toUi(mode, this)
|
||||||
}
|
}
|
||||||
}.catch {
|
}.catch {
|
||||||
emit(listOf(it.toErrorState(canRetry = false)))
|
emit(listOf(it.toErrorState(canRetry = false)))
|
||||||
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (categoryId != NO_ID) {
|
if (categoryId != NO_ID) {
|
||||||
launchJob {
|
launchJob {
|
||||||
categoryName = withContext(Dispatchers.Default) {
|
categoryName = withContext(Dispatchers.Default) {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
repository.getCategory(categoryId).title
|
repository.getCategory(categoryId).title
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.base.ui.BaseActivity
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
||||||
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
||||||
|
import kotlin.text.Typography.dagger
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class HistoryActivity :
|
class HistoryActivity :
|
||||||
@@ -28,6 +29,7 @@ class HistoryActivity :
|
|||||||
val fm = supportFragmentManager
|
val fm = supportFragmentManager
|
||||||
if (fm.findFragmentById(R.id.container) == null) {
|
if (fm.findFragmentById(R.id.container) == null) {
|
||||||
fm.commit {
|
fm.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
val fragment = HistoryListFragment.newInstance()
|
val fragment = HistoryListFragment.newInstance()
|
||||||
replace(R.id.container, fragment)
|
replace(R.id.container, fragment)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import android.view.Menu
|
|||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.core.view.MenuProvider
|
import androidx.core.view.MenuProvider
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
|
|
||||||
class HistoryListMenuProvider(
|
class HistoryListMenuProvider(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@@ -38,6 +38,6 @@ class HistoryListMenuProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareMenu(menu: Menu) {
|
override fun onPrepareMenu(menu: Menu) {
|
||||||
menu.findItem(R.id.action_history_grouping).isChecked = viewModel.isGroupingEnabled.value == true
|
menu.findItem(R.id.action_history_grouping)?.isChecked = viewModel.isGroupingEnabled.value == true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
|||||||
import org.koitharu.kotatsu.list.ui.MangaListViewModel
|
import org.koitharu.kotatsu.list.ui.MangaListViewModel
|
||||||
import org.koitharu.kotatsu.list.ui.model.*
|
import org.koitharu.kotatsu.list.ui.model.*
|
||||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
import org.koitharu.kotatsu.utils.ext.daysDiff
|
import org.koitharu.kotatsu.utils.ext.daysDiff
|
||||||
import org.koitharu.kotatsu.utils.ext.onFirst
|
import org.koitharu.kotatsu.utils.ext.onFirst
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@ class HistoryListViewModel @Inject constructor(
|
|||||||
}.onFirst {
|
}.onFirst {
|
||||||
loadingCounter.decrement()
|
loadingCounter.decrement()
|
||||||
}.catch {
|
}.catch {
|
||||||
it.toErrorState(canRetry = false)
|
emit(listOf(it.toErrorState(canRetry = false)))
|
||||||
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
||||||
|
|
||||||
override fun onRefresh() = Unit
|
override fun onRefresh() = Unit
|
||||||
|
|
||||||
|
|||||||
@@ -56,17 +56,17 @@ class ReadingProgressView @JvmOverloads constructor(
|
|||||||
getProgressDrawable().progress = p
|
getProgressDrawable().progress = p
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAnimationStart(animation: Animator?) = Unit
|
override fun onAnimationStart(animation: Animator) = Unit
|
||||||
|
|
||||||
override fun onAnimationEnd(animation: Animator?) {
|
override fun onAnimationEnd(animation: Animator) {
|
||||||
if (percentAnimator === animation) {
|
if (percentAnimator === animation) {
|
||||||
percentAnimator = null
|
percentAnimator = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAnimationCancel(animation: Animator?) = Unit
|
override fun onAnimationCancel(animation: Animator) = Unit
|
||||||
|
|
||||||
override fun onAnimationRepeat(animation: Animator?) = Unit
|
override fun onAnimationRepeat(animation: Animator) = Unit
|
||||||
|
|
||||||
fun setPercent(value: Float, animate: Boolean) {
|
fun setPercent(value: Float, animate: Boolean) {
|
||||||
val currentDrawable = peekProgressDrawable()
|
val currentDrawable = peekProgressDrawable()
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class ImageActivity : BaseActivity<ActivityImageBinding>() {
|
|||||||
|
|
||||||
private fun setDrawable(drawable: Drawable?) {
|
private fun setDrawable(drawable: Drawable?) {
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
view.setImage(ImageSource.bitmap(drawable.toBitmap()))
|
view.setImage(ImageSource.Bitmap(drawable.toBitmap()))
|
||||||
} else {
|
} else {
|
||||||
view.recycle()
|
view.recycle()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.library.ui.adapter
|
|
||||||
|
|
||||||
import android.view.View
|
|
||||||
import org.koitharu.kotatsu.library.ui.model.LibrarySectionModel
|
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
|
||||||
|
|
||||||
interface LibraryListEventListener : ListStateHolderListener {
|
|
||||||
|
|
||||||
fun onItemClick(item: Manga, section: LibrarySectionModel, view: View)
|
|
||||||
|
|
||||||
fun onItemLongClick(item: Manga, section: LibrarySectionModel, view: View): Boolean
|
|
||||||
|
|
||||||
fun onSectionClick(section: LibrarySectionModel, view: View)
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@ import android.view.View
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.annotation.StyleRes
|
import androidx.annotation.StyleRes
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.core.widget.TextViewCompat
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@@ -46,12 +47,12 @@ class ItemSizeResolver(resources: Resources, private val settings: AppSettings)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewAttachedToWindow(v: View?) {
|
override fun onViewAttachedToWindow(v: View) {
|
||||||
settings.subscribe(this)
|
settings.subscribe(this)
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewDetachedFromWindow(v: View?) {
|
override fun onViewDetachedFromWindow(v: View) {
|
||||||
settings.unsubscribe(this)
|
settings.unsubscribe(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +78,7 @@ class ItemSizeResolver(resources: Resources, private val settings: AppSettings)
|
|||||||
}
|
}
|
||||||
if (textAppearanceResId != prevTextAppearance) {
|
if (textAppearanceResId != prevTextAppearance) {
|
||||||
prevTextAppearance = textAppearanceResId
|
prevTextAppearance = textAppearanceResId
|
||||||
setTextAppearance(textAppearanceResId)
|
TextViewCompat.setTextAppearance(this, textAppearanceResId)
|
||||||
requestLayout()
|
requestLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import androidx.fragment.app.FragmentManager
|
|||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.slider.Slider
|
import com.google.android.material.slider.Slider
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import javax.inject.Inject
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
||||||
import org.koitharu.kotatsu.base.ui.widgets.CheckableButtonGroup
|
import org.koitharu.kotatsu.base.ui.widgets.CheckableButtonGroup
|
||||||
@@ -17,7 +18,6 @@ import org.koitharu.kotatsu.core.prefs.ListMode
|
|||||||
import org.koitharu.kotatsu.databinding.DialogListModeBinding
|
import org.koitharu.kotatsu.databinding.DialogListModeBinding
|
||||||
import org.koitharu.kotatsu.utils.ext.setValueRounded
|
import org.koitharu.kotatsu.utils.ext.setValueRounded
|
||||||
import org.koitharu.kotatsu.utils.progress.IntPercentLabelFormatter
|
import org.koitharu.kotatsu.utils.progress.IntPercentLabelFormatter
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ListModeSelectDialog :
|
class ListModeSelectDialog :
|
||||||
@@ -33,8 +33,9 @@ class ListModeSelectDialog :
|
|||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
) = DialogListModeBinding.inflate(inflater, container, false)
|
) = DialogListModeBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
override fun onBuildDialog(builder: MaterialAlertDialogBuilder) {
|
override fun onBuildDialog(builder: MaterialAlertDialogBuilder): MaterialAlertDialogBuilder {
|
||||||
builder.setTitle(R.string.list_mode)
|
return super.onBuildDialog(builder)
|
||||||
|
.setTitle(R.string.list_mode)
|
||||||
.setPositiveButton(R.string.done, null)
|
.setPositiveButton(R.string.done, null)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
@file:SuppressLint("UnsafeOptInUsageError")
|
|
||||||
package org.koitharu.kotatsu.list.ui.adapter
|
package org.koitharu.kotatsu.list.ui.adapter
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.annotation.CheckResult
|
||||||
import androidx.core.view.doOnNextLayout
|
import androidx.core.view.doOnNextLayout
|
||||||
import com.google.android.material.badge.BadgeDrawable
|
import com.google.android.material.badge.BadgeDrawable
|
||||||
import com.google.android.material.badge.BadgeUtils
|
import com.google.android.material.badge.BadgeUtils
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
@CheckResult
|
||||||
fun View.bindBadge(badge: BadgeDrawable?, counter: Int): BadgeDrawable? {
|
fun View.bindBadge(badge: BadgeDrawable?, counter: Int): BadgeDrawable? {
|
||||||
return if (counter > 0) {
|
return if (counter > 0) {
|
||||||
val badgeDrawable = badge ?: initBadge(this)
|
val badgeDrawable = badge ?: initBadge(this)
|
||||||
@@ -39,4 +39,4 @@ private fun initBadge(anchor: View): BadgeDrawable {
|
|||||||
private fun BadgeDrawable.align() {
|
private fun BadgeDrawable.align() {
|
||||||
horizontalOffset = intrinsicWidth
|
horizontalOffset = intrinsicWidth
|
||||||
verticalOffset = intrinsicHeight
|
verticalOffset = intrinsicHeight
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,31 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.adapter
|
package org.koitharu.kotatsu.list.ui.adapter
|
||||||
|
|
||||||
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.databinding.ItemEmptyStateBinding
|
import org.koitharu.kotatsu.databinding.ItemEmptyStateBinding
|
||||||
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
import org.koitharu.kotatsu.utils.ext.setTextAndVisible
|
import org.koitharu.kotatsu.utils.ext.setTextAndVisible
|
||||||
|
|
||||||
fun emptyStateListAD(
|
fun emptyStateListAD(
|
||||||
|
coil: ImageLoader,
|
||||||
listener: ListStateHolderListener,
|
listener: ListStateHolderListener,
|
||||||
) = adapterDelegateViewBinding<EmptyState, ListModel, ItemEmptyStateBinding>(
|
) = adapterDelegateViewBinding<EmptyState, ListModel, ItemEmptyStateBinding>(
|
||||||
{ inflater, parent -> ItemEmptyStateBinding.inflate(inflater, parent, false) }
|
{ inflater, parent -> ItemEmptyStateBinding.inflate(inflater, parent, false) },
|
||||||
) {
|
) {
|
||||||
|
|
||||||
binding.buttonRetry.setOnClickListener { listener.onEmptyActionClick() }
|
binding.buttonRetry.setOnClickListener { listener.onEmptyActionClick() }
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.icon.setImageResource(item.icon)
|
binding.icon.newImageRequest(item.icon)?.enqueueWith(coil)
|
||||||
binding.textPrimary.setText(item.textPrimary)
|
binding.textPrimary.setText(item.textPrimary)
|
||||||
binding.textSecondary.setTextAndVisible(item.textSecondary)
|
binding.textSecondary.setTextAndVisible(item.textSecondary)
|
||||||
binding.buttonRetry.setTextAndVisible(item.actionStringRes)
|
binding.buttonRetry.setTextAndVisible(item.actionStringRes)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
onViewRecycled {
|
||||||
|
binding.icon.disposeImageRequest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
|
import kotlin.jvm.internal.Intrinsics
|
||||||
import org.koitharu.kotatsu.core.ui.DateTimeAgo
|
import org.koitharu.kotatsu.core.ui.DateTimeAgo
|
||||||
import org.koitharu.kotatsu.list.ui.model.*
|
import org.koitharu.kotatsu.list.ui.model.*
|
||||||
import kotlin.jvm.internal.Intrinsics
|
|
||||||
|
|
||||||
open class MangaListAdapter(
|
open class MangaListAdapter(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
@@ -24,7 +24,7 @@ open class MangaListAdapter(
|
|||||||
.addDelegate(ITEM_TYPE_DATE, relatedDateItemAD())
|
.addDelegate(ITEM_TYPE_DATE, relatedDateItemAD())
|
||||||
.addDelegate(ITEM_TYPE_ERROR_STATE, errorStateListAD(listener))
|
.addDelegate(ITEM_TYPE_ERROR_STATE, errorStateListAD(listener))
|
||||||
.addDelegate(ITEM_TYPE_ERROR_FOOTER, errorFooterAD(listener))
|
.addDelegate(ITEM_TYPE_ERROR_FOOTER, errorFooterAD(listener))
|
||||||
.addDelegate(ITEM_TYPE_EMPTY, emptyStateListAD(listener))
|
.addDelegate(ITEM_TYPE_EMPTY, emptyStateListAD(coil, listener))
|
||||||
.addDelegate(ITEM_TYPE_HEADER, listHeaderAD(listener))
|
.addDelegate(ITEM_TYPE_HEADER, listHeaderAD(listener))
|
||||||
.addDelegate(ITEM_TYPE_HEADER_2, listHeader2AD(listener))
|
.addDelegate(ITEM_TYPE_HEADER_2, listHeader2AD(listener))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ fun mangaListDetailedItemAD(
|
|||||||
}
|
}
|
||||||
binding.textViewRating.textAndVisible = item.rating
|
binding.textViewRating.textAndVisible = item.rating
|
||||||
binding.textViewTags.text = item.tags
|
binding.textViewTags.text = item.tags
|
||||||
itemView.bindBadge(badge, item.counter)
|
badge = itemView.bindBadge(badge, item.counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
onViewRecycled {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ fun mangaListItemAD(
|
|||||||
lifecycle(lifecycleOwner)
|
lifecycle(lifecycleOwner)
|
||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
itemView.bindBadge(badge, item.counter)
|
badge = itemView.bindBadge(badge, item.counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
onViewRecycled {
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.filter
|
package org.koitharu.kotatsu.list.ui.filter
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.AsyncListDiffer.ListListener
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
|
|
||||||
class FilterAdapter(
|
class FilterAdapter(
|
||||||
listener: OnFilterChangedListener,
|
listener: OnFilterChangedListener,
|
||||||
|
listListener: ListListener<FilterItem>,
|
||||||
) : AsyncListDifferDelegationAdapter<FilterItem>(
|
) : AsyncListDifferDelegationAdapter<FilterItem>(
|
||||||
FilterDiffCallback(),
|
FilterDiffCallback(),
|
||||||
filterSortDelegate(listener),
|
filterSortDelegate(listener),
|
||||||
@@ -11,4 +13,9 @@ class FilterAdapter(
|
|||||||
filterHeaderDelegate(),
|
filterHeaderDelegate(),
|
||||||
filterLoadingDelegate(),
|
filterLoadingDelegate(),
|
||||||
filterErrorDelegate(),
|
filterErrorDelegate(),
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
differ.addListListener(listListener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,18 +6,21 @@ import android.os.Bundle
|
|||||||
import android.view.*
|
import android.view.*
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import androidx.recyclerview.widget.AsyncListDiffer
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
||||||
import org.koitharu.kotatsu.databinding.SheetFilterBinding
|
import org.koitharu.kotatsu.databinding.SheetFilterBinding
|
||||||
import org.koitharu.kotatsu.remotelist.ui.RemoteListViewModel
|
import org.koitharu.kotatsu.remotelist.ui.RemoteListViewModel
|
||||||
|
import org.koitharu.kotatsu.utils.ext.isScrolledToTop
|
||||||
import org.koitharu.kotatsu.utils.ext.parentFragmentViewModels
|
import org.koitharu.kotatsu.utils.ext.parentFragmentViewModels
|
||||||
|
|
||||||
class FilterBottomSheet :
|
class FilterBottomSheet :
|
||||||
BaseBottomSheet<SheetFilterBinding>(),
|
BaseBottomSheet<SheetFilterBinding>(),
|
||||||
MenuItem.OnActionExpandListener,
|
MenuItem.OnActionExpandListener,
|
||||||
SearchView.OnQueryTextListener,
|
SearchView.OnQueryTextListener,
|
||||||
DialogInterface.OnKeyListener {
|
DialogInterface.OnKeyListener,
|
||||||
|
AsyncListDiffer.ListListener<FilterItem> {
|
||||||
|
|
||||||
private val viewModel by parentFragmentViewModels<RemoteListViewModel>()
|
private val viewModel by parentFragmentViewModels<RemoteListViewModel>()
|
||||||
|
|
||||||
@@ -33,13 +36,13 @@ class FilterBottomSheet :
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val adapter = FilterAdapter(viewModel)
|
val adapter = FilterAdapter(viewModel, this)
|
||||||
binding.recyclerView.adapter = adapter
|
binding.recyclerView.adapter = adapter
|
||||||
viewModel.filterItems.observe(viewLifecycleOwner, adapter::setItems)
|
viewModel.filterItems.observe(viewLifecycleOwner, adapter::setItems)
|
||||||
initOptionsMenu()
|
initOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||||
setExpanded(isExpanded = true, isLocked = true)
|
setExpanded(isExpanded = true, isLocked = true)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -71,6 +74,12 @@ class FilterBottomSheet :
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCurrentListChanged(previousList: MutableList<FilterItem>, currentList: MutableList<FilterItem>) {
|
||||||
|
if (currentList.size > previousList.size && view != null) {
|
||||||
|
(binding.recyclerView.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun initOptionsMenu() {
|
private fun initOptionsMenu() {
|
||||||
binding.headerBar.toolbar.inflateMenu(R.menu.opt_filter)
|
binding.headerBar.toolbar.inflateMenu(R.menu.opt_filter)
|
||||||
val searchMenuItem = binding.headerBar.toolbar.menu.findItem(R.id.action_search)
|
val searchMenuItem = binding.headerBar.toolbar.menu.findItem(R.id.action_search)
|
||||||
|
|||||||
@@ -6,15 +6,22 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.CoroutineStart
|
import kotlinx.coroutines.CoroutineStart
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.*
|
import java.util.Locale
|
||||||
|
import java.util.TreeSet
|
||||||
|
|
||||||
class FilterCoordinator(
|
class FilterCoordinator(
|
||||||
private val repository: RemoteMangaRepository,
|
private val repository: RemoteMangaRepository,
|
||||||
@@ -153,7 +160,7 @@ class FilterCoordinator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun loadTagsAsync() = coroutineScope.async(Dispatchers.Default, CoroutineStart.LAZY) {
|
private fun loadTagsAsync() = coroutineScope.async(Dispatchers.Default, CoroutineStart.LAZY) {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
repository.getTags()
|
repository.getTags()
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
error.printStackTraceDebug()
|
error.printStackTraceDebug()
|
||||||
@@ -204,4 +211,4 @@ class FilterCoordinator(
|
|||||||
return collator?.compare(t1, t2) ?: compareValues(t1, t2)
|
return collator?.compare(t1, t2) ?: compareValues(t1, t2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class CbzMangaOutput(
|
|||||||
index.addChapter(chapter)
|
index.addChapter(chapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun finalize() {
|
suspend fun finish() {
|
||||||
runInterruptible(Dispatchers.IO) {
|
runInterruptible(Dispatchers.IO) {
|
||||||
output.put(ENTRY_NAME_INDEX, index.toString())
|
output.put(ENTRY_NAME_INDEX, index.toString())
|
||||||
output.finish()
|
output.finish()
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package org.koitharu.kotatsu.local.domain
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
|
||||||
|
class LocalManga(
|
||||||
|
val manga: Manga,
|
||||||
|
val file: File,
|
||||||
|
) {
|
||||||
|
|
||||||
|
var createdAt: Long = -1L
|
||||||
|
get() {
|
||||||
|
if (field == -1L) {
|
||||||
|
field = file.lastModified()
|
||||||
|
}
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as LocalManga
|
||||||
|
|
||||||
|
if (manga != other.manga) return false
|
||||||
|
if (file != other.file) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = manga.hashCode()
|
||||||
|
result = 31 * result + file.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Collection<LocalManga>.unwrap(): List<Manga> = map { it.manga }
|
||||||
|
|
||||||
|
fun LocalManga.isMatchesQuery(query: String): Boolean {
|
||||||
|
return manga.title.contains(query, ignoreCase = true) ||
|
||||||
|
manga.altTitle?.contains(query, ignoreCase = true) == true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun LocalManga.containsTags(tags: Set<MangaTag>): Boolean {
|
||||||
|
return manga.tags.containsAll(tags)
|
||||||
|
}
|
||||||
@@ -7,28 +7,40 @@ import androidx.annotation.WorkerThread
|
|||||||
import androidx.collection.ArraySet
|
import androidx.collection.ArraySet
|
||||||
import androidx.core.net.toFile
|
import androidx.core.net.toFile
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import java.io.File
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import java.util.*
|
import kotlinx.coroutines.Deferred
|
||||||
import java.util.zip.ZipEntry
|
import kotlinx.coroutines.Dispatchers
|
||||||
import java.util.zip.ZipFile
|
import kotlinx.coroutines.async
|
||||||
import javax.inject.Inject
|
import kotlinx.coroutines.awaitAll
|
||||||
import javax.inject.Singleton
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlin.coroutines.CoroutineContext
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.filterNot
|
import kotlinx.coroutines.flow.filterNot
|
||||||
|
import kotlinx.coroutines.runInterruptible
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.local.data.CbzFilter
|
import org.koitharu.kotatsu.local.data.CbzFilter
|
||||||
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
||||||
import org.koitharu.kotatsu.local.data.MangaIndex
|
import org.koitharu.kotatsu.local.data.MangaIndex
|
||||||
import org.koitharu.kotatsu.local.data.TempFileFilter
|
import org.koitharu.kotatsu.local.data.TempFileFilter
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.parsers.util.toCamelCase
|
import org.koitharu.kotatsu.parsers.util.toCamelCase
|
||||||
import org.koitharu.kotatsu.utils.AlphanumComparator
|
import org.koitharu.kotatsu.utils.AlphanumComparator
|
||||||
import org.koitharu.kotatsu.utils.CompositeMutex
|
import org.koitharu.kotatsu.utils.CompositeMutex
|
||||||
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
||||||
import org.koitharu.kotatsu.utils.ext.longHashCode
|
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||||
import org.koitharu.kotatsu.utils.ext.readText
|
import org.koitharu.kotatsu.utils.ext.readText
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import java.io.File
|
||||||
|
import java.util.Enumeration
|
||||||
|
import java.util.zip.ZipEntry
|
||||||
|
import java.util.zip.ZipFile
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
private const val MAX_PARALLELISM = 4
|
private const val MAX_PARALLELISM = 4
|
||||||
|
|
||||||
@@ -45,12 +57,9 @@ class LocalMangaRepository @Inject constructor(private val storageManager: Local
|
|||||||
}
|
}
|
||||||
val list = getRawList()
|
val list = getRawList()
|
||||||
if (query.isNotEmpty()) {
|
if (query.isNotEmpty()) {
|
||||||
list.retainAll { x ->
|
list.retainAll { x -> x.isMatchesQuery(query) }
|
||||||
x.title.contains(query, ignoreCase = true) ||
|
|
||||||
x.altTitle?.contains(query, ignoreCase = true) == true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return list
|
return list.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getList(offset: Int, tags: Set<MangaTag>?, sortOrder: SortOrder?): List<Manga> {
|
override suspend fun getList(offset: Int, tags: Set<MangaTag>?, sortOrder: SortOrder?): List<Manga> {
|
||||||
@@ -59,17 +68,25 @@ class LocalMangaRepository @Inject constructor(private val storageManager: Local
|
|||||||
}
|
}
|
||||||
val list = getRawList()
|
val list = getRawList()
|
||||||
if (!tags.isNullOrEmpty()) {
|
if (!tags.isNullOrEmpty()) {
|
||||||
list.retainAll { x ->
|
list.retainAll { x -> x.containsTags(tags) }
|
||||||
x.tags.containsAll(tags)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return list
|
when (sortOrder) {
|
||||||
|
SortOrder.ALPHABETICAL -> list.sortWith(compareBy(AlphanumComparator()) { x -> x.manga.title })
|
||||||
|
SortOrder.RATING -> list.sortByDescending { it.manga.rating }
|
||||||
|
SortOrder.NEWEST,
|
||||||
|
SortOrder.UPDATED,
|
||||||
|
-> list.sortByDescending { it.createdAt }
|
||||||
|
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
return list.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga) = when {
|
override suspend fun getDetails(manga: Manga) = when {
|
||||||
manga.source != MangaSource.LOCAL -> requireNotNull(findSavedManga(manga)) {
|
manga.source != MangaSource.LOCAL -> requireNotNull(findSavedManga(manga)) {
|
||||||
"Manga is not local or saved"
|
"Manga is not local or saved"
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> getFromFile(Uri.parse(manga.url).toFile())
|
else -> getFromFile(Uri.parse(manga.url).toFile())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,9 +248,9 @@ class LocalMangaRepository @Inject constructor(private val storageManager: Local
|
|||||||
private fun CoroutineScope.getFromFileAsync(
|
private fun CoroutineScope.getFromFileAsync(
|
||||||
file: File,
|
file: File,
|
||||||
context: CoroutineContext,
|
context: CoroutineContext,
|
||||||
): Deferred<Manga?> = async(context) {
|
): Deferred<LocalManga?> = async(context) {
|
||||||
runInterruptible {
|
runInterruptible {
|
||||||
runCatching { getFromFile(file) }.getOrNull()
|
runCatchingCancellable { LocalManga(getFromFile(file), file) }.getOrNull()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +267,7 @@ class LocalMangaRepository @Inject constructor(private val storageManager: Local
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val sortOrders = setOf(SortOrder.ALPHABETICAL)
|
override val sortOrders = setOf(SortOrder.ALPHABETICAL, SortOrder.RATING)
|
||||||
|
|
||||||
override suspend fun getPageUrl(page: MangaPage) = page.url
|
override suspend fun getPageUrl(page: MangaPage) = page.url
|
||||||
|
|
||||||
@@ -279,7 +296,7 @@ class LocalMangaRepository @Inject constructor(private val storageManager: Local
|
|||||||
locks.unlock(id)
|
locks.unlock(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getRawList(): ArrayList<Manga> {
|
private suspend fun getRawList(): ArrayList<LocalManga> {
|
||||||
val files = getAllFiles()
|
val files = getAllFiles()
|
||||||
return coroutineScope {
|
return coroutineScope {
|
||||||
val dispatcher = Dispatchers.IO.limitedParallelism(MAX_PARALLELISM)
|
val dispatcher = Dispatchers.IO.limitedParallelism(MAX_PARALLELISM)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class DirMangaImporter(
|
|||||||
)
|
)
|
||||||
it.sortChaptersByName()
|
it.sortChaptersByName()
|
||||||
it.mergeWithExisting()
|
it.mergeWithExisting()
|
||||||
it.finalize()
|
it.finish()
|
||||||
it.file
|
it.file
|
||||||
}
|
}
|
||||||
return localMangaRepository.getFromFile(dest)
|
return localMangaRepository.getFromFile(dest)
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ class ImportDialogFragment : AlertDialogFragment<DialogImportBinding>(), View.On
|
|||||||
return DialogImportBinding.inflate(inflater, container, false)
|
return DialogImportBinding.inflate(inflater, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBuildDialog(builder: MaterialAlertDialogBuilder) {
|
override fun onBuildDialog(builder: MaterialAlertDialogBuilder): MaterialAlertDialogBuilder {
|
||||||
builder.setTitle(R.string._import)
|
return super.onBuildDialog(builder)
|
||||||
|
.setTitle(R.string._import)
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,12 @@ import org.koitharu.kotatsu.download.ui.service.DownloadService
|
|||||||
import org.koitharu.kotatsu.local.domain.importer.MangaImporter
|
import org.koitharu.kotatsu.local.domain.importer.MangaImporter
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.utils.PendingIntentCompat
|
import org.koitharu.kotatsu.utils.PendingIntentCompat
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.asArrayList
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.referer
|
||||||
|
import org.koitharu.kotatsu.utils.ext.report
|
||||||
|
import org.koitharu.kotatsu.utils.ext.toBitmapOrNull
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -48,8 +53,8 @@ class ImportService : CoroutineIntentService() {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun processIntent(intent: Intent?) {
|
override suspend fun processIntent(startId: Int, intent: Intent) {
|
||||||
val uris = intent?.getParcelableArrayListExtra<Uri>(EXTRA_URIS)
|
val uris = intent.getParcelableArrayListExtra<Uri>(EXTRA_URIS)
|
||||||
if (uris.isNullOrEmpty()) {
|
if (uris.isNullOrEmpty()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -69,6 +74,10 @@ class ImportService : CoroutineIntentService() {
|
|||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onError(startId: Int, error: Throwable) {
|
||||||
|
error.report()
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun importImpl(uri: Uri): Manga {
|
private suspend fun importImpl(uri: Uri): Manga {
|
||||||
val importer = importerFactory.create(uri)
|
val importer = importerFactory.create(uri)
|
||||||
return importer.import(uri)
|
return importer.import(uri)
|
||||||
|
|||||||
@@ -9,13 +9,15 @@ import androidx.core.app.NotificationCompat
|
|||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.CoroutineIntentService
|
import org.koitharu.kotatsu.base.ui.CoroutineIntentService
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class LocalChaptersRemoveService : CoroutineIntentService() {
|
class LocalChaptersRemoveService : CoroutineIntentService() {
|
||||||
@@ -33,8 +35,8 @@ class LocalChaptersRemoveService : CoroutineIntentService() {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun processIntent(intent: Intent?) {
|
override suspend fun processIntent(startId: Int, intent: Intent) {
|
||||||
val manga = intent?.getParcelableExtra<ParcelableManga>(EXTRA_MANGA)?.manga ?: return
|
val manga = intent.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga ?: return
|
||||||
val chaptersIds = intent.getLongArrayExtra(EXTRA_CHAPTERS_IDS)?.toSet() ?: return
|
val chaptersIds = intent.getLongArrayExtra(EXTRA_CHAPTERS_IDS)?.toSet() ?: return
|
||||||
startForeground()
|
startForeground()
|
||||||
val mangaWithChapters = localMangaRepository.getDetails(manga)
|
val mangaWithChapters = localMangaRepository.getDetails(manga)
|
||||||
@@ -46,6 +48,21 @@ class LocalChaptersRemoveService : CoroutineIntentService() {
|
|||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onError(startId: Int, error: Throwable) {
|
||||||
|
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
|
||||||
|
.setContentTitle(getString(R.string.error_occurred))
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
|
.setDefaults(0)
|
||||||
|
.setColor(ContextCompat.getColor(this, R.color.blue_primary_dark))
|
||||||
|
.setSilent(true)
|
||||||
|
.setContentText(error.getDisplayMessage(resources))
|
||||||
|
.setSmallIcon(android.R.drawable.stat_notify_error)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.build()
|
||||||
|
val nm = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
nm.notify(NOTIFICATION_ID + startId, notification)
|
||||||
|
}
|
||||||
|
|
||||||
private fun startForeground() {
|
private fun startForeground() {
|
||||||
val title = getString(R.string.local_manga_processing)
|
val title = getString(R.string.local_manga_processing)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.view.Menu
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
|
import androidx.appcompat.widget.PopupMenu
|
||||||
import androidx.core.net.toFile
|
import androidx.core.net.toFile
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
@@ -13,10 +14,11 @@ import com.google.android.material.snackbar.Snackbar
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.list.ListSelectionController
|
import org.koitharu.kotatsu.base.ui.list.ListSelectionController
|
||||||
import org.koitharu.kotatsu.list.ui.MangaListFragment
|
import org.koitharu.kotatsu.list.ui.MangaListFragment
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.utils.ShareHelper
|
import org.koitharu.kotatsu.utils.ShareHelper
|
||||||
import org.koitharu.kotatsu.utils.ext.addMenuProvider
|
import org.koitharu.kotatsu.utils.ext.addMenuProvider
|
||||||
|
|
||||||
class LocalListFragment : MangaListFragment() {
|
class LocalListFragment : MangaListFragment(), PopupMenu.OnMenuItemClickListener {
|
||||||
|
|
||||||
override val viewModel by viewModels<LocalListViewModel>()
|
override val viewModel by viewModels<LocalListViewModel>()
|
||||||
|
|
||||||
@@ -30,6 +32,14 @@ class LocalListFragment : MangaListFragment() {
|
|||||||
ImportDialogFragment.show(childFragmentManager)
|
ImportDialogFragment.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onFilterClick(view: View?) {
|
||||||
|
super.onFilterClick(view)
|
||||||
|
val menu = PopupMenu(requireContext(), view ?: binding.recyclerView)
|
||||||
|
menu.inflate(R.menu.popup_order)
|
||||||
|
menu.setOnMenuItemClickListener(this)
|
||||||
|
menu.show()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onScrolledToEnd() = Unit
|
override fun onScrolledToEnd() = Unit
|
||||||
|
|
||||||
override fun onCreateActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean {
|
override fun onCreateActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean {
|
||||||
@@ -53,6 +63,17 @@ class LocalListFragment : MangaListFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||||
|
val order = when (item.itemId) {
|
||||||
|
R.id.action_order_new -> SortOrder.NEWEST
|
||||||
|
R.id.action_order_abs -> SortOrder.ALPHABETICAL
|
||||||
|
R.id.action_order_rating -> SortOrder.RATING
|
||||||
|
else -> return false
|
||||||
|
}
|
||||||
|
viewModel.setSortOrder(order)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
private fun showDeletionConfirm(ids: Set<Long>, mode: ActionMode) {
|
private fun showDeletionConfirm(ids: Set<Long>, mode: ActionMode) {
|
||||||
MaterialAlertDialogBuilder(context ?: return)
|
MaterialAlertDialogBuilder(context ?: return)
|
||||||
.setTitle(R.string.delete_manga)
|
.setTitle(R.string.delete_manga)
|
||||||
|
|||||||
@@ -23,4 +23,4 @@ class LocalListMenuProvider(
|
|||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,58 @@
|
|||||||
package org.koitharu.kotatsu.local.ui
|
package org.koitharu.kotatsu.local.ui
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.asFlow
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
|
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
||||||
|
import org.koitharu.kotatsu.list.domain.ListExtraProvider
|
||||||
import org.koitharu.kotatsu.list.ui.MangaListViewModel
|
import org.koitharu.kotatsu.list.ui.MangaListViewModel
|
||||||
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
import org.koitharu.kotatsu.list.ui.model.*
|
||||||
import org.koitharu.kotatsu.list.ui.model.LoadingState
|
|
||||||
import org.koitharu.kotatsu.list.ui.model.toErrorState
|
|
||||||
import org.koitharu.kotatsu.list.ui.model.toUi
|
|
||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class LocalListViewModel @Inject constructor(
|
class LocalListViewModel @Inject constructor(
|
||||||
private val repository: LocalMangaRepository,
|
private val repository: LocalMangaRepository,
|
||||||
private val historyRepository: HistoryRepository,
|
private val historyRepository: HistoryRepository,
|
||||||
settings: AppSettings,
|
private val trackingRepository: TrackingRepository,
|
||||||
) : MangaListViewModel(settings) {
|
private val settings: AppSettings,
|
||||||
|
) : MangaListViewModel(settings), ListExtraProvider {
|
||||||
|
|
||||||
val onMangaRemoved = SingleLiveEvent<Unit>()
|
val onMangaRemoved = SingleLiveEvent<Unit>()
|
||||||
|
val sortOrder = MutableLiveData(settings.localListOrder)
|
||||||
private val listError = MutableStateFlow<Throwable?>(null)
|
private val listError = MutableStateFlow<Throwable?>(null)
|
||||||
private val mangaList = MutableStateFlow<List<Manga>?>(null)
|
private val mangaList = MutableStateFlow<List<Manga>?>(null)
|
||||||
|
private val selectedTags = MutableStateFlow<Set<MangaTag>>(emptySet())
|
||||||
|
private var refreshJob: Job? = null
|
||||||
|
|
||||||
override val content = combine(
|
override val content = combine(
|
||||||
mangaList,
|
mangaList,
|
||||||
createListModeFlow(),
|
createListModeFlow(),
|
||||||
|
sortOrder.asFlow(),
|
||||||
|
selectedTags,
|
||||||
listError,
|
listError,
|
||||||
) { list, mode, error ->
|
) { list, mode, order, tags, error ->
|
||||||
when {
|
when {
|
||||||
error != null -> listOf(error.toErrorState(canRetry = true))
|
error != null -> listOf(error.toErrorState(canRetry = true))
|
||||||
list == null -> listOf(LoadingState)
|
list == null -> listOf(LoadingState)
|
||||||
@@ -53,7 +64,11 @@ class LocalListViewModel @Inject constructor(
|
|||||||
actionStringRes = R.string._import,
|
actionStringRes = R.string._import,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else -> list.toUi(mode)
|
|
||||||
|
else -> buildList(list.size + 1) {
|
||||||
|
add(createHeader(list, tags, order))
|
||||||
|
list.toUi(this, mode, this@LocalListViewModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
||||||
|
|
||||||
@@ -63,14 +78,27 @@ class LocalListViewModel @Inject constructor(
|
|||||||
watchDirectories()
|
watchDirectories()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onUpdateFilter(tags: Set<MangaTag>) {
|
||||||
|
selectedTags.value = tags
|
||||||
|
onRefresh()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRefresh() {
|
override fun onRefresh() {
|
||||||
launchLoadingJob(Dispatchers.Default) {
|
val prevJob = refreshJob
|
||||||
|
refreshJob = launchLoadingJob(Dispatchers.Default) {
|
||||||
|
prevJob?.cancelAndJoin()
|
||||||
doRefresh()
|
doRefresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRetry() = onRefresh()
|
override fun onRetry() = onRefresh()
|
||||||
|
|
||||||
|
fun setSortOrder(value: SortOrder) {
|
||||||
|
sortOrder.value = value
|
||||||
|
settings.localListOrder = value
|
||||||
|
onRefresh()
|
||||||
|
}
|
||||||
|
|
||||||
fun delete(ids: Set<Long>) {
|
fun delete(ids: Set<Long>) {
|
||||||
launchLoadingJob {
|
launchLoadingJob {
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
@@ -78,7 +106,7 @@ class LocalListViewModel @Inject constructor(
|
|||||||
for (manga in itemsToRemove) {
|
for (manga in itemsToRemove) {
|
||||||
val original = repository.getRemoteManga(manga)
|
val original = repository.getRemoteManga(manga)
|
||||||
repository.delete(manga) || throw IOException("Unable to delete file")
|
repository.delete(manga) || throw IOException("Unable to delete file")
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
historyRepository.deleteOrSwap(manga, original)
|
historyRepository.deleteOrSwap(manga, original)
|
||||||
}
|
}
|
||||||
mangaList.update { list ->
|
mangaList.update { list ->
|
||||||
@@ -93,7 +121,9 @@ class LocalListViewModel @Inject constructor(
|
|||||||
private suspend fun doRefresh() {
|
private suspend fun doRefresh() {
|
||||||
try {
|
try {
|
||||||
listError.value = null
|
listError.value = null
|
||||||
mangaList.value = repository.getList(0, null, null)
|
mangaList.value = repository.getList(0, selectedTags.value, sortOrder.value)
|
||||||
|
} catch (e: CancellationException) {
|
||||||
|
throw e
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
listError.value = e
|
listError.value = e
|
||||||
}
|
}
|
||||||
@@ -102,7 +132,7 @@ class LocalListViewModel @Inject constructor(
|
|||||||
private fun cleanup() {
|
private fun cleanup() {
|
||||||
if (!DownloadService.isRunning && !ImportService.isRunning && !LocalChaptersRemoveService.isRunning) {
|
if (!DownloadService.isRunning && !ImportService.isRunning && !LocalChaptersRemoveService.isRunning) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
repository.cleanup()
|
repository.cleanup()
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
error.printStackTraceDebug()
|
error.printStackTraceDebug()
|
||||||
@@ -119,4 +149,46 @@ class LocalListViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createHeader(mangaList: List<Manga>, selectedTags: Set<MangaTag>, order: SortOrder): ListHeader2 {
|
||||||
|
val tags = HashMap<MangaTag, Int>()
|
||||||
|
for (item in mangaList) {
|
||||||
|
for (tag in item.tags) {
|
||||||
|
tags[tag] = tags[tag]?.plus(1) ?: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val topTags = tags.entries.sortedByDescending { it.value }.take(6)
|
||||||
|
val chips = LinkedList<ChipsView.ChipModel>()
|
||||||
|
for ((tag, _) in topTags) {
|
||||||
|
val model = ChipsView.ChipModel(
|
||||||
|
icon = 0,
|
||||||
|
title = tag.title,
|
||||||
|
isCheckable = true,
|
||||||
|
isChecked = tag in selectedTags,
|
||||||
|
data = tag,
|
||||||
|
)
|
||||||
|
if (model.isChecked) {
|
||||||
|
chips.addFirst(model)
|
||||||
|
} else {
|
||||||
|
chips.addLast(model)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ListHeader2(
|
||||||
|
chips = chips,
|
||||||
|
sortOrder = order,
|
||||||
|
hasSelectedTags = selectedTags.isNotEmpty(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getCounter(mangaId: Long): Int {
|
||||||
|
return trackingRepository.getNewChaptersCount(mangaId)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getProgress(mangaId: Long): Float {
|
||||||
|
return if (settings.isReadingIndicatorsEnabled) {
|
||||||
|
historyRepository.getProgress(mangaId)
|
||||||
|
} else {
|
||||||
|
PROGRESS_NONE
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.main.ui
|
package org.koitharu.kotatsu.main.ui
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.SparseIntArray
|
import android.util.SparseIntArray
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
@@ -7,6 +10,7 @@ import android.view.View
|
|||||||
import androidx.activity.result.ActivityResultCallback
|
import androidx.activity.result.ActivityResultCallback
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.app.ActivityOptionsCompat
|
import androidx.core.app.ActivityOptionsCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
@@ -23,14 +27,14 @@ import com.google.android.material.appbar.AppBarLayout.LayoutParams.*
|
|||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.yield
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BaseActivity
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.base.ui.widgets.SlidingBottomNavigationView
|
import org.koitharu.kotatsu.base.ui.widgets.SlidingBottomNavigationView
|
||||||
import org.koitharu.kotatsu.databinding.ActivityMainBinding
|
import org.koitharu.kotatsu.databinding.ActivityMainBinding
|
||||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
import org.koitharu.kotatsu.library.ui.LibraryFragment
|
import org.koitharu.kotatsu.shelf.ui.ShelfFragment
|
||||||
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
||||||
import org.koitharu.kotatsu.main.ui.owners.BottomNavOwner
|
import org.koitharu.kotatsu.main.ui.owners.BottomNavOwner
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
@@ -48,6 +52,7 @@ import org.koitharu.kotatsu.suggestions.ui.SuggestionsWorker
|
|||||||
import org.koitharu.kotatsu.tracker.work.TrackWorker
|
import org.koitharu.kotatsu.tracker.work.TrackWorker
|
||||||
import org.koitharu.kotatsu.utils.VoiceInputContract
|
import org.koitharu.kotatsu.utils.VoiceInputContract
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.*
|
||||||
|
import kotlin.text.Typography.dagger
|
||||||
|
|
||||||
private const val TAG_SEARCH = "search"
|
private const val TAG_SEARCH = "search"
|
||||||
|
|
||||||
@@ -123,16 +128,18 @@ class MainActivity :
|
|||||||
binding.searchView.clearFocus()
|
binding.searchView.clearFocus()
|
||||||
when {
|
when {
|
||||||
fragment != null -> supportFragmentManager.commit {
|
fragment != null -> supportFragmentManager.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
remove(fragment)
|
remove(fragment)
|
||||||
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||||
runOnCommit { onSearchClosed() }
|
runOnCommit { onSearchClosed() }
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> super.onBackPressed()
|
else -> super.onBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFragmentChanged(fragment: Fragment, fromUser: Boolean) {
|
override fun onFragmentChanged(fragment: Fragment, fromUser: Boolean) {
|
||||||
if (fragment is LibraryFragment) {
|
if (fragment is ShelfFragment) {
|
||||||
binding.fab?.show()
|
binding.fab?.show()
|
||||||
} else {
|
} else {
|
||||||
binding.fab?.hide()
|
binding.fab?.hide()
|
||||||
@@ -169,6 +176,7 @@ class MainActivity :
|
|||||||
if (v?.id == R.id.searchView && hasFocus) {
|
if (v?.id == R.id.searchView && hasFocus) {
|
||||||
if (fragment == null) {
|
if (fragment == null) {
|
||||||
supportFragmentManager.commit {
|
supportFragmentManager.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
add(R.id.container, SearchSuggestionFragment.newInstance(), TAG_SEARCH)
|
add(R.id.container, SearchSuggestionFragment.newInstance(), TAG_SEARCH)
|
||||||
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||||
runOnCommit { onSearchOpened() }
|
runOnCommit { onSearchOpened() }
|
||||||
@@ -286,17 +294,16 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onFirstStart() {
|
private fun onFirstStart() {
|
||||||
lifecycleScope.launchWhenResumed {
|
lifecycleScope.launch(Dispatchers.Main) { // not a default `Main.immediate` dispatcher
|
||||||
withContext(Dispatchers.Default) {
|
|
||||||
TrackWorker.setup(applicationContext)
|
|
||||||
SuggestionsWorker.setup(applicationContext)
|
|
||||||
}
|
|
||||||
when {
|
when {
|
||||||
!settings.isSourcesSelected -> OnboardDialogFragment.showWelcome(supportFragmentManager)
|
!settings.isSourcesSelected -> OnboardDialogFragment.showWelcome(supportFragmentManager)
|
||||||
settings.newSources.isNotEmpty() -> NewSourcesDialogFragment.show(supportFragmentManager)
|
settings.newSources.isNotEmpty() -> NewSourcesDialogFragment.show(supportFragmentManager)
|
||||||
}
|
}
|
||||||
yield()
|
withContext(Dispatchers.Default) {
|
||||||
// TODO get<SyncController>().requestFullSyncAndGc(get())
|
TrackWorker.setup(applicationContext)
|
||||||
|
SuggestionsWorker.setup(applicationContext)
|
||||||
|
}
|
||||||
|
requestNotificationsPermission()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +317,7 @@ class MainActivity :
|
|||||||
isResumeEnabled &&
|
isResumeEnabled &&
|
||||||
!actionModeDelegate.isActionModeStarted &&
|
!actionModeDelegate.isActionModeStarted &&
|
||||||
!isSearchOpened &&
|
!isSearchOpened &&
|
||||||
topFragment is LibraryFragment
|
topFragment is ShelfFragment
|
||||||
) {
|
) {
|
||||||
if (fab?.isVisible == false) {
|
if (fab?.isVisible == false) {
|
||||||
fab.show()
|
fab.show()
|
||||||
@@ -347,6 +354,15 @@ class MainActivity :
|
|||||||
showNav(!isOpened)
|
showNav(!isOpened)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun requestNotificationsPermission() {
|
||||||
|
if (
|
||||||
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
|
||||||
|
ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.POST_NOTIFICATIONS), 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private inner class VoiceInputCallback : ActivityResultCallback<String?> {
|
private inner class VoiceInputCallback : ActivityResultCallback<String?> {
|
||||||
|
|
||||||
override fun onActivityResult(result: String?) {
|
override fun onActivityResult(result: String?) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import com.google.android.material.navigation.NavigationBarView
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
||||||
import org.koitharu.kotatsu.explore.ui.ExploreFragment
|
import org.koitharu.kotatsu.explore.ui.ExploreFragment
|
||||||
import org.koitharu.kotatsu.library.ui.LibraryFragment
|
import org.koitharu.kotatsu.shelf.ui.ShelfFragment
|
||||||
import org.koitharu.kotatsu.settings.tools.ToolsFragment
|
import org.koitharu.kotatsu.settings.tools.ToolsFragment
|
||||||
import org.koitharu.kotatsu.tracker.ui.FeedFragment
|
import org.koitharu.kotatsu.tracker.ui.FeedFragment
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -73,7 +73,7 @@ class MainNavigationDelegate(
|
|||||||
private fun onNavigationItemSelected(@IdRes itemId: Int): Boolean {
|
private fun onNavigationItemSelected(@IdRes itemId: Int): Boolean {
|
||||||
setPrimaryFragment(
|
setPrimaryFragment(
|
||||||
when (itemId) {
|
when (itemId) {
|
||||||
R.id.nav_library -> LibraryFragment.newInstance()
|
R.id.nav_shelf -> ShelfFragment.newInstance()
|
||||||
R.id.nav_explore -> ExploreFragment.newInstance()
|
R.id.nav_explore -> ExploreFragment.newInstance()
|
||||||
R.id.nav_feed -> FeedFragment.newInstance()
|
R.id.nav_feed -> FeedFragment.newInstance()
|
||||||
R.id.nav_tools -> ToolsFragment.newInstance()
|
R.id.nav_tools -> ToolsFragment.newInstance()
|
||||||
@@ -85,6 +85,7 @@ class MainNavigationDelegate(
|
|||||||
|
|
||||||
private fun setPrimaryFragment(fragment: Fragment) {
|
private fun setPrimaryFragment(fragment: Fragment) {
|
||||||
fragmentManager.beginTransaction()
|
fragmentManager.beginTransaction()
|
||||||
|
.setReorderingAllowed(true)
|
||||||
.replace(R.id.container, fragment, TAG_PRIMARY)
|
.replace(R.id.container, fragment, TAG_PRIMARY)
|
||||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||||
.commit()
|
.commit()
|
||||||
|
|||||||
@@ -4,33 +4,36 @@ import android.util.SparseIntArray
|
|||||||
import androidx.core.util.set
|
import androidx.core.util.set
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException
|
import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException
|
||||||
import org.koitharu.kotatsu.core.github.AppUpdateRepository
|
import org.koitharu.kotatsu.core.github.AppUpdateRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.sync.domain.SyncController
|
||||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class MainViewModel @Inject constructor(
|
class MainViewModel @Inject constructor(
|
||||||
private val historyRepository: HistoryRepository,
|
private val historyRepository: HistoryRepository,
|
||||||
private val settings: AppSettings,
|
|
||||||
private val appUpdateRepository: AppUpdateRepository,
|
private val appUpdateRepository: AppUpdateRepository,
|
||||||
private val trackingRepository: TrackingRepository,
|
private val trackingRepository: TrackingRepository,
|
||||||
|
syncController: SyncController,
|
||||||
|
database: MangaDatabase,
|
||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
|
|
||||||
val onOpenReader = SingleLiveEvent<Manga>()
|
val onOpenReader = SingleLiveEvent<Manga>()
|
||||||
|
|
||||||
val isResumeEnabled = historyRepository
|
val isResumeEnabled = historyRepository
|
||||||
.observeHasItems()
|
.observeHasItems()
|
||||||
.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, false)
|
.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, false)
|
||||||
|
|
||||||
val counters = combine(
|
val counters = combine(
|
||||||
appUpdateRepository.observeAvailableUpdate(),
|
appUpdateRepository.observeAvailableUpdate(),
|
||||||
@@ -43,9 +46,12 @@ class MainViewModel @Inject constructor(
|
|||||||
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, SparseIntArray(0))
|
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, SparseIntArray(0))
|
||||||
|
|
||||||
init {
|
init {
|
||||||
launchJob(Dispatchers.Default) {
|
launchJob {
|
||||||
appUpdateRepository.fetchUpdate()
|
appUpdateRepository.fetchUpdate()
|
||||||
}
|
}
|
||||||
|
launchJob {
|
||||||
|
syncController.requestFullSyncAndGc(database)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openLastReader() {
|
fun openLastReader() {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.content.Intent
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
import org.acra.dialog.CrashReportDialog
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -14,7 +15,7 @@ class AppProtectHelper @Inject constructor(private val settings: AppSettings) :
|
|||||||
private var isUnlocked = settings.appPassword.isNullOrEmpty()
|
private var isUnlocked = settings.appPassword.isNullOrEmpty()
|
||||||
|
|
||||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
||||||
if (activity !is ProtectActivity && !isUnlocked) {
|
if (!isUnlocked && activity !is ProtectActivity && activity !is CrashReportDialog) {
|
||||||
val sourceIntent = Intent(activity, activity.javaClass)
|
val sourceIntent = Intent(activity, activity.javaClass)
|
||||||
activity.intent?.let {
|
activity.intent?.let {
|
||||||
sourceIntent.putExtras(it)
|
sourceIntent.putExtras(it)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.base.ui.BaseActivity
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.databinding.ActivityProtectBinding
|
import org.koitharu.kotatsu.databinding.ActivityProtectBinding
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ProtectActivity :
|
class ProtectActivity :
|
||||||
@@ -44,11 +45,14 @@ class ProtectActivity :
|
|||||||
viewModel.onError.observe(this, this::onError)
|
viewModel.onError.observe(this, this::onError)
|
||||||
viewModel.isLoading.observe(this, this::onLoadingStateChanged)
|
viewModel.isLoading.observe(this, this::onLoadingStateChanged)
|
||||||
viewModel.onUnlockSuccess.observe(this) {
|
viewModel.onUnlockSuccess.observe(this) {
|
||||||
val intent = intent.getParcelableExtra<Intent>(EXTRA_INTENT)
|
val intent = intent.getParcelableExtraCompat<Intent>(EXTRA_INTENT)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
finishAfterTransition()
|
finishAfterTransition()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
if (!useFingerprint()) {
|
if (!useFingerprint()) {
|
||||||
binding.editPassword.requestFocus()
|
binding.editPassword.requestFocus()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package org.koitharu.kotatsu.reader.domain
|
||||||
|
|
||||||
|
import android.graphics.ColorMatrix
|
||||||
|
import android.graphics.ColorMatrixColorFilter
|
||||||
|
|
||||||
|
class ReaderColorFilter(
|
||||||
|
val brightness: Float,
|
||||||
|
val contrast: Float,
|
||||||
|
) {
|
||||||
|
|
||||||
|
val isEmpty: Boolean
|
||||||
|
get() = brightness == 0f && contrast == 0f
|
||||||
|
|
||||||
|
fun toColorFilter(): ColorMatrixColorFilter {
|
||||||
|
val cm = ColorMatrix()
|
||||||
|
val scale = brightness + 1f
|
||||||
|
cm.setScale(scale, scale, scale, 1f)
|
||||||
|
cm.setContrast(contrast)
|
||||||
|
return ColorMatrixColorFilter(cm)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as ReaderColorFilter
|
||||||
|
|
||||||
|
if (brightness != other.brightness) return false
|
||||||
|
if (contrast != other.contrast) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = brightness.hashCode()
|
||||||
|
result = 31 * result + contrast.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ColorMatrix.setContrast(contrast: Float) {
|
||||||
|
val scale = contrast + 1f
|
||||||
|
val translate = (-.5f * scale + .5f) * 255f
|
||||||
|
val array = floatArrayOf(
|
||||||
|
scale, 0f, 0f, 0f, translate,
|
||||||
|
0f, scale, 0f, 0f, translate,
|
||||||
|
0f, 0f, scale, 0f, translate,
|
||||||
|
0f, 0f, 0f, 1f, 0f,
|
||||||
|
)
|
||||||
|
val matrix = ColorMatrix(array)
|
||||||
|
postConcat(matrix)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.math.roundToInt
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
@@ -17,9 +19,8 @@ import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
|||||||
import org.koitharu.kotatsu.details.ui.model.toListItem
|
import org.koitharu.kotatsu.details.ui.model.toListItem
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.utils.RecyclerViewScrollCallback
|
import org.koitharu.kotatsu.utils.RecyclerViewScrollCallback
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableCompat
|
||||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ChaptersBottomSheet : BaseBottomSheet<SheetChaptersBinding>(), OnListItemClickListener<ChapterListItem> {
|
class ChaptersBottomSheet : BaseBottomSheet<SheetChaptersBinding>(), OnListItemClickListener<ChapterListItem> {
|
||||||
@@ -33,7 +34,7 @@ class ChaptersBottomSheet : BaseBottomSheet<SheetChaptersBinding>(), OnListItemC
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val chapters = arguments?.getParcelable<ParcelableMangaChapters>(ARG_CHAPTERS)?.chapters
|
val chapters = arguments?.getParcelableCompat<ParcelableMangaChapters>(ARG_CHAPTERS)?.chapters
|
||||||
if (chapters.isNullOrEmpty()) {
|
if (chapters.isNullOrEmpty()) {
|
||||||
dismissAllowingStateLoss()
|
dismissAllowingStateLoss()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -9,15 +9,23 @@ import android.transition.Fade
|
|||||||
import android.transition.Slide
|
import android.transition.Slide
|
||||||
import android.transition.TransitionManager
|
import android.transition.TransitionManager
|
||||||
import android.transition.TransitionSet
|
import android.transition.TransitionSet
|
||||||
import android.view.*
|
import android.view.Gravity
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.*
|
import androidx.core.view.OnApplyWindowInsetsListener
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.core.view.isGone
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -40,8 +48,18 @@ import org.koitharu.kotatsu.reader.ui.thumbnails.OnPageSelectListener
|
|||||||
import org.koitharu.kotatsu.reader.ui.thumbnails.PagesThumbnailsSheet
|
import org.koitharu.kotatsu.reader.ui.thumbnails.PagesThumbnailsSheet
|
||||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||||
import org.koitharu.kotatsu.utils.GridTouchHelper
|
import org.koitharu.kotatsu.utils.GridTouchHelper
|
||||||
|
import org.koitharu.kotatsu.utils.IdlingDetector
|
||||||
import org.koitharu.kotatsu.utils.ShareHelper
|
import org.koitharu.kotatsu.utils.ShareHelper
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.assistedViewModels
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.hasGlobalPoint
|
||||||
|
import org.koitharu.kotatsu.utils.ext.isReportable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.observeWithPrevious
|
||||||
|
import org.koitharu.kotatsu.utils.ext.postDelayed
|
||||||
|
import org.koitharu.kotatsu.utils.ext.report
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ReaderActivity :
|
class ReaderActivity :
|
||||||
@@ -51,15 +69,18 @@ class ReaderActivity :
|
|||||||
OnPageSelectListener,
|
OnPageSelectListener,
|
||||||
ReaderConfigBottomSheet.Callback,
|
ReaderConfigBottomSheet.Callback,
|
||||||
ReaderControlDelegate.OnInteractionListener,
|
ReaderControlDelegate.OnInteractionListener,
|
||||||
OnApplyWindowInsetsListener {
|
OnApplyWindowInsetsListener,
|
||||||
|
IdlingDetector.Callback {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var viewModelFactory: ReaderViewModel.Factory
|
lateinit var viewModelFactory: ReaderViewModel.Factory
|
||||||
|
|
||||||
|
private val idlingDetector = IdlingDetector(TimeUnit.SECONDS.toMillis(10), this)
|
||||||
|
|
||||||
val viewModel by assistedViewModels {
|
val viewModel by assistedViewModels {
|
||||||
viewModelFactory.create(
|
viewModelFactory.create(
|
||||||
intent = MangaIntent(intent),
|
intent = MangaIntent(intent),
|
||||||
initialState = intent?.getParcelableExtra(EXTRA_STATE),
|
initialState = intent?.getParcelableExtraCompat(EXTRA_STATE),
|
||||||
preselectedBranch = intent?.getStringExtra(EXTRA_BRANCH),
|
preselectedBranch = intent?.getStringExtra(EXTRA_BRANCH),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -70,6 +91,9 @@ class ReaderActivity :
|
|||||||
pageSwitchTimer.delaySec = value
|
pageSwitchTimer.delaySec = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val readerMode: ReaderMode?
|
||||||
|
get() = readerManager.currentMode
|
||||||
|
|
||||||
private lateinit var pageSwitchTimer: PageSwitchTimer
|
private lateinit var pageSwitchTimer: PageSwitchTimer
|
||||||
private lateinit var touchHelper: GridTouchHelper
|
private lateinit var touchHelper: GridTouchHelper
|
||||||
private lateinit var controlDelegate: ReaderControlDelegate
|
private lateinit var controlDelegate: ReaderControlDelegate
|
||||||
@@ -84,11 +108,12 @@ class ReaderActivity :
|
|||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
touchHelper = GridTouchHelper(this, this)
|
touchHelper = GridTouchHelper(this, this)
|
||||||
pageSwitchTimer = PageSwitchTimer(this, this)
|
pageSwitchTimer = PageSwitchTimer(this, this)
|
||||||
controlDelegate = ReaderControlDelegate(lifecycleScope, settings, this)
|
controlDelegate = ReaderControlDelegate(settings, this, this)
|
||||||
binding.toolbarBottom.setOnMenuItemClickListener(::onOptionsItemSelected)
|
binding.toolbarBottom.setOnMenuItemClickListener(::onOptionsItemSelected)
|
||||||
binding.slider.setLabelFormatter(PageLabelFormatter())
|
binding.slider.setLabelFormatter(PageLabelFormatter())
|
||||||
ReaderSliderListener(this, viewModel).attachToSlider(binding.slider)
|
ReaderSliderListener(this, viewModel).attachToSlider(binding.slider)
|
||||||
insetsDelegate.interceptingWindowInsetsListener = this
|
insetsDelegate.interceptingWindowInsetsListener = this
|
||||||
|
idlingDetector.bindToLifecycle(this)
|
||||||
|
|
||||||
viewModel.onError.observe(this, this::onError)
|
viewModel.onError.observe(this, this::onError)
|
||||||
viewModel.readerMode.observe(this, this::onInitReader)
|
viewModel.readerMode.observe(this, this::onInitReader)
|
||||||
@@ -111,6 +136,11 @@ class ReaderActivity :
|
|||||||
override fun onUserInteraction() {
|
override fun onUserInteraction() {
|
||||||
super.onUserInteraction()
|
super.onUserInteraction()
|
||||||
pageSwitchTimer.onUserInteraction()
|
pageSwitchTimer.onUserInteraction()
|
||||||
|
idlingDetector.onUserInteraction()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onIdle() {
|
||||||
|
viewModel.saveCurrentState(readerManager.currentReader?.getCurrentState())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onInitReader(mode: ReaderMode) {
|
private fun onInitReader(mode: ReaderMode) {
|
||||||
@@ -132,6 +162,7 @@ class ReaderActivity :
|
|||||||
R.id.action_settings -> {
|
R.id.action_settings -> {
|
||||||
startActivity(SettingsActivity.newReaderSettingsIntent(this))
|
startActivity(SettingsActivity.newReaderSettingsIntent(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_chapters -> {
|
R.id.action_chapters -> {
|
||||||
ChaptersBottomSheet.show(
|
ChaptersBottomSheet.show(
|
||||||
supportFragmentManager,
|
supportFragmentManager,
|
||||||
@@ -139,6 +170,7 @@ class ReaderActivity :
|
|||||||
viewModel.getCurrentState()?.chapterId ?: 0L,
|
viewModel.getCurrentState()?.chapterId ?: 0L,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_pages_thumbs -> {
|
R.id.action_pages_thumbs -> {
|
||||||
val pages = viewModel.getCurrentChapterPages()
|
val pages = viewModel.getCurrentChapterPages()
|
||||||
if (!pages.isNullOrEmpty()) {
|
if (!pages.isNullOrEmpty()) {
|
||||||
@@ -152,6 +184,7 @@ class ReaderActivity :
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_bookmark -> {
|
R.id.action_bookmark -> {
|
||||||
if (viewModel.isBookmarkAdded.value == true) {
|
if (viewModel.isBookmarkAdded.value == true) {
|
||||||
viewModel.removeBookmark()
|
viewModel.removeBookmark()
|
||||||
@@ -159,11 +192,13 @@ class ReaderActivity :
|
|||||||
viewModel.addBookmark()
|
viewModel.addBookmark()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_options -> {
|
R.id.action_options -> {
|
||||||
viewModel.saveCurrentState(readerManager.currentReader?.getCurrentState())
|
viewModel.saveCurrentState(readerManager.currentReader?.getCurrentState())
|
||||||
val currentMode = readerManager.currentMode ?: return false
|
val currentMode = readerManager.currentMode ?: return false
|
||||||
ReaderConfigBottomSheet.show(supportFragmentManager, currentMode)
|
ReaderConfigBottomSheet.show(supportFragmentManager, currentMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -192,7 +227,7 @@ class ReaderActivity :
|
|||||||
val resolveTextId = ExceptionResolver.getResolveStringId(e)
|
val resolveTextId = ExceptionResolver.getResolveStringId(e)
|
||||||
if (resolveTextId != 0) {
|
if (resolveTextId != 0) {
|
||||||
dialog.setPositiveButton(resolveTextId, listener)
|
dialog.setPositiveButton(resolveTextId, listener)
|
||||||
} else {
|
} else if (e.isReportable()) {
|
||||||
dialog.setPositiveButton(R.string.report, listener)
|
dialog.setPositiveButton(R.string.report, listener)
|
||||||
}
|
}
|
||||||
dialog.show()
|
dialog.show()
|
||||||
@@ -351,7 +386,7 @@ class ReaderActivity :
|
|||||||
binding.toastView.showTemporary(uiState.chapterName, TOAST_DURATION)
|
binding.toastView.showTemporary(uiState.chapterName, TOAST_DURATION)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uiState.totalPages > 1 && uiState.currentPage < uiState.totalPages) {
|
if (uiState.isSliderAvailable()) {
|
||||||
binding.slider.valueTo = uiState.totalPages.toFloat() - 1
|
binding.slider.valueTo = uiState.totalPages.toFloat() - 1
|
||||||
binding.slider.value = uiState.currentPage.toFloat()
|
binding.slider.value = uiState.currentPage.toFloat()
|
||||||
binding.slider.isVisible = true
|
binding.slider.isVisible = true
|
||||||
@@ -370,7 +405,7 @@ class ReaderActivity :
|
|||||||
if (ExceptionResolver.canResolve(exception)) {
|
if (ExceptionResolver.canResolve(exception)) {
|
||||||
tryResolve(exception)
|
tryResolve(exception)
|
||||||
} else {
|
} else {
|
||||||
exception.report("ReaderActivity::onError")
|
exception.report()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
onCancel(dialog)
|
onCancel(dialog)
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.reader.ui
|
|
||||||
|
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.fragment.app.FragmentManager
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
|
||||||
import org.koitharu.kotatsu.base.ui.widgets.CheckableButtonGroup
|
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
|
||||||
import org.koitharu.kotatsu.databinding.DialogReaderConfigBinding
|
|
||||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
|
||||||
|
|
||||||
@Deprecated("Not in use")
|
|
||||||
class ReaderConfigDialog : AlertDialogFragment<DialogReaderConfigBinding>(),
|
|
||||||
CheckableButtonGroup.OnCheckedChangeListener {
|
|
||||||
|
|
||||||
private lateinit var mode: ReaderMode
|
|
||||||
|
|
||||||
override fun onInflateView(
|
|
||||||
inflater: LayoutInflater,
|
|
||||||
container: ViewGroup?
|
|
||||||
) = DialogReaderConfigBinding.inflate(inflater, container, false)
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
mode = arguments?.getInt(ARG_MODE)
|
|
||||||
?.let { ReaderMode.valueOf(it) }
|
|
||||||
?: ReaderMode.STANDARD
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBuildDialog(builder: MaterialAlertDialogBuilder) {
|
|
||||||
builder.setTitle(R.string.read_mode)
|
|
||||||
.setPositiveButton(R.string.done, null)
|
|
||||||
.setCancelable(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
binding.buttonStandard.isChecked = mode == ReaderMode.STANDARD
|
|
||||||
binding.buttonReversed.isChecked = mode == ReaderMode.REVERSED
|
|
||||||
binding.buttonWebtoon.isChecked = mode == ReaderMode.WEBTOON
|
|
||||||
|
|
||||||
binding.checkableGroup.onCheckedChangeListener = this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDismiss(dialog: DialogInterface) {
|
|
||||||
((parentFragment as? Callback)
|
|
||||||
?: (activity as? Callback))?.onReaderModeChanged(mode)
|
|
||||||
super.onDismiss(dialog)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCheckedChanged(group: CheckableButtonGroup, checkedId: Int) {
|
|
||||||
mode = when (checkedId) {
|
|
||||||
R.id.button_standard -> ReaderMode.STANDARD
|
|
||||||
R.id.button_webtoon -> ReaderMode.WEBTOON
|
|
||||||
R.id.button_reversed -> ReaderMode.REVERSED
|
|
||||||
else -> return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Callback {
|
|
||||||
|
|
||||||
fun onReaderModeChanged(mode: ReaderMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
private const val TAG = "ReaderConfigDialog"
|
|
||||||
private const val ARG_MODE = "mode"
|
|
||||||
|
|
||||||
fun show(fm: FragmentManager, mode: ReaderMode) = ReaderConfigDialog().withArgs(1) {
|
|
||||||
putInt(ARG_MODE, mode.id)
|
|
||||||
}.show(fm, TAG)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +1,39 @@
|
|||||||
package org.koitharu.kotatsu.reader.ui
|
package org.koitharu.kotatsu.reader.ui
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.SoundEffectConstants
|
import android.view.SoundEffectConstants
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.lifecycle.LifecycleCoroutineScope
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
import kotlinx.coroutines.Dispatchers
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
|
||||||
import kotlinx.coroutines.flow.onEach
|
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||||
import org.koitharu.kotatsu.utils.GridTouchHelper
|
import org.koitharu.kotatsu.utils.GridTouchHelper
|
||||||
|
|
||||||
class ReaderControlDelegate(
|
class ReaderControlDelegate(
|
||||||
scope: LifecycleCoroutineScope,
|
private val settings: AppSettings,
|
||||||
settings: AppSettings,
|
|
||||||
private val listener: OnInteractionListener,
|
private val listener: OnInteractionListener,
|
||||||
) {
|
owner: LifecycleOwner,
|
||||||
|
) : DefaultLifecycleObserver, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
private var isTapSwitchEnabled: Boolean = true
|
private var isTapSwitchEnabled: Boolean = true
|
||||||
private var isVolumeKeysSwitchEnabled: Boolean = false
|
private var isVolumeKeysSwitchEnabled: Boolean = false
|
||||||
|
private var isReaderTapsAdaptive: Boolean = true
|
||||||
|
|
||||||
init {
|
init {
|
||||||
settings.observeAsFlow(AppSettings.KEY_READER_SWITCHERS) { readerPageSwitch }
|
owner.lifecycle.addObserver(this)
|
||||||
.flowOn(Dispatchers.Default)
|
settings.subscribe(this)
|
||||||
.onEach {
|
updateSettings()
|
||||||
isTapSwitchEnabled = AppSettings.PAGE_SWITCH_TAPS in it
|
}
|
||||||
isVolumeKeysSwitchEnabled = AppSettings.PAGE_SWITCH_VOLUME_KEYS in it
|
|
||||||
}.launchIn(scope)
|
override fun onDestroy(owner: LifecycleOwner) {
|
||||||
|
settings.unsubscribe(this)
|
||||||
|
owner.lifecycle.removeObserver(this)
|
||||||
|
super.onDestroy(owner)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||||
|
updateSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onGridTouch(area: Int, view: View) {
|
fun onGridTouch(area: Int, view: View) {
|
||||||
@@ -41,7 +47,7 @@ class ReaderControlDelegate(
|
|||||||
view.playSoundEffect(SoundEffectConstants.NAVIGATION_UP)
|
view.playSoundEffect(SoundEffectConstants.NAVIGATION_UP)
|
||||||
}
|
}
|
||||||
GridTouchHelper.AREA_LEFT -> if (isTapSwitchEnabled) {
|
GridTouchHelper.AREA_LEFT -> if (isTapSwitchEnabled) {
|
||||||
listener.switchPageBy(-1)
|
listener.switchPageBy(if (isReaderTapsReversed()) 1 else -1)
|
||||||
view.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT)
|
view.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT)
|
||||||
}
|
}
|
||||||
GridTouchHelper.AREA_BOTTOM -> if (isTapSwitchEnabled) {
|
GridTouchHelper.AREA_BOTTOM -> if (isTapSwitchEnabled) {
|
||||||
@@ -49,7 +55,7 @@ class ReaderControlDelegate(
|
|||||||
view.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN)
|
view.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN)
|
||||||
}
|
}
|
||||||
GridTouchHelper.AREA_RIGHT -> if (isTapSwitchEnabled) {
|
GridTouchHelper.AREA_RIGHT -> if (isTapSwitchEnabled) {
|
||||||
listener.switchPageBy(1)
|
listener.switchPageBy(if (isReaderTapsReversed()) -1 else 1)
|
||||||
view.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT)
|
view.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,19 +78,25 @@ class ReaderControlDelegate(
|
|||||||
KeyEvent.KEYCODE_PAGE_DOWN,
|
KeyEvent.KEYCODE_PAGE_DOWN,
|
||||||
KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN,
|
KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN,
|
||||||
KeyEvent.KEYCODE_DPAD_DOWN,
|
KeyEvent.KEYCODE_DPAD_DOWN,
|
||||||
KeyEvent.KEYCODE_DPAD_RIGHT,
|
|
||||||
-> {
|
-> {
|
||||||
listener.switchPageBy(1)
|
listener.switchPageBy(1)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
KeyEvent.KEYCODE_DPAD_RIGHT -> {
|
||||||
|
listener.switchPageBy(if (isReaderTapsReversed()) -1 else 1)
|
||||||
|
true
|
||||||
|
}
|
||||||
KeyEvent.KEYCODE_PAGE_UP,
|
KeyEvent.KEYCODE_PAGE_UP,
|
||||||
KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP,
|
KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP,
|
||||||
KeyEvent.KEYCODE_DPAD_UP,
|
KeyEvent.KEYCODE_DPAD_UP,
|
||||||
KeyEvent.KEYCODE_DPAD_LEFT,
|
|
||||||
-> {
|
-> {
|
||||||
listener.switchPageBy(-1)
|
listener.switchPageBy(-1)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
KeyEvent.KEYCODE_DPAD_LEFT -> {
|
||||||
|
listener.switchPageBy(if (isReaderTapsReversed()) 1 else -1)
|
||||||
|
true
|
||||||
|
}
|
||||||
KeyEvent.KEYCODE_DPAD_CENTER -> {
|
KeyEvent.KEYCODE_DPAD_CENTER -> {
|
||||||
listener.toggleUiVisibility()
|
listener.toggleUiVisibility()
|
||||||
true
|
true
|
||||||
@@ -99,8 +111,21 @@ class ReaderControlDelegate(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateSettings() {
|
||||||
|
val switch = settings.readerPageSwitch
|
||||||
|
isTapSwitchEnabled = AppSettings.PAGE_SWITCH_TAPS in switch
|
||||||
|
isVolumeKeysSwitchEnabled = AppSettings.PAGE_SWITCH_VOLUME_KEYS in switch
|
||||||
|
isReaderTapsAdaptive = settings.isReaderTapsAdaptive
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isReaderTapsReversed(): Boolean {
|
||||||
|
return isReaderTapsAdaptive && listener.readerMode == ReaderMode.REVERSED
|
||||||
|
}
|
||||||
|
|
||||||
interface OnInteractionListener {
|
interface OnInteractionListener {
|
||||||
|
|
||||||
|
val readerMode: ReaderMode?
|
||||||
|
|
||||||
fun switchPageBy(delta: Int)
|
fun switchPageBy(delta: Int)
|
||||||
|
|
||||||
fun toggleUiVisibility()
|
fun toggleUiVisibility()
|
||||||
|
|||||||
@@ -8,17 +8,22 @@ import android.graphics.Canvas
|
|||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.icu.text.SimpleDateFormat
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.WindowInsets
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.parsers.util.format
|
import org.koitharu.kotatsu.parsers.util.format
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderUiState
|
import org.koitharu.kotatsu.reader.ui.pager.ReaderUiState
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureDimension
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.resolveDp
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
|
||||||
class ReaderInfoBarView @JvmOverloads constructor(
|
class ReaderInfoBarView @JvmOverloads constructor(
|
||||||
@@ -29,23 +34,49 @@ class ReaderInfoBarView @JvmOverloads constructor(
|
|||||||
|
|
||||||
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
private val textBounds = Rect()
|
private val textBounds = Rect()
|
||||||
private val inset = context.resources.resolveDp(2f)
|
|
||||||
private val timeFormat = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT)
|
private val timeFormat = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT)
|
||||||
private val timeReceiver = TimeReceiver()
|
private val timeReceiver = TimeReceiver()
|
||||||
|
private var insetLeft: Int = 0
|
||||||
|
private var insetRight: Int = 0
|
||||||
|
private var insetTop: Int = 0
|
||||||
|
private var cutoutInsetLeft = 0
|
||||||
|
private var cutoutInsetRight = 0
|
||||||
|
private val colorText = ColorUtils.setAlphaComponent(
|
||||||
|
context.getThemeColor(materialR.attr.colorOnSurface, Color.BLACK),
|
||||||
|
200,
|
||||||
|
)
|
||||||
|
private val colorOutline = ColorUtils.setAlphaComponent(
|
||||||
|
context.getThemeColor(materialR.attr.colorSurface, Color.WHITE),
|
||||||
|
200,
|
||||||
|
)
|
||||||
|
|
||||||
private var timeText = timeFormat.format(Date())
|
private var timeText = timeFormat.format(Date())
|
||||||
private var text: String = ""
|
private var text: String = ""
|
||||||
|
|
||||||
private val innerHeight
|
private val innerHeight
|
||||||
get() = height - inset - inset - paddingTop - paddingBottom
|
get() = height - paddingTop - paddingBottom - insetTop
|
||||||
|
|
||||||
private val innerWidth
|
private val innerWidth
|
||||||
get() = width - inset - inset - paddingLeft - paddingRight
|
get() = width - paddingLeft - paddingRight - insetLeft - insetRight
|
||||||
|
|
||||||
init {
|
init {
|
||||||
paint.color = ColorUtils.setAlphaComponent(
|
paint.strokeWidth = context.resources.resolveDp(2f)
|
||||||
context.getThemeColor(materialR.attr.colorOnSurface, Color.BLACK),
|
val insetCorner = getSystemUiDimensionOffset("rounded_corner_content_padding")
|
||||||
160,
|
val fallbackInset = resources.getDimensionPixelOffset(R.dimen.reader_bar_inset_fallback)
|
||||||
|
val insetStart = getSystemUiDimensionOffset("status_bar_padding_start", fallbackInset) + insetCorner
|
||||||
|
val insetEnd = getSystemUiDimensionOffset("status_bar_padding_end", fallbackInset) + insetCorner
|
||||||
|
val isRtl = layoutDirection == LAYOUT_DIRECTION_RTL
|
||||||
|
insetLeft = if (isRtl) insetEnd else insetStart
|
||||||
|
insetRight = if (isRtl) insetStart else insetEnd
|
||||||
|
insetTop = minOf(insetLeft, insetRight)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
|
val desiredWidth = suggestedMinimumWidth + paddingLeft + paddingRight + insetLeft + insetRight
|
||||||
|
val desiredHeight = suggestedMinimumHeight + paddingTop + paddingBottom + insetTop
|
||||||
|
setMeasuredDimension(
|
||||||
|
measureDimension(desiredWidth, widthMeasureSpec),
|
||||||
|
measureDimension(desiredHeight, heightMeasureSpec),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,19 +84,34 @@ class ReaderInfoBarView @JvmOverloads constructor(
|
|||||||
super.onDraw(canvas)
|
super.onDraw(canvas)
|
||||||
val ty = innerHeight / 2f + textBounds.height() / 2f - textBounds.bottom
|
val ty = innerHeight / 2f + textBounds.height() / 2f - textBounds.bottom
|
||||||
paint.textAlign = Paint.Align.LEFT
|
paint.textAlign = Paint.Align.LEFT
|
||||||
canvas.drawText(text, paddingLeft + inset, paddingTop + inset + ty, paint)
|
canvas.drawTextOutline(
|
||||||
|
text,
|
||||||
|
(paddingLeft + insetLeft + cutoutInsetLeft).toFloat(),
|
||||||
|
paddingTop + insetTop + ty,
|
||||||
|
)
|
||||||
paint.textAlign = Paint.Align.RIGHT
|
paint.textAlign = Paint.Align.RIGHT
|
||||||
canvas.drawText(timeText, width - paddingRight - inset, paddingTop + inset + ty, paint)
|
canvas.drawTextOutline(
|
||||||
|
timeText,
|
||||||
|
(width - paddingRight - insetRight - cutoutInsetRight).toFloat(),
|
||||||
|
paddingTop + insetTop + ty,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||||
super.onSizeChanged(w, h, oldw, oldh)
|
super.onSizeChanged(w, h, oldw, oldh)
|
||||||
|
updateCutoutInsets(ViewCompat.getRootWindowInsets(this))
|
||||||
updateTextSize()
|
updateTextSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||||
|
updateCutoutInsets(WindowInsetsCompat.toWindowInsetsCompat(insets))
|
||||||
|
return super.onApplyWindowInsets(insets)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
super.onAttachedToWindow()
|
super.onAttachedToWindow()
|
||||||
context.registerReceiver(timeReceiver, IntentFilter(Intent.ACTION_TIME_TICK))
|
context.registerReceiver(timeReceiver, IntentFilter(Intent.ACTION_TIME_TICK))
|
||||||
|
updateCutoutInsets(ViewCompat.getRootWindowInsets(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDetachedFromWindow() {
|
override fun onDetachedFromWindow() {
|
||||||
@@ -103,6 +149,29 @@ class ReaderInfoBarView @JvmOverloads constructor(
|
|||||||
paint.getTextBounds(str, 0, str.length, textBounds)
|
paint.getTextBounds(str, 0, str.length, textBounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Canvas.drawTextOutline(text: String, x: Float, y: Float) {
|
||||||
|
paint.color = colorOutline
|
||||||
|
paint.style = Paint.Style.STROKE
|
||||||
|
drawText(text, x, y, paint)
|
||||||
|
paint.color = colorText
|
||||||
|
paint.style = Paint.Style.FILL
|
||||||
|
drawText(text, x, y, paint)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateCutoutInsets(insetsCompat: WindowInsetsCompat?) {
|
||||||
|
val cutouts = (insetsCompat ?: return).displayCutout?.boundingRects.orEmpty()
|
||||||
|
cutoutInsetLeft = 0
|
||||||
|
cutoutInsetRight = 0
|
||||||
|
for (rect in cutouts) {
|
||||||
|
if (rect.left <= paddingLeft) {
|
||||||
|
cutoutInsetLeft += rect.width()
|
||||||
|
}
|
||||||
|
if (rect.right >= width - paddingRight) {
|
||||||
|
cutoutInsetRight += rect.width()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private inner class TimeReceiver : BroadcastReceiver() {
|
private inner class TimeReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
@@ -110,4 +179,13 @@ class ReaderInfoBarView @JvmOverloads constructor(
|
|||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getSystemUiDimensionOffset(name: String, fallback: Int = 0): Int = runCatching {
|
||||||
|
val manager = context.packageManager
|
||||||
|
val resources = manager.getResourcesForApplication("com.android.systemui")
|
||||||
|
val resId = resources.getIdentifier(name, "dimen", "com.android.systemui")
|
||||||
|
resources.getDimensionPixelOffset(resId)
|
||||||
|
}.onFailure {
|
||||||
|
it.printStackTraceDebug()
|
||||||
|
}.getOrDefault(fallback)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.koitharu.kotatsu.reader.ui.pager.BaseReader
|
|||||||
import org.koitharu.kotatsu.reader.ui.pager.reversed.ReversedReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.reversed.ReversedReaderFragment
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.webtoon.WebtoonReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.webtoon.WebtoonReaderFragment
|
||||||
import java.util.*
|
import java.util.EnumMap
|
||||||
|
|
||||||
class ReaderManager(
|
class ReaderManager(
|
||||||
private val fragmentManager: FragmentManager,
|
private val fragmentManager: FragmentManager,
|
||||||
@@ -35,11 +35,15 @@ class ReaderManager(
|
|||||||
fun replace(newMode: ReaderMode) {
|
fun replace(newMode: ReaderMode) {
|
||||||
val readerClass = requireNotNull(modeMap[newMode])
|
val readerClass = requireNotNull(modeMap[newMode])
|
||||||
fragmentManager.commit {
|
fragmentManager.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
replace(containerResId, readerClass, null, null)
|
replace(containerResId, readerClass, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun replace(reader: BaseReader<*>) {
|
fun replace(reader: BaseReader<*>) {
|
||||||
fragmentManager.commit { replace(containerResId, reader) }
|
fragmentManager.commit {
|
||||||
|
setReorderingAllowed(true)
|
||||||
|
replace(containerResId, reader)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,22 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import java.util.*
|
import kotlinx.coroutines.CancellationException
|
||||||
import javax.inject.Provider
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.cancelAndJoin
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.base.domain.MangaIntent
|
import org.koitharu.kotatsu.base.domain.MangaIntent
|
||||||
@@ -21,7 +33,11 @@ import org.koitharu.kotatsu.base.ui.BaseViewModel
|
|||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.*
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||||
|
import org.koitharu.kotatsu.core.prefs.ScreenshotsPolicy
|
||||||
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
|
import org.koitharu.kotatsu.core.prefs.observeAsLiveData
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
||||||
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
||||||
@@ -31,12 +47,16 @@ import org.koitharu.kotatsu.parsers.model.MangaPage
|
|||||||
import org.koitharu.kotatsu.reader.data.filterChapters
|
import org.koitharu.kotatsu.reader.data.filterChapters
|
||||||
import org.koitharu.kotatsu.reader.domain.ChaptersLoader
|
import org.koitharu.kotatsu.reader.domain.ChaptersLoader
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderUiState
|
import org.koitharu.kotatsu.reader.ui.pager.ReaderUiState
|
||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
import org.koitharu.kotatsu.utils.asFlowLiveData
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.utils.ext.requireValue
|
import org.koitharu.kotatsu.utils.ext.requireValue
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import java.util.Date
|
||||||
|
import javax.inject.Provider
|
||||||
|
|
||||||
private const val BOUNDS_PAGE_OFFSET = 2
|
private const val BOUNDS_PAGE_OFFSET = 2
|
||||||
private const val PREFETCH_LIMIT = 10
|
private const val PREFETCH_LIMIT = 10
|
||||||
@@ -86,6 +106,14 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
valueProducer = { isReaderBarEnabled },
|
valueProducer = { isReaderBarEnabled },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val readerSettings = ReaderSettings(
|
||||||
|
parentScope = viewModelScope,
|
||||||
|
settings = settings,
|
||||||
|
colorFilterFlow = mangaData.flatMapLatest {
|
||||||
|
if (it == null) flowOf(null) else dataRepository.observeColorFilter(it.id)
|
||||||
|
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, null),
|
||||||
|
)
|
||||||
|
|
||||||
val isScreenshotsBlockEnabled = combine(
|
val isScreenshotsBlockEnabled = combine(
|
||||||
mangaData,
|
mangaData,
|
||||||
settings.observeAsFlow(AppSettings.KEY_SCREENSHOTS_POLICY) { screenshotsPolicy },
|
settings.observeAsFlow(AppSettings.KEY_SCREENSHOTS_POLICY) { screenshotsPolicy },
|
||||||
@@ -94,8 +122,6 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
(policy == ScreenshotsPolicy.BLOCK_NSFW && manga != null && manga.isNsfw)
|
(policy == ScreenshotsPolicy.BLOCK_NSFW && manga != null && manga.isNsfw)
|
||||||
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, false)
|
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, false)
|
||||||
|
|
||||||
val onZoomChanged = SingleLiveEvent<Unit>()
|
|
||||||
|
|
||||||
val isBookmarkAdded: LiveData<Boolean> = currentState.flatMapLatest { state ->
|
val isBookmarkAdded: LiveData<Boolean> = currentState.flatMapLatest { state ->
|
||||||
val manga = mangaData.value
|
val manga = mangaData.value
|
||||||
if (state == null || manga == null) {
|
if (state == null || manga == null) {
|
||||||
@@ -108,7 +134,10 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
loadImpl()
|
loadImpl()
|
||||||
subscribeToSettings()
|
settings.observe()
|
||||||
|
.onEach { key ->
|
||||||
|
if (key == AppSettings.KEY_READER_SLIDER) notifyStateChanged()
|
||||||
|
}.launchIn(viewModelScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
@@ -124,7 +153,7 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
fun switchMode(newMode: ReaderMode) {
|
fun switchMode(newMode: ReaderMode) {
|
||||||
launchJob {
|
launchJob {
|
||||||
val manga = checkNotNull(mangaData.value)
|
val manga = checkNotNull(mangaData.value)
|
||||||
dataRepository.savePreferences(
|
dataRepository.saveReaderMode(
|
||||||
manga = manga,
|
manga = manga,
|
||||||
mode = newMode,
|
mode = newMode,
|
||||||
)
|
)
|
||||||
@@ -300,13 +329,6 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun subscribeToSettings() {
|
|
||||||
settings.observe()
|
|
||||||
.onEach { key ->
|
|
||||||
if (key == AppSettings.KEY_ZOOM_MODE) onZoomChanged.postCall(Unit)
|
|
||||||
}.launchIn(viewModelScope + Dispatchers.Default)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun <T> List<T>.trySublist(fromIndex: Int, toIndex: Int): List<T> {
|
private fun <T> List<T>.trySublist(fromIndex: Int, toIndex: Int): List<T> {
|
||||||
val fromIndexBounded = fromIndex.coerceAtMost(lastIndex)
|
val fromIndexBounded = fromIndex.coerceAtMost(lastIndex)
|
||||||
val toIndexBounded = toIndex.coerceIn(fromIndexBounded, lastIndex)
|
val toIndexBounded = toIndex.coerceIn(fromIndexBounded, lastIndex)
|
||||||
@@ -327,11 +349,11 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
?: manga.chapters?.randomOrNull()
|
?: manga.chapters?.randomOrNull()
|
||||||
?: error("There are no chapters in this manga")
|
?: error("There are no chapters in this manga")
|
||||||
val pages = repo.getPages(chapter)
|
val pages = repo.getPages(chapter)
|
||||||
return runCatching {
|
return runCatchingCancellable {
|
||||||
val isWebtoon = dataRepository.determineMangaIsWebtoon(repo, pages)
|
val isWebtoon = dataRepository.determineMangaIsWebtoon(repo, pages)
|
||||||
if (isWebtoon) ReaderMode.WEBTOON else defaultMode
|
if (isWebtoon) ReaderMode.WEBTOON else defaultMode
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
dataRepository.savePreferences(manga, it)
|
dataRepository.saveReaderMode(manga, it)
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
it.printStackTraceDebug()
|
it.printStackTraceDebug()
|
||||||
}.getOrDefault(defaultMode)
|
}.getOrDefault(defaultMode)
|
||||||
@@ -348,6 +370,7 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
chaptersTotal = chapters.size(),
|
chaptersTotal = chapters.size(),
|
||||||
totalPages = if (chapter != null) chaptersLoader.getPagesCount(chapter.id) else 0,
|
totalPages = if (chapter != null) chaptersLoader.getPagesCount(chapter.id) else 0,
|
||||||
currentPage = state?.page ?: 0,
|
currentPage = state?.page ?: 0,
|
||||||
|
isSliderEnabled = settings.isReaderSliderEnabled,
|
||||||
)
|
)
|
||||||
uiState.postValue(newState)
|
uiState.postValue(newState)
|
||||||
}
|
}
|
||||||
@@ -382,7 +405,7 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
*/
|
*/
|
||||||
private fun HistoryRepository.saveStateAsync(manga: Manga, state: ReaderState, percent: Float): Job {
|
private fun HistoryRepository.saveStateAsync(manga: Manga, state: ReaderState, percent: Float): Job {
|
||||||
return processLifecycleScope.launch(Dispatchers.Default) {
|
return processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
runCatching {
|
runCatchingCancellable {
|
||||||
addOrUpdate(
|
addOrUpdate(
|
||||||
manga = manga,
|
manga = manga,
|
||||||
chapterId = state.chapterId,
|
chapterId = state.chapterId,
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package org.koitharu.kotatsu.reader.ui.colorfilter
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.res.Resources
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.graphics.Insets
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
import coil.ImageLoader
|
||||||
|
import coil.request.ImageRequest
|
||||||
|
import coil.size.Scale
|
||||||
|
import coil.size.ViewSizeResolver
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
import com.google.android.material.slider.LabelFormatter
|
||||||
|
import com.google.android.material.slider.Slider
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import javax.inject.Inject
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaPages
|
||||||
|
import org.koitharu.kotatsu.databinding.ActivityColorFilterBinding
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.util.format
|
||||||
|
import org.koitharu.kotatsu.reader.domain.ReaderColorFilter
|
||||||
|
import org.koitharu.kotatsu.utils.ext.*
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class ColorFilterConfigActivity :
|
||||||
|
BaseActivity<ActivityColorFilterBinding>(),
|
||||||
|
Slider.OnChangeListener,
|
||||||
|
View.OnClickListener {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var coil: ImageLoader
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var viewModelFactory: ColorFilterConfigViewModel.Factory
|
||||||
|
|
||||||
|
private val viewModel: ColorFilterConfigViewModel by assistedViewModels {
|
||||||
|
viewModelFactory.create(
|
||||||
|
manga = checkNotNull(intent.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga),
|
||||||
|
page = checkNotNull(intent.getParcelableExtraCompat<ParcelableMangaPages>(EXTRA_PAGES)?.pages?.firstOrNull()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(ActivityColorFilterBinding.inflate(layoutInflater))
|
||||||
|
supportActionBar?.run {
|
||||||
|
setDisplayHomeAsUpEnabled(true)
|
||||||
|
setHomeAsUpIndicator(materialR.drawable.abc_ic_clear_material)
|
||||||
|
}
|
||||||
|
binding.sliderBrightness.addOnChangeListener(this)
|
||||||
|
binding.sliderContrast.addOnChangeListener(this)
|
||||||
|
val formatter = PercentLabelFormatter(resources)
|
||||||
|
binding.sliderContrast.setLabelFormatter(formatter)
|
||||||
|
binding.sliderBrightness.setLabelFormatter(formatter)
|
||||||
|
binding.buttonDone.setOnClickListener(this)
|
||||||
|
binding.buttonReset.setOnClickListener(this)
|
||||||
|
|
||||||
|
onBackPressedDispatcher.addCallback(ColorFilterConfigBackPressedDispatcher(this, viewModel))
|
||||||
|
|
||||||
|
viewModel.colorFilter.observe(this, this::onColorFilterChanged)
|
||||||
|
viewModel.isLoading.observe(this, this::onLoadingChanged)
|
||||||
|
viewModel.preview.observe(this, this::onPreviewChanged)
|
||||||
|
viewModel.onDismiss.observe(this) {
|
||||||
|
finishAfterTransition()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onValueChange(slider: Slider, value: Float, fromUser: Boolean) {
|
||||||
|
if (fromUser) {
|
||||||
|
when (slider.id) {
|
||||||
|
R.id.slider_brightness -> viewModel.setBrightness(value)
|
||||||
|
R.id.slider_contrast -> viewModel.setContrast(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(v: View) {
|
||||||
|
when (v.id) {
|
||||||
|
R.id.button_done -> viewModel.save()
|
||||||
|
R.id.button_reset -> viewModel.reset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
|
binding.root.updatePadding(
|
||||||
|
left = insets.left,
|
||||||
|
right = insets.right,
|
||||||
|
)
|
||||||
|
binding.scrollView.updatePadding(
|
||||||
|
bottom = insets.bottom,
|
||||||
|
)
|
||||||
|
binding.toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
|
topMargin = insets.top
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onColorFilterChanged(readerColorFilter: ReaderColorFilter?) {
|
||||||
|
binding.sliderBrightness.value = readerColorFilter?.brightness ?: 0f
|
||||||
|
binding.sliderContrast.value = readerColorFilter?.contrast ?: 0f
|
||||||
|
binding.imageViewAfter.colorFilter = readerColorFilter?.toColorFilter()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onPreviewChanged(preview: MangaPage?) {
|
||||||
|
if (preview == null) return
|
||||||
|
ImageRequest.Builder(this@ColorFilterConfigActivity)
|
||||||
|
.data(preview.url)
|
||||||
|
.referer(preview.referer)
|
||||||
|
.scale(Scale.FILL)
|
||||||
|
.decodeRegion()
|
||||||
|
.error(R.drawable.ic_error_placeholder)
|
||||||
|
.size(ViewSizeResolver(binding.imageViewBefore))
|
||||||
|
.allowRgb565(false)
|
||||||
|
.target(ShadowViewTarget(binding.imageViewBefore, binding.imageViewAfter))
|
||||||
|
.enqueueWith(coil)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onLoadingChanged(isLoading: Boolean) {
|
||||||
|
binding.sliderContrast.isEnabled = !isLoading
|
||||||
|
binding.sliderBrightness.isEnabled = !isLoading
|
||||||
|
binding.buttonDone.isEnabled = !isLoading
|
||||||
|
}
|
||||||
|
|
||||||
|
private class PercentLabelFormatter(resources: Resources) : LabelFormatter {
|
||||||
|
|
||||||
|
private val pattern = resources.getString(R.string.percent_string_pattern)
|
||||||
|
|
||||||
|
override fun getFormattedValue(value: Float): String {
|
||||||
|
val percent = ((value + 1f) * 100).format(0)
|
||||||
|
return pattern.format(percent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private const val EXTRA_PAGES = "pages"
|
||||||
|
private const val EXTRA_MANGA = "manga_id"
|
||||||
|
|
||||||
|
fun newIntent(context: Context, manga: Manga, page: MangaPage) =
|
||||||
|
Intent(context, ColorFilterConfigActivity::class.java)
|
||||||
|
.putExtra(EXTRA_MANGA, ParcelableManga(manga, false))
|
||||||
|
.putExtra(EXTRA_PAGES, ParcelableMangaPages(listOf(page)))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package org.koitharu.kotatsu.reader.ui.colorfilter
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
class ColorFilterConfigBackPressedDispatcher(
|
||||||
|
private val context: Context,
|
||||||
|
private val viewModel: ColorFilterConfigViewModel,
|
||||||
|
) : OnBackPressedCallback(true), DialogInterface.OnClickListener {
|
||||||
|
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
if (viewModel.isChanged) {
|
||||||
|
showConfirmation()
|
||||||
|
} else {
|
||||||
|
viewModel.onDismiss.call(Unit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(dialog: DialogInterface, which: Int) {
|
||||||
|
when (which) {
|
||||||
|
DialogInterface.BUTTON_NEGATIVE -> viewModel.onDismiss.call(Unit)
|
||||||
|
DialogInterface.BUTTON_NEUTRAL -> dialog.dismiss()
|
||||||
|
DialogInterface.BUTTON_POSITIVE -> viewModel.save()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showConfirmation() {
|
||||||
|
MaterialAlertDialogBuilder(context)
|
||||||
|
.setTitle(R.string.color_correction)
|
||||||
|
.setMessage(R.string.text_unsaved_changes_prompt)
|
||||||
|
.setNegativeButton(R.string.discard, this)
|
||||||
|
.setNeutralButton(android.R.string.cancel, this)
|
||||||
|
.setPositiveButton(R.string.save, this)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package org.koitharu.kotatsu.reader.ui.colorfilter
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import dagger.assisted.Assisted
|
||||||
|
import dagger.assisted.AssistedFactory
|
||||||
|
import dagger.assisted.AssistedInject
|
||||||
|
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.reader.domain.ReaderColorFilter
|
||||||
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
|
|
||||||
|
class ColorFilterConfigViewModel @AssistedInject constructor(
|
||||||
|
@Assisted private val manga: Manga,
|
||||||
|
@Assisted page: MangaPage,
|
||||||
|
private val mangaRepositoryFactory: MangaRepository.Factory,
|
||||||
|
private val mangaDataRepository: MangaDataRepository,
|
||||||
|
) : BaseViewModel() {
|
||||||
|
|
||||||
|
private var initialColorFilter: ReaderColorFilter? = null
|
||||||
|
val colorFilter = MutableLiveData<ReaderColorFilter?>(null)
|
||||||
|
val onDismiss = SingleLiveEvent<Unit>()
|
||||||
|
val preview = MutableLiveData<MangaPage?>(null)
|
||||||
|
|
||||||
|
val isChanged: Boolean
|
||||||
|
get() = colorFilter.value != initialColorFilter
|
||||||
|
|
||||||
|
init {
|
||||||
|
launchLoadingJob {
|
||||||
|
initialColorFilter = mangaDataRepository.getColorFilter(manga.id)
|
||||||
|
colorFilter.value = initialColorFilter
|
||||||
|
}
|
||||||
|
launchLoadingJob {
|
||||||
|
val repository = mangaRepositoryFactory.create(page.source)
|
||||||
|
val url = repository.getPageUrl(page)
|
||||||
|
preview.value = MangaPage(
|
||||||
|
id = page.id,
|
||||||
|
url = url,
|
||||||
|
referer = page.referer,
|
||||||
|
preview = page.preview,
|
||||||
|
source = page.source,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setBrightness(brightness: Float) {
|
||||||
|
val cf = colorFilter.value
|
||||||
|
colorFilter.value = ReaderColorFilter(brightness, cf?.contrast ?: 0f).takeUnless { it.isEmpty }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setContrast(contrast: Float) {
|
||||||
|
val cf = colorFilter.value
|
||||||
|
colorFilter.value = ReaderColorFilter(cf?.brightness ?: 0f, contrast).takeUnless { it.isEmpty }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun reset() {
|
||||||
|
colorFilter.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun save() {
|
||||||
|
launchLoadingJob {
|
||||||
|
mangaDataRepository.saveColorFilter(manga, colorFilter.value)
|
||||||
|
onDismiss.call(Unit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AssistedFactory
|
||||||
|
interface Factory {
|
||||||
|
|
||||||
|
fun create(manga: Manga, page: MangaPage): ColorFilterConfigViewModel
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.koitharu.kotatsu.reader.ui.colorfilter
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.widget.ImageView
|
||||||
|
import coil.target.ImageViewTarget
|
||||||
|
|
||||||
|
class ShadowViewTarget(
|
||||||
|
view: ImageView,
|
||||||
|
private val shadowView: ImageView,
|
||||||
|
) : ImageViewTarget(view) {
|
||||||
|
|
||||||
|
override var drawable: Drawable?
|
||||||
|
get() = super.drawable
|
||||||
|
set(value) {
|
||||||
|
super.drawable = value
|
||||||
|
shadowView.setImageDrawable(value?.constantState?.newDrawable())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import org.koitharu.kotatsu.core.prefs.ReaderMode
|
|||||||
import org.koitharu.kotatsu.databinding.SheetReaderConfigBinding
|
import org.koitharu.kotatsu.databinding.SheetReaderConfigBinding
|
||||||
import org.koitharu.kotatsu.reader.ui.PageSaveContract
|
import org.koitharu.kotatsu.reader.ui.PageSaveContract
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderViewModel
|
import org.koitharu.kotatsu.reader.ui.ReaderViewModel
|
||||||
|
import org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity
|
||||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||||
import org.koitharu.kotatsu.utils.ScreenOrientationHelper
|
import org.koitharu.kotatsu.utils.ScreenOrientationHelper
|
||||||
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||||
@@ -59,6 +60,7 @@ class ReaderConfigBottomSheet :
|
|||||||
binding.buttonSavePage.setOnClickListener(this)
|
binding.buttonSavePage.setOnClickListener(this)
|
||||||
binding.buttonScreenRotate.setOnClickListener(this)
|
binding.buttonScreenRotate.setOnClickListener(this)
|
||||||
binding.buttonSettings.setOnClickListener(this)
|
binding.buttonSettings.setOnClickListener(this)
|
||||||
|
binding.buttonColorFilter.setOnClickListener(this)
|
||||||
binding.sliderTimer.addOnSliderTouchListener(this)
|
binding.sliderTimer.addOnSliderTouchListener(this)
|
||||||
binding.sliderTimer.setLabelFormatter(PageSwitchTimer.DelayLabelFormatter(view.resources))
|
binding.sliderTimer.setLabelFormatter(PageSwitchTimer.DelayLabelFormatter(view.resources))
|
||||||
|
|
||||||
@@ -80,6 +82,11 @@ class ReaderConfigBottomSheet :
|
|||||||
R.id.button_screen_rotate -> {
|
R.id.button_screen_rotate -> {
|
||||||
orientationHelper?.toggleOrientation()
|
orientationHelper?.toggleOrientation()
|
||||||
}
|
}
|
||||||
|
R.id.button_color_filter -> {
|
||||||
|
val page = viewModel.getCurrentPage() ?: return
|
||||||
|
val manga = viewModel.manga ?: return
|
||||||
|
startActivity(ColorFilterConfigActivity.newIntent(v.context, manga, page))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package org.koitharu.kotatsu.reader.ui.config
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import androidx.lifecycle.MediatorLiveData
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.flow.FlowCollector
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import org.koitharu.kotatsu.core.model.ZoomMode
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.reader.domain.ReaderColorFilter
|
||||||
|
|
||||||
|
class ReaderSettings(
|
||||||
|
private val parentScope: CoroutineScope,
|
||||||
|
private val settings: AppSettings,
|
||||||
|
private val colorFilterFlow: StateFlow<ReaderColorFilter?>,
|
||||||
|
) : MediatorLiveData<ReaderSettings>() {
|
||||||
|
|
||||||
|
private val internalObserver = InternalObserver()
|
||||||
|
private var collectJob: Job? = null
|
||||||
|
|
||||||
|
val zoomMode: ZoomMode
|
||||||
|
get() = settings.zoomMode
|
||||||
|
|
||||||
|
val colorFilter: ReaderColorFilter?
|
||||||
|
get() = colorFilterFlow.value
|
||||||
|
|
||||||
|
val isPagesNumbersEnabled: Boolean
|
||||||
|
get() = settings.isPagesNumbersEnabled
|
||||||
|
|
||||||
|
override fun onInactive() {
|
||||||
|
super.onInactive()
|
||||||
|
settings.unsubscribe(internalObserver)
|
||||||
|
collectJob?.cancel()
|
||||||
|
collectJob = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActive() {
|
||||||
|
super.onActive()
|
||||||
|
settings.subscribe(internalObserver)
|
||||||
|
collectJob?.cancel()
|
||||||
|
collectJob = parentScope.launch {
|
||||||
|
colorFilterFlow.collect(internalObserver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getValue() = this
|
||||||
|
|
||||||
|
private fun notifyChanged() {
|
||||||
|
value = value
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class InternalObserver :
|
||||||
|
FlowCollector<ReaderColorFilter?>,
|
||||||
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
|
override suspend fun emit(value: ReaderColorFilter?) {
|
||||||
|
withContext(Dispatchers.Main.immediate) {
|
||||||
|
notifyChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||||
|
if (key == AppSettings.KEY_ZOOM_MODE || key == AppSettings.KEY_PAGES_NUMBERS) {
|
||||||
|
notifyChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,15 +5,15 @@ import androidx.annotation.CallSuper
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
||||||
import org.koitharu.kotatsu.databinding.LayoutPageInfoBinding
|
import org.koitharu.kotatsu.databinding.LayoutPageInfoBinding
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
|
|
||||||
abstract class BasePageHolder<B : ViewBinding>(
|
abstract class BasePageHolder<B : ViewBinding>(
|
||||||
protected val binding: B,
|
protected val binding: B,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: AppSettings,
|
settings: ReaderSettings,
|
||||||
exceptionResolver: ExceptionResolver
|
exceptionResolver: ExceptionResolver,
|
||||||
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
@@ -37,8 +37,18 @@ abstract class BasePageHolder<B : ViewBinding>(
|
|||||||
|
|
||||||
protected abstract fun onBind(data: ReaderPage)
|
protected abstract fun onBind(data: ReaderPage)
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
open fun onAttachedToWindow() {
|
||||||
|
delegate.onAttachedToWindow()
|
||||||
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
open fun onDetachedFromWindow() {
|
||||||
|
delegate.onDetachedFromWindow()
|
||||||
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
open fun onRecycled() {
|
open fun onRecycled() {
|
||||||
delegate.onRecycle()
|
delegate.onRecycle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import androidx.viewbinding.ViewBinding
|
|||||||
import org.koitharu.kotatsu.base.ui.BaseFragment
|
import org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderState
|
import org.koitharu.kotatsu.reader.ui.ReaderState
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderViewModel
|
import org.koitharu.kotatsu.reader.ui.ReaderViewModel
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableCompat
|
||||||
|
|
||||||
private const val KEY_STATE = "state"
|
private const val KEY_STATE = "state"
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ abstract class BaseReader<B : ViewBinding> : BaseFragment<B>() {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
var restoredState = savedInstanceState?.getParcelable<ReaderState?>(KEY_STATE)
|
var restoredState = savedInstanceState?.getParcelableCompat<ReaderState>(KEY_STATE)
|
||||||
|
|
||||||
viewModel.content.observe(viewLifecycleOwner) {
|
viewModel.content.observe(viewLifecycleOwner) {
|
||||||
onPagesChanged(it.pages, restoredState ?: it.state)
|
onPagesChanged(it.pages, restoredState ?: it.state)
|
||||||
|
|||||||
@@ -4,17 +4,17 @@ import android.view.ViewGroup
|
|||||||
import androidx.recyclerview.widget.AsyncListDiffer
|
import androidx.recyclerview.widget.AsyncListDiffer
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
|
||||||
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
|
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
||||||
private val loader: PageLoader,
|
private val loader: PageLoader,
|
||||||
private val settings: AppSettings,
|
private val readerSettings: ReaderSettings,
|
||||||
private val exceptionResolver: ExceptionResolver,
|
private val exceptionResolver: ExceptionResolver,
|
||||||
) : RecyclerView.Adapter<H>() {
|
) : RecyclerView.Adapter<H>() {
|
||||||
|
|
||||||
@@ -35,6 +35,16 @@ abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
|||||||
super.onViewRecycled(holder)
|
super.onViewRecycled(holder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onViewAttachedToWindow(holder: H) {
|
||||||
|
super.onViewAttachedToWindow(holder)
|
||||||
|
holder.onAttachedToWindow()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewDetachedFromWindow(holder: H) {
|
||||||
|
holder.onDetachedFromWindow()
|
||||||
|
super.onViewDetachedFromWindow(holder)
|
||||||
|
}
|
||||||
|
|
||||||
open fun getItem(position: Int): ReaderPage = differ.currentList[position]
|
open fun getItem(position: Int): ReaderPage = differ.currentList[position]
|
||||||
|
|
||||||
open fun getItemOrNull(position: Int) = differ.currentList.getOrNull(position)
|
open fun getItemOrNull(position: Int) = differ.currentList.getOrNull(position)
|
||||||
@@ -45,8 +55,8 @@ abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
|||||||
|
|
||||||
final override fun onCreateViewHolder(
|
final override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int
|
viewType: Int,
|
||||||
): H = onCreateViewHolder(parent, loader, settings, exceptionResolver)
|
): H = onCreateViewHolder(parent, loader, readerSettings, exceptionResolver)
|
||||||
|
|
||||||
suspend fun setItems(items: List<ReaderPage>) = suspendCoroutine<Unit> { cont ->
|
suspend fun setItems(items: List<ReaderPage>) = suspendCoroutine<Unit> { cont ->
|
||||||
differ.submitList(items) {
|
differ.submitList(items) {
|
||||||
@@ -57,8 +67,8 @@ abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
|||||||
protected abstract fun onCreateViewHolder(
|
protected abstract fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: AppSettings,
|
settings: ReaderSettings,
|
||||||
exceptionResolver: ExceptionResolver
|
exceptionResolver: ExceptionResolver,
|
||||||
): H
|
): H
|
||||||
|
|
||||||
private class DiffCallback : DiffUtil.ItemCallback<ReaderPage>() {
|
private class DiffCallback : DiffUtil.ItemCallback<ReaderPage>() {
|
||||||
@@ -70,6 +80,5 @@ abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
|||||||
override fun areContentsTheSame(oldItem: ReaderPage, newItem: ReaderPage): Boolean {
|
override fun areContentsTheSame(oldItem: ReaderPage, newItem: ReaderPage): Boolean {
|
||||||
return oldItem == newItem
|
return oldItem == newItem
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,26 +2,32 @@ package org.koitharu.kotatsu.reader.ui.pager
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import androidx.lifecycle.Observer
|
||||||
import kotlinx.coroutines.*
|
import com.davemorrissey.labs.subscaleview.DefaultOnImageEventListener
|
||||||
|
import kotlinx.coroutines.CancellationException
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.cancelAndJoin
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
import org.koitharu.kotatsu.core.model.ZoomMode
|
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class PageHolderDelegate(
|
class PageHolderDelegate(
|
||||||
private val loader: PageLoader,
|
private val loader: PageLoader,
|
||||||
private val settings: AppSettings,
|
private val readerSettings: ReaderSettings,
|
||||||
private val callback: Callback,
|
private val callback: Callback,
|
||||||
private val exceptionResolver: ExceptionResolver
|
private val exceptionResolver: ExceptionResolver,
|
||||||
) : SubsamplingScaleImageView.DefaultOnImageEventListener() {
|
) : DefaultOnImageEventListener, Observer<ReaderSettings> {
|
||||||
|
|
||||||
private val scope = loader.loaderScope + Dispatchers.Main.immediate
|
private val scope = loader.loaderScope + Dispatchers.Main.immediate
|
||||||
private var state = State.EMPTY
|
private var state = State.EMPTY
|
||||||
@@ -49,6 +55,14 @@ class PageHolderDelegate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onAttachedToWindow() {
|
||||||
|
readerSettings.observeForever(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onDetachedFromWindow() {
|
||||||
|
readerSettings.removeObserver(this)
|
||||||
|
}
|
||||||
|
|
||||||
fun onRecycle() {
|
fun onRecycle() {
|
||||||
state = State.EMPTY
|
state = State.EMPTY
|
||||||
file = null
|
file = null
|
||||||
@@ -59,7 +73,7 @@ class PageHolderDelegate(
|
|||||||
override fun onReady() {
|
override fun onReady() {
|
||||||
state = State.SHOWING
|
state = State.SHOWING
|
||||||
error = null
|
error = null
|
||||||
callback.onImageShowing(settings.zoomMode)
|
callback.onImageShowing(readerSettings)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onImageLoaded() {
|
override fun onImageLoaded() {
|
||||||
@@ -68,7 +82,7 @@ class PageHolderDelegate(
|
|||||||
callback.onImageShown()
|
callback.onImageShown()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onImageLoadError(e: Exception) {
|
override fun onImageLoadError(e: Throwable) {
|
||||||
val file = this.file
|
val file = this.file
|
||||||
error = e
|
error = e
|
||||||
if (state == State.LOADED && e is IOException && file != null && file.exists()) {
|
if (state == State.LOADED && e is IOException && file != null && file.exists()) {
|
||||||
@@ -79,6 +93,12 @@ class PageHolderDelegate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onChanged(t: ReaderSettings?) {
|
||||||
|
if (state == State.SHOWN) {
|
||||||
|
callback.onImageShowing(readerSettings)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun tryConvert(file: File, e: Exception) {
|
private fun tryConvert(file: File, e: Exception) {
|
||||||
val prevJob = job
|
val prevJob = job
|
||||||
job = scope.launch {
|
job = scope.launch {
|
||||||
@@ -88,6 +108,8 @@ class PageHolderDelegate(
|
|||||||
loader.convertInPlace(file)
|
loader.convertInPlace(file)
|
||||||
state = State.CONVERTED
|
state = State.CONVERTED
|
||||||
callback.onImageReady(file.toUri())
|
callback.onImageReady(file.toUri())
|
||||||
|
} catch (ce: CancellationException) {
|
||||||
|
throw ce
|
||||||
} catch (e2: Throwable) {
|
} catch (e2: Throwable) {
|
||||||
e.addSuppressed(e2)
|
e.addSuppressed(e2)
|
||||||
state = State.ERROR
|
state = State.ERROR
|
||||||
@@ -134,10 +156,10 @@ class PageHolderDelegate(
|
|||||||
|
|
||||||
fun onImageReady(uri: Uri)
|
fun onImageReady(uri: Uri)
|
||||||
|
|
||||||
fun onImageShowing(zoom: ZoomMode)
|
fun onImageShowing(settings: ReaderSettings)
|
||||||
|
|
||||||
fun onImageShown()
|
fun onImageShown()
|
||||||
|
|
||||||
fun onProgressChanged(progress: Int)
|
fun onProgressChanged(progress: Int)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,13 @@ data class ReaderUiState(
|
|||||||
val chaptersTotal: Int,
|
val chaptersTotal: Int,
|
||||||
val currentPage: Int,
|
val currentPage: Int,
|
||||||
val totalPages: Int,
|
val totalPages: Int,
|
||||||
|
private val isSliderEnabled: Boolean,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
fun isSliderAvailable(): Boolean {
|
||||||
|
return isSliderEnabled && totalPages > 1 && currentPage < totalPages
|
||||||
|
}
|
||||||
|
|
||||||
fun computePercent(): Float {
|
fun computePercent(): Float {
|
||||||
val ppc = 1f / chaptersTotal
|
val ppc = 1f / chaptersTotal
|
||||||
val chapterIndex = chapterNumber - 1
|
val chapterIndex = chapterNumber - 1
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ import android.widget.FrameLayout
|
|||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
import org.koitharu.kotatsu.core.model.ZoomMode
|
import org.koitharu.kotatsu.core.model.ZoomMode
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
||||||
import org.koitharu.kotatsu.databinding.ItemPageBinding
|
import org.koitharu.kotatsu.databinding.ItemPageBinding
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.standard.PageHolder
|
import org.koitharu.kotatsu.reader.ui.pager.standard.PageHolder
|
||||||
|
|
||||||
class ReversedPageHolder(
|
class ReversedPageHolder(
|
||||||
binding: ItemPageBinding,
|
binding: ItemPageBinding,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: AppSettings,
|
settings: ReaderSettings,
|
||||||
exceptionResolver: ExceptionResolver
|
exceptionResolver: ExceptionResolver,
|
||||||
) : PageHolder(binding, loader, settings, exceptionResolver) {
|
) : PageHolder(binding, loader, settings, exceptionResolver) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -23,41 +23,42 @@ class ReversedPageHolder(
|
|||||||
.gravity = Gravity.START or Gravity.BOTTOM
|
.gravity = Gravity.START or Gravity.BOTTOM
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onImageShowing(zoom: ZoomMode) {
|
override fun onImageShowing(settings: ReaderSettings) {
|
||||||
with(binding.ssiv) {
|
with(binding.ssiv) {
|
||||||
maxScale = 2f * maxOf(
|
maxScale = 2f * maxOf(
|
||||||
width / sWidth.toFloat(),
|
width / sWidth.toFloat(),
|
||||||
height / sHeight.toFloat()
|
height / sHeight.toFloat(),
|
||||||
)
|
)
|
||||||
when (zoom) {
|
binding.ssiv.colorFilter = settings.colorFilter?.toColorFilter()
|
||||||
|
when (settings.zoomMode) {
|
||||||
ZoomMode.FIT_CENTER -> {
|
ZoomMode.FIT_CENTER -> {
|
||||||
setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE)
|
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
|
||||||
resetScaleAndCenter()
|
resetScaleAndCenter()
|
||||||
}
|
}
|
||||||
ZoomMode.FIT_HEIGHT -> {
|
ZoomMode.FIT_HEIGHT -> {
|
||||||
setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM)
|
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CUSTOM
|
||||||
minScale = height / sHeight.toFloat()
|
minScale = height / sHeight.toFloat()
|
||||||
setScaleAndCenter(
|
setScaleAndCenter(
|
||||||
minScale,
|
minScale,
|
||||||
PointF(sWidth.toFloat(), sHeight / 2f)
|
PointF(sWidth.toFloat(), sHeight / 2f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ZoomMode.FIT_WIDTH -> {
|
ZoomMode.FIT_WIDTH -> {
|
||||||
setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM)
|
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CUSTOM
|
||||||
minScale = width / sWidth.toFloat()
|
minScale = width / sWidth.toFloat()
|
||||||
setScaleAndCenter(
|
setScaleAndCenter(
|
||||||
minScale,
|
minScale,
|
||||||
PointF(sWidth / 2f, 0f)
|
PointF(sWidth / 2f, 0f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ZoomMode.KEEP_START -> {
|
ZoomMode.KEEP_START -> {
|
||||||
setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE)
|
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
|
||||||
setScaleAndCenter(
|
setScaleAndCenter(
|
||||||
maxScale,
|
maxScale,
|
||||||
PointF(sWidth.toFloat(), 0f)
|
PointF(sWidth.toFloat(), 0f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user