mirror of
https://github.com/home-assistant/android
synced 2024-10-07 00:29:32 +00:00
Update Wear Scaffold usage to be more consistent (#3562)
* Update TimeText to only show at the top of the screen * Add Scaffold with PositionIndicator and TimeText where missing
This commit is contained in:
parent
2ff492a1c2
commit
8dac1627f4
|
@ -44,7 +44,7 @@ fun ConversationResultView(
|
||||||
PositionIndicator(scalingLazyListState = scrollState)
|
PositionIndicator(scalingLazyListState = scrollState)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
timeText = { TimeText(visible = !scrollState.isScrollInProgress) }
|
timeText = { TimeText(scalingLazyListState = scrollState) }
|
||||||
) {
|
) {
|
||||||
ScalingLazyColumn(
|
ScalingLazyColumn(
|
||||||
state = scrollState,
|
state = scrollState,
|
||||||
|
|
|
@ -22,10 +22,13 @@ import androidx.compose.ui.unit.dp
|
||||||
import androidx.wear.compose.material.Icon
|
import androidx.wear.compose.material.Icon
|
||||||
import androidx.wear.compose.material.InlineSlider
|
import androidx.wear.compose.material.InlineSlider
|
||||||
import androidx.wear.compose.material.InlineSliderDefaults
|
import androidx.wear.compose.material.InlineSliderDefaults
|
||||||
|
import androidx.wear.compose.material.PositionIndicator
|
||||||
|
import androidx.wear.compose.material.Scaffold
|
||||||
import androidx.wear.compose.material.Text
|
import androidx.wear.compose.material.Text
|
||||||
import androidx.wear.compose.material.ToggleButton
|
import androidx.wear.compose.material.ToggleButton
|
||||||
import androidx.wear.compose.material.ToggleButtonDefaults
|
import androidx.wear.compose.material.ToggleButtonDefaults
|
||||||
import androidx.wear.compose.material.ToggleChipDefaults
|
import androidx.wear.compose.material.ToggleChipDefaults
|
||||||
|
import androidx.wear.compose.material.rememberScalingLazyListState
|
||||||
import com.mikepenz.iconics.compose.Image
|
import com.mikepenz.iconics.compose.Image
|
||||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||||
import io.homeassistant.companion.android.common.R
|
import io.homeassistant.companion.android.common.R
|
||||||
|
@ -60,106 +63,116 @@ fun DetailsPanelView(
|
||||||
) {
|
) {
|
||||||
val haptic = LocalHapticFeedback.current
|
val haptic = LocalHapticFeedback.current
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val scalingLazyListState = rememberScalingLazyListState()
|
||||||
|
|
||||||
WearAppTheme {
|
WearAppTheme {
|
||||||
ThemeLazyColumn {
|
Scaffold(
|
||||||
val attributes = entity.attributes as Map<*, *>
|
positionIndicator = {
|
||||||
|
if (scalingLazyListState.isScrollInProgress) {
|
||||||
|
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
|
||||||
|
) {
|
||||||
|
ThemeLazyColumn(state = scalingLazyListState) {
|
||||||
|
val attributes = entity.attributes as Map<*, *>
|
||||||
|
|
||||||
item {
|
item {
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
val friendlyName = attributes["friendly_name"].toString()
|
val friendlyName = attributes["friendly_name"].toString()
|
||||||
Text(friendlyName)
|
Text(friendlyName)
|
||||||
|
|
||||||
if (entity.domain in HomePresenterImpl.toggleDomains) {
|
if (entity.domain in HomePresenterImpl.toggleDomains) {
|
||||||
val isChecked = entity.state in listOf("on", "locked", "open", "opening")
|
val isChecked = entity.state in listOf("on", "locked", "open", "opening")
|
||||||
ToggleButton(
|
ToggleButton(
|
||||||
checked = isChecked,
|
checked = isChecked,
|
||||||
onCheckedChange = {
|
onCheckedChange = {
|
||||||
onEntityToggled(entity.entityId, entity.state)
|
onEntityToggled(entity.entityId, entity.state)
|
||||||
onEntityClickedFeedback(
|
onEntityClickedFeedback(
|
||||||
isToastEnabled,
|
isToastEnabled,
|
||||||
isHapticEnabled,
|
isHapticEnabled,
|
||||||
context,
|
context,
|
||||||
friendlyName,
|
friendlyName,
|
||||||
haptic
|
haptic
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(start = 16.dp)
|
||||||
|
.size(ToggleButtonDefaults.SmallToggleButtonSize)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = ToggleChipDefaults.switchIcon(isChecked),
|
||||||
|
contentDescription = if (isChecked) {
|
||||||
|
stringResource(R.string.enabled)
|
||||||
|
} else {
|
||||||
|
stringResource(R.string.disabled)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
},
|
}
|
||||||
modifier = Modifier
|
|
||||||
.padding(start = 16.dp)
|
|
||||||
.size(ToggleButtonDefaults.SmallToggleButtonSize)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
imageVector = ToggleChipDefaults.switchIcon(isChecked),
|
|
||||||
contentDescription = if (isChecked) {
|
|
||||||
stringResource(R.string.enabled)
|
|
||||||
} else {
|
|
||||||
stringResource(R.string.disabled)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (entity.domain == "fan") {
|
if (entity.domain == "fan") {
|
||||||
if (entity.supportsFanSetSpeed()) {
|
if (entity.supportsFanSetSpeed()) {
|
||||||
item {
|
item {
|
||||||
FanSpeedSlider(entity, onFanSpeedChanged, isToastEnabled, isHapticEnabled)
|
FanSpeedSlider(entity, onFanSpeedChanged, isToastEnabled, isHapticEnabled)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (entity.domain == "light") {
|
||||||
if (entity.domain == "light") {
|
if (entity.supportsLightBrightness()) {
|
||||||
if (entity.supportsLightBrightness()) {
|
item {
|
||||||
item {
|
BrightnessSlider(entity, onBrightnessChanged, isToastEnabled, isHapticEnabled)
|
||||||
BrightnessSlider(entity, onBrightnessChanged, isToastEnabled, isHapticEnabled)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.supportsLightColorTemperature() && attributes["color_mode"] == EntityExt.LIGHT_MODE_COLOR_TEMP) {
|
||||||
|
item {
|
||||||
|
ColorTempSlider(attributes, onColorTempChanged, isToastEnabled, isHapticEnabled)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity.supportsLightColorTemperature() && attributes["color_mode"] == EntityExt.LIGHT_MODE_COLOR_TEMP) {
|
item {
|
||||||
item {
|
ListHeader(R.string.details)
|
||||||
ColorTempSlider(attributes, onColorTempChanged, isToastEnabled, isHapticEnabled)
|
}
|
||||||
}
|
item {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.state_name, entity.state),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
val lastChanged = DateFormat.getDateTimeInstance().format(entity.lastChanged.time)
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.last_changed, lastChanged),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
val lastUpdated = DateFormat.getDateTimeInstance().format(entity.lastUpdated.time)
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.last_updated, lastUpdated),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.entity_id_name, entity.entityId),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 8.dp)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
ListHeader(R.string.details)
|
|
||||||
}
|
|
||||||
item {
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.state_name, entity.state),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 8.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
item {
|
|
||||||
val lastChanged = DateFormat.getDateTimeInstance().format(entity.lastChanged.time)
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.last_changed, lastChanged),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 8.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
item {
|
|
||||||
val lastUpdated = DateFormat.getDateTimeInstance().format(entity.lastUpdated.time)
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.last_updated, lastUpdated),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 8.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
item {
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.entity_id_name, entity.entityId),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 8.dp)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,11 @@ import androidx.compose.ui.tooling.preview.Devices
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
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.PositionIndicator
|
||||||
|
import androidx.wear.compose.material.Scaffold
|
||||||
import androidx.wear.compose.material.Text
|
import androidx.wear.compose.material.Text
|
||||||
import androidx.wear.compose.material.items
|
import androidx.wear.compose.material.items
|
||||||
|
import androidx.wear.compose.material.rememberScalingLazyListState
|
||||||
import io.homeassistant.companion.android.common.data.integration.Entity
|
import io.homeassistant.companion.android.common.data.integration.Entity
|
||||||
import io.homeassistant.companion.android.theme.WearAppTheme
|
import io.homeassistant.companion.android.theme.WearAppTheme
|
||||||
import io.homeassistant.companion.android.util.playPreviewEntityScene1
|
import io.homeassistant.companion.android.util.playPreviewEntityScene1
|
||||||
|
@ -35,47 +38,57 @@ fun EntityViewList(
|
||||||
) {
|
) {
|
||||||
// Remember expanded state of each header
|
// Remember expanded state of each header
|
||||||
val expandedStates = rememberExpandedStates(entityLists.keys.map { it.hashCode() })
|
val expandedStates = rememberExpandedStates(entityLists.keys.map { it.hashCode() })
|
||||||
|
val scalingLazyListState = rememberScalingLazyListState()
|
||||||
|
|
||||||
WearAppTheme {
|
WearAppTheme {
|
||||||
ThemeLazyColumn {
|
Scaffold(
|
||||||
for (header in entityListsOrder) {
|
positionIndicator = {
|
||||||
val entities = entityLists[header].orEmpty()
|
if (scalingLazyListState.isScrollInProgress) {
|
||||||
if (entities.isNotEmpty()) {
|
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
||||||
item {
|
}
|
||||||
if (entityLists.size > 1) {
|
},
|
||||||
ExpandableListHeader(
|
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
|
||||||
string = header,
|
) {
|
||||||
key = header.hashCode(),
|
ThemeLazyColumn(state = scalingLazyListState) {
|
||||||
expandedStates = expandedStates
|
for (header in entityListsOrder) {
|
||||||
)
|
val entities = entityLists[header].orEmpty()
|
||||||
} else {
|
if (entities.isNotEmpty()) {
|
||||||
ListHeader(header)
|
item {
|
||||||
}
|
if (entityLists.size > 1) {
|
||||||
}
|
ExpandableListHeader(
|
||||||
if (expandedStates[header.hashCode()]!!) {
|
string = header,
|
||||||
val filtered = entities.filter { entityListFilter(it) }
|
key = header.hashCode(),
|
||||||
items(filtered, key = { it.entityId }) { entity ->
|
expandedStates = expandedStates
|
||||||
EntityUi(
|
)
|
||||||
entity,
|
} else {
|
||||||
onEntityClicked,
|
ListHeader(header)
|
||||||
isHapticEnabled,
|
}
|
||||||
isToastEnabled
|
|
||||||
) { entityId -> onEntityLongClicked(entityId) }
|
|
||||||
}
|
}
|
||||||
|
if (expandedStates[header.hashCode()]!!) {
|
||||||
|
val filtered = entities.filter { entityListFilter(it) }
|
||||||
|
items(filtered, key = { it.entityId }) { entity ->
|
||||||
|
EntityUi(
|
||||||
|
entity,
|
||||||
|
onEntityClicked,
|
||||||
|
isHapticEnabled,
|
||||||
|
isToastEnabled
|
||||||
|
) { entityId -> onEntityLongClicked(entityId) }
|
||||||
|
}
|
||||||
|
|
||||||
if (filtered.isEmpty()) {
|
if (filtered.isEmpty()) {
|
||||||
item {
|
item {
|
||||||
Column {
|
Column {
|
||||||
Chip(
|
Chip(
|
||||||
label = {
|
label = {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(commonR.string.loading_entities),
|
text = stringResource(commonR.string.loading_entities),
|
||||||
textAlign = TextAlign.Center
|
textAlign = TextAlign.Center
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onClick = { /* No op */ },
|
onClick = { /* No op */ },
|
||||||
colors = ChipDefaults.primaryChipColors()
|
colors = ChipDefaults.primaryChipColors()
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ fun MainView(
|
||||||
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
timeText = { TimeText(!scalingLazyListState.isScrollInProgress) }
|
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
|
||||||
) {
|
) {
|
||||||
ThemeLazyColumn(
|
ThemeLazyColumn(
|
||||||
state = scalingLazyListState
|
state = scalingLazyListState
|
||||||
|
|
|
@ -40,7 +40,7 @@ fun SensorManagerUi(
|
||||||
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
timeText = { TimeText(!scalingLazyListState.isScrollInProgress) }
|
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
|
||||||
) {
|
) {
|
||||||
ThemeLazyColumn(
|
ThemeLazyColumn(
|
||||||
state = scalingLazyListState
|
state = scalingLazyListState
|
||||||
|
|
|
@ -36,7 +36,7 @@ fun SensorsView(
|
||||||
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
timeText = { TimeText(!scalingLazyListState.isScrollInProgress) }
|
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
|
||||||
) {
|
) {
|
||||||
val sensorManagers = getSensorManagers()
|
val sensorManagers = getSensorManagers()
|
||||||
ThemeLazyColumn(
|
ThemeLazyColumn(
|
||||||
|
|
|
@ -47,7 +47,7 @@ fun SetFavoritesView(
|
||||||
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
timeText = { TimeText(!scalingLazyListState.isScrollInProgress) }
|
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
|
||||||
) {
|
) {
|
||||||
ThemeLazyColumn(
|
ThemeLazyColumn(
|
||||||
state = scalingLazyListState
|
state = scalingLazyListState
|
||||||
|
|
|
@ -17,9 +17,12 @@ import androidx.wear.compose.material.ButtonDefaults
|
||||||
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.Icon
|
import androidx.wear.compose.material.Icon
|
||||||
|
import androidx.wear.compose.material.PositionIndicator
|
||||||
|
import androidx.wear.compose.material.Scaffold
|
||||||
import androidx.wear.compose.material.Text
|
import androidx.wear.compose.material.Text
|
||||||
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 com.mikepenz.iconics.compose.Image
|
import com.mikepenz.iconics.compose.Image
|
||||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||||
import io.homeassistant.companion.android.data.SimplifiedEntity
|
import io.homeassistant.companion.android.data.SimplifiedEntity
|
||||||
|
@ -38,88 +41,98 @@ fun SetTileShortcutsView(
|
||||||
isShowShortcutTextEnabled: Boolean,
|
isShowShortcutTextEnabled: Boolean,
|
||||||
onShowShortcutTextEnabled: (Boolean) -> Unit
|
onShowShortcutTextEnabled: (Boolean) -> Unit
|
||||||
) {
|
) {
|
||||||
|
val scalingLazyListState = rememberScalingLazyListState()
|
||||||
WearAppTheme {
|
WearAppTheme {
|
||||||
ThemeLazyColumn {
|
Scaffold(
|
||||||
item {
|
positionIndicator = {
|
||||||
ListHeader(id = commonR.string.shortcuts_tile)
|
if (scalingLazyListState.isScrollInProgress) {
|
||||||
}
|
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
||||||
item {
|
}
|
||||||
ToggleChip(
|
},
|
||||||
modifier = Modifier.fillMaxWidth(),
|
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
|
||||||
checked = isShowShortcutTextEnabled,
|
) {
|
||||||
onCheckedChange = { onShowShortcutTextEnabled(it) },
|
ThemeLazyColumn(state = scalingLazyListState) {
|
||||||
label = {
|
|
||||||
Text(stringResource(commonR.string.shortcuts_tile_text_setting))
|
|
||||||
},
|
|
||||||
appIcon = {
|
|
||||||
Image(
|
|
||||||
asset =
|
|
||||||
if (isShowShortcutTextEnabled) {
|
|
||||||
CommunityMaterial.Icon.cmd_alphabetical
|
|
||||||
} else {
|
|
||||||
CommunityMaterial.Icon.cmd_alphabetical_off
|
|
||||||
},
|
|
||||||
colorFilter = ColorFilter.tint(wearColorPalette.onSurface)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
toggleControl = {
|
|
||||||
Icon(
|
|
||||||
imageVector = ToggleChipDefaults.checkboxIcon(isShowShortcutTextEnabled),
|
|
||||||
contentDescription = if (isShowShortcutTextEnabled) {
|
|
||||||
stringResource(commonR.string.show)
|
|
||||||
} else {
|
|
||||||
stringResource(commonR.string.hide)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
item {
|
|
||||||
ListHeader(id = commonR.string.shortcuts_choose)
|
|
||||||
}
|
|
||||||
items(shortcutEntities.size) { index ->
|
|
||||||
|
|
||||||
val iconBitmap = getIcon(
|
|
||||||
shortcutEntities[index].icon,
|
|
||||||
shortcutEntities[index].domain,
|
|
||||||
LocalContext.current
|
|
||||||
)
|
|
||||||
|
|
||||||
Chip(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(),
|
|
||||||
icon = {
|
|
||||||
Image(
|
|
||||||
iconBitmap ?: CommunityMaterial.Icon.cmd_bookmark,
|
|
||||||
colorFilter = ColorFilter.tint(Color.White)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
label = {
|
|
||||||
Text(
|
|
||||||
text = stringResource(commonR.string.shortcut_n, index + 1)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
secondaryLabel = {
|
|
||||||
Text(
|
|
||||||
text = shortcutEntities[index].friendlyName,
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onClick = { onShortcutEntitySelectionChange(index) },
|
|
||||||
colors = ChipDefaults.secondaryChipColors()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (shortcutEntities.size < 7) {
|
|
||||||
item {
|
item {
|
||||||
Button(
|
ListHeader(id = commonR.string.shortcuts_tile)
|
||||||
modifier = Modifier.padding(top = 16.dp),
|
}
|
||||||
onClick = { onShortcutEntitySelectionChange(shortcutEntities.size) },
|
item {
|
||||||
colors = ButtonDefaults.primaryButtonColors()
|
ToggleChip(
|
||||||
) {
|
modifier = Modifier.fillMaxWidth(),
|
||||||
Image(
|
checked = isShowShortcutTextEnabled,
|
||||||
CommunityMaterial.Icon3.cmd_plus_thick
|
onCheckedChange = { onShowShortcutTextEnabled(it) },
|
||||||
)
|
label = {
|
||||||
|
Text(stringResource(commonR.string.shortcuts_tile_text_setting))
|
||||||
|
},
|
||||||
|
appIcon = {
|
||||||
|
Image(
|
||||||
|
asset =
|
||||||
|
if (isShowShortcutTextEnabled) {
|
||||||
|
CommunityMaterial.Icon.cmd_alphabetical
|
||||||
|
} else {
|
||||||
|
CommunityMaterial.Icon.cmd_alphabetical_off
|
||||||
|
},
|
||||||
|
colorFilter = ColorFilter.tint(wearColorPalette.onSurface)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
toggleControl = {
|
||||||
|
Icon(
|
||||||
|
imageVector = ToggleChipDefaults.checkboxIcon(isShowShortcutTextEnabled),
|
||||||
|
contentDescription = if (isShowShortcutTextEnabled) {
|
||||||
|
stringResource(commonR.string.show)
|
||||||
|
} else {
|
||||||
|
stringResource(commonR.string.hide)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
ListHeader(id = commonR.string.shortcuts_choose)
|
||||||
|
}
|
||||||
|
items(shortcutEntities.size) { index ->
|
||||||
|
|
||||||
|
val iconBitmap = getIcon(
|
||||||
|
shortcutEntities[index].icon,
|
||||||
|
shortcutEntities[index].domain,
|
||||||
|
LocalContext.current
|
||||||
|
)
|
||||||
|
|
||||||
|
Chip(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
icon = {
|
||||||
|
Image(
|
||||||
|
iconBitmap ?: CommunityMaterial.Icon.cmd_bookmark,
|
||||||
|
colorFilter = ColorFilter.tint(Color.White)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
label = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(commonR.string.shortcut_n, index + 1)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
secondaryLabel = {
|
||||||
|
Text(
|
||||||
|
text = shortcutEntities[index].friendlyName,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = { onShortcutEntitySelectionChange(index) },
|
||||||
|
colors = ChipDefaults.secondaryChipColors()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (shortcutEntities.size < 7) {
|
||||||
|
item {
|
||||||
|
Button(
|
||||||
|
modifier = Modifier.padding(top = 16.dp),
|
||||||
|
onClick = { onShortcutEntitySelectionChange(shortcutEntities.size) },
|
||||||
|
colors = ButtonDefaults.primaryButtonColors()
|
||||||
|
) {
|
||||||
|
Image(
|
||||||
|
CommunityMaterial.Icon3.cmd_plus_thick
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ fun SettingsView(
|
||||||
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
timeText = { TimeText(!scalingLazyListState.isScrollInProgress) }
|
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
|
||||||
) {
|
) {
|
||||||
ThemeLazyColumn(
|
ThemeLazyColumn(
|
||||||
state = scalingLazyListState
|
state = scalingLazyListState
|
||||||
|
|
|
@ -12,10 +12,14 @@ import androidx.compose.ui.tooling.preview.Devices
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
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.PositionIndicator
|
||||||
|
import androidx.wear.compose.material.Scaffold
|
||||||
import androidx.wear.compose.material.Text
|
import androidx.wear.compose.material.Text
|
||||||
|
import androidx.wear.compose.material.rememberScalingLazyListState
|
||||||
import com.mikepenz.iconics.compose.Image
|
import com.mikepenz.iconics.compose.Image
|
||||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||||
import io.homeassistant.companion.android.common.R
|
import io.homeassistant.companion.android.common.R
|
||||||
|
import io.homeassistant.companion.android.theme.WearAppTheme
|
||||||
import io.homeassistant.companion.android.theme.wearColorPalette
|
import io.homeassistant.companion.android.theme.wearColorPalette
|
||||||
import io.homeassistant.companion.android.util.IntervalToString
|
import io.homeassistant.companion.android.util.IntervalToString
|
||||||
import io.homeassistant.companion.android.views.ListHeader
|
import io.homeassistant.companion.android.views.ListHeader
|
||||||
|
@ -27,41 +31,53 @@ fun TemplateTileSettingsView(
|
||||||
refreshInterval: Int,
|
refreshInterval: Int,
|
||||||
onClickRefreshInterval: () -> Unit
|
onClickRefreshInterval: () -> Unit
|
||||||
) {
|
) {
|
||||||
ThemeLazyColumn {
|
val scalingLazyListState = rememberScalingLazyListState()
|
||||||
item {
|
WearAppTheme {
|
||||||
ListHeader(id = R.string.template_tile)
|
Scaffold(
|
||||||
}
|
positionIndicator = {
|
||||||
item {
|
if (scalingLazyListState.isScrollInProgress) {
|
||||||
Chip(
|
PositionIndicator(scalingLazyListState = scalingLazyListState)
|
||||||
modifier = Modifier
|
}
|
||||||
.fillMaxWidth(),
|
},
|
||||||
icon = {
|
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
|
||||||
Image(
|
) {
|
||||||
asset = CommunityMaterial.Icon3.cmd_timer_cog,
|
ThemeLazyColumn(state = scalingLazyListState) {
|
||||||
colorFilter = ColorFilter.tint(wearColorPalette.onSurface)
|
item {
|
||||||
|
ListHeader(id = R.string.template_tile)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
Chip(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
icon = {
|
||||||
|
Image(
|
||||||
|
asset = CommunityMaterial.Icon3.cmd_timer_cog,
|
||||||
|
colorFilter = ColorFilter.tint(wearColorPalette.onSurface)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
colors = ChipDefaults.secondaryChipColors(),
|
||||||
|
label = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.refresh_interval)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
secondaryLabel = { Text(IntervalToString(LocalContext.current, refreshInterval)) },
|
||||||
|
onClick = onClickRefreshInterval
|
||||||
)
|
)
|
||||||
},
|
}
|
||||||
colors = ChipDefaults.secondaryChipColors(),
|
item {
|
||||||
label = {
|
ListHeader(R.string.template_tile_content)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
Text(stringResource(R.string.template_tile_change_message))
|
||||||
|
}
|
||||||
|
item {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = R.string.refresh_interval)
|
templateContent,
|
||||||
|
color = Color.DarkGray
|
||||||
)
|
)
|
||||||
},
|
}
|
||||||
secondaryLabel = { Text(IntervalToString(LocalContext.current, refreshInterval)) },
|
}
|
||||||
onClick = onClickRefreshInterval
|
|
||||||
)
|
|
||||||
}
|
|
||||||
item {
|
|
||||||
ListHeader(R.string.template_tile_content)
|
|
||||||
}
|
|
||||||
item {
|
|
||||||
Text(stringResource(R.string.template_tile_change_message))
|
|
||||||
}
|
|
||||||
item {
|
|
||||||
Text(
|
|
||||||
templateContent,
|
|
||||||
color = Color.DarkGray
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,28 @@
|
||||||
package io.homeassistant.companion.android.home.views
|
package io.homeassistant.companion.android.home.views
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
|
||||||
import androidx.compose.animation.slideInVertically
|
|
||||||
import androidx.compose.animation.slideOutVertically
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Devices
|
import androidx.compose.ui.tooling.preview.Devices
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.wear.compose.material.ScalingLazyListState
|
||||||
import androidx.wear.compose.material.TimeText
|
import androidx.wear.compose.material.TimeText
|
||||||
|
import androidx.wear.compose.material.rememberScalingLazyListState
|
||||||
|
import androidx.wear.compose.material.scrollAway
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TimeText(
|
fun TimeText(
|
||||||
visible: Boolean
|
scalingLazyListState: ScalingLazyListState
|
||||||
) {
|
) {
|
||||||
AnimatedVisibility(
|
TimeText(
|
||||||
visible = visible,
|
modifier = Modifier.scrollAway(scrollState = scalingLazyListState)
|
||||||
enter = slideInVertically(),
|
)
|
||||||
exit = slideOutVertically()
|
|
||||||
) {
|
|
||||||
TimeText()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(device = Devices.WEAR_OS_LARGE_ROUND)
|
@Preview(device = Devices.WEAR_OS_LARGE_ROUND)
|
||||||
@Composable
|
@Composable
|
||||||
private fun PreviewTimeText() {
|
private fun PreviewTimeText() {
|
||||||
CompositionLocalProvider {
|
CompositionLocalProvider {
|
||||||
TimeText(visible = true)
|
TimeText(scalingLazyListState = rememberScalingLazyListState())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ fun PhoneInstallView(
|
||||||
PositionIndicator(scalingLazyListState = scrollState)
|
PositionIndicator(scalingLazyListState = scrollState)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
timeText = { TimeText(visible = !scrollState.isScrollInProgress) }
|
timeText = { TimeText(scalingLazyListState = scrollState) }
|
||||||
) {
|
) {
|
||||||
Box(modifier = Modifier.background(MaterialTheme.colors.background)) {
|
Box(modifier = Modifier.background(MaterialTheme.colors.background)) {
|
||||||
ThemeLazyColumn(state = scrollState) {
|
ThemeLazyColumn(state = scrollState) {
|
||||||
|
|
Loading…
Reference in a new issue