Skip to content

Commit f00ae5d

Browse files
committed
add correct note title to all notes at importing a folder
1 parent e5dba29 commit f00ae5d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ImportFolderDialog.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
4848
else -> true
4949
}
5050
}.forEach {
51-
val storePath = if (updateFilesOnEdit) it.path else ""
52-
val storeContent = if (updateFilesOnEdit) "" else it.readText()
51+
val storePath = if (updateFilesOnEdit) it.absolutePath else ""
52+
val title = it.absolutePath.getFilenameFromPath()
53+
val value = if (updateFilesOnEdit) "" else it.readText()
5354

5455
if (updateFilesOnEdit) {
5556
activity.handleSAFDialog(path) {
56-
lastSavedNoteId = saveNote(storeContent, storePath)
57+
lastSavedNoteId = saveNote(title, value, storePath)
5758
}
5859
} else {
59-
lastSavedNoteId = saveNote(storeContent, storePath)
60+
lastSavedNoteId = saveNote(title, value, storePath)
6061
}
6162
}
6263

@@ -67,9 +68,8 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
6768
dialog.dismiss()
6869
}
6970

70-
private fun saveNote(storeContent: String, storePath: String): Int {
71-
val filename = storePath.getFilenameFromPath()
72-
val note = Note(0, filename, storeContent, TYPE_NOTE, storePath)
71+
private fun saveNote(title: String, value: String, path: String): Int {
72+
val note = Note(0, title, value, TYPE_NOTE, path)
7373
return activity.dbHelper.insertNote(note)
7474
}
7575
}

app/src/main/kotlin/com/simplemobiletools/notes/helpers/DBHelper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.ContentValues
44
import android.content.Context
55
import android.database.Cursor
66
import android.database.sqlite.SQLiteDatabase
7+
import android.database.sqlite.SQLiteDatabase.CONFLICT_IGNORE
78
import android.database.sqlite.SQLiteOpenHelper
89
import com.simplemobiletools.commons.extensions.getIntValue
910
import com.simplemobiletools.commons.extensions.getStringValue
@@ -57,7 +58,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
5758

5859
fun insertNote(note: Note): Int {
5960
val values = fillContentValues(note)
60-
return mDb.insert(TABLE_NAME, null, values).toInt()
61+
return mDb.insertWithOnConflict(TABLE_NAME, null, values, CONFLICT_IGNORE).toInt()
6162
}
6263

6364
private fun fillContentValues(note: Note): ContentValues {

0 commit comments

Comments
 (0)