From 59e29c2452eb8f5150760bbdffe4caa4639d33ca Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 8 Mar 2017 23:06:06 +0100 Subject: [PATCH] remove not existing files from internal db --- .../com/simplemobiletools/notes/helpers/DBHelper.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 a55732e1..284b04a5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/DBHelper.kt @@ -9,6 +9,7 @@ import com.simplemobiletools.commons.extensions.getIntValue import com.simplemobiletools.commons.extensions.getStringValue import com.simplemobiletools.notes.R import com.simplemobiletools.notes.models.Note +import java.io.File import java.util.* class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHelper(mContext, DB_NAME, null, DB_VERSION) { @@ -97,6 +98,11 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe val value = cursor.getStringValue(COL_VALUE) val type = cursor.getIntValue(COL_TYPE) val path = cursor.getStringValue(COL_PATH) ?: "" + if (path.isNotEmpty() && !File(path).exists()) { + deleteNote(id) + continue + } + val note = Note(id, title, value, type, path) notes.add(note) } catch (e: Exception) { @@ -142,6 +148,11 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe updateNote(note.id, values) } + fun updateNotePath(note: Note) { + val values = ContentValues().apply { put(COL_PATH, note.path) } + updateNote(note.id, values) + } + fun updateNote(id: Int, values: ContentValues) { val selection = "$COL_ID = ?" val selectionArgs = arrayOf(id.toString())