Skip to content

Commit e17d139

Browse files
committed
updating the dialogs
1 parent 0932fb3 commit e17d139

File tree

4 files changed

+25
-41
lines changed

4 files changed

+25
-41
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/dialogs/NewNoteDialog.kt

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
11
package com.simplemobiletools.notes.dialogs
22

33
import android.app.Activity
4-
import android.app.AlertDialog
5-
import android.view.WindowManager
4+
import android.support.v7.app.AlertDialog
5+
import com.simplemobiletools.commons.extensions.setupDialogStuff
66
import com.simplemobiletools.commons.extensions.toast
77
import com.simplemobiletools.commons.extensions.value
88
import com.simplemobiletools.notes.R
99
import com.simplemobiletools.notes.databases.DBHelper
1010
import kotlinx.android.synthetic.main.new_note.view.*
1111

1212
class NewNoteDialog(val activity: Activity, val db: DBHelper, callback: (title: String) -> Unit) {
13-
1413
init {
1514
val view = activity.layoutInflater.inflate(R.layout.new_note, null)
1615

17-
AlertDialog.Builder(activity).apply {
18-
setTitle(activity.resources.getString(R.string.new_note))
19-
setView(view)
20-
setPositiveButton(R.string.ok, null)
21-
setNegativeButton(R.string.cancel, null)
22-
create().apply {
23-
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
24-
show()
25-
getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE).setOnClickListener {
26-
val title = view.note_name.value
27-
if (title.isEmpty()) {
28-
activity.toast(R.string.no_title)
29-
} else if (db.doesTitleExist(title)) {
30-
activity.toast(R.string.title_taken)
31-
} else {
32-
callback.invoke(title)
33-
dismiss()
34-
}
16+
AlertDialog.Builder(activity)
17+
.setPositiveButton(R.string.ok, null)
18+
.setNegativeButton(R.string.cancel, null)
19+
.create().apply {
20+
activity.setupDialogStuff(view, this, R.string.new_note)
21+
getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE).setOnClickListener {
22+
val title = view.note_name.value
23+
if (title.isEmpty()) {
24+
activity.toast(R.string.no_title)
25+
} else if (db.doesTitleExist(title)) {
26+
activity.toast(R.string.title_taken)
27+
} else {
28+
callback.invoke(title)
29+
dismiss()
3530
}
3631
}
3732
}

app/src/main/kotlin/com/simplemobiletools/notes/dialogs/OpenNoteDialog.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.simplemobiletools.notes.dialogs
22

33
import android.app.Activity
4-
import android.app.AlertDialog
4+
import android.support.v7.app.AlertDialog
55
import android.view.ViewGroup
66
import android.widget.RadioButton
77
import android.widget.RadioGroup
8-
import com.simplemobiletools.notes.helpers.Config
8+
import com.simplemobiletools.commons.extensions.setupDialogStuff
99
import com.simplemobiletools.notes.R
1010
import com.simplemobiletools.notes.databases.DBHelper
11+
import com.simplemobiletools.notes.helpers.Config
1112
import kotlinx.android.synthetic.main.dialog_radio_group.view.*
1213

1314
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
3233
}
3334

3435
dialog = AlertDialog.Builder(activity)
35-
.setTitle(activity.resources.getString(R.string.pick_a_note))
36-
.setView(view)
37-
.create()
36+
.create().apply {
37+
activity.setupDialogStuff(view, this, R.string.pick_a_note)
38+
}
3839

39-
dialog!!.show()
4040
wasInit = true
4141
}
4242

app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.simplemobiletools.notes.dialogs
22

33
import android.app.Activity
4-
import android.app.AlertDialog
4+
import android.support.v7.app.AlertDialog
55
import android.view.LayoutInflater
6-
import android.view.WindowManager
6+
import com.simplemobiletools.commons.extensions.setupDialogStuff
77
import com.simplemobiletools.commons.extensions.toast
88
import com.simplemobiletools.commons.extensions.value
99
import com.simplemobiletools.notes.R
@@ -18,13 +18,10 @@ class RenameNoteDialog(val activity: Activity, val db: DBHelper, val note: Note,
1818
view.note_name.setText(note.title)
1919

2020
AlertDialog.Builder(activity)
21-
.setTitle(activity.resources.getString(R.string.rename_note))
22-
.setView(view)
2321
.setPositiveButton(R.string.ok, null)
2422
.setNegativeButton(R.string.cancel, null)
2523
.create().apply {
26-
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
27-
show()
24+
activity.setupDialogStuff(view, this, R.string.rename_note)
2825
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
2926
val title = view.note_name.value
3027
if (title.isEmpty()) {

app/src/main/res/layout/radio_button.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)