-
-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial implementation of template tile Includes settings on phone and watch. Watch settings will be removed in next commit * Add refresh interval setting to wear app * Update wear settings layout * Add interval setting to phone app * ktlint * Add example image to the manifest * Add preview of rendered template in phone settings * Process review comments * Use resources for interval strings
- Loading branch information
1 parent
70e6207
commit 3a15c0f
Showing
22 changed files
with
664 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...l/java/io/homeassistant/companion/android/settings/wear/views/SettingsWearTemplateTile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package io.homeassistant.companion.android.settings.wear.views | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material.DropdownMenu | ||
import androidx.compose.material.DropdownMenuItem | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.OutlinedButton | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TextField | ||
import androidx.compose.material.TopAppBar | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.HelpOutline | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.mikepenz.iconics.compose.Image | ||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial | ||
import io.homeassistant.companion.android.R | ||
import io.homeassistant.companion.android.util.IntervalToString | ||
import io.homeassistant.companion.android.common.R as commonR | ||
|
||
@Composable | ||
fun SettingsWearTemplateTile( | ||
template: String, | ||
renderedTemplate: String, | ||
refreshInterval: Int, | ||
onContentChanged: (String) -> Unit, | ||
onRefreshIntervalChanged: (Int) -> Unit, | ||
onBackClicked: () -> Unit | ||
) { | ||
val context = LocalContext.current | ||
Scaffold( | ||
topBar = { | ||
TopAppBar( | ||
title = { Text(stringResource(commonR.string.template_tile)) }, | ||
navigationIcon = { | ||
IconButton( | ||
onClick = onBackClicked | ||
) { | ||
Image( | ||
asset = CommunityMaterial.Icon.cmd_arrow_left, | ||
colorFilter = ColorFilter.tint(colorResource(R.color.colorIcon)) | ||
) | ||
} | ||
}, | ||
actions = { | ||
IconButton(onClick = { | ||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(WEAR_DOCS_LINK)) | ||
context.startActivity(intent) | ||
}) { | ||
Icon( | ||
Icons.Filled.HelpOutline, | ||
contentDescription = stringResource(id = commonR.string.help) | ||
) | ||
} | ||
} | ||
) | ||
} | ||
) { | ||
Column(Modifier.padding(all = 16.dp)) { | ||
Row(verticalAlignment = Alignment.CenterVertically) { | ||
Image( | ||
asset = CommunityMaterial.Icon3.cmd_timer_cog, | ||
colorFilter = ColorFilter.tint(colorResource(R.color.colorPrimary)), | ||
modifier = Modifier | ||
.height(24.dp) | ||
.width(24.dp) | ||
) | ||
Text( | ||
stringResource(commonR.string.refresh_interval), | ||
modifier = Modifier.padding(start = 4.dp, end = 4.dp) | ||
) | ||
Box { | ||
var dropdownExpanded by remember { mutableStateOf(false) } | ||
OutlinedButton( | ||
onClick = { dropdownExpanded = true } | ||
) { | ||
Text(IntervalToString(LocalContext.current, refreshInterval)) | ||
} | ||
DropdownMenu( | ||
expanded = dropdownExpanded, | ||
onDismissRequest = { dropdownExpanded = false } | ||
) { | ||
val options = listOf(0, 60, 2 * 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60, 60 * 60, 5 * 60 * 60, 10 * 60 * 60, 24 * 60 * 60) | ||
for (option in options) { | ||
DropdownMenuItem(onClick = { | ||
onRefreshIntervalChanged(option) | ||
dropdownExpanded = false | ||
}) { | ||
Text(IntervalToString(LocalContext.current, option)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
Text(stringResource(commonR.string.template_tile_help)) | ||
TextField( | ||
value = template, | ||
onValueChange = onContentChanged, | ||
label = { | ||
Text(stringResource(commonR.string.template_tile_content)) | ||
}, | ||
modifier = Modifier.padding(top = 8.dp), | ||
maxLines = 10 | ||
) | ||
Text( | ||
renderedTemplate, | ||
fontSize = 12.sp, | ||
modifier = Modifier.padding(top = 8.dp) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
common/src/main/java/io/homeassistant/companion/android/util/IntervalToString.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.homeassistant.companion.android.util | ||
|
||
import android.content.Context | ||
import io.homeassistant.companion.android.common.R | ||
|
||
fun IntervalToString(context: Context, interval: Int): String { | ||
return when { | ||
interval == 0 -> context.getString(R.string.interval_manual) | ||
interval >= 60 * 60 -> context.resources.getQuantityString(R.plurals.interval_hours, interval / 60 / 60, interval / 60 / 60) | ||
interval >= 60 -> context.resources.getQuantityString(R.plurals.interval_minutes, interval / 60, interval / 60) | ||
else -> context.resources.getQuantityString(R.plurals.interval_seconds, interval, interval) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.