Compare commits
65 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed56170809 | ||
|
|
a36e5fce29 | ||
|
|
760bfaf4d7 | ||
|
|
24463720b1 | ||
|
|
516470e8ae | ||
|
|
7f530d0476 | ||
|
|
8a2706d70b | ||
|
|
27f09480a0 | ||
|
|
c03dcf6d2e | ||
|
|
bdb2ae9c2f | ||
|
|
3413fe6943 | ||
|
|
e6ae9e8bd6 | ||
|
|
8d9426f257 | ||
|
|
30247e3def | ||
|
|
084dc32d2d | ||
|
|
3393f1397b | ||
|
|
61784bcfc4 | ||
|
|
bd692fc60c | ||
|
|
738299e8d3 | ||
|
|
c8b6dc27b2 | ||
|
|
1493aa39a3 | ||
|
|
f115031846 | ||
|
|
571b85dfd8 | ||
|
|
75cc9e9030 | ||
|
|
656a707b4c | ||
|
|
04afe7a934 | ||
|
|
689670b3ff | ||
|
|
6273a9decb | ||
|
|
72336d4f71 | ||
|
|
731e998eb2 | ||
|
|
9bf53114de | ||
|
|
0e1b8db688 | ||
|
|
3a62e2e6c0 | ||
|
|
08764cb3cb | ||
|
|
9c52545f63 | ||
|
|
a6c30d33d4 | ||
|
|
25974af229 | ||
|
|
607dfc9be3 | ||
|
|
560e669700 | ||
|
|
ba403c9360 | ||
|
|
0f1c9ff05d | ||
|
|
662f08e115 | ||
|
|
d647a32e9f | ||
|
|
375e72cb98 | ||
|
|
34c7cafdfe | ||
|
|
03e0eefe4d | ||
|
|
f41425f03d | ||
|
|
400b91278f | ||
|
|
9088f77ae5 | ||
|
|
86da3217d1 | ||
|
|
24908e52af | ||
|
|
1261a6790d | ||
|
|
59fa61864a | ||
|
|
1cbfe017ea | ||
|
|
f469369b14 | ||
|
|
1ddcaed483 | ||
|
|
7bb7736f18 | ||
|
|
d1e7e7a2a6 | ||
|
|
0c4b7b0586 | ||
|
|
f320f22863 | ||
|
|
d224cd99bb | ||
|
|
b955d31770 | ||
|
|
b4eb8d56a6 | ||
|
|
c896ac72e8 | ||
|
|
b599cb33ff |
2
.idea/kotlinc.xml
generated
2
.idea/kotlinc.xml
generated
@@ -4,6 +4,6 @@
|
|||||||
<option name="jvmTarget" value="1.8" />
|
<option name="jvmTarget" value="1.8" />
|
||||||
</component>
|
</component>
|
||||||
<component name="KotlinJpsPluginSettings">
|
<component name="KotlinJpsPluginSettings">
|
||||||
<option name="version" value="1.7.20" />
|
<option name="version" value="1.8.0" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -26,7 +26,7 @@ Download APK directly from GitHub:
|
|||||||
* Notifications about new chapters with updates feed
|
* Notifications about new chapters with updates feed
|
||||||
* Shikimori integration (manga tracking)
|
* Shikimori integration (manga tracking)
|
||||||
* Password/fingerprint protect access to the app
|
* Password/fingerprint protect access to the app
|
||||||
* History and favourites synchronization across devices (coming soon)
|
* History and favourites [synchronization](https://github.com/KotatsuApp/kotatsu-syncserver) across devices
|
||||||
|
|
||||||
### Screenshots
|
### Screenshots
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ android {
|
|||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 33
|
targetSdkVersion 33
|
||||||
versionCode 503
|
versionCode 509
|
||||||
versionName '4.0.3'
|
versionName '4.2'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
@@ -83,15 +83,16 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation('com.github.KotatsuApp:kotatsu-parsers:bf8a1f3db2') {
|
implementation('com.github.KotatsuApp:kotatsu-parsers:cf00732023') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.0'
|
||||||
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.9.0'
|
implementation 'androidx.core:core-ktx:1.9.0'
|
||||||
implementation 'androidx.activity:activity-ktx:1.6.1'
|
implementation 'androidx.activity:activity-ktx:1.6.1'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.5.4'
|
implementation 'androidx.fragment:fragment-ktx:1.5.5'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-service:2.5.1'
|
implementation 'androidx.lifecycle:lifecycle-service:2.5.1'
|
||||||
@@ -113,40 +114,40 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
|
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
|
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
|
||||||
implementation 'com.squareup.okio:okio:3.2.0'
|
implementation 'com.squareup.okio:okio:3.3.0'
|
||||||
|
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
||||||
|
|
||||||
implementation "com.google.dagger:hilt-android:2.44"
|
implementation 'com.google.dagger:hilt-android:2.44.2'
|
||||||
kapt "com.google.dagger:hilt-compiler:2.44"
|
kapt 'com.google.dagger:hilt-compiler:2.44.2'
|
||||||
implementation 'androidx.hilt:hilt-work:1.0.0'
|
implementation 'androidx.hilt:hilt-work:1.0.0'
|
||||||
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
||||||
|
|
||||||
implementation 'io.coil-kt:coil-base:2.2.2'
|
implementation 'io.coil-kt:coil-base:2.2.2'
|
||||||
implementation 'io.coil-kt:coil-svg:2.2.2'
|
implementation 'io.coil-kt:coil-svg:2.2.2'
|
||||||
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:f8a38b08fe'
|
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:1b19231b2f'
|
||||||
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
||||||
|
|
||||||
implementation 'ch.acra:acra-http:5.9.6'
|
implementation 'ch.acra:acra-http:5.9.7'
|
||||||
implementation 'ch.acra:acra-dialog:5.9.6'
|
implementation 'ch.acra:acra-dialog:5.9.7'
|
||||||
|
|
||||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
testImplementation 'org.json:json:20220924'
|
testImplementation 'org.json:json:20220924'
|
||||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.test:runner:1.4.0'
|
androidTestImplementation 'androidx.test:runner:1.5.2'
|
||||||
androidTestImplementation 'androidx.test:rules:1.4.0'
|
androidTestImplementation 'androidx.test:rules:1.5.0'
|
||||||
androidTestImplementation 'androidx.test:core-ktx:1.4.0'
|
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
|
||||||
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5'
|
||||||
|
|
||||||
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.room:room-testing:2.4.3'
|
androidTestImplementation 'androidx.room:room-testing:2.4.3'
|
||||||
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
|
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
|
||||||
|
|
||||||
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.44'
|
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.44.2'
|
||||||
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.44'
|
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.44.2'
|
||||||
}
|
}
|
||||||
|
|||||||
1
app/proguard-rules.pro
vendored
1
app/proguard-rules.pro
vendored
@@ -14,3 +14,4 @@
|
|||||||
|
|
||||||
-keep class org.koitharu.kotatsu.core.exceptions.* { *; }
|
-keep class org.koitharu.kotatsu.core.exceptions.* { *; }
|
||||||
-keep class org.koitharu.kotatsu.settings.NotificationSettingsLegacyFragment
|
-keep class org.koitharu.kotatsu.settings.NotificationSettingsLegacyFragment
|
||||||
|
-keep class org.koitharu.kotatsu.core.prefs.ScreenshotsPolicy { *; }
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
android:fullBackupOnly="true"
|
android:fullBackupOnly="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
android:largeHeap="true"
|
||||||
|
android:localeConfig="@xml/locales"
|
||||||
android:networkSecurityConfig="@xml/network_security_config"
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
@@ -186,6 +188,9 @@
|
|||||||
android:name="android.content.SyncAdapter"
|
android:name="android.content.SyncAdapter"
|
||||||
android:resource="@xml/sync_history" />
|
android:resource="@xml/sync_history" />
|
||||||
</service>
|
</service>
|
||||||
|
<service
|
||||||
|
android:name="org.koitharu.kotatsu.details.service.MangaPrefetchService"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider"
|
android:name="org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider"
|
||||||
@@ -246,6 +251,9 @@
|
|||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.webkit.WebView.MetricsOptOut"
|
android:name="android.webkit.WebView.MetricsOptOut"
|
||||||
android:value="true" />
|
android:value="true" />
|
||||||
|
<meta-data
|
||||||
|
android:name="com.samsung.android.icon_container.has_icon_container"
|
||||||
|
android:value="@bool/com_samsung_android_icon_container_has_icon_container" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ abstract class CoroutineIntentService : BaseService() {
|
|||||||
processIntent(startId, intent)
|
processIntent(startId, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
onError(startId, e)
|
||||||
} finally {
|
} finally {
|
||||||
stopSelf(startId)
|
stopSelf(startId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,20 @@ package org.koitharu.kotatsu.base.ui.list
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.ArrayMap
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
|
import androidx.collection.ArrayMap
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleEventObserver
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.savedstate.SavedStateRegistry
|
import androidx.savedstate.SavedStateRegistry
|
||||||
import androidx.savedstate.SavedStateRegistryOwner
|
import androidx.savedstate.SavedStateRegistryOwner
|
||||||
import kotlin.coroutines.EmptyCoroutineContext
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
private const val PROVIDER_NAME = "selection_decoration_sectioned"
|
private const val PROVIDER_NAME = "selection_decoration_sectioned"
|
||||||
|
|
||||||
|
|||||||
@@ -516,6 +516,6 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
|
|
||||||
interface SectionIndexer {
|
interface SectionIndexer {
|
||||||
|
|
||||||
fun getSectionText(context: Context, position: Int): CharSequence
|
fun getSectionText(context: Context, position: Int): CharSequence?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import android.graphics.Bitmap
|
|||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.webkit.WebViewClient
|
import android.webkit.WebViewClient
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||||
|
|
||||||
private const val CF_CLEARANCE = "cf_clearance"
|
private const val CF_CLEARANCE = "cf_clearance"
|
||||||
|
|
||||||
class CloudFlareClient(
|
class CloudFlareClient(
|
||||||
private val cookieJar: AndroidCookieJar,
|
private val cookieJar: MutableCookieJar,
|
||||||
private val callback: CloudFlareCallback,
|
private val callback: CloudFlareCallback,
|
||||||
private val targetUrl: String,
|
private val targetUrl: String,
|
||||||
) : WebViewClient() {
|
) : WebViewClient() {
|
||||||
@@ -42,4 +42,4 @@ class CloudFlareClient(
|
|||||||
return cookieJar.loadForRequest(targetUrl.toHttpUrl())
|
return cookieJar.loadForRequest(targetUrl.toHttpUrl())
|
||||||
.find { it.name == CF_CLEARANCE }?.value
|
.find { it.name == CF_CLEARANCE }?.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import androidx.core.view.isInvisible
|
|||||||
import androidx.fragment.app.setFragmentResult
|
import androidx.fragment.app.setFragmentResult
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
||||||
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
|
||||||
import org.koitharu.kotatsu.core.network.UserAgentInterceptor
|
import org.koitharu.kotatsu.core.network.UserAgentInterceptor
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||||
import org.koitharu.kotatsu.databinding.FragmentCloudflareBinding
|
import org.koitharu.kotatsu.databinding.FragmentCloudflareBinding
|
||||||
import org.koitharu.kotatsu.utils.ext.stringArgument
|
import org.koitharu.kotatsu.utils.ext.stringArgument
|
||||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), CloudFlareCallback {
|
class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), CloudFlareCallback {
|
||||||
@@ -27,7 +27,7 @@ class CloudFlareDialog : AlertDialogFragment<FragmentCloudflareBinding>(), Cloud
|
|||||||
private val pendingResult = Bundle(1)
|
private val pendingResult = Bundle(1)
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var cookieJar: AndroidCookieJar
|
lateinit var cookieJar: MutableCookieJar
|
||||||
|
|
||||||
override fun onInflateView(
|
override fun onInflateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.app.Application
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.provider.SearchRecentSuggestions
|
import android.provider.SearchRecentSuggestions
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
|
import android.util.AndroidRuntimeException
|
||||||
import androidx.collection.arraySetOf
|
import androidx.collection.arraySetOf
|
||||||
import androidx.room.InvalidationTracker
|
import androidx.room.InvalidationTracker
|
||||||
import coil.ComponentRegistry
|
import coil.ComponentRegistry
|
||||||
@@ -23,8 +24,15 @@ import okhttp3.CookieJar
|
|||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.base.ui.util.ActivityRecreationHandle
|
import org.koitharu.kotatsu.base.ui.util.ActivityRecreationHandle
|
||||||
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.core.cache.MemoryContentCache
|
||||||
|
import org.koitharu.kotatsu.core.cache.StubContentCache
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.network.*
|
import org.koitharu.kotatsu.core.network.*
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.AndroidCookieJar
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.PreferencesCookieJar
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
||||||
import org.koitharu.kotatsu.core.parser.MangaLoaderContextImpl
|
import org.koitharu.kotatsu.core.parser.MangaLoaderContextImpl
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
@@ -39,6 +47,8 @@ import org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider
|
|||||||
import org.koitharu.kotatsu.settings.backup.BackupObserver
|
import org.koitharu.kotatsu.settings.backup.BackupObserver
|
||||||
import org.koitharu.kotatsu.sync.domain.SyncController
|
import org.koitharu.kotatsu.sync.domain.SyncController
|
||||||
import org.koitharu.kotatsu.utils.IncognitoModeIndicator
|
import org.koitharu.kotatsu.utils.IncognitoModeIndicator
|
||||||
|
import org.koitharu.kotatsu.utils.ext.activityManager
|
||||||
|
import org.koitharu.kotatsu.utils.ext.connectivityManager
|
||||||
import org.koitharu.kotatsu.utils.ext.isLowRamDevice
|
import org.koitharu.kotatsu.utils.ext.isLowRamDevice
|
||||||
import org.koitharu.kotatsu.utils.image.CoilImageGetter
|
import org.koitharu.kotatsu.utils.image.CoilImageGetter
|
||||||
import org.koitharu.kotatsu.widget.WidgetUpdater
|
import org.koitharu.kotatsu.widget.WidgetUpdater
|
||||||
@@ -50,7 +60,7 @@ import javax.inject.Singleton
|
|||||||
interface AppModule {
|
interface AppModule {
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
fun bindCookieJar(androidCookieJar: AndroidCookieJar): CookieJar
|
fun bindCookieJar(androidCookieJar: MutableCookieJar): CookieJar
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
fun bindMangaLoaderContext(mangaLoaderContextImpl: MangaLoaderContextImpl): MangaLoaderContext
|
fun bindMangaLoaderContext(mangaLoaderContextImpl: MangaLoaderContextImpl): MangaLoaderContext
|
||||||
@@ -60,6 +70,17 @@ interface AppModule {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideCookieJar(
|
||||||
|
@ApplicationContext context: Context
|
||||||
|
): MutableCookieJar = try {
|
||||||
|
AndroidCookieJar()
|
||||||
|
} catch (e: AndroidRuntimeException) {
|
||||||
|
// WebView is not available
|
||||||
|
PreferencesCookieJar(context)
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideOkHttpClient(
|
fun provideOkHttpClient(
|
||||||
@@ -81,6 +102,12 @@ interface AppModule {
|
|||||||
}.build()
|
}.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideNetworkState(
|
||||||
|
@ApplicationContext context: Context
|
||||||
|
) = NetworkState(context.connectivityManager)
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideMangaDatabase(
|
fun provideMangaDatabase(
|
||||||
@@ -159,5 +186,17 @@ interface AppModule {
|
|||||||
activityRecreationHandle,
|
activityRecreationHandle,
|
||||||
incognitoModeIndicator,
|
incognitoModeIndicator,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideContentCache(
|
||||||
|
application: Application,
|
||||||
|
): ContentCache {
|
||||||
|
return if (application.activityManager?.isLowRamDevice == true) {
|
||||||
|
StubContentCache()
|
||||||
|
} else {
|
||||||
|
MemoryContentCache(application)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
app/src/main/java/org/koitharu/kotatsu/core/cache/ContentCache.kt
vendored
Normal file
23
app/src/main/java/org/koitharu/kotatsu/core/cache/ContentCache.kt
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
|
||||||
|
interface ContentCache {
|
||||||
|
|
||||||
|
val isCachingEnabled: Boolean
|
||||||
|
|
||||||
|
suspend fun getDetails(source: MangaSource, url: String): Manga?
|
||||||
|
|
||||||
|
fun putDetails(source: MangaSource, url: String, details: SafeDeferred<Manga>)
|
||||||
|
|
||||||
|
suspend fun getPages(source: MangaSource, url: String): List<MangaPage>?
|
||||||
|
|
||||||
|
fun putPages(source: MangaSource, url: String, pages: SafeDeferred<List<MangaPage>>)
|
||||||
|
|
||||||
|
data class Key(
|
||||||
|
val source: MangaSource,
|
||||||
|
val url: String,
|
||||||
|
)
|
||||||
|
}
|
||||||
16
app/src/main/java/org/koitharu/kotatsu/core/cache/DeferredLruCache.kt
vendored
Normal file
16
app/src/main/java/org/koitharu/kotatsu/core/cache/DeferredLruCache.kt
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import androidx.collection.LruCache
|
||||||
|
|
||||||
|
class DeferredLruCache<T>(maxSize: Int) : LruCache<ContentCache.Key, SafeDeferred<T>>(maxSize) {
|
||||||
|
|
||||||
|
override fun entryRemoved(
|
||||||
|
evicted: Boolean,
|
||||||
|
key: ContentCache.Key,
|
||||||
|
oldValue: SafeDeferred<T>,
|
||||||
|
newValue: SafeDeferred<T>?,
|
||||||
|
) {
|
||||||
|
super.entryRemoved(evicted, key, oldValue, newValue)
|
||||||
|
oldValue.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
59
app/src/main/java/org/koitharu/kotatsu/core/cache/MemoryContentCache.kt
vendored
Normal file
59
app/src/main/java/org/koitharu/kotatsu/core/cache/MemoryContentCache.kt
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import android.content.ComponentCallbacks2
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
|
||||||
|
class MemoryContentCache(application: Application) : ContentCache, ComponentCallbacks2 {
|
||||||
|
|
||||||
|
init {
|
||||||
|
application.registerComponentCallbacks(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val detailsCache = DeferredLruCache<Manga>(4)
|
||||||
|
private val pagesCache = DeferredLruCache<List<MangaPage>>(4)
|
||||||
|
|
||||||
|
override val isCachingEnabled: Boolean = true
|
||||||
|
|
||||||
|
override suspend fun getDetails(source: MangaSource, url: String): Manga? {
|
||||||
|
return detailsCache[ContentCache.Key(source, url)]?.awaitOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun putDetails(source: MangaSource, url: String, details: SafeDeferred<Manga>) {
|
||||||
|
detailsCache.put(ContentCache.Key(source, url), details)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getPages(source: MangaSource, url: String): List<MangaPage>? {
|
||||||
|
return pagesCache[ContentCache.Key(source, url)]?.awaitOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun putPages(source: MangaSource, url: String, pages: SafeDeferred<List<MangaPage>>) {
|
||||||
|
pagesCache.put(ContentCache.Key(source, url), pages)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration) = Unit
|
||||||
|
|
||||||
|
override fun onLowMemory() = Unit
|
||||||
|
|
||||||
|
override fun onTrimMemory(level: Int) {
|
||||||
|
trimCache(detailsCache, level)
|
||||||
|
trimCache(pagesCache, level)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun trimCache(cache: DeferredLruCache<*>, level: Int) {
|
||||||
|
when (level) {
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL,
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_COMPLETE,
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_MODERATE -> cache.evictAll()
|
||||||
|
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN,
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW,
|
||||||
|
ComponentCallbacks2.TRIM_MEMORY_BACKGROUND -> cache.trimToSize(1)
|
||||||
|
|
||||||
|
else -> cache.trimToSize(cache.maxSize() / 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
app/src/main/java/org/koitharu/kotatsu/core/cache/SafeDeferred.kt
vendored
Normal file
20
app/src/main/java/org/koitharu/kotatsu/core/cache/SafeDeferred.kt
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import kotlinx.coroutines.Deferred
|
||||||
|
|
||||||
|
class SafeDeferred<T>(
|
||||||
|
private val delegate: Deferred<Result<T>>,
|
||||||
|
) {
|
||||||
|
|
||||||
|
suspend fun await(): T {
|
||||||
|
return delegate.await().getOrThrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun awaitOrNull(): T? {
|
||||||
|
return delegate.await().getOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cancel() {
|
||||||
|
delegate.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/src/main/java/org/koitharu/kotatsu/core/cache/StubContentCache.kt
vendored
Normal file
18
app/src/main/java/org/koitharu/kotatsu/core/cache/StubContentCache.kt
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package org.koitharu.kotatsu.core.cache
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
|
||||||
|
class StubContentCache : ContentCache {
|
||||||
|
|
||||||
|
override val isCachingEnabled: Boolean = false
|
||||||
|
|
||||||
|
override suspend fun getDetails(source: MangaSource, url: String): Manga? = null
|
||||||
|
|
||||||
|
override fun putDetails(source: MangaSource, url: String, details: SafeDeferred<Manga>) = Unit
|
||||||
|
|
||||||
|
override suspend fun getPages(source: MangaSource, url: String): List<MangaPage>? = null
|
||||||
|
|
||||||
|
override fun putPages(source: MangaSource, url: String, pages: SafeDeferred<List<MangaPage>>) = Unit
|
||||||
|
}
|
||||||
@@ -14,11 +14,11 @@ abstract class MangaDao {
|
|||||||
abstract suspend fun find(id: Long): MangaWithTags?
|
abstract suspend fun find(id: Long): MangaWithTags?
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM manga WHERE title LIKE :query OR alt_title LIKE :query LIMIT :limit")
|
@Query("SELECT * FROM manga WHERE (title LIKE :query OR alt_title LIKE :query) AND manga_id IN (SELECT manga_id FROM favourites UNION SELECT manga_id FROM history) LIMIT :limit")
|
||||||
abstract suspend fun searchByTitle(query: String, limit: Int): List<MangaWithTags>
|
abstract suspend fun searchByTitle(query: String, limit: Int): List<MangaWithTags>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM manga WHERE (title LIKE :query OR alt_title LIKE :query) AND source = :source LIMIT :limit")
|
@Query("SELECT * FROM manga WHERE (title LIKE :query OR alt_title LIKE :query) AND source = :source AND manga_id IN (SELECT manga_id FROM favourites UNION SELECT manga_id FROM history) LIMIT :limit")
|
||||||
abstract suspend fun searchByTitle(query: String, source: String, limit: Int): List<MangaWithTags>
|
abstract suspend fun searchByTitle(query: String, source: String, limit: Int): List<MangaWithTags>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
@@ -47,4 +47,4 @@ abstract class MangaDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions.resolve
|
package org.koitharu.kotatsu.core.exceptions.resolve
|
||||||
|
|
||||||
import android.util.ArrayMap
|
|
||||||
import androidx.activity.result.ActivityResultCallback
|
import androidx.activity.result.ActivityResultCallback
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.collection.ArrayMap
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import 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
|
||||||
@@ -20,6 +17,9 @@ 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?,
|
||||||
@@ -49,6 +49,7 @@ class ExceptionResolver private constructor(
|
|||||||
openInBrowser(e.url)
|
openInBrowser(e.url)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
package org.koitharu.kotatsu.core.network
|
package org.koitharu.kotatsu.core.network.cookies
|
||||||
|
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import javax.inject.Inject
|
import androidx.annotation.WorkerThread
|
||||||
import javax.inject.Singleton
|
import okhttp3.Cookie
|
||||||
|
import okhttp3.HttpUrl
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
import okhttp3.Cookie
|
|
||||||
import okhttp3.CookieJar
|
|
||||||
import okhttp3.HttpUrl
|
|
||||||
|
|
||||||
@Singleton
|
class AndroidCookieJar : MutableCookieJar {
|
||||||
class AndroidCookieJar @Inject constructor() : CookieJar {
|
|
||||||
|
|
||||||
private val cookieManager = CookieManager.getInstance()
|
private val cookieManager = CookieManager.getInstance()
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
override fun loadForRequest(url: HttpUrl): List<Cookie> {
|
override fun loadForRequest(url: HttpUrl): List<Cookie> {
|
||||||
val rawCookie = cookieManager.getCookie(url.toString()) ?: return emptyList()
|
val rawCookie = cookieManager.getCookie(url.toString()) ?: return emptyList()
|
||||||
return rawCookie.split(';').mapNotNull {
|
return rawCookie.split(';').mapNotNull {
|
||||||
@@ -21,6 +19,7 @@ class AndroidCookieJar @Inject constructor() : CookieJar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||||
if (cookies.isEmpty()) {
|
if (cookies.isEmpty()) {
|
||||||
return
|
return
|
||||||
@@ -31,7 +30,7 @@ class AndroidCookieJar @Inject constructor() : CookieJar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun clear() = suspendCoroutine<Boolean> { continuation ->
|
override suspend fun clear() = suspendCoroutine<Boolean> { continuation ->
|
||||||
cookieManager.removeAllCookies(continuation::resume)
|
cookieManager.removeAllCookies(continuation::resume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network.cookies
|
||||||
|
|
||||||
|
import android.util.Base64
|
||||||
|
import okhttp3.Cookie
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.ObjectInputStream
|
||||||
|
import java.io.ObjectOutputStream
|
||||||
|
|
||||||
|
|
||||||
|
class CookieWrapper(
|
||||||
|
val cookie: Cookie,
|
||||||
|
) {
|
||||||
|
|
||||||
|
constructor(encodedString: String) : this(
|
||||||
|
ObjectInputStream(ByteArrayInputStream(Base64.decode(encodedString, Base64.NO_WRAP))).use {
|
||||||
|
val name = it.readUTF()
|
||||||
|
val value = it.readUTF()
|
||||||
|
val expiresAt = it.readLong()
|
||||||
|
val domain = it.readUTF()
|
||||||
|
val path = it.readUTF()
|
||||||
|
val secure = it.readBoolean()
|
||||||
|
val httpOnly = it.readBoolean()
|
||||||
|
val persistent = it.readBoolean()
|
||||||
|
val hostOnly = it.readBoolean()
|
||||||
|
Cookie.Builder().also { c ->
|
||||||
|
c.name(name)
|
||||||
|
c.value(value)
|
||||||
|
if (persistent) {
|
||||||
|
c.expiresAt(expiresAt)
|
||||||
|
}
|
||||||
|
if (hostOnly) {
|
||||||
|
c.hostOnlyDomain(domain)
|
||||||
|
} else {
|
||||||
|
c.domain(domain)
|
||||||
|
}
|
||||||
|
c.path(path)
|
||||||
|
if (secure) {
|
||||||
|
c.secure()
|
||||||
|
}
|
||||||
|
if (httpOnly) {
|
||||||
|
c.httpOnly()
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
fun encode(): String {
|
||||||
|
val output = ByteArrayOutputStream()
|
||||||
|
ObjectOutputStream(output).use {
|
||||||
|
it.writeUTF(cookie.name)
|
||||||
|
it.writeUTF(cookie.value)
|
||||||
|
it.writeLong(cookie.expiresAt)
|
||||||
|
it.writeUTF(cookie.domain)
|
||||||
|
it.writeUTF(cookie.path)
|
||||||
|
it.writeBoolean(cookie.secure)
|
||||||
|
it.writeBoolean(cookie.httpOnly)
|
||||||
|
it.writeBoolean(cookie.persistent)
|
||||||
|
it.writeBoolean(cookie.hostOnly)
|
||||||
|
}
|
||||||
|
return Base64.encodeToString(output.toByteArray(), Base64.NO_WRAP)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isExpired() = cookie.expiresAt < System.currentTimeMillis()
|
||||||
|
|
||||||
|
fun key(): String {
|
||||||
|
return (if (cookie.secure) "https" else "http") + "://" + cookie.domain + cookie.path + "|" + cookie.name
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as CookieWrapper
|
||||||
|
|
||||||
|
if (cookie != other.cookie) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return cookie.hashCode()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network.cookies
|
||||||
|
|
||||||
|
import androidx.annotation.WorkerThread
|
||||||
|
import okhttp3.Cookie
|
||||||
|
import okhttp3.CookieJar
|
||||||
|
import okhttp3.HttpUrl
|
||||||
|
|
||||||
|
interface MutableCookieJar : CookieJar {
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
override fun loadForRequest(url: HttpUrl): List<Cookie>
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>)
|
||||||
|
|
||||||
|
suspend fun clear(): Boolean
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network.cookies
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.annotation.WorkerThread
|
||||||
|
import androidx.collection.ArrayMap
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import okhttp3.Cookie
|
||||||
|
import okhttp3.HttpUrl
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
|
private const val PREFS_NAME = "cookies"
|
||||||
|
|
||||||
|
class PreferencesCookieJar(
|
||||||
|
context: Context,
|
||||||
|
) : MutableCookieJar {
|
||||||
|
|
||||||
|
private val cache = ArrayMap<String, CookieWrapper>()
|
||||||
|
private val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
|
private var isLoaded = false
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
override fun loadForRequest(url: HttpUrl): List<Cookie> {
|
||||||
|
loadPersistent()
|
||||||
|
val expired = HashSet<String>()
|
||||||
|
val result = ArrayList<Cookie>()
|
||||||
|
for ((key, cookie) in cache) {
|
||||||
|
if (cookie.isExpired()) {
|
||||||
|
expired += key
|
||||||
|
} else if (cookie.cookie.matches(url)) {
|
||||||
|
result += cookie.cookie
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (expired.isNotEmpty()) {
|
||||||
|
cache.removeAll(expired)
|
||||||
|
removePersistent(expired)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||||
|
val wrapped = cookies.map { CookieWrapper(it) }
|
||||||
|
prefs.edit(commit = true) {
|
||||||
|
for (cookie in wrapped) {
|
||||||
|
val key = cookie.key()
|
||||||
|
cache[key] = cookie
|
||||||
|
if (cookie.cookie.persistent) {
|
||||||
|
putString(key, cookie.encode())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun clear(): Boolean {
|
||||||
|
cache.clear()
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
prefs.edit(commit = true) { clear() }
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
private fun loadPersistent() {
|
||||||
|
if (!isLoaded) {
|
||||||
|
val map = prefs.all
|
||||||
|
cache.ensureCapacity(map.size)
|
||||||
|
for ((k, v) in map) {
|
||||||
|
val cookie = try {
|
||||||
|
CookieWrapper(v as String)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cache[k] = cookie
|
||||||
|
}
|
||||||
|
isLoaded = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun removePersistent(keys: Collection<String>) {
|
||||||
|
prefs.edit(commit = true) {
|
||||||
|
for (key in keys) {
|
||||||
|
remove(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package org.koitharu.kotatsu.core.os
|
||||||
|
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.ConnectivityManager.NetworkCallback
|
||||||
|
import android.net.Network
|
||||||
|
import android.net.NetworkRequest
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import org.koitharu.kotatsu.utils.MediatorStateFlow
|
||||||
|
import org.koitharu.kotatsu.utils.ext.isNetworkAvailable
|
||||||
|
|
||||||
|
class NetworkState(
|
||||||
|
private val connectivityManager: ConnectivityManager,
|
||||||
|
) : MediatorStateFlow<Boolean>(connectivityManager.isNetworkAvailable) {
|
||||||
|
|
||||||
|
private val callback = NetworkCallbackImpl()
|
||||||
|
|
||||||
|
override fun onActive() {
|
||||||
|
invalidate()
|
||||||
|
val request = NetworkRequest.Builder().build()
|
||||||
|
connectivityManager.registerNetworkCallback(request, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onInactive() {
|
||||||
|
connectivityManager.unregisterNetworkCallback(callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun awaitForConnection() {
|
||||||
|
if (value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
first { it }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun invalidate() {
|
||||||
|
publishValue(connectivityManager.isNetworkAvailable)
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class NetworkCallbackImpl : NetworkCallback() {
|
||||||
|
|
||||||
|
override fun onAvailable(network: Network) = invalidate()
|
||||||
|
|
||||||
|
override fun onLost(network: Network) = invalidate()
|
||||||
|
|
||||||
|
override fun onUnavailable() = invalidate()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.os
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.net.ConnectivityManager.NetworkCallback
|
|
||||||
import android.net.Network
|
|
||||||
import android.net.NetworkRequest
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import kotlinx.coroutines.channels.ProducerScope
|
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
|
||||||
import kotlinx.coroutines.channels.onSuccess
|
|
||||||
import kotlinx.coroutines.channels.trySendBlocking
|
|
||||||
import kotlinx.coroutines.flow.FlowCollector
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.flow.callbackFlow
|
|
||||||
import org.koitharu.kotatsu.utils.ext.connectivityManager
|
|
||||||
import org.koitharu.kotatsu.utils.ext.isNetworkAvailable
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
class NetworkStateObserver @Inject constructor(
|
|
||||||
@ApplicationContext context: Context,
|
|
||||||
) : StateFlow<Boolean> {
|
|
||||||
|
|
||||||
private val connectivityManager = context.connectivityManager
|
|
||||||
|
|
||||||
override val replayCache: List<Boolean>
|
|
||||||
get() = listOf(value)
|
|
||||||
|
|
||||||
override val value: Boolean
|
|
||||||
get() = connectivityManager.isNetworkAvailable
|
|
||||||
|
|
||||||
override suspend fun collect(collector: FlowCollector<Boolean>): Nothing {
|
|
||||||
collector.emit(value)
|
|
||||||
while (true) {
|
|
||||||
observeImpl().collect(collector)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun observeImpl() = callbackFlow<Boolean> {
|
|
||||||
val request = NetworkRequest.Builder().build()
|
|
||||||
val callback = FlowNetworkCallback(this)
|
|
||||||
connectivityManager.registerNetworkCallback(request, callback)
|
|
||||||
awaitClose {
|
|
||||||
connectivityManager.unregisterNetworkCallback(callback)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private inner class FlowNetworkCallback(
|
|
||||||
private val producerScope: ProducerScope<Boolean>,
|
|
||||||
) : NetworkCallback() {
|
|
||||||
|
|
||||||
private var prevValue = value
|
|
||||||
|
|
||||||
override fun onAvailable(network: Network) = update()
|
|
||||||
|
|
||||||
override fun onLost(network: Network) = update()
|
|
||||||
|
|
||||||
override fun onUnavailable() = update()
|
|
||||||
|
|
||||||
private fun update() {
|
|
||||||
val newValue = connectivityManager.isNetworkAvailable
|
|
||||||
if (newValue != prevValue) {
|
|
||||||
producerScope.trySendBlocking(newValue).onSuccess {
|
|
||||||
prevValue = newValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,25 +6,25 @@ import android.util.Base64
|
|||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import androidx.core.os.LocaleListCompat
|
import androidx.core.os.LocaleListCompat
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.parsers.config.MangaSourceConfig
|
import org.koitharu.kotatsu.parsers.config.MangaSourceConfig
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.utils.ext.toList
|
import org.koitharu.kotatsu.utils.ext.toList
|
||||||
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class MangaLoaderContextImpl @Inject constructor(
|
class MangaLoaderContextImpl @Inject constructor(
|
||||||
override val httpClient: OkHttpClient,
|
override val httpClient: OkHttpClient,
|
||||||
override val cookieJar: AndroidCookieJar,
|
override val cookieJar: MutableCookieJar,
|
||||||
@ApplicationContext private val androidContext: Context,
|
@ApplicationContext private val androidContext: Context,
|
||||||
) : MangaLoaderContext() {
|
) : MangaLoaderContext() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
import java.util.*
|
import java.util.EnumMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
|
||||||
|
|
||||||
interface MangaRepository {
|
interface MangaRepository {
|
||||||
|
|
||||||
@@ -31,6 +37,7 @@ interface MangaRepository {
|
|||||||
class Factory @Inject constructor(
|
class Factory @Inject constructor(
|
||||||
private val localMangaRepository: LocalMangaRepository,
|
private val localMangaRepository: LocalMangaRepository,
|
||||||
private val loaderContext: MangaLoaderContext,
|
private val loaderContext: MangaLoaderContext,
|
||||||
|
private val contentCache: ContentCache,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val cache = EnumMap<MangaSource, WeakReference<RemoteMangaRepository>>(MangaSource::class.java)
|
private val cache = EnumMap<MangaSource, WeakReference<RemoteMangaRepository>>(MangaSource::class.java)
|
||||||
@@ -42,7 +49,7 @@ interface MangaRepository {
|
|||||||
cache[source]?.get()?.let { return it }
|
cache[source]?.get()?.let { return it }
|
||||||
return synchronized(cache) {
|
return synchronized(cache) {
|
||||||
cache[source]?.get()?.let { return it }
|
cache[source]?.get()?.let { return it }
|
||||||
val repository = RemoteMangaRepository(MangaParser(source, loaderContext))
|
val repository = RemoteMangaRepository(MangaParser(source, loaderContext), contentCache)
|
||||||
cache[source] = WeakReference(repository)
|
cache[source] = WeakReference(repository)
|
||||||
repository
|
repository
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,28 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.async
|
||||||
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.core.cache.SafeDeferred
|
||||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||||
import org.koitharu.kotatsu.parsers.MangaParser
|
import org.koitharu.kotatsu.parsers.MangaParser
|
||||||
import org.koitharu.kotatsu.parsers.MangaParserAuthProvider
|
import org.koitharu.kotatsu.parsers.MangaParserAuthProvider
|
||||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
import org.koitharu.kotatsu.parsers.model.Favicons
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
class RemoteMangaRepository(private val parser: MangaParser) : MangaRepository {
|
class RemoteMangaRepository(
|
||||||
|
private val parser: MangaParser,
|
||||||
|
private val cache: ContentCache,
|
||||||
|
) : MangaRepository {
|
||||||
|
|
||||||
override val source: MangaSource
|
override val source: MangaSource
|
||||||
get() = parser.source
|
get() = parser.source
|
||||||
@@ -28,9 +44,23 @@ class RemoteMangaRepository(private val parser: MangaParser) : MangaRepository {
|
|||||||
return parser.getList(offset, tags, sortOrder)
|
return parser.getList(offset, tags, sortOrder)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga = parser.getDetails(manga)
|
override suspend fun getDetails(manga: Manga): Manga {
|
||||||
|
cache.getDetails(source, manga.url)?.let { return it }
|
||||||
|
val details = asyncSafe {
|
||||||
|
parser.getDetails(manga)
|
||||||
|
}
|
||||||
|
cache.putDetails(source, manga.url, details)
|
||||||
|
return details.await()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> = parser.getPages(chapter)
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
||||||
|
cache.getPages(source, chapter.url)?.let { return it }
|
||||||
|
val pages = asyncSafe {
|
||||||
|
parser.getPages(chapter)
|
||||||
|
}
|
||||||
|
cache.putPages(source, chapter.url, pages)
|
||||||
|
return pages.await()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getPageUrl(page: MangaPage): String = parser.getPageUrl(page)
|
override suspend fun getPageUrl(page: MangaPage): String = parser.getPageUrl(page)
|
||||||
|
|
||||||
@@ -45,4 +75,10 @@ class RemoteMangaRepository(private val parser: MangaParser) : MangaRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getConfig() = parser.config as SourceSettings
|
private fun getConfig() = parser.config as SourceSettings
|
||||||
}
|
|
||||||
|
private fun <T> asyncSafe(block: suspend CoroutineScope.() -> T) = SafeDeferred(
|
||||||
|
processLifecycleScope.async(Dispatchers.Default) {
|
||||||
|
runCatchingCancellable { block() }
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.koitharu.kotatsu.core.prefs
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.net.ConnectivityManager
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
@@ -17,6 +16,7 @@ import org.koitharu.kotatsu.core.network.DoHProvider
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.shelf.domain.ShelfSection
|
import org.koitharu.kotatsu.shelf.domain.ShelfSection
|
||||||
|
import org.koitharu.kotatsu.utils.ext.connectivityManager
|
||||||
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
|
||||||
@@ -34,6 +34,7 @@ import javax.inject.Singleton
|
|||||||
class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||||
|
|
||||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
private val connectivityManager = context.connectivityManager
|
||||||
|
|
||||||
private val remoteSources = EnumSet.allOf(MangaSource::class.java).apply {
|
private val remoteSources = EnumSet.allOf(MangaSource::class.java).apply {
|
||||||
remove(MangaSource.LOCAL)
|
remove(MangaSource.LOCAL)
|
||||||
@@ -156,6 +157,11 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val isDynamicShortcutsEnabled: Boolean
|
val isDynamicShortcutsEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_SHORTCUTS, true)
|
get() = prefs.getBoolean(KEY_SHORTCUTS, true)
|
||||||
|
|
||||||
|
fun isContentPrefetchEnabled(): Boolean {
|
||||||
|
val policy = NetworkPolicy.from(prefs.getString(KEY_PREFETCH_CONTENT, null), NetworkPolicy.NEVER)
|
||||||
|
return policy.isNetworkAllowed(connectivityManager)
|
||||||
|
}
|
||||||
|
|
||||||
var sourcesOrder: List<String>
|
var sourcesOrder: List<String>
|
||||||
get() = prefs.getString(KEY_SOURCES_ORDER, null)
|
get() = prefs.getString(KEY_SOURCES_ORDER, null)
|
||||||
?.split('|')
|
?.split('|')
|
||||||
@@ -234,12 +240,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val isWebtoonZoomEnable: Boolean
|
val isWebtoonZoomEnable: Boolean
|
||||||
get() = prefs.getBoolean(KEY_WEBTOON_ZOOM, true)
|
get() = prefs.getBoolean(KEY_WEBTOON_ZOOM, true)
|
||||||
|
|
||||||
fun isPagesPreloadAllowed(cm: ConnectivityManager): Boolean {
|
fun isPagesPreloadEnabled(): Boolean {
|
||||||
return when (prefs.getString(KEY_PAGES_PRELOAD, null)?.toIntOrNull()) {
|
val policy = NetworkPolicy.from(prefs.getString(KEY_PAGES_PRELOAD, null), NetworkPolicy.NON_METERED)
|
||||||
NETWORK_ALWAYS -> true
|
return policy.isNetworkAllowed(connectivityManager)
|
||||||
NETWORK_NEVER -> false
|
|
||||||
else -> cm.isActiveNetworkMetered
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDateFormat(format: String = prefs.getString(KEY_DATE_FORMAT, "").orEmpty()): DateFormat =
|
fun getDateFormat(format: String = prefs.getString(KEY_DATE_FORMAT, "").orEmpty()): DateFormat =
|
||||||
@@ -293,7 +296,6 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val TRACK_FAVOURITES = "favourites"
|
const val TRACK_FAVOURITES = "favourites"
|
||||||
|
|
||||||
const val KEY_LIST_MODE = "list_mode_2"
|
const val KEY_LIST_MODE = "list_mode_2"
|
||||||
const val KEY_APP_SECTION = "app_section_2"
|
|
||||||
const val KEY_THEME = "theme"
|
const val KEY_THEME = "theme"
|
||||||
const val KEY_DYNAMIC_THEME = "dynamic_theme"
|
const val KEY_DYNAMIC_THEME = "dynamic_theme"
|
||||||
const val KEY_THEME_AMOLED = "amoled_theme"
|
const val KEY_THEME_AMOLED = "amoled_theme"
|
||||||
@@ -355,13 +357,10 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val KEY_LOCAL_LIST_ORDER = "local_order"
|
const val KEY_LOCAL_LIST_ORDER = "local_order"
|
||||||
const val KEY_WEBTOON_ZOOM = "webtoon_zoom"
|
const val KEY_WEBTOON_ZOOM = "webtoon_zoom"
|
||||||
const val KEY_SHELF_SECTIONS = "shelf_sections_2"
|
const val KEY_SHELF_SECTIONS = "shelf_sections_2"
|
||||||
|
const val KEY_PREFETCH_CONTENT = "prefetch_content"
|
||||||
|
|
||||||
// About
|
// About
|
||||||
const val KEY_APP_UPDATE = "app_update"
|
const val KEY_APP_UPDATE = "app_update"
|
||||||
const val KEY_APP_TRANSLATION = "about_app_translation"
|
const val KEY_APP_TRANSLATION = "about_app_translation"
|
||||||
|
|
||||||
private const val NETWORK_NEVER = 0
|
|
||||||
private const val NETWORK_ALWAYS = 1
|
|
||||||
private const val NETWORK_NON_METERED = 2
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
|
||||||
|
enum class NetworkPolicy(
|
||||||
|
private val key: Int,
|
||||||
|
) {
|
||||||
|
|
||||||
|
NEVER(0),
|
||||||
|
ALWAYS(1),
|
||||||
|
NON_METERED(2);
|
||||||
|
|
||||||
|
fun isNetworkAllowed(cm: ConnectivityManager) = when (this) {
|
||||||
|
NEVER -> false
|
||||||
|
ALWAYS -> true
|
||||||
|
NON_METERED -> !cm.isActiveNetworkMetered
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun from(key: String?, default: NetworkPolicy): NetworkPolicy {
|
||||||
|
val intKey = key?.toIntOrNull() ?: return default
|
||||||
|
return enumValues<NetworkPolicy>().find { it.key == intKey } ?: default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,10 +52,13 @@ class ZipOutput(
|
|||||||
return if (entryNames.add(entry.name)) {
|
return if (entryNames.add(entry.name)) {
|
||||||
val zipEntry = ZipEntry(entry.name)
|
val zipEntry = ZipEntry(entry.name)
|
||||||
output.putNextEntry(zipEntry)
|
output.putNextEntry(zipEntry)
|
||||||
other.getInputStream(entry).use { input ->
|
try {
|
||||||
input.copyTo(output)
|
other.getInputStream(entry).use { input ->
|
||||||
|
input.copyTo(output)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
output.closeEntry()
|
||||||
}
|
}
|
||||||
output.closeEntry()
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
@@ -115,4 +118,4 @@ class ZipOutput(
|
|||||||
closeEntry()
|
closeEntry()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package org.koitharu.kotatsu.details.service
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import dagger.hilt.android.EntryPointAccessors
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
import org.koitharu.kotatsu.base.ui.CoroutineIntentService
|
||||||
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaChapters
|
||||||
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class MangaPrefetchService : CoroutineIntentService() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mangaRepositoryFactory: MangaRepository.Factory
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var cache: ContentCache
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var historyRepository: HistoryRepository
|
||||||
|
|
||||||
|
override suspend fun processIntent(startId: Int, intent: Intent) {
|
||||||
|
when (intent.action) {
|
||||||
|
ACTION_PREFETCH_DETAILS -> prefetchDetails(
|
||||||
|
manga = intent.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga ?: return,
|
||||||
|
)
|
||||||
|
|
||||||
|
ACTION_PREFETCH_PAGES -> prefetchPages(
|
||||||
|
chapter = intent.getParcelableExtraCompat<ParcelableMangaChapters>(EXTRA_CHAPTER)
|
||||||
|
?.chapters?.singleOrNull() ?: return,
|
||||||
|
)
|
||||||
|
|
||||||
|
ACTION_PREFETCH_LAST -> prefetchLast()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(startId: Int, error: Throwable) = Unit
|
||||||
|
|
||||||
|
private suspend fun prefetchDetails(manga: Manga) = coroutineScope {
|
||||||
|
val source = mangaRepositoryFactory.create(manga.source)
|
||||||
|
runCatchingCancellable { source.getDetails(manga) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun prefetchPages(chapter: MangaChapter) {
|
||||||
|
val source = mangaRepositoryFactory.create(chapter.source)
|
||||||
|
runCatchingCancellable { source.getPages(chapter) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun prefetchLast() {
|
||||||
|
val last = historyRepository.getLastOrNull() ?: return
|
||||||
|
if (last.source == MangaSource.LOCAL) return
|
||||||
|
val repo = mangaRepositoryFactory.create(last.source)
|
||||||
|
val details = runCatchingCancellable { repo.getDetails(last) }.getOrNull() ?: return
|
||||||
|
val chapters = details.chapters
|
||||||
|
if (chapters.isNullOrEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val history = historyRepository.getOne(last)
|
||||||
|
val chapter = if (history == null) {
|
||||||
|
chapters.firstOrNull()
|
||||||
|
} else {
|
||||||
|
chapters.find { x -> x.id == history.chapterId } ?: chapters.firstOrNull()
|
||||||
|
} ?: return
|
||||||
|
runCatchingCancellable { repo.getPages(chapter) }
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private const val EXTRA_MANGA = "manga"
|
||||||
|
private const val EXTRA_CHAPTER = "manga"
|
||||||
|
private const val ACTION_PREFETCH_DETAILS = "details"
|
||||||
|
private const val ACTION_PREFETCH_PAGES = "pages"
|
||||||
|
private const val ACTION_PREFETCH_LAST = "last"
|
||||||
|
|
||||||
|
fun prefetchDetails(context: Context, manga: Manga) {
|
||||||
|
if (!isPrefetchAvailable(context, manga.source)) return
|
||||||
|
val intent = Intent(context, MangaPrefetchService::class.java)
|
||||||
|
intent.action = ACTION_PREFETCH_DETAILS
|
||||||
|
intent.putExtra(EXTRA_MANGA, ParcelableManga(manga, withChapters = false))
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun prefetchPages(context: Context, chapter: MangaChapter) {
|
||||||
|
if (!isPrefetchAvailable(context, chapter.source)) return
|
||||||
|
val intent = Intent(context, MangaPrefetchService::class.java)
|
||||||
|
intent.action = ACTION_PREFETCH_PAGES
|
||||||
|
intent.putExtra(EXTRA_CHAPTER, ParcelableMangaChapters(listOf(chapter)))
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun prefetchLast(context: Context) {
|
||||||
|
if (!isPrefetchAvailable(context, null)) return
|
||||||
|
val intent = Intent(context, MangaPrefetchService::class.java)
|
||||||
|
intent.action = ACTION_PREFETCH_LAST
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isPrefetchAvailable(context: Context, source: MangaSource?): Boolean {
|
||||||
|
if (source == MangaSource.LOCAL) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val entryPoint = EntryPointAccessors.fromApplication(context, PrefetchCompanionEntryPoint::class.java)
|
||||||
|
return entryPoint.contentCache.isCachingEnabled && entryPoint.settings.isContentPrefetchEnabled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.koitharu.kotatsu.details.service
|
||||||
|
|
||||||
|
import dagger.hilt.EntryPoint
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
|
||||||
|
@EntryPoint
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
interface PrefetchCompanionEntryPoint {
|
||||||
|
val settings: AppSettings
|
||||||
|
val contentCache: ContentCache
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import androidx.core.graphics.Insets
|
|||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.snackbar.BaseTransientBottomBar
|
import com.google.android.material.snackbar.BaseTransientBottomBar
|
||||||
@@ -33,6 +34,8 @@ import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
|||||||
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
||||||
import org.koitharu.kotatsu.core.ui.MangaErrorDialog
|
import org.koitharu.kotatsu.core.ui.MangaErrorDialog
|
||||||
import org.koitharu.kotatsu.databinding.ActivityDetailsBinding
|
import org.koitharu.kotatsu.databinding.ActivityDetailsBinding
|
||||||
|
import org.koitharu.kotatsu.details.service.MangaPrefetchService
|
||||||
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
||||||
import org.koitharu.kotatsu.details.ui.model.HistoryInfo
|
import org.koitharu.kotatsu.details.ui.model.HistoryInfo
|
||||||
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
||||||
import org.koitharu.kotatsu.main.ui.owners.NoModalBottomSheetOwner
|
import org.koitharu.kotatsu.main.ui.owners.NoModalBottomSheetOwner
|
||||||
@@ -120,6 +123,7 @@ class DetailsActivity :
|
|||||||
viewModel.branches.observe(this) {
|
viewModel.branches.observe(this) {
|
||||||
binding.buttonDropdown.isVisible = it.size > 1
|
binding.buttonDropdown.isVisible = it.size > 1
|
||||||
}
|
}
|
||||||
|
viewModel.chapters.observe(this, PrefetchObserver(this))
|
||||||
|
|
||||||
registerReceiver(downloadReceiver, IntentFilter(DownloadService.ACTION_DOWNLOAD_COMPLETE))
|
registerReceiver(downloadReceiver, IntentFilter(DownloadService.ACTION_DOWNLOAD_COMPLETE))
|
||||||
addMenuProvider(
|
addMenuProvider(
|
||||||
@@ -228,18 +232,18 @@ class DetailsActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onHistoryChanged(info: HistoryInfo?) {
|
private fun onHistoryChanged(info: HistoryInfo) {
|
||||||
with(binding.buttonRead) {
|
with(binding.buttonRead) {
|
||||||
if (info?.history != null) {
|
if (info.history != null) {
|
||||||
setText(R.string._continue)
|
setText(R.string._continue)
|
||||||
setIconResource(R.drawable.ic_play)
|
setIconResource(if (info.isIncognitoMode) R.drawable.ic_incognito else R.drawable.ic_play)
|
||||||
} else {
|
} else {
|
||||||
setText(R.string.read)
|
setText(R.string.read)
|
||||||
setIconResource(R.drawable.ic_read)
|
setIconResource(if (info.isIncognitoMode) R.drawable.ic_incognito else R.drawable.ic_play)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val text = when {
|
val text = when {
|
||||||
info == null -> getString(R.string.loading_)
|
!info.isValid -> getString(R.string.loading_)
|
||||||
info.currentChapter >= 0 -> getString(R.string.chapter_d_of_d, info.currentChapter + 1, info.totalChapters)
|
info.currentChapter >= 0 -> getString(R.string.chapter_d_of_d, info.currentChapter + 1, info.totalChapters)
|
||||||
info.totalChapters == 0 -> getString(R.string.no_chapters)
|
info.totalChapters == 0 -> getString(R.string.no_chapters)
|
||||||
else -> resources.getQuantityString(R.plurals.chapters, info.totalChapters, info.totalChapters)
|
else -> resources.getQuantityString(R.plurals.chapters, info.totalChapters, info.totalChapters)
|
||||||
@@ -325,6 +329,24 @@ class DetailsActivity :
|
|||||||
return sb
|
return sb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class PrefetchObserver(
|
||||||
|
private val context: Context,
|
||||||
|
) : Observer<List<ChapterListItem>> {
|
||||||
|
|
||||||
|
private var isCalled = false
|
||||||
|
|
||||||
|
override fun onChanged(t: List<ChapterListItem>?) {
|
||||||
|
if (t.isNullOrEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!isCalled) {
|
||||||
|
isCalled = true
|
||||||
|
val item = t.find { it.hasFlag(ChapterListItem.FLAG_CURRENT) } ?: t.first()
|
||||||
|
MangaPrefetchService.prefetchPages(context, item.chapter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newIntent(context: Context, manga: Manga): Intent {
|
fun newIntent(context: Context, manga: Manga): Intent {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import coil.request.ImageRequest
|
|||||||
import coil.util.CoilUtils
|
import coil.util.CoilUtils
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BaseFragment
|
import org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
@@ -27,9 +26,9 @@ import org.koitharu.kotatsu.base.ui.list.decor.SpacingItemDecoration
|
|||||||
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.bookmarks.ui.adapter.BookmarksAdapter
|
import org.koitharu.kotatsu.bookmarks.ui.adapter.BookmarksAdapter
|
||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
|
||||||
import org.koitharu.kotatsu.databinding.FragmentDetailsBinding
|
import org.koitharu.kotatsu.databinding.FragmentDetailsBinding
|
||||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
||||||
|
import org.koitharu.kotatsu.details.ui.model.HistoryInfo
|
||||||
import org.koitharu.kotatsu.details.ui.scrobbling.ScrobblingItemDecoration
|
import org.koitharu.kotatsu.details.ui.scrobbling.ScrobblingItemDecoration
|
||||||
import org.koitharu.kotatsu.details.ui.scrobbling.ScrollingInfoAdapter
|
import org.koitharu.kotatsu.details.ui.scrobbling.ScrollingInfoAdapter
|
||||||
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
||||||
@@ -45,8 +44,20 @@ import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingInfo
|
|||||||
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
||||||
import org.koitharu.kotatsu.search.ui.SearchActivity
|
import org.koitharu.kotatsu.search.ui.SearchActivity
|
||||||
import org.koitharu.kotatsu.utils.FileSize
|
import org.koitharu.kotatsu.utils.FileSize
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.computeSize
|
||||||
|
import org.koitharu.kotatsu.utils.ext.crossfade
|
||||||
|
import org.koitharu.kotatsu.utils.ext.drawableTop
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.ifNullOrEmpty
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureHeight
|
||||||
|
import org.koitharu.kotatsu.utils.ext.referer
|
||||||
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
||||||
|
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||||
|
import org.koitharu.kotatsu.utils.ext.toFileOrNull
|
||||||
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||||
import org.koitharu.kotatsu.utils.image.CoverSizeResolver
|
import org.koitharu.kotatsu.utils.image.CoverSizeResolver
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DetailsFragment :
|
class DetailsFragment :
|
||||||
@@ -75,7 +86,7 @@ class DetailsFragment :
|
|||||||
binding.chipsTags.onChipClickListener = this
|
binding.chipsTags.onChipClickListener = this
|
||||||
viewModel.manga.observe(viewLifecycleOwner, ::onMangaUpdated)
|
viewModel.manga.observe(viewLifecycleOwner, ::onMangaUpdated)
|
||||||
viewModel.isLoading.observe(viewLifecycleOwner, ::onLoadingStateChanged)
|
viewModel.isLoading.observe(viewLifecycleOwner, ::onLoadingStateChanged)
|
||||||
viewModel.readingHistory.observe(viewLifecycleOwner, ::onHistoryChanged)
|
viewModel.historyInfo.observe(viewLifecycleOwner, ::onHistoryChanged)
|
||||||
viewModel.bookmarks.observe(viewLifecycleOwner, ::onBookmarksChanged)
|
viewModel.bookmarks.observe(viewLifecycleOwner, ::onBookmarksChanged)
|
||||||
viewModel.scrobblingInfo.observe(viewLifecycleOwner, ::onScrobblingInfoChanged)
|
viewModel.scrobblingInfo.observe(viewLifecycleOwner, ::onScrobblingInfoChanged)
|
||||||
viewModel.description.observe(viewLifecycleOwner, ::onDescriptionChanged)
|
viewModel.description.observe(viewLifecycleOwner, ::onDescriptionChanged)
|
||||||
@@ -123,12 +134,14 @@ class DetailsFragment :
|
|||||||
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_state_finished)
|
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_state_finished)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MangaState.ONGOING -> {
|
MangaState.ONGOING -> {
|
||||||
infoLayout.textViewState.apply {
|
infoLayout.textViewState.apply {
|
||||||
textAndVisible = resources.getString(R.string.state_ongoing)
|
textAndVisible = resources.getString(R.string.state_ongoing)
|
||||||
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_state_ongoing)
|
drawableTop = ContextCompat.getDrawable(context, R.drawable.ic_state_ongoing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> infoLayout.textViewState.isVisible = false
|
else -> infoLayout.textViewState.isVisible = false
|
||||||
}
|
}
|
||||||
if (manga.source == MangaSource.LOCAL) {
|
if (manga.source == MangaSource.LOCAL) {
|
||||||
@@ -178,8 +191,8 @@ class DetailsFragment :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onHistoryChanged(history: MangaHistory?) {
|
private fun onHistoryChanged(history: HistoryInfo) {
|
||||||
binding.progressView.setPercent(history?.percent ?: PROGRESS_NONE, animate = true)
|
binding.progressView.setPercent(history.history?.percent ?: PROGRESS_NONE, animate = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onLoadingStateChanged(isLoading: Boolean) {
|
private fun onLoadingStateChanged(isLoading: Boolean) {
|
||||||
@@ -229,6 +242,7 @@ class DetailsFragment :
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.textView_source -> {
|
R.id.textView_source -> {
|
||||||
startActivity(
|
startActivity(
|
||||||
MangaListActivity.newIntent(
|
MangaListActivity.newIntent(
|
||||||
@@ -237,6 +251,7 @@ class DetailsFragment :
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.imageView_cover -> {
|
R.id.imageView_cover -> {
|
||||||
startActivity(
|
startActivity(
|
||||||
ImageActivity.newIntent(v.context, manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }),
|
ImageActivity.newIntent(v.context, manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }),
|
||||||
@@ -249,7 +264,7 @@ class DetailsFragment :
|
|||||||
override fun onLongClick(v: View): Boolean {
|
override fun onLongClick(v: View): Boolean {
|
||||||
when (v.id) {
|
when (v.id) {
|
||||||
R.id.button_read -> {
|
R.id.button_read -> {
|
||||||
if (viewModel.readingHistory.value == null) {
|
if (viewModel.historyInfo.value?.history == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val menu = PopupMenu(v.context, v)
|
val menu = PopupMenu(v.context, v)
|
||||||
@@ -271,12 +286,14 @@ class DetailsFragment :
|
|||||||
)
|
)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu.show()
|
menu.show()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,18 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import java.io.IOException
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||||
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.flow.transformLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.plus
|
import kotlinx.coroutines.plus
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
@@ -46,6 +54,7 @@ import org.koitharu.kotatsu.utils.asFlowLiveData
|
|||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class DetailsViewModel @AssistedInject constructor(
|
class DetailsViewModel @AssistedInject constructor(
|
||||||
@Assisted intent: MangaIntent,
|
@Assisted intent: MangaIntent,
|
||||||
@@ -80,8 +89,14 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
private val favourite = favouritesRepository.observeCategoriesIds(delegate.mangaId).map { it.isNotEmpty() }
|
private val favourite = favouritesRepository.observeCategoriesIds(delegate.mangaId).map { it.isNotEmpty() }
|
||||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, false)
|
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, false)
|
||||||
|
|
||||||
private val newChapters = trackingRepository.observeNewChaptersCount(delegate.mangaId)
|
private val newChapters = settings.observeAsFlow(AppSettings.KEY_TRACKER_ENABLED) { isTrackerEnabled }
|
||||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, 0)
|
.flatMapLatest { isEnabled ->
|
||||||
|
if (isEnabled) {
|
||||||
|
trackingRepository.observeNewChaptersCount(delegate.mangaId)
|
||||||
|
} else {
|
||||||
|
flowOf(0)
|
||||||
|
}
|
||||||
|
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, 0)
|
||||||
|
|
||||||
private val chaptersQuery = MutableStateFlow("")
|
private val chaptersQuery = MutableStateFlow("")
|
||||||
|
|
||||||
@@ -91,17 +106,18 @@ class DetailsViewModel @AssistedInject constructor(
|
|||||||
val manga = delegate.manga.filterNotNull().asLiveData(viewModelScope.coroutineContext)
|
val manga = delegate.manga.filterNotNull().asLiveData(viewModelScope.coroutineContext)
|
||||||
val favouriteCategories = favourite.asLiveData(viewModelScope.coroutineContext)
|
val favouriteCategories = favourite.asLiveData(viewModelScope.coroutineContext)
|
||||||
val newChaptersCount = newChapters.asLiveData(viewModelScope.coroutineContext)
|
val newChaptersCount = newChapters.asLiveData(viewModelScope.coroutineContext)
|
||||||
|
|
||||||
@Deprecated("")
|
|
||||||
val readingHistory = history.asLiveData(viewModelScope.coroutineContext)
|
|
||||||
val isChaptersReversed = chaptersReversed.asLiveData(viewModelScope.coroutineContext)
|
val isChaptersReversed = chaptersReversed.asLiveData(viewModelScope.coroutineContext)
|
||||||
|
|
||||||
val historyInfo = combine(
|
val historyInfo: LiveData<HistoryInfo> = combine(
|
||||||
delegate.manga,
|
delegate.manga,
|
||||||
history,
|
history,
|
||||||
) { m, h ->
|
historyRepository.observeShouldSkip(delegate.manga),
|
||||||
HistoryInfo(m, h)
|
) { m, h, im ->
|
||||||
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, null)
|
HistoryInfo(m, h, im)
|
||||||
|
}.asFlowLiveData(
|
||||||
|
context = viewModelScope.coroutineContext + Dispatchers.Default,
|
||||||
|
defaultValue = HistoryInfo(null, null, false),
|
||||||
|
)
|
||||||
|
|
||||||
val bookmarks = delegate.manga.flatMapLatest {
|
val bookmarks = delegate.manga.flatMapLatest {
|
||||||
if (it != null) bookmarksRepository.observeBookmarks(it) else flowOf(emptyList())
|
if (it != null) bookmarksRepository.observeBookmarks(it) else flowOf(emptyList())
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ class ChaptersAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSectionText(context: Context, position: Int): CharSequence {
|
override fun getSectionText(context: Context, position: Int): CharSequence? {
|
||||||
return items[position].chapter.number.toString()
|
val item = items.getOrNull(position) ?: return null
|
||||||
|
return item.chapter.number.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,12 @@ class HistoryInfo(
|
|||||||
val totalChapters: Int,
|
val totalChapters: Int,
|
||||||
val currentChapter: Int,
|
val currentChapter: Int,
|
||||||
val history: MangaHistory?,
|
val history: MangaHistory?,
|
||||||
|
val isIncognitoMode: Boolean,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
val isValid: Boolean
|
||||||
|
get() = totalChapters >= 0
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (javaClass != other?.javaClass) return false
|
if (javaClass != other?.javaClass) return false
|
||||||
@@ -18,6 +22,7 @@ class HistoryInfo(
|
|||||||
if (totalChapters != other.totalChapters) return false
|
if (totalChapters != other.totalChapters) return false
|
||||||
if (currentChapter != other.currentChapter) return false
|
if (currentChapter != other.currentChapter) return false
|
||||||
if (history != other.history) return false
|
if (history != other.history) return false
|
||||||
|
if (isIncognitoMode != other.isIncognitoMode) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -26,20 +31,21 @@ class HistoryInfo(
|
|||||||
var result = totalChapters
|
var result = totalChapters
|
||||||
result = 31 * result + currentChapter
|
result = 31 * result + currentChapter
|
||||||
result = 31 * result + (history?.hashCode() ?: 0)
|
result = 31 * result + (history?.hashCode() ?: 0)
|
||||||
|
result = 31 * result + isIncognitoMode.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
fun HistoryInfo(manga: Manga?, history: MangaHistory?, isIncognitoMode: Boolean): HistoryInfo {
|
||||||
fun HistoryInfo(manga: Manga?, history: MangaHistory?): HistoryInfo? {
|
val chapters = manga?.chapters
|
||||||
val chapters = manga?.chapters ?: return null
|
|
||||||
return HistoryInfo(
|
return HistoryInfo(
|
||||||
totalChapters = chapters.size,
|
totalChapters = chapters?.size ?: -1,
|
||||||
currentChapter = if (history != null) {
|
currentChapter = if (history != null && !chapters.isNullOrEmpty()) {
|
||||||
chapters.indexOfFirst { it.id == history.chapterId }
|
chapters.indexOfFirst { it.id == history.chapterId }
|
||||||
} else {
|
} else {
|
||||||
-1
|
-1
|
||||||
},
|
},
|
||||||
history = history,
|
history = history,
|
||||||
|
isIncognitoMode = isIncognitoMode,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import kotlinx.coroutines.NonCancellable
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runInterruptible
|
|
||||||
import kotlinx.coroutines.sync.Semaphore
|
import kotlinx.coroutines.sync.Semaphore
|
||||||
import kotlinx.coroutines.sync.withPermit
|
import kotlinx.coroutines.sync.withPermit
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -36,6 +35,7 @@ import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
|||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.util.await
|
import org.koitharu.kotatsu.parsers.util.await
|
||||||
|
import org.koitharu.kotatsu.utils.ext.copyToSuspending
|
||||||
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.referer
|
import org.koitharu.kotatsu.utils.ext.referer
|
||||||
@@ -219,10 +219,8 @@ class DownloadManager @AssistedInject constructor(
|
|||||||
val call = okHttp.newCall(request)
|
val call = okHttp.newCall(request)
|
||||||
val file = File(destination, tempFileName)
|
val file = File(destination, tempFileName)
|
||||||
val response = call.clone().await()
|
val response = call.clone().await()
|
||||||
runInterruptible(Dispatchers.IO) {
|
file.outputStream().use { out ->
|
||||||
file.outputStream().use { out ->
|
checkNotNull(response.body).byteStream().copyToSuspending(out)
|
||||||
checkNotNull(response.body).byteStream().copyTo(out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package org.koitharu.kotatsu.explore.ui
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.widget.PopupMenu
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
@@ -11,11 +13,12 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.domain.reverseAsync
|
||||||
import org.koitharu.kotatsu.base.ui.BaseFragment
|
import org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
||||||
import org.koitharu.kotatsu.bookmarks.ui.BookmarksActivity
|
import org.koitharu.kotatsu.bookmarks.ui.BookmarksActivity
|
||||||
import org.koitharu.kotatsu.databinding.FragmentExploreBinding
|
import org.koitharu.kotatsu.databinding.FragmentExploreBinding
|
||||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
@@ -31,6 +34,7 @@ import org.koitharu.kotatsu.search.ui.MangaListActivity
|
|||||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||||
import org.koitharu.kotatsu.suggestions.ui.SuggestionsActivity
|
import org.koitharu.kotatsu.suggestions.ui.SuggestionsActivity
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ExploreFragment :
|
class ExploreFragment :
|
||||||
@@ -67,6 +71,7 @@ class ExploreFragment :
|
|||||||
}
|
}
|
||||||
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
||||||
viewModel.onOpenManga.observe(viewLifecycleOwner, ::onOpenManga)
|
viewModel.onOpenManga.observe(viewLifecycleOwner, ::onOpenManga)
|
||||||
|
viewModel.onActionDone.observe(viewLifecycleOwner, ::onActionDone)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -95,6 +100,7 @@ class ExploreFragment :
|
|||||||
viewModel.openRandom()
|
viewModel.openRandom()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return
|
else -> return
|
||||||
}
|
}
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
@@ -105,6 +111,14 @@ class ExploreFragment :
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onItemLongClick(item: ExploreItem.Source, view: View): Boolean {
|
||||||
|
val menu = PopupMenu(view.context, view)
|
||||||
|
menu.inflate(R.menu.popup_source)
|
||||||
|
menu.setOnMenuItemClickListener(SourceMenuListener(item))
|
||||||
|
menu.show()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRetryClick(error: Throwable) = Unit
|
override fun onRetryClick(error: Throwable) = Unit
|
||||||
|
|
||||||
override fun onEmptyActionClick() = onManageClick(requireView())
|
override fun onEmptyActionClick() = onManageClick(requireView())
|
||||||
@@ -124,6 +138,37 @@ class ExploreFragment :
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun onActionDone(action: ReversibleAction) {
|
||||||
|
val handle = action.handle
|
||||||
|
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
||||||
|
val snackbar = Snackbar.make(binding.recyclerView, action.stringResId, length)
|
||||||
|
if (handle != null) {
|
||||||
|
snackbar.setAction(R.string.undo) { handle.reverseAsync() }
|
||||||
|
}
|
||||||
|
snackbar.anchorView = (activity as? BottomNavOwner)?.bottomNav
|
||||||
|
snackbar.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class SourceMenuListener(
|
||||||
|
private val sourceItem: ExploreItem.Source,
|
||||||
|
) : PopupMenu.OnMenuItemClickListener {
|
||||||
|
|
||||||
|
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||||
|
when (item.itemId) {
|
||||||
|
R.id.action_settings -> {
|
||||||
|
startActivity(SettingsActivity.newSourceSettingsIntent(requireContext(), sourceItem.source))
|
||||||
|
}
|
||||||
|
|
||||||
|
R.id.action_hide -> {
|
||||||
|
viewModel.hideSource(sourceItem.source)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newInstance() = ExploreFragment()
|
fun newInstance() = ExploreFragment()
|
||||||
|
|||||||
@@ -4,11 +4,17 @@ import androidx.lifecycle.LiveData
|
|||||||
import androidx.lifecycle.asFlow
|
import androidx.lifecycle.asFlow
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.onStart
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
||||||
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.explore.domain.ExploreRepository
|
import org.koitharu.kotatsu.explore.domain.ExploreRepository
|
||||||
import org.koitharu.kotatsu.explore.ui.model.ExploreItem
|
import org.koitharu.kotatsu.explore.ui.model.ExploreItem
|
||||||
@@ -16,6 +22,7 @@ import org.koitharu.kotatsu.parsers.model.Manga
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class ExploreViewModel @Inject constructor(
|
class ExploreViewModel @Inject constructor(
|
||||||
@@ -24,6 +31,7 @@ class ExploreViewModel @Inject constructor(
|
|||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
|
|
||||||
val onOpenManga = SingleLiveEvent<Manga>()
|
val onOpenManga = SingleLiveEvent<Manga>()
|
||||||
|
val onActionDone = SingleLiveEvent<ReversibleAction>()
|
||||||
|
|
||||||
val content: LiveData<List<ExploreItem>> = isLoading.asFlow().flatMapLatest { loading ->
|
val content: LiveData<List<ExploreItem>> = isLoading.asFlow().flatMapLatest { loading ->
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@@ -40,6 +48,16 @@ class ExploreViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hideSource(source: MangaSource) {
|
||||||
|
launchJob(Dispatchers.Default) {
|
||||||
|
settings.hiddenSources += source.name
|
||||||
|
val rollback = ReversibleHandle {
|
||||||
|
settings.hiddenSources -= source.name
|
||||||
|
}
|
||||||
|
onActionDone.postCall(ReversibleAction(R.string.source_disabled, rollback))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createContentFlow() = settings.observe()
|
private fun createContentFlow() = settings.observe()
|
||||||
.filter {
|
.filter {
|
||||||
it == AppSettings.KEY_SOURCES_HIDDEN ||
|
it == AppSettings.KEY_SOURCES_HIDDEN ||
|
||||||
|
|||||||
@@ -7,15 +7,16 @@ import android.view.View
|
|||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.appcompat.widget.PopupMenu
|
import androidx.appcompat.widget.PopupMenu
|
||||||
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.list.ListSelectionController
|
import org.koitharu.kotatsu.base.ui.list.ListSelectionController
|
||||||
import org.koitharu.kotatsu.core.ui.titleRes
|
import org.koitharu.kotatsu.core.ui.titleRes
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesActivity
|
import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesActivity
|
||||||
import org.koitharu.kotatsu.list.ui.MangaListFragment
|
import org.koitharu.kotatsu.list.ui.MangaListFragment
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.utils.ext.addMenuProvider
|
||||||
import org.koitharu.kotatsu.utils.ext.assistedViewModels
|
import org.koitharu.kotatsu.utils.ext.assistedViewModels
|
||||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class FavouritesListFragment : MangaListFragment(), PopupMenu.OnMenuItemClickListener {
|
class FavouritesListFragment : MangaListFragment(), PopupMenu.OnMenuItemClickListener {
|
||||||
@@ -23,9 +24,7 @@ class FavouritesListFragment : MangaListFragment(), PopupMenu.OnMenuItemClickLis
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var viewModelFactory: FavouritesListViewModel.Factory
|
lateinit var viewModelFactory: FavouritesListViewModel.Factory
|
||||||
|
|
||||||
override val viewModel by assistedViewModels<FavouritesListViewModel> {
|
override val viewModel by assistedViewModels { viewModelFactory.create(categoryId) }
|
||||||
viewModelFactory.create(categoryId)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val categoryId: Long
|
private val categoryId: Long
|
||||||
get() = arguments?.getLong(ARG_CATEGORY_ID) ?: NO_ID
|
get() = arguments?.getLong(ARG_CATEGORY_ID) ?: NO_ID
|
||||||
@@ -34,6 +33,9 @@ class FavouritesListFragment : MangaListFragment(), PopupMenu.OnMenuItemClickLis
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
if (viewModel.categoryId != NO_ID) {
|
||||||
|
addMenuProvider(FavouritesListMenuProvider(view.context, viewModel))
|
||||||
|
}
|
||||||
viewModel.sortOrder.observe(viewLifecycleOwner) { activity?.invalidateOptionsMenu() }
|
viewModel.sortOrder.observe(viewLifecycleOwner) { activity?.invalidateOptionsMenu() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +75,7 @@ class FavouritesListFragment : MangaListFragment(), PopupMenu.OnMenuItemClickLis
|
|||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> super.onActionItemClicked(controller, mode, item)
|
else -> super.onActionItemClicked(controller, mode, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package org.koitharu.kotatsu.favourites.ui.list
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
|
import androidx.core.view.forEach
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.ui.titleRes
|
||||||
|
import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesActivity
|
||||||
|
import org.koitharu.kotatsu.favourites.ui.categories.edit.FavouritesCategoryEditActivity
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
|
||||||
|
class FavouritesListMenuProvider(
|
||||||
|
private val context: Context,
|
||||||
|
private val viewModel: FavouritesListViewModel,
|
||||||
|
) : MenuProvider {
|
||||||
|
|
||||||
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||||
|
menuInflater.inflate(R.menu.opt_favourites, menu)
|
||||||
|
val subMenu = menu.findItem(R.id.action_order)?.subMenu ?: return
|
||||||
|
for (order in FavouriteCategoriesActivity.SORT_ORDERS) {
|
||||||
|
subMenu.add(R.id.group_order, Menu.NONE, order.ordinal, order.titleRes)
|
||||||
|
}
|
||||||
|
subMenu.setGroupCheckable(R.id.group_order, true, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareMenu(menu: Menu) {
|
||||||
|
super.onPrepareMenu(menu)
|
||||||
|
val order = viewModel.sortOrder.value ?: return
|
||||||
|
menu.findItem(R.id.action_order)?.subMenu?.forEach { item ->
|
||||||
|
if (item.order == order.ordinal) {
|
||||||
|
item.isChecked = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||||
|
if (menuItem.groupId == R.id.group_order) {
|
||||||
|
val order = enumValues<SortOrder>()[menuItem.order]
|
||||||
|
viewModel.setSortOrder(order)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return when (menuItem.itemId) {
|
||||||
|
R.id.action_edit -> {
|
||||||
|
context.startActivity(
|
||||||
|
FavouritesCategoryEditActivity.newIntent(context, viewModel.categoryId),
|
||||||
|
)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,7 +31,7 @@ import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
|||||||
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
class FavouritesListViewModel @AssistedInject constructor(
|
class FavouritesListViewModel @AssistedInject constructor(
|
||||||
@Assisted private val categoryId: Long,
|
@Assisted val categoryId: Long,
|
||||||
private val repository: FavouritesRepository,
|
private val repository: FavouritesRepository,
|
||||||
private val trackingRepository: TrackingRepository,
|
private val trackingRepository: TrackingRepository,
|
||||||
private val historyRepository: HistoryRepository,
|
private val historyRepository: HistoryRepository,
|
||||||
@@ -55,7 +55,7 @@ class FavouritesListViewModel @AssistedInject constructor(
|
|||||||
} else {
|
} else {
|
||||||
repository.observeAll(categoryId)
|
repository.observeAll(categoryId)
|
||||||
},
|
},
|
||||||
createListModeFlow(),
|
listModeFlow,
|
||||||
) { list, mode ->
|
) { list, mode ->
|
||||||
when {
|
when {
|
||||||
list.isEmpty() -> listOf(
|
list.isEmpty() -> listOf(
|
||||||
@@ -117,7 +117,11 @@ class FavouritesListViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getCounter(mangaId: Long): Int {
|
override suspend fun getCounter(mangaId: Long): Int {
|
||||||
return trackingRepository.getNewChaptersCount(mangaId)
|
return if (settings.isTrackerEnabled) {
|
||||||
|
trackingRepository.getNewChaptersCount(mangaId)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getProgress(mangaId: Long): Float {
|
override suspend fun getProgress(mangaId: Long): Float {
|
||||||
|
|||||||
@@ -1,15 +1,23 @@
|
|||||||
package org.koitharu.kotatsu.history.domain
|
package org.koitharu.kotatsu.history.domain
|
||||||
|
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.onStart
|
||||||
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.db.entity.*
|
import org.koitharu.kotatsu.core.db.entity.toEntities
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toManga
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toMangaTag
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||||
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.history.data.HistoryEntity
|
import org.koitharu.kotatsu.history.data.HistoryEntity
|
||||||
import org.koitharu.kotatsu.history.data.toMangaHistory
|
import org.koitharu.kotatsu.history.data.toMangaHistory
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
@@ -18,6 +26,7 @@ import org.koitharu.kotatsu.scrobbling.domain.Scrobbler
|
|||||||
import org.koitharu.kotatsu.scrobbling.domain.tryScrobble
|
import org.koitharu.kotatsu.scrobbling.domain.tryScrobble
|
||||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||||
import org.koitharu.kotatsu.utils.ext.mapItems
|
import org.koitharu.kotatsu.utils.ext.mapItems
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
const val PROGRESS_NONE = -1f
|
const val PROGRESS_NONE = -1f
|
||||||
|
|
||||||
@@ -66,7 +75,7 @@ class HistoryRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun addOrUpdate(manga: Manga, chapterId: Long, page: Int, scroll: Int, percent: Float) {
|
suspend fun addOrUpdate(manga: Manga, chapterId: Long, page: Int, scroll: Int, percent: Float) {
|
||||||
if (manga.isNsfw && settings.isHistoryExcludeNsfw || settings.isIncognitoModeEnabled) {
|
if (shouldSkip(manga)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val tags = manga.tags.toEntities()
|
val tags = manga.tags.toEntities()
|
||||||
@@ -138,6 +147,30 @@ class HistoryRepository @Inject constructor(
|
|||||||
return db.historyDao.findPopularTags(limit).map { x -> x.toMangaTag() }
|
return db.historyDao.findPopularTags(limit).map { x -> x.toMangaTag() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun shouldSkip(manga: Manga): Boolean {
|
||||||
|
return manga.isNsfw && settings.isHistoryExcludeNsfw || settings.isIncognitoModeEnabled
|
||||||
|
}
|
||||||
|
|
||||||
|
fun observeShouldSkip(manga: Manga): Flow<Boolean> {
|
||||||
|
return settings.observe()
|
||||||
|
.filter { key -> key == AppSettings.KEY_INCOGNITO_MODE || key == AppSettings.KEY_HISTORY_EXCLUDE_NSFW }
|
||||||
|
.onStart { emit("") }
|
||||||
|
.map { shouldSkip(manga) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun observeShouldSkip(mangaFlow: Flow<Manga?>): Flow<Boolean> {
|
||||||
|
return mangaFlow
|
||||||
|
.distinctUntilChangedBy { it?.isNsfw }
|
||||||
|
.flatMapLatest { m ->
|
||||||
|
if (m != null) {
|
||||||
|
observeShouldSkip(m)
|
||||||
|
} else {
|
||||||
|
settings.observeAsFlow(AppSettings.KEY_INCOGNITO_MODE) { isIncognitoModeEnabled }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun recover(ids: Collection<Long>) {
|
private suspend fun recover(ids: Collection<Long>) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
for (id in ids) {
|
for (id in ids) {
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ class HistoryListAdapter(
|
|||||||
listener: MangaListListener
|
listener: MangaListListener
|
||||||
) : MangaListAdapter(coil, lifecycleOwner, listener), FastScroller.SectionIndexer {
|
) : MangaListAdapter(coil, lifecycleOwner, listener), FastScroller.SectionIndexer {
|
||||||
|
|
||||||
override fun getSectionText(context: Context, position: Int): CharSequence {
|
override fun getSectionText(context: Context, position: Int): CharSequence? {
|
||||||
val list = items
|
val list = items
|
||||||
for (i in (0..position).reversed()) {
|
for (i in (0..position).reversed()) {
|
||||||
val item = list[i]
|
val item = list.getOrNull(i) ?: continue
|
||||||
if (item is DateTimeAgo) {
|
if (item is DateTimeAgo) {
|
||||||
return item.format(context.resources)
|
return item.format(context.resources)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ package org.koitharu.kotatsu.history.ui
|
|||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import java.util.*
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
@@ -21,11 +18,20 @@ import org.koitharu.kotatsu.history.domain.HistoryRepository
|
|||||||
import org.koitharu.kotatsu.history.domain.MangaWithHistory
|
import org.koitharu.kotatsu.history.domain.MangaWithHistory
|
||||||
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
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.EmptyState
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.LoadingState
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.toErrorState
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.toGridModel
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.toListDetailedModel
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.toListModel
|
||||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||||
import org.koitharu.kotatsu.utils.asFlowLiveData
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
import org.koitharu.kotatsu.utils.ext.daysDiff
|
import org.koitharu.kotatsu.utils.ext.daysDiff
|
||||||
import org.koitharu.kotatsu.utils.ext.onFirst
|
import org.koitharu.kotatsu.utils.ext.onFirst
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class HistoryListViewModel @Inject constructor(
|
class HistoryListViewModel @Inject constructor(
|
||||||
@@ -42,7 +48,7 @@ class HistoryListViewModel @Inject constructor(
|
|||||||
override val content = combine(
|
override val content = combine(
|
||||||
repository.observeAllWithHistory(),
|
repository.observeAllWithHistory(),
|
||||||
historyGrouping,
|
historyGrouping,
|
||||||
createListModeFlow(),
|
listModeFlow,
|
||||||
) { list, grouped, mode ->
|
) { list, grouped, mode ->
|
||||||
when {
|
when {
|
||||||
list.isEmpty() -> listOf(
|
list.isEmpty() -> listOf(
|
||||||
@@ -53,6 +59,7 @@ class HistoryListViewModel @Inject constructor(
|
|||||||
actionStringRes = 0,
|
actionStringRes = 0,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> mapList(list, grouped, mode)
|
else -> mapList(list, grouped, mode)
|
||||||
}
|
}
|
||||||
}.onStart {
|
}.onStart {
|
||||||
@@ -103,7 +110,11 @@ class HistoryListViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
prevDate = date
|
prevDate = date
|
||||||
}
|
}
|
||||||
val counter = trackingRepository.getNewChaptersCount(manga.id)
|
val counter = if (settings.isTrackerEnabled) {
|
||||||
|
trackingRepository.getNewChaptersCount(manga.id)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
val percent = if (showPercent) history.percent else PROGRESS_NONE
|
val percent = if (showPercent) history.percent else PROGRESS_NONE
|
||||||
result += when (mode) {
|
result += when (mode) {
|
||||||
ListMode.LIST -> manga.toListModel(counter, percent)
|
ListMode.LIST -> manga.toListModel(counter, percent)
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ class ListModeBottomSheet :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onButtonChecked(group: MaterialButtonToggleGroup?, checkedId: Int, isChecked: Boolean) {
|
override fun onButtonChecked(group: MaterialButtonToggleGroup?, checkedId: Int, isChecked: Boolean) {
|
||||||
|
if (!isChecked) {
|
||||||
|
return
|
||||||
|
}
|
||||||
val mode = when (checkedId) {
|
val mode = when (checkedId) {
|
||||||
R.id.button_list -> ListMode.LIST
|
R.id.button_list -> ListMode.LIST
|
||||||
R.id.button_list_detailed -> ListMode.DETAILED_LIST
|
R.id.button_list_detailed -> ListMode.DETAILED_LIST
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.list.ui
|
package org.koitharu.kotatsu.list.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.*
|
import android.view.LayoutInflater
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import android.view.ViewGroup.MarginLayoutParams
|
import android.view.ViewGroup.MarginLayoutParams
|
||||||
import androidx.annotation.CallSuper
|
import androidx.annotation.CallSuper
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
@@ -15,7 +19,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.domain.reverseAsync
|
import org.koitharu.kotatsu.base.domain.reverseAsync
|
||||||
@@ -42,13 +45,23 @@ import org.koitharu.kotatsu.list.ui.adapter.MangaListListener
|
|||||||
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.list.ui.model.MangaItemModel
|
import org.koitharu.kotatsu.list.ui.model.MangaItemModel
|
||||||
|
import org.koitharu.kotatsu.main.ui.MainActivity
|
||||||
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.main.ui.MainActivity
|
|
||||||
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.MangaTag
|
||||||
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
|
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
||||||
import org.koitharu.kotatsu.utils.ShareHelper
|
import org.koitharu.kotatsu.utils.ShareHelper
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.addMenuProvider
|
||||||
|
import org.koitharu.kotatsu.utils.ext.clearItemDecorations
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureHeight
|
||||||
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
||||||
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
abstract class MangaListFragment :
|
abstract class MangaListFragment :
|
||||||
@@ -138,6 +151,20 @@ abstract class MangaListFragment :
|
|||||||
return selectionController?.onItemLongClick(item.id) ?: false
|
return selectionController?.onItemLongClick(item.id) ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onReadClick(manga: Manga, view: View) {
|
||||||
|
if (selectionController?.onItemClick(manga.id) != true) {
|
||||||
|
val intent = ReaderActivity.newIntent(context ?: return, manga)
|
||||||
|
startActivity(intent, scaleUpActivityOptionsOf(view).toBundle())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTagClick(manga: Manga, tag: MangaTag, view: View) {
|
||||||
|
if (selectionController?.onItemClick(manga.id) != true) {
|
||||||
|
val intent = MangaListActivity.newIntent(context ?: return, setOf(tag))
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onRefresh() {
|
override fun onRefresh() {
|
||||||
binding.swipeRefreshLayout.isRefreshing = true
|
binding.swipeRefreshLayout.isRefreshing = true
|
||||||
@@ -251,12 +278,14 @@ abstract class MangaListFragment :
|
|||||||
)
|
)
|
||||||
addItemDecoration(decoration)
|
addItemDecoration(decoration)
|
||||||
}
|
}
|
||||||
|
|
||||||
ListMode.DETAILED_LIST -> {
|
ListMode.DETAILED_LIST -> {
|
||||||
layoutManager = FitHeightLinearLayoutManager(context)
|
layoutManager = FitHeightLinearLayoutManager(context)
|
||||||
val spacing = resources.getDimensionPixelOffset(R.dimen.list_spacing)
|
val spacing = resources.getDimensionPixelOffset(R.dimen.list_spacing)
|
||||||
updatePadding(left = spacing, right = spacing)
|
updatePadding(left = spacing, right = spacing)
|
||||||
addItemDecoration(SpacingItemDecoration(spacing))
|
addItemDecoration(SpacingItemDecoration(spacing))
|
||||||
}
|
}
|
||||||
|
|
||||||
ListMode.GRID -> {
|
ListMode.GRID -> {
|
||||||
layoutManager = FitHeightGridLayoutManager(context, checkNotNull(spanResolver).spanCount).also {
|
layoutManager = FitHeightGridLayoutManager(context, checkNotNull(spanResolver).spanCount).also {
|
||||||
it.spanSizeLookup = spanSizeLookup
|
it.spanSizeLookup = spanSizeLookup
|
||||||
@@ -284,21 +313,25 @@ abstract class MangaListFragment :
|
|||||||
selectionController?.addAll(ids)
|
selectionController?.addAll(ids)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_share -> {
|
R.id.action_share -> {
|
||||||
ShareHelper(requireContext()).shareMangaLinks(selectedItems)
|
ShareHelper(requireContext()).shareMangaLinks(selectedItems)
|
||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_favourite -> {
|
R.id.action_favourite -> {
|
||||||
FavouriteCategoriesBottomSheet.show(childFragmentManager, selectedItems)
|
FavouriteCategoriesBottomSheet.show(childFragmentManager, selectedItems)
|
||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_save -> {
|
R.id.action_save -> {
|
||||||
DownloadService.confirmAndStart(requireContext(), selectedItems)
|
DownloadService.confirmAndStart(requireContext(), selectedItems)
|
||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,29 @@
|
|||||||
package org.koitharu.kotatsu.list.ui
|
package org.koitharu.kotatsu.list.ui
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||||
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
|
||||||
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
import org.koitharu.kotatsu.core.prefs.observeAsLiveData
|
import org.koitharu.kotatsu.core.prefs.observeAsLiveData
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
|
|
||||||
abstract class MangaListViewModel(
|
abstract class MangaListViewModel(
|
||||||
private val settings: AppSettings,
|
private val settings: AppSettings,
|
||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
|
|
||||||
abstract val content: LiveData<List<ListModel>>
|
abstract val content: LiveData<List<ListModel>>
|
||||||
val listMode = MutableLiveData<ListMode>()
|
protected val listModeFlow = settings.observeAsFlow(AppSettings.KEY_LIST_MODE) { listMode }
|
||||||
|
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, settings.listMode)
|
||||||
|
val listMode = listModeFlow.asFlowLiveData(viewModelScope.coroutineContext)
|
||||||
val onActionDone = SingleLiveEvent<ReversibleAction>()
|
val onActionDone = SingleLiveEvent<ReversibleAction>()
|
||||||
val gridScale = settings.observeAsLiveData(
|
val gridScale = settings.observeAsLiveData(
|
||||||
context = viewModelScope.coroutineContext + Dispatchers.Default,
|
context = viewModelScope.coroutineContext + Dispatchers.Default,
|
||||||
@@ -30,13 +33,6 @@ abstract class MangaListViewModel(
|
|||||||
|
|
||||||
open fun onUpdateFilter(tags: Set<MangaTag>) = Unit
|
open fun onUpdateFilter(tags: Set<MangaTag>) = Unit
|
||||||
|
|
||||||
protected fun createListModeFlow() = settings.observeAsFlow(AppSettings.KEY_LIST_MODE) { listMode }
|
|
||||||
.onEach {
|
|
||||||
if (listMode.value != it) {
|
|
||||||
listMode.postValue(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract fun onRefresh()
|
abstract fun onRefresh()
|
||||||
|
|
||||||
abstract fun onRetry()
|
abstract fun onRetry()
|
||||||
|
|||||||
@@ -22,11 +22,12 @@ open class MangaSelectionDecoration(context: Context) : AbstractSelectionItemDec
|
|||||||
|
|
||||||
protected val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
protected val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
protected val checkIcon = ContextCompat.getDrawable(context, materialR.drawable.ic_mtrl_checked_circle)
|
protected val checkIcon = ContextCompat.getDrawable(context, materialR.drawable.ic_mtrl_checked_circle)
|
||||||
protected val iconOffset = context.resources.getDimensionPixelOffset(R.dimen.grid_spacing_outer)
|
protected val iconOffset = context.resources.getDimensionPixelOffset(R.dimen.card_indicator_offset)
|
||||||
|
protected val iconSize = context.resources.getDimensionPixelOffset(R.dimen.card_indicator_size)
|
||||||
protected val strokeColor = context.getThemeColor(materialR.attr.colorPrimary, Color.RED)
|
protected val strokeColor = context.getThemeColor(materialR.attr.colorPrimary, Color.RED)
|
||||||
protected val fillColor = ColorUtils.setAlphaComponent(
|
protected val fillColor = ColorUtils.setAlphaComponent(
|
||||||
ColorUtils.blendARGB(strokeColor, context.getThemeColor(materialR.attr.colorSurface), 0.8f),
|
ColorUtils.blendARGB(strokeColor, context.getThemeColor(materialR.attr.colorSurface), 0.8f),
|
||||||
0x74
|
0x74,
|
||||||
)
|
)
|
||||||
protected val defaultRadius = context.resources.getDimension(R.dimen.list_selector_corner)
|
protected val defaultRadius = context.resources.getDimension(R.dimen.list_selector_corner)
|
||||||
|
|
||||||
@@ -65,11 +66,11 @@ open class MangaSelectionDecoration(context: Context) : AbstractSelectionItemDec
|
|||||||
setBounds(
|
setBounds(
|
||||||
(bounds.left + iconOffset).toInt(),
|
(bounds.left + iconOffset).toInt(),
|
||||||
(bounds.top + iconOffset).toInt(),
|
(bounds.top + iconOffset).toInt(),
|
||||||
(bounds.left + iconOffset + intrinsicWidth).toInt(),
|
(bounds.left + iconOffset + iconSize).toInt(),
|
||||||
(bounds.top + iconOffset + intrinsicHeight).toInt(),
|
(bounds.top + iconOffset + iconSize).toInt(),
|
||||||
)
|
)
|
||||||
draw(canvas)
|
draw(canvas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.koitharu.kotatsu.list.ui.adapter
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
|
||||||
|
interface MangaDetailsClickListener : OnListItemClickListener<Manga> {
|
||||||
|
|
||||||
|
fun onReadClick(manga: Manga, view: View)
|
||||||
|
|
||||||
|
fun onTagClick(manga: Manga, tag: MangaTag, view: View)
|
||||||
|
}
|
||||||
@@ -1,34 +1,52 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.adapter
|
package org.koitharu.kotatsu.list.ui.adapter
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.google.android.material.badge.BadgeDrawable
|
import com.google.android.material.badge.BadgeDrawable
|
||||||
|
import com.google.android.material.chip.Chip
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.databinding.ItemMangaListDetailsBinding
|
import org.koitharu.kotatsu.databinding.ItemMangaListDetailsBinding
|
||||||
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.list.ui.model.MangaListDetailedModel
|
import org.koitharu.kotatsu.list.ui.model.MangaListDetailedModel
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
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.referer
|
||||||
|
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||||
import org.koitharu.kotatsu.utils.image.CoverSizeResolver
|
import org.koitharu.kotatsu.utils.image.CoverSizeResolver
|
||||||
|
|
||||||
fun mangaListDetailedItemAD(
|
fun mangaListDetailedItemAD(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
lifecycleOwner: LifecycleOwner,
|
lifecycleOwner: LifecycleOwner,
|
||||||
clickListener: OnListItemClickListener<Manga>,
|
clickListener: MangaDetailsClickListener,
|
||||||
) = adapterDelegateViewBinding<MangaListDetailedModel, ListModel, ItemMangaListDetailsBinding>(
|
) = adapterDelegateViewBinding<MangaListDetailedModel, ListModel, ItemMangaListDetailsBinding>(
|
||||||
{ inflater, parent -> ItemMangaListDetailsBinding.inflate(inflater, parent, false) },
|
{ inflater, parent -> ItemMangaListDetailsBinding.inflate(inflater, parent, false) },
|
||||||
) {
|
) {
|
||||||
var badge: BadgeDrawable? = null
|
var badge: BadgeDrawable? = null
|
||||||
|
|
||||||
itemView.setOnClickListener {
|
val listenerAdapter = object : View.OnClickListener, View.OnLongClickListener, ChipsView.OnChipClickListener {
|
||||||
clickListener.onItemClick(item.manga, it)
|
override fun onClick(v: View) = when (v.id) {
|
||||||
}
|
R.id.button_read -> clickListener.onReadClick(item.manga, v)
|
||||||
itemView.setOnLongClickListener {
|
else -> clickListener.onItemClick(item.manga, v)
|
||||||
clickListener.onItemLongClick(item.manga, it)
|
}
|
||||||
|
|
||||||
|
override fun onLongClick(v: View): Boolean = clickListener.onItemLongClick(item.manga, v)
|
||||||
|
|
||||||
|
override fun onChipClick(chip: Chip, data: Any?) {
|
||||||
|
val tag = data as? MangaTag ?: return
|
||||||
|
clickListener.onTagClick(item.manga, tag, chip)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
itemView.setOnClickListener(listenerAdapter)
|
||||||
|
itemView.setOnLongClickListener(listenerAdapter)
|
||||||
|
binding.buttonRead.setOnClickListener(listenerAdapter)
|
||||||
|
binding.chipsTags.onChipClickListener = listenerAdapter
|
||||||
|
|
||||||
bind { payloads ->
|
bind { payloads ->
|
||||||
binding.textViewTitle.text = item.title
|
binding.textViewTitle.text = item.title
|
||||||
@@ -44,8 +62,9 @@ fun mangaListDetailedItemAD(
|
|||||||
lifecycle(lifecycleOwner)
|
lifecycle(lifecycleOwner)
|
||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
binding.textViewRating.textAndVisible = item.rating
|
binding.chipsTags.setChips(item.tags)
|
||||||
binding.textViewTags.text = item.tags
|
binding.ratingBar.isVisible = item.manga.hasRating
|
||||||
|
binding.ratingBar.rating = binding.ratingBar.numStars * item.manga.rating
|
||||||
badge = itemView.bindBadge(badge, item.counter)
|
badge = itemView.bindBadge(badge, item.counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.adapter
|
package org.koitharu.kotatsu.list.ui.adapter
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
|
||||||
interface MangaListListener : OnListItemClickListener<Manga>, ListStateHolderListener, ListHeaderClickListener {
|
interface MangaListListener : MangaDetailsClickListener, ListStateHolderListener, ListHeaderClickListener {
|
||||||
|
|
||||||
fun onUpdateFilter(tags: Set<MangaTag>)
|
fun onUpdateFilter(tags: Set<MangaTag>)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.model
|
package org.koitharu.kotatsu.list.ui.model
|
||||||
|
|
||||||
import java.net.SocketTimeoutException
|
|
||||||
import java.net.UnknownHostException
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
|
import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
import org.koitharu.kotatsu.core.prefs.ListMode
|
||||||
@@ -11,6 +10,8 @@ import org.koitharu.kotatsu.list.domain.ListExtraProvider
|
|||||||
import org.koitharu.kotatsu.parsers.exception.AuthRequiredException
|
import org.koitharu.kotatsu.parsers.exception.AuthRequiredException
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.utils.ext.ifZero
|
import org.koitharu.kotatsu.utils.ext.ifZero
|
||||||
|
import java.net.SocketTimeoutException
|
||||||
|
import java.net.UnknownHostException
|
||||||
|
|
||||||
fun Manga.toListModel(counter: Int, progress: Float) = MangaListModel(
|
fun Manga.toListModel(counter: Int, progress: Float) = MangaListModel(
|
||||||
id = id,
|
id = id,
|
||||||
@@ -26,12 +27,11 @@ fun Manga.toListDetailedModel(counter: Int, progress: Float) = MangaListDetailed
|
|||||||
id = id,
|
id = id,
|
||||||
title = title,
|
title = title,
|
||||||
subtitle = altTitle,
|
subtitle = altTitle,
|
||||||
rating = if (hasRating) String.format("%.1f", rating * 5) else null,
|
|
||||||
tags = tags.joinToString(", ") { it.title },
|
|
||||||
coverUrl = coverUrl,
|
coverUrl = coverUrl,
|
||||||
manga = this,
|
manga = this,
|
||||||
counter = counter,
|
counter = counter,
|
||||||
progress = progress,
|
progress = progress,
|
||||||
|
tags = tags.map { ChipsView.ChipModel(0, it.title, false, false, it) },
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Manga.toGridModel(counter: Int, progress: Float) = MangaGridModel(
|
fun Manga.toGridModel(counter: Int, progress: Float) = MangaGridModel(
|
||||||
@@ -69,9 +69,11 @@ suspend fun <C : MutableCollection<in MangaItemModel>> List<Manga>.toUi(
|
|||||||
ListMode.LIST -> mapTo(destination) {
|
ListMode.LIST -> mapTo(destination) {
|
||||||
it.toListModel(extraProvider.getCounter(it.id), extraProvider.getProgress(it.id))
|
it.toListModel(extraProvider.getCounter(it.id), extraProvider.getProgress(it.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
ListMode.DETAILED_LIST -> mapTo(destination) {
|
ListMode.DETAILED_LIST -> mapTo(destination) {
|
||||||
it.toListDetailedModel(extraProvider.getCounter(it.id), extraProvider.getProgress(it.id))
|
it.toListDetailedModel(extraProvider.getCounter(it.id), extraProvider.getProgress(it.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
ListMode.GRID -> mapTo(destination) {
|
ListMode.GRID -> mapTo(destination) {
|
||||||
it.toGridModel(extraProvider.getCounter(it.id), extraProvider.getProgress(it.id))
|
it.toGridModel(extraProvider.getCounter(it.id), extraProvider.getProgress(it.id))
|
||||||
}
|
}
|
||||||
@@ -95,5 +97,6 @@ private fun getErrorIcon(error: Throwable) = when (error) {
|
|||||||
is UnknownHostException,
|
is UnknownHostException,
|
||||||
is SocketTimeoutException,
|
is SocketTimeoutException,
|
||||||
-> R.drawable.ic_plug_large
|
-> R.drawable.ic_plug_large
|
||||||
|
|
||||||
else -> R.drawable.ic_error_large
|
else -> R.drawable.ic_error_large
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.model
|
package org.koitharu.kotatsu.list.ui.model
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.base.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
|
||||||
data class MangaListDetailedModel(
|
data class MangaListDetailedModel(
|
||||||
override val id: Long,
|
override val id: Long,
|
||||||
override val title: String,
|
override val title: String,
|
||||||
val subtitle: String?,
|
val subtitle: String?,
|
||||||
val tags: String,
|
|
||||||
override val coverUrl: String,
|
override val coverUrl: String,
|
||||||
val rating: String?,
|
|
||||||
override val manga: Manga,
|
override val manga: Manga,
|
||||||
override val counter: Int,
|
override val counter: Int,
|
||||||
override val progress: Float,
|
override val progress: Float,
|
||||||
) : MangaItemModel
|
val tags: List<ChipsView.ChipModel>,
|
||||||
|
) : MangaItemModel
|
||||||
|
|||||||
@@ -23,10 +23,7 @@ class CbzFetcher(
|
|||||||
val zip = ZipFile(uri.schemeSpecificPart)
|
val zip = ZipFile(uri.schemeSpecificPart)
|
||||||
val entry = zip.getEntry(uri.fragment)
|
val entry = zip.getEntry(uri.fragment)
|
||||||
val ext = MimeTypeMap.getFileExtensionFromUrl(entry.name)
|
val ext = MimeTypeMap.getFileExtensionFromUrl(entry.name)
|
||||||
val bufferedSource = ExtraCloseableBufferedSource(
|
val bufferedSource = zip.getInputStream(entry).source().withExtraCloseable(zip).buffer()
|
||||||
zip.getInputStream(entry).source().buffer(),
|
|
||||||
zip,
|
|
||||||
)
|
|
||||||
SourceResult(
|
SourceResult(
|
||||||
source = ImageSource(
|
source = ImageSource(
|
||||||
source = bufferedSource,
|
source = bufferedSource,
|
||||||
@@ -50,4 +47,4 @@ class CbzFetcher(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CbzMetadata(val uri: Uri) : ImageSource.Metadata()
|
class CbzMetadata(val uri: Uri) : ImageSource.Metadata()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.local.data
|
|
||||||
|
|
||||||
import okhttp3.internal.closeQuietly
|
|
||||||
import okio.BufferedSource
|
|
||||||
import okio.Closeable
|
|
||||||
|
|
||||||
class ExtraCloseableBufferedSource(
|
|
||||||
private val delegate: BufferedSource,
|
|
||||||
vararg closeable: Closeable,
|
|
||||||
) : BufferedSource by delegate {
|
|
||||||
|
|
||||||
private val extraCloseable = closeable
|
|
||||||
|
|
||||||
override fun close() {
|
|
||||||
delegate.close()
|
|
||||||
extraCloseable.forEach { x -> x.closeQuietly() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.koitharu.kotatsu.local.data
|
||||||
|
|
||||||
|
import okhttp3.internal.closeQuietly
|
||||||
|
import okio.Closeable
|
||||||
|
import okio.Source
|
||||||
|
|
||||||
|
private class ExtraCloseableSource(
|
||||||
|
private val delegate: Source,
|
||||||
|
private val extraCloseable: Closeable,
|
||||||
|
) : Source by delegate {
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
try {
|
||||||
|
delegate.close()
|
||||||
|
} finally {
|
||||||
|
extraCloseable.closeQuietly()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Source.withExtraCloseable(closeable: Closeable): Source = ExtraCloseableSource(this, closeable)
|
||||||
@@ -3,22 +3,30 @@ package org.koitharu.kotatsu.local.data
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.tomclaw.cache.DiskLruCache
|
import com.tomclaw.cache.DiskLruCache
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.koitharu.kotatsu.utils.FileSize
|
||||||
|
import org.koitharu.kotatsu.utils.ext.copyToSuspending
|
||||||
|
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||||
|
import org.koitharu.kotatsu.utils.ext.subdir
|
||||||
|
import org.koitharu.kotatsu.utils.ext.takeIfReadable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.takeIfWriteable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
|
||||||
import org.koitharu.kotatsu.utils.FileSize
|
|
||||||
import org.koitharu.kotatsu.utils.ext.longHashCode
|
|
||||||
import org.koitharu.kotatsu.utils.ext.subdir
|
|
||||||
import org.koitharu.kotatsu.utils.ext.takeIfReadable
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class PagesCache @Inject constructor(@ApplicationContext context: Context) {
|
class PagesCache @Inject constructor(@ApplicationContext context: Context) {
|
||||||
|
|
||||||
private val cacheDir = context.externalCacheDir ?: context.cacheDir
|
private val cacheDir = checkNotNull(findSuitableDir(context)) {
|
||||||
|
val dirs = (context.externalCacheDirs + context.cacheDir).joinToString(";") {
|
||||||
|
it.absolutePath
|
||||||
|
}
|
||||||
|
"Cannot find any suitable directory for PagesCache: [$dirs]"
|
||||||
|
}
|
||||||
private val lruCache = createDiskLruCacheSafe(
|
private val lruCache = createDiskLruCacheSafe(
|
||||||
dir = cacheDir.subdir(CacheDir.PAGES.dir),
|
dir = cacheDir,
|
||||||
size = FileSize.MEGABYTES.convert(200, FileSize.BYTES),
|
size = FileSize.MEGABYTES.convert(200, FileSize.BYTES),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,42 +34,15 @@ class PagesCache @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
return lruCache.get(url)?.takeIfReadable()
|
return lruCache.get(url)?.takeIfReadable()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun put(url: String, inputStream: InputStream): File {
|
suspend fun put(url: String, inputStream: InputStream): File = withContext(Dispatchers.IO) {
|
||||||
val file = File(cacheDir, url.longHashCode().toString())
|
val file = File(cacheDir.parentFile, url.longHashCode().toString())
|
||||||
file.outputStream().use { out ->
|
try {
|
||||||
inputStream.copyTo(out)
|
file.outputStream().use { out ->
|
||||||
}
|
inputStream.copyToSuspending(out)
|
||||||
val res = lruCache.put(url, file)
|
|
||||||
file.delete()
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
fun put(
|
|
||||||
url: String,
|
|
||||||
inputStream: InputStream,
|
|
||||||
contentLength: Long,
|
|
||||||
progress: MutableStateFlow<Float>,
|
|
||||||
): File {
|
|
||||||
val file = File(cacheDir, url.longHashCode().toString())
|
|
||||||
file.outputStream().use { out ->
|
|
||||||
var bytesCopied: Long = 0
|
|
||||||
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
|
|
||||||
var bytes = inputStream.read(buffer)
|
|
||||||
while (bytes >= 0) {
|
|
||||||
out.write(buffer, 0, bytes)
|
|
||||||
bytesCopied += bytes
|
|
||||||
publishProgress(contentLength, bytesCopied, progress)
|
|
||||||
bytes = inputStream.read(buffer)
|
|
||||||
}
|
}
|
||||||
}
|
lruCache.put(url, file)
|
||||||
val res = lruCache.put(url, file)
|
} finally {
|
||||||
file.delete()
|
file.delete()
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun publishProgress(contentLength: Long, bytesCopied: Long, progress: MutableStateFlow<Float>) {
|
|
||||||
if (contentLength > 0) {
|
|
||||||
progress.value = (bytesCopied.toDouble() / contentLength.toDouble()).toFloat()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,3 +56,10 @@ private fun createDiskLruCacheSafe(dir: File, size: Long): DiskLruCache {
|
|||||||
DiskLruCache.create(dir, size)
|
DiskLruCache.create(dir, size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun findSuitableDir(context: Context): File? {
|
||||||
|
val dirs = context.externalCacheDirs + context.cacheDir
|
||||||
|
return dirs.firstNotNullOfOrNull {
|
||||||
|
it.subdir(CacheDir.PAGES.dir).takeIfWriteable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.content.Context
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import java.io.File
|
|
||||||
import kotlinx.coroutines.NonCancellable
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
||||||
@@ -14,8 +13,11 @@ import org.koitharu.kotatsu.parsers.model.Manga
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.model.RATING_UNKNOWN
|
import org.koitharu.kotatsu.parsers.model.RATING_UNKNOWN
|
||||||
|
import org.koitharu.kotatsu.utils.AlphanumComparator
|
||||||
|
import org.koitharu.kotatsu.utils.ext.copyToSuspending
|
||||||
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
||||||
import org.koitharu.kotatsu.utils.ext.longOf
|
import org.koitharu.kotatsu.utils.ext.longOf
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
// TODO: Add support for chapters in cbz
|
// TODO: Add support for chapters in cbz
|
||||||
// https://github.com/KotatsuApp/Kotatsu/issues/31
|
// https://github.com/KotatsuApp/Kotatsu/issues/31
|
||||||
@@ -57,11 +59,12 @@ class DirMangaImporter(
|
|||||||
|
|
||||||
private suspend fun addPages(output: CbzMangaOutput, root: DocumentFile, path: String, state: State) {
|
private suspend fun addPages(output: CbzMangaOutput, root: DocumentFile, path: String, state: State) {
|
||||||
var number = 0
|
var number = 0
|
||||||
for (file in root.listFiles()) {
|
for (file in root.listFiles().sortedWith(compareBy(AlphanumComparator()) { it.name.orEmpty() })) {
|
||||||
when {
|
when {
|
||||||
file.isDirectory -> {
|
file.isDirectory -> {
|
||||||
addPages(output, file, path + "/" + file.name, state)
|
addPages(output, file, path + "/" + file.name, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
file.isFile -> {
|
file.isFile -> {
|
||||||
val tempFile = file.asTempFile()
|
val tempFile = file.asTempFile()
|
||||||
if (!state.hasCover) {
|
if (!state.hasCover) {
|
||||||
@@ -86,7 +89,7 @@ class DirMangaImporter(
|
|||||||
"Cannot open input stream for $uri"
|
"Cannot open input stream for $uri"
|
||||||
}.use { input ->
|
}.use { input ->
|
||||||
file.outputStream().use { output ->
|
file.outputStream().use { output ->
|
||||||
input.copyTo(output)
|
input.copyToSuspending(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return file
|
return file
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.local.domain.importer
|
package org.koitharu.kotatsu.local.domain.importer
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import java.io.File
|
|
||||||
import java.io.IOException
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runInterruptible
|
import kotlinx.coroutines.runInterruptible
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -11,7 +9,10 @@ import org.koitharu.kotatsu.local.data.CbzFilter
|
|||||||
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.copyToSuspending
|
||||||
import org.koitharu.kotatsu.utils.ext.resolveName
|
import org.koitharu.kotatsu.utils.ext.resolveName
|
||||||
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class ZipMangaImporter(
|
class ZipMangaImporter(
|
||||||
storageManager: LocalStorageManager,
|
storageManager: LocalStorageManager,
|
||||||
@@ -27,10 +28,10 @@ class ZipMangaImporter(
|
|||||||
}
|
}
|
||||||
val dest = File(getOutputDir(), name)
|
val dest = File(getOutputDir(), name)
|
||||||
runInterruptible {
|
runInterruptible {
|
||||||
contentResolver.openInputStream(uri)?.use { source ->
|
contentResolver.openInputStream(uri)
|
||||||
dest.outputStream().use { output ->
|
}?.use { source ->
|
||||||
source.copyTo(output)
|
dest.outputStream().use { output ->
|
||||||
}
|
source.copyToSuspending(output)
|
||||||
}
|
}
|
||||||
} ?: throw IOException("Cannot open input stream: $uri")
|
} ?: throw IOException("Cannot open input stream: $uri")
|
||||||
localMangaRepository.getFromFile(dest)
|
localMangaRepository.getFromFile(dest)
|
||||||
|
|||||||
@@ -4,14 +4,16 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import androidx.lifecycle.asFlow
|
import androidx.lifecycle.asFlow
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import java.io.IOException
|
import kotlinx.coroutines.CancellationException
|
||||||
import java.util.*
|
import kotlinx.coroutines.Dispatchers
|
||||||
import javax.inject.Inject
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.cancelAndJoin
|
||||||
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.base.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
@@ -20,7 +22,11 @@ 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.list.domain.ListExtraProvider
|
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.*
|
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListHeader2
|
||||||
|
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.MangaTag
|
||||||
@@ -30,6 +36,9 @@ 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
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
import java.io.IOException
|
||||||
|
import java.util.LinkedList
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class LocalListViewModel @Inject constructor(
|
class LocalListViewModel @Inject constructor(
|
||||||
@@ -48,7 +57,7 @@ class LocalListViewModel @Inject constructor(
|
|||||||
|
|
||||||
override val content = combine(
|
override val content = combine(
|
||||||
mangaList,
|
mangaList,
|
||||||
createListModeFlow(),
|
listModeFlow,
|
||||||
sortOrder.asFlow(),
|
sortOrder.asFlow(),
|
||||||
selectedTags,
|
selectedTags,
|
||||||
listError,
|
listError,
|
||||||
@@ -181,7 +190,11 @@ class LocalListViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getCounter(mangaId: Long): Int {
|
override suspend fun getCounter(mangaId: Long): Int {
|
||||||
return trackingRepository.getNewChaptersCount(mangaId)
|
return if (settings.isTrackerEnabled) {
|
||||||
|
trackingRepository.getNewChaptersCount(mangaId)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getProgress(mangaId: Long): Float {
|
override suspend fun getProgress(mangaId: Long): Float {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ 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.service.MangaPrefetchService
|
||||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
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
|
||||||
@@ -334,6 +335,7 @@ class MainActivity :
|
|||||||
TrackWorker.setup(applicationContext)
|
TrackWorker.setup(applicationContext)
|
||||||
SuggestionsWorker.setup(applicationContext)
|
SuggestionsWorker.setup(applicationContext)
|
||||||
}
|
}
|
||||||
|
MangaPrefetchService.prefetchLast(this@MainActivity)
|
||||||
requestNotificationsPermission()
|
requestNotificationsPermission()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class MainNavigationDelegate(
|
|||||||
fun onCreate(savedInstanceState: Bundle?) {
|
fun onCreate(savedInstanceState: Bundle?) {
|
||||||
primaryFragment?.let {
|
primaryFragment?.let {
|
||||||
onFragmentChanged(it, fromUser = false)
|
onFragmentChanged(it, fromUser = false)
|
||||||
|
navBar.selectedItemId = getItemId(it)
|
||||||
} ?: onNavigationItemSelected(navBar.selectedItemId)
|
} ?: onNavigationItemSelected(navBar.selectedItemId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +93,14 @@ class MainNavigationDelegate(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getItemId(fragment: Fragment) = when (fragment) {
|
||||||
|
is ShelfFragment -> R.id.nav_shelf
|
||||||
|
is ExploreFragment -> R.id.nav_explore
|
||||||
|
is FeedFragment -> R.id.nav_feed
|
||||||
|
is ToolsFragment -> R.id.nav_tools
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
|
||||||
private fun setPrimaryFragment(fragment: Fragment) {
|
private fun setPrimaryFragment(fragment: Fragment) {
|
||||||
fragmentManager.beginTransaction()
|
fragmentManager.beginTransaction()
|
||||||
.setReorderingAllowed(true)
|
.setReorderingAllowed(true)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.koitharu.kotatsu.core.db.MangaDatabase
|
|||||||
import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException
|
import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException
|
||||||
import org.koitharu.kotatsu.core.github.AppUpdateRepository
|
import org.koitharu.kotatsu.core.github.AppUpdateRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
import org.koitharu.kotatsu.core.prefs.observeAsLiveData
|
import org.koitharu.kotatsu.core.prefs.observeAsLiveData
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
@@ -34,9 +35,12 @@ class MainViewModel @Inject constructor(
|
|||||||
|
|
||||||
val onOpenReader = SingleLiveEvent<Manga>()
|
val onOpenReader = SingleLiveEvent<Manga>()
|
||||||
|
|
||||||
val isResumeEnabled = historyRepository
|
val isResumeEnabled = combine(
|
||||||
.observeHasItems()
|
historyRepository.observeHasItems(),
|
||||||
.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, false)
|
settings.observeAsFlow(AppSettings.KEY_INCOGNITO_MODE) { isIncognitoModeEnabled },
|
||||||
|
) { hasItems, incognito ->
|
||||||
|
hasItems && !incognito
|
||||||
|
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, false)
|
||||||
|
|
||||||
val isFeedAvailable = settings.observeAsLiveData(
|
val isFeedAvailable = settings.observeAsLiveData(
|
||||||
context = viewModelScope.coroutineContext + Dispatchers.Default,
|
context = viewModelScope.coroutineContext + Dispatchers.Default,
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package org.koitharu.kotatsu.reader.domain
|
package org.koitharu.kotatsu.reader.domain
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.collection.LongSparseArray
|
import androidx.collection.LongSparseArray
|
||||||
import androidx.collection.set
|
import androidx.collection.set
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@@ -31,8 +29,8 @@ 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.util.await
|
import org.koitharu.kotatsu.parsers.util.await
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
||||||
import org.koitharu.kotatsu.utils.ext.connectivityManager
|
|
||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
import org.koitharu.kotatsu.utils.ext.withProgress
|
||||||
import org.koitharu.kotatsu.utils.progress.ProgressDeferred
|
import org.koitharu.kotatsu.utils.progress.ProgressDeferred
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
@@ -49,13 +47,11 @@ class PageLoader @Inject constructor(
|
|||||||
private val okHttp: OkHttpClient,
|
private val okHttp: OkHttpClient,
|
||||||
private val cache: PagesCache,
|
private val cache: PagesCache,
|
||||||
private val settings: AppSettings,
|
private val settings: AppSettings,
|
||||||
@ApplicationContext context: Context,
|
|
||||||
private val mangaRepositoryFactory: MangaRepository.Factory,
|
private val mangaRepositoryFactory: MangaRepository.Factory,
|
||||||
) : Closeable {
|
) : Closeable {
|
||||||
|
|
||||||
val loaderScope = CoroutineScope(SupervisorJob() + InternalErrorHandler() + Dispatchers.Default)
|
val loaderScope = CoroutineScope(SupervisorJob() + InternalErrorHandler() + Dispatchers.Default)
|
||||||
|
|
||||||
private val connectivityManager = context.connectivityManager
|
|
||||||
private val tasks = LongSparseArray<ProgressDeferred<File, Float>>()
|
private val tasks = LongSparseArray<ProgressDeferred<File, Float>>()
|
||||||
private val convertLock = Mutex()
|
private val convertLock = Mutex()
|
||||||
private var repository: MangaRepository? = null
|
private var repository: MangaRepository? = null
|
||||||
@@ -72,7 +68,7 @@ class PageLoader @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isPrefetchApplicable(): Boolean {
|
fun isPrefetchApplicable(): Boolean {
|
||||||
return repository is RemoteMangaRepository && settings.isPagesPreloadAllowed(connectivityManager)
|
return repository is RemoteMangaRepository && settings.isPagesPreloadEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun prefetch(pages: List<ReaderPage>) {
|
fun prefetch(pages: List<ReaderPage>) {
|
||||||
@@ -179,9 +175,12 @@ class PageLoader @Inject constructor(
|
|||||||
val uri = Uri.parse(pageUrl)
|
val uri = Uri.parse(pageUrl)
|
||||||
return if (uri.scheme == "cbz") {
|
return if (uri.scheme == "cbz") {
|
||||||
runInterruptible(Dispatchers.IO) {
|
runInterruptible(Dispatchers.IO) {
|
||||||
val zip = ZipFile(uri.schemeSpecificPart)
|
ZipFile(uri.schemeSpecificPart)
|
||||||
val entry = zip.getEntry(uri.fragment)
|
}.use { zip ->
|
||||||
zip.getInputStream(entry).use {
|
runInterruptible(Dispatchers.IO) {
|
||||||
|
val entry = zip.getEntry(uri.fragment)
|
||||||
|
zip.getInputStream(entry)
|
||||||
|
}.use {
|
||||||
cache.put(pageUrl, it)
|
cache.put(pageUrl, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,10 +199,8 @@ class PageLoader @Inject constructor(
|
|||||||
val body = checkNotNull(response.body) {
|
val body = checkNotNull(response.body) {
|
||||||
"Null response"
|
"Null response"
|
||||||
}
|
}
|
||||||
runInterruptible(Dispatchers.IO) {
|
body.withProgress(progress).byteStream().use {
|
||||||
body.byteStream().use {
|
cache.put(pageUrl, it)
|
||||||
cache.put(pageUrl, it, body.contentLength(), progress)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ import android.webkit.MimeTypeMap
|
|||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.io.File
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.coroutines.Continuation
|
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runInterruptible
|
import kotlinx.coroutines.runInterruptible
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
@@ -20,6 +16,11 @@ import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
import org.koitharu.kotatsu.parsers.util.toFileNameSafe
|
import org.koitharu.kotatsu.parsers.util.toFileNameSafe
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
|
import org.koitharu.kotatsu.utils.ext.copyToSuspending
|
||||||
|
import java.io.File
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.coroutines.Continuation
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
|
||||||
private const val MAX_FILENAME_LENGTH = 10
|
private const val MAX_FILENAME_LENGTH = 10
|
||||||
private const val EXTENSION_FALLBACK = "png"
|
private const val EXTENSION_FALLBACK = "png"
|
||||||
@@ -48,12 +49,12 @@ class PageSaveHelper @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
runInterruptible(Dispatchers.IO) {
|
runInterruptible(Dispatchers.IO) {
|
||||||
contentResolver.openOutputStream(destination)?.use { output ->
|
contentResolver.openOutputStream(destination)
|
||||||
pageFile.inputStream().use { input ->
|
}?.use { output ->
|
||||||
input.copyTo(output)
|
pageFile.inputStream().use { input ->
|
||||||
}
|
input.copyToSuspending(output)
|
||||||
} ?: throw IOException("Output stream is null")
|
}
|
||||||
}
|
} ?: throw IOException("Output stream is null")
|
||||||
return destination
|
return destination
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ class ReaderViewModel @AssistedInject constructor(
|
|||||||
} ?: ReaderState(manga, preselectedBranch)
|
} ?: ReaderState(manga, preselectedBranch)
|
||||||
}
|
}
|
||||||
|
|
||||||
val branch = chapters[currentState.value?.chapterId ?: 0L].branch
|
val branch = chapters[currentState.value?.chapterId ?: 0L]?.branch
|
||||||
mangaData.value = manga.filterChapters(branch)
|
mangaData.value = manga.filterChapters(branch)
|
||||||
readerMode.postValue(mode)
|
readerMode.postValue(mode)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.annotation.CallSuper
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.databinding.LayoutPageInfoBinding
|
import org.koitharu.kotatsu.databinding.LayoutPageInfoBinding
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
@@ -13,11 +14,12 @@ abstract class BasePageHolder<B : ViewBinding>(
|
|||||||
protected val binding: B,
|
protected val binding: B,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
protected val delegate = PageHolderDelegate(loader, settings, this, exceptionResolver)
|
protected val delegate = PageHolderDelegate(loader, settings, this, networkState, exceptionResolver)
|
||||||
protected val bindingInfo = LayoutPageInfoBinding.bind(binding.root)
|
protected val bindingInfo = LayoutPageInfoBinding.bind(binding.root)
|
||||||
|
|
||||||
val context: Context
|
val context: Context
|
||||||
|
|||||||
@@ -4,17 +4,19 @@ import android.view.ViewGroup
|
|||||||
import androidx.recyclerview.widget.AsyncListDiffer
|
import androidx.recyclerview.widget.AsyncListDiffer
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
||||||
private val loader: PageLoader,
|
private val loader: PageLoader,
|
||||||
private val readerSettings: ReaderSettings,
|
private val readerSettings: ReaderSettings,
|
||||||
|
private val networkState: NetworkState,
|
||||||
private val exceptionResolver: ExceptionResolver,
|
private val exceptionResolver: ExceptionResolver,
|
||||||
) : RecyclerView.Adapter<H>() {
|
) : RecyclerView.Adapter<H>() {
|
||||||
|
|
||||||
@@ -56,9 +58,9 @@ abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
|||||||
final override fun onCreateViewHolder(
|
final override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
viewType: Int,
|
viewType: Int,
|
||||||
): H = onCreateViewHolder(parent, loader, readerSettings, exceptionResolver)
|
): H = onCreateViewHolder(parent, loader, readerSettings, networkState, exceptionResolver)
|
||||||
|
|
||||||
suspend fun setItems(items: List<ReaderPage>) = suspendCoroutine<Unit> { cont ->
|
suspend fun setItems(items: List<ReaderPage>) = suspendCoroutine { cont ->
|
||||||
differ.submitList(items) {
|
differ.submitList(items) {
|
||||||
cont.resume(Unit)
|
cont.resume(Unit)
|
||||||
}
|
}
|
||||||
@@ -68,6 +70,7 @@ abstract class BaseReaderAdapter<H : BasePageHolder<*>>(
|
|||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
): H
|
): H
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.cancelAndJoin
|
import kotlinx.coroutines.cancelAndJoin
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
@@ -16,9 +17,11 @@ import kotlinx.coroutines.flow.onEach
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.plus
|
import kotlinx.coroutines.plus
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@@ -26,6 +29,7 @@ class PageHolderDelegate(
|
|||||||
private val loader: PageLoader,
|
private val loader: PageLoader,
|
||||||
private val readerSettings: ReaderSettings,
|
private val readerSettings: ReaderSettings,
|
||||||
private val callback: Callback,
|
private val callback: Callback,
|
||||||
|
private val networkState: NetworkState,
|
||||||
private val exceptionResolver: ExceptionResolver,
|
private val exceptionResolver: ExceptionResolver,
|
||||||
) : DefaultOnImageEventListener, Observer<ReaderSettings> {
|
) : DefaultOnImageEventListener, Observer<ReaderSettings> {
|
||||||
|
|
||||||
@@ -118,29 +122,36 @@ class PageHolderDelegate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun CoroutineScope.doLoad(data: MangaPage, force: Boolean) {
|
private suspend fun doLoad(data: MangaPage, force: Boolean) {
|
||||||
state = State.LOADING
|
state = State.LOADING
|
||||||
error = null
|
error = null
|
||||||
callback.onLoadingStarted()
|
callback.onLoadingStarted()
|
||||||
try {
|
try {
|
||||||
val task = loader.loadPageAsync(data, force)
|
val task = loader.loadPageAsync(data, force)
|
||||||
val progressObserver = observeProgress(this, task.progressAsFlow())
|
file = coroutineScope {
|
||||||
val file = task.await()
|
val progressObserver = observeProgress(this, task.progressAsFlow())
|
||||||
progressObserver.cancel()
|
val file = task.await()
|
||||||
this@PageHolderDelegate.file = file
|
progressObserver.cancel()
|
||||||
|
file
|
||||||
|
}
|
||||||
state = State.LOADED
|
state = State.LOADED
|
||||||
callback.onImageReady(file.toUri())
|
callback.onImageReady(checkNotNull(file).toUri())
|
||||||
} catch (e: CancellationException) {
|
} catch (e: CancellationException) {
|
||||||
throw e
|
throw e
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
state = State.ERROR
|
state = State.ERROR
|
||||||
error = e
|
error = e
|
||||||
callback.onError(e)
|
callback.onError(e)
|
||||||
|
if (e is IOException && !networkState.value) {
|
||||||
|
networkState.awaitForConnection()
|
||||||
|
retry(data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeProgress(scope: CoroutineScope, progress: Flow<Float>) = progress
|
private fun observeProgress(scope: CoroutineScope, progress: Flow<Float>) = progress
|
||||||
.debounce(500)
|
.debounce(250)
|
||||||
.onEach { callback.onProgressChanged((100 * it).toInt()) }
|
.onEach { callback.onProgressChanged((100 * it).toInt()) }
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,24 @@ package org.koitharu.kotatsu.reader.ui.pager.reversed
|
|||||||
import android.graphics.PointF
|
import android.graphics.PointF
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
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.os.NetworkState
|
||||||
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.config.ReaderSettings
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.standard.PageHolder
|
import org.koitharu.kotatsu.reader.ui.pager.standard.PageHolder
|
||||||
|
|
||||||
class ReversedPageHolder(
|
class ReversedPageHolder(
|
||||||
|
owner: LifecycleOwner,
|
||||||
binding: ItemPageBinding,
|
binding: ItemPageBinding,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) : PageHolder(binding, loader, settings, exceptionResolver) {
|
) : PageHolder(owner, binding, loader, settings, networkState, exceptionResolver) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
(binding.textViewNumber.layoutParams as FrameLayout.LayoutParams)
|
(binding.textViewNumber.layoutParams as FrameLayout.LayoutParams)
|
||||||
@@ -35,6 +39,7 @@ class ReversedPageHolder(
|
|||||||
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
|
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
|
||||||
resetScaleAndCenter()
|
resetScaleAndCenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoomMode.FIT_HEIGHT -> {
|
ZoomMode.FIT_HEIGHT -> {
|
||||||
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CUSTOM
|
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CUSTOM
|
||||||
minScale = height / sHeight.toFloat()
|
minScale = height / sHeight.toFloat()
|
||||||
@@ -43,6 +48,7 @@ class ReversedPageHolder(
|
|||||||
PointF(sWidth.toFloat(), sHeight / 2f),
|
PointF(sWidth.toFloat(), sHeight / 2f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoomMode.FIT_WIDTH -> {
|
ZoomMode.FIT_WIDTH -> {
|
||||||
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CUSTOM
|
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CUSTOM
|
||||||
minScale = width / sWidth.toFloat()
|
minScale = width / sWidth.toFloat()
|
||||||
@@ -51,6 +57,7 @@ class ReversedPageHolder(
|
|||||||
PointF(sWidth / 2f, 0f),
|
PointF(sWidth / 2f, 0f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoomMode.KEEP_START -> {
|
ZoomMode.KEEP_START -> {
|
||||||
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
|
minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
|
||||||
setScaleAndCenter(
|
setScaleAndCenter(
|
||||||
|
|||||||
@@ -2,27 +2,34 @@ package org.koitharu.kotatsu.reader.ui.pager.reversed
|
|||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.databinding.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.config.ReaderSettings
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
|
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
|
||||||
|
|
||||||
class ReversedPagesAdapter(
|
class ReversedPagesAdapter(
|
||||||
|
private val lifecycleOwner: LifecycleOwner,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) : BaseReaderAdapter<ReversedPageHolder>(loader, settings, exceptionResolver) {
|
) : BaseReaderAdapter<ReversedPageHolder>(loader, settings, networkState, exceptionResolver) {
|
||||||
|
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) = ReversedPageHolder(
|
) = ReversedPageHolder(
|
||||||
|
owner = lifecycleOwner,
|
||||||
binding = ItemPageBinding.inflate(LayoutInflater.from(parent.context), parent, false),
|
binding = ItemPageBinding.inflate(LayoutInflater.from(parent.context), parent, false),
|
||||||
loader = loader,
|
loader = loader,
|
||||||
settings = settings,
|
settings = settings,
|
||||||
|
networkState = networkState,
|
||||||
exceptionResolver = exceptionResolver,
|
exceptionResolver = exceptionResolver,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlin.math.absoluteValue
|
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.databinding.FragmentReaderStandardBinding
|
import org.koitharu.kotatsu.databinding.FragmentReaderStandardBinding
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderState
|
import org.koitharu.kotatsu.reader.ui.ReaderState
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.BaseReader
|
import org.koitharu.kotatsu.reader.ui.pager.BaseReader
|
||||||
@@ -19,10 +19,15 @@ import org.koitharu.kotatsu.utils.ext.doOnPageChanged
|
|||||||
import org.koitharu.kotatsu.utils.ext.recyclerView
|
import org.koitharu.kotatsu.utils.ext.recyclerView
|
||||||
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
||||||
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ReversedReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
class ReversedReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var networkState: NetworkState
|
||||||
|
|
||||||
private var pagerAdapter: ReversedPagesAdapter? = null
|
private var pagerAdapter: ReversedPagesAdapter? = null
|
||||||
|
|
||||||
override fun onInflateView(
|
override fun onInflateView(
|
||||||
@@ -33,7 +38,13 @@ class ReversedReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
|||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
pagerAdapter = ReversedPagesAdapter(viewModel.pageLoader, viewModel.readerSettings, exceptionResolver)
|
pagerAdapter = ReversedPagesAdapter(
|
||||||
|
lifecycleOwner = viewLifecycleOwner,
|
||||||
|
loader = viewModel.pageLoader,
|
||||||
|
settings = viewModel.readerSettings,
|
||||||
|
networkState = networkState,
|
||||||
|
exceptionResolver = exceptionResolver,
|
||||||
|
)
|
||||||
with(binding.pager) {
|
with(binding.pager) {
|
||||||
adapter = pagerAdapter
|
adapter = pagerAdapter
|
||||||
offscreenPageLimit = 2
|
offscreenPageLimit = 2
|
||||||
@@ -44,8 +55,8 @@ class ReversedReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
|||||||
val transformer = if (it) ReversedPageAnimTransformer() else null
|
val transformer = if (it) ReversedPageAnimTransformer() else null
|
||||||
binding.pager.setPageTransformer(transformer)
|
binding.pager.setPageTransformer(transformer)
|
||||||
if (transformer == null) {
|
if (transformer == null) {
|
||||||
binding.pager.recyclerView?.children?.forEach {
|
binding.pager.recyclerView?.children?.forEach { v ->
|
||||||
it.resetTransformations()
|
v.resetTransformations()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ import android.graphics.PointF
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import com.davemorrissey.labs.subscaleview.ImageSource
|
import com.davemorrissey.labs.subscaleview.ImageSource
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
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.os.NetworkState
|
||||||
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.config.ReaderSettings
|
||||||
@@ -18,14 +20,17 @@ import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
|||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.*
|
||||||
|
|
||||||
open class PageHolder(
|
open class PageHolder(
|
||||||
|
owner: LifecycleOwner,
|
||||||
binding: ItemPageBinding,
|
binding: ItemPageBinding,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) : BasePageHolder<ItemPageBinding>(binding, loader, settings, exceptionResolver),
|
) : BasePageHolder<ItemPageBinding>(binding, loader, settings, networkState, exceptionResolver),
|
||||||
View.OnClickListener {
|
View.OnClickListener {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
binding.ssiv.bindToLifecycle(owner)
|
||||||
binding.ssiv.isEagerLoadingEnabled = !isLowRamDevice(context)
|
binding.ssiv.isEagerLoadingEnabled = !isLowRamDevice(context)
|
||||||
binding.ssiv.addOnImageEventListener(delegate)
|
binding.ssiv.addOnImageEventListener(delegate)
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
@@ -74,6 +79,7 @@ open class PageHolder(
|
|||||||
binding.ssiv.minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
|
binding.ssiv.minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
|
||||||
binding.ssiv.resetScaleAndCenter()
|
binding.ssiv.resetScaleAndCenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoomMode.FIT_HEIGHT -> {
|
ZoomMode.FIT_HEIGHT -> {
|
||||||
binding.ssiv.minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CUSTOM
|
binding.ssiv.minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CUSTOM
|
||||||
binding.ssiv.minScale = binding.ssiv.height / binding.ssiv.sHeight.toFloat()
|
binding.ssiv.minScale = binding.ssiv.height / binding.ssiv.sHeight.toFloat()
|
||||||
@@ -82,6 +88,7 @@ open class PageHolder(
|
|||||||
PointF(0f, binding.ssiv.sHeight / 2f),
|
PointF(0f, binding.ssiv.sHeight / 2f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoomMode.FIT_WIDTH -> {
|
ZoomMode.FIT_WIDTH -> {
|
||||||
binding.ssiv.minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CUSTOM
|
binding.ssiv.minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CUSTOM
|
||||||
binding.ssiv.minScale = binding.ssiv.width / binding.ssiv.sWidth.toFloat()
|
binding.ssiv.minScale = binding.ssiv.width / binding.ssiv.sWidth.toFloat()
|
||||||
@@ -90,6 +97,7 @@ open class PageHolder(
|
|||||||
PointF(binding.ssiv.sWidth / 2f, 0f),
|
PointF(binding.ssiv.sWidth / 2f, 0f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoomMode.KEEP_START -> {
|
ZoomMode.KEEP_START -> {
|
||||||
binding.ssiv.minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
|
binding.ssiv.minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE
|
||||||
binding.ssiv.setScaleAndCenter(
|
binding.ssiv.setScaleAndCenter(
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlin.math.absoluteValue
|
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.databinding.FragmentReaderStandardBinding
|
import org.koitharu.kotatsu.databinding.FragmentReaderStandardBinding
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderState
|
import org.koitharu.kotatsu.reader.ui.ReaderState
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.BaseReader
|
import org.koitharu.kotatsu.reader.ui.pager.BaseReader
|
||||||
@@ -18,10 +18,15 @@ import org.koitharu.kotatsu.utils.ext.doOnPageChanged
|
|||||||
import org.koitharu.kotatsu.utils.ext.recyclerView
|
import org.koitharu.kotatsu.utils.ext.recyclerView
|
||||||
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
||||||
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class PagerReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
class PagerReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var networkState: NetworkState
|
||||||
|
|
||||||
private var pagesAdapter: PagesAdapter? = null
|
private var pagesAdapter: PagesAdapter? = null
|
||||||
|
|
||||||
override fun onInflateView(
|
override fun onInflateView(
|
||||||
@@ -32,7 +37,13 @@ class PagerReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
|||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
pagesAdapter = PagesAdapter(viewModel.pageLoader, viewModel.readerSettings, exceptionResolver)
|
pagesAdapter = PagesAdapter(
|
||||||
|
lifecycleOwner = viewLifecycleOwner,
|
||||||
|
loader = viewModel.pageLoader,
|
||||||
|
settings = viewModel.readerSettings,
|
||||||
|
networkState = networkState,
|
||||||
|
exceptionResolver = exceptionResolver,
|
||||||
|
)
|
||||||
with(binding.pager) {
|
with(binding.pager) {
|
||||||
adapter = pagesAdapter
|
adapter = pagesAdapter
|
||||||
offscreenPageLimit = 2
|
offscreenPageLimit = 2
|
||||||
|
|||||||
@@ -2,27 +2,34 @@ package org.koitharu.kotatsu.reader.ui.pager.standard
|
|||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.databinding.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.config.ReaderSettings
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
|
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
|
||||||
|
|
||||||
class PagesAdapter(
|
class PagesAdapter(
|
||||||
|
private val lifecycleOwner: LifecycleOwner,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) : BaseReaderAdapter<PageHolder>(loader, settings, exceptionResolver) {
|
) : BaseReaderAdapter<PageHolder>(loader, settings, networkState, exceptionResolver) {
|
||||||
|
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) = PageHolder(
|
) = PageHolder(
|
||||||
|
owner = lifecycleOwner,
|
||||||
binding = ItemPageBinding.inflate(LayoutInflater.from(parent.context), parent, false),
|
binding = ItemPageBinding.inflate(LayoutInflater.from(parent.context), parent, false),
|
||||||
loader = loader,
|
loader = loader,
|
||||||
settings = settings,
|
settings = settings,
|
||||||
|
networkState = networkState,
|
||||||
exceptionResolver = exceptionResolver,
|
exceptionResolver = exceptionResolver,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,25 +2,30 @@ package org.koitharu.kotatsu.reader.ui.pager.webtoon
|
|||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
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.os.NetworkState
|
||||||
import org.koitharu.kotatsu.databinding.ItemPageWebtoonBinding
|
import org.koitharu.kotatsu.databinding.ItemPageWebtoonBinding
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
|
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
|
||||||
|
|
||||||
class WebtoonAdapter(
|
class WebtoonAdapter(
|
||||||
|
private val lifecycleOwner: LifecycleOwner,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) : BaseReaderAdapter<WebtoonHolder>(loader, settings, exceptionResolver) {
|
) : BaseReaderAdapter<WebtoonHolder>(loader, settings, networkState, exceptionResolver) {
|
||||||
|
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
parent: ViewGroup,
|
parent: ViewGroup,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) = WebtoonHolder(
|
) = WebtoonHolder(
|
||||||
|
owner = lifecycleOwner,
|
||||||
binding = ItemPageWebtoonBinding.inflate(
|
binding = ItemPageWebtoonBinding.inflate(
|
||||||
LayoutInflater.from(parent.context),
|
LayoutInflater.from(parent.context),
|
||||||
parent,
|
parent,
|
||||||
@@ -28,6 +33,7 @@ class WebtoonAdapter(
|
|||||||
),
|
),
|
||||||
loader = loader,
|
loader = loader,
|
||||||
settings = settings,
|
settings = settings,
|
||||||
|
networkState = networkState,
|
||||||
exceptionResolver = exceptionResolver,
|
exceptionResolver = exceptionResolver,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,31 +3,40 @@ package org.koitharu.kotatsu.reader.ui.pager.webtoon
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import com.davemorrissey.labs.subscaleview.ImageSource
|
import com.davemorrissey.labs.subscaleview.ImageSource
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
import com.davemorrissey.labs.subscaleview.decoder.SkiaPooledImageRegionDecoder
|
import com.davemorrissey.labs.subscaleview.decoder.SkiaPooledImageRegionDecoder
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.databinding.ItemPageWebtoonBinding
|
import org.koitharu.kotatsu.databinding.ItemPageWebtoonBinding
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.BasePageHolder
|
import org.koitharu.kotatsu.reader.ui.pager.BasePageHolder
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
||||||
import org.koitharu.kotatsu.utils.GoneOnInvisibleListener
|
import org.koitharu.kotatsu.utils.GoneOnInvisibleListener
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.hideCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.ifZero
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setProgressCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.showCompat
|
||||||
|
|
||||||
class WebtoonHolder(
|
class WebtoonHolder(
|
||||||
|
owner: LifecycleOwner,
|
||||||
binding: ItemPageWebtoonBinding,
|
binding: ItemPageWebtoonBinding,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
settings: ReaderSettings,
|
settings: ReaderSettings,
|
||||||
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) : BasePageHolder<ItemPageWebtoonBinding>(binding, loader, settings, exceptionResolver),
|
) : BasePageHolder<ItemPageWebtoonBinding>(binding, loader, settings, networkState, exceptionResolver),
|
||||||
View.OnClickListener {
|
View.OnClickListener {
|
||||||
|
|
||||||
private var scrollToRestore = 0
|
private var scrollToRestore = 0
|
||||||
private val goneOnInvisibleListener = GoneOnInvisibleListener(bindingInfo.progressBar)
|
private val goneOnInvisibleListener = GoneOnInvisibleListener(bindingInfo.progressBar)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
binding.ssiv.bindToLifecycle(owner)
|
||||||
binding.ssiv.regionDecoderFactory = SkiaPooledImageRegionDecoder.Factory()
|
binding.ssiv.regionDecoderFactory = SkiaPooledImageRegionDecoder.Factory()
|
||||||
binding.ssiv.addOnImageEventListener(delegate)
|
binding.ssiv.addOnImageEventListener(delegate)
|
||||||
bindingInfo.buttonRetry.setOnClickListener(this)
|
bindingInfo.buttonRetry.setOnClickListener(this)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.view.ViewGroup
|
|||||||
import android.view.animation.AccelerateDecelerateInterpolator
|
import android.view.animation.AccelerateDecelerateInterpolator
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.databinding.FragmentReaderWebtoonBinding
|
import org.koitharu.kotatsu.databinding.FragmentReaderWebtoonBinding
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderState
|
import org.koitharu.kotatsu.reader.ui.ReaderState
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.BaseReader
|
import org.koitharu.kotatsu.reader.ui.pager.BaseReader
|
||||||
@@ -15,10 +16,14 @@ import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
|||||||
import org.koitharu.kotatsu.utils.ext.findCenterViewPosition
|
import org.koitharu.kotatsu.utils.ext.findCenterViewPosition
|
||||||
import org.koitharu.kotatsu.utils.ext.firstVisibleItemPosition
|
import org.koitharu.kotatsu.utils.ext.firstVisibleItemPosition
|
||||||
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class WebtoonReaderFragment : BaseReader<FragmentReaderWebtoonBinding>() {
|
class WebtoonReaderFragment : BaseReader<FragmentReaderWebtoonBinding>() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var networkState: NetworkState
|
||||||
|
|
||||||
private val scrollInterpolator = AccelerateDecelerateInterpolator()
|
private val scrollInterpolator = AccelerateDecelerateInterpolator()
|
||||||
private var webtoonAdapter: WebtoonAdapter? = null
|
private var webtoonAdapter: WebtoonAdapter? = null
|
||||||
|
|
||||||
@@ -29,7 +34,13 @@ class WebtoonReaderFragment : BaseReader<FragmentReaderWebtoonBinding>() {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
webtoonAdapter = WebtoonAdapter(viewModel.pageLoader, viewModel.readerSettings, exceptionResolver)
|
webtoonAdapter = WebtoonAdapter(
|
||||||
|
lifecycleOwner = viewLifecycleOwner,
|
||||||
|
loader = viewModel.pageLoader,
|
||||||
|
settings = viewModel.readerSettings,
|
||||||
|
networkState = networkState,
|
||||||
|
exceptionResolver = exceptionResolver,
|
||||||
|
)
|
||||||
with(binding.recyclerView) {
|
with(binding.recyclerView) {
|
||||||
setHasFixedSize(true)
|
setHasFixedSize(true)
|
||||||
adapter = webtoonAdapter
|
adapter = webtoonAdapter
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class RemoteListViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
override val content = combine(
|
override val content = combine(
|
||||||
mangaList,
|
mangaList,
|
||||||
createListModeFlow(),
|
listModeFlow,
|
||||||
createHeaderFlow(),
|
createHeaderFlow(),
|
||||||
listError,
|
listError,
|
||||||
hasNextPage,
|
hasNextPage,
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class SearchViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
override val content = combine(
|
override val content = combine(
|
||||||
mangaList,
|
mangaList,
|
||||||
createListModeFlow(),
|
listModeFlow,
|
||||||
listError,
|
listError,
|
||||||
hasNextPage,
|
hasNextPage,
|
||||||
) { list, mode, error, hasNext ->
|
) { list, mode, error, hasNext ->
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import androidx.core.graphics.Insets
|
|||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
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.BaseActivity
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.base.ui.list.ListSelectionController
|
import org.koitharu.kotatsu.base.ui.list.ListSelectionController
|
||||||
@@ -27,11 +26,15 @@ import org.koitharu.kotatsu.list.ui.adapter.MangaListListener
|
|||||||
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
||||||
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.MangaTag
|
||||||
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
|
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
||||||
import org.koitharu.kotatsu.search.ui.SearchActivity
|
import org.koitharu.kotatsu.search.ui.SearchActivity
|
||||||
import org.koitharu.kotatsu.search.ui.multi.adapter.MultiSearchAdapter
|
import org.koitharu.kotatsu.search.ui.multi.adapter.MultiSearchAdapter
|
||||||
import org.koitharu.kotatsu.utils.ShareHelper
|
import org.koitharu.kotatsu.utils.ShareHelper
|
||||||
import org.koitharu.kotatsu.utils.ext.assistedViewModels
|
import org.koitharu.kotatsu.utils.ext.assistedViewModels
|
||||||
import org.koitharu.kotatsu.utils.ext.invalidateNestedItemDecorations
|
import org.koitharu.kotatsu.utils.ext.invalidateNestedItemDecorations
|
||||||
|
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MultiSearchActivity :
|
class MultiSearchActivity :
|
||||||
@@ -110,6 +113,20 @@ class MultiSearchActivity :
|
|||||||
return selectionController.onItemLongClick(item.id)
|
return selectionController.onItemLongClick(item.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onReadClick(manga: Manga, view: View) {
|
||||||
|
if (!selectionController.onItemClick(manga.id)) {
|
||||||
|
val intent = ReaderActivity.newIntent(this, manga)
|
||||||
|
startActivity(intent, scaleUpActivityOptionsOf(view).toBundle())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTagClick(manga: Manga, tag: MangaTag, view: View) {
|
||||||
|
if (!selectionController.onItemClick(manga.id)) {
|
||||||
|
val intent = MangaListActivity.newIntent(this, setOf(tag))
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRetryClick(error: Throwable) {
|
override fun onRetryClick(error: Throwable) {
|
||||||
viewModel.doSearch(viewModel.query.value.orEmpty())
|
viewModel.doSearch(viewModel.query.value.orEmpty())
|
||||||
}
|
}
|
||||||
@@ -139,16 +156,19 @@ class MultiSearchActivity :
|
|||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_favourite -> {
|
R.id.action_favourite -> {
|
||||||
FavouriteCategoriesBottomSheet.show(supportFragmentManager, collectSelectedItems())
|
FavouriteCategoriesBottomSheet.show(supportFragmentManager, collectSelectedItems())
|
||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_save -> {
|
R.id.action_save -> {
|
||||||
DownloadService.confirmAndStart(this, collectSelectedItems())
|
DownloadService.confirmAndStart(this, collectSelectedItems())
|
||||||
mode.finish()
|
mode.finish()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,13 @@ import androidx.preference.ListPreference
|
|||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
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.io.File
|
|
||||||
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
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BasePreferenceFragment
|
import org.koitharu.kotatsu.base.ui.BasePreferenceFragment
|
||||||
import org.koitharu.kotatsu.base.ui.dialog.StorageSelectDialog
|
import org.koitharu.kotatsu.base.ui.dialog.StorageSelectDialog
|
||||||
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
import org.koitharu.kotatsu.core.network.DoHProvider
|
import org.koitharu.kotatsu.core.network.DoHProvider
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
||||||
@@ -26,6 +25,8 @@ import org.koitharu.kotatsu.sync.ui.SyncSettingsIntent
|
|||||||
import org.koitharu.kotatsu.utils.ext.getStorageName
|
import org.koitharu.kotatsu.utils.ext.getStorageName
|
||||||
import org.koitharu.kotatsu.utils.ext.setDefaultValueCompat
|
import org.koitharu.kotatsu.utils.ext.setDefaultValueCompat
|
||||||
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||||
|
import java.io.File
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ContentSettingsFragment :
|
class ContentSettingsFragment :
|
||||||
@@ -36,9 +37,12 @@ class ContentSettingsFragment :
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var storageManager: LocalStorageManager
|
lateinit var storageManager: LocalStorageManager
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var contentCache: ContentCache
|
||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
addPreferencesFromResource(R.xml.pref_content)
|
addPreferencesFromResource(R.xml.pref_content)
|
||||||
|
findPreference<Preference>(AppSettings.KEY_PREFETCH_CONTENT)?.isVisible = contentCache.isCachingEnabled
|
||||||
findPreference<SliderPreference>(AppSettings.KEY_DOWNLOADS_PARALLELISM)?.run {
|
findPreference<SliderPreference>(AppSettings.KEY_DOWNLOADS_PARALLELISM)?.run {
|
||||||
summary = value.toString()
|
summary = value.toString()
|
||||||
setOnPreferenceChangeListener { preference, newValue ->
|
setOnPreferenceChangeListener { preference, newValue ->
|
||||||
@@ -82,11 +86,13 @@ class ContentSettingsFragment :
|
|||||||
AppSettings.KEY_LOCAL_STORAGE -> {
|
AppSettings.KEY_LOCAL_STORAGE -> {
|
||||||
findPreference<Preference>(key)?.bindStorageName()
|
findPreference<Preference>(key)?.bindStorageName()
|
||||||
}
|
}
|
||||||
|
|
||||||
AppSettings.KEY_SUGGESTIONS -> {
|
AppSettings.KEY_SUGGESTIONS -> {
|
||||||
findPreference<Preference>(AppSettings.KEY_SUGGESTIONS)?.setSummary(
|
findPreference<Preference>(AppSettings.KEY_SUGGESTIONS)?.setSummary(
|
||||||
if (settings.isSuggestionsEnabled) R.string.enabled else R.string.disabled,
|
if (settings.isSuggestionsEnabled) R.string.enabled else R.string.disabled,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
AppSettings.KEY_SOURCES_HIDDEN -> {
|
AppSettings.KEY_SOURCES_HIDDEN -> {
|
||||||
bindRemoteSourcesSummary()
|
bindRemoteSourcesSummary()
|
||||||
}
|
}
|
||||||
@@ -104,6 +110,7 @@ class ContentSettingsFragment :
|
|||||||
.show()
|
.show()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
AppSettings.KEY_SYNC -> {
|
AppSettings.KEY_SYNC -> {
|
||||||
val am = AccountManager.get(requireContext())
|
val am = AccountManager.get(requireContext())
|
||||||
val accountType = getString(R.string.account_type_sync)
|
val accountType = getString(R.string.account_type_sync)
|
||||||
@@ -119,6 +126,7 @@ class ContentSettingsFragment :
|
|||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> super.onPreferenceTreeClick(preference)
|
else -> super.onPreferenceTreeClick(preference)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import kotlinx.coroutines.CancellationException
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BasePreferenceFragment
|
import org.koitharu.kotatsu.base.ui.BasePreferenceFragment
|
||||||
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||||
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.local.data.CacheDir
|
import org.koitharu.kotatsu.local.data.CacheDir
|
||||||
@@ -41,7 +41,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
|
|||||||
lateinit var shikimoriRepository: ShikimoriRepository
|
lateinit var shikimoriRepository: ShikimoriRepository
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var cookieJar: AndroidCookieJar
|
lateinit var cookieJar: MutableCookieJar
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var shortcutsUpdater: ShortcutsUpdater
|
lateinit var shortcutsUpdater: ShortcutsUpdater
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ class SourceSettingsFragment : BasePreferenceFragment(0) {
|
|||||||
}.onSuccess { username ->
|
}.onSuccess { username ->
|
||||||
preference.title = getString(R.string.logged_in_as, username)
|
preference.title = getString(R.string.logged_in_as, username)
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
preference.isEnabled = error is AuthRequiredException
|
|
||||||
when {
|
when {
|
||||||
error is AuthRequiredException -> Unit
|
error is AuthRequiredException -> Unit
|
||||||
ExceptionResolver.canResolve(error) -> {
|
ExceptionResolver.canResolve(error) -> {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import androidx.core.view.isVisible
|
|||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.core.widget.TextViewCompat
|
import androidx.core.widget.TextViewCompat
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
import com.google.android.material.color.MaterialColors
|
import com.google.android.material.color.MaterialColors
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
@@ -30,6 +29,7 @@ import org.koitharu.kotatsu.settings.about.AppUpdateDialog
|
|||||||
import org.koitharu.kotatsu.settings.tools.model.StorageUsage
|
import org.koitharu.kotatsu.settings.tools.model.StorageUsage
|
||||||
import org.koitharu.kotatsu.utils.FileSize
|
import org.koitharu.kotatsu.utils.FileSize
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ToolsFragment :
|
class ToolsFragment :
|
||||||
@@ -48,6 +48,7 @@ class ToolsFragment :
|
|||||||
binding.buttonSettings.setOnClickListener(this)
|
binding.buttonSettings.setOnClickListener(this)
|
||||||
binding.buttonDownloads.setOnClickListener(this)
|
binding.buttonDownloads.setOnClickListener(this)
|
||||||
binding.cardUpdate.root.setOnClickListener(this)
|
binding.cardUpdate.root.setOnClickListener(this)
|
||||||
|
binding.cardUpdate.buttonChangelog.setOnClickListener(this)
|
||||||
binding.cardUpdate.buttonDownload.setOnClickListener(this)
|
binding.cardUpdate.buttonDownload.setOnClickListener(this)
|
||||||
binding.switchIncognito.setOnCheckedChangeListener(this)
|
binding.switchIncognito.setOnCheckedChangeListener(this)
|
||||||
|
|
||||||
@@ -69,10 +70,13 @@ class ToolsFragment :
|
|||||||
intent.data = url.toUri()
|
intent.data = url.toUri()
|
||||||
startActivity(Intent.createChooser(intent, getString(R.string.open_in_browser)))
|
startActivity(Intent.createChooser(intent, getString(R.string.open_in_browser)))
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.card_update -> {
|
R.id.card_update -> {
|
||||||
val version = viewModel.appUpdate.value ?: return
|
val version = viewModel.appUpdate.value ?: return
|
||||||
AppUpdateDialog(v.context).show(version)
|
AppUpdateDialog(v.context).show(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R.id.button_changelog -> showChangelog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,6 +145,13 @@ class ToolsFragment :
|
|||||||
return MaterialColors.harmonize(color, backgroundColor)
|
return MaterialColors.harmonize(color, backgroundColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showChangelog() {
|
||||||
|
TransitionManager.beginDelayedTransition(binding.cardUpdate.root)
|
||||||
|
binding.cardUpdate.buttonChangelog.isVisible = false
|
||||||
|
binding.cardUpdate.textSecondary.isVisible = true
|
||||||
|
binding.cardUpdate.textChangelog.isVisible = true
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newInstance() = ToolsFragment()
|
fun newInstance() = ToolsFragment()
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||||
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.core.os.NetworkStateObserver
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
import org.koitharu.kotatsu.core.prefs.ListMode
|
||||||
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
@@ -46,24 +46,29 @@ class ShelfViewModel @Inject constructor(
|
|||||||
private val favouritesRepository: FavouritesRepository,
|
private val favouritesRepository: FavouritesRepository,
|
||||||
private val trackingRepository: TrackingRepository,
|
private val trackingRepository: TrackingRepository,
|
||||||
private val settings: AppSettings,
|
private val settings: AppSettings,
|
||||||
networkStateObserver: NetworkStateObserver,
|
networkState: NetworkState,
|
||||||
) : BaseViewModel(), ListExtraProvider {
|
) : BaseViewModel(), ListExtraProvider {
|
||||||
|
|
||||||
val onActionDone = SingleLiveEvent<ReversibleAction>()
|
val onActionDone = SingleLiveEvent<ReversibleAction>()
|
||||||
|
|
||||||
val content: LiveData<List<ListModel>> = combine(
|
val content: LiveData<List<ListModel>> = combine(
|
||||||
settings.observeAsFlow(AppSettings.KEY_SHELF_SECTIONS) { shelfSections },
|
settings.observeAsFlow(AppSettings.KEY_SHELF_SECTIONS) { shelfSections },
|
||||||
networkStateObserver,
|
settings.observeAsFlow(AppSettings.KEY_TRACKER_ENABLED) { isTrackerEnabled },
|
||||||
|
networkState,
|
||||||
repository.observeShelfContent(),
|
repository.observeShelfContent(),
|
||||||
) { sections, isConnected, content ->
|
) { sections, isTrackerEnabled, isConnected, content ->
|
||||||
mapList(content, sections, isConnected)
|
mapList(content, isTrackerEnabled, sections, isConnected)
|
||||||
}.debounce(500)
|
}.debounce(500)
|
||||||
.catch { e ->
|
.catch { e ->
|
||||||
emit(listOf(e.toErrorState(canRetry = false)))
|
emit(listOf(e.toErrorState(canRetry = false)))
|
||||||
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
||||||
|
|
||||||
override suspend fun getCounter(mangaId: Long): Int {
|
override suspend fun getCounter(mangaId: Long): Int {
|
||||||
return trackingRepository.getNewChaptersCount(mangaId)
|
return if (settings.isTrackerEnabled) {
|
||||||
|
trackingRepository.getNewChaptersCount(mangaId)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getProgress(mangaId: Long): Float {
|
override suspend fun getProgress(mangaId: Long): Float {
|
||||||
@@ -135,6 +140,7 @@ class ShelfViewModel @Inject constructor(
|
|||||||
|
|
||||||
private suspend fun mapList(
|
private suspend fun mapList(
|
||||||
content: ShelfContent,
|
content: ShelfContent,
|
||||||
|
isTrackerEnabled: Boolean,
|
||||||
sections: List<ShelfSection>,
|
sections: List<ShelfSection>,
|
||||||
isNetworkAvailable: Boolean,
|
isNetworkAvailable: Boolean,
|
||||||
): List<ListModel> {
|
): List<ListModel> {
|
||||||
@@ -144,7 +150,10 @@ class ShelfViewModel @Inject constructor(
|
|||||||
when (section) {
|
when (section) {
|
||||||
ShelfSection.HISTORY -> mapHistory(result, content.history)
|
ShelfSection.HISTORY -> mapHistory(result, content.history)
|
||||||
ShelfSection.LOCAL -> mapLocal(result, content.local)
|
ShelfSection.LOCAL -> mapLocal(result, content.local)
|
||||||
ShelfSection.UPDATED -> mapUpdated(result, content.updated)
|
ShelfSection.UPDATED -> if (isTrackerEnabled) {
|
||||||
|
mapUpdated(result, content.updated)
|
||||||
|
}
|
||||||
|
|
||||||
ShelfSection.FAVORITES -> mapFavourites(result, content.favourites)
|
ShelfSection.FAVORITES -> mapFavourites(result, content.favourites)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,7 +203,7 @@ class ShelfViewModel @Inject constructor(
|
|||||||
val showPercent = settings.isReadingIndicatorsEnabled
|
val showPercent = settings.isReadingIndicatorsEnabled
|
||||||
destination += ShelfSectionModel.History(
|
destination += ShelfSectionModel.History(
|
||||||
items = list.map { (manga, history) ->
|
items = list.map { (manga, history) ->
|
||||||
val counter = trackingRepository.getNewChaptersCount(manga.id)
|
val counter = getCounter(manga.id)
|
||||||
val percent = if (showPercent) history.percent else PROGRESS_NONE
|
val percent = if (showPercent) history.percent else PROGRESS_NONE
|
||||||
manga.toGridModel(counter, percent)
|
manga.toGridModel(counter, percent)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ class ScrollKeepObserver(
|
|||||||
|
|
||||||
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
|
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
|
||||||
val position = minOf(toPosition, fromPosition) // if items are swapping positions may be swapped too
|
val position = minOf(toPosition, fromPosition) // if items are swapping positions may be swapped too
|
||||||
if (position < layoutManager.findFirstVisibleItemPosition()) {
|
if (position == 0 || position < layoutManager.findFirstVisibleItemPosition()) {
|
||||||
postScroll(position)
|
postScroll(position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||||
if (positionStart < layoutManager.findFirstVisibleItemPosition()) {
|
if (positionStart == 0 || positionStart < layoutManager.findFirstVisibleItemPosition()) {
|
||||||
postScroll(positionStart)
|
postScroll(positionStart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ class ShelfAdapter(
|
|||||||
.addDelegate(errorStateListAD(listener))
|
.addDelegate(errorStateListAD(listener))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSectionText(context: Context, position: Int): CharSequence {
|
override fun getSectionText(context: Context, position: Int): CharSequence? {
|
||||||
val item = items.getOrNull(position) as? ShelfSectionModel
|
val item = items.getOrNull(position) as? ShelfSectionModel ?: return null
|
||||||
return item?.getTitle(context.resources) ?: ""
|
return item.getTitle(context.resources)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DiffCallback : DiffUtil.ItemCallback<ListModel>() {
|
private class DiffCallback : DiffUtil.ItemCallback<ListModel>() {
|
||||||
|
|||||||
@@ -23,9 +23,10 @@ class ShelfSettingsViewModel @Inject constructor(
|
|||||||
|
|
||||||
val content = combine(
|
val content = combine(
|
||||||
settings.observeAsFlow(AppSettings.KEY_SHELF_SECTIONS) { shelfSections },
|
settings.observeAsFlow(AppSettings.KEY_SHELF_SECTIONS) { shelfSections },
|
||||||
|
settings.observeAsFlow(AppSettings.KEY_TRACKER_ENABLED) { isTrackerEnabled },
|
||||||
favouritesRepository.observeCategories(),
|
favouritesRepository.observeCategories(),
|
||||||
) { sections, categories ->
|
) { sections, isTrackerEnabled, categories ->
|
||||||
buildList(sections, categories)
|
buildList(sections, isTrackerEnabled, categories)
|
||||||
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, emptyList())
|
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, emptyList())
|
||||||
|
|
||||||
private var updateJob: Job? = null
|
private var updateJob: Job? = null
|
||||||
@@ -64,13 +65,18 @@ class ShelfSettingsViewModel @Inject constructor(
|
|||||||
|
|
||||||
private fun buildList(
|
private fun buildList(
|
||||||
sections: List<ShelfSection>,
|
sections: List<ShelfSection>,
|
||||||
|
isTrackerEnabled: Boolean,
|
||||||
categories: List<FavouriteCategory>
|
categories: List<FavouriteCategory>
|
||||||
): List<ShelfSettingsItemModel> {
|
): List<ShelfSettingsItemModel> {
|
||||||
val result = ArrayList<ShelfSettingsItemModel>()
|
val result = ArrayList<ShelfSettingsItemModel>()
|
||||||
val sectionsList = ShelfSection.values().toMutableList()
|
val sectionsList = ShelfSection.values().toMutableList()
|
||||||
|
if (!isTrackerEnabled) {
|
||||||
|
sectionsList.remove(ShelfSection.UPDATED)
|
||||||
|
}
|
||||||
for (section in sections) {
|
for (section in sections) {
|
||||||
sectionsList.remove(section)
|
if (sectionsList.remove(section)) {
|
||||||
result.addSection(section, true, categories)
|
result.addSection(section, true, categories)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (section in sectionsList) {
|
for (section in sectionsList) {
|
||||||
result.addSection(section, false, categories)
|
result.addSection(section, false, categories)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.koitharu.kotatsu.suggestions.ui
|
|||||||
|
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
@@ -17,6 +16,7 @@ import org.koitharu.kotatsu.list.ui.model.toUi
|
|||||||
import org.koitharu.kotatsu.suggestions.domain.SuggestionRepository
|
import org.koitharu.kotatsu.suggestions.domain.SuggestionRepository
|
||||||
import org.koitharu.kotatsu.utils.asFlowLiveData
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
import org.koitharu.kotatsu.utils.ext.onFirst
|
import org.koitharu.kotatsu.utils.ext.onFirst
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class SuggestionsViewModel @Inject constructor(
|
class SuggestionsViewModel @Inject constructor(
|
||||||
@@ -26,7 +26,7 @@ class SuggestionsViewModel @Inject constructor(
|
|||||||
|
|
||||||
override val content = combine(
|
override val content = combine(
|
||||||
repository.observeAll(),
|
repository.observeAll(),
|
||||||
createListModeFlow(),
|
listModeFlow,
|
||||||
) { list, mode ->
|
) { list, mode ->
|
||||||
when {
|
when {
|
||||||
list.isEmpty() -> listOf(
|
list.isEmpty() -> listOf(
|
||||||
@@ -37,6 +37,7 @@ class SuggestionsViewModel @Inject constructor(
|
|||||||
actionStringRes = 0,
|
actionStringRes = 0,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> list.toUi(mode)
|
else -> list.toUi(mode)
|
||||||
}
|
}
|
||||||
}.onStart {
|
}.onStart {
|
||||||
|
|||||||
@@ -5,16 +5,17 @@ import android.accounts.AccountManager
|
|||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.ArrayMap
|
import androidx.collection.ArrayMap
|
||||||
import androidx.room.InvalidationTracker
|
import androidx.room.InvalidationTracker
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import java.util.concurrent.TimeUnit
|
import kotlinx.coroutines.Dispatchers
|
||||||
import javax.inject.Inject
|
import kotlinx.coroutines.Job
|
||||||
import javax.inject.Singleton
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.*
|
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 org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
@@ -22,6 +23,9 @@ import org.koitharu.kotatsu.core.db.TABLE_FAVOURITES
|
|||||||
import org.koitharu.kotatsu.core.db.TABLE_FAVOURITE_CATEGORIES
|
import org.koitharu.kotatsu.core.db.TABLE_FAVOURITE_CATEGORIES
|
||||||
import org.koitharu.kotatsu.core.db.TABLE_HISTORY
|
import org.koitharu.kotatsu.core.db.TABLE_HISTORY
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class SyncController @Inject constructor(
|
class SyncController @Inject constructor(
|
||||||
|
|||||||
@@ -144,6 +144,10 @@ class FeedFragment :
|
|||||||
startActivity(DetailsActivity.newIntent(context ?: return, item))
|
startActivity(DetailsActivity.newIntent(context ?: return, item))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onReadClick(manga: Manga, view: View) = Unit
|
||||||
|
|
||||||
|
override fun onTagClick(manga: Manga, tag: MangaTag, view: View) = Unit
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newInstance() = FeedFragment()
|
fun newInstance() = FeedFragment()
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class UpdatesViewModel @Inject constructor(
|
|||||||
|
|
||||||
override val content = combine(
|
override val content = combine(
|
||||||
repository.observeUpdatedManga(),
|
repository.observeUpdatedManga(),
|
||||||
createListModeFlow(),
|
listModeFlow,
|
||||||
) { mangaMap, mode ->
|
) { mangaMap, mode ->
|
||||||
when {
|
when {
|
||||||
mangaMap.isEmpty() -> listOf(
|
mangaMap.isEmpty() -> listOf(
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package org.koitharu.kotatsu.utils
|
package org.koitharu.kotatsu.utils
|
||||||
|
|
||||||
import android.util.ArrayMap
|
import androidx.collection.ArrayMap
|
||||||
import java.util.*
|
|
||||||
import kotlin.coroutines.coroutineContext
|
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlinx.coroutines.CancellableContinuation
|
import kotlinx.coroutines.CancellableContinuation
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import java.util.LinkedList
|
||||||
|
import kotlin.coroutines.coroutineContext
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
|
||||||
class CompositeMutex<T : Any> : Set<T> {
|
class CompositeMutex<T : Any> : Set<T> {
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ class CompositeMutex<T : Any> : Set<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun isEmpty(): Boolean {
|
override fun isEmpty(): Boolean {
|
||||||
return data.isEmpty()
|
return data.isEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun iterator(): Iterator<T> {
|
override fun iterator(): Iterator<T> {
|
||||||
@@ -59,7 +59,7 @@ class CompositeMutex<T : Any> : Set<T> {
|
|||||||
|
|
||||||
private suspend fun waitForRemoval(element: T) {
|
private suspend fun waitForRemoval(element: T) {
|
||||||
val list = data[element] ?: return
|
val list = data[element] ?: return
|
||||||
suspendCancellableCoroutine<Unit> { continuation ->
|
suspendCancellableCoroutine { continuation ->
|
||||||
list.add(continuation)
|
list.add(continuation)
|
||||||
continuation.invokeOnCancellation {
|
continuation.invokeOnCancellation {
|
||||||
list.remove(continuation)
|
list.remove(continuation)
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package org.koitharu.kotatsu.utils
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.FlowCollector
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
|
abstract class MediatorStateFlow<T>(initialValue: T) : StateFlow<T> {
|
||||||
|
|
||||||
|
private val delegate = MutableStateFlow(initialValue)
|
||||||
|
private val collectors = AtomicInteger(0)
|
||||||
|
|
||||||
|
final override val replayCache: List<T>
|
||||||
|
get() = delegate.replayCache
|
||||||
|
|
||||||
|
final override val value: T
|
||||||
|
get() = delegate.value
|
||||||
|
|
||||||
|
final override suspend fun collect(collector: FlowCollector<T>): Nothing {
|
||||||
|
try {
|
||||||
|
if (collectors.getAndIncrement() == 0) {
|
||||||
|
onActive()
|
||||||
|
}
|
||||||
|
delegate.collect(collector)
|
||||||
|
} finally {
|
||||||
|
if (collectors.decrementAndGet() == 0) {
|
||||||
|
onInactive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun publishValue(v: T) {
|
||||||
|
delegate.value = v
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun onActive()
|
||||||
|
|
||||||
|
abstract fun onInactive()
|
||||||
|
}
|
||||||
@@ -5,12 +5,16 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.speech.RecognizerIntent
|
import android.speech.RecognizerIntent
|
||||||
import androidx.activity.result.contract.ActivityResultContract
|
import androidx.activity.result.contract.ActivityResultContract
|
||||||
|
import androidx.core.os.ConfigurationCompat
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
class VoiceInputContract : ActivityResultContract<String?, String?>() {
|
class VoiceInputContract : ActivityResultContract<String?, String?>() {
|
||||||
|
|
||||||
override fun createIntent(context: Context, input: String?): Intent {
|
override fun createIntent(context: Context, input: String?): Intent {
|
||||||
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
|
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
|
||||||
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
|
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
|
||||||
|
val locale = ConfigurationCompat.getLocales(context.resources.configuration).get(0) ?: Locale.getDefault()
|
||||||
|
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, locale.toLanguageTag())
|
||||||
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, input)
|
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, input)
|
||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
@@ -23,4 +27,4 @@ class VoiceInputContract : ActivityResultContract<String?, String?>() {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ fun File.subdir(name: String) = File(this, name).also {
|
|||||||
|
|
||||||
fun File.takeIfReadable() = takeIf { it.exists() && it.canRead() }
|
fun File.takeIfReadable() = takeIf { it.exists() && it.canRead() }
|
||||||
|
|
||||||
|
fun File.takeIfWriteable() = takeIf { it.exists() && it.canWrite() }
|
||||||
|
|
||||||
fun ZipFile.readText(entry: ZipEntry) = getInputStream(entry).bufferedReader().use {
|
fun ZipFile.readText(entry: ZipEntry) = getInputStream(entry).bufferedReader().use {
|
||||||
it.readText()
|
it.readText()
|
||||||
}
|
}
|
||||||
@@ -74,4 +76,4 @@ private fun computeSizeInternal(file: File): Long {
|
|||||||
} else {
|
} else {
|
||||||
return file.length()
|
return file.length()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
app/src/main/java/org/koitharu/kotatsu/utils/ext/IO.kt
Normal file
34
app/src/main/java/org/koitharu/kotatsu/utils/ext/IO.kt
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package org.koitharu.kotatsu.utils.ext
|
||||||
|
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
|
import kotlinx.coroutines.ensureActive
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import org.koitharu.kotatsu.utils.progress.ProgressResponseBody
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
|
|
||||||
|
suspend fun InputStream.copyToSuspending(
|
||||||
|
out: OutputStream,
|
||||||
|
bufferSize: Int = DEFAULT_BUFFER_SIZE
|
||||||
|
): Long = withContext(Dispatchers.IO) {
|
||||||
|
val job = currentCoroutineContext()[Job]
|
||||||
|
var bytesCopied: Long = 0
|
||||||
|
val buffer = ByteArray(bufferSize)
|
||||||
|
var bytes = read(buffer)
|
||||||
|
while (bytes >= 0) {
|
||||||
|
out.write(buffer, 0, bytes)
|
||||||
|
bytesCopied += bytes
|
||||||
|
job?.ensureActive()
|
||||||
|
bytes = read(buffer)
|
||||||
|
job?.ensureActive()
|
||||||
|
}
|
||||||
|
bytesCopied
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ResponseBody.withProgress(progressState: MutableStateFlow<Float>): ResponseBody {
|
||||||
|
return ProgressResponseBody(this, progressState)
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user