Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button
import androidx.compose.material.Scaffold
import androidx.compose.material.Switch
import androidx.compose.material.SwitchDefaults
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -38,6 +34,9 @@ import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.lifecycle.withCreationCallback
import io.homeassistant.companion.android.BaseActivity
import io.homeassistant.companion.android.common.R as commonR
import io.homeassistant.companion.android.common.compose.composable.HAAccentButton
import io.homeassistant.companion.android.common.compose.composable.HASwitch
import io.homeassistant.companion.android.common.compose.composable.HATopBar
import io.homeassistant.companion.android.common.compose.theme.HATheme
import io.homeassistant.companion.android.common.data.integration.Entity
import io.homeassistant.companion.android.common.data.websocket.impl.entities.AreaRegistryResponse
Expand All @@ -48,7 +47,6 @@ import io.homeassistant.companion.android.database.server.Server
import io.homeassistant.companion.android.database.widget.WidgetBackgroundType
import io.homeassistant.companion.android.settings.widgets.ManageWidgetsViewModel
import io.homeassistant.companion.android.util.compose.ExposedDropdownMenu
import io.homeassistant.companion.android.util.compose.HomeAssistantAppTheme
import io.homeassistant.companion.android.util.compose.ServerExposedDropdownMenu
import io.homeassistant.companion.android.util.compose.WidgetBackgroundTypeExposedDropdownMenu
import io.homeassistant.companion.android.util.compose.entity.EntityPicker
Expand All @@ -58,8 +56,6 @@ import io.homeassistant.companion.android.util.previewEntity1
import io.homeassistant.companion.android.util.previewEntity2
import io.homeassistant.companion.android.util.previewServer1
import io.homeassistant.companion.android.util.previewServer2
import io.homeassistant.companion.android.util.safeBottomWindowInsets
import io.homeassistant.companion.android.util.safeTopWindowInsets
import kotlinx.coroutines.launch

@AndroidEntryPoint
Expand Down Expand Up @@ -105,7 +101,7 @@ class TodoWidgetConfigureActivity : BaseActivity() {
viewModel.onSetup(widgetId, supportedTextColors)

setContent {
HomeAssistantAppTheme {
HATheme {
TodoWidgetConfigureScreen(
viewModel = viewModel,
onActionClick = { onActionClick() },
Expand Down Expand Up @@ -210,22 +206,17 @@ private fun TodoWidgetConfigureView(
areaRegistry: List<AreaRegistryResponse>? = null,
) {
Scaffold(
contentWindowInsets = WindowInsets.safeDrawing,
topBar = {
TopAppBar(
title = { Text(stringResource(commonR.string.widget_todo_label)) },
windowInsets = safeTopWindowInsets(),
backgroundColor = colorResource(commonR.color.colorBackground),
contentColor = colorResource(commonR.color.colorOnBackground),
)
HATopBar(title = { Text(stringResource(commonR.string.widget_todo_label)) })
},
) { padding ->
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.windowInsetsPadding(safeBottomWindowInsets())
.padding(padding)
.padding(all = 16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
if (servers.size > 1) {
ServerExposedDropdownMenu(
Expand All @@ -236,19 +227,16 @@ private fun TodoWidgetConfigureView(
)
}

// TODO use new theme for Material3 components https://github.com/home-assistant/android/issues/6303
HATheme {
EntityPicker(
entities = entities,
selectedEntityId = selectedEntityId,
onEntitySelectedId = { onEntitySelected(it) },
onEntityCleared = { onEntitySelected(null) },
entityRegistry = entityRegistry,
deviceRegistry = deviceRegistry,
areaRegistry = areaRegistry,
addButtonText = stringResource(commonR.string.todo_widget_select_list),
)
}
EntityPicker(
entities = entities,
selectedEntityId = selectedEntityId,
onEntitySelectedId = { onEntitySelected(it) },
onEntityCleared = { onEntitySelected(null) },
entityRegistry = entityRegistry,
deviceRegistry = deviceRegistry,
areaRegistry = areaRegistry,
addButtonText = stringResource(commonR.string.todo_widget_select_list),
)

Row(
modifier = Modifier.clickable { onShowCompletedChanged(!showCompleted) },
Expand All @@ -260,12 +248,9 @@ private fun TodoWidgetConfigureView(
.weight(1f),
)

Switch(
HASwitch(
checked = showCompleted,
onCheckedChange = { onShowCompletedChanged(it) },
colors = SwitchDefaults.colors(
uncheckedThumbColor = colorResource(commonR.color.colorSwitchUncheckedThumb),
),
)
}

Expand All @@ -288,20 +273,19 @@ private fun TodoWidgetConfigureView(
)
Comment thread
blackredit marked this conversation as resolved.
}

Button(
HAAccentButton(
text = stringResource(if (isUpdateWidget) commonR.string.update_widget else commonR.string.add_widget),
modifier = Modifier.fillMaxWidth(),
onClick = { onActionClick() },
) {
Text(stringResource(if (isUpdateWidget) commonR.string.update_widget else commonR.string.add_widget))
}
onClick = onActionClick,
)
}
}
}

@Preview
@Composable
private fun TodoWidgetConfigureViewPreview() {
HomeAssistantAppTheme {
HATheme {
TodoWidgetConfigureView(
servers = listOf(
previewServer1,
Expand Down