forked from omni/OmniCards
feat: added card view with full brightness, and center no cards text
This commit is contained in:
@@ -4,10 +4,11 @@ import android.content.ContentValues
|
||||
import android.content.Context
|
||||
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) {
|
||||
override fun onCreate(db: SQLiteDatabase?) {
|
||||
db!!.execSQL("CREATE TABLE IF NOT EXISTS cards (id SERIAL PRIMARY KEY, 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)")
|
||||
}
|
||||
|
||||
override fun onUpgrade(
|
||||
@@ -18,7 +19,7 @@ class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?)
|
||||
db!!.execSQL("DROP TABLE IF EXISTS cards")
|
||||
}
|
||||
|
||||
fun addCard(name: String, codeValue: String, codeType: CodeType) {
|
||||
fun addCard(name: String, codeValue: String, codeType: BarcodeFormat) {
|
||||
val values = ContentValues()
|
||||
|
||||
values.put("name", name)
|
||||
@@ -42,7 +43,7 @@ class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?)
|
||||
cards.add(CardInfo(
|
||||
id = cursor.getInt(cursor.getColumnIndexOrThrow("id")),
|
||||
name = cursor.getString(cursor.getColumnIndexOrThrow("name")),
|
||||
codeType = CodeType.valueOf(cursor.getString(cursor.getColumnIndexOrThrow("codeType"))),
|
||||
codeType = BarcodeFormat.valueOf(cursor.getString(cursor.getColumnIndexOrThrow("codeType"))),
|
||||
codeValue = cursor.getString(cursor.getColumnIndexOrThrow("codeValue"))
|
||||
))
|
||||
}
|
||||
@@ -52,4 +53,29 @@ class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?)
|
||||
|
||||
return cards
|
||||
}
|
||||
|
||||
fun getCard(id: Int): CardInfo? {
|
||||
val db = this.readableDatabase
|
||||
|
||||
val cursor = db.rawQuery("SELECT * FROM cards WHERE id = ?", arrayOf(id.toString()))
|
||||
|
||||
if (!cursor.moveToFirst()) {
|
||||
cursor.close()
|
||||
db.close()
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
val cardInfo = CardInfo(
|
||||
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"))
|
||||
)
|
||||
|
||||
cursor.close()
|
||||
db.close()
|
||||
|
||||
return cardInfo
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user