Migrate DB to new color format

pull/84/head
Alinson S. Xavier 10 years ago
parent 5bd0c842f5
commit 728c9557f0

@ -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"

@ -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;

@ -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];
}

Loading…
Cancel
Save