forked from omni/OmniCards
feat: added backup and restored functionality
This commit is contained in:
@@ -106,4 +106,28 @@ class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?)
|
||||
|
||||
db.close()
|
||||
}
|
||||
|
||||
fun clearDatabase() {
|
||||
val db = this.writableDatabase
|
||||
|
||||
db.execSQL("DELETE FROM cards")
|
||||
}
|
||||
|
||||
fun addCards(cards: List<CardInfo>) {
|
||||
val db = this.writableDatabase
|
||||
|
||||
for (card in cards) {
|
||||
val values = ContentValues()
|
||||
|
||||
values.put("id", card.id)
|
||||
values.put("name", card.name)
|
||||
values.put("codeValue", card.codeValue)
|
||||
values.put("codeType", card.codeType.name)
|
||||
values.put("color", card.color)
|
||||
|
||||
db.insert("cards", null, values)
|
||||
}
|
||||
|
||||
db.close()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user