Skip to content

Commit

Permalink
Update dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
floschu committed Oct 19, 2024
1 parent 1012987 commit fea1171
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package at.florianschuster.hydro.ui

import android.graphics.Paint.Align
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.WaterDrop
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import at.florianschuster.hydro.AppAction
import at.florianschuster.hydro.AppState
import at.florianschuster.hydro.model.Milliliters
Expand All @@ -24,17 +34,23 @@ fun GoalOfTheDayBottomSheet(
BottomSheet(
title = "Goal of the Day"
) {
MillilitersSlider(
range = remember { Milliliters.DAILY_GOAL_MIN..Milliliters.DAILY_GOAL_MAX },
stepsSize = remember { Milliliters.DAILY_GOAL_STEPS },
milliliters = state.dailyGoal,
onMillilitersChanged = { dispatch(AppAction.SetDailyGoal(it)) }
)
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
imageVector = Icons.Outlined.WaterDrop,
contentDescription = null
)
Spacer(modifier = Modifier.width(16.dp))
MillilitersSlider(
range = remember { Milliliters.DAILY_GOAL_MIN..Milliliters.DAILY_GOAL_MAX },
stepsSize = remember { Milliliters.DAILY_GOAL_STEPS },
milliliters = state.dailyGoal,
onMillilitersChanged = { dispatch(AppAction.SetDailyGoal(it)) }
)
}
Text(text = state.dailyGoal.format(state.liquidUnit))
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun MillilitersSlider(
range: ClosedRange<Milliliters>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
package at.florianschuster.hydro.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.Slider
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import at.florianschuster.hydro.AppAction
import at.florianschuster.hydro.AppState
import at.florianschuster.hydro.R
import at.florianschuster.hydro.model.format
import at.florianschuster.hydro.ui.base.BottomSheet
import kotlin.math.roundToInt
Expand All @@ -26,23 +41,34 @@ fun SetIntervalBottomSheet(
title = "Interval"
) {
var value by remember(state.reminder) {
mutableStateOf(state.reminder.interval.inWholeMinutes.toFloat())
mutableFloatStateOf(state.reminder.interval.inWholeMinutes.toFloat())
}
val intervalValue by remember(value) {
derivedStateOf { value.roundToInt().minutes }
}
Slider(
value = value,
valueRange = 1f..60f,
steps = 58,
onValueChange = { minutesValue -> value = minutesValue },
onValueChangeFinished = {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(R.drawable.ic_arrow_range),
contentDescription = null
)
Spacer(modifier = Modifier.width(16.dp))
Slider(
value = value,
valueRange = 1f..60f,
onValueChange = { minutesValue -> value = minutesValue },
)
}
Text(text = intervalValue.format())

Spacer(modifier = Modifier.height(32.dp))
TextButton(
onClick = {
dispatch(
AppAction.SetReminder(state.reminder.copy(interval = intervalValue))
)
onClose()
}
)
Text(text = intervalValue.format())
) { Text("Save") }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fun TimePickerDialog(
) { Text("Cancel") }
TextButton(
onClick = { onConfirm(state.hour, state.minute) }
) { Text("OK") }
) { Text("Save") }
}
}
}
Expand Down

0 comments on commit fea1171

Please sign in to comment.