Implement filter by colors

pull/145/head
Alinson S. Xavier 9 years ago
parent b749f7f391
commit 6ef2983906

@ -19,6 +19,10 @@
package org.isoron.uhabits.models; package org.isoron.uhabits.models;
import android.support.annotation.*;
import java.util.*;
import static org.isoron.uhabits.models.Checkmark.*; import static org.isoron.uhabits.models.Checkmark.*;
public class HabitMatcher public class HabitMatcher
@ -34,13 +38,22 @@ public class HabitMatcher
private final boolean completedAllowed; private final boolean completedAllowed;
private final List<Integer> allowedColors;
public HabitMatcher(boolean allowArchived, public HabitMatcher(boolean allowArchived,
boolean reminderRequired, boolean reminderRequired,
boolean completedAllowed) boolean completedAllowed,
@NonNull List<Integer> allowedColors)
{ {
this.archivedAllowed = allowArchived; this.archivedAllowed = allowArchived;
this.reminderRequired = reminderRequired; this.reminderRequired = reminderRequired;
this.completedAllowed = completedAllowed; this.completedAllowed = completedAllowed;
this.allowedColors = allowedColors;
}
public List<Integer> getAllowedColors()
{
return allowedColors;
} }
public boolean isArchivedAllowed() public boolean isArchivedAllowed()
@ -65,7 +78,7 @@ public class HabitMatcher
int todayCheckmark = habit.getCheckmarks().getTodayValue(); int todayCheckmark = habit.getCheckmarks().getTodayValue();
if (todayCheckmark != UNCHECKED && !isCompletedAllowed()) return false; if (todayCheckmark != UNCHECKED && !isCompletedAllowed()) return false;
if(!allowedColors.contains(habit.getColor())) return false;
return true; return true;
} }
} }

@ -19,6 +19,10 @@
package org.isoron.uhabits.models; package org.isoron.uhabits.models;
import org.isoron.uhabits.utils.*;
import java.util.*;
public class HabitMatcherBuilder public class HabitMatcherBuilder
{ {
private boolean archivedAllowed = false; private boolean archivedAllowed = false;
@ -27,10 +31,20 @@ public class HabitMatcherBuilder
private boolean completedAllowed = true; private boolean completedAllowed = true;
private List<Integer> allowedColors = allColors();
private static List<Integer> allColors()
{
List<Integer> colors = new ArrayList<>();
for(int i = 0; i < ColorUtils.CSV_PALETTE.length; i++)
colors.add(i);
return colors;
}
public HabitMatcher build() public HabitMatcher build()
{ {
return new HabitMatcher(archivedAllowed, reminderRequired, return new HabitMatcher(archivedAllowed, reminderRequired,
completedAllowed); completedAllowed, allowedColors);
} }
public HabitMatcherBuilder setArchivedAllowed(boolean archivedAllowed) public HabitMatcherBuilder setArchivedAllowed(boolean archivedAllowed)
@ -39,6 +53,12 @@ public class HabitMatcherBuilder
return this; return this;
} }
public HabitMatcherBuilder setAllowedColors(List<Integer> allowedColors)
{
this.allowedColors = allowedColors;
return this;
}
public HabitMatcherBuilder setCompletedAllowed(boolean completedAllowed) public HabitMatcherBuilder setCompletedAllowed(boolean completedAllowed)
{ {
this.completedAllowed = completedAllowed; this.completedAllowed = completedAllowed;

@ -61,9 +61,14 @@ public class ListHabitsActivity extends BaseActivity
system = new BaseSystem(this); system = new BaseSystem(this);
adapter = new HabitCardListAdapter(habits, checkmarkCount); adapter = new HabitCardListAdapter(habits, checkmarkCount);
// List<Integer> colors = new ArrayList<>();
// colors.add(0);
// colors.add(1);
// colors.add(2);
//
// HabitMatcher matcher = new HabitMatcherBuilder() // HabitMatcher matcher = new HabitMatcherBuilder()
// .setCompletedAllowed(false)
// .setArchivedAllowed(false) // .setArchivedAllowed(false)
// .setAllowedColors(colors)
// .build(); // .build();
// adapter.setFilter(matcher); // adapter.setFilter(matcher);

Loading…
Cancel
Save