mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-15 18:56:11 -04:00
Code cleanup
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
package eu.darken.capod.pods.core.apple
|
||||
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.PodDevice
|
||||
import eu.darken.capod.pods.core.apple.protocol.ContinuityProtocol
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
|
||||
interface ApplePods : PodDevice {
|
||||
|
||||
val tag: String
|
||||
|
||||
val proximityMessage: ProximityPairing.Message
|
||||
|
||||
override val rawData: ByteArray
|
||||
@@ -38,9 +35,4 @@ interface ApplePods : PodDevice {
|
||||
|
||||
val rawSuffix: UByte
|
||||
get() = proximityMessage.data[8]
|
||||
|
||||
companion object {
|
||||
|
||||
val TAG = logTag("Pod", "AppleDevice")
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ interface BasicSingleApplePods : ApplePods, HasSinglePod {
|
||||
get() = when (val value = rawPodsBattery.lowerNibble.toInt()) {
|
||||
15 -> null
|
||||
else -> if (value > 10) {
|
||||
log(tag) { "Left pod: Above 100% battery: $value" }
|
||||
log { "Left pod: Above 100% battery: $value" }
|
||||
1.0f
|
||||
} else {
|
||||
(value / 10f)
|
||||
|
||||
@@ -29,7 +29,7 @@ interface DualApplePods : ApplePods, HasDualPods, HasEarDetection, HasCase {
|
||||
return when (value) {
|
||||
15 -> null
|
||||
else -> if (value > 10) {
|
||||
log(tag) { "Left pod: Above 100% battery: $value" }
|
||||
log { "Left pod: Above 100% battery: $value" }
|
||||
1.0f
|
||||
} else {
|
||||
(value / 10f)
|
||||
@@ -46,7 +46,7 @@ interface DualApplePods : ApplePods, HasDualPods, HasEarDetection, HasCase {
|
||||
return when (value) {
|
||||
15 -> null
|
||||
else -> if (value > 10) {
|
||||
log(tag) { "Right pod: Above 100% battery: $value" }
|
||||
log { "Right pod: Above 100% battery: $value" }
|
||||
1.0f
|
||||
} else {
|
||||
value / 10f
|
||||
@@ -85,7 +85,7 @@ interface DualApplePods : ApplePods, HasDualPods, HasEarDetection, HasCase {
|
||||
get() = when (val value = rawCaseBattery.lowerNibble.toInt()) {
|
||||
15 -> null
|
||||
else -> if (value > 10) {
|
||||
log(tag) { "Case: Above 100% battery: $value" }
|
||||
log { "Case: Above 100% battery: $value" }
|
||||
1.0f
|
||||
} else {
|
||||
value / 10f
|
||||
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
@@ -18,6 +17,4 @@ data class UnknownAppleDevice constructor(
|
||||
override fun getLabel(context: Context): String {
|
||||
return context.getString(R.string.device_unknown_label)
|
||||
}
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "Unknown")
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple.airpods
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.DualApplePods
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
@@ -22,8 +21,6 @@ data class AirPodsGen1 constructor(
|
||||
override val iconRes: Int
|
||||
get() = R.drawable.ic_device_airpods_gen1
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "AirPods", "Gen1")
|
||||
|
||||
override val batteryCasePercent: Float?
|
||||
get() = super.batteryCasePercent ?: cachedBatteryPercentage
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple.airpods
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.DualApplePods
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
@@ -22,8 +21,6 @@ data class AirPodsGen2 constructor(
|
||||
override val iconRes: Int
|
||||
get() = R.drawable.ic_device_airpods_gen2
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "AirPods", "Gen2")
|
||||
|
||||
override val batteryCasePercent: Float?
|
||||
get() = super.batteryCasePercent ?: cachedBatteryPercentage
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple.airpods
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.SingleApplePods
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
@@ -21,5 +20,4 @@ data class AirPodsMax constructor(
|
||||
override val iconRes: Int
|
||||
get() = R.drawable.ic_device_generic_headphones
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "AirPods", "Max")
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple.airpods
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.DualApplePods
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
@@ -24,8 +23,6 @@ data class AirPodsPro constructor(
|
||||
override val iconRes: Int
|
||||
get() = R.drawable.ic_device_airpods_gen2
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "AirPods", "Pro")
|
||||
|
||||
override val batteryCasePercent: Float?
|
||||
get() = super.batteryCasePercent ?: cachedBatteryPercentage
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple.beats
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.BasicSingleApplePods
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
@@ -21,5 +20,4 @@ data class BeatsFlex constructor(
|
||||
override val iconRes: Int
|
||||
get() = R.drawable.ic_device_generic_earbuds
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "Beats", "Flex")
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple.beats
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.BasicSingleApplePods
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
@@ -21,5 +20,4 @@ data class BeatsSolo3 constructor(
|
||||
override val iconRes: Int
|
||||
get() = R.drawable.ic_device_generic_earbuds
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "Beats", "Solo3")
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple.beats
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.BasicSingleApplePods
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
@@ -21,5 +20,4 @@ data class BeatsStudio3 constructor(
|
||||
override val iconRes: Int
|
||||
get() = R.drawable.ic_device_generic_earbuds
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "Beats", "Studio3")
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple.beats
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.BasicSingleApplePods
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
@@ -21,5 +20,4 @@ data class BeatsX constructor(
|
||||
override val iconRes: Int
|
||||
get() = R.drawable.ic_device_generic_earbuds
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "Beats", "X")
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple.beats
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.BasicSingleApplePods
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
@@ -21,5 +20,4 @@ data class PowerBeats3 constructor(
|
||||
override val iconRes: Int
|
||||
get() = R.drawable.ic_device_generic_earbuds
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "Beats", "Power3")
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package eu.darken.capod.pods.core.apple.beats
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import eu.darken.capod.R
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.pods.core.apple.DualApplePods
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import java.time.Instant
|
||||
@@ -22,8 +21,6 @@ data class PowerBeatsPro constructor(
|
||||
override val iconRes: Int
|
||||
get() = R.drawable.ic_device_generic_earbuds
|
||||
|
||||
override val tag: String = logTag("Pod", "Apple", "Beats", "PowerPro")
|
||||
|
||||
override val batteryCasePercent: Float?
|
||||
get() = super.batteryCasePercent ?: cachedBatteryPercentage
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import dagger.Reusable
|
||||
import eu.darken.capod.common.debug.logging.log
|
||||
import eu.darken.capod.common.lowerNibble
|
||||
import eu.darken.capod.common.upperNibble
|
||||
import eu.darken.capod.pods.core.apple.ApplePods
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
@@ -38,11 +37,11 @@ object ProximityPairing {
|
||||
class Decoder @Inject constructor() {
|
||||
fun decode(message: ContinuityProtocol.Message): Message? {
|
||||
if (message.type != CONTINUITY_PROTOCOL_MESSAGE_TYPE_PROXIMITY_PAIRING) {
|
||||
log(ApplePods.TAG) { "Not a proximity pairing message: $this" }
|
||||
log { "Not a proximity pairing message: $this" }
|
||||
return null
|
||||
}
|
||||
if (message.length != PROXIMITY_PAIRING_MESSAGE_LENGTH) {
|
||||
log(ApplePods.TAG) { "Proximity pairing message has invalid length." }
|
||||
log { "Proximity pairing message has invalid length." }
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user