@@ -8,7 +8,6 @@ import android.app.PendingIntent
8
8
import android.content.Context
9
9
import android.content.Intent
10
10
import android.content.pm.ServiceInfo
11
- import androidx.annotation.StringRes
12
11
import androidx.core.app.NotificationCompat
13
12
import androidx.work.ForegroundInfo
14
13
import dagger.hilt.android.qualifiers.ApplicationContext
@@ -20,10 +19,16 @@ import eu.darken.capod.common.debug.logging.logTag
20
19
import eu.darken.capod.common.hasApiLevel
21
20
import eu.darken.capod.common.notifications.PendingIntentCompat
22
21
import eu.darken.capod.main.ui.MainActivity
22
+ import eu.darken.capod.pods.core.DualPodDevice
23
23
import eu.darken.capod.pods.core.HasCase
24
24
import eu.darken.capod.pods.core.HasChargeDetection
25
25
import eu.darken.capod.pods.core.HasEarDetection
26
26
import eu.darken.capod.pods.core.PodDevice
27
+ import eu.darken.capod.pods.core.SinglePodDevice
28
+ import eu.darken.capod.pods.core.getBatteryLevelCase
29
+ import eu.darken.capod.pods.core.getBatteryLevelHeadset
30
+ import eu.darken.capod.pods.core.getBatteryLevelLeftPod
31
+ import eu.darken.capod.pods.core.getBatteryLevelRightPod
27
32
import kotlinx.coroutines.sync.Mutex
28
33
import kotlinx.coroutines.sync.withLock
29
34
import javax.inject.Inject
@@ -75,36 +80,65 @@ class MonitorNotifications @Inject constructor(
75
80
}
76
81
77
82
return builder.apply {
78
- @StringRes var contentTitleRes = eu.darken.capod.common. R .string.pods_case_unknown_state
83
+
79
84
// Options here should be mutually exclusive, and are prioritized by their order of importance
80
85
// Some options are omitted here, as they will conflict with other options
81
86
// TODO: Implement a settings pane to allow user to customize this
82
- when (device) {
87
+ val stateText = when {
83
88
// Pods charging state
84
89
// This goes first as pods should not be worn if it is still charging
85
- is HasChargeDetection -> {
86
- if (device.isHeadsetBeingCharged)
87
- contentTitleRes = eu.darken.capod.common.R .string.pods_charging_label
90
+ device is HasChargeDetection && device.isHeadsetBeingCharged -> {
91
+ context.getString(eu.darken.capod.common.R .string.pods_charging_label)
88
92
}
89
93
90
94
// Pods wear state
91
- is HasEarDetection -> {
92
- contentTitleRes = if (device.isBeingWorn) eu.darken.capod.common.R .string.headset_being_worn_label
93
- else eu.darken.capod.common.R .string.headset_not_being_worn_label
95
+ device is HasEarDetection -> {
96
+ if (device.isBeingWorn) context.getString( eu.darken.capod.common.R .string.headset_being_worn_label)
97
+ else context.getString( eu.darken.capod.common.R .string.headset_not_being_worn_label)
94
98
}
95
99
96
100
// Case charge state
97
101
// This is under pods wear state as we don't want it conflicting with it
98
- is HasCase -> {
99
- if (device.isCaseCharging)
100
- contentTitleRes = eu.darken.capod.common.R .string.pods_charging_label
102
+ device is HasCase && device.isCaseCharging -> {
103
+ context.getString(eu.darken.capod.common.R .string.pods_charging_label)
104
+ }
105
+
106
+ else -> context.getString(eu.darken.capod.common.R .string.pods_case_unknown_state)
107
+ }
108
+
109
+ val batteryText = when (device) {
110
+ is DualPodDevice -> {
111
+ val left = device.getBatteryLevelLeftPod(context)
112
+ val right = device.getBatteryLevelRightPod(context)
113
+ when {
114
+ device is HasCase -> {
115
+ val case = device.getBatteryLevelCase(context)
116
+ " $left $case $right "
117
+ }
118
+
119
+ else -> " $left $right "
120
+ }
101
121
}
122
+
123
+ is SinglePodDevice -> {
124
+ val headset = device.getBatteryLevelHeadset(context)
125
+ when {
126
+ device is HasCase -> {
127
+ val case = device.getBatteryLevelCase(context)
128
+ " $headset $case "
129
+ }
130
+
131
+ else -> headset
132
+ }
133
+ }
134
+
135
+ else -> " ?"
102
136
}
103
137
104
138
setStyle(NotificationCompat .DecoratedCustomViewStyle ())
105
139
setCustomBigContentView(notificationViewFactory.createContentView(device))
106
140
setSmallIcon(device.iconRes)
107
- setContentTitle(context.getString(contentTitleRes) )
141
+ setContentTitle(" $batteryText ~ $stateText " )
108
142
setSubText(null )
109
143
log(TAG , VERBOSE ) { " updatingNotification(): $device " }
110
144
}
0 commit comments