Automatic Lint

This commit is contained in:
Syer10
2022-10-29 17:27:49 +00:00
parent fed9043b94
commit d27dc90050
15 changed files with 32 additions and 34 deletions

View File

@@ -23,7 +23,6 @@ import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.screen.Screen
import java.lang.reflect.Method
private const val SAVED_STATE_KEY = "androidx.lifecycle.internal.SavedStateHandlesProvider"
val SavedStateHandleSupportClass: Class<*> by lazy {
@@ -46,7 +45,8 @@ private fun createSavedStateHandle(
val vm = getSavedStateHandlesVM.invoke(null, viewModelStoreOwner)!!
val handles = vm::class.java.methods.first { it.name == "getHandles" }.invoke(vm) as MutableMap<String, SavedStateHandle>
return handles[key] ?: SavedStateHandle.createHandle(
provider.consumeRestoredStateForKey(key), defaultArgs
provider.consumeRestoredStateForKey(key),
defaultArgs
).also { handles[key] = it }
}
@@ -78,21 +78,26 @@ fun CreationExtras.createSavedStateHandle(): SavedStateHandle {
"CreationExtras must have a value by `VIEW_MODEL_KEY`"
)
return createSavedStateHandle(
savedStateRegistryOwner, viewModelStateRegistryOwner, key, defaultArgs
savedStateRegistryOwner,
viewModelStateRegistryOwner,
key,
defaultArgs
)
}
internal val SavedStateRegistryOwner.savedStateHandlesProvider: SavedStateHandlesProvider
get() = savedStateRegistry.getSavedStateProvider(SAVED_STATE_KEY)?.let(::SavedStateHandlesProvider)
?: throw IllegalStateException("enableSavedStateHandles() wasn't called " +
"prior to createSavedStateHandle() call")
?: throw IllegalStateException(
"enableSavedStateHandles() wasn't called " +
"prior to createSavedStateHandle() call"
)
/**
* This single SavedStateProvider is responsible for saving the state of every
* SavedStateHandle associated with the SavedState/ViewModel pair.
*/
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]

View File

@@ -12,14 +12,14 @@ import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
fun <T> SavedStateHandle.getStateFlow(
initialValue: () -> T,
initialValue: () -> T
): SavedStateHandleDelegate<T> {
return SavedStateHandleDelegate(this, initialValue)
}
class SavedStateHandleDelegate<T>(
private val savedStateHandle: SavedStateHandle,
private val initialValue: () -> T,
private val initialValue: () -> T
) : ReadOnlyProperty<ViewModel, SavedStateHandleStateFlow<T>> {
private var item: SavedStateHandleStateFlow<T>? = null
@@ -28,7 +28,9 @@ class SavedStateHandleDelegate<T>(
if (item == null) {
savedStateHandle.getSavedStateFlow(property.name, initialValue)
.also { item = it }
} else item!!
} else {
item!!
}
}
}
}
@@ -36,7 +38,7 @@ class SavedStateHandleDelegate<T>(
class SavedStateHandleStateFlow<T>(
private val key: String,
private val savedStateHandle: SavedStateHandle,
private val stateFlow: StateFlow<T>,
private val stateFlow: StateFlow<T>
) : StateFlow<T> by stateFlow {
override var value: T
@@ -52,7 +54,7 @@ class SavedStateHandleStateFlow<T>(
fun <T> SavedStateHandle.getSavedStateFlow(
key: String,
initialValue: () -> T,
initialValue: () -> T
): SavedStateHandleStateFlow<T> {
val value = get<T>(key)
@@ -65,6 +67,6 @@ fun <T> SavedStateHandle.getSavedStateFlow(
return SavedStateHandleStateFlow(
key = key,
savedStateHandle = this,
stateFlow = flow,
stateFlow = flow
)
}

View File

@@ -8,11 +8,8 @@ package ca.gosyer.jui.uicore.resources
import androidx.compose.runtime.Composable
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.PluralFormatted
import dev.icerock.moko.resources.desc.Resource
import dev.icerock.moko.resources.desc.ResourceFormatted
import dev.icerock.moko.resources.desc.StringDesc
@Composable

View File

@@ -70,6 +70,6 @@ private fun UIImage.toSkiaImage(): Image? {
return Image.makeRaster(
imageInfo = ImageInfo(width = width, height = height, colorType = ColorType.RGBA_8888, alphaType = alphaType),
bytes = byteArray,
rowBytes = bytesPerRow.toInt(),
rowBytes = bytesPerRow.toInt()
)
}

View File

@@ -8,11 +8,8 @@ package ca.gosyer.jui.uicore.resources
import androidx.compose.runtime.Composable
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.PluralFormatted
import dev.icerock.moko.resources.desc.Resource
import dev.icerock.moko.resources.desc.ResourceFormatted
import dev.icerock.moko.resources.desc.StringDesc
@Composable

View File

@@ -8,11 +8,8 @@ package ca.gosyer.jui.uicore.resources
import androidx.compose.runtime.Composable
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.PluralFormatted
import dev.icerock.moko.resources.desc.Resource
import dev.icerock.moko.resources.desc.ResourceFormatted
import dev.icerock.moko.resources.desc.StringDesc
@Composable