diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/NewNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/NewNoteDialog.kt index 7a85c1fa..732b9e6b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/NewNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/NewNoteDialog.kt @@ -1,8 +1,8 @@ package com.simplemobiletools.notes.dialogs import android.app.Activity -import android.app.AlertDialog -import android.view.WindowManager +import android.support.v7.app.AlertDialog +import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.value import com.simplemobiletools.notes.R @@ -10,28 +10,23 @@ import com.simplemobiletools.notes.databases.DBHelper import kotlinx.android.synthetic.main.new_note.view.* class NewNoteDialog(val activity: Activity, val db: DBHelper, callback: (title: String) -> Unit) { - init { val view = activity.layoutInflater.inflate(R.layout.new_note, null) - AlertDialog.Builder(activity).apply { - setTitle(activity.resources.getString(R.string.new_note)) - setView(view) - setPositiveButton(R.string.ok, null) - setNegativeButton(R.string.cancel, null) - create().apply { - window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - show() - getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val title = view.note_name.value - if (title.isEmpty()) { - activity.toast(R.string.no_title) - } else if (db.doesTitleExist(title)) { - activity.toast(R.string.title_taken) - } else { - callback.invoke(title) - dismiss() - } + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this, R.string.new_note) + getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val title = view.note_name.value + if (title.isEmpty()) { + activity.toast(R.string.no_title) + } else if (db.doesTitleExist(title)) { + activity.toast(R.string.title_taken) + } else { + callback.invoke(title) + dismiss() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenNoteDialog.kt index 024fe329..4dd00939 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenNoteDialog.kt @@ -1,13 +1,14 @@ package com.simplemobiletools.notes.dialogs import android.app.Activity -import android.app.AlertDialog +import android.support.v7.app.AlertDialog import android.view.ViewGroup import android.widget.RadioButton import android.widget.RadioGroup -import com.simplemobiletools.notes.helpers.Config +import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.notes.R import com.simplemobiletools.notes.databases.DBHelper +import com.simplemobiletools.notes.helpers.Config import kotlinx.android.synthetic.main.dialog_radio_group.view.* class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> Unit) : RadioGroup.OnCheckedChangeListener { @@ -32,11 +33,10 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> U } dialog = AlertDialog.Builder(activity) - .setTitle(activity.resources.getString(R.string.pick_a_note)) - .setView(view) - .create() + .create().apply { + activity.setupDialogStuff(view, this, R.string.pick_a_note) + } - dialog!!.show() wasInit = true } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt index 73aeeff1..e304a383 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt @@ -1,9 +1,9 @@ package com.simplemobiletools.notes.dialogs import android.app.Activity -import android.app.AlertDialog +import android.support.v7.app.AlertDialog import android.view.LayoutInflater -import android.view.WindowManager +import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.value import com.simplemobiletools.notes.R @@ -18,13 +18,10 @@ class RenameNoteDialog(val activity: Activity, val db: DBHelper, val note: Note, view.note_name.setText(note.title) AlertDialog.Builder(activity) - .setTitle(activity.resources.getString(R.string.rename_note)) - .setView(view) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .create().apply { - window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - show() + activity.setupDialogStuff(view, this, R.string.rename_note) getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ val title = view.note_name.value if (title.isEmpty()) { diff --git a/app/src/main/res/layout/radio_button.xml b/app/src/main/res/layout/radio_button.xml deleted file mode 100644 index a00b06c8..00000000 --- a/app/src/main/res/layout/radio_button.xml +++ /dev/null @@ -1,8 +0,0 @@ - -