diff options
Diffstat (limited to 'main/src/cgeo/geocaching/ui/Formatter.java')
| -rw-r--r-- | main/src/cgeo/geocaching/ui/Formatter.java | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/ui/Formatter.java b/main/src/cgeo/geocaching/ui/Formatter.java index ecae9ea..9242b9a 100644 --- a/main/src/cgeo/geocaching/ui/Formatter.java +++ b/main/src/cgeo/geocaching/ui/Formatter.java @@ -1,9 +1,9 @@ package cgeo.geocaching.ui; +import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; -import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.enumerations.CacheListType; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.WaypointType; @@ -15,6 +15,7 @@ import android.text.format.DateUtils; import java.text.DateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; public abstract class Formatter { @@ -22,7 +23,7 @@ public abstract class Formatter { /** Text separator used for formatting texts */ public static final String SEPARATOR = " ยท "; - private static final Context context = cgeoapplication.getInstance().getBaseContext(); + private static final Context context = CgeoApplication.getInstance().getBaseContext(); /** * Generate a time string according to system-wide settings (locale, 12/24 hour) @@ -87,9 +88,9 @@ public abstract class Formatter { int diff = cgeo.geocaching.utils.DateUtils.daysSince(date); switch (diff) { case 0: - return cgeoapplication.getInstance().getString(R.string.log_today); + return CgeoApplication.getInstance().getString(R.string.log_today); case 1: - return cgeoapplication.getInstance().getString(R.string.log_yesterday); + return CgeoApplication.getInstance().getString(R.string.log_yesterday); default: return formatShortDate(date); } @@ -107,6 +108,18 @@ public abstract class Formatter { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL); } + /** + * Generate a numeric date and time string according to system-wide settings (locale, + * date format) such as "7 september at 12:35". + * + * @param date + * milliseconds since the epoch + * @return the formatted string + */ + public static String formatDateTime(long date) { + return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); + } + public static String formatCacheInfoLong(Geocache cache, CacheListType cacheListType) { final ArrayList<String> infos = new ArrayList<String>(); if (StringUtils.isNotBlank(cache.getGeocode())) { @@ -116,10 +129,10 @@ public abstract class Formatter { addShortInfos(cache, infos); if (cache.isPremiumMembersOnly()) { - infos.add(cgeoapplication.getInstance().getString(R.string.cache_premium)); + infos.add(CgeoApplication.getInstance().getString(R.string.cache_premium)); } if (cacheListType != CacheListType.OFFLINE && cacheListType != CacheListType.HISTORY && cache.getListId() > 0) { - infos.add(cgeoapplication.getInstance().getString(R.string.cache_offline)); + infos.add(CgeoApplication.getInstance().getString(R.string.cache_offline)); } return StringUtils.join(infos, Formatter.SEPARATOR); } @@ -141,8 +154,11 @@ public abstract class Formatter { // don't show "not chosen" for events and virtuals, that should be the normal case if (cache.getSize() != CacheSize.UNKNOWN && cache.showSize()) { infos.add(cache.getSize().getL10n()); - } else if (cache.isEventCache() && cache.getHiddenDate() != null) { - infos.add(Formatter.formatShortDate(cache.getHiddenDate().getTime())); + } else if (cache.isEventCache()) { + final Date hiddenDate = cache.getHiddenDate(); + if (hiddenDate != null) { + infos.add(Formatter.formatShortDate(hiddenDate.getTime())); + } } } @@ -161,7 +177,7 @@ public abstract class Formatter { infos.add(waypointType.getL10n()); } if (Waypoint.PREFIX_OWN.equalsIgnoreCase(waypoint.getPrefix())) { - infos.add(cgeoapplication.getInstance().getString(R.string.waypoint_custom)); + infos.add(CgeoApplication.getInstance().getString(R.string.waypoint_custom)); } else { if (StringUtils.isNotBlank(waypoint.getPrefix())) { infos.add(waypoint.getPrefix()); |
