From ad888854bc34ea5f78745266a29b27552d06e0d7 Mon Sep 17 00:00:00 2001 From: kyori Date: Mon, 20 Aug 2018 20:56:22 +0900 Subject: [PATCH] Use SimpleDateFormatter repeatedly. --- .../tusky/adapter/NotificationsAdapter.java | 14 +++++++++----- .../tusky/adapter/StatusBaseViewHolder.java | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java index 4c937c4d..248aa047 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java @@ -328,6 +328,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter { private StatusViewData.Concrete statusViewData; private boolean useAbsoluteTime; + private SimpleDateFormat sdf; + private boolean passed1day; StatusNotificationViewHolder(View itemView, boolean useAbsoluteTime) { super(itemView); @@ -353,6 +355,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter { contentWarningButton.setOnCheckedChangeListener(this); this.useAbsoluteTime = useAbsoluteTime; + sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()); + passed1day = false; } private void showNotificationContent(boolean show) { @@ -381,11 +385,11 @@ public class NotificationsAdapter extends RecyclerView.Adapter { if (useAbsoluteTime) { String time; 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()); + if (!passed1day) { + if (new Date().getTime() - createdAt.getTime() > 86400000L) { + passed1day = true; + sdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault()); + } } time = sdf.format(createdAt); } else { diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index 185156f9..d3e0772b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -67,6 +67,8 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { TextView contentWarningDescription; private boolean useAbsoluteTime; + private SimpleDateFormat sdf; + private boolean passed1day; StatusBaseViewHolder(View itemView, boolean useAbsoluteTime) { super(itemView); @@ -97,6 +99,8 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { contentWarningButton = itemView.findViewById(R.id.status_content_warning_button); this.useAbsoluteTime = useAbsoluteTime; + sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()); + passed1day = false; } protected abstract int getMediaPreviewHeight(Context context); @@ -135,11 +139,11 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { if (useAbsoluteTime) { String time; 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()); + if (!passed1day) { + if (new Date().getTime() - createdAt.getTime() > 86400000L) { + passed1day = true; + sdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault()); + } } time = sdf.format(createdAt); } else {