Show absolute time in Notifications tab

main
kyori 6 years ago
parent 040b8be606
commit 3106cfc6b0
  1. 21
      app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java

@ -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,7 +369,21 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
username.setText(usernameText);
}
private void setCreatedAt(@Nullable Date createdAt) {
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 {
// This is the visible timestampInfo.
String readout;
/* This one is for screen-readers. Frequently, they would mispronounce timestamps like "17m"
@ -386,6 +404,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
timestampInfo.setText(readout);
timestampInfo.setContentDescription(readoutAloud);
}
}
void setMessage(NotificationViewData.Concrete notificationViewData, LinkListener listener, BidiFormatter bidiFormatter) {
this.statusViewData = notificationViewData.getStatusViewData();

Loading…
Cancel
Save