show last-seen info in profile

This commit is contained in:
adbenitez
2021-11-22 23:11:42 -05:00
parent 22fced3fa5
commit c7956abbaf
3 changed files with 21 additions and 13 deletions
+2
View File
@@ -85,6 +85,8 @@
<string name="this_month">This month</string>
<string name="last_week">Last week</string>
<string name="last_month">Last month</string>
<string name="last_seen_at">Last seen at %1$s</string>
<string name="last_seen_never">Last seen: never</string>
<!-- Translators: show beside messages that are "N minutes old". prefer a short string, prefer abbreviations if they're well-known -->
<plurals name="n_minutes">
<item quantity="one">%d min</item>
@@ -19,6 +19,7 @@ import com.b44t.messenger.DcLot;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.contacts.ContactSelectionListItem;
import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.StickyHeaderDecoration.StickyHeaderAdapter;
import java.util.ArrayList;
@@ -235,11 +236,12 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter
txt = context.getString(R.string.profile_shared_chats);
break;
case ItemData.TYPE_PRIMARY_SETTING:
if(itemDataContact!=null && itemDataContact.isVerified()) {
txt = context.getString(R.string.verified_contact);
long lastSeen = (itemDataContact!=null? itemDataContact.getLastSeen() : 0);
if(lastSeen==0) {
txt = context.getString(R.string.last_seen_never);
}
else {
txt = context.getString(R.string.contact);
txt = context.getString(R.string.last_seen_at, DateUtils.getExtendedTimeSpanString(context, locale, lastSeen));
}
break;
case ItemData.TYPE_STATUS:
@@ -77,6 +77,19 @@ public class DateUtils extends android.text.format.DateUtils {
}
}
public static String getExtendedTimeSpanString(final Context c, final Locale locale, final long timestamp) {
StringBuilder format = new StringBuilder();
if (DateUtils.isToday(timestamp)) {}
else if (isWithin(timestamp, 6, TimeUnit.DAYS)) format.append("EEE ");
else if (isWithin(timestamp, 365, TimeUnit.DAYS)) format.append("MMM d, ");
else format.append("MMM d, yyyy, ");
if (DateFormat.is24HourFormat(c)) format.append("HH:mm");
else format.append("hh:mm a");
return getFormattedDateTime(timestamp, format.toString(), locale);
}
public static String getExtendedRelativeTimeSpanString(final Context c, final Locale locale, final long timestamp) {
if (isWithin(timestamp, 1, TimeUnit.MINUTES)) {
return c.getString(R.string.now);
@@ -84,16 +97,7 @@ public class DateUtils extends android.text.format.DateUtils {
int mins = (int)TimeUnit.MINUTES.convert(System.currentTimeMillis() - timestamp, TimeUnit.MILLISECONDS);
return c.getResources().getQuantityString(R.plurals.n_minutes, mins, mins);
} else {
StringBuilder format = new StringBuilder();
if (DateUtils.isToday(timestamp)) {}
else if (isWithin(timestamp, 6, TimeUnit.DAYS)) format.append("EEE ");
else if (isWithin(timestamp, 365, TimeUnit.DAYS)) format.append("MMM d, ");
else format.append("MMM d, yyyy, ");
if (DateFormat.is24HourFormat(c)) format.append("HH:mm");
else format.append("hh:mm a");
return getFormattedDateTime(timestamp, format.toString(), locale);
return getExtendedTimeSpanString(c, locale, timestamp);
}
}