Skip to content

Commit

Permalink
fix: Use generic device profile if Bluetooth device has no address (w…
Browse files Browse the repository at this point in the history
…eird edge case)
  • Loading branch information
timschneeb committed Mar 28, 2023
1 parent 8acaf40 commit 8f5883d
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ class RoutingObserver(val context: Context) : MediaRouter.Callback(), KoinCompon
else
"${group.name.lowercase()}_${(if(group == DeviceGroup.BLUETOOTH) address else productName).lowercase().sanitize()}"
val name: String
// If single profile
get() = if(group.usesSingleProfile())
context.getString(group.nameRes)
// If Bluetooth device without address, use single profile
else if((group == DeviceGroup.BLUETOOTH && address.isBlank()))
"${context.getString(group.nameRes)} (${context.getString(R.string.group_unknown)})"
else {
"${if(hasProductName()) productName else address} (${context.getString(group.nameRes)})".let {
if(group == DeviceGroup.USB)
Expand All @@ -190,8 +194,10 @@ class RoutingObserver(val context: Context) : MediaRouter.Callback(), KoinCompon


override fun toString() = "Device(id=$id, group=$group, name='$name', productName='$productName', address='$address')"
// Special case: you can connect two phones of the same model name via bluetooth
private fun hasProductName() = (productName != Build.MODEL || group == DeviceGroup.BLUETOOTH) && productName.isNotEmpty()
private fun hasProductName(): Boolean {
// Special case: you can connect two phones of the same model name via bluetooth
return (productName != Build.MODEL || group == DeviceGroup.BLUETOOTH) && productName.isNotEmpty()
}
private fun String.sanitize() = this.replace("[ \\;/:*?\"<>|&']".toRegex(),"_")
}

Expand Down

0 comments on commit 8f5883d

Please sign in to comment.