mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-14 18:26:11 -04:00
refactor: Use PodDevice properties instead of reaching through BLE metadata
Replace device.meta?.profile?.address/id/label with device.address/profileId/label in AutoConnect, PopUpReaction, and BatteryGlanceWidget.
This commit is contained in:
@@ -86,8 +86,8 @@ class BatteryGlanceWidget : GlanceAppWidget() {
|
||||
|
||||
val isPro = upgradeInfo?.isPro ?: initialIsPro
|
||||
|
||||
val liveDevice = devices.firstOrNull { it.meta?.profile?.id == profileId }
|
||||
val device = liveDevice ?: cachedDevice?.takeIf { it.meta?.profile?.id == profileId }
|
||||
val liveDevice = devices.firstOrNull { it.profileId == profileId }
|
||||
val device = liveDevice ?: cachedDevice?.takeIf { it.profileId == profileId }
|
||||
|
||||
val profileLabel = profileId?.let { pid ->
|
||||
profiles.firstOrNull { it.id == pid }?.label
|
||||
|
||||
@@ -49,7 +49,7 @@ class AutoConnect @Inject constructor(
|
||||
.map { (connectedDevices, mainDevice) ->
|
||||
log(TAG, VERBOSE) { "mainPodDevice is $mainDevice" }
|
||||
|
||||
val mainDeviceAddr = mainDevice.meta?.profile?.address
|
||||
val mainDeviceAddr = mainDevice.address
|
||||
if (mainDeviceAddr.isNullOrEmpty()) {
|
||||
log(TAG, WARN) { "mainDeviceAddress is null" }
|
||||
return@map
|
||||
|
||||
@@ -53,7 +53,7 @@ class PopUpReaction @Inject constructor(
|
||||
log(TAG, VERBOSE) { "previous-id=${previous?.identifier}, current-id=${current.identifier}" }
|
||||
|
||||
val isSameDeviceOrProfile = previous?.identifier == current.identifier ||
|
||||
(previous?.meta?.profile?.id != null && previous.meta?.profile?.id == current.meta?.profile?.id)
|
||||
(previous?.profileId != null && previous.profileId == current.profileId)
|
||||
val isSameDeviceWithCaseNowOpen = isSameDeviceOrProfile && previous?.caseLidState != current.caseLidState
|
||||
val isNewDeviceWithJustOpenedCase = !isSameDeviceOrProfile && previous?.caseLidState != current.caseLidState
|
||||
|
||||
@@ -66,7 +66,7 @@ class PopUpReaction @Inject constructor(
|
||||
}
|
||||
|
||||
private fun throttleCasePopUps(current: PodDevice): Event? {
|
||||
val cooldownKey = current.meta?.profile?.id ?: current.identifier.toString()
|
||||
val cooldownKey = current.profileId ?: current.identifier.toString()
|
||||
val now = Instant.now()
|
||||
val lastShown = caseCoolDowns[cooldownKey]
|
||||
|
||||
@@ -110,7 +110,7 @@ class PopUpReaction @Inject constructor(
|
||||
deviceMonitor.primaryDevice().distinctUntilChangedBy { it?.rawDataHex },
|
||||
) { devices, broadcast ->
|
||||
log(TAG) { "$broadcast $devices " }
|
||||
val primaryAddr = broadcast?.meta?.profile?.address
|
||||
val primaryAddr = broadcast?.address
|
||||
val direct = devices.singleOrNull { it.address == primaryAddr }.also {
|
||||
log(TAG, VERBOSE) { "Connected main device is $it" }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user