Prevent creating new object in setCreatedAt

This commit is contained in:
kyori 2018-08-20 22:51:30 +09:00
parent ad888854bc
commit 589188e27d
2 changed files with 16 additions and 20 deletions

View file

@ -328,8 +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 SimpleDateFormat shortSdf;
private boolean passed1day; private SimpleDateFormat longSdf;
StatusNotificationViewHolder(View itemView, boolean useAbsoluteTime) { StatusNotificationViewHolder(View itemView, boolean useAbsoluteTime) {
super(itemView); super(itemView);
@ -355,8 +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()); shortSdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
passed1day = false; longSdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault());
} }
private void showNotificationContent(boolean show) { private void showNotificationContent(boolean show) {
@ -385,13 +385,11 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
if (useAbsoluteTime) { if (useAbsoluteTime) {
String time; String time;
if (createdAt != null) { if (createdAt != null) {
if (!passed1day) { if (System.currentTimeMillis() - createdAt.getTime() > 86400000L) {
if (new Date().getTime() - createdAt.getTime() > 86400000L) { time = longSdf.format(createdAt);
passed1day = true; } else {
sdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault()); time = shortSdf.format(createdAt);
}
} }
time = sdf.format(createdAt);
} else { } else {
time = "??:??:??"; time = "??:??:??";
} }

View file

@ -67,8 +67,8 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
TextView contentWarningDescription; TextView contentWarningDescription;
private boolean useAbsoluteTime; private boolean useAbsoluteTime;
private SimpleDateFormat sdf; private SimpleDateFormat shortSdf;
private boolean passed1day; private SimpleDateFormat longSdf;
StatusBaseViewHolder(View itemView, boolean useAbsoluteTime) { StatusBaseViewHolder(View itemView, boolean useAbsoluteTime) {
super(itemView); super(itemView);
@ -99,8 +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()); shortSdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
passed1day = false; longSdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault());
} }
protected abstract int getMediaPreviewHeight(Context context); protected abstract int getMediaPreviewHeight(Context context);
@ -139,13 +139,11 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
if (useAbsoluteTime) { if (useAbsoluteTime) {
String time; String time;
if (createdAt != null) { if (createdAt != null) {
if (!passed1day) { if (System.currentTimeMillis() - createdAt.getTime() > 86400000L) {
if (new Date().getTime() - createdAt.getTime() > 86400000L) { time = longSdf.format(createdAt);
passed1day = true; } else {
sdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault()); time = shortSdf.format(createdAt);
}
} }
time = sdf.format(createdAt);
} else { } else {
time = "??:??:??"; time = "??:??:??";
} }