moving more db related functions to Room

This commit is contained in:
tibbi
2018-11-07 20:12:07 +01:00
parent 95ab889045
commit 43896a964a
5 changed files with 26 additions and 27 deletions

View File

@ -7,7 +7,6 @@ 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.getLongValue
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.Widget
@ -92,22 +91,6 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
}
}
fun getNoteId(path: String): Long {
val cols = arrayOf(COL_ID)
val selection = "$COL_PATH = ?"
val selectionArgs = arrayOf(path)
var cursor: Cursor? = null
try {
cursor = mDb.query(NOTES_TABLE_NAME, cols, selection, selectionArgs, null, null, null)
if (cursor?.moveToFirst() == true) {
return cursor.getLongValue(COL_ID)
}
} finally {
cursor?.close()
}
return 0
}
fun getWidgets(): ArrayList<Widget> {
val widgets = ArrayList<Widget>()
val cols = arrayOf(COL_WIDGET_ID, COL_NOTE_ID)

View File

@ -42,6 +42,15 @@ class NotesHelper(val activity: Activity) {
}.start()
}
fun getNoteIdWithPath(path: String, callback: (id: Long?) -> Unit) {
Thread {
val id = activity.notesDB.getNoteIdWithPath(path)
activity.runOnUiThread {
callback(id)
}
}.start()
}
fun insertOrUpdateNote(note: Note, callback: ((newNoteId: Long) -> Unit)? = null) {
Thread {
val noteId = activity.notesDB.insertOrUpdate(note)