parent
9a91c72d1e
commit
ea6f54cd73
@ -0,0 +1,23 @@
|
||||
package dev.lowrespalmtree.comet
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import dev.lowrespalmtree.comet.databinding.DialogInputBinding
|
||||
|
||||
/** Generic text input dialog. Used for code 10 and a few other simple text input. */
|
||||
class InputDialog(
|
||||
private val context: Context,
|
||||
private val prompt: String
|
||||
) {
|
||||
fun show(onOk: (text: String) -> Unit, onDismiss: () -> Unit) {
|
||||
val binding = DialogInputBinding.inflate(LayoutInflater.from(context))
|
||||
AlertDialog.Builder(context)
|
||||
.setMessage(prompt)
|
||||
.setView(binding.root)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ -> onOk(binding.textInput.text.toString()) }
|
||||
.setOnDismissListener { onDismiss() }
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/text_input"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:inputType="text" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in new issue