Skip to content

Commit

Permalink
Add icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Andryss committed Apr 26, 2024
1 parent 77a25b1 commit c0b757c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.vivlaniv.nexohub.entities

import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
Expand All @@ -20,6 +24,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
Expand All @@ -29,8 +34,9 @@ import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
Expand All @@ -45,30 +51,58 @@ import org.vivlaniv.nexohub.AppState
import org.vivlaniv.nexohub.DeviceInfo
import org.vivlaniv.nexohub.PropertyInfo
import org.vivlaniv.nexohub.PutDevicePropertyTask
import org.vivlaniv.nexohub.R
import org.vivlaniv.nexohub.SavedDevice
import org.vivlaniv.nexohub.SendDeviceSignalTask
import org.vivlaniv.nexohub.SignalInfo
import org.vivlaniv.nexohub.TAG
import org.vivlaniv.nexohub.Type


val typeImage = mapOf(
"Lamp" to R.drawable.lamp,
"Teapot" to R.drawable.teapot
)

@Composable
fun DeviceCard(state: AppState, device: SavedDevice) {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
) {
Text(
modifier = Modifier.padding(4.dp),
text = device.alias ?: device.type,
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically
) {
Surface(
modifier = Modifier
.size(100.dp)
.padding(8.dp)
.border(1.dp, Color.Gray, RoundedCornerShape(10.dp)),
color = Color.Transparent
) {
Image(
painter = painterResource(id = typeImage.getOrDefault(device.type, R.drawable.question)),
contentDescription = device.type,
modifier = Modifier.padding(8.dp)
)
}
Column {
Text(
modifier = Modifier.padding(4.dp),
text = device.alias ?: device.type,
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)

Text(
modifier = Modifier.padding(4.dp),
text = device.type
)
Text(
modifier = Modifier.padding(4.dp),
text = device.type
)
}
}

if (device.room != null) {
Text(
Expand Down Expand Up @@ -139,7 +173,6 @@ fun DeviceProperty(state: AppState, device: String, propertyInfo: PropertyInfo)
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun TextFieldDeviceProperty(propertyInfo: PropertyInfo, putPropertyCallback: (Int) -> Unit) {

Expand Down
Binary file added mobile-app/src/main/res/drawable/lamp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mobile-app/src/main/res/drawable/question.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mobile-app/src/main/res/drawable/teapot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Lamp(

class Teapot(
private var volume: Int = 70,
private var temperature: Int = 0
private var temperature: Int = 20
) : AbstractDevice() {
init {
// TODO: coroutines
Expand Down

0 comments on commit c0b757c

Please sign in to comment.