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.
This commit is contained in:
Hugo Musso Gualandi 2020-11-22 14:22:18 -03:00
parent de7a3e8f97
commit 79db294ca2

View file

@ -26,6 +26,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.format.DateUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; 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); h = (hours< 10)? "0"+String.valueOf(hours):String.valueOf(hours);
playedTime.setText(h + ":" + m + ":" + s); playedTime.setText(h + ":" + m + ":" + s);
Date lastTimePlayedDate = gic.getLastTimePlayed(); long now = System.currentTimeMillis();
long lastTimePlayedTimestamp = gic.getLastTimePlayed().getTime();
DateFormat format = DateFormat.getDateTimeInstance(); CharSequence humanReadableRelativeTime = DateUtils.getRelativeTimeSpanString(
format.setTimeZone(TimeZone.getDefault()); lastTimePlayedTimestamp, now, DateUtils.MINUTE_IN_MILLIS);
lastTimePlayed.setText(humanReadableRelativeTime);
lastTimePlayed.setText(format.format(lastTimePlayedDate));
return convertView; return convertView;
} }