Skip to content

Commit

Permalink
Rename camera snapshot tile to camera tile
Browse files Browse the repository at this point in the history
  • Loading branch information
jpelgrom committed Sep 15, 2023
1 parent dc34d37 commit 95692de
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fun SettingsWearTemplateTile(
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)
val options = listOf(0, 60, 2 * 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60, 60 * 60, 2 * 60 * 60, 5 * 60 * 60, 10 * 60 * 60, 24 * 60 * 60)
for (option in options) {
DropdownMenuItem(onClick = {
onRefreshIntervalChanged(option)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 44,
"identityHash": "851ffd8a5c12488fc1112538639b07c9",
"identityHash": "3201b89ecfb5c51a8600de7386008f21",
"entities": [
{
"tableName": "sensor_attributes",
Expand Down Expand Up @@ -769,7 +769,7 @@
"foreignKeys": []
},
{
"tableName": "camera_snapshot_tiles",
"tableName": "camera_tiles",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `entity_id` TEXT, `refresh_interval` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
Expand Down Expand Up @@ -1034,7 +1034,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '851ffd8a5c12488fc1112538639b07c9')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3201b89ecfb5c51a8600de7386008f21')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import io.homeassistant.companion.android.database.settings.LocalNotificationSet
import io.homeassistant.companion.android.database.settings.LocalSensorSettingConverter
import io.homeassistant.companion.android.database.settings.Setting
import io.homeassistant.companion.android.database.settings.SettingsDao
import io.homeassistant.companion.android.database.wear.CameraSnapshotTile
import io.homeassistant.companion.android.database.wear.CameraSnapshotTileDao
import io.homeassistant.companion.android.database.wear.CameraTile
import io.homeassistant.companion.android.database.wear.CameraTileDao
import io.homeassistant.companion.android.database.wear.EntityStateComplications
import io.homeassistant.companion.android.database.wear.EntityStateComplicationsDao
import io.homeassistant.companion.android.database.wear.FavoriteCaches
Expand Down Expand Up @@ -89,7 +89,7 @@ import io.homeassistant.companion.android.common.R as commonR
TileEntity::class,
Favorites::class,
FavoriteCaches::class,
CameraSnapshotTile::class,
CameraTile::class,
EntityStateComplications::class,
Server::class,
Setting::class
Expand Down Expand Up @@ -137,7 +137,7 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun tileDao(): TileDao
abstract fun favoritesDao(): FavoritesDao
abstract fun favoriteCachesDao(): FavoriteCachesDao
abstract fun cameraSnapshotTileDao(): CameraSnapshotTileDao
abstract fun cameraTileDao(): CameraTileDao
abstract fun entityStateComplicationsDao(): EntityStateComplicationsDao
abstract fun serverDao(): ServerDao
abstract fun settingsDao(): SettingsDao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.homeassistant.companion.android.database.qs.TileDao
import io.homeassistant.companion.android.database.sensor.SensorDao
import io.homeassistant.companion.android.database.server.ServerDao
import io.homeassistant.companion.android.database.settings.SettingsDao
import io.homeassistant.companion.android.database.wear.CameraSnapshotTileDao
import io.homeassistant.companion.android.database.wear.CameraTileDao
import io.homeassistant.companion.android.database.wear.EntityStateComplicationsDao
import io.homeassistant.companion.android.database.wear.FavoriteCachesDao
import io.homeassistant.companion.android.database.wear.FavoritesDao
Expand Down Expand Up @@ -74,7 +74,7 @@ object DatabaseModule {
fun provideSettingsDao(database: AppDatabase): SettingsDao = database.settingsDao()

@Provides
fun provideCameraSnapshotTileDao(database: AppDatabase): CameraSnapshotTileDao = database.cameraSnapshotTileDao()
fun provideCameraTileDao(database: AppDatabase): CameraTileDao = database.cameraTileDao()

@Provides
fun provideEntityStateComplicationsDao(database: AppDatabase): EntityStateComplicationsDao = database.entityStateComplicationsDao()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import androidx.room.Entity
import androidx.room.PrimaryKey

/**
* Represents the configuration of a camera snapshot tile.
* Represents the configuration of a camera tile.
* If the tile was added but not configured, everything except the tile ID will be `null`.
*/
@Entity(tableName = "camera_snapshot_tiles")
data class CameraSnapshotTile(
@Entity(tableName = "camera_tiles")
data class CameraTile(
/** The system's tile ID */
@PrimaryKey
@ColumnInfo(name = "id")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.homeassistant.companion.android.database.wear

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow

@Dao
interface CameraTileDao {

@Query("SELECT * FROM camera_tiles WHERE id = :id")
suspend fun get(id: Int): CameraTile?

@Query("SELECT * FROM camera_tiles ORDER BY id ASC")
fun getAllFlow(): Flow<List<CameraTile>>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun add(tile: CameraTile)

@Query("DELETE FROM camera_tiles where id = :id")
fun delete(id: Int)
}
13 changes: 7 additions & 6 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@
<string name="button_forward">Next</string>
<string name="button_widget_desc">Call any service</string>
<string name="calendar">Calendar</string>
<string name="camera">Camera</string>
<string name="camera_tile">Camera tile</string>
<string name="camera_tile_desc">See what\'s on your camera</string>
<string name="camera_tile_log_in">Log in to Home Assistant to add a camera tile</string>
<string name="camera_tile_no_tiles_yet">There are no camera tiles added yet - add one from the watch face to set it up</string>
<string name="camera_tile_n">Camera tile #%d</string>
<string name="camera_tiles">Camera tiles</string>
<string name="camera_widgets">Camera widgets</string>
<string name="camera_widget_desc">Displays the latest image from the camera</string>
<string name="camera_snapshot">Camera snapshot</string>
<string name="camera_snapshot_tile_desc">See what\'s on your camera</string>
<string name="camera_snapshot_tile_log_in">Log in to Home Assistant to add a camera snapshot</string>
<string name="camera_snapshot_tile_no_tiles_yet">There are no camera snapshot tiles added yet - add one from the watch face to set it up</string>
<string name="camera_snapshot_tile_n">Camera tile #%d</string>
<string name="camera_snapshot_tiles">Camera snapshot tiles</string>
<string name="cancel">Cancel</string>
<string name="changelog">View full change log</string>
<string name="checking_with_home_assistant">Checking with Home Assistant</string>
Expand Down
12 changes: 6 additions & 6 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<category android:name="com.google.android.clockwork.tiles.category.PROVIDER_CONFIG" />
</intent-filter>
<intent-filter>
<action android:name="ConfigCameraSnapshotTile" />
<action android:name="ConfigCameraTile" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.google.android.clockwork.tiles.category.PROVIDER_CONFIG" />
</intent-filter>
Expand Down Expand Up @@ -173,25 +173,25 @@
android:resource="@drawable/conversation_tile_example" />
</service>
<service
android:name=".tiles.CameraSnapshotTile"
android:label="@string/camera_snapshot"
android:description="@string/camera_snapshot_tile_desc"
android:name=".tiles.CameraTile"
android:label="@string/camera"
android:description="@string/camera_tile_desc"
android:permission="com.google.android.wearable.permission.BIND_TILE_PROVIDER"
android:exported="true">
<intent-filter>
<action android:name="androidx.wear.tiles.action.BIND_TILE_PROVIDER" />
</intent-filter>

<meta-data android:name="androidx.wear.tiles.PREVIEW"
android:resource="@drawable/camera_snapshot_tile_example" />
android:resource="@drawable/camera_tile_example" />

<meta-data
android:name="com.google.android.clockwork.tiles.MULTI_INSTANCES_SUPPORTED"
android:value="true" /> <!-- This is supported starting from Wear OS 3 -->

<meta-data
android:name="com.google.android.clockwork.tiles.PROVIDER_CONFIG_ACTION"
android:value="ConfigCameraSnapshotTile" />
android:value="ConfigCameraTile" />
</service>
<receiver android:name=".tiles.TileActionReceiver"
android:exported="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import dagger.hilt.android.AndroidEntryPoint
import io.homeassistant.companion.android.home.views.DEEPLINK_PREFIX_SET_CAMERA_SNAPSHOT_TILE
import io.homeassistant.companion.android.home.views.DEEPLINK_PREFIX_SET_CAMERA_TILE
import io.homeassistant.companion.android.home.views.DEEPLINK_PREFIX_SET_SHORTCUT_TILE
import io.homeassistant.companion.android.home.views.LoadHomePage
import io.homeassistant.companion.android.onboarding.OnboardingActivity
Expand All @@ -38,12 +38,12 @@ class HomeActivity : ComponentActivity(), HomeView {
return Intent(context, HomeActivity::class.java)
}

fun getCameraSnapshotTileSettingsIntent(
fun getCameraTileSettingsIntent(
context: Context,
tileId: Int
) = Intent(
Intent.ACTION_VIEW,
"$DEEPLINK_PREFIX_SET_CAMERA_SNAPSHOT_TILE/$tileId".toUri(),
"$DEEPLINK_PREFIX_SET_CAMERA_TILE/$tileId".toUri(),
context,
HomeActivity::class.java
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import io.homeassistant.companion.android.common.data.websocket.impl.entities.En
import io.homeassistant.companion.android.common.sensors.SensorManager
import io.homeassistant.companion.android.data.SimplifiedEntity
import io.homeassistant.companion.android.database.sensor.SensorDao
import io.homeassistant.companion.android.database.wear.CameraSnapshotTile
import io.homeassistant.companion.android.database.wear.CameraSnapshotTileDao
import io.homeassistant.companion.android.database.wear.CameraTile
import io.homeassistant.companion.android.database.wear.CameraTileDao
import io.homeassistant.companion.android.database.wear.FavoriteCaches
import io.homeassistant.companion.android.database.wear.FavoriteCachesDao
import io.homeassistant.companion.android.database.wear.FavoritesDao
Expand All @@ -50,7 +50,7 @@ class MainViewModel @Inject constructor(
private val favoritesDao: FavoritesDao,
private val favoriteCachesDao: FavoriteCachesDao,
private val sensorsDao: SensorDao,
private val cameraSnapshotTileDao: CameraSnapshotTileDao,
private val cameraTileDao: CameraTileDao,
application: Application
) : AndroidViewModel(application) {

Expand Down Expand Up @@ -91,7 +91,7 @@ class MainViewModel @Inject constructor(

val shortcutEntitiesMap = mutableStateMapOf<Int?, SnapshotStateList<SimplifiedEntity>>()

val cameraSnapshotTiles = cameraSnapshotTileDao.getAllFlow().collectAsState()
val cameraTiles = cameraTileDao.getAllFlow().collectAsState()

var areas = mutableListOf<AreaRegistryResponse>()
private set
Expand Down Expand Up @@ -417,16 +417,16 @@ class MainViewModel @Inject constructor(
}
}

fun setCameraSnapshotTileEntity(tileId: Int, entityId: String) = viewModelScope.launch {
val current = cameraSnapshotTileDao.get(tileId)
val updated = current?.copy(entityId = entityId) ?: CameraSnapshotTile(id = tileId, entityId = entityId)
cameraSnapshotTileDao.add(updated)
fun setCameraTileEntity(tileId: Int, entityId: String) = viewModelScope.launch {
val current = cameraTileDao.get(tileId)
val updated = current?.copy(entityId = entityId) ?: CameraTile(id = tileId, entityId = entityId)
cameraTileDao.add(updated)
}

fun setCameraSnapshotTileRefreshInterval(tileId: Int, interval: Long) = viewModelScope.launch {
val current = cameraSnapshotTileDao.get(tileId)
val updated = current?.copy(refreshInterval = interval) ?: CameraSnapshotTile(id = tileId, refreshInterval = interval)
cameraSnapshotTileDao.add(updated)
fun setCameraTileRefreshInterval(tileId: Int, interval: Long) = viewModelScope.launch {
val current = cameraTileDao.get(tileId)
val updated = current?.copy(refreshInterval = interval) ?: CameraTile(id = tileId, refreshInterval = interval)
cameraTileDao.add(updated)
}

fun setTileShortcut(tileId: Int?, index: Int, entity: SimplifiedEntity) {
Expand Down
Loading

0 comments on commit 95692de

Please sign in to comment.