mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-04 08:07:32 +01:00
use some extension functions
This commit is contained in:
parent
4f81180977
commit
66d75b96b0
@ -16,6 +16,8 @@ import com.simplemobiletools.notes.Utils
|
|||||||
import com.simplemobiletools.notes.databases.DBHelper
|
import com.simplemobiletools.notes.databases.DBHelper
|
||||||
import com.simplemobiletools.notes.dialogs.OpenNoteDialog
|
import com.simplemobiletools.notes.dialogs.OpenNoteDialog
|
||||||
import com.simplemobiletools.notes.dialogs.WidgetNoteDialog
|
import com.simplemobiletools.notes.dialogs.WidgetNoteDialog
|
||||||
|
import com.simplemobiletools.notes.extensions.toast
|
||||||
|
import com.simplemobiletools.notes.extensions.value
|
||||||
import com.simplemobiletools.notes.models.Note
|
import com.simplemobiletools.notes.models.Note
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
|
||||||
@ -127,11 +129,11 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
|
|||||||
show()
|
show()
|
||||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||||
val titleET = newNoteView.findViewById(R.id.note_name) as EditText
|
val titleET = newNoteView.findViewById(R.id.note_name) as EditText
|
||||||
val title = titleET.text.toString().trim { it <= ' ' }
|
val title = titleET.value
|
||||||
if (title.isEmpty()) {
|
if (title.isEmpty()) {
|
||||||
Utils.showToast(applicationContext, R.string.no_title)
|
toast(R.string.no_title)
|
||||||
} else if (mDb.doesTitleExist(title)) {
|
} else if (mDb.doesTitleExist(title)) {
|
||||||
Utils.showToast(applicationContext, R.string.title_taken)
|
toast(R.string.title_taken)
|
||||||
} else {
|
} else {
|
||||||
saveText()
|
saveText()
|
||||||
val newNote = Note(0, title, "")
|
val newNote = Note(0, title, "")
|
||||||
@ -177,10 +179,10 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
|
|||||||
if (mCurrentNote == null)
|
if (mCurrentNote == null)
|
||||||
return
|
return
|
||||||
|
|
||||||
val newText = getCurrentNoteValue()
|
val newText = notes_view.value
|
||||||
val oldText = mCurrentNote!!.value
|
val oldText = mCurrentNote!!.value
|
||||||
if (newText != oldText) {
|
if (newText != oldText) {
|
||||||
Utils.showToast(applicationContext, R.string.note_saved)
|
toast(R.string.note_saved)
|
||||||
mCurrentNote!!.value = newText
|
mCurrentNote!!.value = newText
|
||||||
mDb.updateNote(mCurrentNote!!)
|
mDb.updateNote(mCurrentNote!!)
|
||||||
}
|
}
|
||||||
@ -190,9 +192,9 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun shareText() {
|
private fun shareText() {
|
||||||
val text = getCurrentNoteValue()
|
val text = notes_view.value
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
Utils.showToast(applicationContext, R.string.cannot_share_empty_text)
|
toast(R.string.cannot_share_empty_text)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,16 +209,10 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentNoteValue(): String {
|
|
||||||
return notes_view.text.toString().trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun hideKeyboard() {
|
private fun hideKeyboard() {
|
||||||
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
imm.hideSoftInputFromWindow(notes_view.windowToken, 0)
|
imm.hideSoftInputFromWindow(notes_view.windowToken, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun noteSelected(id: Int) {
|
override fun noteSelected(id: Int) = updateSelectedNote(id)
|
||||||
updateSelectedNote(id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.simplemobiletools.notes.extensions
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.widget.Toast
|
||||||
|
|
||||||
|
fun Context.toast(id: Int) = Toast.makeText(this, id, Toast.LENGTH_SHORT).show()
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.simplemobiletools.notes.extensions
|
||||||
|
|
||||||
|
import android.widget.EditText
|
||||||
|
|
||||||
|
val EditText.value: String get() = text.toString().trim()
|
Loading…
x
Reference in New Issue
Block a user