Use mock dialog values in preview
This commit is contained in:
parent
7bfbcc955c
commit
189c1e8db8
|
@ -3,8 +3,12 @@ package dev.lonami.talaria.data
|
||||||
import dev.lonami.talaria.bindings.Native
|
import dev.lonami.talaria.bindings.Native
|
||||||
import dev.lonami.talaria.model.Dialog
|
import dev.lonami.talaria.model.Dialog
|
||||||
|
|
||||||
object DialogSource {
|
interface DialogSource {
|
||||||
fun loadDialogs(): List<Dialog> {
|
fun loadDialogs(): List<Dialog>;
|
||||||
|
}
|
||||||
|
|
||||||
|
class NativeDialogSource : DialogSource {
|
||||||
|
override fun loadDialogs(): List<Dialog> {
|
||||||
val dialogs = mutableListOf<Dialog>()
|
val dialogs = mutableListOf<Dialog>()
|
||||||
|
|
||||||
val dialogPtr = Native.getDialogs()
|
val dialogPtr = Native.getDialogs()
|
||||||
|
@ -23,3 +27,13 @@ object DialogSource {
|
||||||
return dialogs
|
return dialogs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MockDialogSource : DialogSource {
|
||||||
|
override fun loadDialogs(): List<Dialog> {
|
||||||
|
val dialogs = mutableListOf<Dialog>()
|
||||||
|
for (i in 0 until 10) {
|
||||||
|
dialogs.add(Dialog("Sample Dialog $i", "Sample Message $i", i == 0))
|
||||||
|
}
|
||||||
|
return dialogs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import dev.lonami.talaria.R
|
import dev.lonami.talaria.R
|
||||||
|
import dev.lonami.talaria.data.MockDialogSource
|
||||||
import dev.lonami.talaria.model.Dialog
|
import dev.lonami.talaria.model.Dialog
|
||||||
import dev.lonami.talaria.ui.theme.TalariaTheme
|
import dev.lonami.talaria.ui.theme.TalariaTheme
|
||||||
|
|
||||||
|
@ -69,7 +70,8 @@ fun DialogScreen(
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
fun DialogPreview() {
|
fun DialogPreview() {
|
||||||
|
val viewModel = DialogViewModel(MockDialogSource())
|
||||||
TalariaTheme {
|
TalariaTheme {
|
||||||
DialogScreen(onDialogSelected = { })
|
DialogScreen(onDialogSelected = { }, dialogViewModel = viewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,17 @@ package dev.lonami.talaria.ui
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import dev.lonami.talaria.data.DialogSource
|
import dev.lonami.talaria.data.DialogSource
|
||||||
|
import dev.lonami.talaria.data.NativeDialogSource
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
class DialogViewModel : ViewModel() {
|
class DialogViewModel(private val repository: DialogSource = NativeDialogSource()) : ViewModel() {
|
||||||
private val _uiState = MutableStateFlow(DialogUiState())
|
private val _uiState = MutableStateFlow(DialogUiState())
|
||||||
val uiState: StateFlow<DialogUiState> = _uiState.asStateFlow()
|
val uiState: StateFlow<DialogUiState> = _uiState.asStateFlow()
|
||||||
|
|
||||||
private fun loadDialogs() {
|
private fun loadDialogs() {
|
||||||
_uiState.value = DialogUiState(DialogSource.loadDialogs())
|
_uiState.value = DialogUiState(repository.loadDialogs())
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
Loading…
Reference in New Issue