mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-16 08:30:05 +01:00
remove not existing files from internal db
This commit is contained in:
parent
ae4e811ab7
commit
59e29c2452
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user