Merge pull request #171 from regularcoder/dev

Add repetition count to overview card
pull/174/head
Alinson S. Xavier 9 years ago committed by GitHub
commit 6f10039aba

@ -49,6 +49,9 @@ public class OverviewCard extends HabitCard
@BindView(R.id.yearDiffLabel) @BindView(R.id.yearDiffLabel)
TextView yearDiffLabel; TextView yearDiffLabel;
@BindView(R.id.totalCountLabel)
TextView totalCountLabel;
@BindView(R.id.title) @BindView(R.id.title)
TextView title; TextView title;
@ -128,12 +131,14 @@ public class OverviewCard extends HabitCard
monthDiffLabel.setText(formatPercentageDiff(monthDiff)); monthDiffLabel.setText(formatPercentageDiff(monthDiff));
yearDiffLabel.setText(formatPercentageDiff(yearDiff)); yearDiffLabel.setText(formatPercentageDiff(yearDiff));
totalCountLabel.setText(String.valueOf(cache.totalCount));
StyledResources res = new StyledResources(getContext()); StyledResources res = new StyledResources(getContext());
int inactiveColor = res.getColor(R.attr.mediumContrastTextColor); int inactiveColor = res.getColor(R.attr.mediumContrastTextColor);
monthDiffLabel.setTextColor(monthDiff >= 0 ? color : inactiveColor); monthDiffLabel.setTextColor(monthDiff >= 0 ? color : inactiveColor);
yearDiffLabel.setTextColor(yearDiff >= 0 ? color : inactiveColor); yearDiffLabel.setTextColor(yearDiff >= 0 ? color : inactiveColor);
totalCountLabel.setTextColor(yearDiff >= 0 ? color : inactiveColor);
postInvalidate(); postInvalidate();
} }
@ -145,6 +150,8 @@ public class OverviewCard extends HabitCard
public float lastMonthScore; public float lastMonthScore;
public float lastYearScore; public float lastYearScore;
public long totalCount;
} }
private class RefreshTask implements Task private class RefreshTask implements Task
@ -152,7 +159,9 @@ public class OverviewCard extends HabitCard
@Override @Override
public void doInBackground() public void doInBackground()
{ {
ScoreList scores = getHabit().getScores(); Habit habit = getHabit();
ScoreList scores = habit.getScores();
long today = DateUtils.getStartOfToday(); long today = DateUtils.getStartOfToday();
long lastMonth = today - 30 * DateUtils.millisecondsInOneDay; long lastMonth = today - 30 * DateUtils.millisecondsInOneDay;
@ -161,6 +170,7 @@ public class OverviewCard extends HabitCard
cache.todayScore = (float) scores.getTodayValue(); cache.todayScore = (float) scores.getTodayValue();
cache.lastMonthScore = (float) scores.getValue(lastMonth); cache.lastMonthScore = (float) scores.getValue(lastMonth);
cache.lastYearScore = (float) scores.getValue(lastYear); cache.lastYearScore = (float) scores.getValue(lastYear);
cache.totalCount = habit.getRepetitions().getTotalCount();
} }
@Override @Override

@ -191,4 +191,12 @@ public abstract class RepetitionList
habit.getStreaks().invalidateNewerThan(timestamp); habit.getStreaks().invalidateNewerThan(timestamp);
return rep; return rep;
} }
/**
* Returns the number of all repetitions
*
* @return number of all repetitions
*/
@NonNull
public abstract long getTotalCount();
} }

@ -99,4 +99,10 @@ public class MemoryRepetitionList extends RepetitionList
observable.notifyListeners(); observable.notifyListeners();
} }
@NonNull
@Override
public long getTotalCount()
{
return list.size();
}
} }

@ -19,9 +19,12 @@
package org.isoron.uhabits.models.sqlite; package org.isoron.uhabits.models.sqlite;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.*; import android.support.annotation.*;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.activeandroid.Cache;
import com.activeandroid.query.*; import com.activeandroid.query.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
@ -160,4 +163,14 @@ public class SQLiteRepetitionList extends RepetitionList
return reps; return reps;
} }
@NonNull
@Override
public long getTotalCount()
{
SQLiteDatabase db = Cache.openDatabase();
return DatabaseUtils.queryNumEntries(db, "Repetitions",
"habit=?", new String[] { Long.toString(habit.getId()) });
}
} }

@ -105,5 +105,24 @@
android:textColor="?mediumContrastTextColor"/> android:textColor="?mediumContrastTextColor"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
<TextView
android:id="@+id/totalCountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/total"
android:textColor="?mediumContrastTextColor"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
</merge> </merge>

@ -171,6 +171,8 @@
<string name="quarter">Quarter</string> <string name="quarter">Quarter</string>
<string name="year">Year</string> <string name="year">Year</string>
<string name="total">Total</string>
<!-- Middle part of the sentence '1 time in xx days' --> <!-- Middle part of the sentence '1 time in xx days' -->
<string name="time_every">time in</string> <string name="time_every">time in</string>

Loading…
Cancel
Save