diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/Database.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/Database.kt index 0f7ae9c..c7cc58f 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/Database.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/Database.kt @@ -7,26 +7,9 @@ import android.database.sqlite.SQLiteOpenHelper import org.unifiedpush.distributor.nextpush.services.RegistrationCountCache import java.util.concurrent.atomic.AtomicReference -private const val DB_NAME = "apps_db" -private const val DB_VERSION = 2 - class Database(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) { - private val TABLE_APPS = "apps" - private val FIELD_PACKAGE_NAME = "packageName" - private val FIELD_CONNECTOR_TOKEN = "connectorToken" - private val FIELD_APP_TOKEN = "appToken" - private val FIELD_NOTIFICATION_TITLE = "notificationTitle" // Used for non-UnifiedPush notif - private val CREATE_TABLE_APPS = "CREATE TABLE $TABLE_APPS (" + - "$FIELD_PACKAGE_NAME TEXT," + - "$FIELD_CONNECTOR_TOKEN TEXT," + - "$FIELD_APP_TOKEN TEXT," + - "$FIELD_NOTIFICATION_TITLE TEXT," + - "PRIMARY KEY ($FIELD_CONNECTOR_TOKEN));" - - private val UPGRADE_1_2 = "ALTER TABLE $TABLE_APPS ADD COLUMN $FIELD_NOTIFICATION_TITLE TEXT" - override fun onCreate(db: SQLiteDatabase) { db.execSQL(CREATE_TABLE_APPS) } @@ -178,6 +161,23 @@ class Database(val context: Context) : } companion object { + private const val DB_NAME = "apps_db" + private const val DB_VERSION = 3 + + private const val TABLE_APPS = "apps" + private const val FIELD_PACKAGE_NAME = "packageName" + private const val FIELD_CONNECTOR_TOKEN = "connectorToken" + private const val FIELD_APP_TOKEN = "appToken" + private const val FIELD_NOTIFICATION_TITLE = "notificationTitle" // Used for non-UnifiedPush notif + private const val CREATE_TABLE_APPS = "CREATE TABLE $TABLE_APPS (" + + "$FIELD_PACKAGE_NAME TEXT," + + "$FIELD_CONNECTOR_TOKEN TEXT," + + "$FIELD_APP_TOKEN TEXT," + + "$FIELD_NOTIFICATION_TITLE TEXT," + + "PRIMARY KEY ($FIELD_CONNECTOR_TOKEN));" + + private const val UPGRADE_1_2 = "ALTER TABLE $TABLE_APPS ADD COLUMN $FIELD_NOTIFICATION_TITLE TEXT" + private val db: AtomicReference = AtomicReference(null) fun getDb(context: Context): Database {