Show absolute time in Notifications tab

This commit is contained in:
kyori 2018-08-16 23:10:21 +09:00
parent ca3a5791e3
commit 1d657a65a7

View file

@ -16,10 +16,12 @@
package com.keylesspalace.tusky.adapter;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
@ -50,9 +52,11 @@ import com.keylesspalace.tusky.viewdata.NotificationViewData;
import com.keylesspalace.tusky.viewdata.StatusViewData;
import com.squareup.picasso.Picasso;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
public class NotificationsAdapter extends RecyclerView.Adapter {
private static final int VIEW_TYPE_MENTION = 0;
@ -365,26 +369,41 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
username.setText(usernameText);
}
private void setCreatedAt(@Nullable Date createdAt) {
// This is the visible timestampInfo.
String readout;
/* This one is for screen-readers. Frequently, they would mispronounce timestamps like "17m"
* as 17 meters instead of minutes. */
CharSequence readoutAloud;
if (createdAt != null) {
long then = createdAt.getTime();
long now = new Date().getTime();
readout = DateUtils.getRelativeTimeSpanString(timestampInfo.getContext(), then, now);
readoutAloud = android.text.format.DateUtils.getRelativeTimeSpanString(then, now,
android.text.format.DateUtils.SECOND_IN_MILLIS,
android.text.format.DateUtils.FORMAT_ABBREV_RELATIVE);
protected void setCreatedAt(@Nullable Date createdAt) {
SharedPreferences defPrefs = PreferenceManager.getDefaultSharedPreferences(timestampInfo.getContext());
if (defPrefs.getBoolean("absoluteTimeView", true)) {
String time = "ERROR!";
if (createdAt != null) {
SimpleDateFormat sdf;
if (new Date().getTime() - createdAt.getTime() > 86400000L) {
sdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault());
} else {
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
}
time = sdf.format(createdAt);
timestampInfo.setText(time);
}
} else {
// unknown minutes~
readout = "?m";
readoutAloud = "? minutes";
// This is the visible timestampInfo.
String readout;
/* This one is for screen-readers. Frequently, they would mispronounce timestamps like "17m"
* as 17 meters instead of minutes. */
CharSequence readoutAloud;
if (createdAt != null) {
long then = createdAt.getTime();
long now = new Date().getTime();
readout = DateUtils.getRelativeTimeSpanString(timestampInfo.getContext(), then, now);
readoutAloud = android.text.format.DateUtils.getRelativeTimeSpanString(then, now,
android.text.format.DateUtils.SECOND_IN_MILLIS,
android.text.format.DateUtils.FORMAT_ABBREV_RELATIVE);
} else {
// unknown minutes~
readout = "?m";
readoutAloud = "? minutes";
}
timestampInfo.setText(readout);
timestampInfo.setContentDescription(readoutAloud);
}
timestampInfo.setText(readout);
timestampInfo.setContentDescription(readoutAloud);
}
void setMessage(NotificationViewData.Concrete notificationViewData, LinkListener listener, BidiFormatter bidiFormatter) {