From 051677e7dd38500bf57bc7024630fbbffb73507d Mon Sep 17 00:00:00 2001 From: Ricky Cheung Date: Thu, 27 Jun 2024 15:03:11 +0800 Subject: [PATCH] Prevent return@apply duplicates Signed-off-by: Ricky Cheung --- .../capod/monitor/ui/MonitorNotifications.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) 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 a265f8ba..428d9837 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 @@ -79,26 +79,25 @@ class MonitorNotifications @Inject constructor( // 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 { + when (device) { // 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 + is HasChargeDetection -> { + if (device.isHeadsetBeingCharged) + contentTitleRes = eu.darken.capod.common.R.string.pods_charging_label } // 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 + is HasEarDetection -> { + contentTitleRes = if (device.isBeingWorn) eu.darken.capod.common.R.string.headset_being_worn_label + else eu.darken.capod.common.R.string.headset_not_being_worn_label } // 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 + is HasCase -> { + if (device.isCaseCharging) + contentTitleRes = eu.darken.capod.common.R.string.pods_charging_label } }