aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/dialog/EditTextDialogFragment.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/view/dialog/EditTextDialogFragment.kt')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/dialog/EditTextDialogFragment.kt81
1 files changed, 81 insertions, 0 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/EditTextDialogFragment.kt b/app/src/main/java/net/lacolaco/smileessence/view/dialog/EditTextDialogFragment.kt
new file mode 100644
index 00000000..399b84ad
--- /dev/null
+++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/EditTextDialogFragment.kt
@@ -0,0 +1,81 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2012-2014 lacolaco.net
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.lacolaco.smileessence.view.dialog
+
+import android.app.AlertDialog
+import android.app.Dialog
+import android.app.DialogFragment
+import android.os.Bundle
+import android.view.View
+import android.widget.EditText
+import net.lacolaco.smileessence.R
+
+abstract class EditTextDialogFragment : DialogFragment() {
+ private lateinit var title: String
+ private lateinit var text: String
+
+ // ------------------------ OVERRIDE METHODS ------------------------
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ val args = arguments
+ text = args.getString(textKey)
+ title = args.getString(titleKey)
+ }
+
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ val view = activity.layoutInflater.inflate(R.layout.part_edittext, null)
+ val editText = view.findViewById(R.id.part_edittext) as EditText
+ editText.setText(text)
+ return AlertDialog.Builder(activity)
+ .setTitle(title)
+ .setView(view)
+ .setPositiveButton(R.string.alert_dialog_ok) { dialog, which ->
+ onTextInput(editText.text.toString())
+ dialog.dismiss()
+ }
+ .setNegativeButton(R.string.alert_dialog_cancel) { dialog, which -> dialog.dismiss() }
+ .create()
+ }
+
+ // -------------------------- OTHER METHODS --------------------------
+
+ abstract fun onTextInput(text: String)
+
+ fun setParams(title: String, text: String) {
+ val args = Bundle()
+ args.putString(titleKey, title)
+ args.putString(textKey, text)
+ arguments = args
+ }
+
+ companion object {
+
+ // ------------------------------ FIELDS ------------------------------
+
+ private val titleKey = "title"
+ private val textKey = "text"
+ }
+}