insert the default shared theme only after the function has been activated
This commit is contained in:
parent
3496de5d6a
commit
27cf585f24
|
@ -15,7 +15,7 @@ import com.simplemobiletools.commons.helpers.MyContentProvider.Companion.fillThe
|
||||||
import com.simplemobiletools.commons.models.SharedTheme
|
import com.simplemobiletools.commons.models.SharedTheme
|
||||||
|
|
||||||
class MyContentProviderDbHelper private constructor(private val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
|
class MyContentProviderDbHelper private constructor(private val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
|
||||||
private val mDb: SQLiteDatabase = writableDatabase
|
private val mDb = writableDatabase
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val DB_NAME = "Commons.db"
|
private val DB_NAME = "Commons.db"
|
||||||
|
@ -29,16 +29,15 @@ class MyContentProviderDbHelper private constructor(private val context: Context
|
||||||
override fun onCreate(db: SQLiteDatabase) {
|
override fun onCreate(db: SQLiteDatabase) {
|
||||||
db.execSQL("CREATE TABLE $TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TEXT_COLOR INTEGER DEFAULT 0, $COL_BACKGROUND_COLOR INTEGER DEFAULT 0," +
|
db.execSQL("CREATE TABLE $TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TEXT_COLOR INTEGER DEFAULT 0, $COL_BACKGROUND_COLOR INTEGER DEFAULT 0," +
|
||||||
" $COL_PRIMARY_COLOR INTEGER DEFAULT 0, $COL_LAST_UPDATED_TS INTEGER DEFAULT 0)")
|
" $COL_PRIMARY_COLOR INTEGER DEFAULT 0, $COL_LAST_UPDATED_TS INTEGER DEFAULT 0)")
|
||||||
insertDefaultTheme(db)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
|
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
|
||||||
|
|
||||||
private fun insertDefaultTheme(db: SQLiteDatabase) {
|
private fun insertDefaultTheme() {
|
||||||
val resources = context.resources
|
val resources = context.resources
|
||||||
val theme = SharedTheme(resources.getColor(R.color.theme_dark_text_color), resources.getColor(R.color.theme_dark_background_color),
|
val theme = SharedTheme(resources.getColor(R.color.theme_dark_text_color), resources.getColor(R.color.theme_dark_background_color),
|
||||||
resources.getColor(R.color.color_primary))
|
resources.getColor(R.color.color_primary))
|
||||||
insertTheme(theme, db)
|
insertTheme(theme, mDb)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun insertTheme(sharedTheme: SharedTheme, db: SQLiteDatabase) {
|
private fun insertTheme(sharedTheme: SharedTheme, db: SQLiteDatabase) {
|
||||||
|
@ -52,7 +51,24 @@ class MyContentProviderDbHelper private constructor(private val context: Context
|
||||||
return mDb.update(TABLE_NAME, values, selection, selectionArgs)
|
return mDb.update(TABLE_NAME, values, selection, selectionArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isThemeAvailable(): Boolean {
|
||||||
|
val cols = arrayOf(COL_ID)
|
||||||
|
val selection = "$COL_ID = ?"
|
||||||
|
val selectionArgs = arrayOf(THEME_ID.toString())
|
||||||
|
var cursor: Cursor? = null
|
||||||
|
try {
|
||||||
|
cursor = mDb.query(TABLE_NAME, cols, selection, selectionArgs, null, null, null)
|
||||||
|
return cursor.moveToFirst()
|
||||||
|
} finally {
|
||||||
|
cursor?.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getSharedTheme(): Cursor? {
|
fun getSharedTheme(): Cursor? {
|
||||||
|
if (!isThemeAvailable()) {
|
||||||
|
insertDefaultTheme()
|
||||||
|
}
|
||||||
|
|
||||||
val cols = arrayOf(COL_TEXT_COLOR, COL_BACKGROUND_COLOR, COL_PRIMARY_COLOR, COL_LAST_UPDATED_TS)
|
val cols = arrayOf(COL_TEXT_COLOR, COL_BACKGROUND_COLOR, COL_PRIMARY_COLOR, COL_LAST_UPDATED_TS)
|
||||||
val selection = "$COL_ID = ?"
|
val selection = "$COL_ID = ?"
|
||||||
val selectionArgs = arrayOf(THEME_ID.toString())
|
val selectionArgs = arrayOf(THEME_ID.toString())
|
||||||
|
|
Loading…
Reference in New Issue