Use SimpleDateFormatter repeatedly.

This commit is contained in:
kyori 2018-08-20 20:56:22 +09:00
parent 4264fc42d6
commit ad888854bc
2 changed files with 18 additions and 10 deletions

View File

@ -328,6 +328,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
private StatusViewData.Concrete statusViewData; private StatusViewData.Concrete statusViewData;
private boolean useAbsoluteTime; private boolean useAbsoluteTime;
private SimpleDateFormat sdf;
private boolean passed1day;
StatusNotificationViewHolder(View itemView, boolean useAbsoluteTime) { StatusNotificationViewHolder(View itemView, boolean useAbsoluteTime) {
super(itemView); super(itemView);
@ -353,6 +355,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
contentWarningButton.setOnCheckedChangeListener(this); contentWarningButton.setOnCheckedChangeListener(this);
this.useAbsoluteTime = useAbsoluteTime; this.useAbsoluteTime = useAbsoluteTime;
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
passed1day = false;
} }
private void showNotificationContent(boolean show) { private void showNotificationContent(boolean show) {
@ -381,11 +385,11 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
if (useAbsoluteTime) { if (useAbsoluteTime) {
String time; String time;
if (createdAt != null) { if (createdAt != null) {
SimpleDateFormat sdf; if (!passed1day) {
if (new Date().getTime() - createdAt.getTime() > 86400000L) { if (new Date().getTime() - createdAt.getTime() > 86400000L) {
sdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault()); passed1day = true;
} else { sdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault());
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()); }
} }
time = sdf.format(createdAt); time = sdf.format(createdAt);
} else { } else {

View File

@ -67,6 +67,8 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
TextView contentWarningDescription; TextView contentWarningDescription;
private boolean useAbsoluteTime; private boolean useAbsoluteTime;
private SimpleDateFormat sdf;
private boolean passed1day;
StatusBaseViewHolder(View itemView, boolean useAbsoluteTime) { StatusBaseViewHolder(View itemView, boolean useAbsoluteTime) {
super(itemView); super(itemView);
@ -97,6 +99,8 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
contentWarningButton = itemView.findViewById(R.id.status_content_warning_button); contentWarningButton = itemView.findViewById(R.id.status_content_warning_button);
this.useAbsoluteTime = useAbsoluteTime; this.useAbsoluteTime = useAbsoluteTime;
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
passed1day = false;
} }
protected abstract int getMediaPreviewHeight(Context context); protected abstract int getMediaPreviewHeight(Context context);
@ -135,11 +139,11 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
if (useAbsoluteTime) { if (useAbsoluteTime) {
String time; String time;
if (createdAt != null) { if (createdAt != null) {
SimpleDateFormat sdf; if (!passed1day) {
if (new Date().getTime() - createdAt.getTime() > 86400000L) { if (new Date().getTime() - createdAt.getTime() > 86400000L) {
sdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault()); passed1day = true;
} else { sdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault());
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()); }
} }
time = sdf.format(createdAt); time = sdf.format(createdAt);
} else { } else {