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