Skip to content

Commit 07a1179

Browse files
Ricky Cheungd4rken
Ricky Cheung
authored andcommitted
Implement support for different states in notification text
Fixes #198 Signed-off-by: Ricky Cheung <[email protected]>
1 parent 65a7b19 commit 07a1179

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

app-common/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<string name="pods_microphone_label">Microphone</string>
6262
<string name="pods_yours">Yours</string>
6363
<string name="headset_being_worn_label">Being worn</string>
64+
<string name="headset_not_being_worn_label">Not being worn</string>
6465
<string name="pods_case_unknown_state">Unknown state</string>
6566

6667
<string name="last_seen_x">Last seen: %s</string>

app/src/main/java/eu/darken/capod/monitor/ui/MonitorNotifications.kt

+33
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.app.PendingIntent
88
import android.content.Context
99
import android.content.Intent
1010
import android.content.pm.ServiceInfo
11+
import androidx.annotation.StringRes
1112
import androidx.core.app.NotificationCompat
1213
import androidx.work.ForegroundInfo
1314
import dagger.hilt.android.qualifiers.ApplicationContext
@@ -19,6 +20,10 @@ import eu.darken.capod.common.debug.logging.logTag
1920
import eu.darken.capod.common.hasApiLevel
2021
import eu.darken.capod.common.notifications.PendingIntentCompat
2122
import eu.darken.capod.main.ui.MainActivity
23+
import eu.darken.capod.pods.core.HasCase
24+
import eu.darken.capod.pods.core.HasChargeDetection
25+
import eu.darken.capod.pods.core.HasDualMicrophone
26+
import eu.darken.capod.pods.core.HasEarDetection
2227
import eu.darken.capod.pods.core.PodDevice
2328
import kotlinx.coroutines.sync.Mutex
2429
import kotlinx.coroutines.sync.withLock
@@ -71,9 +76,37 @@ class MonitorNotifications @Inject constructor(
7176
}
7277

7378
return builder.apply {
79+
@StringRes var contentTitleRes = eu.darken.capod.common.R.string.pods_case_unknown_state
80+
// Options here should be mutually exclusive, and are prioritized by their order of importance
81+
// Some options are omitted here, as they will conflict with other options
82+
// TODO: Implement a settings pane to allow user to customize this
83+
device.apply {
84+
// Pods charging state
85+
// This goes first as pods should not be worn if it is still charging
86+
if (this is HasChargeDetection && isHeadsetBeingCharged) {
87+
contentTitleRes = eu.darken.capod.common.R.string.pods_charging_label
88+
return@apply
89+
}
90+
91+
// Pods wear state
92+
if (this is HasEarDetection) {
93+
contentTitleRes = if (isBeingWorn) eu.darken.capod.common.R.string.headset_being_worn_label
94+
else eu.darken.capod.common.R.string.headset_not_being_worn_label
95+
return@apply
96+
}
97+
98+
// Case charge state
99+
// This is under pods wear state as we don't want it conflicting with it
100+
if (this is HasCase && isCaseCharging) {
101+
contentTitleRes = eu.darken.capod.common.R.string.pods_charging_label
102+
return@apply
103+
}
104+
}
105+
74106
setStyle(NotificationCompat.DecoratedCustomViewStyle())
75107
setCustomContentView(notificationViewFactory.createContentView(device))
76108
setSmallIcon(device.iconRes)
109+
setContentTitle(context.getString(contentTitleRes))
77110
setSubText(null)
78111
log(TAG, VERBOSE) { "updatingNotification(): $device" }
79112
}

0 commit comments

Comments
 (0)