show last battery status when a pod or case is disconnected

This commit is contained in:
Kavish Devar
2025-01-07 00:35:44 +05:30
parent 7ed8f9b09c
commit 2c2552a57e
2 changed files with 33 additions and 33 deletions

View File

@@ -127,21 +127,21 @@ fun BatteryView(service: AirPodsService, preview: Boolean = false) {
.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
if (left?.status != BatteryStatus.DISCONNECTED) {
// if (left?.status != BatteryStatus.DISCONNECTED) {
BatteryIndicator(
left?.level ?: 0,
left?.status == BatteryStatus.CHARGING
)
}
if (left?.status != BatteryStatus.DISCONNECTED && right?.status != BatteryStatus.DISCONNECTED) {
// }
// if (left?.status != BatteryStatus.DISCONNECTED && right?.status != BatteryStatus.DISCONNECTED) {
Spacer(modifier = Modifier.width(16.dp))
}
if (right?.status != BatteryStatus.DISCONNECTED) {
// }
// if (right?.status != BatteryStatus.DISCONNECTED) {
BatteryIndicator(
right?.level ?: 0,
right?.status == BatteryStatus.CHARGING
)
}
// }
}
}
}
@@ -160,9 +160,9 @@ fun BatteryView(service: AirPodsService, preview: Boolean = false) {
.fillMaxWidth()
.scale(1.25f)
)
if (case?.status != BatteryStatus.DISCONNECTED) {
// if (case?.status != BatteryStatus.DISCONNECTED) {
BatteryIndicator(case?.level ?: 0, case?.status == BatteryStatus.CHARGING)
}
// }
}
}
}

View File

@@ -171,31 +171,31 @@ class AirPodsService: Service() {
it.setTextViewText(
R.id.left_battery_widget,
batteryNotification.getBattery().find { it.component == BatteryComponent.LEFT }?.let {
if (it.status != BatteryStatus.DISCONNECTED) {
// if (it.status != BatteryStatus.DISCONNECTED) {
"${if (it.status == BatteryStatus.CHARGING) "⚡" else ""} ${it.level}%"
} else {
""
}
// } else {
// ""
// }
} ?: ""
)
it.setTextViewText(
R.id.right_battery_widget,
batteryNotification.getBattery().find { it.component == BatteryComponent.RIGHT }?.let {
if (it.status != BatteryStatus.DISCONNECTED) {
// if (it.status != BatteryStatus.DISCONNECTED) {
"${if (it.status == BatteryStatus.CHARGING) "⚡" else ""} ${it.level}%"
} else {
""
}
// } else {
// ""
// }
} ?: ""
)
it.setTextViewText(
R.id.case_battery_widget,
batteryNotification.getBattery().find { it.component == BatteryComponent.CASE }?.let {
if (it.status != BatteryStatus.DISCONNECTED) {
// if (it.status != BatteryStatus.DISCONNECTED) {
"${if (it.status == BatteryStatus.CHARGING) "⚡" else ""} ${it.level}%"
} else {
""
}
// } else {
// ""
// }
} ?: ""
)
}
@@ -205,7 +205,7 @@ class AirPodsService: Service() {
fun updateNotificationContent(connected: Boolean, airpodsName: String? = null, batteryList: List<Battery>? = null) {
val notificationManager = getSystemService(NotificationManager::class.java)
val textColor = this.getSharedPreferences("settings", MODE_PRIVATE).getLong("textColor", 0)
// val textColor = this.getSharedPreferences("settings", MODE_PRIVATE).getLong("textColor", 0)
var updatedNotification: Notification? = null
if (connected) {
@@ -262,23 +262,23 @@ class AirPodsService: Service() {
updatedNotification = NotificationCompat.Builder(this, "background_service_status")
.setSmallIcon(R.drawable.airpods)
.setContentTitle("""L: ${batteryList?.find { it.component == BatteryComponent.LEFT }?.let {
if (it.status != BatteryStatus.DISCONNECTED) {
// if (it.status != BatteryStatus.DISCONNECTED) {
"${if (it.status == BatteryStatus.CHARGING) "⚡" else ""} ${it.level}%"
} else {
""
}
// } else {
// ""
// }
} ?: ""} R: ${batteryList?.find { it.component == BatteryComponent.RIGHT }?.let {
if (it.status != BatteryStatus.DISCONNECTED) {
// if (it.status != BatteryStatus.DISCONNECTED) {
"${if (it.status == BatteryStatus.CHARGING) "⚡" else ""} ${it.level}%"
} else {
""
}
// } else {
// ""
// }
} ?: ""} C: ${batteryList?.find { it.component == BatteryComponent.CASE }?.let {
if (it.status != BatteryStatus.DISCONNECTED) {
// if (it.status != BatteryStatus.DISCONNECTED) {
"${if (it.status == BatteryStatus.CHARGING) "⚡" else ""} ${it.level}%"
} else {
""
}
// } else {
// ""
// }
} ?: ""}""")
.setCategory(Notification.CATEGORY_SERVICE)
.setPriority(NotificationCompat.PRIORITY_LOW)