Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/gradle/kotlin-2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dshokouhi authored Dec 3, 2024
2 parents 22eadf7 + a32d262 commit 2bbf970
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 101 deletions.
50 changes: 25 additions & 25 deletions app/src/full/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
<uses-permission android:name="com.google.android.gms.permission.CAR_FUEL" />
<uses-permission android:name="com.google.android.gms.permission.CAR_MILEAGE" />
<uses-permission android:name="com.google.android.gms.permission.CAR_SPEED" />
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
<uses-permission android:name="android.permission.health.READ_BASAL_BODY_TEMPERATURE" />
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE" />
<uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE" />
<uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE" />
<uses-permission android:name="android.permission.health.READ_BODY_FAT" />
<uses-permission android:name="android.permission.health.READ_BODY_WATER_MASS" />
<uses-permission android:name="android.permission.health.READ_BODY_TEMPERATURE" />
<uses-permission android:name="android.permission.health.READ_BONE_MASS" />
<uses-permission android:name="android.permission.health.READ_DISTANCE" />
<uses-permission android:name="android.permission.health.READ_ELEVATION_GAINED" />
<uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED" />
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
<uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY" />
<uses-permission android:name="android.permission.health.READ_HEIGHT" />
<uses-permission android:name="android.permission.health.READ_HYDRATION" />
<uses-permission android:name="android.permission.health.READ_LEAN_BODY_MASS" />
<uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION" />
<uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE" />
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
<uses-permission android:name="android.permission.health.READ_SLEEP" />
<uses-permission android:name="android.permission.health.READ_STEPS" />
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />
<uses-permission android:name="android.permission.health.READ_WEIGHT" />
<uses-permission android:name="android.permission.health.READ_VO2_MAX" />
<!-- <uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />-->
<!-- <uses-permission android:name="android.permission.health.READ_BASAL_BODY_TEMPERATURE" />-->
<!-- <uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE" />-->
<!-- <uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE" />-->
<!-- <uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE" />-->
<!-- <uses-permission android:name="android.permission.health.READ_BODY_FAT" />-->
<!-- <uses-permission android:name="android.permission.health.READ_BODY_WATER_MASS" />-->
<!-- <uses-permission android:name="android.permission.health.READ_BODY_TEMPERATURE" />-->
<!-- <uses-permission android:name="android.permission.health.READ_BONE_MASS" />-->
<!-- <uses-permission android:name="android.permission.health.READ_DISTANCE" />-->
<!-- <uses-permission android:name="android.permission.health.READ_ELEVATION_GAINED" />-->
<!-- <uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED" />-->
<!-- <uses-permission android:name="android.permission.health.READ_HEART_RATE" />-->
<!-- <uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY" />-->
<!-- <uses-permission android:name="android.permission.health.READ_HEIGHT" />-->
<!-- <uses-permission android:name="android.permission.health.READ_HYDRATION" />-->
<!-- <uses-permission android:name="android.permission.health.READ_LEAN_BODY_MASS" />-->
<!-- <uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION" />-->
<!-- <uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE" />-->
<!-- <uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />-->
<!-- <uses-permission android:name="android.permission.health.READ_SLEEP" />-->
<!-- <uses-permission android:name="android.permission.health.READ_STEPS" />-->
<!-- <uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />-->
<!-- <uses-permission android:name="android.permission.health.READ_WEIGHT" />-->
<!-- <uses-permission android:name="android.permission.health.READ_VO2_MAX" />-->

