mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-15 10:46:12 -04:00
Improve notification status text
This commit is contained in:
@@ -20,10 +20,6 @@ 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.PodDevice
|
||||
import eu.darken.capod.pods.core.apple.DualApplePods
|
||||
import eu.darken.capod.pods.core.getBatteryLevelCase
|
||||
import eu.darken.capod.pods.core.getBatteryLevelLeftPod
|
||||
import eu.darken.capod.pods.core.getBatteryLevelRightPod
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
@@ -66,21 +62,7 @@ class MonitorNotifications @Inject constructor(
|
||||
}
|
||||
|
||||
builder.setSmallIcon(device.iconRes)
|
||||
|
||||
val infoText = when (device) {
|
||||
is DualApplePods -> {
|
||||
val sb = StringBuilder()
|
||||
sb.append("L: ${device.getBatteryLevelLeftPod(context)}")
|
||||
sb.append(" | ")
|
||||
sb.append("C: ${device.getBatteryLevelCase(context)}")
|
||||
sb.append(" | ")
|
||||
sb.append("R: ${device.getBatteryLevelRightPod(context)}")
|
||||
}
|
||||
else -> {
|
||||
"Unknown device"
|
||||
}
|
||||
}
|
||||
builder.setContentTitle(infoText)
|
||||
builder.setContentTitle(device.getShortStatus(context))
|
||||
log(TAG, VERBOSE) { "updatingNotification(): $device" }
|
||||
return builder
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ interface PodDevice {
|
||||
|
||||
fun getLabel(context: Context): String
|
||||
|
||||
fun getShortStatus(context: Context): String
|
||||
|
||||
@get:DrawableRes
|
||||
val iconRes: Int
|
||||
get() = R.drawable.ic_device_generic_earbuds
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package eu.darken.capod.pods.core.apple
|
||||
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.log
|
||||
import eu.darken.capod.common.lowerNibble
|
||||
import eu.darken.capod.pods.core.HasSinglePod
|
||||
import eu.darken.capod.pods.core.getBatteryLevelHeadset
|
||||
|
||||
interface BasicSingleApplePods : ApplePods, HasSinglePod {
|
||||
|
||||
override fun getShortStatus(context: Context): String = context.getString(
|
||||
R.string.pods_single_basic_status_short,
|
||||
getBatteryLevelHeadset(context),
|
||||
)
|
||||
|
||||
override val batteryHeadsetPercent: Float?
|
||||
get() = when (val value = rawPodsBattery.lowerNibble.toInt()) {
|
||||
15 -> null
|
||||
|
||||
@@ -7,13 +7,24 @@ import eu.darken.capod.common.debug.logging.log
|
||||
import eu.darken.capod.common.isBitSet
|
||||
import eu.darken.capod.common.lowerNibble
|
||||
import eu.darken.capod.common.upperNibble
|
||||
import eu.darken.capod.pods.core.HasCase
|
||||
import eu.darken.capod.pods.core.HasDualPods
|
||||
import eu.darken.capod.pods.core.*
|
||||
import eu.darken.capod.pods.core.HasDualPods.Pod
|
||||
import eu.darken.capod.pods.core.HasEarDetection
|
||||
|
||||
interface DualApplePods : ApplePods, HasDualPods, HasEarDetection, HasCase {
|
||||
|
||||
override fun getShortStatus(context: Context): String = context.getString(
|
||||
R.string.pods_dual_case_status_short,
|
||||
getBatteryLevelLeftPod(context).let {
|
||||
if (isLeftPodCharging) "$it*" else it
|
||||
},
|
||||
getBatteryLevelCase(context).let {
|
||||
if (isCaseCharging) "$it*" else it
|
||||
},
|
||||
getBatteryLevelRightPod(context).let {
|
||||
if (isRightPodCharging) "$it*" else it
|
||||
},
|
||||
)
|
||||
|
||||
val microPhonePod: Pod
|
||||
get() = when (rawStatus.isBitSet(5)) {
|
||||
true -> Pod.LEFT
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
package eu.darken.capod.pods.core.apple
|
||||
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.isBitSet
|
||||
import eu.darken.capod.common.upperNibble
|
||||
import eu.darken.capod.pods.core.HasEarDetection
|
||||
import eu.darken.capod.pods.core.HasSinglePod
|
||||
import eu.darken.capod.pods.core.getBatteryLevelHeadset
|
||||
|
||||
interface SingleApplePods : BasicSingleApplePods, HasEarDetection, HasSinglePod {
|
||||
|
||||
override fun getShortStatus(context: Context): String = context.getString(
|
||||
R.string.pods_single_basic_status_short,
|
||||
getBatteryLevelHeadset(context),
|
||||
)
|
||||
|
||||
val isHeadphonesBeingWorn: Boolean
|
||||
get() = rawStatus.isBitSet(1)
|
||||
|
||||
|
||||
@@ -17,4 +17,8 @@ data class UnknownAppleDevice constructor(
|
||||
override fun getLabel(context: Context): String {
|
||||
return context.getString(R.string.device_unknown_label)
|
||||
}
|
||||
|
||||
override fun getShortStatus(context: Context): String {
|
||||
return context.getString(R.string.device_unknown_label)
|
||||
}
|
||||
}
|
||||
@@ -99,4 +99,6 @@
|
||||
<string name="settings_showall_description">Show other people\'s devices that are near you.</string>
|
||||
<string name="settings_autopplay_label">Auto play</string>
|
||||
<string name="settings_autoplay_description">Start music playback music when wearing the device (if supported).</string>
|
||||
<string name="pods_dual_case_status_short">L %1$s | C %2$s | R %3$s</string>
|
||||
<string name="pods_single_basic_status_short">Headphones: %1$s</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user