@@ -16,6 +16,8 @@ import com.simplemobiletools.notes.Utils
16
16
import com.simplemobiletools.notes.databases.DBHelper
17
17
import com.simplemobiletools.notes.dialogs.OpenNoteDialog
18
18
import com.simplemobiletools.notes.dialogs.WidgetNoteDialog
19
+ import com.simplemobiletools.notes.extensions.toast
20
+ import com.simplemobiletools.notes.extensions.value
19
21
import com.simplemobiletools.notes.models.Note
20
22
import kotlinx.android.synthetic.main.activity_main.*
21
23
@@ -127,11 +129,11 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
127
129
show()
128
130
getButton(AlertDialog .BUTTON_POSITIVE ).setOnClickListener {
129
131
val titleET = newNoteView.findViewById(R .id.note_name) as EditText
130
- val title = titleET.text.toString().trim { it <= ' ' }
132
+ val title = titleET.value
131
133
if (title.isEmpty()) {
132
- Utils .showToast(applicationContext, R .string.no_title)
134
+ toast( R .string.no_title)
133
135
} else if (mDb.doesTitleExist(title)) {
134
- Utils .showToast(applicationContext, R .string.title_taken)
136
+ toast( R .string.title_taken)
135
137
} else {
136
138
saveText()
137
139
val newNote = Note (0 , title, " " )
@@ -177,10 +179,10 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
177
179
if (mCurrentNote == null )
178
180
return
179
181
180
- val newText = getCurrentNoteValue()
182
+ val newText = notes_view.value
181
183
val oldText = mCurrentNote!! .value
182
184
if (newText != oldText) {
183
- Utils .showToast(applicationContext, R .string.note_saved)
185
+ toast( R .string.note_saved)
184
186
mCurrentNote!! .value = newText
185
187
mDb.updateNote(mCurrentNote!! )
186
188
}
@@ -190,9 +192,9 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
190
192
}
191
193
192
194
private fun shareText () {
193
- val text = getCurrentNoteValue()
195
+ val text = notes_view.value
194
196
if (text.isEmpty()) {
195
- Utils .showToast(applicationContext, R .string.cannot_share_empty_text)
197
+ toast( R .string.cannot_share_empty_text)
196
198
return
197
199
}
198
200
@@ -207,16 +209,10 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
207
209
}
208
210
}
209
211
210
- private fun getCurrentNoteValue (): String {
211
- return notes_view.text.toString().trim()
212
- }
213
-
214
212
private fun hideKeyboard () {
215
213
val imm = getSystemService(Context .INPUT_METHOD_SERVICE ) as InputMethodManager
216
214
imm.hideSoftInputFromWindow(notes_view.windowToken, 0 )
217
215
}
218
216
219
- override fun noteSelected (id : Int ) {
220
- updateSelectedNote(id)
221
- }
217
+ override fun noteSelected (id : Int ) = updateSelectedNote(id)
222
218
}
0 commit comments