mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-19 03:02:04 +01:00
Automatic Lint
This commit is contained in:
@@ -23,7 +23,6 @@ import cafe.adriel.voyager.core.model.ScreenModel
|
|||||||
import cafe.adriel.voyager.core.screen.Screen
|
import cafe.adriel.voyager.core.screen.Screen
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
|
|
||||||
|
|
||||||
private const val SAVED_STATE_KEY = "androidx.lifecycle.internal.SavedStateHandlesProvider"
|
private const val SAVED_STATE_KEY = "androidx.lifecycle.internal.SavedStateHandlesProvider"
|
||||||
|
|
||||||
val SavedStateHandleSupportClass: Class<*> by lazy {
|
val SavedStateHandleSupportClass: Class<*> by lazy {
|
||||||
@@ -46,7 +45,8 @@ private fun createSavedStateHandle(
|
|||||||
val vm = getSavedStateHandlesVM.invoke(null, viewModelStoreOwner)!!
|
val vm = getSavedStateHandlesVM.invoke(null, viewModelStoreOwner)!!
|
||||||
val handles = vm::class.java.methods.first { it.name == "getHandles" }.invoke(vm) as MutableMap<String, SavedStateHandle>
|
val handles = vm::class.java.methods.first { it.name == "getHandles" }.invoke(vm) as MutableMap<String, SavedStateHandle>
|
||||||
return handles[key] ?: SavedStateHandle.createHandle(
|
return handles[key] ?: SavedStateHandle.createHandle(
|
||||||
provider.consumeRestoredStateForKey(key), defaultArgs
|
provider.consumeRestoredStateForKey(key),
|
||||||
|
defaultArgs
|
||||||
).also { handles[key] = it }
|
).also { handles[key] = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,21 +78,26 @@ fun CreationExtras.createSavedStateHandle(): SavedStateHandle {
|
|||||||
"CreationExtras must have a value by `VIEW_MODEL_KEY`"
|
"CreationExtras must have a value by `VIEW_MODEL_KEY`"
|
||||||
)
|
)
|
||||||
return createSavedStateHandle(
|
return createSavedStateHandle(
|
||||||
savedStateRegistryOwner, viewModelStateRegistryOwner, key, defaultArgs
|
savedStateRegistryOwner,
|
||||||
|
viewModelStateRegistryOwner,
|
||||||
|
key,
|
||||||
|
defaultArgs
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val SavedStateRegistryOwner.savedStateHandlesProvider: SavedStateHandlesProvider
|
internal val SavedStateRegistryOwner.savedStateHandlesProvider: SavedStateHandlesProvider
|
||||||
get() = savedStateRegistry.getSavedStateProvider(SAVED_STATE_KEY)?.let(::SavedStateHandlesProvider)
|
get() = savedStateRegistry.getSavedStateProvider(SAVED_STATE_KEY)?.let(::SavedStateHandlesProvider)
|
||||||
?: throw IllegalStateException("enableSavedStateHandles() wasn't called " +
|
?: throw IllegalStateException(
|
||||||
"prior to createSavedStateHandle() call")
|
"enableSavedStateHandles() wasn't called " +
|
||||||
|
"prior to createSavedStateHandle() call"
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This single SavedStateProvider is responsible for saving the state of every
|
* This single SavedStateProvider is responsible for saving the state of every
|
||||||
* SavedStateHandle associated with the SavedState/ViewModel pair.
|
* SavedStateHandle associated with the SavedState/ViewModel pair.
|
||||||
*/
|
*/
|
||||||
internal class SavedStateHandlesProvider(
|
internal class SavedStateHandlesProvider(
|
||||||
private val savedStateRegistry: SavedStateRegistry.SavedStateProvider,
|
private val savedStateRegistry: SavedStateRegistry.SavedStateProvider
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* Restore the state associated with a particular SavedStateHandle, identified by its [key]
|
* Restore the state associated with a particular SavedStateHandle, identified by its [key]
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ import kotlin.properties.ReadOnlyProperty
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
fun <T> SavedStateHandle.getStateFlow(
|
fun <T> SavedStateHandle.getStateFlow(
|
||||||
initialValue: () -> T,
|
initialValue: () -> T
|
||||||
): SavedStateHandleDelegate<T> {
|
): SavedStateHandleDelegate<T> {
|
||||||
return SavedStateHandleDelegate(this, initialValue)
|
return SavedStateHandleDelegate(this, initialValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
class SavedStateHandleDelegate<T>(
|
class SavedStateHandleDelegate<T>(
|
||||||
private val savedStateHandle: SavedStateHandle,
|
private val savedStateHandle: SavedStateHandle,
|
||||||
private val initialValue: () -> T,
|
private val initialValue: () -> T
|
||||||
) : ReadOnlyProperty<ViewModel, SavedStateHandleStateFlow<T>> {
|
) : ReadOnlyProperty<ViewModel, SavedStateHandleStateFlow<T>> {
|
||||||
private var item: SavedStateHandleStateFlow<T>? = null
|
private var item: SavedStateHandleStateFlow<T>? = null
|
||||||
|
|
||||||
@@ -28,7 +28,9 @@ class SavedStateHandleDelegate<T>(
|
|||||||
if (item == null) {
|
if (item == null) {
|
||||||
savedStateHandle.getSavedStateFlow(property.name, initialValue)
|
savedStateHandle.getSavedStateFlow(property.name, initialValue)
|
||||||
.also { item = it }
|
.also { item = it }
|
||||||
} else item!!
|
} else {
|
||||||
|
item!!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,7 +38,7 @@ class SavedStateHandleDelegate<T>(
|
|||||||
class SavedStateHandleStateFlow<T>(
|
class SavedStateHandleStateFlow<T>(
|
||||||
private val key: String,
|
private val key: String,
|
||||||
private val savedStateHandle: SavedStateHandle,
|
private val savedStateHandle: SavedStateHandle,
|
||||||
private val stateFlow: StateFlow<T>,
|
private val stateFlow: StateFlow<T>
|
||||||
) : StateFlow<T> by stateFlow {
|
) : StateFlow<T> by stateFlow {
|
||||||
|
|
||||||
override var value: T
|
override var value: T
|
||||||
@@ -52,7 +54,7 @@ class SavedStateHandleStateFlow<T>(
|
|||||||
|
|
||||||
fun <T> SavedStateHandle.getSavedStateFlow(
|
fun <T> SavedStateHandle.getSavedStateFlow(
|
||||||
key: String,
|
key: String,
|
||||||
initialValue: () -> T,
|
initialValue: () -> T
|
||||||
): SavedStateHandleStateFlow<T> {
|
): SavedStateHandleStateFlow<T> {
|
||||||
val value = get<T>(key)
|
val value = get<T>(key)
|
||||||
|
|
||||||
@@ -65,6 +67,6 @@ fun <T> SavedStateHandle.getSavedStateFlow(
|
|||||||
return SavedStateHandleStateFlow(
|
return SavedStateHandleStateFlow(
|
||||||
key = key,
|
key = key,
|
||||||
savedStateHandle = this,
|
savedStateHandle = this,
|
||||||
stateFlow = flow,
|
stateFlow = flow
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -8,11 +8,8 @@ package ca.gosyer.jui.uicore.resources
|
|||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import dev.icerock.moko.resources.PluralsResource
|
import dev.icerock.moko.resources.PluralsResource
|
||||||
import dev.icerock.moko.resources.StringResource
|
|
||||||
import dev.icerock.moko.resources.desc.Plural
|
import dev.icerock.moko.resources.desc.Plural
|
||||||
import dev.icerock.moko.resources.desc.PluralFormatted
|
import dev.icerock.moko.resources.desc.PluralFormatted
|
||||||
import dev.icerock.moko.resources.desc.Resource
|
|
||||||
import dev.icerock.moko.resources.desc.ResourceFormatted
|
|
||||||
import dev.icerock.moko.resources.desc.StringDesc
|
import dev.icerock.moko.resources.desc.StringDesc
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -70,6 +70,6 @@ private fun UIImage.toSkiaImage(): Image? {
|
|||||||
return Image.makeRaster(
|
return Image.makeRaster(
|
||||||
imageInfo = ImageInfo(width = width, height = height, colorType = ColorType.RGBA_8888, alphaType = alphaType),
|
imageInfo = ImageInfo(width = width, height = height, colorType = ColorType.RGBA_8888, alphaType = alphaType),
|
||||||
bytes = byteArray,
|
bytes = byteArray,
|
||||||
rowBytes = bytesPerRow.toInt(),
|
rowBytes = bytesPerRow.toInt()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -8,11 +8,8 @@ package ca.gosyer.jui.uicore.resources
|
|||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import dev.icerock.moko.resources.PluralsResource
|
import dev.icerock.moko.resources.PluralsResource
|
||||||
import dev.icerock.moko.resources.StringResource
|
|
||||||
import dev.icerock.moko.resources.desc.Plural
|
import dev.icerock.moko.resources.desc.Plural
|
||||||
import dev.icerock.moko.resources.desc.PluralFormatted
|
import dev.icerock.moko.resources.desc.PluralFormatted
|
||||||
import dev.icerock.moko.resources.desc.Resource
|
|
||||||
import dev.icerock.moko.resources.desc.ResourceFormatted
|
|
||||||
import dev.icerock.moko.resources.desc.StringDesc
|
import dev.icerock.moko.resources.desc.StringDesc
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -8,11 +8,8 @@ package ca.gosyer.jui.uicore.resources
|
|||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import dev.icerock.moko.resources.PluralsResource
|
import dev.icerock.moko.resources.PluralsResource
|
||||||
import dev.icerock.moko.resources.StringResource
|
|
||||||
import dev.icerock.moko.resources.desc.Plural
|
import dev.icerock.moko.resources.desc.Plural
|
||||||
import dev.icerock.moko.resources.desc.PluralFormatted
|
import dev.icerock.moko.resources.desc.PluralFormatted
|
||||||
import dev.icerock.moko.resources.desc.Resource
|
|
||||||
import dev.icerock.moko.resources.desc.ResourceFormatted
|
|
||||||
import dev.icerock.moko.resources.desc.StringDesc
|
import dev.icerock.moko.resources.desc.StringDesc
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
Reference in New Issue
Block a user