Vince
04/26/2023, 1:35 AMfun Screen() {
Entry()
Entry()
Entry()
Entry()
//Which entry value is smallest number on screen
}
fun Entry() {
TextField()
}
andrew
04/26/2023, 2:21 AMVince
04/26/2023, 2:27 AMandrew
04/26/2023, 2:38 AMandrew
04/26/2023, 2:38 AMandrew
04/26/2023, 2:39 AMVince
04/26/2023, 2:39 AMVince
04/26/2023, 2:39 AMandrew
04/26/2023, 2:40 AMVince
04/26/2023, 2:42 AMVince
04/26/2023, 2:43 AMEntry()
is supposed to a be a composable that has multiple customizations not just TextField
so that I don’t have to copy paste them 4 times to keep in a single method.Vince
04/26/2023, 2:44 AMandrew
04/26/2023, 2:46 AMandrew
04/26/2023, 2:46 AMVince
04/26/2023, 2:47 AMVince
04/26/2023, 2:47 AMandrew
04/26/2023, 2:47 AMandrew
04/26/2023, 2:48 AMVince
04/26/2023, 2:48 AMandrew
04/26/2023, 2:48 AMVince
04/26/2023, 2:48 AMVince
04/26/2023, 2:48 AMandrew
04/26/2023, 2:48 AMVince
04/26/2023, 2:48 AMandrew
04/26/2023, 2:49 AMandrew
04/26/2023, 2:49 AMVince
04/26/2023, 2:49 AMandrew
04/26/2023, 2:49 AMVince
04/26/2023, 2:50 AMandrew
04/26/2023, 2:50 AMVince
04/26/2023, 2:50 AMandrew
04/26/2023, 2:51 AMVince
04/26/2023, 2:51 AMandrew
04/26/2023, 2:51 AMVince
04/26/2023, 2:52 AMVince
04/26/2023, 2:52 AMandrew
04/26/2023, 2:53 AMTravis Griggs
04/26/2023, 2:53 AMVince
04/26/2023, 2:53 AMVince
04/26/2023, 2:54 AMandrew
04/26/2023, 2:56 AMVince
04/26/2023, 2:56 AMVince
04/26/2023, 2:57 AMandrew
04/26/2023, 2:58 AMTravis Griggs
04/26/2023, 2:58 AMTravis Griggs
04/26/2023, 2:59 AMVince
04/26/2023, 3:04 AMfun Screen() {
Entry().value().observe{}
Entry().value().observe{}
}
class Entry() {
fun value(): Observable {
Observable.just(1)
}
}
With Rx so my view didn’t need a view model to render and could just “publish” it’s results for processing to anyone listening. I was hoping to find a way to do it without pushing a view model in to each view that way. Total IOC and purely agnostic. Passing
EntryModel : ViewModel() {
entry1 = mutableStateOf(1)
entry2 = mutableStateOf(2)...
}
And pass that is my best betVince
04/26/2023, 3:06 AMandrew
04/26/2023, 3:06 AMandrew
04/26/2023, 3:07 AMTravis Griggs
04/26/2023, 3:09 AMVince
04/26/2023, 3:10 AMandrew
04/26/2023, 4:48 AMTravis Griggs
04/26/2023, 3:43 PM@Composable
fun DerivedDemoScreen() {
var foodsToPack = remember {
mutableStateListOf<String>(
"Dr Pepper",
"Clif Bar",
"Something Fowl",
"Healthy Chips",
"More Dr Pepper"
)
}
val aMouthfulToSay by remember { derivedStateOf { foodsToPack.maxBy { foodName -> foodName.length } } }
val whatWasThat by remember { derivedStateOf { foodsToPack.minBy { foodName -> foodName.length } } }
Column {
LazyColumn(
modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally
) {
itemsIndexed(items = foodsToPack) { index, foodName ->
Entry(value = foodName,
modifier = Modifier.fillMaxWidth(),
onChange = { updated -> foodsToPack[index] = updated })
}
}
Text(text = "Longest: $aMouthfulToSay")
Text(text = "Shortest: $whatWasThat")
}
}
@Composable
private fun Entry(
value: String,
modifier: Modifier = Modifier,
onChange: UnaryAction<String> = { _ -> }
) {
TextField(value = value, onValueChange = onChange, modifier = modifier)
}
@Preview
@Composable
private fun DerivedDemosScreenPreview() {
StatusDemoTheme {
DerivedDemoScreen()
}
}
Travis Griggs
04/26/2023, 3:43 PMVince
04/30/2023, 4:58 PMclass HoleScoreViewModel : ViewModel() {
private var _highScore: MutableLiveData<Int> = MutableLiveData<Int>(0)
private var _lowScore: MutableLiveData<Int> = MutableLiveData<Int>(0)
private var player1Score: MutableLiveData<Int> = MutableLiveData(0)
private var player2Score: MutableLiveData<Int> = MutableLiveData(0)
private var player3Score: MutableLiveData<Int> = MutableLiveData(0)
private var player4Score: MutableLiveData<Int> = MutableLiveData(0)
/* score setters for each entry field */
fun getHighScore(): Int {
//return player number with highest score
}
}
@Composable
fun EnterScore(matchViewModel: MatchViewModel, navController: NavHostController) {
val scoreViewModel: HoleScoreViewModel = HoleScoreViewModel()
Column(
modifier = Modifier.padding(12.dp),
verticalArrangement = Arrangement.Center
) {
PlayerScore() // times four
Button(modifier = Modifier
.fillMaxWidth()
.height(48.dp),
content = {
Text(text = "Next Hole")
},
onClick = {
//TODO do actual point entries
//val playerScore = scoreViewModel.getHighScore()
//matchViewModel.updateMatchScore(playerScore)
})
}
}
@Composable
fun PlayerScore() {
//TODO add a lambda for updating the player score?
Row(
modifier = Modifier
.background(background),
verticalAlignment = Alignment.CenterVertically,
) {
OutlinedTextField(
value = score.value,
label = { Text("Score") },
onValueChange = {
if (it.isEmpty()) {
score.value = ""
} else if (it.isDigitsOnly() && it.toInt() <= 9) {
score.value = it
//use lambda to set player score on scoreViewModel
}
},
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
)
}
Vince
04/30/2023, 5:00 PMVince
04/30/2023, 5:00 PMTravis Griggs
05/01/2023, 3:00 PMVince
05/01/2023, 4:14 PM