|
|
@ -121,10 +121,8 @@ public class Habit extends Model
|
|
|
|
|
|
|
|
|
|
|
|
protected static From select()
|
|
|
|
protected static From select()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(includeArchived)
|
|
|
|
if (includeArchived) return new Select().from(Habit.class).orderBy("position");
|
|
|
|
return new Select().from(Habit.class).orderBy("position");
|
|
|
|
else return new Select().from(Habit.class).where("archived = 0").orderBy("position");
|
|
|
|
else
|
|
|
|
|
|
|
|
return new Select().from(Habit.class).where("archived = 0").orderBy("position");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void setIncludeArchived(boolean includeArchived)
|
|
|
|
public static void setIncludeArchived(boolean includeArchived)
|
|
|
@ -155,7 +153,8 @@ public class Habit extends Model
|
|
|
|
|
|
|
|
|
|
|
|
public static java.util.List<Habit> getHighlightedHabits()
|
|
|
|
public static java.util.List<Habit> getHighlightedHabits()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return select().where("highlight = 1").orderBy("reminder_hour desc, reminder_min desc")
|
|
|
|
return select().where("highlight = 1")
|
|
|
|
|
|
|
|
.orderBy("reminder_hour desc, reminder_min desc")
|
|
|
|
.execute();
|
|
|
|
.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -170,9 +169,11 @@ public class Habit extends Model
|
|
|
|
|
|
|
|
|
|
|
|
Habit h = Habit.getByPosition(from);
|
|
|
|
Habit h = Habit.getByPosition(from);
|
|
|
|
if (to < from) new Update(Habit.class).set("position = position + 1")
|
|
|
|
if (to < from) new Update(Habit.class).set("position = position + 1")
|
|
|
|
.where("position >= ? and position < ?", to, from).execute();
|
|
|
|
.where("position >= ? and position < ?", to, from)
|
|
|
|
|
|
|
|
.execute();
|
|
|
|
else new Update(Habit.class).set("position = position - 1")
|
|
|
|
else new Update(Habit.class).set("position = position - 1")
|
|
|
|
.where("position > ? and position <= ?", from, to).execute();
|
|
|
|
.where("position > ? and position <= ?", from, to)
|
|
|
|
|
|
|
|
.execute();
|
|
|
|
|
|
|
|
|
|
|
|
h.position = to;
|
|
|
|
h.position = to;
|
|
|
|
h.save();
|
|
|
|
h.save();
|
|
|
@ -193,8 +194,7 @@ public class Habit extends Model
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ActiveAndroid.setTransactionSuccessful();
|
|
|
|
ActiveAndroid.setTransactionSuccessful();
|
|
|
|
}
|
|
|
|
} finally
|
|
|
|
finally
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ActiveAndroid.endTransaction();
|
|
|
|
ActiveAndroid.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -271,8 +271,10 @@ public class Habit extends Model
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteReps(long timestamp)
|
|
|
|
public void deleteReps(long timestamp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
new Delete().from(Repetition.class).where("habit = ?", getId())
|
|
|
|
new Delete().from(Repetition.class)
|
|
|
|
.and("timestamp = ?", timestamp).execute();
|
|
|
|
.where("habit = ?", getId())
|
|
|
|
|
|
|
|
.and("timestamp = ?", timestamp)
|
|
|
|
|
|
|
|
.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteCheckmarksNewerThan(long timestamp)
|
|
|
|
public void deleteCheckmarksNewerThan(long timestamp)
|
|
|
@ -339,8 +341,7 @@ public class Habit extends Model
|
|
|
|
beginning = newestCheckmark.timestamp + day;
|
|
|
|
beginning = newestCheckmark.timestamp + day;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(beginning > today)
|
|
|
|
if (beginning > today) return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long beginningExtended = beginning - (long) (freq_den) * day;
|
|
|
|
long beginningExtended = beginning - (long) (freq_den) * day;
|
|
|
|
List<Repetition> reps = selectRepsFromTo(beginningExtended, today).execute();
|
|
|
|
List<Repetition> reps = selectRepsFromTo(beginningExtended, today).execute();
|
|
|
@ -382,8 +383,7 @@ public class Habit extends Model
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ActiveAndroid.setTransactionSuccessful();
|
|
|
|
ActiveAndroid.setTransactionSuccessful();
|
|
|
|
}
|
|
|
|
} finally
|
|
|
|
finally
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ActiveAndroid.endTransaction();
|
|
|
|
ActiveAndroid.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -419,10 +419,7 @@ public class Habit extends Model
|
|
|
|
|
|
|
|
|
|
|
|
public Repetition getOldestRepNewerThan(long timestamp)
|
|
|
|
public Repetition getOldestRepNewerThan(long timestamp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return selectReps()
|
|
|
|
return selectReps().where("timestamp > ?", timestamp).limit(1).executeSingle();
|
|
|
|
.where("timestamp > ?", timestamp)
|
|
|
|
|
|
|
|
.limit(1)
|
|
|
|
|
|
|
|
.executeSingle();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void toggleRepetition(long timestamp)
|
|
|
|
public void toggleRepetition(long timestamp)
|
|
|
@ -471,13 +468,18 @@ public class Habit extends Model
|
|
|
|
|
|
|
|
|
|
|
|
public Score getNewestScore()
|
|
|
|
public Score getNewestScore()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new Select().from(Score.class).where("habit = ?", getId()).orderBy("timestamp desc")
|
|
|
|
return new Select().from(Score.class)
|
|
|
|
.limit(1).executeSingle();
|
|
|
|
.where("habit = ?", getId())
|
|
|
|
|
|
|
|
.orderBy("timestamp desc")
|
|
|
|
|
|
|
|
.limit(1)
|
|
|
|
|
|
|
|
.executeSingle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteScoresNewerThan(long timestamp)
|
|
|
|
public void deleteScoresNewerThan(long timestamp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
new Delete().from(Score.class).where("habit = ?", getId()).and("timestamp >= ?", timestamp)
|
|
|
|
new Delete().from(Score.class)
|
|
|
|
|
|
|
|
.where("habit = ?", getId())
|
|
|
|
|
|
|
|
.and("timestamp >= ?", timestamp)
|
|
|
|
.execute();
|
|
|
|
.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -533,8 +535,7 @@ public class Habit extends Model
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ActiveAndroid.setTransactionSuccessful();
|
|
|
|
ActiveAndroid.setTransactionSuccessful();
|
|
|
|
}
|
|
|
|
} finally
|
|
|
|
finally
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ActiveAndroid.endTransaction();
|
|
|
|
ActiveAndroid.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -549,17 +550,18 @@ public class Habit extends Model
|
|
|
|
|
|
|
|
|
|
|
|
public List<Score> getScores(long fromTimestamp, long toTimestamp, int divisor, long offset)
|
|
|
|
public List<Score> getScores(long fromTimestamp, long toTimestamp, int divisor, long offset)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new Select().from(Score.class).where("habit = ? and timestamp > ? and " +
|
|
|
|
return new Select().from(Score.class)
|
|
|
|
"timestamp <= ? and (timestamp - ?) % ? = 0", getId(), fromTimestamp, toTimestamp,
|
|
|
|
.where("habit = ? and timestamp > ? and " +
|
|
|
|
offset, divisor).execute();
|
|
|
|
"timestamp <= ? and (timestamp - ?) % ? = 0", getId(), fromTimestamp,
|
|
|
|
|
|
|
|
toTimestamp, offset, divisor)
|
|
|
|
|
|
|
|
.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Streak> getStreaks()
|
|
|
|
public List<Streak> getStreaks()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
updateStreaks();
|
|
|
|
updateStreaks();
|
|
|
|
|
|
|
|
|
|
|
|
return new Select()
|
|
|
|
return new Select().from(Streak.class)
|
|
|
|
.from(Streak.class)
|
|
|
|
|
|
|
|
.where("habit = ?", getId())
|
|
|
|
.where("habit = ?", getId())
|
|
|
|
.orderBy("end asc")
|
|
|
|
.orderBy("end asc")
|
|
|
|
.execute();
|
|
|
|
.execute();
|
|
|
@ -567,8 +569,7 @@ public class Habit extends Model
|
|
|
|
|
|
|
|
|
|
|
|
public Streak getNewestStreak()
|
|
|
|
public Streak getNewestStreak()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new Select()
|
|
|
|
return new Select().from(Streak.class)
|
|
|
|
.from(Streak.class)
|
|
|
|
|
|
|
|
.where("habit = ?", getId())
|
|
|
|
.where("habit = ?", getId())
|
|
|
|
.orderBy("end desc")
|
|
|
|
.orderBy("end desc")
|
|
|
|
.limit(1)
|
|
|
|
.limit(1)
|
|
|
@ -614,8 +615,7 @@ public class Habit extends Model
|
|
|
|
if ((checks[j + 1] > 0 && checks[j] == 0)) list.add(current - day);
|
|
|
|
if ((checks[j + 1] > 0 && checks[j] == 0)) list.add(current - day);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(list.size() % 2 == 1)
|
|
|
|
if (list.size() % 2 == 1) list.add(current);
|
|
|
|
list.add(current);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ActiveAndroid.beginTransaction();
|
|
|
|
ActiveAndroid.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
@ -632,8 +632,7 @@ public class Habit extends Model
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ActiveAndroid.setTransactionSuccessful();
|
|
|
|
ActiveAndroid.setTransactionSuccessful();
|
|
|
|
}
|
|
|
|
} finally
|
|
|
|
finally
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ActiveAndroid.endTransaction();
|
|
|
|
ActiveAndroid.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -657,7 +656,8 @@ public class Habit extends Model
|
|
|
|
{
|
|
|
|
{
|
|
|
|
savedHabit.save();
|
|
|
|
savedHabit.save();
|
|
|
|
savedId = savedHabit.getId();
|
|
|
|
savedId = savedHabit.getId();
|
|
|
|
} else
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
savedHabit.save(savedId);
|
|
|
|
savedHabit.save(savedId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|