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

@@ -32,4 +32,4 @@ actual inline fun <reified VM : ViewModel> Screen.stateViewModel(
lifecycle.defaultViewModelCreationExtras.addScreenModelKey<VM>(this, tag).createSavedStateHandle()
}
return rememberScreenModel(tag) { viewModelFactory.factory(handle) }
}
}

View File

@@ -8,4 +8,4 @@ package ca.gosyer.jui.ui.base.screen
import cafe.adriel.voyager.androidx.AndroidScreen
actual typealias BaseScreen = AndroidScreen
actual typealias BaseScreen = AndroidScreen

View File

@@ -6,4 +6,4 @@
package ca.gosyer.jui.ui.base.state
actual typealias SavedStateHandle = androidx.lifecycle.SavedStateHandle
actual typealias SavedStateHandle = androidx.lifecycle.SavedStateHandle

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]
@@ -111,4 +116,4 @@ inline fun <reified T : ScreenModel> CreationExtras.addScreenModelKey(screen: Sc
return MutableCreationExtras(this).apply {
set(VIEW_MODEL_KEY, getKey<T>(screen, tag))
}
}
}

View File

@@ -8,4 +8,4 @@ package ca.gosyer.jui.ui.base.screen
import cafe.adriel.voyager.core.screen.Screen
expect abstract class BaseScreen() : Screen
expect abstract class BaseScreen() : Screen

View File

@@ -16,4 +16,4 @@ expect class SavedStateHandle {
fun <T> remove(key: String): T?
fun <T> getStateFlow(key: String, initialValue: T): StateFlow<T>
}
}

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

@@ -28,4 +28,4 @@ actual inline fun <reified VM : ViewModel> Screen.stateViewModel(
val viewModelFactory = LocalViewModels.current
val savedStateHandle = rememberSaveable { SavedStateHandle() }
return rememberScreenModel(tag) { viewModelFactory.factory(savedStateHandle) }
}
}

View File

@@ -13,4 +13,4 @@ import cafe.adriel.voyager.core.screen.uniqueScreenKey
actual abstract class BaseScreen : Screen {
override val key: ScreenKey = uniqueScreenKey
}
}

View File

@@ -47,4 +47,4 @@ actual class SavedStateHandle {
MutableStateFlow(regular[key]).apply { flows[key] = this }
}.asStateFlow() as StateFlow<T>
}
}
}

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

@@ -47,4 +47,4 @@ internal actual fun RealDropdownMenuItem(
interactionSource = interactionSource,
content = content
)
*/
*/

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