From 79db294ca235129b0c00ed9034ce158079c6aff2 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Sun, 22 Nov 2020 14:22:18 -0300 Subject: [PATCH] Use human-readable relative times in LoadGameActivity. When loading a saved game, display the last time played in human readable relative time. For example, "5 minutes ago" or "Yesterday". This matches the template from list_entry_layout.xml The current implementation writes the date in full, including day, month, year, hours, minutes, and seconds. Not only is that more information than we really need, but in devices with a narrower screen this can cause the date to be drawn on top of the difficulty. --- .../privacyfriendlysudoku/ui/LoadGameActivity.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/LoadGameActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/LoadGameActivity.java index 5f47dc3..7ca9a92 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/LoadGameActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/LoadGameActivity.java @@ -26,6 +26,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; +import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -260,12 +261,11 @@ public class LoadGameActivity extends BaseActivity implements IDeleteDialogFragm h = (hours< 10)? "0"+String.valueOf(hours):String.valueOf(hours); playedTime.setText(h + ":" + m + ":" + s); - Date lastTimePlayedDate = gic.getLastTimePlayed(); - - DateFormat format = DateFormat.getDateTimeInstance(); - format.setTimeZone(TimeZone.getDefault()); - - lastTimePlayed.setText(format.format(lastTimePlayedDate)); + long now = System.currentTimeMillis(); + long lastTimePlayedTimestamp = gic.getLastTimePlayed().getTime(); + CharSequence humanReadableRelativeTime = DateUtils.getRelativeTimeSpanString( + lastTimePlayedTimestamp, now, DateUtils.MINUTE_IN_MILLIS); + lastTimePlayed.setText(humanReadableRelativeTime); return convertView; }