mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-15 02:36:12 -04:00
Implement support for different states in notification text
Fixes #198 Signed-off-by: Ricky Cheung <rcheung844@gmail.com>
This commit is contained in:
committed by
Matthias Urhahn
parent
65a7b1933a
commit
07a11799b1
@@ -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" }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user