From 721c323e7702b30037841f82f17c9df48266917f Mon Sep 17 00:00:00 2001 From: Daniel Shokouhi Date: Mon, 28 Aug 2023 12:06:11 -0700 Subject: [PATCH] Clean up some left over code after update to getIcon --- .../android/util/vehicle/GridItems.kt | 20 +++++++++---------- .../vehicle/EntityGridVehicleScreen.kt | 3 +-- .../android/vehicle/MapVehicleScreen.kt | 3 +-- .../EntityStateDataSourceService.kt | 3 +-- .../views/ComplicationConfigMainView.kt | 2 +- .../companion/android/home/views/MainView.kt | 4 ++-- .../android/home/views/SetFavoriteView.kt | 3 +-- .../home/views/SetShortcutsTileView.kt | 2 +- .../companion/android/tiles/ShortcutsTile.kt | 3 +-- .../companion/android/util/CommonFunctions.kt | 2 +- .../android/views/ChooseEntityView.kt | 2 +- 11 files changed, 20 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/util/vehicle/GridItems.kt b/app/src/main/java/io/homeassistant/companion/android/util/vehicle/GridItems.kt index 053f62770b7..d5a9803b979 100755 --- a/app/src/main/java/io/homeassistant/companion/android/util/vehicle/GridItems.kt +++ b/app/src/main/java/io/homeassistant/companion/android/util/vehicle/GridItems.kt @@ -154,18 +154,16 @@ fun getDomainList( if (!domainIsEmpty) { listBuilder.addItem( GridItem.Builder().apply { - if (icon != null) { - setImage( - CarIcon.Builder( - IconicsDrawable(carContext, icon) - .apply { - sizeDp = 64 - }.toAndroidIconCompat() - ) - .setTint(CarColor.DEFAULT) - .build() + setImage( + CarIcon.Builder( + IconicsDrawable(carContext, icon) + .apply { + sizeDp = 64 + }.toAndroidIconCompat() ) - } + .setTint(CarColor.DEFAULT) + .build() + ) } .setTitle(friendlyDomain) .setOnClickListener { diff --git a/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt b/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt index 01205b17fa9..cacd6f0eed9 100644 --- a/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt +++ b/app/src/main/java/io/homeassistant/companion/android/vehicle/EntityGridVehicleScreen.kt @@ -19,7 +19,6 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import com.mikepenz.iconics.utils.sizeDp import com.mikepenz.iconics.utils.toAndroidIconCompat import io.homeassistant.companion.android.common.R @@ -164,7 +163,7 @@ class EntityGridVehicleScreen( Log.i(TAG, "Grid limit ($gridLimit) reached, not adding more entities (${entities.size}) for $title ") return@forEachIndexed } - val icon = entity.getIcon(carContext) ?: CommunityMaterial.Icon.cmd_cloud_question + val icon = entity.getIcon(carContext) val gridItem = GridItem.Builder() .setLoading(false) diff --git a/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt b/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt index 6214b43f264..f5f459bea10 100644 --- a/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt +++ b/app/src/main/java/io/homeassistant/companion/android/vehicle/MapVehicleScreen.kt @@ -19,7 +19,6 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import com.mikepenz.iconics.utils.sizeDp import com.mikepenz.iconics.utils.toAndroidIconCompat import io.homeassistant.companion.android.common.R @@ -93,7 +92,7 @@ class MapVehicleScreen( Log.i(TAG, "Grid limit ($gridLimit) reached, not adding any more navigation entities (${entities.size})") return@forEachIndexed } - val icon = pair.first.getIcon(carContext) ?: CommunityMaterial.Icon.cmd_account + val icon = pair.first.getIcon(carContext) gridBuilder.addItem( GridItem.Builder() .setTitle(pair.first.friendlyName) diff --git a/wear/src/main/java/io/homeassistant/companion/android/complications/EntityStateDataSourceService.kt b/wear/src/main/java/io/homeassistant/companion/android/complications/EntityStateDataSourceService.kt index ce669d454be..dc7a8b974d3 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/complications/EntityStateDataSourceService.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/complications/EntityStateDataSourceService.kt @@ -13,7 +13,6 @@ import androidx.wear.watchface.complications.data.ShortTextComplicationData import androidx.wear.watchface.complications.datasource.ComplicationRequest import androidx.wear.watchface.complications.datasource.SuspendingComplicationDataSourceService import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import com.mikepenz.iconics.utils.colorInt import dagger.hilt.android.AndroidEntryPoint import io.homeassistant.companion.android.common.R @@ -69,7 +68,7 @@ class EntityStateDataSourceService : SuspendingComplicationDataSourceService() { null } - val icon = entity.getIcon(applicationContext) ?: CommunityMaterial.Icon.cmd_bookmark + val icon = entity.getIcon(applicationContext) val iconBitmap = IconicsDrawable(this, icon).apply { colorInt = Color.WHITE }.toBitmap() diff --git a/wear/src/main/java/io/homeassistant/companion/android/complications/views/ComplicationConfigMainView.kt b/wear/src/main/java/io/homeassistant/companion/android/complications/views/ComplicationConfigMainView.kt index d348c94f649..58753b1320d 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/complications/views/ComplicationConfigMainView.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/complications/views/ComplicationConfigMainView.kt @@ -106,7 +106,7 @@ fun MainConfigView( modifier = Modifier.fillMaxWidth(), icon = { Image( - asset = iconBitmap ?: CommunityMaterial.Icon.cmd_bookmark, + asset = iconBitmap, colorFilter = ColorFilter.tint(wearColorPalette.onSurface) ) }, diff --git a/wear/src/main/java/io/homeassistant/companion/android/home/views/MainView.kt b/wear/src/main/java/io/homeassistant/companion/android/home/views/MainView.kt index c5c76cf1e00..f441d81e848 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/home/views/MainView.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/home/views/MainView.kt @@ -95,7 +95,7 @@ fun MainView( .fillMaxWidth(), icon = { Image( - asset = getIcon(cached?.icon, favoriteEntityID.split(".")[0], context) ?: CommunityMaterial.Icon.cmd_bookmark, + asset = getIcon(cached?.icon, favoriteEntityID.split(".")[0], context), colorFilter = ColorFilter.tint(wearColorPalette.onSurface) ) }, @@ -272,7 +272,7 @@ fun MainView( "", domain, context - )?.let { Image(asset = it) } + ).let { Image(asset = it) } }, label = { Text(text = mainViewModel.stringForDomain(domain)!!) diff --git a/wear/src/main/java/io/homeassistant/companion/android/home/views/SetFavoriteView.kt b/wear/src/main/java/io/homeassistant/companion/android/home/views/SetFavoriteView.kt index 3c08823fbf2..3dc8a06440b 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/home/views/SetFavoriteView.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/home/views/SetFavoriteView.kt @@ -16,7 +16,6 @@ import androidx.wear.compose.material.Text import androidx.wear.compose.material.ToggleChip import androidx.wear.compose.material.ToggleChipDefaults import com.mikepenz.iconics.compose.Image -import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import io.homeassistant.companion.android.common.data.integration.Entity import io.homeassistant.companion.android.common.data.integration.getIcon import io.homeassistant.companion.android.home.MainViewModel @@ -100,7 +99,7 @@ private fun FavoriteToggleChip( .fillMaxWidth(), appIcon = { Image( - asset = iconBitmap ?: CommunityMaterial.Icon.cmd_bookmark, + asset = iconBitmap, colorFilter = ColorFilter.tint(wearColorPalette.onSurface) ) }, diff --git a/wear/src/main/java/io/homeassistant/companion/android/home/views/SetShortcutsTileView.kt b/wear/src/main/java/io/homeassistant/companion/android/home/views/SetShortcutsTileView.kt index 94c793c81d4..7c348df5510 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/home/views/SetShortcutsTileView.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/home/views/SetShortcutsTileView.kt @@ -62,7 +62,7 @@ fun SetShortcutsTileView( .fillMaxWidth(), icon = { Image( - iconBitmap ?: CommunityMaterial.Icon.cmd_bookmark, + iconBitmap, colorFilter = ColorFilter.tint(Color.White) ) }, diff --git a/wear/src/main/java/io/homeassistant/companion/android/tiles/ShortcutsTile.kt b/wear/src/main/java/io/homeassistant/companion/android/tiles/ShortcutsTile.kt index e94084d7385..cdf3423b002 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/tiles/ShortcutsTile.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/tiles/ShortcutsTile.kt @@ -29,7 +29,6 @@ import androidx.wear.tiles.TileService import com.google.common.util.concurrent.ListenableFuture import com.mikepenz.iconics.IconicsColor import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import com.mikepenz.iconics.utils.backgroundColor import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp @@ -117,7 +116,7 @@ class ShortcutsTile : TileService() { entity.icon, entity.domain, this@ShortcutsTile - ) ?: CommunityMaterial.Icon.cmd_bookmark + ) val iconBitmap = IconicsDrawable(this@ShortcutsTile, iconIIcon).apply { colorInt = Color.WHITE sizeDp = iconSize.roundToInt() diff --git a/wear/src/main/java/io/homeassistant/companion/android/util/CommonFunctions.kt b/wear/src/main/java/io/homeassistant/companion/android/util/CommonFunctions.kt index 2bca7681f56..ae3ae6174cf 100755 --- a/wear/src/main/java/io/homeassistant/companion/android/util/CommonFunctions.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/util/CommonFunctions.kt @@ -30,7 +30,7 @@ fun stringForDomain(domain: String, context: Context): String? = ) )[domain]?.let { context.getString(it) } -fun getIcon(icon: String?, domain: String, context: Context): IIcon? { +fun getIcon(icon: String?, domain: String, context: Context): IIcon { val simpleEntity = Entity( "$domain.ha_android_placeholder", "", diff --git a/wear/src/main/java/io/homeassistant/companion/android/views/ChooseEntityView.kt b/wear/src/main/java/io/homeassistant/companion/android/views/ChooseEntityView.kt index 68c544c86af..610ab0aec77 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/views/ChooseEntityView.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/views/ChooseEntityView.kt @@ -126,7 +126,7 @@ private fun ChooseEntityChip( .fillMaxWidth(), icon = { Image( - asset = iconBitmap ?: CommunityMaterial.Icon.cmd_bookmark, + asset = iconBitmap, colorFilter = ColorFilter.tint(Color.White) ) },