Implement support for different states in notification text

Fixes #198

Signed-off-by: Ricky Cheung <rcheung844@gmail.com>
This commit is contained in:
Ricky Cheung
2024-06-27 08:34:19 +02:00
committed by Matthias Urhahn
parent 65a7b1933a
commit 07a11799b1
2 changed files with 34 additions and 0 deletions
@@ -61,6 +61,7 @@
<string name="pods_microphone_label">Microphone</string>
<string name="pods_yours">Yours</string>
<string name="headset_being_worn_label">Being worn</string>
<string name="headset_not_being_worn_label">Not being worn</string>
<string name="pods_case_unknown_state">Unknown state</string>
<string name="last_seen_x">Last seen: %s</string>
@@ -8,6 +8,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat
import androidx.work.ForegroundInfo
import dagger.hilt.android.qualifiers.ApplicationContext
@@ -19,6 +20,10 @@ import eu.darken.capod.common.debug.logging.logTag
import eu.darken.capod.common.hasApiLevel
import eu.darken.capod.common.notifications.PendingIntentCompat
import eu.darken.capod.main.ui.MainActivity
import eu.darken.capod.pods.core.HasCase
import eu.darken.capod.pods.core.HasChargeDetection
import eu.darken.capod.pods.core.HasDualMicrophone
import eu.darken.capod.pods.core.HasEarDetection
import eu.darken.capod.pods.core.PodDevice
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
@@ -71,9 +76,37 @@ class MonitorNotifications @Inject constructor(
}
return builder.apply {
@StringRes var contentTitleRes = eu.darken.capod.common.R.string.pods_case_unknown_state
// Options here should be mutually exclusive, and are prioritized by their order of importance
// Some options are omitted here, as they will conflict with other options
// TODO: Implement a settings pane to allow user to customize this
device.apply {
// Pods charging state
// This goes first as pods should not be worn if it is still charging
if (this is HasChargeDetection && isHeadsetBeingCharged) {
contentTitleRes = eu.darken.capod.common.R.string.pods_charging_label
return@apply
}
// Pods wear state
if (this is HasEarDetection) {
contentTitleRes = if (isBeingWorn) eu.darken.capod.common.R.string.headset_being_worn_label
else eu.darken.capod.common.R.string.headset_not_being_worn_label
return@apply
}
// Case charge state
// This is under pods wear state as we don't want it conflicting with it
if (this is HasCase && isCaseCharging) {
contentTitleRes = eu.darken.capod.common.R.string.pods_charging_label
return@apply
}
}
setStyle(NotificationCompat.DecoratedCustomViewStyle())
setCustomContentView(notificationViewFactory.createContentView(device))
setSmallIcon(device.iconRes)
setContentTitle(context.getString(contentTitleRes))
setSubText(null)
log(TAG, VERBOSE) { "updatingNotification(): $device" }
}