Skip to content

Commit 2c2552a

Browse files
committed
show last battery status when a pod or case is disconnected
1 parent 7ed8f9b commit 2c2552a

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

android/app/src/main/java/me/kavishdevar/aln/composables/BatteryView.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,21 @@ fun BatteryView(service: AirPodsService, preview: Boolean = false) {
127127
.fillMaxWidth(),
128128
horizontalArrangement = Arrangement.Center
129129
) {
130-
if (left?.status != BatteryStatus.DISCONNECTED) {
130+
// if (left?.status != BatteryStatus.DISCONNECTED) {
131131
BatteryIndicator(
132132
left?.level ?: 0,
133133
left?.status == BatteryStatus.CHARGING
134134
)
135-
}
136-
if (left?.status != BatteryStatus.DISCONNECTED && right?.status != BatteryStatus.DISCONNECTED) {
135+
// }
136+
// if (left?.status != BatteryStatus.DISCONNECTED && right?.status != BatteryStatus.DISCONNECTED) {
137137
Spacer(modifier = Modifier.width(16.dp))
138-
}
139-
if (right?.status != BatteryStatus.DISCONNECTED) {
138+
// }
139+
// if (right?.status != BatteryStatus.DISCONNECTED) {
140140
BatteryIndicator(
141141
right?.level ?: 0,
142142
right?.status == BatteryStatus.CHARGING
143143
)
144-
}
144+
// }
145145
}
146146
}
147147
}
@@ -160,9 +160,9 @@ fun BatteryView(service: AirPodsService, preview: Boolean = false) {
160160
.fillMaxWidth()
161161
.scale(1.25f)
162162
)
163-
if (case?.status != BatteryStatus.DISCONNECTED) {
163+
// if (case?.status != BatteryStatus.DISCONNECTED) {
164164
BatteryIndicator(case?.level ?: 0, case?.status == BatteryStatus.CHARGING)
165-
}
165+
// }
166166
}
167167
}
168168
}

android/app/src/main/java/me/kavishdevar/aln/services/AirPodsService.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -171,31 +171,31 @@ class AirPodsService: Service() {
171171
it.setTextViewText(
172172
R.id.left_battery_widget,
173173
batteryNotification.getBattery().find { it.component == BatteryComponent.LEFT }?.let {
174-
if (it.status != BatteryStatus.DISCONNECTED) {
174+
// if (it.status != BatteryStatus.DISCONNECTED) {
175175
"${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
176-
} else {
177-
""
178-
}
176+
// } else {
177+
// ""
178+
// }
179179
} ?: ""
180180
)
181181
it.setTextViewText(
182182
R.id.right_battery_widget,
183183
batteryNotification.getBattery().find { it.component == BatteryComponent.RIGHT }?.let {
184-
if (it.status != BatteryStatus.DISCONNECTED) {
184+
// if (it.status != BatteryStatus.DISCONNECTED) {
185185
"${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
186-
} else {
187-
""
188-
}
186+
// } else {
187+
// ""
188+
// }
189189
} ?: ""
190190
)
191191
it.setTextViewText(
192192
R.id.case_battery_widget,
193193
batteryNotification.getBattery().find { it.component == BatteryComponent.CASE }?.let {
194-
if (it.status != BatteryStatus.DISCONNECTED) {
194+
// if (it.status != BatteryStatus.DISCONNECTED) {
195195
"${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
196-
} else {
197-
""
198-
}
196+
// } else {
197+
// ""
198+
// }
199199
} ?: ""
200200
)
201201
}
@@ -205,7 +205,7 @@ class AirPodsService: Service() {
205205

206206
fun updateNotificationContent(connected: Boolean, airpodsName: String? = null, batteryList: List<Battery>? = null) {
207207
val notificationManager = getSystemService(NotificationManager::class.java)
208-
val textColor = this.getSharedPreferences("settings", MODE_PRIVATE).getLong("textColor", 0)
208+
// val textColor = this.getSharedPreferences("settings", MODE_PRIVATE).getLong("textColor", 0)
209209
var updatedNotification: Notification? = null
210210

211211
if (connected) {
@@ -262,23 +262,23 @@ class AirPodsService: Service() {
262262
updatedNotification = NotificationCompat.Builder(this, "background_service_status")
263263
.setSmallIcon(R.drawable.airpods)
264264
.setContentTitle("""L: ${batteryList?.find { it.component == BatteryComponent.LEFT }?.let {
265-
if (it.status != BatteryStatus.DISCONNECTED) {
265+
// if (it.status != BatteryStatus.DISCONNECTED) {
266266
"${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
267-
} else {
268-
""
269-
}
267+
// } else {
268+
// ""
269+
// }
270270
} ?: ""} R: ${batteryList?.find { it.component == BatteryComponent.RIGHT }?.let {
271-
if (it.status != BatteryStatus.DISCONNECTED) {
271+
// if (it.status != BatteryStatus.DISCONNECTED) {
272272
"${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
273-
} else {
274-
""
275-
}
273+
// } else {
274+
// ""
275+
// }
276276
} ?: ""} C: ${batteryList?.find { it.component == BatteryComponent.CASE }?.let {
277-
if (it.status != BatteryStatus.DISCONNECTED) {
277+
// if (it.status != BatteryStatus.DISCONNECTED) {
278278
"${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
279-
} else {
280-
""
281-
}
279+
// } else {
280+
// ""
281+
// }
282282
} ?: ""}""")
283283
.setCategory(Notification.CATEGORY_SERVICE)
284284
.setPriority(NotificationCompat.PRIORITY_LOW)

0 commit comments

Comments
 (0)