Skip to content

Commit

Permalink
Fix uninitialized database for new users.
Browse files Browse the repository at this point in the history
  • Loading branch information
hwki committed Nov 19, 2023
1 parent 50b5d61 commit dafa655
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions bitcoin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.brentpanther.bitcoinwidget"
minSdk 23
targetSdk 34
versionCode 321
versionName "8.4.2"
versionCode 322
versionName "8.4.3"

}

Expand Down Expand Up @@ -65,7 +65,7 @@ dependencies {
implementation platform('androidx.compose:compose-bom:2023.10.01')

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.1"
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'androidx.work:work-runtime-ktx:2.8.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.brentpanther.bitcoinwidget.db

import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
Expand Down Expand Up @@ -76,9 +78,17 @@ abstract class WidgetDatabase : RoomDatabase() {
fun getInstance(context: Context): WidgetDatabase {
val callback = object : Callback() {

override fun onCreate(db: SupportSQLiteDatabase) {
val values = ContentValues().apply {
put("refresh", 15)
put("consistentSize", false)
put("dataMigrationVersion", 1)
}
db.insert("configuration", SQLiteDatabase.CONFLICT_REPLACE, values)
}

override fun onOpen(db: SupportSQLiteDatabase) {
DataMigration.migrate(db)
super.onOpen(db)
}
}
return INSTANCE ?: synchronized(this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class WidgetDataStrategy(val widgetId: Int) {

fun shouldRefresh(): Boolean {
return widget?.let {
it.state == WidgetState.DRAFT || System.currentTimeMillis() - it.lastUpdated > 15000
it.state == WidgetState.DRAFT || System.currentTimeMillis() - it.lastUpdated > 30000
} ?: false
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.0-rc03'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit dafa655

Please sign in to comment.