Replace primitive int by PaletteColor

pull/699/head
Alinson S. Xavier 5 years ago
parent 63f2b80515
commit 5d2ff40dc9

@ -101,28 +101,28 @@ public class BaseUserInterfaceTest
h1.setName("Wake up early");
h1.setQuestion("Did you wake up early today?");
h1.setDescription("test description 1");
h1.setColor(5);
h1.setColor(new PaletteColor(5));
habitList.update(h1);
Habit h2 = fixtures.createShortHabit();
h2.setName("Track time");
h2.setQuestion("Did you track your time?");
h2.setDescription("test description 2");
h2.setColor(5);
h2.setColor(new PaletteColor(5));
habitList.update(h2);
Habit h3 = fixtures.createLongHabit();
h3.setName("Meditate");
h3.setQuestion("Did meditate today?");
h3.setDescription("test description 3");
h3.setColor(10);
h3.setColor(new PaletteColor(10));
habitList.update(h3);
Habit h4 = fixtures.createEmptyHabit();
h4.setName(EMPTY_DESCRIPTION_HABIT_NAME);
h4.setQuestion("Did you read books today?");
h4.setDescription("");
h4.setColor(2);
h4.setColor(new PaletteColor(2));
habitList.update(h4);
}

@ -56,7 +56,7 @@ public class HabitFixtures
habit.setName("Meditate");
habit.setQuestion("Did you meditate this morning?");
habit.setDescription("This is a test description");
habit.setColor(5);
habit.setColor(new PaletteColor(5));
habit.setFrequency(Frequency.DAILY);
habit.setId(id);
habitList.add(habit);
@ -67,7 +67,7 @@ public class HabitFixtures
{
Habit habit = createEmptyHabit();
habit.setFrequency(new Frequency(3, 7));
habit.setColor(7);
habit.setColor(new PaletteColor(7));
Timestamp today = DateUtils.getToday();
int marks[] = { 0, 1, 3, 5, 7, 8, 9, 10, 12, 14, 15, 17, 19, 20, 26, 27,
@ -84,7 +84,7 @@ public class HabitFixtures
{
Habit habit = createEmptyHabit();
habit.setFrequency(new Frequency(1, 2));
habit.setColor(11);
habit.setColor(new PaletteColor(11));
Timestamp today = DateUtils.getToday();
int marks[] = {0, 3, 5, 6, 7, 10, 13, 14, 15, 18, 21, 22, 23, 24, 27, 28, 30, 31, 34, 37,

@ -20,7 +20,6 @@
package org.isoron.uhabits.activities.common.views;
import androidx.test.filters.*;
import androidx.test.runner.*;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@ -49,7 +48,7 @@ public class BarChartTest extends BaseViewTest
Timestamp today = DateUtils.getToday();
CheckmarkList checkmarks = habit.getCheckmarks();
view.setCheckmarks(checkmarks.getByInterval(today.minus(20), today));
view.setColor(PaletteUtils.getColor(targetContext, habit.getColor()));
view.setColor(PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), targetContext));
view.setTarget(200.0);
measureView(view, dpToPixels(300), dpToPixels(200));
}

@ -19,10 +19,8 @@
package org.isoron.uhabits.activities.common.views;
import androidx.test.ext.junit.runners.*;
import androidx.test.filters.*;
import androidx.test.runner.*;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
@ -49,7 +47,7 @@ public class FrequencyChartTest extends BaseViewTest
view = new FrequencyChart(targetContext);
view.setFrequency(habit.getRepetitions().getWeekdayFrequency());
view.setColor(PaletteUtils.getAndroidTestColor(habit.getColor()));
view.setColor(PaletteUtilsKt.toFixedAndroidColor(habit.getColor()));
measureView(view, dpToPixels(300), dpToPixels(100));
}

@ -58,7 +58,7 @@ public class HistoryChartTest extends BaseViewTest
chart = new HistoryChart(targetContext);
chart.setSkipEnabled(true);
chart.setCheckmarks(habit.getCheckmarks().getAllValues());
chart.setColor(PaletteUtils.getAndroidTestColor(habit.getColor()));
chart.setColor(PaletteUtilsKt.toFixedAndroidColor(habit.getColor()));
measureView(chart, dpToPixels(400), dpToPixels(200));
controller = mock(HistoryChart.Controller.class);

