New color but Sort By Color broken

pull/286/head
austil 9 years ago
parent 96b95edef8
commit 4ce9013e6a

@ -30,6 +30,7 @@ public class ColorPickerDialog extends com.android.colorpicker.ColorPickerDialog
{
super.setOnColorSelectedListener(c -> {
c = ColorUtils.colorToPaletteIndex(getContext(), c);
c = ColorUtils.StaticColor.getColorByXmlIndex(c).dbIndex;
listener.onColorSelected(c);
});
}

@ -230,7 +230,7 @@ public abstract class HabitList implements Iterable<Habit>
habit.getDescription(),
Integer.toString(freq.getNumerator()),
Integer.toString(freq.getDenominator()),
ColorUtils.CSV_PALETTE[habit.getColor()]
ColorUtils.StaticColor.getColorByDbIndex(habit.getColor()).name()
};
csv.writeNext(cols, false);

@ -36,7 +36,7 @@ public class HabitMatcherBuilder
private static List<Integer> allColors()
{
List<Integer> colors = new ArrayList<>();
for(int i = 0; i < ColorUtils.CSV_PALETTE.length; i++)
for(int i = 0; i < ColorUtils.StaticColor.values().length; i++)
colors.add(i);
return colors;
}

@ -22,6 +22,7 @@ package org.isoron.uhabits.models.memory;
import android.support.annotation.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.ColorUtils;
import java.util.*;
@ -155,8 +156,8 @@ public class MemoryHabitList extends HabitList
(h1, h2) -> h1.getName().compareTo(h2.getName());
Comparator<Habit> colorComparator = (h1, h2) -> {
Integer c1 = h1.getColor();
Integer c2 = h2.getColor();
Integer c1 = ColorUtils.StaticColor.getColorByDbIndex(h1.getColor()).xmlIndex;
Integer c2 = ColorUtils.StaticColor.getColorByDbIndex(h2.getColor()).xmlIndex;
if (c1.equals(c2)) return nameComparator.compare(h1, h2);
else return c1.compareTo(c2);
};

@ -25,21 +25,55 @@ import android.util.*;
public abstract class ColorUtils
{
public static String CSV_PALETTE[] = {
"#D32F2F", // 0 red
"#E64A19", // 1 orange
"#F9A825", // 2 yellow
"#AFB42B", // 3 light green
"#388E3C", // 4 dark green
"#00897B", // 5 teal
"#00ACC1", // 6 cyan
"#039BE5", // 7 blue
"#5E35B1", // 8 deep purple
"#8E24AA", // 9 purple
"#D81B60", // 10 pink
"#303030", // 11 dark grey
"#aaaaaa" // 12 light grey
};
public enum StaticColor
{
RED ( 0, 0),
DEEP_ORANGE ( 1, 1),
ORANGE ( 2,13),
YELLOW ( 3, 2),
LIGHT_GREEN ( 4, 3),
DARK_GREEN ( 5, 4),
TEAL ( 6, 5),
CYAN ( 7, 6),
BLUE ( 8, 7),
DEEP_PURPLE ( 9, 8),
PURPLE (10, 9),
PINK (11,10),
BROWN (12,14),
DARK_GREY (13,11),
GREY (14,15),
LIGHT_GREY (15,12);
public final int xmlIndex;
public final int dbIndex;
StaticColor(int xmlIndex, int dbIndex)
{
this.xmlIndex = xmlIndex;
this.dbIndex = dbIndex;
}
public static StaticColor getColorByDbIndex(int dbIndex)
{
for(StaticColor c : StaticColor.values())
if (c.dbIndex == dbIndex) return c;
Log.w("ColorHelper",
String.format("Invalid color db index: %d. Returning default.", dbIndex));
return RED;
}
public static StaticColor getColorByXmlIndex(int xmlIndex)
{
for(StaticColor c : StaticColor.values())
if (c.xmlIndex == xmlIndex) return c;
Log.w("ColorHelper",
String.format("Invalid color xml index: %d. Returning default.", xmlIndex));
return RED;
}
}
public static int colorToPaletteIndex(Context context, int color)
{
@ -78,6 +112,8 @@ public abstract class ColorUtils
if (context == null)
throw new IllegalArgumentException("Context is null");
paletteColor = ColorUtils.StaticColor.getColorByDbIndex(paletteColor).xmlIndex;
StyledResources res = new StyledResources(context);
int palette[] = res.getPalette();
if (paletteColor < 0 || paletteColor >= palette.length)

@ -19,6 +19,7 @@
<array name="lightPalette">
<item>@color/red_700</item>
<item>@color/deep_orange_700</item>
<item>@color/orange_700</item>
<item>@color/yellow_800</item>
<item>@color/lime_700</item>
<item>@color/green_700</item>
@ -28,13 +29,16 @@
<item>@color/deep_purple_600</item>
<item>@color/purple_600</item>
<item>@color/pink_600</item>
<item>@color/brown_700</item>
<item>@color/grey_800</item>
<item>@color/grey_600</item>
<item>@color/grey_500</item>
</array>
<array name="darkPalette">
<item>@color/red_200</item>
<item>@color/deep_orange_200</item>
<item>@color/orange_200</item>
<item>@color/yellow_200</item>
<item>@color/lime_200</item>
<item>@color/green_A200</item>
@ -44,13 +48,16 @@
<item>@color/deep_purple_200</item>
<item>@color/purple_200</item>
<item>@color/pink_200</item>
<item>@color/brown_200</item>
<item>@color/grey_100</item>
<item>@color/grey_300</item>
<item>@color/grey_500</item>
</array>
<array name="transparentWidgetPalette">
<item>@color/red_800</item>
<item>@color/deep_orange_800</item>
<item>@color/orange_800</item>
<item>@color/yellow_800</item>
<item>@color/lime_800</item>
<item>@color/green_700</item>
@ -60,6 +67,8 @@
<item>@color/deep_purple_700</item>
<item>@color/purple_700</item>
<item>@color/pink_700</item>
<item>@color/brown_800</item>
<item>@color/black_aa</item>
<item>@color/black_aa</item>
<item>@color/black_aa</item>
</array>

@ -172,8 +172,8 @@ public class HabitListTest extends BaseUnitTest
String expectedCSV =
"Position,Name,Description,NumRepetitions,Interval,Color\n" +
"001,Meditate,Did you meditate this morning?,1,1,#AFB42B\n" +
"002,Wake up early,Did you wake up before 6am?,2,3,#00897B\n";
"001,Meditate,Did you meditate this morning?,1,1,LIGHT_GREEN\n" +
"002,Wake up early,Did you wake up before 6am?,2,3,TEAL\n";
StringWriter writer = new StringWriter();
list.writeCSV(writer);

Loading…
Cancel
Save