|
|
@ -26,11 +26,13 @@ import org.apache.commons.lang3.builder.*;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.concurrent.*;
|
|
|
|
import javax.inject.*;
|
|
|
|
import javax.inject.*;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The thing that the user wants to track.
|
|
|
|
* The thing that the user wants to track.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@ThreadSafe
|
|
|
|
public class Habit
|
|
|
|
public class Habit
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public static final String HABIT_URI_FORMAT =
|
|
|
|
public static final String HABIT_URI_FORMAT =
|
|
|
@ -54,22 +56,23 @@ public class Habit
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private boolean archived;
|
|
|
|
private boolean archived;
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Nullable
|
|
|
|
private StreakList streaks;
|
|
|
|
private Reminder reminder;
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private ScoreList scores;
|
|
|
|
private final StreakList streaks;
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private RepetitionList repetitions;
|
|
|
|
private final ScoreList scores;
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private CheckmarkList checkmarks;
|
|
|
|
private final RepetitionList repetitions;
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@NonNull
|
|
|
|
private Reminder reminder;
|
|
|
|
private final CheckmarkList checkmarks;
|
|
|
|
|
|
|
|
|
|
|
|
private ModelObservable observable = new ModelObservable();
|
|
|
|
@NonNull
|
|
|
|
|
|
|
|
private final ModelObservable observable;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Constructs a habit with default attributes.
|
|
|
|
* Constructs a habit with default attributes.
|
|
|
@ -88,12 +91,13 @@ public class Habit
|
|
|
|
streaks = factory.buildStreakList(this);
|
|
|
|
streaks = factory.buildStreakList(this);
|
|
|
|
scores = factory.buildScoreList(this);
|
|
|
|
scores = factory.buildScoreList(this);
|
|
|
|
repetitions = factory.buildRepetitionList(this);
|
|
|
|
repetitions = factory.buildRepetitionList(this);
|
|
|
|
|
|
|
|
observable = new ModelObservable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Clears the reminder for a habit.
|
|
|
|
* Clears the reminder for a habit.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void clearReminder()
|
|
|
|
public synchronized void clearReminder()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
reminder = null;
|
|
|
|
reminder = null;
|
|
|
|
observable.notifyListeners();
|
|
|
|
observable.notifyListeners();
|
|
|
@ -104,7 +108,7 @@ public class Habit
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param model the model whose attributes should be copied from
|
|
|
|
* @param model the model whose attributes should be copied from
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void copyFrom(@NonNull Habit model)
|
|
|
|
public synchronized void copyFrom(@NonNull Habit model)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.name = model.getName();
|
|
|
|
this.name = model.getName();
|
|
|
|
this.description = model.getDescription();
|
|
|
|
this.description = model.getDescription();
|
|
|
@ -119,7 +123,7 @@ public class Habit
|
|
|
|
* List of checkmarks belonging to this habit.
|
|
|
|
* List of checkmarks belonging to this habit.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
public CheckmarkList getCheckmarks()
|
|
|
|
public synchronized CheckmarkList getCheckmarks()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return checkmarks;
|
|
|
|
return checkmarks;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -133,56 +137,56 @@ public class Habit
|
|
|
|
* habit.color).
|
|
|
|
* habit.color).
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
public Integer getColor()
|
|
|
|
public synchronized Integer getColor()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return color;
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setColor(@NonNull Integer color)
|
|
|
|
public synchronized void setColor(@NonNull Integer color)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.color = color;
|
|
|
|
this.color = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
public String getDescription()
|
|
|
|
public synchronized String getDescription()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return description;
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setDescription(@NonNull String description)
|
|
|
|
public synchronized void setDescription(@NonNull String description)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.description = description;
|
|
|
|
this.description = description;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
public Frequency getFrequency()
|
|
|
|
public synchronized Frequency getFrequency()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return frequency;
|
|
|
|
return frequency;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setFrequency(@NonNull Frequency frequency)
|
|
|
|
public synchronized void setFrequency(@NonNull Frequency frequency)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.frequency = frequency;
|
|
|
|
this.frequency = frequency;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Nullable
|
|
|
|
public Long getId()
|
|
|
|
public synchronized Long getId()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setId(@Nullable Long id)
|
|
|
|
public synchronized void setId(@Nullable Long id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.id = id;
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
public String getName()
|
|
|
|
public synchronized String getName()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setName(@NonNull String name)
|
|
|
|
public synchronized void setName(@NonNull String name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.name = name;
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -203,13 +207,13 @@ public class Habit
|
|
|
|
* @throws IllegalStateException if habit has no reminder
|
|
|
|
* @throws IllegalStateException if habit has no reminder
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
public Reminder getReminder()
|
|
|
|
public synchronized Reminder getReminder()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (reminder == null) throw new IllegalStateException();
|
|
|
|
if (reminder == null) throw new IllegalStateException();
|
|
|
|
return reminder;
|
|
|
|
return reminder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setReminder(@Nullable Reminder reminder)
|
|
|
|
public synchronized void setReminder(@Nullable Reminder reminder)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.reminder = reminder;
|
|
|
|
this.reminder = reminder;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -248,17 +252,17 @@ public class Habit
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return true if habit has reminder, false otherwise
|
|
|
|
* @return true if habit has reminder, false otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public boolean hasReminder()
|
|
|
|
public synchronized boolean hasReminder()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return reminder != null;
|
|
|
|
return reminder != null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isArchived()
|
|
|
|
public synchronized boolean isArchived()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return archived;
|
|
|
|
return archived;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setArchived(boolean archived)
|
|
|
|
public synchronized void setArchived(boolean archived)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.archived = archived;
|
|
|
|
this.archived = archived;
|
|
|
|
}
|
|
|
|
}
|
|
|
|