From 728c9557f0bdcbb62334e0a6976ded082690e905 Mon Sep 17 00:00:00 2001 From: Alinson Xavier Date: Fri, 15 Apr 2016 18:20:49 -0400 Subject: [PATCH] Migrate DB to new color format --- app/build.gradle | 2 +- app/src/main/assets/migrations/14.sql | 14 ++++++++++ .../isoron/uhabits/helpers/ColorHelper.java | 26 ++----------------- 3 files changed, 17 insertions(+), 25 deletions(-) create mode 100644 app/src/main/assets/migrations/14.sql diff --git a/app/build.gradle b/app/build.gradle index d98191ed1..92535bce0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 15 targetSdkVersion 23 - buildConfigField "Integer", "databaseVersion", "13" + buildConfigField "Integer", "databaseVersion", "14" buildConfigField "String", "databaseFilename", "\"uhabits.db\"" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/assets/migrations/14.sql b/app/src/main/assets/migrations/14.sql new file mode 100644 index 000000000..e267afc2c --- /dev/null +++ b/app/src/main/assets/migrations/14.sql @@ -0,0 +1,14 @@ +update habits set color=0 where color=-2937041; +update habits set color=1 where color=-1684967; +update habits set color=2 where color=-415707; +update habits set color=3 where color=-5262293; +update habits set color=4 where color=-13070788; +update habits set color=5 where color=-16742021; +update habits set color=6 where color=-16732991; +update habits set color=7 where color=-16540699; +update habits set color=8 where color=-10603087; +update habits set color=9 where color=-7461718; +update habits set color=10 where color=-2614432; +update habits set color=11 where color=-13619152; +update habits set color=12 where color=-5592406; +update habits set color=0 where color<0 or color>12; \ No newline at end of file diff --git a/app/src/main/java/org/isoron/uhabits/helpers/ColorHelper.java b/app/src/main/java/org/isoron/uhabits/helpers/ColorHelper.java index 361c1272c..975d9a774 100644 --- a/app/src/main/java/org/isoron/uhabits/helpers/ColorHelper.java +++ b/app/src/main/java/org/isoron/uhabits/helpers/ColorHelper.java @@ -28,7 +28,6 @@ import org.isoron.uhabits.R; public class ColorHelper { - public static int CSV_PALETTE[] = { Color.parseColor("#D32F2F"), // red @@ -74,32 +73,11 @@ public class ColorHelper public static int getColor(Context context, int paletteColor) { - if(context == null) throw new IllegalArgumentException("Context is null"); + int palette[] = getPalette(context); if(paletteColor < 0 || paletteColor >= palette.length) - { - // TODO: Write DB migration and change warnings to runtime exceptions - int androidColor = paletteColor; - paletteColor = -1; - - Log.w("ColorHelper", "Invalid palette color detected. Trying to convert."); - - for(int k = 0; k < CSV_PALETTE.length; k++) - { - if (CSV_PALETTE[k] == androidColor) - { - paletteColor = k; - break; - } - } - - if(paletteColor < 0) - { - Log.w("ColorHelper", "Conversion failed. Returning default."); - paletteColor = 0; - } - } + throw new IllegalArgumentException(String.format("Invalid color: %d", paletteColor)); return palette[paletteColor]; }