Skip to content

Commit aaa9e3f

Browse files
committed
Select the prefilled text by default in SimpleInputDialog
1 parent f881884 commit aaa9e3f

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

app-timer-list/src/main/java/xyz/aprildown/timer/app/timer/list/FolderToolbar.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ internal class FolderToolbar(
4141
cardElevation = context.dimen(R.dimen.elevation_timer_card).toFloat()
4242
binding = ViewFolderToolbarBinding.inflate(LayoutInflater.from(context), this)
4343

44-
fun requestFolderName(f: (String) -> Unit) {
45-
SimpleInputDialog(context).show(titleRes = RBase.string.folder_name) {
44+
fun requestFolderName(
45+
prefill: String? = null,
46+
f: (String) -> Unit,
47+
) {
48+
SimpleInputDialog(context).show(
49+
titleRes = RBase.string.folder_name,
50+
preFill = prefill,
51+
) {
4652
if (it.isNotBlank()) {
4753
f.invoke(it)
4854
}
@@ -124,7 +130,10 @@ internal class FolderToolbar(
124130
item {
125131
labelRes = RBase.string.folder_rename
126132
callback = {
127-
requestFolderName {
133+
requestFolderName(
134+
prefill = binding.textFolderToolbarCurrent.text.toString()
135+
.takeIf { it.isNotBlank() },
136+
) {
128137
this@FolderToolbar.callback?.onChangeCurrentFolderName(it)
129138
}
130139
}

app-timer-one/src/main/java/xyz/aprildown/timer/app/timer/one/BaseOneFragment.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import xyz.aprildown.timer.presentation.one.OneViewModel
3939
import xyz.aprildown.timer.presentation.stream.MachineContract
4040
import xyz.aprildown.timer.presentation.stream.StreamState
4141
import xyz.aprildown.timer.presentation.stream.TimerIndex
42+
import xyz.aprildown.timer.presentation.stream.getLoop
4243
import xyz.aprildown.timer.presentation.stream.getStep
4344
import javax.inject.Inject
4445
import javax.inject.Provider
@@ -245,7 +246,9 @@ abstract class BaseOneFragment<T : ViewBinding>(
245246
protected fun showPickLoopDialog(maxLoop: Int, onPick: (Int) -> Unit) {
246247
SimpleInputDialog(requireContext()).show(
247248
inputType = InputType.TYPE_CLASS_NUMBER,
248-
hint = getString(RBase.string.name_loop_loop_hint)
249+
preFill = viewModel.timerCurrentIndex.value
250+
?.getLoop(viewModel.timer.value?.loop ?: 0)?.toString(),
251+
hint = getString(RBase.string.name_loop_loop_hint),
249252
) { input ->
250253
input.toIntOrNull()
251254
?.takeIf { it in 1..maxLoop }

component-key/src/main/java/xyz/aprildown/timer/component/key/SimpleInputDialog.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import androidx.core.view.updateLayoutParams
1414
import com.github.deweyreed.tools.anko.dp
1515
import com.github.deweyreed.tools.helper.gone
1616
import com.github.deweyreed.tools.helper.onImeActionClick
17-
import com.github.deweyreed.tools.helper.setTextAndSelectEnd
1817
import com.google.android.material.dialog.MaterialAlertDialogBuilder
1918
import xyz.aprildown.timer.app.base.R as RBase
2019

@@ -71,7 +70,8 @@ class SimpleInputDialog(
7170
}
7271

7372
if (!preFill.isNullOrBlank()) {
74-
edit.setTextAndSelectEnd(preFill)
73+
edit.setText(preFill)
74+
edit.post { edit.selectAll() }
7575
}
7676
if (hint != null) {
7777
edit.hint = hint

presentation/src/main/java/xyz/aprildown/timer/presentation/stream/TimerIndex.kt

+12-12
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ fun Intent.putTimerIndex(index: TimerIndex?): Intent = apply {
7373
}
7474
}
7575

76-
fun TimerIndex?.getNiceLoopString(max: Int = 1): String =
77-
"%d/%d".format(
78-
this?.let {
79-
when (it) {
80-
is TimerIndex.Start -> 1
81-
is TimerIndex.Step -> it.loopIndex + 1
82-
is TimerIndex.Group -> it.loopIndex + 1
83-
is TimerIndex.End -> max
84-
}
85-
} ?: 0,
86-
max
87-
)
76+
fun TimerIndex?.getNiceLoopString(max: Int = 1): String {
77+
return "%d/%d".format(this?.getLoop(max) ?: 0, max)
78+
}
79+
80+
fun TimerIndex.getLoop(max: Int): Int {
81+
return when (this) {
82+
is TimerIndex.Start -> 1
83+
is TimerIndex.Step -> loopIndex + 1
84+
is TimerIndex.Group -> loopIndex + 1
85+
is TimerIndex.End -> max
86+
}
87+
}

0 commit comments

Comments
 (0)