@ -54,7 +54,7 @@ public class ScoreChartTest extends BaseViewTest
view = new ScoreChart(targetContext);
view.setScores(habit.getScores().toList());
view.setColor(PaletteUtils.getColor(targetContext, habit.getColor()));
view.setColor(PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), targetContext));
view.setBucketSize(7);
measureView(view, dpToPixels(300), dpToPixels(200));
}

@ -48,7 +48,7 @@ public class StreakChartTest extends BaseViewTest
Habit habit = fixtures.createLongHabit();
view = new StreakChart(targetContext);
view.setColor(PaletteUtils.getAndroidTestColor(habit.getColor()));
view.setColor(PaletteUtilsKt.toFixedAndroidColor(habit.getColor()));
view.setStreaks(habit.getStreaks().getBest(5));
measureView(view, dpToPixels(300), dpToPixels(100));
}

@ -79,7 +79,7 @@ class HabitCardViewTest : BaseViewTest() {
@Test
fun testChangeModel() {
habit1.name = "Wake up early"
habit1.color = 2
habit1.color = PaletteColor(2)
habit1.observable.notifyListeners()
Thread.sleep(500)
assertRenders(view, "$PATH/render_changed.png")

@ -47,7 +47,7 @@ public class TargetWidgetTest extends BaseViewTest
prefs.setWidgetOpacity(255);
habit = fixtures.createLongNumericalHabit();
habit.setColor(11);
habit.setColor(new PaletteColor(11));
TargetWidget widget = new TargetWidget(targetContext, 0, habit);
view = convertToView(widget, 400, 400);
}

@ -19,6 +19,7 @@
package org.isoron.uhabits.activities.common.dialogs;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.ui.callbacks.*;
import org.isoron.uhabits.utils.*;
@ -31,8 +32,8 @@ public class ColorPickerDialog extends com.android.colorpicker.ColorPickerDialog
{
super.setOnColorSelectedListener(c ->
{
c = PaletteUtils.colorToPaletteIndex(getContext(), c);
callback.onColorPicked(c);
PaletteColor pc = PaletteUtilsKt.toPaletteColor(c, getContext());
callback.onColorPicked(pc);
});
}
}

@ -24,6 +24,7 @@ import android.content.*;
import org.isoron.androidbase.activities.*;
import org.isoron.androidbase.utils.*;
import org.isoron.uhabits.R;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.utils.*;
import javax.inject.*;
@ -39,14 +40,14 @@ public class ColorPickerDialogFactory
this.context = context;
}
public ColorPickerDialog create(int paletteColor)
public ColorPickerDialog create(PaletteColor color)
{
ColorPickerDialog dialog = new ColorPickerDialog();
StyledResources res = new StyledResources(context);
int color = PaletteUtils.getColor(context, paletteColor);
int androidColor = PaletteUtilsKt.toThemedAndroidColor(color, context);
dialog.initialize(R.string.color_picker_default_title, res.getPalette(),
color, 4, com.android.colorpicker.ColorPickerDialog.SIZE_SMALL);
androidColor, 4, com.android.colorpicker.ColorPickerDialog.SIZE_SMALL);
return dialog;
}

@ -179,7 +179,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
if (getContext() == null || habit == null || historyChart == null)
return;
int color = PaletteUtils.getColor(getContext(), habit.getColor());
int color = PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), getContext());
historyChart.setColor(color);
historyChart.setCheckmarks(checkmarks);
historyChart.setNumerical(habit.isNumerical());

@ -21,12 +21,12 @@ package org.isoron.uhabits.activities.common.views;
import android.content.*;
import android.graphics.*;
import android.graphics.Color;
import android.graphics.Paint.*;
import android.util.*;
import android.view.*;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.*;
import org.isoron.androidbase.utils.*;
import org.isoron.uhabits.*;