<queries>
<!-- For GMS Core/Play service -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.wifi.improv.DeviceState
import dagger.hilt.android.AndroidEntryPoint
import io.homeassistant.companion.android.common.data.wifi.WifiHelper
import io.homeassistant.companion.android.improv.ImprovRepository
import io.homeassistant.companion.android.util.compose.HomeAssistantAppTheme
import io.homeassistant.companion.android.util.setLayoutAndExpandedByDefault
import io.homeassistant.companion.android.webview.externalbus.ExternalBusMessage
import io.homeassistant.companion.android.webview.externalbus.ExternalBusRepository
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -29,14 +32,25 @@ class ImprovSetupDialog : BottomSheetDialogFragment() {
@Inject
lateinit var improvRepository: ImprovRepository

@Inject
lateinit var externalBusRepository: ExternalBusRepository

@Inject
lateinit var wifiHelper: WifiHelper

companion object {
const val TAG = "ImprovSetupDialog"

private const val ARG_NAME = "name"

const val RESULT_KEY = "ImprovSetupResult"
const val RESULT_DOMAIN = "domain"

fun newInstance(deviceName: String?): ImprovSetupDialog {
return ImprovSetupDialog().apply {
arguments = bundleOf(ARG_NAME to deviceName)
}
}
}

private val screenState = MutableStateFlow(
Expand All @@ -48,9 +62,20 @@ class ImprovSetupDialog : BottomSheetDialogFragment() {
)
)

private var initialDeviceName: String? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycleScope.launch {
if (savedInstanceState == null) {
if (arguments?.containsKey(ARG_NAME) == true) {
val name = arguments?.getString(ARG_NAME, "").takeIf { !it.isNullOrBlank() }
name?.let {
initialDeviceName = it
screenState.emit(screenState.value.copy(initialDeviceName = it))
}
}
}
repeatOnLifecycle(Lifecycle.State.RESUMED) {
screenState.emit(screenState.value.copy(activeSsid = wifiHelper.getWifiSsid()?.removeSurrounding("\"")))
launch {
Expand All @@ -61,11 +86,23 @@ class ImprovSetupDialog : BottomSheetDialogFragment() {
launch {
improvRepository.getDevices().collect {
screenState.emit(screenState.value.copy(devices = it))
if (initialDeviceName != null) {
it.firstOrNull { device -> device.name == initialDeviceName }
?.let { foundDevice ->
screenState.emit(
screenState.value.copy(
initialDeviceAddress = foundDevice.address
)
)
initialDeviceName = null
}
}
}
}
launch {
improvRepository.getDeviceState().collect {
screenState.emit(screenState.value.copy(deviceState = it))
if (it == DeviceState.PROVISIONED) notifyFrontend()
}
}
launch {
Expand Down Expand Up @@ -127,4 +164,16 @@ class ImprovSetupDialog : BottomSheetDialogFragment() {
}
}
}

private fun notifyFrontend() {
lifecycleScope.launch {
externalBusRepository.send(
ExternalBusMessage(
id = -1,
type = "command",
command = "improv/device_setup_done"
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ data class ImprovSheetState(
val devices: List<ImprovDevice>,
val deviceState: DeviceState?,
val errorState: ErrorState?,
val activeSsid: String? = null
val activeSsid: String? = null,
val initialDeviceName: String? = null,
val initialDeviceAddress: String? = null
) {
/** @return `true` when [errorState] is not `null` or [ErrorState.NO_ERROR] */
val hasError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ fun ImprovSheetView(
onRestart: () -> Unit,
onDismiss: () -> Unit
) {
var selectedName by rememberSaveable { mutableStateOf<String?>(null) }
var selectedAddress by rememberSaveable { mutableStateOf<String?>(null) }
var selectedName by rememberSaveable(screenState.initialDeviceName) { mutableStateOf<String?>(screenState.initialDeviceName) }
var selectedAddress by rememberSaveable(screenState.initialDeviceAddress) { mutableStateOf<String?>(screenState.initialDeviceAddress) }
var submittedWifi by rememberSaveable { mutableStateOf(false) }

ModalBottomSheet(
title = if (screenState.scanning && screenState.deviceState == null && !screenState.hasError) {
if (selectedAddress != null) {
stringResource(commonR.string.improv_wifi_title)
} else if (selectedName != null) {
""
} else {
stringResource(commonR.string.improv_list_title)
}
Expand Down Expand Up @@ -142,7 +144,7 @@ fun ImprovSheetView(
commonR.string.improv_device_authorized
} else if (screenState.deviceState == DeviceState.PROVISIONING) {
commonR.string.improv_device_provisioning
} else if (selectedAddress != null) {
} else if (selectedName != null) {
commonR.string.improv_device_connecting
} else {
commonR.string.state_unknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SensorReceiver : SensorReceiverBase() {
DynamicColorSensorManager(),
DevicePolicyManager(),
GeocodeSensorManager(),
HealthConnectSensorManager(),
// HealthConnectSensorManager(),
KeyguardSensorManager(),
LastAppSensorManager(),
LastRebootSensorManager(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import io.homeassistant.companion.android.database.sensor.Sensor
import io.homeassistant.companion.android.database.sensor.SensorDao
import io.homeassistant.companion.android.sensors.SensorReceiver
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@HiltViewModel
class SensorSettingsViewModel @Inject constructor(
Expand Down Expand Up @@ -47,8 +49,13 @@ class SensorSettingsViewModel @Inject constructor(
init {
viewModelScope.launch {
sensorDao.getAllFlow().collect {
sensorsList = it
filterSensorsList()
withContext(Dispatchers.IO) {
// Compare contents, because the worker typically pushes a DB update on
// sensor updates even when contents don't change
val different = sensorsList != it
sensorsList = it
if (different) filterSensorsList()
}
}
}
}
Expand All @@ -67,7 +74,7 @@ class SensorSettingsViewModel @Inject constructor(
}
}

private suspend fun filterSensorsList() {
private suspend fun filterSensorsList() = withContext(Dispatchers.IO) {
val app = getApplication<Application>()
val managers = SensorReceiver.MANAGERS.sortedBy { app.getString(it.name) }
sensors = SensorReceiver.MANAGERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ import android.content.pm.PackageManager
import android.util.Log
import androidx.car.app.CarContext
import androidx.car.app.model.Action
import androidx.car.app.model.ActionStrip
import io.homeassistant.companion.android.common.R
import io.homeassistant.companion.android.launch.LaunchActivity

private const val TAG = "NativeActionStrip"

fun nativeModeActionStrip(carContext: CarContext): ActionStrip {
return ActionStrip.Builder().addAction(
Action.Builder()
.setTitle(carContext.getString(R.string.aa_launch_native))
.setOnClickListener {
startNativeActivity(carContext)
}.build()
).build()
fun nativeModeAction(carContext: CarContext): Action {
return Action.Builder()
.setTitle(carContext.getString(R.string.aa_launch_native))
.setOnClickListener {
startNativeActivity(carContext)
}.build()
}

fun startNativeActivity(carContext: CarContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Build
import androidx.annotation.RequiresApi
import androidx.car.app.CarContext
import androidx.car.app.model.Action
import androidx.car.app.model.ActionStrip
import androidx.car.app.model.GridTemplate
import androidx.car.app.model.Template
import androidx.lifecycle.lifecycleScope
Expand All @@ -18,7 +19,7 @@ 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
import io.homeassistant.companion.android.util.vehicle.nativeModeAction
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -80,7 +81,7 @@ class DomainListScreen(
setTitle(carContext.getString(R.string.all_entities))
setHeaderAction(Action.BACK)
if (isAutomotive && !isDrivingOptimized && BuildConfig.FLAVOR != "full") {
setActionStrip(nativeModeActionStrip(carContext))
setActionStrip(ActionStrip.Builder().addAction(nativeModeAction(carContext)).build())
}
val domainBuild = domainList.build()
if (!domainsAdded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ class HaCarAppService : CarAppService() {
serverManager,
serverIdFlow,
entityFlow,
prefsRepository
) { loadEntities(lifecycleScope, it) }
prefsRepository,
{ loadEntities(lifecycleScope, it) },
{ loadEntities(lifecycleScope, serverId.value) }
)
)

push(
Expand All @@ -108,8 +110,10 @@ class HaCarAppService : CarAppService() {
serverManager,
serverIdFlow,
entityFlow,
prefsRepository
) { loadEntities(lifecycleScope, it) }
prefsRepository,
{ loadEntities(lifecycleScope, it) },
{ loadEntities(lifecycleScope, serverId.value) }
)
)
}
return LoginScreen(
Expand All @@ -129,7 +133,6 @@ class HaCarAppService : CarAppService() {
private fun loadEntities(scope: CoroutineScope, id: Int) {
allEntitiesJob?.cancel()
allEntitiesJob = scope.launch {
allEntities.emit(emptyMap())
serverId.value = id
val entities: MutableMap<String, Entity<*>>? =
if (serverManager.getServer(id) != null) {
Expand Down
Loading

0 comments on commit 2bbf970

Please sign in to comment.