Fix crashes
This commit is contained in:
@@ -16,16 +16,16 @@ class MemoryContentCache @Inject constructor(application: Application) : Compone
|
|||||||
|
|
||||||
private val isLowRam = application.isLowRamDevice()
|
private val isLowRam = application.isLowRamDevice()
|
||||||
|
|
||||||
init {
|
|
||||||
application.registerComponentCallbacks(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val detailsCache = ExpiringLruCache<SafeDeferred<Manga>>(if (isLowRam) 1 else 4, 5, TimeUnit.MINUTES)
|
private val detailsCache = ExpiringLruCache<SafeDeferred<Manga>>(if (isLowRam) 1 else 4, 5, TimeUnit.MINUTES)
|
||||||
private val pagesCache =
|
private val pagesCache =
|
||||||
ExpiringLruCache<SafeDeferred<List<MangaPage>>>(if (isLowRam) 1 else 4, 10, TimeUnit.MINUTES)
|
ExpiringLruCache<SafeDeferred<List<MangaPage>>>(if (isLowRam) 1 else 4, 10, TimeUnit.MINUTES)
|
||||||
private val relatedMangaCache =
|
private val relatedMangaCache =
|
||||||
ExpiringLruCache<SafeDeferred<List<Manga>>>(if (isLowRam) 1 else 3, 10, TimeUnit.MINUTES)
|
ExpiringLruCache<SafeDeferred<List<Manga>>>(if (isLowRam) 1 else 3, 10, TimeUnit.MINUTES)
|
||||||
|
|
||||||
|
init {
|
||||||
|
application.registerComponentCallbacks(this)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun getDetails(source: MangaSource, url: String): Manga? {
|
suspend fun getDetails(source: MangaSource, url: String): Manga? {
|
||||||
return detailsCache[Key(source, url)]?.awaitOrNull()
|
return detailsCache[Key(source, url)]?.awaitOrNull()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.koitharu.kotatsu.core.prefs
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import okhttp3.internal.isSensitiveHeader
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.getEnumValue
|
import org.koitharu.kotatsu.core.util.ext.getEnumValue
|
||||||
import org.koitharu.kotatsu.core.util.ext.ifNullOrEmpty
|
import org.koitharu.kotatsu.core.util.ext.ifNullOrEmpty
|
||||||
import org.koitharu.kotatsu.core.util.ext.putEnumValue
|
import org.koitharu.kotatsu.core.util.ext.putEnumValue
|
||||||
@@ -12,6 +11,7 @@ import org.koitharu.kotatsu.parsers.config.ConfigKey
|
|||||||
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.parsers.model.SortOrder
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
import org.koitharu.kotatsu.settings.utils.validation.DomainValidator
|
||||||
|
|
||||||
class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig {
|
class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig {
|
||||||
|
|
||||||
@@ -31,7 +31,11 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig
|
|||||||
.ifNullOrEmpty { key.defaultValue }
|
.ifNullOrEmpty { key.defaultValue }
|
||||||
.sanitizeHeaderValue()
|
.sanitizeHeaderValue()
|
||||||
|
|
||||||
is ConfigKey.Domain -> prefs.getString(key.key, key.defaultValue).ifNullOrEmpty { key.defaultValue }
|
is ConfigKey.Domain -> prefs.getString(key.key, key.defaultValue)
|
||||||
|
?.trim()
|
||||||
|
?.takeIf { DomainValidator.isValidDomain(it) }
|
||||||
|
?: key.defaultValue
|
||||||
|
|
||||||
is ConfigKey.ShowSuspiciousContent -> prefs.getBoolean(key.key, key.defaultValue)
|
is ConfigKey.ShowSuspiciousContent -> prefs.getBoolean(key.key, key.defaultValue)
|
||||||
is ConfigKey.SplitByTranslations -> prefs.getBoolean(key.key, key.defaultValue)
|
is ConfigKey.SplitByTranslations -> prefs.getBoolean(key.key, key.defaultValue)
|
||||||
} as T
|
} as T
|
||||||
|
|||||||
@@ -11,20 +11,24 @@ class DomainValidator : EditTextValidator() {
|
|||||||
if (trimmed.isEmpty()) {
|
if (trimmed.isEmpty()) {
|
||||||
return ValidationResult.Success
|
return ValidationResult.Success
|
||||||
}
|
}
|
||||||
return if (!checkCharacters(trimmed)) {
|
return if (!isValidDomain(trimmed)) {
|
||||||
ValidationResult.Failed(context.getString(R.string.invalid_domain_message))
|
ValidationResult.Failed(context.getString(R.string.invalid_domain_message))
|
||||||
} else {
|
} else {
|
||||||
ValidationResult.Success
|
ValidationResult.Success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkCharacters(value: String): Boolean = runCatching {
|
companion object {
|
||||||
val parts = value.split(':')
|
|
||||||
require(parts.size <= 2)
|
fun isValidDomain(value: String): Boolean = runCatching {
|
||||||
val urlBuilder = HttpUrl.Builder()
|
require(value.isNotEmpty())
|
||||||
urlBuilder.host(parts.first())
|
val parts = value.split(':')
|
||||||
if (parts.size == 2) {
|
require(parts.size <= 2)
|
||||||
urlBuilder.port(parts[1].toInt())
|
val urlBuilder = HttpUrl.Builder()
|
||||||
}
|
urlBuilder.host(parts.first())
|
||||||
}.isSuccess
|
if (parts.size == 2) {
|
||||||
|
urlBuilder.port(parts[1].toInt())
|
||||||
|
}
|
||||||
|
}.isSuccess
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user