Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53542bee authored by Marten Gajda's avatar Marten Gajda
Browse files

use relative dates in list view and widget

parent 01662435
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -32,10 +32,8 @@
    <!-- date & time string -->
    <string name="today">Heute</string>
    <string name="today_with_time">Heute, %1$s</string>
    <string name="today_with_full_date">%1$s (Heute)</string>
    <string name="tomorrow">Morgen</string>
    <string name="tomorrow_with_time">Morgen, %1$s</string>
    <string name="tomorrow_with_full_date">%1$s (Morgen)</string>

    <!-- Task detail view -->
    <string name="activity_task_details_edit">Bearbeiten</string>
+0 −2
Original line number Diff line number Diff line
@@ -34,10 +34,8 @@
    <!-- date & time string -->
    <string name="today">Today</string>
    <string name="today_with_time">Today, %1$s</string>
    <string name="today_with_full_date">%1$s (Today)</string>
    <string name="tomorrow">Tomorrow</string>
    <string name="tomorrow_with_time">Tomorrow, %1$s</string>
    <string name="tomorrow_with_full_date">%1$s (Tomorrow)</string>

    <!-- Task detail view -->
    <string name="activity_task_details_edit">Edit</string>
+48 −4
Original line number Diff line number Diff line
@@ -47,6 +47,18 @@ public class DateFormatter

	public enum DateFormatContext
	{

		/**
		 * Always uses a relative date. Use this when the date is with the past or next 6 days, otherwise you might get an absolute date.
		 */
		RELATIVE {
			@Override
			public boolean useRelative(Time now, Time date)
			{
				return Math.abs(date.toMillis(false) - now.toMillis(false)) < 7 * 24 * 3600 * 1000;
			}
		},

		/**
		 * The date format in the details view.
		 */
@@ -54,7 +66,7 @@ public class DateFormatter
			@Override
			public int getTodayStringId(Time date)
			{
				return R.string.today_with_full_date;
				return 0;

			}

@@ -62,7 +74,7 @@ public class DateFormatter
			@Override
			public int getTomorrowStringId(Time date)
			{
				return R.string.tomorrow_with_full_date;
				return 0;
			}


@@ -86,14 +98,26 @@ public class DateFormatter
		 * 
		 * Currently this inherits the default short format.
		 */
		LIST_VIEW,
		LIST_VIEW {
			@Override
			public boolean useRelative(Time now, Time date)
			{
				return Math.abs(date.toMillis(false) - now.toMillis(false)) < 7 * 24 * 3600 * 1000;
			}
		},

		/**
		 * The date format in the widget.
		 * 
		 * Currently this inherits the default short format.
		 */
		WIDGET_VIEW,
		WIDGET_VIEW {
			@Override
			public boolean useRelative(Time now, Time date)
			{
				return Math.abs(date.toMillis(false) - now.toMillis(false)) < 7 * 24 * 3600 * 1000;
			}
		},

		/**
		 * The date format in the dash clock. This shows a time only.
@@ -189,6 +213,12 @@ public class DateFormatter
					| DateUtils.FORMAT_ABBREV_WEEKDAY;
			}
		}


		public boolean useRelative(Time now, Time date)
		{
			return false;
		}
	}

	/**
@@ -235,6 +265,20 @@ public class DateFormatter

		boolean isToday = date.year == mNow.year && date.yearDay == mNow.yearDay;

		if (dateContext.useRelative(mNow, date))
		{
			if (date.allDay)
			{
				Time allDayNow = new Time("UTC");
				allDayNow.set(mNow.monthDay, mNow.month, mNow.year);
				return DateUtils.getRelativeTimeSpanString(date.toMillis(false), allDayNow.toMillis(false), DateUtils.DAY_IN_MILLIS).toString();
			}
			else
			{
				return DateUtils.getRelativeTimeSpanString(date.toMillis(false), mNow.toMillis(false), DateUtils.MINUTE_IN_MILLIS).toString();
			}
		}

		if (isToday)
		{
			int stringId = dateContext.getTodayStringId(date);