diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/show/views/OverviewCard.java b/app/src/main/java/org/isoron/uhabits/activities/habits/show/views/OverviewCard.java index 8787250dc..24eebec29 100644 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/show/views/OverviewCard.java +++ b/app/src/main/java/org/isoron/uhabits/activities/habits/show/views/OverviewCard.java @@ -49,6 +49,9 @@ public class OverviewCard extends HabitCard @BindView(R.id.yearDiffLabel) TextView yearDiffLabel; + @BindView(R.id.totalCountLabel) + TextView totalCountLabel; + @BindView(R.id.title) TextView title; @@ -128,12 +131,14 @@ public class OverviewCard extends HabitCard monthDiffLabel.setText(formatPercentageDiff(monthDiff)); yearDiffLabel.setText(formatPercentageDiff(yearDiff)); + totalCountLabel.setText(String.valueOf(cache.totalCount)); StyledResources res = new StyledResources(getContext()); int inactiveColor = res.getColor(R.attr.mediumContrastTextColor); monthDiffLabel.setTextColor(monthDiff >= 0 ? color : inactiveColor); yearDiffLabel.setTextColor(yearDiff >= 0 ? color : inactiveColor); + totalCountLabel.setTextColor(yearDiff >= 0 ? color : inactiveColor); postInvalidate(); } @@ -145,6 +150,8 @@ public class OverviewCard extends HabitCard public float lastMonthScore; public float lastYearScore; + + public long totalCount; } private class RefreshTask implements Task @@ -152,7 +159,9 @@ public class OverviewCard extends HabitCard @Override public void doInBackground() { - ScoreList scores = getHabit().getScores(); + Habit habit = getHabit(); + + ScoreList scores = habit.getScores(); long today = DateUtils.getStartOfToday(); long lastMonth = today - 30 * DateUtils.millisecondsInOneDay; @@ -161,6 +170,7 @@ public class OverviewCard extends HabitCard cache.todayScore = (float) scores.getTodayValue(); cache.lastMonthScore = (float) scores.getValue(lastMonth); cache.lastYearScore = (float) scores.getValue(lastYear); + cache.totalCount = habit.getRepetitions().getTotalCount(); } @Override diff --git a/app/src/main/java/org/isoron/uhabits/models/RepetitionList.java b/app/src/main/java/org/isoron/uhabits/models/RepetitionList.java index e527048f5..07a9df1ad 100644 --- a/app/src/main/java/org/isoron/uhabits/models/RepetitionList.java +++ b/app/src/main/java/org/isoron/uhabits/models/RepetitionList.java @@ -191,4 +191,12 @@ public abstract class RepetitionList habit.getStreaks().invalidateNewerThan(timestamp); return rep; } + + /** + * Returns the number of all repetitions + * + * @return number of all repetitions + */ + @NonNull + public abstract long getTotalCount(); } diff --git a/app/src/main/java/org/isoron/uhabits/models/memory/MemoryRepetitionList.java b/app/src/main/java/org/isoron/uhabits/models/memory/MemoryRepetitionList.java index 461de8021..8e55f84fc 100644 --- a/app/src/main/java/org/isoron/uhabits/models/memory/MemoryRepetitionList.java +++ b/app/src/main/java/org/isoron/uhabits/models/memory/MemoryRepetitionList.java @@ -99,4 +99,10 @@ public class MemoryRepetitionList extends RepetitionList observable.notifyListeners(); } + @NonNull + @Override + public long getTotalCount() + { + return list.size(); + } } diff --git a/app/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionList.java b/app/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionList.java index 2ce44ceb4..aa3594edf 100644 --- a/app/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionList.java +++ b/app/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionList.java @@ -19,9 +19,12 @@ package org.isoron.uhabits.models.sqlite; +import android.database.DatabaseUtils; +import android.database.sqlite.SQLiteDatabase; import android.support.annotation.*; import android.support.annotation.Nullable; +import com.activeandroid.Cache; import com.activeandroid.query.*; import org.isoron.uhabits.models.*; @@ -160,4 +163,14 @@ public class SQLiteRepetitionList extends RepetitionList return reps; } + + @NonNull + @Override + public long getTotalCount() + { + SQLiteDatabase db = Cache.openDatabase(); + + return DatabaseUtils.queryNumEntries(db, "Repetitions", + "habit=?", new String[] { Long.toString(habit.getId()) }); + } } diff --git a/app/src/main/res/layout/show_habit_overview.xml b/app/src/main/res/layout/show_habit_overview.xml index 908927c3c..33f6a7cca 100644 --- a/app/src/main/res/layout/show_habit_overview.xml +++ b/app/src/main/res/layout/show_habit_overview.xml @@ -105,5 +105,24 @@ android:textColor="?mediumContrastTextColor"/> + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 82d37f949..7aa0c5978 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -171,6 +171,8 @@ Quarter Year + Total + time in