mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-04-09 21:02:53 +00:00
do not show "off" option when off listening mode is disabled
This commit is contained in:
@@ -60,6 +60,10 @@ import me.kavishdevar.aln.utils.NoiseControlMode
|
|||||||
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||||||
@Composable
|
@Composable
|
||||||
fun NoiseControlSettings(service: AirPodsService) {
|
fun NoiseControlSettings(service: AirPodsService) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val sharedPreferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||||
|
val offListeningMode = sharedPreferences.getBoolean("off_listening_mode", true)
|
||||||
|
|
||||||
val isDarkTheme = isSystemInDarkTheme()
|
val isDarkTheme = isSystemInDarkTheme()
|
||||||
val backgroundColor = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFE3E3E8)
|
val backgroundColor = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFE3E3E8)
|
||||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||||
@@ -68,15 +72,18 @@ fun NoiseControlSettings(service: AirPodsService) {
|
|||||||
|
|
||||||
val noiseControlMode = remember { mutableStateOf(NoiseControlMode.OFF) }
|
val noiseControlMode = remember { mutableStateOf(NoiseControlMode.OFF) }
|
||||||
|
|
||||||
|
|
||||||
val d1a = remember { mutableFloatStateOf(0f) }
|
val d1a = remember { mutableFloatStateOf(0f) }
|
||||||
val d2a = remember { mutableFloatStateOf(0f) }
|
val d2a = remember { mutableFloatStateOf(0f) }
|
||||||
val d3a = remember { mutableFloatStateOf(0f) }
|
val d3a = remember { mutableFloatStateOf(0f) }
|
||||||
|
|
||||||
fun onModeSelected(mode: NoiseControlMode, received: Boolean = false) {
|
fun onModeSelected(mode: NoiseControlMode, received: Boolean = false) {
|
||||||
noiseControlMode.value = mode
|
if (!received && !offListeningMode && mode == NoiseControlMode.OFF) {
|
||||||
if (!received) service.setANCMode(mode.ordinal+1)
|
noiseControlMode.value = NoiseControlMode.ADAPTIVE
|
||||||
when (mode) {
|
} else {
|
||||||
|
noiseControlMode.value = mode
|
||||||
|
}
|
||||||
|
if (!received) service.setANCMode(mode.ordinal + 1)
|
||||||
|
when (noiseControlMode.value) {
|
||||||
NoiseControlMode.NOISE_CANCELLATION -> {
|
NoiseControlMode.NOISE_CANCELLATION -> {
|
||||||
d1a.floatValue = 1f
|
d1a.floatValue = 1f
|
||||||
d2a.floatValue = 1f
|
d2a.floatValue = 1f
|
||||||
@@ -106,8 +113,7 @@ fun NoiseControlSettings(service: AirPodsService) {
|
|||||||
if (intent.action == AirPodsNotifications.ANC_DATA) {
|
if (intent.action == AirPodsNotifications.ANC_DATA) {
|
||||||
noiseControlMode.value = NoiseControlMode.entries.toTypedArray()[intent.getIntExtra("data", 3) - 1]
|
noiseControlMode.value = NoiseControlMode.entries.toTypedArray()[intent.getIntExtra("data", 3) - 1]
|
||||||
onModeSelected(noiseControlMode.value, true)
|
onModeSelected(noiseControlMode.value, true)
|
||||||
}
|
} else if (intent.action == AirPodsNotifications.DISCONNECT_RECEIVERS) {
|
||||||
else if (intent.action == AirPodsNotifications.DISCONNECT_RECEIVERS) {
|
|
||||||
try {
|
try {
|
||||||
context.unregisterReceiver(this)
|
context.unregisterReceiver(this)
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
@@ -118,16 +124,13 @@ fun NoiseControlSettings(service: AirPodsService) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val context = LocalContext.current
|
val noiseControlIntentFilter = IntentFilter().apply {
|
||||||
val noiseControlIntentFilter = IntentFilter()
|
addAction(AirPodsNotifications.ANC_DATA)
|
||||||
.apply {
|
addAction(AirPodsNotifications.DISCONNECT_RECEIVERS)
|
||||||
addAction(AirPodsNotifications.ANC_DATA)
|
}
|
||||||
addAction(AirPodsNotifications.DISCONNECT_RECEIVERS)
|
|
||||||
}
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
context.registerReceiver(noiseControlReceiver, noiseControlIntentFilter, Context.RECEIVER_EXPORTED)
|
context.registerReceiver(noiseControlReceiver, noiseControlIntentFilter, Context.RECEIVER_EXPORTED)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
context.registerReceiver(noiseControlReceiver, noiseControlIntentFilter)
|
context.registerReceiver(noiseControlReceiver, noiseControlIntentFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,20 +160,22 @@ fun NoiseControlSettings(service: AirPodsService) {
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.background(backgroundColor, RoundedCornerShape(14.dp))
|
.background(backgroundColor, RoundedCornerShape(14.dp))
|
||||||
) {
|
) {
|
||||||
NoiseControlButton(
|
if (offListeningMode) {
|
||||||
icon = ImageBitmap.imageResource(R.drawable.noise_cancellation),
|
NoiseControlButton(
|
||||||
onClick = { onModeSelected(NoiseControlMode.OFF) },
|
icon = ImageBitmap.imageResource(R.drawable.noise_cancellation),
|
||||||
textColor = if (noiseControlMode.value == NoiseControlMode.OFF) textColorSelected else textColor,
|
onClick = { onModeSelected(NoiseControlMode.OFF) },
|
||||||
backgroundColor = if (noiseControlMode.value == NoiseControlMode.OFF) selectedBackground else Color.Transparent,
|
textColor = if (noiseControlMode.value == NoiseControlMode.OFF) textColorSelected else textColor,
|
||||||
modifier = Modifier.weight(1f)
|
backgroundColor = if (noiseControlMode.value == NoiseControlMode.OFF) selectedBackground else Color.Transparent,
|
||||||
)
|
modifier = Modifier.weight(1f)
|
||||||
VerticalDivider(
|
)
|
||||||
thickness = 1.dp,
|
VerticalDivider(
|
||||||
modifier = Modifier
|
thickness = 1.dp,
|
||||||
.padding(vertical = 10.dp)
|
modifier = Modifier
|
||||||
.alpha(d1a.floatValue),
|
.padding(vertical = 10.dp)
|
||||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.12f),
|
.alpha(d1a.floatValue),
|
||||||
)
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.12f),
|
||||||
|
)
|
||||||
|
}
|
||||||
NoiseControlButton(
|
NoiseControlButton(
|
||||||
icon = ImageBitmap.imageResource(R.drawable.transparency),
|
icon = ImageBitmap.imageResource(R.drawable.transparency),
|
||||||
onClick = { onModeSelected(NoiseControlMode.TRANSPARENCY) },
|
onClick = { onModeSelected(NoiseControlMode.TRANSPARENCY) },
|
||||||
@@ -214,13 +219,15 @@ fun NoiseControlSettings(service: AirPodsService) {
|
|||||||
.padding(horizontal = 8.dp)
|
.padding(horizontal = 8.dp)
|
||||||
.padding(top = 1.dp)
|
.padding(top = 1.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
if (offListeningMode) {
|
||||||
text = "Off",
|
Text(
|
||||||
style = TextStyle(fontSize = 12.sp, color = textColor),
|
text = "Off",
|
||||||
textAlign = TextAlign.Center,
|
style = TextStyle(fontSize = 12.sp, color = textColor),
|
||||||
fontWeight = FontWeight.Bold,
|
textAlign = TextAlign.Center,
|
||||||
modifier = Modifier.weight(1f)
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
modifier = Modifier.weight(1f)
|
||||||
|
)
|
||||||
|
}
|
||||||
Text(
|
Text(
|
||||||
text = "Transparency",
|
text = "Transparency",
|
||||||
style = TextStyle(fontSize = 12.sp, color = textColor),
|
style = TextStyle(fontSize = 12.sp, color = textColor),
|
||||||
|
|||||||
Reference in New Issue
Block a user