Improve notification texts

This commit is contained in:
darken
2022-01-11 22:41:54 +01:00
parent 24cf1a6f8c
commit f822050ea1
8 changed files with 64 additions and 16 deletions
@@ -41,33 +41,33 @@ class DualApplePodsCardVH(parent: ViewGroup) :
val sb = StringBuilder(context.getString(R.string.pods_dual_left_label))
sb.append("\n").append(device.getBatteryLevelLeftPod(context))
when {
device.isLeftPodCharging -> sb.append("\n").append("Charging")
device.isLeftPodInEar -> sb.append("\n").append("In ear")
device.isLeftPodCharging -> sb.append("\n").append(getString(R.string.pods_charging_label))
device.isLeftPodInEar -> sb.append("\n").append(getString(R.string.pods_inear_label))
else -> {}
}
text = sb
}
podRight.apply {
val sb = StringBuilder("Right pod")
val sb = StringBuilder(getString(R.string.pods_dual_right_label))
sb.append("\n").append(device.getBatteryLevelRightPod(context))
when {
device.isRightPodCharging -> sb.append("\n").append("Charging")
device.isRightPodInEar -> sb.append("\n").append("In ear")
device.isRightPodCharging -> sb.append("\n").append(getString(R.string.pods_charging_label))
device.isRightPodInEar -> sb.append("\n").append(getString(R.string.pods_inear_label))
else -> {}
}
text = sb
}
when (device.microPhonePod) {
Pod.LEFT -> podLeft.append("\n(Microphone)")
Pod.RIGHT -> podRight.append("\n(Microphone)")
Pod.LEFT -> podLeft.append("\n(${context.getString(R.string.pods_microphone_label)})")
Pod.RIGHT -> podRight.append("\n(${context.getString(R.string.pods_microphone_label)})")
}
podCase.apply {
val sb = StringBuilder("Case")
val sb = StringBuilder(getString(R.string.pods_case_label))
sb.append("\n").append(device.getBatteryLevelCase(context))
if (device.isCaseCharging) sb.append("\n").append("Charging")
if (device.isCaseCharging) sb.append("\n").append(getString(R.string.pods_charging_label))
when (device.caseLidState) {
LidState.OPEN -> sb.append("\n").append(context.getString(R.string.pods_case_status_open_label))
LidState.CLOSED -> sb.append("\n").append(context.getString(R.string.pods_case_status_closed_label))
@@ -57,12 +57,19 @@ class MonitorNotifications @Inject constructor(
fun getBuilder(device: PodDevice?): NotificationCompat.Builder {
if (device == null) {
builder.setContentTitle(context.getString(R.string.pods_none_label_short))
builder.setSubText(context.getString(R.string.app_name))
builder.setSmallIcon(R.drawable.ic_device_generic_earbuds)
return builder
}
builder.setSmallIcon(device.iconRes)
builder.setContentTitle(device.getShortStatus(context))
builder.setSubText(null)
builder.setContentTitle(device.getStatusShort(context))
builder.setStyle(
NotificationCompat.BigTextStyle()
.setBigContentTitle(device.getLabel(context))
.bigText(device.getStatusLong(context).joinToString("\n"))
)
log(TAG, VERBOSE) { "updatingNotification(): $device" }
return builder
}
@@ -31,7 +31,9 @@ interface PodDevice {
fun getLabel(context: Context): String
fun getShortStatus(context: Context): String
fun getStatusShort(context: Context): String
fun getStatusLong(context: Context): List<String>
@get:DrawableRes
val iconRes: Int
@@ -9,11 +9,15 @@ import eu.darken.capod.pods.core.getBatteryLevelHeadset
interface BasicSingleApplePods : ApplePods, HasSinglePod {
override fun getShortStatus(context: Context): String = context.getString(
override fun getStatusShort(context: Context): String = context.getString(
R.string.pods_single_basic_status_short,
getBatteryLevelHeadset(context),
)
override fun getStatusLong(context: Context): List<String> {
return listOf("${context.getString(R.string.pods_single_headphones_label)}: ${getBatteryLevelHeadset(context)}")
}
override val batteryHeadsetPercent: Float?
get() = when (val value = rawPodsBattery.lowerNibble.toInt()) {
15 -> null
@@ -12,7 +12,7 @@ import eu.darken.capod.pods.core.HasDualPods.Pod
interface DualApplePods : ApplePods, HasDualPods, HasEarDetection, HasCase {
override fun getShortStatus(context: Context): String = context.getString(
override fun getStatusShort(context: Context): String = context.getString(
R.string.pods_dual_case_status_short,
getBatteryLevelLeftPod(context).let {
if (isLeftPodCharging) "$it*" else it
@@ -25,6 +25,30 @@ interface DualApplePods : ApplePods, HasDualPods, HasEarDetection, HasCase {
},
)
override fun getStatusLong(context: Context): List<String> {
val list = mutableListOf<String>()
StringBuilder("${context.getString(R.string.pods_dual_left_label)}: ${getBatteryLevelLeftPod(context)}").apply {
if (isLeftPodCharging) append(", ${context.getString(R.string.pods_charging_label)}")
if (isLeftPodInEar) append(", ${context.getString(R.string.pods_inear_label)}")
list.add(this.toString())
}
StringBuilder("${context.getString(R.string.pods_dual_right_label)}: ${getBatteryLevelRightPod(context)}").apply {
if (isRightPodCharging) append(", ${context.getString(R.string.pods_charging_label)}")
if (isRightPodInEar) append(", ${context.getString(R.string.pods_inear_label)}")
if (microPhonePod == Pod.RIGHT) append(", ${context.getString(R.string.pods_microphone_label)}")
list.add(this.toString())
}
StringBuilder("${context.getString(R.string.pods_case_label)}: ${getBatteryLevelCase(context)}").apply {
if (isCaseCharging) append(", ${context.getString(R.string.pods_charging_label)}")
list.add(this.toString())
}
return list
}
val microPhonePod: Pod
get() = when (rawStatus.isBitSet(5)) {
true -> Pod.LEFT
@@ -10,11 +10,15 @@ import eu.darken.capod.pods.core.getBatteryLevelHeadset
interface SingleApplePods : BasicSingleApplePods, HasEarDetection, HasSinglePod {
override fun getShortStatus(context: Context): String = context.getString(
override fun getStatusShort(context: Context): String = context.getString(
R.string.pods_single_basic_status_short,
getBatteryLevelHeadset(context),
)
override fun getStatusLong(context: Context): List<String> {
TODO("Not yet implemented")
}
val isHeadphonesBeingWorn: Boolean
get() = rawStatus.isBitSet(1)
@@ -18,7 +18,11 @@ data class UnknownAppleDevice(
return context.getString(R.string.pods_unknown_label)
}
override fun getShortStatus(context: Context): String {
override fun getStatusShort(context: Context): String {
return context.getString(R.string.pods_unknown_label)
}
override fun getStatusLong(context: Context): List<String> {
return listOf(rawDataHex)
}
}
+4 -1
View File
@@ -37,7 +37,7 @@
<string name="pods_dual_left_label">Left pod</string>
<string name="pods_dual_right_label">Right pod</string>
<string name="pods_dual_case_status_short">L %1$s | C %2$s | R %3$s</string>
<string name="pods_case_status_label">Case</string>
<string name="pods_case_label">Case</string>
<string name="pods_case_status_open_label">Open</string>
<string name="pods_case_status_closed_label">Closed</string>
<string name="pods_reception_x_label">Reception %s</string>
@@ -113,4 +113,7 @@
<string name="settings_fake_data_description">Show fake data, i.e. simulate device that don\'t exist.</string>
<string name="settings_debug_label">Debug settings</string>
<string name="settings_debug_description">Additional settings to help troubleshoot issues with the app.</string>
<string name="pods_charging_label">Charging</string>
<string name="pods_inear_label">In ear</string>
<string name="pods_microphone_label">Microphone</string>
</resources>