mirror of
https://github.com/home-assistant/android
synced 2024-07-09 04:15:51 +00:00
Sort entities, add time and headers in wear settings (#1912)
* Sort entities, add time and headers in wear settings * Review comment
This commit is contained in:
parent
1e5534de68
commit
fe3bbdf112
|
@ -64,11 +64,12 @@ fun MainView(
|
||||||
var expandedScripts: Boolean by rememberSaveable { mutableStateOf(true) }
|
var expandedScripts: Boolean by rememberSaveable { mutableStateOf(true) }
|
||||||
var expandedSwitches: Boolean by rememberSaveable { mutableStateOf(true) }
|
var expandedSwitches: Boolean by rememberSaveable { mutableStateOf(true) }
|
||||||
|
|
||||||
val scenes = entities.filter { it.key.split(".")[0] == "scene" }.values.toList()
|
val entitiesList = entities.values.toList().sortedBy { it.entityId }
|
||||||
val scripts = entities.filter { it.key.split(".")[0] == "script" }.values.toList()
|
val scenes = entitiesList.filter { it.entityId.split(".")[0] == "scene" }
|
||||||
val lights = entities.filter { it.key.split(".")[0] == "light" }.values.toList()
|
val scripts = entitiesList.filter { it.entityId.split(".")[0] == "script" }
|
||||||
val inputBooleans = entities.filter { it.key.split(".")[0] == "input_boolean" }.values.toList()
|
val lights = entitiesList.filter { it.entityId.split(".")[0] == "light" }
|
||||||
val switches = entities.filter { it.key.split(".")[0] == "switch" }.values.toList()
|
val inputBooleans = entitiesList.filter { it.entityId.split(".")[0] == "input_boolean" }
|
||||||
|
val switches = entitiesList.filter { it.entityId.split(".")[0] == "switch" }
|
||||||
|
|
||||||
val haptic = LocalHapticFeedback.current
|
val haptic = LocalHapticFeedback.current
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
|
@ -17,9 +17,13 @@ import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.wear.compose.material.Chip
|
import androidx.wear.compose.material.Chip
|
||||||
import androidx.wear.compose.material.ChipDefaults
|
import androidx.wear.compose.material.ChipDefaults
|
||||||
|
import androidx.wear.compose.material.ExperimentalWearMaterialApi
|
||||||
|
import androidx.wear.compose.material.PositionIndicator
|
||||||
|
import androidx.wear.compose.material.Scaffold
|
||||||
import androidx.wear.compose.material.ScalingLazyColumn
|
import androidx.wear.compose.material.ScalingLazyColumn
|
||||||
import androidx.wear.compose.material.ScalingLazyListState
|
import androidx.wear.compose.material.ScalingLazyListState
|
||||||
import androidx.wear.compose.material.Text
|
import androidx.wear.compose.material.Text
|
||||||
|
import androidx.wear.compose.material.TimeText
|
||||||
import androidx.wear.compose.material.ToggleChip
|
import androidx.wear.compose.material.ToggleChip
|
||||||
import androidx.wear.compose.material.ToggleChipDefaults
|
import androidx.wear.compose.material.ToggleChipDefaults
|
||||||
import androidx.wear.compose.material.rememberScalingLazyListState
|
import androidx.wear.compose.material.rememberScalingLazyListState
|
||||||
|
@ -31,6 +35,7 @@ import io.homeassistant.companion.android.util.RotaryEventDispatcher
|
||||||
import io.homeassistant.companion.android.util.RotaryEventState
|
import io.homeassistant.companion.android.util.RotaryEventState
|
||||||
import io.homeassistant.companion.android.util.previewFavoritesList
|
import io.homeassistant.companion.android.util.previewFavoritesList
|
||||||
|
|
||||||
|
@ExperimentalWearMaterialApi
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsView(
|
fun SettingsView(
|
||||||
favorites: List<String>,
|
favorites: List<String>,
|
||||||
|
@ -44,159 +49,176 @@ fun SettingsView(
|
||||||
) {
|
) {
|
||||||
val scalingLazyListState: ScalingLazyListState = rememberScalingLazyListState()
|
val scalingLazyListState: ScalingLazyListState = rememberScalingLazyListState()
|
||||||
RotaryEventState(scrollState = scalingLazyListState)
|
RotaryEventState(scrollState = scalingLazyListState)
|
||||||
|
Scaffold(
|
||||||
ScalingLazyColumn(
|
positionIndicator = {
|
||||||
modifier = Modifier
|
if (scalingLazyListState.isScrollInProgress)
|
||||||
.fillMaxSize(),
|
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
||||||
contentPadding = PaddingValues(
|
},
|
||||||
top = 40.dp,
|
timeText = {
|
||||||
start = 8.dp,
|
if (!scalingLazyListState.isScrollInProgress)
|
||||||
end = 8.dp,
|
TimeText()
|
||||||
bottom = 40.dp
|
}
|
||||||
),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
state = scalingLazyListState
|
|
||||||
) {
|
) {
|
||||||
item {
|
ScalingLazyColumn(
|
||||||
ListHeader(id = R.string.settings)
|
modifier = Modifier
|
||||||
}
|
.fillMaxSize(),
|
||||||
item {
|
contentPadding = PaddingValues(
|
||||||
Chip(
|
top = 20.dp,
|
||||||
modifier = Modifier
|
start = 8.dp,
|
||||||
.fillMaxWidth(),
|
end = 8.dp,
|
||||||
icon = {
|
bottom = 40.dp
|
||||||
Image(asset = CommunityMaterial.Icon3.cmd_star)
|
),
|
||||||
},
|
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
label = {
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
Text(
|
state = scalingLazyListState
|
||||||
text = stringResource(id = R.string.favorite)
|
) {
|
||||||
|
item {
|
||||||
|
ListHeader(id = R.string.favorite_settings)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
Chip(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
icon = {
|
||||||
|
Image(asset = CommunityMaterial.Icon3.cmd_star)
|
||||||
|
},
|
||||||
|
label = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.favorite)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = onClickSetFavorites,
|
||||||
|
colors = ChipDefaults.primaryChipColors(
|
||||||
|
contentColor = Color.Black
|
||||||
)
|
)
|
||||||
},
|
|
||||||
onClick = onClickSetFavorites,
|
|
||||||
colors = ChipDefaults.primaryChipColors(
|
|
||||||
contentColor = Color.Black
|
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
item {
|
||||||
item {
|
Chip(
|
||||||
Chip(
|
modifier = Modifier
|
||||||
modifier = Modifier
|
.fillMaxWidth()
|
||||||
.fillMaxWidth(),
|
.padding(top = 10.dp),
|
||||||
icon = {
|
icon = {
|
||||||
Image(asset = CommunityMaterial.Icon.cmd_delete)
|
Image(asset = CommunityMaterial.Icon.cmd_delete)
|
||||||
},
|
},
|
||||||
label = {
|
label = {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = R.string.clear_favorites),
|
text = stringResource(id = R.string.clear_favorites),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = onClearFavorites,
|
||||||
|
colors = ChipDefaults.primaryChipColors(
|
||||||
|
contentColor = Color.Black
|
||||||
|
),
|
||||||
|
secondaryLabel = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.irreverisble)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
enabled = favorites.isNotEmpty()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
ListHeader(
|
||||||
|
id = R.string.feedback_settings,
|
||||||
|
modifier = Modifier.padding(top = 16.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
val haptic = LocalHapticFeedback.current
|
||||||
|
ToggleChip(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 10.dp),
|
||||||
|
checked = isHapticEnabled,
|
||||||
|
onCheckedChange = {
|
||||||
|
onHapticEnabled(it)
|
||||||
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
|
},
|
||||||
|
label = {
|
||||||
|
Text(stringResource(R.string.setting_haptic_label))
|
||||||
|
},
|
||||||
|
appIcon = {
|
||||||
|
Image(
|
||||||
|
asset =
|
||||||
|
if (isHapticEnabled)
|
||||||
|
CommunityMaterial.Icon3.cmd_watch_vibrate
|
||||||
|
else
|
||||||
|
CommunityMaterial.Icon3.cmd_watch_vibrate_off
|
||||||
|
)
|
||||||
|
},
|
||||||
|
colors = ToggleChipDefaults.toggleChipColors(
|
||||||
|
checkedStartBackgroundColor = Color(0xFFAECBFA),
|
||||||
|
checkedEndBackgroundColor = Color(0xFFAECBFA),
|
||||||
|
uncheckedStartBackgroundColor = Color(0xFFAECBFA),
|
||||||
|
uncheckedEndBackgroundColor = Color(0xFFAECBFA),
|
||||||
|
checkedContentColor = Color.Black,
|
||||||
|
uncheckedContentColor = Color.Black,
|
||||||
)
|
)
|
||||||
},
|
)
|
||||||
onClick = onClearFavorites,
|
}
|
||||||
colors = ChipDefaults.primaryChipColors(
|
item {
|
||||||
contentColor = Color.Black
|
ToggleChip(
|
||||||
),
|
modifier = Modifier
|
||||||
secondaryLabel = {
|
.fillMaxWidth()
|
||||||
Text(
|
.padding(top = 10.dp),
|
||||||
text = stringResource(id = R.string.irreverisble)
|
checked = isToastEnabled,
|
||||||
|
onCheckedChange = {
|
||||||
|
onToastEnabled(it)
|
||||||
|
},
|
||||||
|
label = {
|
||||||
|
Text(stringResource(R.string.setting_toast_label))
|
||||||
|
},
|
||||||
|
appIcon = {
|
||||||
|
Image(
|
||||||
|
asset =
|
||||||
|
if (isToastEnabled)
|
||||||
|
CommunityMaterial.Icon3.cmd_message
|
||||||
|
else
|
||||||
|
CommunityMaterial.Icon3.cmd_message_off
|
||||||
|
)
|
||||||
|
},
|
||||||
|
colors = ToggleChipDefaults.toggleChipColors(
|
||||||
|
checkedStartBackgroundColor = Color(0xFFAECBFA),
|
||||||
|
checkedEndBackgroundColor = Color(0xFFAECBFA),
|
||||||
|
uncheckedStartBackgroundColor = Color(0xFFAECBFA),
|
||||||
|
uncheckedEndBackgroundColor = Color(0xFFAECBFA),
|
||||||
|
checkedContentColor = Color.Black,
|
||||||
|
uncheckedContentColor = Color.Black,
|
||||||
)
|
)
|
||||||
},
|
)
|
||||||
enabled = favorites.isNotEmpty()
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
item {
|
||||||
val haptic = LocalHapticFeedback.current
|
ListHeader(
|
||||||
ToggleChip(
|
id = R.string.tile_settings,
|
||||||
modifier = Modifier
|
modifier = Modifier.padding(top = 16.dp)
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(top = 10.dp),
|
|
||||||
checked = isHapticEnabled,
|
|
||||||
onCheckedChange = {
|
|
||||||
onHapticEnabled(it)
|
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
|
||||||
},
|
|
||||||
label = {
|
|
||||||
Text(stringResource(R.string.setting_haptic_label))
|
|
||||||
},
|
|
||||||
appIcon = {
|
|
||||||
Image(
|
|
||||||
asset =
|
|
||||||
if (isHapticEnabled)
|
|
||||||
CommunityMaterial.Icon3.cmd_watch_vibrate
|
|
||||||
else
|
|
||||||
CommunityMaterial.Icon3.cmd_watch_vibrate_off
|
|
||||||
)
|
|
||||||
},
|
|
||||||
colors = ToggleChipDefaults.toggleChipColors(
|
|
||||||
checkedStartBackgroundColor = Color(0xFFAECBFA),
|
|
||||||
checkedEndBackgroundColor = Color(0xFFAECBFA),
|
|
||||||
uncheckedStartBackgroundColor = Color(0xFFAECBFA),
|
|
||||||
uncheckedEndBackgroundColor = Color(0xFFAECBFA),
|
|
||||||
checkedContentColor = Color.Black,
|
|
||||||
uncheckedContentColor = Color.Black,
|
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
item {
|
||||||
item {
|
Chip(
|
||||||
ToggleChip(
|
modifier = Modifier
|
||||||
modifier = Modifier
|
.fillMaxWidth(),
|
||||||
.fillMaxWidth()
|
icon = {
|
||||||
.padding(top = 10.dp),
|
Image(asset = CommunityMaterial.Icon3.cmd_star_circle_outline)
|
||||||
checked = isToastEnabled,
|
},
|
||||||
onCheckedChange = {
|
label = {
|
||||||
onToastEnabled(it)
|
Text(
|
||||||
},
|
text = stringResource(id = R.string.shortcuts)
|
||||||
label = {
|
)
|
||||||
Text(stringResource(R.string.setting_toast_label))
|
},
|
||||||
},
|
onClick = onClickSetShortcuts,
|
||||||
appIcon = {
|
colors = ChipDefaults.primaryChipColors(
|
||||||
Image(
|
contentColor = Color.Black
|
||||||
asset =
|
|
||||||
if (isToastEnabled)
|
|
||||||
CommunityMaterial.Icon3.cmd_message
|
|
||||||
else
|
|
||||||
CommunityMaterial.Icon3.cmd_message_off
|
|
||||||
)
|
|
||||||
},
|
|
||||||
colors = ToggleChipDefaults.toggleChipColors(
|
|
||||||
checkedStartBackgroundColor = Color(0xFFAECBFA),
|
|
||||||
checkedEndBackgroundColor = Color(0xFFAECBFA),
|
|
||||||
uncheckedStartBackgroundColor = Color(0xFFAECBFA),
|
|
||||||
uncheckedEndBackgroundColor = Color(0xFFAECBFA),
|
|
||||||
checkedContentColor = Color.Black,
|
|
||||||
uncheckedContentColor = Color.Black,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
ListHeader(
|
|
||||||
id = R.string.tile_settings,
|
|
||||||
modifier = Modifier.padding(top = 16.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
item {
|
|
||||||
Chip(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(),
|
|
||||||
icon = {
|
|
||||||
Image(asset = CommunityMaterial.Icon3.cmd_star_circle_outline)
|
|
||||||
},
|
|
||||||
label = {
|
|
||||||
Text(
|
|
||||||
text = stringResource(id = R.string.shortcuts)
|
|
||||||
)
|
)
|
||||||
},
|
|
||||||
onClick = onClickSetShortcuts,
|
|
||||||
colors = ChipDefaults.primaryChipColors(
|
|
||||||
contentColor = Color.Black
|
|
||||||
|
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalWearMaterialApi
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun PreviewSettingsView() {
|
private fun PreviewSettingsView() {
|
||||||
|
|
|
@ -49,4 +49,6 @@
|
||||||
<string name="toast_message">%1$s was selected</string>
|
<string name="toast_message">%1$s was selected</string>
|
||||||
<string name="setting_toast_label">Enable Toast Confirmation</string>
|
<string name="setting_toast_label">Enable Toast Confirmation</string>
|
||||||
<string name="setting_haptic_label">Enable Haptic Feeback</string>
|
<string name="setting_haptic_label">Enable Haptic Feeback</string>
|
||||||
|
<string name="feedback_settings">Feedback Settings</string>
|
||||||
|
<string name="favorite_settings">Favorite Settings</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user