@@ -16,6 +16,8 @@ import com.simplemobiletools.notes.Utils
1616import com.simplemobiletools.notes.databases.DBHelper
1717import com.simplemobiletools.notes.dialogs.OpenNoteDialog
1818import com.simplemobiletools.notes.dialogs.WidgetNoteDialog
19+ import com.simplemobiletools.notes.extensions.toast
20+ import com.simplemobiletools.notes.extensions.value
1921import com.simplemobiletools.notes.models.Note
2022import kotlinx.android.synthetic.main.activity_main.*
2123
@@ -127,11 +129,11 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
127129 show()
128130 getButton(AlertDialog .BUTTON_POSITIVE ).setOnClickListener {
129131 val titleET = newNoteView.findViewById(R .id.note_name) as EditText
130- val title = titleET.text.toString().trim { it <= ' ' }
132+ val title = titleET.value
131133 if (title.isEmpty()) {
132- Utils .showToast(applicationContext, R .string.no_title)
134+ toast( R .string.no_title)
133135 } else if (mDb.doesTitleExist(title)) {
134- Utils .showToast(applicationContext, R .string.title_taken)
136+ toast( R .string.title_taken)
135137 } else {
136138 saveText()
137139 val newNote = Note (0 , title, " " )
@@ -177,10 +179,10 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
177179 if (mCurrentNote == null )
178180 return
179181
180- val newText = getCurrentNoteValue()
182+ val newText = notes_view.value
181183 val oldText = mCurrentNote!! .value
182184 if (newText != oldText) {
183- Utils .showToast(applicationContext, R .string.note_saved)
185+ toast( R .string.note_saved)
184186 mCurrentNote!! .value = newText
185187 mDb.updateNote(mCurrentNote!! )
186188 }
@@ -190,9 +192,9 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
190192 }
191193
192194 private fun shareText () {
193- val text = getCurrentNoteValue()
195+ val text = notes_view.value
194196 if (text.isEmpty()) {
195- Utils .showToast(applicationContext, R .string.cannot_share_empty_text)
197+ toast( R .string.cannot_share_empty_text)
196198 return
197199 }
198200
@@ -207,16 +209,10 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
207209 }
208210 }
209211
210- private fun getCurrentNoteValue (): String {
211- return notes_view.text.toString().trim()
212- }
213-
214212 private fun hideKeyboard () {
215213 val imm = getSystemService(Context .INPUT_METHOD_SERVICE ) as InputMethodManager
216214 imm.hideSoftInputFromWindow(notes_view.windowToken, 0 )
217215 }
218216
219- override fun noteSelected (id : Int ) {
220- updateSelectedNote(id)
221- }
217+ override fun noteSelected (id : Int ) = updateSelectedNote(id)
222218}
0 commit comments