mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Merge pull request #171 from regularcoder/dev
Add repetition count to overview card
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -99,4 +99,10 @@ public class MemoryRepetitionList extends RepetitionList
|
||||
observable.notifyListeners();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public long getTotalCount()
|
||||
{
|
||||
return list.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()) });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,5 +105,24 @@
|
||||
android:textColor="?mediumContrastTextColor"/>
|
||||
|
||||
</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>
|
||||
</merge>
|
||||
@@ -171,6 +171,8 @@
|
||||
<string name="quarter">Quarter</string>
|
||||
<string name="year">Year</string>
|
||||
|
||||
<string name="total">Total</string>
|
||||
|
||||
<!-- Middle part of the sentence '1 time in xx days' -->
|
||||
<string name="time_every">time in</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user