store the note value in db only if its not linked to a file

This commit is contained in:
tibbi
2017-03-08 21:49:45 +01:00
parent c0617d518a
commit 6585cf0b2f
11 changed files with 29 additions and 17 deletions

View File

@ -30,7 +30,7 @@ class NotesPagerAdapter(fm: FragmentManager, private val notes: List<Note>) : Fr
override fun getPageTitle(position: Int) = notes[position].title
fun getCurrentNoteText(position: Int) = fragments[position].getCurrentNoteText()
fun getCurrentNoteText(position: Int) = fragments[position].getCurrentNoteViewText()
fun showKeyboard(position: Int) = fragments[position]?.showKeyboard()
}

View File

@ -56,16 +56,14 @@ class NoteFragment : Fragment() {
return view
}
fun getCurrentNoteText() = view.notes_view.text.toString()
fun saveText() {
val newText = getCurrentNoteText()
val oldText = note.value
val newText = getCurrentNoteViewText()
val oldText = getNoteStoredValue()
if (newText != oldText) {
note.value = newText
mDb.updateNoteValue(note)
context.updateWidget()
saveNoteValue(note)
}
context.updateWidget()
}
fun showKeyboard() {
@ -74,12 +72,26 @@ class NoteFragment : Fragment() {
imm.showSoftInput(view.notes_view, InputMethodManager.SHOW_IMPLICIT)
}
private fun saveNoteValue(note: Note) {
if (note.path.isEmpty()) {
mDb.updateNoteValue(note)
} else {
}
}
fun getCurrentNoteViewText() = view.notes_view.text.toString()
private fun getNoteStoredValue(): String {
return note.value
}
override fun onResume() {
super.onResume()
val config = context.config
view.notes_view.apply {
setText(note.value)
setText(getNoteStoredValue())
setColors(config.textColor, config.primaryColor, config.backgroundColor)
setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getTextSize())
gravity = context.getTextGravity()