-
-
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.
* Add non-functional example of favorites tile * Load real scene entities into the Tile * Make the tile buttons actionable * Add icons of the entities * Add tile preview image * Also support fewer than 7 entities * Cleanup and pass ktlint formatting * Add settings page for tile shortcuts * Use new settings in Tile * Make the tile update when the settings are changed * Support all types of entities in TileActionActivity * Rename tile and process comments * ktlint * Update layout of settings a bit * Use a string resource like a normal person * Remove remaining SetTitle instances * Process review comments and add data class to store entity strings * Process review comments * tiny ktlint fix * Fix broken previews * Fix white lines after merge * Move tile refresh to compose function. * Fix crash when missing friendly name or icon. * ktlint... Co-authored-by: Justin Bassett <[email protected]>
- Loading branch information
1 parent
55a9c51
commit 3d909c6
Showing
18 changed files
with
673 additions
and
11 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
16 changes: 16 additions & 0 deletions
16
wear/src/main/java/io/homeassistant/companion/android/data/SimplifiedEntity.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,16 @@ | ||
package io.homeassistant.companion.android.data | ||
|
||
data class SimplifiedEntity( | ||
var entityId: String, | ||
var friendlyName: String = entityId, | ||
var icon: String = "" | ||
) { | ||
constructor(entityString: String) : this( | ||
entityString.split(",")[0], | ||
entityString.split(",")[1], | ||
entityString.split(",")[2] | ||
) | ||
|
||
val entityString: String | ||
get() = "$entityId,$friendlyName,$icon" | ||
} |
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
105 changes: 105 additions & 0 deletions
105
wear/src/main/java/io/homeassistant/companion/android/home/views/ChooseEntityView.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,105 @@ | ||
package io.homeassistant.companion.android.home.views | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.dp | ||
import androidx.wear.compose.material.Chip | ||
import androidx.wear.compose.material.ChipDefaults | ||
import androidx.wear.compose.material.ScalingLazyColumn | ||
import androidx.wear.compose.material.ScalingLazyListState | ||
import androidx.wear.compose.material.Text | ||
import androidx.wear.compose.material.rememberScalingLazyListState | ||
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.common.data.integration.Entity | ||
import io.homeassistant.companion.android.data.SimplifiedEntity | ||
import io.homeassistant.companion.android.util.RotaryEventState | ||
import io.homeassistant.companion.android.util.getIcon | ||
|
||
@Composable | ||
fun ChooseEntityView( | ||
validEntities: List<Entity<*>>, | ||
onNoneClicked: () -> Unit, | ||
onEntitySelected: (entity: SimplifiedEntity) -> Unit | ||
) { | ||
val scalingLazyListState: ScalingLazyListState = rememberScalingLazyListState() | ||
RotaryEventState(scrollState = scalingLazyListState) | ||
ScalingLazyColumn( | ||
modifier = Modifier | ||
.fillMaxSize(), | ||
contentPadding = PaddingValues( | ||
top = 40.dp, | ||
start = 8.dp, | ||
end = 8.dp, | ||
bottom = 40.dp | ||
), | ||
verticalArrangement = Arrangement.spacedBy(4.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
state = scalingLazyListState | ||
) { | ||
item { | ||
ListHeader(id = R.string.shortcuts) | ||
} | ||
item { | ||
Chip( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(bottom = 16.dp), | ||
icon = { Image(asset = CommunityMaterial.Icon.cmd_delete) }, | ||
label = { Text(stringResource(id = R.string.none)) }, | ||
onClick = onNoneClicked, | ||
colors = ChipDefaults.primaryChipColors( | ||
contentColor = Color.Black | ||
) | ||
) | ||
} | ||
items(validEntities.size) { index -> | ||
val attributes = validEntities[index].attributes as Map<*, *> | ||
val iconBitmap = getIcon( | ||
attributes["icon"] as String?, | ||
validEntities[index].entityId.split(".")[0], | ||
LocalContext.current | ||
) | ||
Chip( | ||
modifier = Modifier | ||
.fillMaxWidth(), | ||
icon = { | ||
Image( | ||
asset = iconBitmap ?: CommunityMaterial.Icon.cmd_cellphone, | ||
colorFilter = ColorFilter.tint(Color.White) | ||
) | ||
}, | ||
label = { | ||
Text( | ||
text = attributes["friendly_name"].toString(), | ||
maxLines = 2, | ||
overflow = TextOverflow.Ellipsis | ||
) | ||
}, | ||
enabled = validEntities[index].state != "unavailable", | ||
onClick = { | ||
onEntitySelected( | ||
SimplifiedEntity( | ||
validEntities[index].entityId, | ||
attributes["friendly_name"] as String? ?: validEntities[index].entityId, | ||
attributes["icon"] as String? ?: "" | ||
) | ||
) | ||
}, | ||
colors = ChipDefaults.secondaryChipColors() | ||
) | ||
} | ||
} | ||
} |
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.