mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-02 18:00:12 +02:00
insert the initial note at creating the Room database
This commit is contained in:
parent
d0e731fcb7
commit
2fc3d8cba9
@ -5,6 +5,8 @@ import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.helpers.TYPE_NOTE
|
||||
import com.simplemobiletools.notes.pro.interfaces.NotesDao
|
||||
import com.simplemobiletools.notes.pro.interfaces.WidgetsDao
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
@ -31,7 +33,7 @@ abstract class NotesDatabase : RoomDatabase() {
|
||||
.addCallback(object : Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
super.onCreate(db)
|
||||
insertFirstNote()
|
||||
insertFirstNote(context)
|
||||
}
|
||||
})
|
||||
.build()
|
||||
@ -46,9 +48,11 @@ abstract class NotesDatabase : RoomDatabase() {
|
||||
db = null
|
||||
}
|
||||
|
||||
private fun insertFirstNote() {
|
||||
private fun insertFirstNote(context: Context) {
|
||||
Executors.newSingleThreadExecutor().execute {
|
||||
|
||||
val generalNote = context.resources.getString(R.string.general_note)
|
||||
val note = Note(1, generalNote, "", TYPE_NOTE)
|
||||
db!!.NotesDao().insertOrUpdate(note)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
||||
private val mDb = writableDatabase
|
||||
|
||||
companion object {
|
||||
private const val DB_NAME = "notes.db"
|
||||
private const val DB_NAME = "notes_old.db"
|
||||
private const val DB_VERSION = 4
|
||||
private const val NOTES_TABLE_NAME = "notes"
|
||||
private const val WIDGETS_TABLE_NAME = "widgets"
|
||||
|
Loading…
x
Reference in New Issue
Block a user