diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/ActiveBgAlert.java b/wear/src/main/java/com/eveningoutpost/dexdrip/Models/ActiveBgAlert.java index 754b83667a..a9ae6ef107 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/ActiveBgAlert.java +++ b/wear/src/main/java/com/eveningoutpost/dexdrip/Models/ActiveBgAlert.java @@ -96,18 +96,23 @@ public String toString() { // so we have the following static functions: getOnly, saveData, ClearData public static ActiveBgAlert getOnly() { - ActiveBgAlert aba = new Select() - .from(ActiveBgAlert.class) - .orderBy("_ID asc") - .executeSingle(); - - if (aba != null) { - Log.v(TAG, "ActiveBgAlert getOnly aba = " + aba.toString()); - } else { - Log.v(TAG, "ActiveBgAlert getOnly returning null"); + try { + ActiveBgAlert aba = new Select() + .from(ActiveBgAlert.class) + .orderBy("_ID asc") + .executeSingle(); + + if (aba != null) { + Log.v(TAG, "ActiveBgAlert getOnly aba = " + aba.toString()); + } else { + Log.v(TAG, "ActiveBgAlert getOnly returning null"); + } + return aba; + } catch (android.database.sqlite.SQLiteException e) { + Log.d(TAG,"ActiveBgAlert rebuilding table strcuture"); + fixUpTable(); + return null; } - - return aba; } public static AlertType alertTypegetOnly() { @@ -186,6 +191,12 @@ public void updateNextAlertAt(long nextAlertTime){ private static void fixUpTable() { if (patched) return; String[] patchup = { + "CREATE TABLE ActiveBgAlert (_id INTEGER PRIMARY KEY AUTOINCREMENT;", + "ALTER TABLE ActiveBgAlert ADD COLUMN alert_started_at INTEGER;", + "ALTER TABLE ActiveBgAlert ADD COLUMN alert_uuid TEXT;", + "ALTER TABLE ActiveBgAlert ADD COLUMN is_snoozed INTEGER;", + "ALTER TABLE ActiveBgAlert ADD COLUMN last_alerted_at INTEGER;", + "ALTER TABLE ActiveBgAlert ADD COLUMN next_alert_at INTEGER;", "ALTER TABLE ActiveBgAlert ADD COLUMN alert_started_at INTEGER;" }; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/AlertType.java b/wear/src/main/java/com/eveningoutpost/dexdrip/Models/AlertType.java index 2be34d8d48..228681245e 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/AlertType.java +++ b/wear/src/main/java/com/eveningoutpost/dexdrip/Models/AlertType.java @@ -1,35 +1,30 @@ package com.eveningoutpost.dexdrip.Models; -import android.app.AlarmManager; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.provider.BaseColumns; -import com.activeandroid.util.SQLiteUtils; -import com.eveningoutpost.dexdrip.Models.UserError.Log; import com.activeandroid.Model; import com.activeandroid.annotation.Column; import com.activeandroid.annotation.Table; import com.activeandroid.query.Select; -//KS import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; -//KS import com.eveningoutpost.dexdrip.Services.MissedReadingService; +import com.activeandroid.util.SQLiteUtils; +import com.eveningoutpost.dexdrip.Models.UserError.Log; import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; import com.eveningoutpost.dexdrip.UtilityModels.Notifications; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.annotations.Expose; +import com.google.gson.internal.bind.DateTypeAdapter; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.UUID; -import java.util.concurrent.atomic.AtomicBoolean; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.annotations.Expose; -import com.google.gson.internal.bind.DateTypeAdapter; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; +//KS import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; +//KS import com.eveningoutpost.dexdrip.Services.MissedReadingService; /** * Created by Emma Black on 1/14/15. @@ -120,12 +115,27 @@ public class AlertType extends Model { private static void fixUpTable() { if (patched) return; String[] patchup = { + "CREATE TABLE AlertType (_id INTEGER PRIMARY KEY AUTOINCREMENT);", + "ALTER TABLE AlertType ADD COLUMN above INTEGER;", + "ALTER TABLE AlertType ADD COLUMN active INTEGER;", + "ALTER TABLE AlertType ADD COLUMN all_day INTEGER;", + "ALTER TABLE AlertType ADD COLUMN default_snooze INTEGER;", + "ALTER TABLE AlertType ADD COLUMN end_time_minutes INTEGER;", + "ALTER TABLE AlertType ADD COLUMN minutes_between INTEGER;", + "ALTER TABLE AlertType ADD COLUMN override_silent_mode INTEGER;", + "ALTER TABLE AlertType ADD COLUMN start_time_minutes INTEGER;", + "ALTER TABLE AlertType ADD COLUMN vibrate INTEGER;", + "ALTER TABLE AlertType ADD COLUMN mp3_file TEXT;", + "ALTER TABLE AlertType ADD COLUMN threshold REAL;", + "ALTER TABLE AlertType ADD COLUMN uuid TEXT;", + "CREATE INDEX index_AlertType_uuid on AlertType(uuid);", "ALTER TABLE AlertType ADD COLUMN volume INTEGER;", "ALTER TABLE AlertType ADD COLUMN light INTEGER;", "ALTER TABLE AlertType ADD COLUMN predictive INTEGER;", "ALTER TABLE AlertType ADD COLUMN text TEXT;", "ALTER TABLE AlertType ADD COLUMN time_until_threshold_crossed REAL;" - }; + }; + for (String patch : patchup) { try { @@ -276,6 +286,7 @@ public static AlertType HigherAlert(AlertType a1, AlertType a2) { } public static void remove_all() { + fixUpTable(); List Alerts = new Select() .from(AlertType.class) .execute();