Skip to content

Commit

Permalink
Merge pull request #2 from Agung-Krisna/futureFeatures
Browse files Browse the repository at this point in the history
feat: changing data type from Integer to Double
  • Loading branch information
Agung-Krisna authored Jul 21, 2024
2 parents 0cd6f5b + 39b226f commit fe62b31
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
8 changes: 8 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions app/src/main/java/id/my/kaorikizuna/incu8tor/model/DeviceModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ 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
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(
Expand All @@ -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),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
)
Expand Down Expand Up @@ -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()
)
)
)
Expand Down Expand Up @@ -213,7 +218,6 @@ fun AddDeviceScreen(onSave: (DeviceDetail) -> Unit, onBackClicked: () -> Unit) {
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(onClick = {
Log.w("asdfasdf", "$deviceDetail")
onSave(deviceDetail)
onBackClicked()
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
)
)
Expand Down Expand Up @@ -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()
)
)
)
Expand Down

0 comments on commit fe62b31

Please sign in to comment.