Skip to content

Commit fe69082

Browse files
committed
android: add ui for hearing stuff
mostly copied from the transparency settings, which are now updated to match ios <26 ui
1 parent 3ace0e1 commit fe69082

File tree

8 files changed

+1530
-158
lines changed

8 files changed

+1530
-158
lines changed

android/app/src/main/java/me/kavishdevar/librepods/MainActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ import me.kavishdevar.librepods.screens.AirPodsSettingsScreen
112112
import me.kavishdevar.librepods.screens.AppSettingsScreen
113113
import me.kavishdevar.librepods.screens.DebugScreen
114114
import me.kavishdevar.librepods.screens.HeadTrackingScreen
115+
import me.kavishdevar.librepods.screens.HearingAidScreen
116+
import me.kavishdevar.librepods.screens.HearingAidAdjustmentsScreen
115117
import me.kavishdevar.librepods.screens.LongPress
116118
import me.kavishdevar.librepods.screens.Onboarding
117119
import me.kavishdevar.librepods.screens.RenameScreen
@@ -380,6 +382,12 @@ fun Main() {
380382
composable("onboarding") {
381383
Onboarding(navController, context)
382384
}
385+
composable("hearing_aid") {
386+
HearingAidScreen(navController)
387+
}
388+
composable("hearing_aid_adjustments") {
389+
HearingAidAdjustmentsScreen(navController)
390+
}
383391
}
384392
}
385393

