From e9f615819fe07c544045e34fccbb01a74510953e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 3 Feb 2024 21:24:59 +0800 Subject: [PATCH] Update dependency io.coil-kt.coil3:coil-bom to v3.0.0-alpha04 (#677) * Update dependency io.coil-kt.coil3:coil-bom to v3.0.0-alpha04 * Revert "Fix delayed application of HTTP engine changes" This reverts commit c82de0b779b1112bc11545a16fecdd03e1659d80. * Revert "No longer need restart to switch HC" This reverts commit 7e8b0a58 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: FooIbar <118464521+FooIbar@users.noreply.github.com> --- .../com/hippo/ehviewer/EhApplication.kt | 8 +++--- .../kotlin/com/hippo/ehviewer/Settings.kt | 2 +- .../com/hippo/ehviewer/SettingsCollector.kt | 9 ------- .../ehviewer/ui/settings/AdvancedScreen.kt | 8 ++---- .../com/hippo/ehviewer/util/LazyDelegate.kt | 25 ------------------- app/src/main/res/values-zh-rCN/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- gradle/libs.versions.toml | 2 +- 8 files changed, 9 insertions(+), 49 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/EhApplication.kt b/app/src/main/kotlin/com/hippo/ehviewer/EhApplication.kt index 7d1db04f9..5efa81f6f 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/EhApplication.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/EhApplication.kt @@ -54,12 +54,10 @@ import com.hippo.ehviewer.util.Crash import com.hippo.ehviewer.util.FavouriteStatusRouter import com.hippo.ehviewer.util.FileUtils import com.hippo.ehviewer.util.ReadableTime -import com.hippo.ehviewer.util.delegateLazy import com.hippo.ehviewer.util.isAtLeastP import com.hippo.ehviewer.util.isAtLeastQ import com.hippo.ehviewer.util.isAtLeastS import com.hippo.ehviewer.util.isCronetAvailable -import com.hippo.ehviewer.util.resettableLazy import eu.kanade.tachiyomi.network.interceptor.UncaughtExceptionInterceptor import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.withUIContext @@ -185,7 +183,7 @@ class EhApplication : Application(), SingletonImageLoader.Factory { override fun newImageLoader(context: Context) = context.imageLoader { components { serviceLoaderEnabled(false) - add(KtorNetworkFetcherFactory(delegateLazy { ktorClient })) + add(KtorNetworkFetcherFactory { ktorClient }) add(MergeInterceptor) add(DownloadThumbInterceptor) if (isAtLeastP) { @@ -202,7 +200,7 @@ class EhApplication : Application(), SingletonImageLoader.Factory { } companion object { - var ktorClient by resettableLazy { + val ktorClient by lazy { if (Settings.enableCronet && isCronetAvailable) { HttpClient(CronetEngine) { install(HttpCookies) { @@ -226,7 +224,7 @@ class EhApplication : Application(), SingletonImageLoader.Factory { } } - var noRedirectKtorClient by resettableLazy { + val noRedirectKtorClient by lazy { HttpClient(ktorClient.engine) { followRedirects = false install(HttpCookies) { diff --git a/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt b/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt index a6bcf2174..826ba9e7e 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt @@ -149,7 +149,7 @@ object Settings : DataStorePreferences(null) { var harmonizeCategoryColor by boolPref("harmonize_category_color", true) var preloadThumbAggressively by boolPref("preload_thumb_aggressively", false) var downloadOriginImage by boolPref("download_origin_image", false) - var enableCronet by boolPref("enable_cronet", true).observed { updateWhenEnableCronetChanges() } + var enableCronet by boolPref("enable_cronet", true) var recentFavCat by intPref("recent_fav_cat", FavListUrlBuilder.FAV_CAT_LOCAL) var defaultFavSlot by intPref("default_favorite_slot", -2) var securityDelay by intPref("require_unlock_delay", 0) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/SettingsCollector.kt b/app/src/main/kotlin/com/hippo/ehviewer/SettingsCollector.kt index d72a554f8..2499423c3 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/SettingsCollector.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/SettingsCollector.kt @@ -3,8 +3,6 @@ package com.hippo.ehviewer import android.app.UiModeManager import androidx.appcompat.app.AppCompatDelegate import androidx.core.os.LocaleListCompat -import com.hippo.ehviewer.EhApplication.Companion.ktorClient -import com.hippo.ehviewer.EhApplication.Companion.noRedirectKtorClient import com.hippo.ehviewer.client.EhCookieStore import com.hippo.ehviewer.client.EhEngine import com.hippo.ehviewer.client.EhTagDatabase @@ -45,13 +43,6 @@ fun updateWhenKeepMediaStatusChanges() { } } -fun updateWhenEnableCronetChanges() { - collectScope.launchIO { - ktorClient = ktorClient.apply { close() } - noRedirectKtorClient = noRedirectKtorClient.apply { close() } - } -} - fun updateWhenThemeChanges() { collectScope.launch { delay(100) // Avoid recompose being cancelled diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt index d0840dc09..f05b3119b 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt @@ -153,18 +153,14 @@ fun AdvancedScreen(navigator: DestinationsNavigator) { SingleChoiceSegmentedButtonRow(modifier = Modifier.align(Alignment.Center)) { SegmentedButton( selected = !enableCronet, - onClick = { - enableCronet = false - }, + onClick = { enableCronet = false }, shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2), ) { Text("OkHttp") } SegmentedButton( selected = enableCronet, - onClick = { - enableCronet = true - }, + onClick = { enableCronet = true }, shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2), enabled = isCronetAvailable, ) { diff --git a/app/src/main/kotlin/com/hippo/ehviewer/util/LazyDelegate.kt b/app/src/main/kotlin/com/hippo/ehviewer/util/LazyDelegate.kt index f9d55045a..0c6cc9d32 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/util/LazyDelegate.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/util/LazyDelegate.kt @@ -6,36 +6,11 @@ import kotlin.reflect.KMutableProperty0 import kotlin.reflect.KProperty fun unsafeLazy(initializer: () -> T) = lazy(LazyThreadSafetyMode.NONE, initializer) -fun resettableLazy(initializer: () -> T) = ResettableLazy(initializer) -fun delegateLazy(initializer: () -> T) = object : kotlin.Lazy { - override val value: T - get() = initializer() - - override fun isInitialized() = true -} interface Lazy { var value: T } -class ResettableLazy(private val initializer: () -> T) { - - private var value: T? = null - - operator fun getValue(thisRef: Any?, prop: KProperty<*>): T { - return value ?: initializer().apply { value = this } - } - - operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: T) { - check(this.value == value) { "New values aren't accepted to reset this delegated property" } - invalidate() - } - - private fun invalidate() { - value = null - } -} - fun lazyMut(init: () -> KMutableProperty0) = object : Lazy { private val lazy by lazy { init() } override var value diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 51d50b2d2..b49783230 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -355,7 +355,7 @@ 已保存日志至 %s 阅读缓存大小 App 界面语言 - Http 引擎 + Http 引擎(重启生效) [实验性] 触摸溢出系数 增大此项将降低滑动手势敏感度 导出数据 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d98e792dd..186db128a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -399,7 +399,7 @@ Logcat dumped to %s Read cache size App language - Http Engine + Http Engine (Restart required) [Experimental] Touch slop factor Increasing this will reduce swipe gesture sensitivity Export data diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2b325d452..4895ffb84 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ androidx-recyclerview = "1.3.2" androidx-room = "2.6.1" androidx-work = "2.9.0" arrow = "1.2.1" -coil = "3.0.0-alpha03" +coil = "3.0.0-alpha04" compose-bom = "2024.01.00-alpha03" compose-compiler = "1.5.9-dev-k2.0.0-Beta3-7c5ec6895a0" compose-destinations = "1.10.0"