Always show the time of the received message.

This commit is contained in:
Özgür Emir 2014-04-13 01:53:05 +02:00 committed by Jake McGinty
parent 0f9a6e6296
commit c85a8bbb38

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.thoughtcrime.securesms.util; package org.thoughtcrime.securesms.util;
import android.content.Context; 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 { 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) { public static String getBetterRelativeTimeSpanString(final Context c, final long millis) {
final String prettyDate; int formatFlags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_TIME;
if (isToday(millis)) { if (!isToday(millis)) {
prettyDate = DateUtils.formatDateTime(c, millis, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_TIME); if (isWithinWeek(millis)) {
} else if (isWithinWeek(millis)) { formatFlags |= DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY;
prettyDate = DateUtils.formatDateTime(c, millis, } else if (isWithinYear(millis)) {
DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_SHOW_TIME); formatFlags |= DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_ABBREV_ALL;
} else if (isWithinYear(millis)) { } else {
prettyDate = DateUtils.formatDateTime(c, millis, formatFlags |= DateUtils.FORMAT_NUMERIC_DATE;
DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_ABBREV_ALL); }
} else {
prettyDate = DateUtils.formatDateTime(c, millis,
DateUtils.FORMAT_NUMERIC_DATE);
} }
return prettyDate; return DateUtils.formatDateTime(c, millis, formatFlags);
} }
} }