android/app/src/main/java/me/kavishdevar/librepods/composables/AccessibilitySlider.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ import kotlin.math.roundToInt
4949
@OptIn(ExperimentalMaterial3Api::class)
5050
@Composable
5151
fun AccessibilitySlider(
52-
label: String,
52+
label: String? = null,
5353
value: Float,
5454
onValueChange: (Float) -> Unit,
55-
valueRange: ClosedFloatingPointRange<Float>
55+
valueRange: ClosedFloatingPointRange<Float>,
56+
widthFrac: Float = 1f
5657
) {
5758
val isDarkTheme = isSystemInDarkTheme()
5859

@@ -62,18 +63,20 @@ fun AccessibilitySlider(
6263
val labelTextColor = if (isDarkTheme) Color.White else Color.Black
6364

6465
Column(
65-
modifier = Modifier.fillMaxWidth(),
66+
modifier = Modifier.fillMaxWidth(widthFrac),
6667
verticalArrangement = Arrangement.spacedBy(8.dp)
6768
) {
68-
Text(
69-
text = label,
70-
style = TextStyle(
71-
fontSize = 16.sp,
72-
fontWeight = FontWeight.Medium,
73-
color = labelTextColor,
74-
fontFamily = androidx.compose.ui.text.font.FontFamily(Font(R.font.sf_pro))
69+
if (label != null) {
70+
Text(
71+
text = label,
72+
style = TextStyle(
73+
fontSize = 16.sp,
74+
fontWeight = FontWeight.Medium,
75+
color = labelTextColor,
76+
fontFamily = androidx.compose.ui.text.font.FontFamily(Font(R.font.sf_pro))
77+
)
7578
)
76-
)
79+
}
7780

7881
Slider(
7982
value = value,

android/app/src/main/java/me/kavishdevar/librepods/composables/IndependentToggle.kt

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ import androidx.compose.foundation.background
2727
import androidx.compose.foundation.gestures.detectTapGestures
2828
import androidx.compose.foundation.isSystemInDarkTheme
2929
import androidx.compose.foundation.layout.Box
30+
import androidx.compose.foundation.layout.Column
31+
import androidx.compose.foundation.layout.Arrangement
3032
import androidx.compose.foundation.layout.Row
33+
import androidx.compose.foundation.layout.Spacer
3134
import androidx.compose.foundation.layout.fillMaxWidth
3235
import androidx.compose.foundation.layout.height
3336
import androidx.compose.foundation.layout.padding
@@ -45,17 +48,22 @@ import androidx.compose.ui.Modifier
4548
import androidx.compose.ui.graphics.Color
4649
import androidx.compose.ui.input.pointer.pointerInput
4750
import androidx.compose.ui.platform.LocalContext
51+
import androidx.compose.ui.text.TextStyle
52+
import androidx.compose.ui.text.font.Font
53+
import androidx.compose.ui.text.font.FontFamily
54+
import androidx.compose.ui.text.font.FontWeight
4855
import androidx.compose.ui.tooling.preview.Preview
4956
import androidx.compose.ui.unit.dp
5057
import androidx.compose.ui.unit.sp
5158
import me.kavishdevar.librepods.services.AirPodsService
59+
import me.kavishdevar.librepods.R
5260
import me.kavishdevar.librepods.utils.AACPManager
5361
import kotlin.io.encoding.ExperimentalEncodingApi
5462
import androidx.core.content.edit
5563
import android.util.Log
5664

5765
@Composable
58-
fun IndependentToggle(name: String, service: AirPodsService? = null, functionName: String? = null, sharedPreferences: SharedPreferences, default: Boolean = false, controlCommandIdentifier: AACPManager.Companion.ControlCommandIdentifiers? = null) {
66+
fun IndependentToggle(name: String, service: AirPodsService? = null, functionName: String? = null, sharedPreferences: SharedPreferences, default: Boolean = false, controlCommandIdentifier: AACPManager.Companion.ControlCommandIdentifiers? = null, description: String? = null) {
5967
val isDarkTheme = isSystemInDarkTheme()
6068
val textColor = if (isDarkTheme) Color.White else Color.Black
6169
val snakeCasedName =
@@ -109,39 +117,57 @@ fun IndependentToggle(name: String, service: AirPodsService? = null, functionNam
109117
}
110118
}
111119
}
112-
Box (
120+
Column (
113121
modifier = Modifier
114-
.padding(vertical = 8.dp)
115-
.background(animatedBackgroundColor, RoundedCornerShape(14.dp))
116-
.pointerInput(Unit) {
117-
detectTapGestures(
118-
onPress = {
119-
backgroundColor = if (isDarkTheme) Color(0x40888888) else Color(0x40D9D9D9)
120-
tryAwaitRelease()
121-
backgroundColor = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
122-
},
123-
onTap = {
124-
checked = !checked
125-
cb()
126-
}
127-
)
128-
},
129-
)
130-
{
131-
Row(
122+
.padding(vertical = 8.dp),
123+
) {
124+
Box (
132125
modifier = Modifier
133-
.fillMaxWidth()
134-
.height(55.dp)
135-
.padding(horizontal = 12.dp),
136-
verticalAlignment = Alignment.CenterVertically
137-
) {
138-
Text(text = name, modifier = Modifier.weight(1f), fontSize = 16.sp, color = textColor)
139-
StyledSwitch(
140-
checked = checked,
141-
onCheckedChange = {
142-
checked = it
143-
cb()
126+
.background(animatedBackgroundColor, RoundedCornerShape(14.dp))
127+
.pointerInput(Unit) {
128+
detectTapGestures(
129+
onPress = {
130+
backgroundColor = if (isDarkTheme) Color(0x40888888) else Color(0x40D9D9D9)
131+
tryAwaitRelease()
132+
backgroundColor = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
133+
},
134+
onTap = {
135+
checked = !checked
136+
cb()
137+
}
138+
)
144139
},
140+
)
141+
{
142+
Row(
143+
modifier = Modifier
144+
.fillMaxWidth()
145+
.height(55.dp)
146+
.padding(horizontal = 12.dp),
147+
verticalAlignment = Alignment.CenterVertically
148+
) {
149+
Text(text = name, modifier = Modifier.weight(1f), fontSize = 16.sp, color = textColor)
150+
StyledSwitch(
151+
checked = checked,
152+
onCheckedChange = {
153+
checked = it
154+
cb()
155+
},
156+
)
157+
}
158+
}
159+
if (description != null) {
160+
Spacer(modifier = Modifier.height(8.dp))
161+
Text(
162+
text = description,
163+
style = TextStyle(
164+
fontSize = 12.sp,
165+
fontWeight = FontWeight.Light,
166+
color = (if (isSystemInDarkTheme()) Color.White else Color.Black).copy(alpha = 0.6f),
167+
fontFamily = FontFamily(Font(R.font.sf_pro))
168+
),
169+
modifier = Modifier
170+
.padding(horizontal = 8.dp)
145171
)
146172
}
147173
}

0 commit comments

Comments
 (0)