Dependency update / Dropped features that supports <Android 21 / Dropped support for hiyobi.me

This commit is contained in:
tom5079
2021-05-15 06:43:14 +09:00
parent 00c8078642
commit 51851addc1
21 changed files with 64 additions and 268 deletions

View File

@@ -62,8 +62,8 @@ class ImageCache(context: Context) : DIAware {
}
fun free(images: List<String>) {
client.dispatcher().let { it.queuedCalls() + it.runningCalls() }
.filter { it.request().url().toString() in images }
client.dispatcher.let { it.queuedCalls() + it.runningCalls() }
.filter { it.request().url.toString() in images }
.forEach { it.cancel() }
images.forEach { _channels.remove(it) }
@@ -71,7 +71,7 @@ class ImageCache(context: Context) : DIAware {
@Synchronized
suspend fun clear() = coroutineScope {
client.dispatcher().queuedCalls().forEach { it.cancel() }
client.dispatcher.queuedCalls().forEach { it.cancel() }
cacheFolder.listFiles()?.forEach { it.delete() }
cache.clear()
@@ -79,7 +79,7 @@ class ImageCache(context: Context) : DIAware {
@OptIn(ExperimentalCoroutinesApi::class)
fun load(request: Request): File {
val key = request.url().toString()
val key = request.url.toString()
val channel = if (_channels[key]?.isClosedForSend == false)
_channels[key]!!
@@ -93,16 +93,16 @@ class ImageCache(context: Context) : DIAware {
client.newCall(request).enqueue(object: Callback {
override fun onFailure(call: Call, e: IOException) {
file.delete()
cache.remove(call.request().url().toString())
cache.remove(call.request().url.toString())
FirebaseCrashlytics.getInstance().recordException(e)
channel.close(e)
}
override fun onResponse(call: Call, response: Response) {
if (response.code() != 200) {
if (response.code != 200) {
file.delete()
cache.remove(call.request().url().toString())
cache.remove(call.request().url.toString())
channel.close(IOException("HTTP Response code is not 200"))
@@ -110,7 +110,7 @@ class ImageCache(context: Context) : DIAware {
return
}
response.body()?.use { body ->
response.body?.use { body ->
if (!file.exists())
file.createNewFile()

View File

@@ -46,7 +46,7 @@ data class ProxyInfo(
Authenticator { _, response ->
val credential = Credentials.basic(username, password)
response.request().newBuilder()
response.request.newBuilder()
.header("Proxy-Authorization", credential)
.build()
}

View File

@@ -44,10 +44,10 @@ fun updateTranslations() = CoroutineScope(Dispatchers.IO).launch {
translations = emptyMap()
kotlin.runCatching {
translations = Json.decodeFromString<Map<String, String>>(client.newCall(
Request.Builder()
.url(contentURL + "${Preferences["tag_translation", ""].let { if (it.isEmpty()) Locale.getDefault().language else it }}.json")
.build()
).execute().also { if (it.code() != 200) return@launch }.body()?.use { it.string() } ?: return@launch).filterValues { it.isNotEmpty() }
Request.Builder()
.url(contentURL + "${Preferences["tag_translation", ""].let { if (it.isEmpty()) Locale.getDefault().language else it }}.json")
.build()
).execute().also { if (it.code != 200) return@launch }.body?.use { it.string() } ?: return@launch).filterValues { it.isNotEmpty() }
}
}
@@ -58,7 +58,7 @@ fun getAvailableLanguages(): List<String> {
Request.Builder()
.url(filesURL)
.build()
).execute().also { if (it.code() != 200) throw IOException() }.body()?.use { it.string() } ?: return emptyList())
).execute().also { if (it.code != 200) throw IOException() }.body?.use { it.string() } ?: return emptyList())
return listOf("en") + (json["tree"]?.jsonArray?.mapNotNull {
val name = it["path"]?.jsonPrimitive?.content?.takeWhile { c -> c != '.' }

View File

@@ -199,7 +199,7 @@ fun restore(context: Context, url: String, onFailure: ((Throwable) -> Unit)? = n
override fun onResponse(call: Call, response: Response) {
val favorites = object: DIAware { override val di by di(context); val favorites: SavedSourceSet by instance(tag = "favorites") }
kotlin.runCatching {
Json.decodeFromString<Set<String>>(response.also { if (it.code() != 200) throw IOException() }.body().use { it?.string() } ?: "[]").let {
Json.decodeFromString<Set<String>>(response.also { if (it.code != 200) throw IOException() }.body.use { it?.string() } ?: "[]").let {
favorites.favorites.addAll(mapOf("hitomi.la" to it))
onSuccess?.invoke(it)
}