Always show creation time for own keys, and show as "just now" for new keys

This commit is contained in:
Vincent Breitmoser 2018-03-31 00:13:49 +02:00
parent 5032453dc2
commit a1da52420e
2 changed files with 27 additions and 10 deletions

View file

@ -63,6 +63,8 @@ public class KeySectionedListAdapter extends SectionCursorAdapter<KeySectionedLi
private static final short VIEW_SECTION_TYPE_PRIVATE = 0x0;
private static final short VIEW_SECTION_TYPE_PUBLIC = 0x1;
private static final long JUST_NOW_TIMESPAN = DateUtils.MINUTE_IN_MILLIS * 5;
private String mQuery;
private List<Integer> mSelected;
private KeyListListener mListener;
@ -483,15 +485,8 @@ public class KeySectionedListAdapter extends SectionCursorAdapter<KeySectionedLi
mMainUserId.setTextColor(textColor);
mMainUserIdRest.setTextColor(textColor);
if (keyItem.hasDuplicate()) {
String dateTime = DateUtils.formatDateTime(context,
keyItem.getCreationTime(),
DateUtils.FORMAT_SHOW_DATE
| DateUtils.FORMAT_SHOW_TIME
| DateUtils.FORMAT_SHOW_YEAR
| DateUtils.FORMAT_ABBREV_MONTH);
mCreationDate.setText(context.getString(R.string.label_key_created,
dateTime));
if (keyItem.hasDuplicate() || keyItem.isSecret()) {
mCreationDate.setText(getSecretKeyReadableTime(context, keyItem));
mCreationDate.setTextColor(textColor);
mCreationDate.setVisibility(View.VISIBLE);
} else {
@ -517,6 +512,27 @@ public class KeySectionedListAdapter extends SectionCursorAdapter<KeySectionedLi
}
}
@NonNull
private String getSecretKeyReadableTime(Context context, KeyListCursor keyItem) {
long creationMillis = keyItem.getCreationTime();
boolean allowRelativeTimestamp = keyItem.hasDuplicate();
if (allowRelativeTimestamp) {
long creationAgeMillis = System.currentTimeMillis() - creationMillis;
if (creationAgeMillis < JUST_NOW_TIMESPAN) {
return context.getString(R.string.label_key_created_just_now);
}
}
String dateTime = DateUtils.formatDateTime(context,
creationMillis,
DateUtils.FORMAT_SHOW_DATE
| DateUtils.FORMAT_SHOW_TIME
| DateUtils.FORMAT_SHOW_YEAR
| DateUtils.FORMAT_ABBREV_MONTH);
return context.getString(R.string.label_key_created, dateTime);
}
@Override
public void onClick(View v) {
int pos = getAdapterPosition();

View file

@ -167,7 +167,8 @@
<string name="label_keyservers">"Manage OpenPGP keyservers"</string>
<string name="label_key_id">"Key ID"</string>
<string name="label_key_id_colon">"Key ID:"</string>
<string name="label_key_created">"Key created %s"</string>
<string name="label_key_created">"Created %s"</string>
<string name="label_key_created_just_now">"Created just now"</string>
<string name="label_key_type">"Type"</string>
<string name="label_creation">"Creation"</string>
<string name="label_creation_colon">"Creation:"</string>