diff --git a/app/src/main/java/com/gh/common/util/NewsUtils.java b/app/src/main/java/com/gh/common/util/NewsUtils.java index 02ec919dd7..77c9526d01 100644 --- a/app/src/main/java/com/gh/common/util/NewsUtils.java +++ b/app/src/main/java/com/gh/common/util/NewsUtils.java @@ -118,57 +118,12 @@ public class NewsUtils { * 设置新闻发布时间 */ public static void setNewsPublishOn(TextView textView, long time) { - time = time * 1000; - SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); - try { - long today = format.parse(format.format(new Date())).getTime(); - if (time >= today && time < today + 86400 * 1000) { - format.applyPattern("HH:mm"); - textView.setText(format.format(time)); - } else if (time >= today - 86400 * 1000 && time < today) { - format.applyPattern("HH:mm"); - textView.setText(String.format("昨天 %s", format.format(time))); - } else { - format.applyPattern("yyyy年MM月dd日 HH:mm"); - textView.setText(format.format(time)); - } - } catch (ParseException e) { - e.printStackTrace(); - format.applyPattern("yyyy年MM月dd日 HH:mm"); - textView.setText(format.format(time)); - } + CommentUtils.setCommentTime(textView, time); } public static void setNewsDetailTime(TextView textView, long time) { - SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); - try { - long today = format.parse(format.format(new Date())).getTime(); - long day = time * 1000; - if (day >= today && day < today + 86400 * 1000) { - long min = new Date().getTime() / 1000 - day / 1000; - int hour = (int) (min / (60 * 60)); - if (hour == 0) { - if (min < 60) { - textView.setText("刚刚"); - } else { - textView.setText(String.format(Locale.getDefault(), "%d分钟前", (int) (min / 60))); - } - } else { - textView.setText(String.format(Locale.getDefault(), "%d小时前", hour)); - } - } else if (day >= today - 86400 * 1000 * 100 && day < today) { - format.applyPattern("HH:mm"); - textView.setText("昨天 "); - } else { - format.applyPattern("yyyy-MM-dd"); - textView.setText(format.format(day)); - } - } catch (ParseException e) { - e.printStackTrace(); - format.applyPattern("yyyy-MM-dd"); - textView.setText(format.format(time * 1000)); - } + CommentUtils.setCommentTime(textView, time); } public static String getFormattedTime(long time) {