From f00ae5de189b9140f64ceb6c75dff1304ecd9766 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 17 May 2018 11:39:49 +0200 Subject: [PATCH] add correct note title to all notes at importing a folder --- .../notes/dialogs/ImportFolderDialog.kt | 14 +++++++------- .../simplemobiletools/notes/helpers/DBHelper.kt | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ImportFolderDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ImportFolderDialog.kt index ae9a007b..76b240cc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ImportFolderDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ImportFolderDialog.kt @@ -48,15 +48,16 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal else -> true } }.forEach { - val storePath = if (updateFilesOnEdit) it.path else "" - val storeContent = if (updateFilesOnEdit) "" else it.readText() + val storePath = if (updateFilesOnEdit) it.absolutePath else "" + val title = it.absolutePath.getFilenameFromPath() + val value = if (updateFilesOnEdit) "" else it.readText() if (updateFilesOnEdit) { activity.handleSAFDialog(path) { - lastSavedNoteId = saveNote(storeContent, storePath) + lastSavedNoteId = saveNote(title, value, storePath) } } else { - lastSavedNoteId = saveNote(storeContent, storePath) + lastSavedNoteId = saveNote(title, value, storePath) } } @@ -67,9 +68,8 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal dialog.dismiss() } - private fun saveNote(storeContent: String, storePath: String): Int { - val filename = storePath.getFilenameFromPath() - val note = Note(0, filename, storeContent, TYPE_NOTE, storePath) + private fun saveNote(title: String, value: String, path: String): Int { + val note = Note(0, title, value, TYPE_NOTE, path) return activity.dbHelper.insertNote(note) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/DBHelper.kt index 8b622407..e1a64795 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/DBHelper.kt @@ -4,6 +4,7 @@ import android.content.ContentValues import android.content.Context import android.database.Cursor import android.database.sqlite.SQLiteDatabase +import android.database.sqlite.SQLiteDatabase.CONFLICT_IGNORE import android.database.sqlite.SQLiteOpenHelper import com.simplemobiletools.commons.extensions.getIntValue import com.simplemobiletools.commons.extensions.getStringValue @@ -57,7 +58,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe fun insertNote(note: Note): Int { val values = fillContentValues(note) - return mDb.insert(TABLE_NAME, null, values).toInt() + return mDb.insertWithOnConflict(TABLE_NAME, null, values, CONFLICT_IGNORE).toInt() } private fun fillContentValues(note: Note): ContentValues {