@ -48,7 +48,7 @@ class EditHabitActivity : AppCompatActivity() {
var habitId = -1L
var habitType = -1
var unit = ""
var paletteColor = 11
var color = PaletteColor(11)
var androidColor = 0
var freqNum = 1
var freqDen = 1
@ -71,7 +71,7 @@ class EditHabitActivity : AppCompatActivity() {
habitId = intent.getLongExtra("habitId", -1)
val habit = component.habitList.getById(habitId)!!
habitType = habit.type
paletteColor = habit.color
color = habit.color
freqNum = habit.frequency.numerator
freqDen = habit.frequency.denominator
if (habit.hasReminder()) {
@ -91,7 +91,7 @@ class EditHabitActivity : AppCompatActivity() {
if (state != null) {
habitId = state.getLong("habitId")
habitType = state.getInt("habitType")
paletteColor = state.getInt("paletteColor")
color = PaletteColor(state.getInt("paletteColor"))
freqNum = state.getInt("freqNum")
freqDen = state.getInt("freqDen")
reminderHour = state.getInt("reminderHour")
@ -117,9 +117,9 @@ class EditHabitActivity : AppCompatActivity() {
val colorPickerDialogFactory = ColorPickerDialogFactory(this)
binding.colorButton.setOnClickListener {
val dialog = colorPickerDialogFactory.create(paletteColor)
val dialog = colorPickerDialogFactory.create(color)
dialog.setListener { paletteColor ->
this.paletteColor = paletteColor
this.color = paletteColor
updateColors()
}
dialog.show(supportFragmentManager, "colorPicker")
@ -165,6 +165,7 @@ class EditHabitActivity : AppCompatActivity() {
reminderMin = minute
populateReminder()
}
override fun onTimeCleared(view: RadialPickerLayout?) {
reminderHour = -1
reminderMin = -1
@ -208,7 +209,7 @@ class EditHabitActivity : AppCompatActivity() {
habit.name = nameInput.text.trim().toString()
habit.question = questionInput.text.trim().toString()
habit.description = notesInput.text.trim().toString()
habit.color = paletteColor
habit.color = color
if (reminderHour >= 0) {
habit.setReminder(Reminder(reminderHour, reminderMin, reminderDays))
} else {
@ -283,7 +284,7 @@ class EditHabitActivity : AppCompatActivity() {
}
private fun updateColors() {
androidColor = PaletteUtils.getColor(this, paletteColor)
androidColor = color.toThemedAndroidColor(this)
binding.colorButton.backgroundTintList = ColorStateList.valueOf(androidColor)
if (!themeSwitcher.isNightMode) {
val darkerAndroidColor = ColorUtils.mixColors(Color.BLACK, androidColor, 0.15f)
@ -297,7 +298,7 @@ class EditHabitActivity : AppCompatActivity() {
with(state) {
putLong("habitId", habitId)
putInt("habitType", habitType)
putInt("paletteColor", paletteColor)
putInt("paletteColor", color.paletteIndex)
putInt("androidColor", androidColor)
putInt("freqNum", freqNum)
putInt("freqDen", freqDen)

@ -202,7 +202,7 @@ class ListHabitsScreen
activity.startActivityForResult(intent, REQUEST_SETTINGS)
}
override fun showColorPicker(defaultColor: Int,
override fun showColorPicker(defaultColor: PaletteColor,
callback: OnColorPickedCallback) {
val picker = colorPickerFactory.create(defaultColor)
picker.setListener(callback)

@ -195,7 +195,7 @@ class HabitCardView(
fun getActiveColor(habit: Habit): Int {
return when (habit.isArchived) {
true -> sres.getColor(R.attr.mediumContrastTextColor)
false -> PaletteUtils.getColor(context, habit.color)
false -> habit.color.toThemedAndroidColor(context)
}
}

@ -104,7 +104,7 @@ public class ShowHabitRootView extends BaseRootView
if (!res.getBoolean(R.attr.useHabitColorAsPrimary))
return super.getToolbarColor();
return PaletteUtils.getColor(getContext(), habit.getColor());
return PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), getContext());
}
@Override

@ -143,7 +143,7 @@ public class BarCard extends HabitCard
@Override
public void onPreExecute()
{
int color = PaletteUtils.getColor(getContext(), habit.getColor());
int color = PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), getContext());
title.setTextColor(color);
chart.setColor(color);
if (habit.isNumerical())

@ -102,8 +102,7 @@ public class FrequencyCard extends HabitCard
@Override
public void onPreExecute()
{
int paletteColor = getHabit().getColor();
int color = PaletteUtils.getColor(getContext(), paletteColor);
int color = PaletteUtilsKt.toThemedAndroidColor(getHabit().getColor(), getContext());
title.setTextColor(color);
chart.setColor(color);
}

@ -131,7 +131,7 @@ public class HistoryCard extends HabitCard
@Override
public void onPreExecute()
{
int color = PaletteUtils.getColor(getContext(), habit.getColor());
int color = PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), getContext());
title.setTextColor(color);
chart.setColor(color);
if(habit.isNumerical())

@ -173,7 +173,7 @@ public class OverviewCard extends HabitCard
@Override
public void onPreExecute()
{
color = PaletteUtils.getColor(getContext(), getHabit().getColor());
color = PaletteUtilsKt.toThemedAndroidColor(getHabit().getColor(), getContext());
refreshColors();
}
}

@ -160,8 +160,7 @@ public class ScoreCard extends HabitCard
@Override
public void onPreExecute()
{
int color =
PaletteUtils.getColor(getContext(), getHabit().getColor());
int color = PaletteUtilsKt.toThemedAndroidColor(getHabit().getColor(), getContext());
title.setTextColor(color);
chart.setColor(color);
}

@ -100,7 +100,7 @@ public class StreakCard extends HabitCard
public void onPreExecute()
{
int color =
PaletteUtils.getColor(getContext(), getHabit().getColor());
PaletteUtilsKt.toThemedAndroidColor(getHabit().getColor(), getContext());
title.setTextColor(color);
streakChart.setColor(color);
}

@ -30,7 +30,6 @@ import org.isoron.uhabits.core.tasks.*
import org.isoron.uhabits.databinding.*
import org.isoron.uhabits.utils.*
import org.isoron.uhabits.utils.PaletteUtils.getAndroidTestColor
import org.isoron.uhabits.utils.PaletteUtils.getColor
import java.util.*
class SubtitleCard(context: Context?, attrs: AttributeSet?) : HabitCard(context, attrs) {
@ -43,7 +42,7 @@ class SubtitleCard(context: Context?, attrs: AttributeSet?) : HabitCard(context,
public override fun refreshData() {
val habit = habit
val color = getColor(context, habit.color)
val color = habit.color.toThemedAndroidColor(context)
if (habit.isNumerical) {
binding.targetText.text = "${habit.targetValue.toShortString()} ${habit.unit}"
} else {

@ -171,7 +171,7 @@ public class TargetCard extends HabitCard
@Override
public void onPreExecute()
{
int color = PaletteUtils.getColor(context, habit.getColor());
int color = PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), context);
if(title != null) title.setTextColor(color);
chart.setColor(color);
}

@ -25,9 +25,9 @@ import android.graphics.*
import android.graphics.BitmapFactory.*
import android.os.*
import android.os.Build.VERSION.*
import android.util.*
import androidx.core.app.*
import androidx.core.app.NotificationCompat.*
import android.util.*
import org.isoron.androidbase.*
import org.isoron.uhabits.R
import org.isoron.uhabits.core.*
@ -44,7 +44,7 @@ class AndroidNotificationTray
private val pendingIntents: PendingIntentFactory,
private val preferences: Preferences,
private val ringtoneManager: RingtoneManager
) : NotificationTray.SystemTray {
) : NotificationTray.SystemTray {
private var active = HashSet<Int>()
override fun log(msg: String) {

@ -4,18 +4,25 @@ import android.content.Context
import android.graphics.Color
import android.util.Log
import org.isoron.androidbase.utils.StyledResources
import org.isoron.uhabits.core.models.*
object PaletteUtils {
@JvmStatic
fun colorToPaletteIndex(context: Context, color: Int): Int {
fun getAndroidTestColor(index: Int) = PaletteColor(index).toFixedAndroidColor()
}
fun PaletteColor.toThemedAndroidColor(context: Context): Int {
val palette = StyledResources(context).getPalette()
return palette.indexOf(color)
return if (paletteIndex in palette.indices) {
palette[paletteIndex]
} else {
Log.w("ColorHelper", "Invalid color: $paletteIndex. Returning default.")
palette[0]
}
}
@JvmStatic
fun getAndroidTestColor(index: Int): Int {
val palette = intArrayOf(
fun PaletteColor.toFixedAndroidColor(): Int {
return intArrayOf(
Color.parseColor("#D32F2F"), // 0 red
Color.parseColor("#E64A19"), // 1 deep orange
Color.parseColor("#F57C00"), // 2 orange
@ -36,19 +43,10 @@ object PaletteUtils {
Color.parseColor("#303030"), // 17 dark grey
Color.parseColor("#757575"), // 18 grey
Color.parseColor("#aaaaaa") // 19 light grey
)
return palette[index]
}
)[paletteIndex]
}
@JvmStatic
fun getColor(context: Context, paletteColor: Int): Int {
fun Int.toPaletteColor(context: Context): PaletteColor {
val palette = StyledResources(context).getPalette()
return if (paletteColor in palette.indices) {
palette[paletteColor]
} else {
Log.w("ColorHelper", "Invalid color: $paletteColor. Returning default.")
palette[0]
}
}
return PaletteColor(palette.indexOf(this))
}

@ -44,7 +44,7 @@ open class CheckmarkWidget(
(v as CheckmarkWidgetView).apply {
setBackgroundAlpha(preferedBackgroundAlpha)
setActiveColor(PaletteUtils.getColor(context, habit.color))
setActiveColor(habit.color.toThemedAndroidColor(context))
setName(habit.name)
setCheckmarkValue(habit.checkmarks.todayValue)
if (habit.isNumerical) {

@ -43,7 +43,7 @@ class FrequencyWidget(
if (preferedBackgroundAlpha >= 255) widgetView.setShadowAlpha(0x4f)
(widgetView.dataView as FrequencyChart).apply {
setFirstWeekday(firstWeekday)
setColor(PaletteUtils.getColor(context, habit.color))
setColor(habit.color.toThemedAndroidColor(context))
setFrequency(habit.repetitions.weekdayFrequency)
}
}

@ -45,7 +45,7 @@ class HistoryWidget(
(widgetView.dataView as HistoryChart).apply {
setFirstWeekday(firstWeekday)
setSkipEnabled(prefs.isSkipEnabled)
setColor(PaletteUtils.getColor(context, habit.color))
setColor(habit.color.toThemedAndroidColor(context))
setCheckmarks(habit.checkmarks.allValues)
setNumerical(habit.isNumerical)
setTarget(habit.targetValue / habit.frequency.denominator)

@ -50,7 +50,7 @@ class ScoreWidget(
(widgetView.dataView as ScoreChart).apply {
setIsTransparencyEnabled(true)
setBucketSize(size)
setColor(PaletteUtils.getColor(context, habit.color))
setColor(habit.color.toThemedAndroidColor(context))
setScores(scores)
}
}

@ -42,7 +42,7 @@ class StreakWidget(
widgetView.setBackgroundAlpha(preferedBackgroundAlpha)
if (preferedBackgroundAlpha >= 255) widgetView.setShadowAlpha(0x4f)
(widgetView.dataView as StreakChart).apply {
setColor(PaletteUtils.getColor(context, habit.color))
setColor(habit.color.toThemedAndroidColor(context))
setStreaks(habit.streaks.getBest(maxStreakCount))
}
}

@ -37,14 +37,14 @@ public class ChangeHabitColorCommand extends Command
final List<Habit> selected;
@NonNull
final List<Integer> originalColors;
final List<PaletteColor> originalColors;
@NonNull
final Integer newColor;
final PaletteColor newColor;
public ChangeHabitColorCommand(@NonNull HabitList habitList,
@NonNull List<Habit> selected,
@NonNull Integer newColor)
@NonNull PaletteColor newColor)
{
this.habitList = habitList;
this.selected = selected;
@ -92,7 +92,7 @@ public class ChangeHabitColorCommand extends Command
public Record(ChangeHabitColorCommand command)
{
id = command.getId();
color = command.newColor;
color = command.newColor.getPaletteIndex();
habits = new LinkedList<>();
for (Habit h : command.selected)
{
@ -107,7 +107,7 @@ public class ChangeHabitColorCommand extends Command
for (Long id : this.habits) selected.add(habitList.getById(id));
ChangeHabitColorCommand command;
command = new ChangeHabitColorCommand(habitList, selected, color);
command = new ChangeHabitColorCommand(habitList, selected, new PaletteColor(color));
command.setId(id);
return command;
}

@ -123,21 +123,13 @@ public class Habit
return checkmarks;
}
/**
* Color of the habit.
* <p>
* This number is not an android.graphics.Color, but an index to the
* activity color palette, which changes according to the theme. To convert
* this color into an android.graphics.Color, use ColorHelper.getColor(context,
* habit.color).
*/
@NonNull
public synchronized Integer getColor()
public synchronized PaletteColor getColor()
{
return data.color;
}
public synchronized void setColor(@NonNull Integer color)
public synchronized void setColor(@NonNull PaletteColor color)
{
data.color = color;
}
@ -391,7 +383,7 @@ public class Habit
@NonNull
public Frequency frequency;
public int color;
public PaletteColor color;
public boolean archived;
@ -413,7 +405,7 @@ public class Habit
public HabitData()
{
this.color = 8;
this.color = new PaletteColor(8);
this.archived = false;
this.frequency = new Frequency(3, 7);
this.type = YES_NO_HABIT;

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

@ -0,0 +1,51 @@
/*
* Copyright (C) 2016-2020 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.core.models
data class PaletteColor(val paletteIndex: Int) {
fun toCsvColor(): String {
return arrayOf(
"#D32F2F", // 0 red
"#E64A19", // 1 deep orange
"#F57C00", // 2 orange
"#FF8F00", // 3 amber
"#F9A825", // 4 yellow
"#AFB42B", // 5 lime
"#7CB342", // 6 light green
"#388E3C", // 7 green
"#00897B", // 8 teal
"#00ACC1", // 9 cyan
"#039BE5", // 10 light blue
"#1976D2", // 11 blue
"#303F9F", // 12 indigo
"#5E35B1", // 13 deep purple
"#8E24AA", // 14 purple
"#D81B60", // 15 pink
"#5D4037", // 16 brown
"#303030", // 17 dark grey
"#757575", // 18 grey
"#aaaaaa" // 19 light grey
)[paletteIndex]
}
fun compareTo(other: PaletteColor): Int {
return paletteIndex.compareTo(other.paletteIndex)
}
}

@ -90,7 +90,7 @@ public class HabitRecord
this.name = model.getName();
this.description = model.getDescription();
this.highlight = 0;
this.color = model.getColor();
this.color = model.getColor().getPaletteIndex();
this.archived = model.isArchived() ? 1 : 0;
this.type = model.getType();
this.targetType = model.getTargetType();
@ -123,7 +123,7 @@ public class HabitRecord
habit.setDescription(this.description);
habit.setQuestion(this.question);
habit.setFrequency(new Frequency(this.freqNum, this.freqDen));
habit.setColor(this.color);
habit.setColor(new PaletteColor(this.color));
habit.setArchived(this.archived != 0);
habit.setType(this.type);
habit.setTargetType(this.targetType);

@ -46,7 +46,7 @@ public class HabitFixtures
Habit habit = modelFactory.buildHabit();
habit.setName("Meditate");
habit.setQuestion("Did you meditate this morning?");
habit.setColor(3);
habit.setColor(new PaletteColor(3));
habit.setFrequency(Frequency.DAILY);
saveIfSQLite(habit);
@ -57,7 +57,7 @@ public class HabitFixtures
{
Habit habit = createEmptyHabit();
habit.setFrequency(new Frequency(3, 7));
habit.setColor(4);
habit.setColor(new PaletteColor(4));
Timestamp today = DateUtils.getToday();
int marks[] = {0, 1, 3, 5, 7, 8, 9, 10, 12, 14, 15, 17, 19, 20, 26, 27,
@ -79,7 +79,7 @@ public class HabitFixtures
habit.setUnit("miles");
habit.setTargetType(Habit.AT_LEAST);
habit.setTargetValue(2.0);
habit.setColor(1);
habit.setColor(new PaletteColor(1));
saveIfSQLite(habit);
Timestamp today = DateUtils.getToday();
@ -104,7 +104,7 @@ public class HabitFixtures
habit.setUnit("steps");
habit.setTargetType(Habit.AT_LEAST);
habit.setTargetValue(100);
habit.setColor(1);
habit.setColor(new PaletteColor(1));
saveIfSQLite(habit);
int times[] = {0, 5, 9, 15, 17, 21, 23, 27, 28, 35, 41, 45, 47, 53, 56, 62, 70, 73, 78,

@ -19,7 +19,9 @@
package org.isoron.uhabits.core.ui.callbacks;
import org.isoron.uhabits.core.models.*;
public interface OnColorPickedCallback
{
void onColorPicked(int color);
void onColorPicked(PaletteColor color);
}

@ -133,7 +133,7 @@ public class ListHabitsSelectionMenuBehavior
public interface Screen
{
void showColorPicker(int defaultColor,
void showColorPicker(PaletteColor defaultColor,
@NonNull OnColorPickedCallback callback);
void showDeleteConfirmationScreen(

@ -1,27 +0,0 @@
package org.isoron.uhabits.core.utils;
public class ColorConstants
{
public static String CSV_PALETTE[] = {
"#D32F2F", // 0 red
"#E64A19", // 1 deep orange
"#F57C00", // 2 orange
"#FF8F00", // 3 amber
"#F9A825", // 4 yellow
"#AFB42B", // 5 lime
"#7CB342", // 6 light green
"#388E3C", // 7 green
"#00897B", // 8 teal
"#00ACC1", // 9 cyan
"#039BE5", // 10 light blue
"#1976D2", // 11 blue
"#303F9F", // 12 indigo
"#5E35B1", // 13 deep purple
"#8E24AA", // 14 purple
"#D81B60", // 15 pink
"#5D4037", // 16 brown
"#303030", // 17 dark grey
"#757575", // 18 grey
"#aaaaaa" // 19 light grey
};
}

@ -45,12 +45,12 @@ public class ChangeHabitColorCommandTest extends BaseUnitTest
for (int i = 0; i < 3; i++)
{
Habit habit = fixtures.createShortHabit();
habit.setColor(i + 1);
habit.setColor(new PaletteColor(i + 1));
selected.add(habit);
habitList.add(habit);
}
command = new ChangeHabitColorCommand(habitList, selected, 0);
command = new ChangeHabitColorCommand(habitList, selected, new PaletteColor(0));
}
@Test
@ -81,13 +81,13 @@ public class ChangeHabitColorCommandTest extends BaseUnitTest
private void checkNewColors()
{
for (Habit h : selected)
assertThat(h.getColor(), equalTo(0));
assertThat(h.getColor(), equalTo(new PaletteColor(0)));
}
private void checkOriginalColors()
{
int k = 0;
for (Habit h : selected)
assertThat(h.getColor(), equalTo(++k));
assertThat(h.getColor(), equalTo(new PaletteColor(++k)));
}
}

@ -66,7 +66,7 @@ public class CommandParserTest extends BaseUnitTest
public void testDecodeChangeColorCommand() throws JSONException
{
ChangeHabitColorCommand original, decoded;
original = new ChangeHabitColorCommand(habitList, selected, 20);
original = new ChangeHabitColorCommand(habitList, selected, new PaletteColor(20));
decoded = (ChangeHabitColorCommand) parser.parse(original.toJson());
MatcherAssert.assertThat(decoded.getId(), equalTo(original.getId()));
@ -122,7 +122,7 @@ public class CommandParserTest extends BaseUnitTest
{
Habit modified = modelFactory.buildHabit();
modified.setName("Edited JSON");
modified.setColor(2);
modified.setColor(new PaletteColor(2));
EditHabitCommand original, decoded;
original = new EditHabitCommand(modelFactory, habitList, habit, modified);

@ -113,22 +113,22 @@ public class HabitListTest extends BaseUnitTest
{
Habit h1 = fixtures.createEmptyHabit();
h1.setName("A Habit");
h1.setColor(2);
h1.setColor(new PaletteColor(2));
h1.setPosition(1);
Habit h2 = fixtures.createEmptyHabit();
h2.setName("B Habit");
h2.setColor(2);
h2.setColor(new PaletteColor(2));
h2.setPosition(3);
Habit h3 = fixtures.createEmptyHabit();
h3.setName("C Habit");
h3.setColor(0);
h3.setColor(new PaletteColor(0));
h3.setPosition(0);
Habit h4 = fixtures.createEmptyHabit();
h4.setName("D Habit");
h4.setColor(1);
h4.setColor(new PaletteColor(1));
h4.setPosition(2);
HabitList list = modelFactory.buildHabitList();
@ -246,14 +246,14 @@ public class HabitListTest extends BaseUnitTest
h1.setQuestion("Did you meditate this morning?");
h1.setDescription("this is a test description");
h1.setFrequency(Frequency.DAILY);
h1.setColor(3);
h1.setColor(new PaletteColor(3));
Habit h2 = fixtures.createEmptyHabit();
h2.setName("Wake up early");
h2.setQuestion("Did you wake up before 6am?");
h2.setDescription("");
h2.setFrequency(new Frequency(2, 3));
h2.setColor(5);
h2.setColor(new PaletteColor(5));
list.add(h1);
list.add(h2);

@ -58,7 +58,7 @@ public class HabitTest extends BaseUnitTest
{
Habit model = modelFactory.buildHabit();
model.setArchived(true);
model.setColor(0);
model.setColor(new PaletteColor(0));
model.setFrequency(new Frequency(10, 20));
model.setReminder(new Reminder(8, 30, new WeekdayList(1)));
@ -152,7 +152,7 @@ public class HabitTest extends BaseUnitTest
h.setReminder(new Reminder(22, 30, WeekdayList.EVERY_DAY));
String expected = "{id: <null>, data: {name: , description: ," +
" frequency: {numerator: 3, denominator: 7}," +
" color: 8, archived: false, targetType: 0," +
" color: PaletteColor(paletteIndex=8), archived: false, targetType: 0," +
" targetValue: 100.0, type: 0, unit: ," +
" reminder: {hour: 22, minute: 30," +
" days: {weekdays: [true,true,true,true,true,true,true]}}," +

@ -37,7 +37,7 @@ public class HabitRecordTest extends BaseUnitTest
Habit original = modelFactory.buildHabit();
original.setName("Hello world");
original.setQuestion("Did you greet the world today?");
original.setColor(1);
original.setColor(new PaletteColor(1));
original.setArchived(true);
original.setFrequency(Frequency.THREE_TIMES_PER_WEEK);
original.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
@ -59,7 +59,7 @@ public class HabitRecordTest extends BaseUnitTest
Habit original = modelFactory.buildHabit();
original.setName("Hello world");
original.setQuestion("Did you greet the world today?");
original.setColor(5);
original.setColor(new PaletteColor(5));
original.setArchived(false);
original.setFrequency(Frequency.DAILY);
original.setReminder(null);

@ -94,15 +94,15 @@ public class ListHabitsSelectionMenuBehaviorTest extends BaseUnitTest
@Test
public void onChangeColor() throws Exception
{
assertThat(habit1.getColor(), equalTo(8));
assertThat(habit2.getColor(), equalTo(8));
assertThat(habit1.getColor(), equalTo(new PaletteColor(8)));
assertThat(habit2.getColor(), equalTo(new PaletteColor(8)));
when(adapter.getSelected()).thenReturn(asList(habit1, habit2));
behavior.onChangeColor();
verify(screen).showColorPicker(eq(8), colorPickerCallback.capture());
colorPickerCallback.getValue().onColorPicked(30);
assertThat(habit1.getColor(), equalTo(30));
verify(screen).showColorPicker(eq(new PaletteColor(8)), colorPickerCallback.capture());
colorPickerCallback.getValue().onColorPicked(new PaletteColor(30));
assertThat(habit1.getColor(), equalTo(new PaletteColor(30)));
}
@Test

Loading…
Cancel
Save