mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-13 15:02:05 +02:00
use one shared function for updating note title, value, path
This commit is contained in:
parent
2fc3d8cba9
commit
f26ea25a1e
@ -445,12 +445,12 @@ class MainActivity : SimpleActivity() {
|
||||
exportNoteValueToFile(exportPath, currentNoteText, true) {
|
||||
if (syncFile) {
|
||||
mCurrentNote.path = exportPath
|
||||
dbHelper.updateNotePath(mCurrentNote)
|
||||
|
||||
if (mCurrentNote.getNoteStoredValue() == currentNoteText) {
|
||||
mCurrentNote.value = ""
|
||||
dbHelper.updateNoteValue(mCurrentNote)
|
||||
}
|
||||
|
||||
dbHelper.updateNote(mCurrentNote)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,9 @@ class RenameNoteDialog(val activity: SimpleActivity, val note: Note, callback: (
|
||||
else -> {
|
||||
note.title = title
|
||||
val path = note.path
|
||||
if (path.isNotEmpty()) {
|
||||
if (path.isEmpty()) {
|
||||
activity.dbHelper.updateNote(note)
|
||||
} else {
|
||||
if (title.isEmpty()) {
|
||||
activity.toast(R.string.filename_cannot_be_empty)
|
||||
return@setOnClickListener
|
||||
@ -46,14 +48,14 @@ class RenameNoteDialog(val activity: SimpleActivity, val note: Note, callback: (
|
||||
activity.renameFile(file.absolutePath, newFile.absolutePath) {
|
||||
if (it) {
|
||||
note.path = newFile.absolutePath
|
||||
activity.dbHelper.updateNotePath(note)
|
||||
activity.dbHelper.updateNote(note)
|
||||
} else {
|
||||
activity.toast(R.string.rename_file_error)
|
||||
return@renameFile
|
||||
}
|
||||
}
|
||||
}
|
||||
activity.dbHelper.updateNoteTitle(note)
|
||||
|
||||
dismiss()
|
||||
callback(note)
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ class NoteFragment : androidx.fragment.app.Fragment() {
|
||||
|
||||
private fun saveNoteValue(note: Note) {
|
||||
if (note.path.isEmpty()) {
|
||||
db.updateNoteValue(note)
|
||||
db.updateNote(note)
|
||||
(activity as MainActivity).noteSavedSuccessfully(note.title)
|
||||
} else {
|
||||
val currentText = getCurrentNoteViewText()
|
||||
|
@ -69,7 +69,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
||||
put(COL_TITLE, note.title)
|
||||
put(COL_VALUE, note.value)
|
||||
put(COL_PATH, note.path)
|
||||
put(COL_TYPE, 0)
|
||||
put(COL_TYPE, TYPE_NOTE)
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,24 +168,10 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
||||
return 0
|
||||
}
|
||||
|
||||
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 updateNotePath(note: Note) {
|
||||
val values = ContentValues().apply { put(COL_PATH, note.path) }
|
||||
updateNote(note.id!!, values)
|
||||
}
|
||||
|
||||
private fun updateNote(id: Int, values: ContentValues) {
|
||||
fun updateNote(note: Note) {
|
||||
val values = fillNoteContentValues(note)
|
||||
val selection = "$COL_ID = ?"
|
||||
val selectionArgs = arrayOf(id.toString())
|
||||
val selectionArgs = arrayOf(note.id.toString())
|
||||
mDb.update(NOTES_TABLE_NAME, values, selection, selectionArgs)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user