Introduce lazyMut

This commit is contained in:
tarsin committed 2023-07-10 18:26:15 +08:00
1 parent 505ba6e4e3
commit 60ccd988cb
2 files changed
+29 -10

No files matched your search

@@ -83,6 +83,9 @@ import com.hippo.ehviewer.ui.legacy.WindowInsetsAnimationHelper
import com.hippo.ehviewer.ui.setMD3Content
import com.hippo.ehviewer.util.ExceptionUtils
import com.hippo.ehviewer.util.getParcelableCompat
import com.hippo.ehviewer.util.getValue
import com.hippo.ehviewer.util.lazyMut
import com.hippo.ehviewer.util.setValue
import com.hippo.ehviewer.yorozuya.SimpleHandler
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.launchUI
@@ -147,16 +150,10 @@ class VMStorage : ViewModel() {
class FavoritesScene : SearchBarScene() {
private val vm: VMStorage by viewModels()
private var urlBuilder
get() = vm.urlBuilder
set(value) { vm.urlBuilder = value }
private var initialKey
get() = vm.initialKey
set(value) { vm.initialKey = value }
private val cloudDataFlow
get() = vm.cloudDataFlow
private val localFavDataFlow
get() = vm.localFavDataFlow
private var urlBuilder by lazyMut { vm::urlBuilder }
private var initialKey by lazyMut { vm::initialKey }
private val cloudDataFlow by lazy { vm.cloudDataFlow }
private val localFavDataFlow by lazy { vm.localFavDataFlow }
private var _binding: SceneFavoritesBinding? = null
private val binding get() = _binding!!
private var mAdapter: PagingDataAdapter<GalleryInfo, GalleryHolder>? = null
@@ -0,0 +1,22 @@
@file:Suppress("NOTHING_TO_INLINE")
package com.hippo.ehviewer.util
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty
interface Lazy<T> {
var value: T
}
fun <T> lazyMut(init: () -> KMutableProperty0<T>) = object : Lazy<T> {
private val lazy by lazy { init() }
override var value
get() = lazy.get()
set(value) = lazy.set(value)
}
inline operator fun <T> Lazy<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value
inline operator fun <T> Lazy<T>.setValue(thisRef: Any?, prop: KProperty<*>?, newValue: T) {
value = newValue
}