diff --git a/app-common/src/main/res/values/strings.xml b/app-common/src/main/res/values/strings.xml index fb718e3f..70b5bd51 100644 --- a/app-common/src/main/res/values/strings.xml +++ b/app-common/src/main/res/values/strings.xml @@ -61,6 +61,7 @@ Microphone Yours Being worn + Not being worn Unknown state Last seen: %s diff --git a/app/src/main/java/eu/darken/capod/monitor/ui/MonitorNotifications.kt b/app/src/main/java/eu/darken/capod/monitor/ui/MonitorNotifications.kt index 0b6fc856..eb103ffe 100644 --- a/app/src/main/java/eu/darken/capod/monitor/ui/MonitorNotifications.kt +++ b/app/src/main/java/eu/darken/capod/monitor/ui/MonitorNotifications.kt @@ -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" } }