diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index b268ef3..7fc6645 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -4,6 +4,14 @@ diff --git a/app/src/main/java/id/my/kaorikizuna/incu8tor/model/DeviceModel.kt b/app/src/main/java/id/my/kaorikizuna/incu8tor/model/DeviceModel.kt index 28aaaa3..6c6fc72 100644 --- a/app/src/main/java/id/my/kaorikizuna/incu8tor/model/DeviceModel.kt +++ b/app/src/main/java/id/my/kaorikizuna/incu8tor/model/DeviceModel.kt @@ -7,17 +7,17 @@ import androidx.lifecycle.ViewModel data class Device(var name: String, var macAddress: String, var isConnected: Boolean) data class Humidity( - var min: Int, - var max: Int + var min: Double, + var max: Double ) { - constructor() : this(0, 0) + constructor() : this(0.0, 0.0) } data class Temperature( - var min: Int, - var max: Int + var min: Double, + var max: Double ) { - constructor() : this(0, 0) + constructor() : this(0.0, 0.0) } // DeviceSettings from the app @@ -25,15 +25,15 @@ data class DeviceSettings( var humidity: Humidity, var temperature: Temperature ) { - constructor() : this(Humidity(0, 0), Temperature(0, 0)) + constructor() : this(Humidity(0.0, 0.0), Temperature(0.0, 0.0)) } // DeviceSensors from the actual device data class DeviceSensors( - var humidity: Int, - var temperature: Int + var humidity: Double, + var temperature: Double ) { - constructor() : this(0, 0) + constructor() : this(0.0, 0.0) } data class DeviceDetail( @@ -56,8 +56,8 @@ data class DeviceDetail( "", false, "", - DeviceSettings(Humidity(0, 0), Temperature(0, 0)), - DeviceSensors(0, 0), + DeviceSettings(Humidity(0.0, 0.0), Temperature(0.0, 0.0)), + DeviceSensors(0.0, 0.0), ) } diff --git a/app/src/main/java/id/my/kaorikizuna/incu8tor/ui/addevice/AddDevice.kt b/app/src/main/java/id/my/kaorikizuna/incu8tor/ui/addevice/AddDevice.kt index 6923e28..de92627 100644 --- a/app/src/main/java/id/my/kaorikizuna/incu8tor/ui/addevice/AddDevice.kt +++ b/app/src/main/java/id/my/kaorikizuna/incu8tor/ui/addevice/AddDevice.kt @@ -79,6 +79,7 @@ import id.my.kaorikizuna.incu8tor.ui.theme.Blue import id.my.kaorikizuna.incu8tor.ui.theme.DarkBlue import id.my.kaorikizuna.incu8tor.ui.theme.DarkRed import id.my.kaorikizuna.incu8tor.ui.theme.Red +import kotlin.math.roundToInt @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -122,7 +123,10 @@ fun AddDeviceScreen(onSave: (DeviceDetail) -> Unit, onBackClicked: () -> Unit) { // set the device to be in valid range deviceDetail.settings = - DeviceSettings(temperature = Temperature(34, 38), humidity = Humidity(50, 70)) + DeviceSettings( + temperature = Temperature(34.0, 38.0), + humidity = Humidity(50.0, 70.0) + ) var temperatureSliderPositions by remember { mutableStateOf(deviceDetail.settings.temperature.min.toFloat()..deviceDetail.settings.temperature.max.toFloat()) } Column { @@ -136,8 +140,9 @@ fun AddDeviceScreen(onSave: (DeviceDetail) -> Unit, onBackClicked: () -> Unit) { deviceDetail.copy( settings = DeviceSettings( temperature = Temperature( - temperatureSliderPositions.start.toInt(), - temperatureSliderPositions.endInclusive.toInt() + temperatureSliderPositions.start.roundToInt().toDouble(), + temperatureSliderPositions.endInclusive.roundToInt() + .toDouble() ), humidity = deviceDetail.settings.humidity ) @@ -178,8 +183,8 @@ fun AddDeviceScreen(onSave: (DeviceDetail) -> Unit, onBackClicked: () -> Unit) { settings = DeviceSettings( temperature = deviceDetail.settings.temperature, humidity = Humidity( - humiditySliderPositions.start.toInt(), - humiditySliderPositions.endInclusive.toInt() + humiditySliderPositions.start.roundToInt().toDouble(), + humiditySliderPositions.endInclusive.roundToInt().toDouble() ) ) ) @@ -213,7 +218,6 @@ fun AddDeviceScreen(onSave: (DeviceDetail) -> Unit, onBackClicked: () -> Unit) { horizontalAlignment = Alignment.CenterHorizontally ) { Button(onClick = { - Log.w("asdfasdf", "$deviceDetail") onSave(deviceDetail) onBackClicked() }) { diff --git a/app/src/main/java/id/my/kaorikizuna/incu8tor/ui/deviceConfiguration/DeviceConfigurationScreen.kt b/app/src/main/java/id/my/kaorikizuna/incu8tor/ui/deviceConfiguration/DeviceConfigurationScreen.kt index 1d52222..f9dfda9 100644 --- a/app/src/main/java/id/my/kaorikizuna/incu8tor/ui/deviceConfiguration/DeviceConfigurationScreen.kt +++ b/app/src/main/java/id/my/kaorikizuna/incu8tor/ui/deviceConfiguration/DeviceConfigurationScreen.kt @@ -57,6 +57,7 @@ import id.my.kaorikizuna.incu8tor.ui.theme.DarkBlue import id.my.kaorikizuna.incu8tor.ui.theme.DarkRed import id.my.kaorikizuna.incu8tor.ui.theme.Red import id.my.kaorikizuna.incu8tor.viewmodel.DeviceViewModel +import kotlin.math.roundToInt @Composable fun DeviceConfigurationScreen( @@ -132,8 +133,9 @@ fun DeviceConfigurationScreen( currentDeviceDetail.copy( settings = DeviceSettings( temperature = Temperature( - temperatureSliderPositions.start.toInt(), - temperatureSliderPositions.endInclusive.toInt() + temperatureSliderPositions.start.roundToInt().toDouble(), + temperatureSliderPositions.endInclusive.roundToInt() + .toDouble() ), humidity = currentDeviceDetail.settings.humidity ) ) @@ -170,8 +172,8 @@ fun DeviceConfigurationScreen( settings = DeviceSettings( temperature = currentDeviceDetail.settings.temperature, humidity = Humidity( - humiditySliderPositions.start.toInt(), - humiditySliderPositions.endInclusive.toInt() + humiditySliderPositions.start.roundToInt().toDouble(), + humiditySliderPositions.endInclusive.roundToInt().toDouble() ) ) )