From c85a8bbb387b81fa3bad242084e47d6eab72cdf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Emir?= Date: Sun, 13 Apr 2014 01:53:05 +0200 Subject: [PATCH] Always show the time of the received message. --- .../securesms/util/DateUtils.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/org/thoughtcrime/securesms/util/DateUtils.java b/src/org/thoughtcrime/securesms/util/DateUtils.java index 229be41d30..c55b44df73 100644 --- a/src/org/thoughtcrime/securesms/util/DateUtils.java +++ b/src/org/thoughtcrime/securesms/util/DateUtils.java @@ -1,11 +1,25 @@ +/** + * Copyright (C) 2014 Open Whisper Systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.thoughtcrime.securesms.util; import android.content.Context; -import java.util.Calendar; - /** - * Created by kaonashi on 1/6/14. + * Utility methods to help display dates in a nice, easily readable way. */ public class DateUtils extends android.text.format.DateUtils { @@ -22,19 +36,16 @@ public class DateUtils extends android.text.format.DateUtils { } public static String getBetterRelativeTimeSpanString(final Context c, final long millis) { - final String prettyDate; - if (isToday(millis)) { - prettyDate = DateUtils.formatDateTime(c, millis, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_TIME); - } else if (isWithinWeek(millis)) { - prettyDate = DateUtils.formatDateTime(c, millis, - DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_SHOW_TIME); - } else if (isWithinYear(millis)) { - prettyDate = DateUtils.formatDateTime(c, millis, - DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_ABBREV_ALL); - } else { - prettyDate = DateUtils.formatDateTime(c, millis, - DateUtils.FORMAT_NUMERIC_DATE); + int formatFlags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_TIME; + if (!isToday(millis)) { + if (isWithinWeek(millis)) { + formatFlags |= DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY; + } else if (isWithinYear(millis)) { + formatFlags |= DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_ABBREV_ALL; + } else { + formatFlags |= DateUtils.FORMAT_NUMERIC_DATE; + } } - return prettyDate; + return DateUtils.formatDateTime(c, millis, formatFlags); } }