mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Implement filter by colors
This commit is contained in:
@@ -19,6 +19,10 @@
|
||||
|
||||
package org.isoron.uhabits.models;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.isoron.uhabits.models.Checkmark.*;
|
||||
|
||||
public class HabitMatcher
|
||||
@@ -34,13 +38,22 @@ public class HabitMatcher
|
||||
|
||||
private final boolean completedAllowed;
|
||||
|
||||
private final List<Integer> allowedColors;
|
||||
|
||||
public HabitMatcher(boolean allowArchived,
|
||||
boolean reminderRequired,
|
||||
boolean completedAllowed)
|
||||
boolean completedAllowed,
|
||||
@NonNull List<Integer> allowedColors)
|
||||
{
|
||||
this.archivedAllowed = allowArchived;
|
||||
this.reminderRequired = reminderRequired;
|
||||
this.completedAllowed = completedAllowed;
|
||||
this.allowedColors = allowedColors;
|
||||
}
|
||||
|
||||
public List<Integer> getAllowedColors()
|
||||
{
|
||||
return allowedColors;
|
||||
}
|
||||
|
||||
public boolean isArchivedAllowed()
|
||||
@@ -65,7 +78,7 @@ public class HabitMatcher
|
||||
|
||||
int todayCheckmark = habit.getCheckmarks().getTodayValue();
|
||||
if (todayCheckmark != UNCHECKED && !isCompletedAllowed()) return false;
|
||||
|
||||
if(!allowedColors.contains(habit.getColor())) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
|
||||
package org.isoron.uhabits.models;
|
||||
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class HabitMatcherBuilder
|
||||
{
|
||||
private boolean archivedAllowed = false;
|
||||
@@ -27,10 +31,20 @@ public class HabitMatcherBuilder
|
||||
|
||||
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()
|
||||
{
|
||||
return new HabitMatcher(archivedAllowed, reminderRequired,
|
||||
completedAllowed);
|
||||
completedAllowed, allowedColors);
|
||||
}
|
||||
|
||||
public HabitMatcherBuilder setArchivedAllowed(boolean archivedAllowed)
|
||||
@@ -39,6 +53,12 @@ public class HabitMatcherBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
public HabitMatcherBuilder setAllowedColors(List<Integer> allowedColors)
|
||||
{
|
||||
this.allowedColors = allowedColors;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HabitMatcherBuilder setCompletedAllowed(boolean completedAllowed)
|
||||
{
|
||||
this.completedAllowed = completedAllowed;
|
||||
|
||||
@@ -61,9 +61,14 @@ public class ListHabitsActivity extends BaseActivity
|
||||
system = new BaseSystem(this);
|
||||
adapter = new HabitCardListAdapter(habits, checkmarkCount);
|
||||
|
||||
// List<Integer> colors = new ArrayList<>();
|
||||
// colors.add(0);
|
||||
// colors.add(1);
|
||||
// colors.add(2);
|
||||
//
|
||||
// HabitMatcher matcher = new HabitMatcherBuilder()
|
||||
// .setCompletedAllowed(false)
|
||||
// .setArchivedAllowed(false)
|
||||
// .setAllowedColors(colors)
|
||||
// .build();
|
||||
// adapter.setFilter(matcher);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user