fix #69, weird behaviour at renaming note

This commit is contained in:
tibbi 2017-03-06 22:07:24 +01:00
parent a05056c9f9
commit 79285a197c
3 changed files with 14 additions and 5 deletions

View File

@ -32,7 +32,7 @@ class RenameNoteDialog(val activity: Activity, val db: DBHelper, val note: Note,
activity.toast(R.string.title_taken)
} else {
note.title = title
db.updateNote(note)
db.updateNoteTitle(note)
dismiss()
callback.invoke(note)
}

View File

@ -62,7 +62,7 @@ class NoteFragment : Fragment() {
val oldText = note.value
if (newText != oldText) {
note.value = newText
mDb.updateNote(note)
mDb.updateNoteValue(note)
context.updateWidget()
}
}

View File

@ -125,10 +125,19 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
return note
}
fun updateNote(note: Note) {
val values = fillContentValues(note)
fun updateNoteValue(note: Note) {
val values = ContentValues().apply { put(COL_VALUE, note.value) }
updateNote(note.id, values)
}
fun updateNoteTitle(note: Note) {
val values = ContentValues().apply { put(COL_TITLE, note.title) }
updateNote(note.id, values)
}
fun updateNote(id: Int, values: ContentValues) {
val selection = "$COL_ID = ?"
val selectionArgs = arrayOf(note.id.toString())
val selectionArgs = arrayOf(id.toString())
mDb.update(TABLE_NAME, values, selection, selectionArgs)
}
}