mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
moving more db related functions to Room
This commit is contained in:
@ -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)
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user