Slightly nicer notifications.

This commit is contained in:
darken
2022-01-01 20:57:30 +01:00
parent 661696aa7e
commit c5231b26aa
3 changed files with 29 additions and 14 deletions
@@ -80,7 +80,6 @@ class OverviewFragmentVM @Inject constructor(
.forEach { items.add(it) } .forEach { items.add(it) }
pods pods
.sortedBy { it.rssi }
.map { .map {
when (it) { when (it) {
is DualApplePods -> DualApplePodsCardVH.Item(it) is DualApplePods -> DualApplePodsCardVH.Item(it)
@@ -19,9 +19,9 @@ class PodMonitor @Inject constructor(
val pods: Flow<List<PodDevice>> = bleScanner.scan() val pods: Flow<List<PodDevice>> = bleScanner.scan()
.onStart { emptyList<PodDevice>() } .onStart { emptyList<PodDevice>() }
.map { scanResults -> .map { scanResults ->
scanResults.mapNotNull { scanResult -> scanResults
podFactory.createPod(scanResult) .sortedByDescending { it.rssi }
} .mapNotNull { podFactory.createPod(it) }
} }
companion object { companion object {
@@ -20,6 +20,10 @@ import eu.darken.capod.common.hasApiLevel
import eu.darken.capod.common.notifications.PendingIntentCompat import eu.darken.capod.common.notifications.PendingIntentCompat
import eu.darken.capod.main.ui.MainActivity import eu.darken.capod.main.ui.MainActivity
import eu.darken.capod.pods.core.PodDevice import eu.darken.capod.pods.core.PodDevice
import eu.darken.capod.pods.core.airpods.DualApplePods
import eu.darken.capod.pods.core.getBatteryCase
import eu.darken.capod.pods.core.getBatteryLeftPod
import eu.darken.capod.pods.core.getBatteryRightPod
import javax.inject.Inject import javax.inject.Inject
@@ -48,20 +52,32 @@ class MonitorNotifications @Inject constructor(
builder = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID) builder = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setChannelId(NOTIFICATION_CHANNEL_ID) .setChannelId(NOTIFICATION_CHANNEL_ID)
.setContentIntent(openPi) .setContentIntent(openPi)
.setPriority(NotificationCompat.PRIORITY_HIGH) .setPriority(NotificationCompat.PRIORITY_LOW)
.setSmallIcon(R.drawable.ic_notification_device_status_icon) .setSmallIcon(R.drawable.ic_notification_device_status_icon)
.setOngoing(true)
.setContentTitle(context.getString(R.string.app_name)) .setContentTitle(context.getString(R.string.app_name))
.setStyle(
NotificationCompat.BigTextStyle().bigText(context.getString(R.string.device_status_loading_message))
)
} }
fun getBuilder(podDevice: PodDevice?): NotificationCompat.Builder { fun getBuilder(device: PodDevice?): NotificationCompat.Builder {
if (podDevice == null) return builder if (device == null) {
builder.setContentTitle(context.getString(R.string.device_status_loading_message))
// builder.setContentTitle(gear.primary.get(context)) return builder
// builder.setStyle(NotificationCompat.BigTextStyle().bigText(it.secondary.get(context))) }
log(TAG, VERBOSE) { "updatingNotification(): $podDevice" } val infoText = when (device) {
is DualApplePods -> {
val sb = StringBuilder()
sb.append("L: ${device.getBatteryLeftPod(context)}")
sb.append(" | ")
sb.append("C: ${device.getBatteryCase(context)}")
sb.append(" | ")
sb.append("R: ${device.getBatteryRightPod(context)}")
}
else -> {
"Unknown device"
}
}
builder.setContentTitle(infoText)
log(TAG, VERBOSE) { "updatingNotification(): $device" }
return builder return builder
} }