Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide hidden entities from android auto domains #3731

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -9,6 +9,7 @@ import androidx.car.app.model.CarColor
import androidx.car.app.model.CarIcon
import androidx.car.app.model.GridItem
import androidx.car.app.model.ItemList
import androidx.lifecycle.LifecycleCoroutineScope
import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
import com.mikepenz.iconics.utils.sizeDp
Expand All @@ -20,14 +21,17 @@ import io.homeassistant.companion.android.common.data.integration.domain
import io.homeassistant.companion.android.common.data.integration.getIcon
import io.homeassistant.companion.android.common.data.prefs.PrefsRepository
import io.homeassistant.companion.android.common.data.servers.ServerManager
import io.homeassistant.companion.android.common.data.websocket.impl.entities.EntityRegistryResponse
import io.homeassistant.companion.android.common.util.capitalize
import io.homeassistant.companion.android.util.RegistriesDataHandler
import io.homeassistant.companion.android.vehicle.ChangeServerScreen
import io.homeassistant.companion.android.vehicle.DomainListScreen
import io.homeassistant.companion.android.vehicle.EntityGridVehicleScreen
import io.homeassistant.companion.android.vehicle.MapVehicleScreen
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import java.util.Calendar
import java.util.Locale

Expand Down Expand Up @@ -113,7 +117,9 @@ fun getDomainList(
serverManager: ServerManager,
serverId: StateFlow<Int>,
prefsRepository: PrefsRepository,
allEntities: Flow<Map<String, Entity<*>>>
allEntities: Flow<Map<String, Entity<*>>>,
entityRegistry: List<EntityRegistryResponse>?,
lifecycleScope: LifecycleCoroutineScope
): ItemList.Builder {
val listBuilder = ItemList.Builder()
domains.forEach { domain ->
Expand All @@ -131,40 +137,57 @@ fun getDomainList(
null
).getIcon(carContext)

listBuilder.addItem(
GridItem.Builder().apply {
if (icon != null) {
setImage(
CarIcon.Builder(
IconicsDrawable(carContext, icon)
.apply {
sizeDp = 64
}.toAndroidIconCompat()
)
.setTint(CarColor.DEFAULT)
.build()
)
}
val entityList = allEntities.map {
it.values.filter { entity ->
entity.domain == domain && RegistriesDataHandler.getHiddenByForEntity(
entity.entityId,
entityRegistry
) == null
}
.setTitle(friendlyDomain)
.setOnClickListener {
Log.i(TAG, "Domain:$domain clicked")
screenManager.push(
EntityGridVehicleScreen(
carContext,
serverManager,
serverId,
prefsRepository,
serverManager.integrationRepository(serverId.value),
friendlyDomain,
domains,
allEntities.map { it.values.filter { entity -> entity.domain == domain } },
allEntities
) { }
)
}
var domainIsEmpty = false
lifecycleScope.launch {
entityList.collect {
domainIsEmpty = it.isEmpty()
}
}
jpelgrom marked this conversation as resolved.
Show resolved Hide resolved
if (!domainIsEmpty) {
listBuilder.addItem(
GridItem.Builder().apply {
if (icon != null) {
setImage(
CarIcon.Builder(
IconicsDrawable(carContext, icon)
.apply {
sizeDp = 64
}.toAndroidIconCompat()
)
.setTint(CarColor.DEFAULT)
.build()
)
}
}
.build()
)
.setTitle(friendlyDomain)
.setOnClickListener {
Log.i(TAG, "Domain:$domain clicked")
screenManager.push(
EntityGridVehicleScreen(
carContext,
serverManager,
serverId,
prefsRepository,
serverManager.integrationRepository(serverId.value),
friendlyDomain,
entityRegistry,
domains,
entityList,
allEntities
) { }
)
}
.build()
)
}
}
return listBuilder
}
Expand All @@ -177,7 +200,8 @@ fun getDomainsGridItem(
integrationRepository: IntegrationRepository,
serverId: StateFlow<Int>,
allEntities: Flow<Map<String, Entity<*>>>,
prefsRepository: PrefsRepository
prefsRepository: PrefsRepository,
entityRegistry: List<EntityRegistryResponse>?
): GridItem.Builder {
return GridItem.Builder().apply {
setTitle(carContext.getString(R.string.all_entities))
Expand All @@ -202,7 +226,8 @@ fun getDomainsGridItem(
integrationRepository,
serverId,
allEntities,
prefsRepository
prefsRepository,
entityRegistry
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.homeassistant.companion.android.common.data.integration.IntegrationRep
import io.homeassistant.companion.android.common.data.integration.domain
import io.homeassistant.companion.android.common.data.prefs.PrefsRepository
import io.homeassistant.companion.android.common.data.servers.ServerManager
import io.homeassistant.companion.android.common.data.websocket.impl.entities.EntityRegistryResponse
import io.homeassistant.companion.android.util.vehicle.SUPPORTED_DOMAINS
import io.homeassistant.companion.android.util.vehicle.getDomainList
import io.homeassistant.companion.android.util.vehicle.nativeModeActionStrip
Expand All @@ -29,7 +30,8 @@ class DomainListScreen(
val integrationRepository: IntegrationRepository,
private val serverId: StateFlow<Int>,
private val allEntities: Flow<Map<String, Entity<*>>>,
private val prefsRepository: PrefsRepository
private val prefsRepository: PrefsRepository,
private val entityRegistry: List<EntityRegistryResponse>?
) : BaseVehicleScreen(carContext) {

companion object {
Expand Down Expand Up @@ -68,7 +70,9 @@ class DomainListScreen(
serverManager,
serverId,
prefsRepository,
allEntities
allEntities,
entityRegistry,
lifecycleScope
)

return GridTemplate.Builder().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import io.homeassistant.companion.android.common.data.integration.isExecuting
import io.homeassistant.companion.android.common.data.integration.onPressed
import io.homeassistant.companion.android.common.data.prefs.PrefsRepository
import io.homeassistant.companion.android.common.data.servers.ServerManager
import io.homeassistant.companion.android.common.data.websocket.impl.entities.EntityRegistryResponse
import io.homeassistant.companion.android.util.vehicle.MAP_DOMAINS
import io.homeassistant.companion.android.util.vehicle.NOT_ACTIONABLE_DOMAINS
import io.homeassistant.companion.android.util.vehicle.SUPPORTED_DOMAINS
Expand All @@ -53,6 +54,7 @@ class EntityGridVehicleScreen(
val prefsRepository: PrefsRepository,
val integrationRepository: IntegrationRepository,
val title: String,
private val entityRegistry: List<EntityRegistryResponse>?,
private val domains: MutableSet<String>,
private val entitiesFlow: Flow<List<Entity<*>>>,
private val allEntities: Flow<Map<String, Entity<*>>>,
Expand Down Expand Up @@ -92,7 +94,9 @@ class EntityGridVehicleScreen(
serverManager,
serverId,
prefsRepository,
allEntities
allEntities,
entityRegistry,
lifecycleScope
)
}
if (isFavorites) {
Expand All @@ -112,7 +116,8 @@ class EntityGridVehicleScreen(
integrationRepository,
serverId,
allEntities,
prefsRepository
prefsRepository,
entityRegistry
).build()
)
if (shouldSwitchServers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.homeassistant.companion.android.common.data.integration.Entity
import io.homeassistant.companion.android.common.data.integration.domain
import io.homeassistant.companion.android.common.data.prefs.PrefsRepository
import io.homeassistant.companion.android.common.data.servers.ServerManager
import io.homeassistant.companion.android.common.data.websocket.impl.entities.EntityRegistryResponse
import io.homeassistant.companion.android.sensors.SensorReceiver
import io.homeassistant.companion.android.util.vehicle.SUPPORTED_DOMAINS
import io.homeassistant.companion.android.util.vehicle.getChangeServerGridItem
Expand Down Expand Up @@ -45,6 +46,7 @@ class MainVehicleScreen(
}

private var favoritesEntities: List<Entity<*>> = listOf()
private var entityRegistry: List<EntityRegistryResponse>? = null
private var favoritesList = emptyList<String>()
private var isLoggedIn: Boolean? = null
private val domains = mutableSetOf<String>()
Expand All @@ -66,6 +68,7 @@ class MainVehicleScreen(
.getSessionState() == SessionState.CONNECTED
invalidate()
}
entityRegistry = serverManager.webSocketRepository(serverId.value).getEntityRegistry()
allEntities.collect { entities ->
val newDomains = entities.values
.map { it.domain }
Expand Down Expand Up @@ -112,6 +115,7 @@ class MainVehicleScreen(
prefsRepository,
serverManager.integrationRepository(serverId.value),
carContext.getString(commonR.string.favorites),
entityRegistry,
domains,
flowOf(),
allEntities
Expand All @@ -126,7 +130,9 @@ class MainVehicleScreen(
serverManager,
serverId,
prefsRepository,
allEntities
allEntities,
entityRegistry,
lifecycleScope
)
}

Expand Down