forked from omni/OmniCards
feat: added color pick for cards
This commit is contained in:
@@ -6,25 +6,28 @@ import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import com.google.zxing.BarcodeFormat
|
||||
|
||||
class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?) : SQLiteOpenHelper(context, "omni_cards", factory, 1) {
|
||||
class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?) : SQLiteOpenHelper(context, "omni_cards", factory, 2) {
|
||||
override fun onCreate(db: SQLiteDatabase?) {
|
||||
db!!.execSQL("CREATE TABLE IF NOT EXISTS cards (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, codeType TEXT, codeValue TEXT)")
|
||||
db!!.execSQL("CREATE TABLE IF NOT EXISTS cards (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, codeType TEXT, codeValue TEXT, color TEXT)")
|
||||
}
|
||||
|
||||
override fun onUpgrade(
|
||||
db: SQLiteDatabase?,
|
||||
p1: Int,
|
||||
oldVersion: Int,
|
||||
p2: Int
|
||||
) {
|
||||
db!!.execSQL("DROP TABLE IF EXISTS cards")
|
||||
if (oldVersion < 2) {
|
||||
db!!.execSQL("ALTER TABLE cards ADD COLUMN color TEXT")
|
||||
}
|
||||
}
|
||||
|
||||
fun addCard(name: String, codeValue: String, codeType: BarcodeFormat) {
|
||||
fun addCard(name: String, codeValue: String, codeType: BarcodeFormat, color: String?) {
|
||||
val values = ContentValues()
|
||||
|
||||
values.put("name", name)
|
||||
values.put("codeValue", codeValue)
|
||||
values.put("codeType", codeType.name)
|
||||
values.put("color", color)
|
||||
|
||||
val db = this.writableDatabase
|
||||
|
||||
@@ -33,12 +36,13 @@ class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?)
|
||||
db.close()
|
||||
}
|
||||
|
||||
fun editCard(id: Int, name: String, codeValue: String, codeType: BarcodeFormat) {
|
||||
fun editCard(id: Int, name: String, codeValue: String, codeType: BarcodeFormat, color: String?) {
|
||||
val values = ContentValues()
|
||||
|
||||
values.put("name", name)
|
||||
values.put("codeValue", codeValue)
|
||||
values.put("codeType", codeType.name)
|
||||
values.put("color", color)
|
||||
|
||||
val db = this.writableDatabase
|
||||
|
||||
@@ -58,7 +62,8 @@ class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?)
|
||||
id = cursor.getInt(cursor.getColumnIndexOrThrow("id")),
|
||||
name = cursor.getString(cursor.getColumnIndexOrThrow("name")),
|
||||
codeType = BarcodeFormat.valueOf(cursor.getString(cursor.getColumnIndexOrThrow("codeType"))),
|
||||
codeValue = cursor.getString(cursor.getColumnIndexOrThrow("codeValue"))
|
||||
codeValue = cursor.getString(cursor.getColumnIndexOrThrow("codeValue")),
|
||||
color = cursor.getString(cursor.getColumnIndexOrThrow("color"))
|
||||
))
|
||||
}
|
||||
|
||||
@@ -84,7 +89,8 @@ class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?)
|
||||
id = cursor.getInt(cursor.getColumnIndexOrThrow("id")),
|
||||
name = cursor.getString(cursor.getColumnIndexOrThrow("name")),
|
||||
codeType = BarcodeFormat.valueOf(cursor.getString(cursor.getColumnIndexOrThrow("codeType"))),
|
||||
codeValue = cursor.getString(cursor.getColumnIndexOrThrow("codeValue"))
|
||||
codeValue = cursor.getString(cursor.getColumnIndexOrThrow("codeValue")),
|
||||
color = cursor.getString(cursor.getColumnIndexOrThrow("color"))
|
||||
)
|
||||
|
||||
cursor.close()
|
||||
|
||||
Reference in New Issue
Block a user