Skip to content

Commit

Permalink
Using different method for time in deck picker and review
Browse files Browse the repository at this point in the history
This corrects #5829 (comment)
  • Loading branch information
Arthur-Milchior authored and mikehardy committed Jun 20, 2020
1 parent abdddfb commit 7122f0d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@ public void __renderPage() {
if (getCol().cardCount() != -1) {
String time = "-";
if (eta != -1) {
time = Utils.timeQuantity(AnkiDroidApp.getInstance(), eta*60);
time = Utils.timeQuantityTopDeckPicker(AnkiDroidApp.getInstance(), eta*60);
}
if (getSupportActionBar() != null) {
getSupportActionBar().setSubtitle(res.getQuantityString(R.plurals.deckpicker_title, due, due, time));
Expand Down
33 changes: 32 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/libanki/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static long intTime(int scale) {
* @return The time quantity string. Something like "3 s" or "1.7
* yr". Only months and year have a number after the decimal.
*/
public static String timeQuantity(Context context, long time_s) {
public static String timeQuantityTopDeckPicker(Context context, long time_s) {
Resources res = context.getResources();
// N.B.: the integer s, min, h, d and (one decimal, rounded by format) double for month, year is
// hard-coded. See also 01-core.xml
Expand All @@ -159,6 +159,37 @@ public static String timeQuantity(Context context, long time_s) {
}
}


/**
* Return a string representing a time quantity
*
* Equivalent to Anki's anki/utils.py's shortTimeFmt, applied to a number.
* I.e. equivalent to Anki's anki/utils.py's fmtTimeSpan, with the parameter short=True.
*
* @param context The application's environment.
* @param time_s The time to format, in seconds
* @return The time quantity string. Something like "3 s" or "1.7
* yr". Only months and year have a number after the decimal.
*/
public static String timeQuantityNextIvl(Context context, long time_s) {
Resources res = context.getResources();
// N.B.: the integer s, min, h, d and (one decimal, rounded by format) double for month, year is
// hard-coded. See also 01-core.xml
if (Math.abs(time_s) < TIME_MINUTE ) {
return res.getString(R.string.time_quantity_seconds, time_s);
} else if (Math.abs(time_s) < TIME_HOUR) {
return res.getString(R.string.time_quantity_minutes, (int) Math.round(time_s/TIME_MINUTE));
} else if (Math.abs(time_s) < TIME_DAY) {
return res.getString(R.string.time_quantity_hours, (int) Math.round(time_s/TIME_HOUR));
} else if (Math.abs(time_s) < TIME_MONTH) {
return res.getString(R.string.time_quantity_days, (int) Math.round(time_s/TIME_DAY));
} else if (Math.abs(time_s) < TIME_YEAR) {
return res.getString(R.string.time_quantity_months, time_s/TIME_MONTH);
} else {
return res.getString(R.string.time_quantity_years, time_s/TIME_YEAR);
}
}

/**
* Return a string representing how much time remains
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ public String nextIvlStr(Context context, Card card, int ease) {
if (ivl == 0) {
return context.getString(R.string.sched_end);
}
String s = Utils.timeQuantity(context, ivl);
String s = Utils.timeQuantityNextIvl(context, ivl);
if (ivl < mCol.getConf().getInt("collapseTime")) {
s = context.getString(R.string.less_than_time, s);
}
Expand Down

0 comments on commit 7122f0d

Please sign in to comment.