Skip to content

Commit 85690ec

Browse files
committed
don't force switching to heliboard when opening settings
1 parent 8f85c6b commit 85690ec

1 file changed

Lines changed: 82 additions & 57 deletions

File tree

app/src/main/java/helium314/keyboard/settings/WelcomeWizard.kt

Lines changed: 82 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.foundation.clickable
1313
import androidx.compose.foundation.layout.Arrangement
1414
import androidx.compose.foundation.layout.Box
1515
import androidx.compose.foundation.layout.Column
16+
import androidx.compose.foundation.layout.ColumnScope
1617
import androidx.compose.foundation.layout.Row
1718
import androidx.compose.foundation.layout.Spacer
1819
import androidx.compose.foundation.layout.fillMaxSize
@@ -99,78 +100,85 @@ fun WelcomeWizard(
99100
)
100101
}
101102
}
103+
@Composable
104+
fun ColumnScope.Step(step: Int, title: String, instruction: String, actionText: String, icon: Painter, action: () -> Unit) {
105+
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
106+
Text("1", color = if (step == 1) titleColor else textColorDim)
107+
Text("2", color = if (step == 2) titleColor else textColorDim)
108+
Text("3", color = if (step == 3) titleColor else textColorDim)
109+
}
110+
Column(Modifier
111+
.background(color = stepBackgroundColor)
112+
.padding(16.dp)
113+
) {
114+
Text(title)
115+
Text(instruction, style = MaterialTheme.typography.bodyLarge.merge(color = textColor))
116+
}
117+
Spacer(Modifier.height(4.dp))
118+
Row(
119+
Modifier.clickable { action() }
120+
.background(color = stepBackgroundColor)
121+
.padding(16.dp),
122+
verticalAlignment = Alignment.CenterVertically
123+
) {
124+
Icon(icon, null, Modifier.padding(end = 6.dp).size(32.dp), tint = textColor)
125+
Text(actionText, Modifier.weight(1f))
126+
}
127+
}
102128
@Composable fun steps() {
103129
if (step == 0)
104-
Column(horizontalAlignment = Alignment.CenterHorizontally) {
105-
Image(painterResource(R.drawable.setup_welcome_image), null)
106-
Row(Modifier.clickable { step = 1 }
107-
.padding(top = 4.dp, start = 4.dp, end = 4.dp)
108-
//.background(color = MaterialTheme.colorScheme.primary)
109-
) {
110-
Spacer(Modifier.weight(1f))
111-
Text(
112-
stringResource(R.string.setup_start_action),
113-
modifier = Modifier.padding(horizontal = 16.dp)
114-
)
115-
}
116-
}
130+
Step0 { step = 1 }
117131
else
118132
Column {
119-
val title: String
120-
val instruction: String
121-
val icon: Painter
122-
val actionText: String
123-
val action: () -> Unit
124133
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
125134
step = determineStep()
126135
}
127136
if (step == 1) {
128-
title = stringResource(R.string.setup_step1_title, appName)
129-
instruction = stringResource(R.string.setup_step1_instruction, appName)
130-
icon = painterResource(R.drawable.ic_setup_key)
131-
actionText = stringResource(R.string.setup_step1_action)
132-
action = {
137+
Step(
138+
step,
139+
stringResource(R.string.setup_step1_title, appName),
140+
stringResource(R.string.setup_step1_instruction, appName),
141+
stringResource(R.string.setup_step1_action),
142+
painterResource(R.drawable.ic_setup_key)
143+
) {
133144
val intent = Intent()
134145
intent.action = Settings.ACTION_INPUT_METHOD_SETTINGS
135146
intent.addCategory(Intent.CATEGORY_DEFAULT)
136147
launcher.launch(intent)
137148
}
138149
} else if (step == 2) {
139-
title = stringResource(R.string.setup_step2_title, appName)
140-
instruction = stringResource(R.string.setup_step2_instruction, appName)
141-
icon = painterResource(R.drawable.ic_setup_select)
142-
actionText = stringResource(R.string.setup_step2_action)
143-
action = imm::showInputMethodPicker
150+
Step(
151+
step,
152+
stringResource(R.string.setup_step2_title, appName),
153+
stringResource(R.string.setup_step2_instruction, appName),
154+
stringResource(R.string.setup_step2_action),
155+
painterResource(R.drawable.ic_setup_select),
156+
imm::showInputMethodPicker
157+
)
158+
Spacer(Modifier.height(4.dp))
159+
Row(
160+
Modifier.clickable { close() }
161+
.background(color = stepBackgroundColor)
162+
.padding(16.dp),
163+
verticalAlignment = Alignment.CenterVertically
164+
) {
165+
Icon(
166+
painterResource(R.drawable.sym_keyboard_language_switch),
167+
null,
168+
Modifier.padding(end = 6.dp).size(32.dp),
169+
tint = textColor
170+
)
171+
Text(stringResource(R.string.setup_step3_action), Modifier.weight(1f))
172+
}
144173
} else { // step 3
145-
title = stringResource(R.string.setup_step3_title)
146-
instruction = stringResource(R.string.setup_step3_instruction, appName)
147-
icon = painterResource(R.drawable.sym_keyboard_language_switch)
148-
actionText = stringResource(R.string.setup_step3_action)
149-
action = close
150-
}
151-
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
152-
Text("1", color = if (step == 1) titleColor else textColorDim)
153-
Text("2", color = if (step == 2) titleColor else textColorDim)
154-
Text("3", color = if (step == 3) titleColor else textColorDim)
155-
}
156-
Column(Modifier
157-
.background(color = stepBackgroundColor)
158-
.padding(16.dp)
159-
) {
160-
Text(title)
161-
Text(instruction, style = MaterialTheme.typography.bodyLarge.merge(color = textColor))
162-
}
163-
Spacer(Modifier.height(4.dp))
164-
Row(
165-
Modifier.clickable { action() }
166-
.background(color = stepBackgroundColor)
167-
.padding(16.dp),
168-
verticalAlignment = Alignment.CenterVertically
169-
) {
170-
Icon(icon, null, Modifier.padding(end = 6.dp).size(32.dp), tint = textColor)
171-
Text(actionText, Modifier.weight(1f))
172-
}
173-
if (step == 3) {
174+
Step(
175+
step,
176+
stringResource(R.string.setup_step3_title),
177+
stringResource(R.string.setup_step3_instruction, appName),
178+
stringResource(R.string.setup_step3_action),
179+
painterResource(R.drawable.sym_keyboard_language_switch),
180+
close
181+
)
174182
Spacer(Modifier.height(4.dp))
175183
Row(
176184
Modifier.clickable { finish() }
@@ -217,6 +225,23 @@ fun WelcomeWizard(
217225
}
218226
}
219227

228+
@Composable
229+
fun Step0(onClick: () -> Unit) {
230+
Column(horizontalAlignment = Alignment.CenterHorizontally) {
231+
Image(painterResource(R.drawable.setup_welcome_image), null)
232+
Row(Modifier.clickable { onClick() }
233+
.padding(top = 4.dp, start = 4.dp, end = 4.dp)
234+
//.background(color = MaterialTheme.colorScheme.primary)
235+
) {
236+
Spacer(Modifier.weight(1f))
237+
Text(
238+
stringResource(R.string.setup_start_action),
239+
modifier = Modifier.padding(horizontal = 16.dp)
240+
)
241+
}
242+
}
243+
}
244+
220245
@Preview
221246
@Composable
222247
private fun Preview() {

0 commit comments

Comments
 (0)