Skip to content

Commit 033d9e1

Browse files
authored
feat: add presets to User Agent edit column (#81)
1 parent a22a22e commit 033d9e1

5 files changed

Lines changed: 155 additions & 47 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ android {
5050
dependencies {
5151
def lifecycle_version = "2.6.0-alpha05"
5252
def nav_version = "2.5.3"
53-
def material3_version = "1.0.1"
53+
def material3_version = "1.1.0-alpha08"
5454

5555
implementation 'androidx.core:core-ktx:1.9.0'
5656
implementation 'androidx.appcompat:appcompat:1.6.0'

app/src/main/java/dev/bluehouse/enablevolte/Components.kt

Lines changed: 111 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import androidx.compose.foundation.layout.Column
44
import androidx.compose.foundation.layout.Row
55
import androidx.compose.foundation.layout.fillMaxWidth
66
import androidx.compose.foundation.layout.padding
7+
import androidx.compose.foundation.layout.wrapContentHeight
8+
import androidx.compose.foundation.layout.wrapContentWidth
79
import androidx.compose.material3.AlertDialog
10+
import androidx.compose.material3.DropdownMenuItem
811
import androidx.compose.material3.ExperimentalMaterial3Api
12+
import androidx.compose.material3.ExposedDropdownMenuBox
13+
import androidx.compose.material3.ExposedDropdownMenuDefaults
914
import androidx.compose.material3.MaterialTheme
1015
import androidx.compose.material3.Surface
1116
import androidx.compose.material3.Switch
@@ -23,7 +28,8 @@ import androidx.compose.ui.Alignment
2328
import androidx.compose.ui.Modifier
2429
import androidx.compose.ui.platform.LocalLifecycleOwner
2530
import androidx.compose.ui.res.stringResource
26-
import androidx.compose.ui.unit.Dp
31+
import androidx.compose.ui.text.TextStyle
32+
import androidx.compose.ui.unit.dp
2733
import androidx.compose.ui.unit.sp
2834
import androidx.lifecycle.Lifecycle
2935
import androidx.lifecycle.LifecycleEventObserver
@@ -49,7 +55,7 @@ fun OnLifecycleEvent(onEvent: (owner: LifecycleOwner, event: Lifecycle.Event) ->
4955

5056
@Composable
5157
fun HeaderText(text: String) {
52-
Row(modifier = Modifier.padding(top = Dp(20f), bottom = Dp(12f))) {
58+
Row(modifier = Modifier.padding(top = 20.dp, bottom = 12.dp)) {
5359
Text(text = text, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
5460
}
5561
}
@@ -64,25 +70,117 @@ fun BooleanPropertyView(
6470
onClick: ((Boolean) -> Unit)? = null,
6571
) {
6672
if (toggled == null) {
67-
Column(modifier = Modifier.padding(top = Dp(12f), bottom = Dp(12f))) {
68-
Text(text = label, fontSize = 18.sp, modifier = Modifier.padding(bottom = Dp(4f)))
73+
Column(modifier = Modifier.padding(top = 12.dp, bottom = 12.dp)) {
74+
Text(text = label, fontSize = 18.sp, modifier = Modifier.padding(bottom = 4.dp))
6975
Text(text = stringResource(R.string.unknown), fontSize = 14.sp, color = MaterialTheme.colorScheme.outline)
7076
}
7177
return
7278
}
7379
if (onClick != null) {
74-
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(top = Dp(12f), bottom = Dp(12f))) {
80+
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(top = 12.dp, bottom = 12.dp)) {
7581
Text(text = label, modifier = Modifier.weight(1F), fontSize = 18.sp)
7682
Switch(checked = toggled, enabled = enabled, onCheckedChange = onClick)
7783
}
7884
} else {
79-
Column(modifier = Modifier.padding(top = Dp(12f), bottom = Dp(12f))) {
80-
Text(text = label, fontSize = 18.sp, modifier = Modifier.padding(bottom = Dp(4f)))
85+
Column(modifier = Modifier.padding(top = 12.dp, bottom = 12.dp)) {
86+
Text(text = label, fontSize = 18.sp, modifier = Modifier.padding(bottom = 4.dp))
8187
Text(text = if (toggled) { trueLabel } else { falseLabel }, fontSize = 14.sp, color = MaterialTheme.colorScheme.outline)
8288
}
8389
}
8490
}
8591

92+
@OptIn(ExperimentalMaterial3Api::class)
93+
@Composable
94+
fun UserAgentPropertyView(label: String, value: String?, onUpdate: ((String) -> Unit)? = null) {
95+
val labels = arrayOf(stringResource(R.string.default_), stringResource(R.string.lgu))
96+
val values = arrayOf(stringResource(R.string.ua_default), stringResource(R.string.ua_lgu))
97+
98+
var typedText by rememberSaveable { mutableStateOf("") }
99+
var openTextEditDialog by rememberSaveable { mutableStateOf(false) }
100+
var dropdownExpanded by rememberSaveable { mutableStateOf(false) }
101+
var selectedIndex by rememberSaveable { mutableStateOf(if (values.contains(value)) values.indexOf(value) else 0) }
102+
103+
if (onUpdate != null) {
104+
if (openTextEditDialog) {
105+
AlertDialog(
106+
onDismissRequest = {
107+
// Dismiss the dialog when the user clicks outside the dialog or on the back
108+
// button. If you want to disable that functionality, simply use an empty
109+
// onDismissRequest.
110+
openTextEditDialog = false
111+
},
112+
) {
113+
Surface(
114+
modifier = Modifier
115+
.wrapContentWidth()
116+
.wrapContentHeight(),
117+
shape = MaterialTheme.shapes.large,
118+
) {
119+
Column(modifier = Modifier.padding(all = 16.dp)) {
120+
Text(text = stringResource(R.string.update_value), style = MaterialTheme.typography.titleLarge, modifier = Modifier.padding(bottom = 24.dp))
121+
ExposedDropdownMenuBox(
122+
expanded = dropdownExpanded,
123+
onExpandedChange = { dropdownExpanded = !dropdownExpanded },
124+
modifier = Modifier.padding(bottom = 8.dp),
125+
) {
126+
TextField(
127+
// The `menuAnchor` modifier must be passed to the text field for correctness.
128+
modifier = Modifier.menuAnchor().wrapContentWidth(),
129+
readOnly = true,
130+
value = if (values[selectedIndex] == typedText) labels[selectedIndex] else "Custom",
131+
onValueChange = {},
132+
label = { Text("Presets") },
133+
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = dropdownExpanded) },
134+
colors = ExposedDropdownMenuDefaults.textFieldColors(),
135+
)
136+
ExposedDropdownMenu(
137+
expanded = dropdownExpanded,
138+
onDismissRequest = { dropdownExpanded = false },
139+
) {
140+
labels.forEachIndexed { i, label ->
141+
DropdownMenuItem(
142+
text = { Text(text = label) },
143+
onClick = {
144+
typedText = values[i]
145+
selectedIndex = i
146+
dropdownExpanded = false
147+
},
148+
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
149+
)
150+
}
151+
}
152+
}
153+
TextField(textStyle = TextStyle(fontSize = 14.sp), value = typedText, onValueChange = { typedText = it })
154+
Row(modifier = Modifier.align(Alignment.End)) {
155+
TextButton(
156+
onClick = {
157+
onUpdate(typedText)
158+
openTextEditDialog = false
159+
},
160+
) {
161+
Text(stringResource(R.string.confirm))
162+
}
163+
TextButton(
164+
onClick = {
165+
openTextEditDialog = false
166+
},
167+
) {
168+
Text(stringResource(R.string.dismiss))
169+
}
170+
}
171+
}
172+
}
173+
}
174+
}
175+
}
176+
ClickablePropertyView(label = label, value = value) {
177+
if (value != null) {
178+
typedText = value
179+
openTextEditDialog = true
180+
}
181+
}
182+
}
183+
86184
@OptIn(ExperimentalMaterial3Api::class)
87185
@Composable
88186
fun StringPropertyView(label: String, value: String?, onUpdate: ((String) -> Unit)? = null) {
@@ -136,22 +234,22 @@ fun StringPropertyView(label: String, value: String?, onUpdate: ((String) -> Uni
136234
@Composable
137235
fun ClickablePropertyView(label: String, value: String?, onClick: (() -> Unit)? = null) {
138236
if (value == null) {
139-
Column(modifier = Modifier.padding(top = Dp(12f), bottom = Dp(12f))) {
140-
Text(text = label, modifier = Modifier.padding(bottom = Dp(4f)))
237+
Column(modifier = Modifier.padding(top = 12.dp, bottom = 12.dp)) {
238+
Text(text = label, modifier = Modifier.padding(bottom = 4.dp))
141239
Text(text = stringResource(R.string.unknown), color = MaterialTheme.colorScheme.outline, fontSize = 14f.sp)
142240
}
143241
return
144242
}
145243
if (onClick != null) {
146244
Surface(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
147-
Column(modifier = Modifier.padding(top = Dp(12f), bottom = Dp(12f))) {
148-
Text(text = label, modifier = Modifier.padding(bottom = Dp(4f)), fontSize = 18.sp)
245+
Column(modifier = Modifier.padding(top = 12.dp, bottom = 12.dp)) {
246+
Text(text = label, modifier = Modifier.padding(bottom = 4.dp), fontSize = 18.sp)
149247
Text(text = value, color = MaterialTheme.colorScheme.outline, fontSize = 14f.sp)
150248
}
151249
}
152250
} else {
153-
Column(modifier = Modifier.padding(top = Dp(12f), bottom = Dp(12f))) {
154-
Text(text = label, modifier = Modifier.padding(bottom = Dp(4f)))
251+
Column(modifier = Modifier.padding(top = 12.dp, bottom = 12.dp)) {
252+
Text(text = label, modifier = Modifier.padding(bottom = 4.dp))
155253
Text(text = value, color = MaterialTheme.colorScheme.outline, fontSize = 14f.sp)
156254
}
157255
}

app/src/main/java/dev/bluehouse/enablevolte/pages/Config.kt

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import dev.bluehouse.enablevolte.ClickablePropertyView
2222
import dev.bluehouse.enablevolte.HeaderText
2323
import dev.bluehouse.enablevolte.OnLifecycleEvent
2424
import dev.bluehouse.enablevolte.R
25-
import dev.bluehouse.enablevolte.StringPropertyView
2625
import dev.bluehouse.enablevolte.SubscriptionModer
26+
import dev.bluehouse.enablevolte.UserAgentPropertyView
2727
import dev.bluehouse.enablevolte.checkShizukuPermission
2828
import java.lang.IllegalStateException
2929

@@ -84,7 +84,7 @@ fun Config(navController: NavController, subId: Int) {
8484
}
8585

8686
Column(modifier = Modifier.padding(Dp(16f)).verticalScroll(scrollState)) {
87-
HeaderText(text = stringResource(R.string.toggles))
87+
HeaderText(text = stringResource(R.string.feature_toggles))
8888
BooleanPropertyView(label = stringResource(R.string.enable_volte), toggled = voLTEEnabled) {
8989
voLTEEnabled = if (voLTEEnabled) {
9090
moder.updateCarrierConfig(CarrierConfigManager.KEY_CARRIER_VOLTE_AVAILABLE_BOOL, false)
@@ -109,6 +109,37 @@ fun Config(navController: NavController, subId: Int) {
109109
true
110110
}
111111
}
112+
BooleanPropertyView(label = stringResource(R.string.enable_video_calling_vt), toggled = vtEnabled) {
113+
vtEnabled = if (vtEnabled) {
114+
moder.updateCarrierConfig(CarrierConfigManager.KEY_CARRIER_VT_AVAILABLE_BOOL, false)
115+
false
116+
} else {
117+
moder.updateCarrierConfig(CarrierConfigManager.KEY_CARRIER_VT_AVAILABLE_BOOL, true)
118+
moder.restartIMSRegistration()
119+
true
120+
}
121+
}
122+
BooleanPropertyView(label = stringResource(R.string.enable_enhanced_4g_lte_lte_untested), toggled = is4GPlusEnabled) {
123+
is4GPlusEnabled = if (is4GPlusEnabled) {
124+
moder.updateCarrierConfig(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL, false)
125+
moder.updateCarrierConfig(CarrierConfigManager.KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL, false)
126+
moder.updateCarrierConfig(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL, true)
127+
false
128+
} else {
129+
moder.updateCarrierConfig(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL, true)
130+
moder.updateCarrierConfig(CarrierConfigManager.KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL, true)
131+
moder.updateCarrierConfig(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL, false)
132+
true
133+
}
134+
}
135+
136+
HeaderText(text = stringResource(R.string.string_values))
137+
UserAgentPropertyView(label = stringResource(R.string.user_agent), value = configuredUserAgent) {
138+
moder.updateCarrierConfig(moder.KEY_IMS_USER_AGENT, it)
139+
configuredUserAgent = it
140+
}
141+
142+
HeaderText(text = stringResource(R.string.cosmetic_toggles))
112143
BooleanPropertyView(label = stringResource(R.string.show_vowifi_preference_in_settings), toggled = showVoWifiMode) {
113144
showVoWifiMode = if (showVoWifiMode) {
114145
moder.updateCarrierConfig(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, false)
@@ -149,16 +180,6 @@ fun Config(navController: NavController, subId: Int) {
149180
true
150181
}
151182
}
152-
BooleanPropertyView(label = stringResource(R.string.enable_video_calling_vt), toggled = vtEnabled) {
153-
vtEnabled = if (vtEnabled) {
154-
moder.updateCarrierConfig(CarrierConfigManager.KEY_CARRIER_VT_AVAILABLE_BOOL, false)
155-
false
156-
} else {
157-
moder.updateCarrierConfig(CarrierConfigManager.KEY_CARRIER_VT_AVAILABLE_BOOL, true)
158-
moder.restartIMSRegistration()
159-
true
160-
}
161-
}
162183
BooleanPropertyView(label = stringResource(R.string.show_4g_for_lte_data_icon), toggled = show4GForLteEnabled) {
163184
show4GForLteEnabled = if (show4GForLteEnabled) {
164185
moder.updateCarrierConfig(CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL, false)
@@ -177,25 +198,6 @@ fun Config(navController: NavController, subId: Int) {
177198
true
178199
}
179200
}
180-
BooleanPropertyView(label = stringResource(R.string.enable_enhanced_4g_lte_lte_untested), toggled = is4GPlusEnabled) {
181-
is4GPlusEnabled = if (is4GPlusEnabled) {
182-
moder.updateCarrierConfig(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL, false)
183-
moder.updateCarrierConfig(CarrierConfigManager.KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL, false)
184-
moder.updateCarrierConfig(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL, true)
185-
false
186-
} else {
187-
moder.updateCarrierConfig(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL, true)
188-
moder.updateCarrierConfig(CarrierConfigManager.KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL, true)
189-
moder.updateCarrierConfig(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL, false)
190-
true
191-
}
192-
}
193-
194-
HeaderText(text = stringResource(R.string.string_values))
195-
StringPropertyView(label = stringResource(R.string.user_agent), value = configuredUserAgent) {
196-
moder.updateCarrierConfig(moder.KEY_IMS_USER_AGENT, it)
197-
configuredUserAgent = it
198-
}
199201

200202
HeaderText(text = stringResource(R.string.miscellaneous))
201203
ClickablePropertyView(

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<string name="show_vowifi_preference_in_settings">Show VoWiFi preference in Settings</string>
1717
<string name="show_vowifi_roaming_preference_in_settings">Show VoWiFi Roaming preference in Settings</string>
1818
<string name="add_wifi_calling_to_network_name">Add "Wi-Fi Calling" to Network Name</string>
19-
<string name="show_wifi_only_for_vowifi">Show "WiFi only" mode for VoWiFi</string>
19+
<string name="show_wifi_only_for_vowifi">Show \"WiFi only\" mode for VoWiFi</string>
2020
<string name="enable_video_calling_vt">Enable Video Calling (VT)</string>
2121
<string name="sim_detected">SIM Detected</string>
2222
<string name="volte_supported_by_device">VoLTE Supported by Device</string>
@@ -26,7 +26,8 @@
2626
<string name="registered">Registered</string>
2727
<string name="unregistered">Unregistered</string>
2828
<string name="newer_version_available">Newer version %1$s available!</string>
29-
<string name="toggles">Toggles</string>
29+
<string name="feature_toggles">Enable/Disable Feature</string>
30+
<string name="cosmetic_toggles">Cosmetic Toggles</string>
3031
<string name="show_4g_for_lte_data_icon">Show 4G for LTE Data Icon</string>
3132
<string name="hide_enhanced_data_icon">Hide Enhanced Data Icon</string>
3233
<string name="enable_enhanced_4g_lte_lte_untested">Enable Enhanced 4G LTE/LTE+ (Untested)</string>
@@ -37,4 +38,6 @@
3738
<string name="user_agent">User Agent</string>
3839
<string name="version">Version</string>
3940
<string name="update_value">Update Value</string>
41+
<string name="lgu">LG U+</string>
42+
<string name="default_">Default</string>
4043
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="ua_default">#MANUFACTURE#_#MODEL#_Android #AV#_#BUILD#</string>
4+
<string name="ua_lgu">TTA-VoLTE/3.0 GB17L/T1B1.220819.007 Device-Type/Android_Phone OMD</string>
5+
</resources>

0 commit comments

Comments
 (0)