Use abbreviated dates in task list

Exclude 'Today' for dates with time
pull/757/head
Alex Baker 6 years ago
parent 2d4c0a62e8
commit 05e735e7e6

@ -163,11 +163,27 @@ public class DateUtilities {
return string;
}
public static String getAbbreviatedRelativeDateWithTime(Context context, long date) {
long startOfToday = getStartOfDay(currentTimeMillis());
long startOfDate = getStartOfDay(date);
String day = getRelativeDay(context, date, startOfDate, startOfToday, true);
if (Task.hasDueTime(date)) {
String time = getTimeString(context, date);
return startOfToday == startOfDate ? time : String.format("%s %s", day, time);
}
return day;
}
/** @return yesterday, today, tomorrow, or null */
public static String getRelativeDay(Context context, long date, boolean abbreviated) {
long today = getStartOfDay(currentTimeMillis());
long input = getStartOfDay(date);
return getRelativeDay(context, date, input, today, abbreviated);
}
private static String getRelativeDay(
Context context, long date, long input, long today, boolean abbreviated) {
if (today == input) {
return context.getString(R.string.today);
}
@ -180,7 +196,8 @@ public class DateUtilities {
return context.getString(abbreviated ? R.string.yest : R.string.yesterday);
}
if (today + abbreviationLimit >= input && today - abbreviationLimit <= input) {
if (today + abbreviationLimit >= input
&& today - abbreviationLimit <= input) {
return abbreviated
? DateUtilities.getWeekdayShort(newDateTime(date))
: DateUtilities.getWeekday(newDateTime(date));

@ -4,6 +4,7 @@ import static com.google.common.collect.Lists.newArrayList;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastKitKat;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop;
import static com.todoroo.andlib.utility.DateUtilities.getAbbreviatedRelativeDateWithTime;
import android.annotation.SuppressLint;
import android.content.Context;
@ -267,7 +268,7 @@ class ViewHolder extends RecyclerView.ViewHolder {
} else {
dueDate.setTextColor(textColorSecondary);
}
String dateValue = DateUtilities.getRelativeDateStringWithTime(context, task.getDueDate());
String dateValue = getAbbreviatedRelativeDateWithTime(context, task.getDueDate());
dueDate.setText(dateValue);
dueDate.setVisibility(View.VISIBLE);
} else {

Loading…
Cancel
Save