Skip to content

Commit

Permalink
Implement support for different states in notification text
Browse files Browse the repository at this point in the history
Fixes #198

Signed-off-by: Ricky Cheung <[email protected]>
  • Loading branch information
Ricky Cheung authored and d4rken committed Jun 27, 2024
1 parent 65a7b19 commit 07a1179
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions app-common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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" }
}
Expand Down

0 comments on commit 07a1179

Please sign in to comment.