Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
af103aa
Fix typo: serizliation -> serialization in Gradle configuration
AgentKush Jan 21, 2026
388ed31
Fix: Implement info menu action in ReaderMenuProvider
AgentKush Jan 21, 2026
67e2bc9
Fix: Add documentation for page count mismatch handling in ReaderView…
AgentKush Jan 21, 2026
0733353
Fix: Replace internal PlatformRegistry API with OkHttp.initialize
AgentKush Jan 21, 2026
129bef3
Implement TODO items: onTrimMemory and TIP spacing
AgentKush Jan 21, 2026
84f7698
Implement adaptive prefetch queue limit based on RAM, network, and po…
AgentKush Jan 21, 2026
aafde60
Localize WebView proxy unsupported error message
AgentKush Jan 21, 2026
0df96fa
Clean up stale TODO/FIXME comments and improve code documentation
AgentKush Jan 21, 2026
17e87f1
Implement adblock CSS element hiding and domain modifiers
AgentKush Jan 21, 2026
e4ef5bc
Implement directory sharing support for local manga
AgentKush Jan 21, 2026
f95e139
Improve UX for missing chapters and clean up remaining TODOs
AgentKush Jan 21, 2026
ac2e165
Update kotatsu-parsers to v1.2
AgentKush Jan 22, 2026
42510b3
Add configurable JS timeout for WebView evaluation
AgentKush Jan 22, 2026
74dba9f
Add configurable compression format options to BitmapWrapper
AgentKush Jan 22, 2026
c906f70
Add persistent blacklist with TTL to MirrorSwitcher
AgentKush Jan 22, 2026
f4dc2ec
Add related manga support for external plugins
AgentKush Jan 22, 2026
4088fb9
Add exponential backoff retry to RateLimitInterceptor
AgentKush Jan 22, 2026
1d56aa7
Add persistent blacklist for image proxy interceptors
AgentKush Jan 22, 2026
e529452
Add configurable TTL for memory content caches
AgentKush Jan 22, 2026
098c31b
Add configurable parallel chapter checking for tracker
AgentKush Jan 22, 2026
0c9ebd9
feat: Implement Scrobbler Offline Queue (#5)
AgentKush Jan 22, 2026
f2f8190
feat: Implement Network Quality Adaptive Behavior (#6)
AgentKush Jan 22, 2026
65a0879
feat: Implement DNS Prefetching for Common Domains (#7)
AgentKush Jan 22, 2026
e2f97b5
feat: Implement Download Resume Support (#8)
AgentKush Jan 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/src/main/kotlin/org/koitharu/kotatsu/core/BaseApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch
import okhttp3.internal.platform.PlatformRegistry
import okhttp3.OkHttp
import org.acra.ACRA
import org.acra.ReportField
import org.acra.config.dialog
Expand All @@ -26,6 +26,7 @@ import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.db.MangaDatabase
import org.koitharu.kotatsu.core.os.AppValidator
import org.koitharu.kotatsu.core.os.RomCompat
import org.koitharu.kotatsu.core.network.DnsPrefetchManager
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.util.ext.processLifecycleScope
import org.koitharu.kotatsu.local.data.LocalStorageChanges
Expand Down Expand Up @@ -61,6 +62,9 @@ open class BaseApp : Application(), Configuration.Provider {
@Inject
lateinit var workScheduleManager: WorkScheduleManager

@Inject
lateinit var dnsPrefetchManager: DnsPrefetchManager

@Inject
lateinit var localMangaIndexProvider: Provider<LocalMangaIndex>

Expand All @@ -75,7 +79,7 @@ open class BaseApp : Application(), Configuration.Provider {

override fun onCreate() {
super.onCreate()
PlatformRegistry.applicationContext = this // TODO replace with OkHttp.initialize
OkHttp.initialize(this)
if (ACRA.isACRASenderServiceProcess()) {
return
}
Expand All @@ -94,6 +98,7 @@ open class BaseApp : Application(), Configuration.Provider {
localStorageChanges.collect(localMangaIndexProvider.get())
}
workScheduleManager.init()
dnsPrefetchManager.initialize()
}

override fun attachBaseContext(base: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.koitharu.kotatsu.core.cache
import android.app.Application
import android.content.ComponentCallbacks2
import android.content.res.Configuration
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.util.ext.isLowRamDevice
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaPage
Expand All @@ -11,16 +12,41 @@ import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton

/**
* In-memory cache for manga content with configurable TTL.
*
* Cache TTL settings can be configured in AppSettings:
* - Details cache: default 5 minutes (configurable 1-60 min)
* - Pages cache: default 10 minutes (configurable 1-120 min)
* - Related manga cache: default 10 minutes (configurable 1-120 min)
*
* Note: Changes to TTL settings require app restart to take effect.
*/
@Singleton
class MemoryContentCache @Inject constructor(application: Application) : ComponentCallbacks2 {
class MemoryContentCache @Inject constructor(
application: Application,
settings: AppSettings,
) : ComponentCallbacks2 {

private val isLowRam = application.isLowRamDevice()

private val detailsCache = ExpiringLruCache<SafeDeferred<Manga>>(if (isLowRam) 1 else 4, 5, TimeUnit.MINUTES)
private val pagesCache =
ExpiringLruCache<SafeDeferred<List<MangaPage>>>(if (isLowRam) 1 else 4, 10, TimeUnit.MINUTES)
private val relatedMangaCache =
ExpiringLruCache<SafeDeferred<List<Manga>>>(if (isLowRam) 1 else 3, 10, TimeUnit.MINUTES)
private val detailsCache = ExpiringLruCache<SafeDeferred<Manga>>(
maxSize = if (isLowRam) 1 else 4,
lifetime = settings.cacheDetailsTtlMinutes.toLong(),
timeUnit = TimeUnit.MINUTES,
)

private val pagesCache = ExpiringLruCache<SafeDeferred<List<MangaPage>>>(
maxSize = if (isLowRam) 1 else 4,
lifetime = settings.cachePagesTtlMinutes.toLong(),
timeUnit = TimeUnit.MINUTES,
)

private val relatedMangaCache = ExpiringLruCache<SafeDeferred<List<Manga>>>(
maxSize = if (isLowRam) 1 else 3,
lifetime = settings.cacheRelatedTtlMinutes.toLong(),
timeUnit = TimeUnit.MINUTES,
)

init {
application.registerComponentCallbacks(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.koitharu.kotatsu.core.exceptions

/**
* Exception thrown when the device's WebView implementation does not support proxy configuration.
* This typically occurs on older Android versions or devices with outdated WebView providers.
*/
class ProxyWebViewUnsupportedException : IllegalStateException("Proxy for WebView is not supported on this device")
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class CaptchaHandler @Inject constructor(
notify = request.extras[suppressCaptchaKey] != true,
)
) {
coilProvider.get().enqueue(request) // TODO check if ok
// Retry the failed request now that captcha is resolved
coilProvider.get().enqueue(request)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
import org.koitharu.kotatsu.core.exceptions.EmptyMangaException
import org.koitharu.kotatsu.core.exceptions.InteractiveActionRequiredException
import org.koitharu.kotatsu.core.exceptions.ProxyConfigException
import org.koitharu.kotatsu.core.exceptions.ProxyWebViewUnsupportedException
import org.koitharu.kotatsu.core.exceptions.UnsupportedSourceException
import org.koitharu.kotatsu.core.nav.AppRouter
import org.koitharu.kotatsu.core.nav.router
Expand Down
38 changes: 35 additions & 3 deletions app/src/main/kotlin/org/koitharu/kotatsu/core/nav/AppRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -640,16 +640,45 @@ class AppRouter private constructor(
.startChooser()
}

private fun shareFile(file: File) { // TODO directory sharing support
private fun shareFile(file: File) {
val context = contextOrNull() ?: return
if (file.isDirectory) {
shareDirectory(file, context)
} else {
shareSingleFile(file, context)
}
}

private fun shareSingleFile(file: File, context: Context) {
val mimeType = when {
file.extension.equals("cbz", ignoreCase = true) -> TYPE_CBZ
file.extension.equals("cbr", ignoreCase = true) -> TYPE_CBR
file.extension.equals("zip", ignoreCase = true) -> TYPE_ZIP
else -> TYPE_OCTET_STREAM
}
val intentBuilder = ShareCompat.IntentBuilder(context)
.setType(TYPE_CBZ)
.setType(mimeType)
val uri = FileProvider.getUriForFile(context, "${BuildConfig.APPLICATION_ID}.files", file)
intentBuilder.addStream(uri)
intentBuilder.setChooserTitle(context.getString(R.string.share_s, file.name))
intentBuilder.startChooser()
}

private fun shareDirectory(directory: File, context: Context) {
val files = directory.listFiles { f -> f.isFile && !f.isHidden }
if (files.isNullOrEmpty()) {
return
}
val intentBuilder = ShareCompat.IntentBuilder(context)
.setType(TYPE_IMAGE)
for (file in files) {
val uri = FileProvider.getUriForFile(context, "${BuildConfig.APPLICATION_ID}.files", file)
intentBuilder.addStream(uri)
}
intentBuilder.setChooserTitle(context.getString(R.string.share_s, directory.name))
intentBuilder.startChooser()
}

@UiContext
private fun contextOrNull(): Context? = activity ?: fragment?.context

Expand Down Expand Up @@ -854,8 +883,11 @@ class AppRouter private constructor(
private const val TYPE_TEXT = "text/plain"
private const val TYPE_IMAGE = "image/*"
private const val TYPE_CBZ = "application/x-cbz"
private const val TYPE_CBR = "application/x-cbr"
private const val TYPE_ZIP = "application/zip"
private const val TYPE_OCTET_STREAM = "application/octet-stream"

private fun Class<out Fragment>.fragmentTag() = name // TODO
private fun Class<out Fragment>.fragmentTag() = name

private inline fun <reified F : Fragment> fragmentTag() = F::class.java.fragmentTag()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package org.koitharu.kotatsu.core.network

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject
import javax.inject.Singleton

/**
* Provides adaptive network settings based on current network quality.
* Use this class to get dynamic settings that adjust to network conditions.
*/
@Singleton
class AdaptiveNetworkSettings @Inject constructor(
private val networkQualityMonitor: NetworkQualityMonitor,
) {
/**
* Current network quality level.
*/
val quality: Flow<NetworkQuality>
get() = networkQualityMonitor.quality

/**
* Current quality value (for synchronous access).
*/
val currentQuality: NetworkQuality
get() = networkQualityMonitor.quality.value

/**
* Observable settings that update when network quality changes.
*/
val adaptiveSettings: Flow<Settings> = networkQualityMonitor.quality.map { quality ->
Settings(
quality = quality,
connectTimeoutMs = getConnectTimeout(quality),
readTimeoutMs = getReadTimeout(quality),
writeTimeoutMs = getWriteTimeout(quality),
maxConcurrentDownloads = getMaxConcurrentDownloads(quality),
preloadPageCount = getPreloadPageCount(quality),
imageQualityReduction = getImageQualityReduction(quality),
retryCount = getRetryCount(quality),
retryDelayMs = getRetryDelay(quality),
enableAggressiveCache = shouldEnableAggressiveCache(quality),
)
}

/**
* Get current settings snapshot.
*/
fun getCurrentSettings(): Settings {
val quality = currentQuality
return Settings(
quality = quality,
connectTimeoutMs = getConnectTimeout(quality),
readTimeoutMs = getReadTimeout(quality),
writeTimeoutMs = getWriteTimeout(quality),
maxConcurrentDownloads = getMaxConcurrentDownloads(quality),
preloadPageCount = getPreloadPageCount(quality),
imageQualityReduction = getImageQualityReduction(quality),
retryCount = getRetryCount(quality),
retryDelayMs = getRetryDelay(quality),
enableAggressiveCache = shouldEnableAggressiveCache(quality),
)
}

/**
* Report a successful download for bandwidth estimation.
*/
fun reportDownload(bytes: Long, durationMs: Long) {
networkQualityMonitor.reportDownload(bytes, durationMs)
}

private fun getConnectTimeout(quality: NetworkQuality): Long {
return when (quality) {
NetworkQuality.EXCELLENT -> 10_000L
NetworkQuality.GOOD -> 15_000L
NetworkQuality.MODERATE -> 20_000L
NetworkQuality.POOR -> 30_000L
NetworkQuality.OFFLINE -> 15_000L
}
}

private fun getReadTimeout(quality: NetworkQuality): Long {
return when (quality) {
NetworkQuality.EXCELLENT -> 30_000L
NetworkQuality.GOOD -> 45_000L
NetworkQuality.MODERATE -> 60_000L
NetworkQuality.POOR -> 90_000L
NetworkQuality.OFFLINE -> 60_000L
}
}

private fun getWriteTimeout(quality: NetworkQuality): Long {
return when (quality) {
NetworkQuality.EXCELLENT -> 15_000L
NetworkQuality.GOOD -> 20_000L
NetworkQuality.MODERATE -> 25_000L
NetworkQuality.POOR -> 40_000L
NetworkQuality.OFFLINE -> 20_000L
}
}

private fun getMaxConcurrentDownloads(quality: NetworkQuality): Int {
return when (quality) {
NetworkQuality.EXCELLENT -> 6
NetworkQuality.GOOD -> 4
NetworkQuality.MODERATE -> 2
NetworkQuality.POOR -> 1
NetworkQuality.OFFLINE -> 0
}
}

private fun getPreloadPageCount(quality: NetworkQuality): Int {
return when (quality) {
NetworkQuality.EXCELLENT -> 5
NetworkQuality.GOOD -> 3
NetworkQuality.MODERATE -> 1
NetworkQuality.POOR -> 0
NetworkQuality.OFFLINE -> 0
}
}

/**
* Returns image quality reduction factor (0-100).
* 0 = full quality, 100 = maximum reduction
*/
private fun getImageQualityReduction(quality: NetworkQuality): Int {
return when (quality) {
NetworkQuality.EXCELLENT -> 0
NetworkQuality.GOOD -> 0
NetworkQuality.MODERATE -> 20
NetworkQuality.POOR -> 40
NetworkQuality.OFFLINE -> 0
}
}

private fun getRetryCount(quality: NetworkQuality): Int {
return when (quality) {
NetworkQuality.EXCELLENT -> 2
NetworkQuality.GOOD -> 3
NetworkQuality.MODERATE -> 4
NetworkQuality.POOR -> 5
NetworkQuality.OFFLINE -> 3
}
}

private fun getRetryDelay(quality: NetworkQuality): Long {
return when (quality) {
NetworkQuality.EXCELLENT -> 500L
NetworkQuality.GOOD -> 1_000L
NetworkQuality.MODERATE -> 2_000L
NetworkQuality.POOR -> 4_000L
NetworkQuality.OFFLINE -> 1_000L
}
}

private fun shouldEnableAggressiveCache(quality: NetworkQuality): Boolean {
return when (quality) {
NetworkQuality.EXCELLENT -> false
NetworkQuality.GOOD -> false
NetworkQuality.MODERATE -> true
NetworkQuality.POOR -> true
NetworkQuality.OFFLINE -> true
}
}

/**
* Adaptive network settings snapshot.
*/
data class Settings(
val quality: NetworkQuality,
val connectTimeoutMs: Long,
val readTimeoutMs: Long,
val writeTimeoutMs: Long,
val maxConcurrentDownloads: Int,
val preloadPageCount: Int,
val imageQualityReduction: Int,
val retryCount: Int,
val retryDelayMs: Long,
val enableAggressiveCache: Boolean,
) {
/**
* Check if downloads should be allowed.
*/
val allowsDownloads: Boolean
get() = quality.isConnected

/**
* Check if preloading is recommended.
*/
val allowsPreloading: Boolean
get() = quality.allowsPreloading

/**
* Check if high quality images should be used.
*/
val allowsHighQuality: Boolean
get() = quality.allowsHighQuality
}
}
Loading