From 8801cfcf6ab3848f11bbd5f458cb252366035d8b Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 20 Jul 2014 07:34:33 +0200 Subject: refactoring: reduce package cycles --- main/src/cgeo/geocaching/CacheDetailActivity.java | 2 +- main/src/cgeo/geocaching/CompassActivity.java | 2 +- main/src/cgeo/geocaching/Geocache.java | 2 +- main/src/cgeo/geocaching/LogCacheActivity.java | 2 +- main/src/cgeo/geocaching/LogTrackableActivity.java | 2 +- main/src/cgeo/geocaching/MainActivity.java | 2 +- .../cgeo/geocaching/NavigateAnyPointActivity.java | 2 +- main/src/cgeo/geocaching/TrackableActivity.java | 2 +- main/src/cgeo/geocaching/connector/gc/GCMap.java | 2 +- .../geocaching/connector/gc/UncertainProperty.java | 52 ++++++ .../cgeo/geocaching/export/FieldnoteExport.java | 2 +- .../cgeo/geocaching/ui/CacheDetailsCreator.java | 1 + main/src/cgeo/geocaching/ui/CacheListAdapter.java | 1 + main/src/cgeo/geocaching/ui/Formatter.java | 191 --------------------- .../cgeo/geocaching/ui/logs/LogsViewCreator.java | 2 +- .../cgeo/geocaching/utils/DatabaseBackupUtils.java | 1 - main/src/cgeo/geocaching/utils/Formatter.java | 191 +++++++++++++++++++++ .../cgeo/geocaching/utils/LogTemplateProvider.java | 1 - .../cgeo/geocaching/utils/UncertainProperty.java | 53 ------ 19 files changed, 256 insertions(+), 257 deletions(-) create mode 100644 main/src/cgeo/geocaching/connector/gc/UncertainProperty.java delete mode 100644 main/src/cgeo/geocaching/ui/Formatter.java create mode 100644 main/src/cgeo/geocaching/utils/Formatter.java delete mode 100644 main/src/cgeo/geocaching/utils/UncertainProperty.java (limited to 'main/src') diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 7d044e7..7115805 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -32,7 +32,6 @@ import cgeo.geocaching.ui.CoordinatesFormatSwitcher; import cgeo.geocaching.ui.DecryptTextClickListener; import cgeo.geocaching.ui.EditNoteDialog; import cgeo.geocaching.ui.EditNoteDialog.EditNoteDialogListener; -import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.HtmlImageCounter; import cgeo.geocaching.ui.ImagesList; import cgeo.geocaching.ui.IndexOutOfBoundsAvoidingTextView; @@ -43,6 +42,7 @@ import cgeo.geocaching.ui.dialog.Dialogs; import cgeo.geocaching.ui.logs.CacheLogsViewCreator; import cgeo.geocaching.utils.CancellableHandler; import cgeo.geocaching.utils.CryptUtils; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.ImageUtils; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.MatcherWrapper; diff --git a/main/src/cgeo/geocaching/CompassActivity.java b/main/src/cgeo/geocaching/CompassActivity.java index 14b33b6..025d938 100644 --- a/main/src/cgeo/geocaching/CompassActivity.java +++ b/main/src/cgeo/geocaching/CompassActivity.java @@ -14,8 +14,8 @@ import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.speech.SpeechService; import cgeo.geocaching.ui.CompassView; -import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.LoggingUI; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.Log; import org.apache.commons.lang3.StringUtils; diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 489c70c..e0daae1 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -11,6 +11,7 @@ import cgeo.geocaching.connector.capability.ISearchByGeocode; import cgeo.geocaching.connector.gc.GCConnector; import cgeo.geocaching.connector.gc.GCConstants; import cgeo.geocaching.connector.gc.Tile; +import cgeo.geocaching.connector.gc.UncertainProperty; import cgeo.geocaching.enumerations.CacheAttribute; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; @@ -34,7 +35,6 @@ import cgeo.geocaching.utils.LogTemplateProvider; import cgeo.geocaching.utils.LogTemplateProvider.LogContext; import cgeo.geocaching.utils.MatcherWrapper; import cgeo.geocaching.utils.RxUtils; -import cgeo.geocaching.utils.UncertainProperty; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; diff --git a/main/src/cgeo/geocaching/LogCacheActivity.java b/main/src/cgeo/geocaching/LogCacheActivity.java index 09f76b5..b4facd7 100644 --- a/main/src/cgeo/geocaching/LogCacheActivity.java +++ b/main/src/cgeo/geocaching/LogCacheActivity.java @@ -12,11 +12,11 @@ import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.gcvote.GCVote; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.twitter.Twitter; -import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.dialog.DateDialog; import cgeo.geocaching.ui.dialog.Dialogs; import cgeo.geocaching.utils.AsyncTaskWithProgress; import cgeo.geocaching.utils.DateUtils; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.LogTemplateProvider; import cgeo.geocaching.utils.LogTemplateProvider.LogContext; diff --git a/main/src/cgeo/geocaching/LogTrackableActivity.java b/main/src/cgeo/geocaching/LogTrackableActivity.java index a531130..a712891 100644 --- a/main/src/cgeo/geocaching/LogTrackableActivity.java +++ b/main/src/cgeo/geocaching/LogTrackableActivity.java @@ -11,9 +11,9 @@ import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.twitter.Twitter; -import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.dialog.DateDialog; import cgeo.geocaching.ui.dialog.Dialogs; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.LogTemplateProvider.LogContext; diff --git a/main/src/cgeo/geocaching/MainActivity.java b/main/src/cgeo/geocaching/MainActivity.java index a3be760..2d6e9f0 100644 --- a/main/src/cgeo/geocaching/MainActivity.java +++ b/main/src/cgeo/geocaching/MainActivity.java @@ -19,9 +19,9 @@ import cgeo.geocaching.sensors.GeoDirHandler; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.SettingsActivity; -import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.dialog.Dialogs; import cgeo.geocaching.utils.DatabaseBackupUtils; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.RxUtils; import cgeo.geocaching.utils.TextUtils; diff --git a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java index 415c7a6..48e0c17 100644 --- a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java +++ b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java @@ -13,9 +13,9 @@ import cgeo.geocaching.sensors.GeoDirHandler; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.ui.AbstractViewHolder; -import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.dialog.CoordinatesInputDialog; import cgeo.geocaching.ui.dialog.Dialogs; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.Log; import org.apache.commons.lang3.StringUtils; diff --git a/main/src/cgeo/geocaching/TrackableActivity.java b/main/src/cgeo/geocaching/TrackableActivity.java index 6cc7374..00f3716 100644 --- a/main/src/cgeo/geocaching/TrackableActivity.java +++ b/main/src/cgeo/geocaching/TrackableActivity.java @@ -14,10 +14,10 @@ import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.ui.AbstractCachingPageViewCreator; import cgeo.geocaching.ui.AnchorAwareLinkMovementMethod; import cgeo.geocaching.ui.CacheDetailsCreator; -import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.UserActionsClickListener; import cgeo.geocaching.ui.UserNameClickListener; import cgeo.geocaching.ui.logs.TrackableLogsViewCreator; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.HtmlUtils; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.UnknownTagsHandler; diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java index 1ab642e..27ce06e 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCMap.java +++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java @@ -15,7 +15,7 @@ import cgeo.geocaching.geopoint.Units; import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.settings.Settings; -import cgeo.geocaching.ui.Formatter; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.LeastRecentlyUsedMap; import cgeo.geocaching.utils.Log; diff --git a/main/src/cgeo/geocaching/connector/gc/UncertainProperty.java b/main/src/cgeo/geocaching/connector/gc/UncertainProperty.java new file mode 100644 index 0000000..71adcbd --- /dev/null +++ b/main/src/cgeo/geocaching/connector/gc/UncertainProperty.java @@ -0,0 +1,52 @@ +package cgeo.geocaching.connector.gc; + + +/** + * Property with certainty. When merging properties, the one with higher certainty wins. + * + * @param + */ +public class UncertainProperty { + + private final T value; + private final int certaintyLevel; + + public UncertainProperty(T value) { + this(value, Tile.ZOOMLEVEL_MAX + 1); + } + + public UncertainProperty(T value, int certaintyLevel) { + this.value = value; + this.certaintyLevel = certaintyLevel; + } + + public T getValue() { + return value; + } + + public int getCertaintyLevel() { + return certaintyLevel; + } + + public UncertainProperty getMergedProperty(final UncertainProperty other) { + if (null == other || null == other.value) { + return this; + } + if (null == this.value) { + return other; + } + if (other.certaintyLevel > certaintyLevel) { + return other; + } + + return this; + } + + public static UncertainProperty getMergedProperty(UncertainProperty property, UncertainProperty otherProperty) { + if (null == property) { + return otherProperty; + } + return property.getMergedProperty(otherProperty); + } + +} diff --git a/main/src/cgeo/geocaching/export/FieldnoteExport.java b/main/src/cgeo/geocaching/export/FieldnoteExport.java index f6f27c6..c03b848 100644 --- a/main/src/cgeo/geocaching/export/FieldnoteExport.java +++ b/main/src/cgeo/geocaching/export/FieldnoteExport.java @@ -11,8 +11,8 @@ import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; import cgeo.geocaching.connector.capability.FieldNotesCapability; import cgeo.geocaching.settings.Settings; -import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.utils.AsyncTaskWithProgress; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.Log; import android.app.Activity; diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java index 8a7f167..78e1dec 100644 --- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java +++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java @@ -9,6 +9,7 @@ import cgeo.geocaching.Waypoint; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Units; +import cgeo.geocaching.utils.Formatter; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index 5b1bd61..6cd9e29 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -19,6 +19,7 @@ import cgeo.geocaching.sorting.InverseComparator; import cgeo.geocaching.sorting.VisitComparator; import cgeo.geocaching.utils.AngleUtils; import cgeo.geocaching.utils.DateUtils; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.Log; import org.apache.commons.collections4.CollectionUtils; diff --git a/main/src/cgeo/geocaching/ui/Formatter.java b/main/src/cgeo/geocaching/ui/Formatter.java deleted file mode 100644 index 4720e31..0000000 --- a/main/src/cgeo/geocaching/ui/Formatter.java +++ /dev/null @@ -1,191 +0,0 @@ -package cgeo.geocaching.ui; - -import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.Geocache; -import cgeo.geocaching.R; -import cgeo.geocaching.Waypoint; -import cgeo.geocaching.enumerations.CacheListType; -import cgeo.geocaching.enumerations.CacheSize; -import cgeo.geocaching.enumerations.WaypointType; - -import org.apache.commons.lang3.StringUtils; - -import android.content.Context; -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 { - - /** Text separator used for formatting texts */ - public static final String SEPARATOR = " · "; - - private static final Context context = CgeoApplication.getInstance().getBaseContext(); - - /** - * Generate a time string according to system-wide settings (locale, 12/24 hour) - * such as "13:24". - * - * @param date - * milliseconds since the epoch - * @return the formatted string - */ - public static String formatTime(long date) { - return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_TIME); - } - - /** - * Generate a date string according to system-wide settings (locale, date format) - * such as "20 December" or "20 December 2010". The year will only be included when necessary. - * - * @param date - * milliseconds since the epoch - * @return the formatted string - */ - public static String formatDate(long date) { - return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE); - } - - /** - * Generate a date string according to system-wide settings (locale, date format) - * such as "20 December 2010". The year will always be included, making it suitable - * to generate long-lived log entries. - * - * @param date - * milliseconds since the epoch - * @return the formatted string - */ - public static String formatFullDate(long date) { - return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE - | DateUtils.FORMAT_SHOW_YEAR); - } - - /** - * Generate a numeric date string according to system-wide settings (locale, date format) - * such as "10/20/2010". - * - * @param date - * milliseconds since the epoch - * @return the formatted string - */ - public static String formatShortDate(long date) { - DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context); - return dateFormat.format(date); - } - - /** - * Generate a numeric date string according to system-wide settings (locale, date format) - * such as "10/20/2010". Today and yesterday will be presented as strings "today" and "yesterday". - * - * @param date - * milliseconds since the epoch - * @return the formatted string - */ - public static String formatShortDateVerbally(long date) { - int diff = cgeo.geocaching.utils.DateUtils.daysSince(date); - switch (diff) { - case 0: - return CgeoApplication.getInstance().getString(R.string.log_today); - case 1: - return CgeoApplication.getInstance().getString(R.string.log_yesterday); - default: - return formatShortDate(date); - } - } - - /** - * Generate a numeric date and time string according to system-wide settings (locale, - * date format) such as "7 sept. at 12:35". - * - * @param date - * milliseconds since the epoch - * @return the formatted string - */ - public static String formatShortDateTime(long date) { - 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 infos = new ArrayList<>(); - if (StringUtils.isNotBlank(cache.getGeocode())) { - infos.add(cache.getGeocode()); - } - - addShortInfos(cache, infos); - - if (cache.isPremiumMembersOnly()) { - 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)); - } - return StringUtils.join(infos, Formatter.SEPARATOR); - } - - public static String formatCacheInfoShort(Geocache cache) { - final ArrayList infos = new ArrayList<>(); - addShortInfos(cache, infos); - return StringUtils.join(infos, Formatter.SEPARATOR); - } - - private static void addShortInfos(Geocache cache, final ArrayList infos) { - if (cache.hasDifficulty()) { - infos.add("D " + String.format("%.1f", cache.getDifficulty())); - } - if (cache.hasTerrain()) { - infos.add("T " + String.format("%.1f", cache.getTerrain())); - } - - // 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()) { - final Date hiddenDate = cache.getHiddenDate(); - if (hiddenDate != null) { - infos.add(Formatter.formatShortDate(hiddenDate.getTime())); - } - } - } - - public static String formatCacheInfoHistory(Geocache cache) { - final ArrayList infos = new ArrayList<>(3); - infos.add(StringUtils.upperCase(cache.getGeocode())); - infos.add(Formatter.formatDate(cache.getVisitedDate())); - infos.add(Formatter.formatTime(cache.getVisitedDate())); - return StringUtils.join(infos, Formatter.SEPARATOR); - } - - public static String formatWaypointInfo(Waypoint waypoint) { - final List infos = new ArrayList<>(3); - WaypointType waypointType = waypoint.getWaypointType(); - if (waypointType != WaypointType.OWN && waypointType != null) { - infos.add(waypointType.getL10n()); - } - if (Waypoint.PREFIX_OWN.equalsIgnoreCase(waypoint.getPrefix())) { - infos.add(CgeoApplication.getInstance().getString(R.string.waypoint_custom)); - } else { - if (StringUtils.isNotBlank(waypoint.getPrefix())) { - infos.add(waypoint.getPrefix()); - } - if (StringUtils.isNotBlank(waypoint.getLookup())) { - infos.add(waypoint.getLookup()); - } - } - return StringUtils.join(infos, Formatter.SEPARATOR); - } -} diff --git a/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java b/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java index 020b895..e951394 100644 --- a/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java +++ b/main/src/cgeo/geocaching/ui/logs/LogsViewCreator.java @@ -10,9 +10,9 @@ import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.ui.AbstractCachingListViewPageViewCreator; import cgeo.geocaching.ui.AnchorAwareLinkMovementMethod; import cgeo.geocaching.ui.DecryptTextClickListener; -import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.HtmlImageCounter; import cgeo.geocaching.ui.UserActionsClickListener; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.TextUtils; import cgeo.geocaching.utils.UnknownTagsHandler; diff --git a/main/src/cgeo/geocaching/utils/DatabaseBackupUtils.java b/main/src/cgeo/geocaching/utils/DatabaseBackupUtils.java index 14840b9..d8aff74 100644 --- a/main/src/cgeo/geocaching/utils/DatabaseBackupUtils.java +++ b/main/src/cgeo/geocaching/utils/DatabaseBackupUtils.java @@ -3,7 +3,6 @@ package cgeo.geocaching.utils; import cgeo.geocaching.DataStore; import cgeo.geocaching.MainActivity; import cgeo.geocaching.R; -import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.dialog.Dialogs; import org.apache.commons.lang3.StringUtils; diff --git a/main/src/cgeo/geocaching/utils/Formatter.java b/main/src/cgeo/geocaching/utils/Formatter.java new file mode 100644 index 0000000..3068cd4 --- /dev/null +++ b/main/src/cgeo/geocaching/utils/Formatter.java @@ -0,0 +1,191 @@ +package cgeo.geocaching.utils; + +import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.Geocache; +import cgeo.geocaching.R; +import cgeo.geocaching.Waypoint; +import cgeo.geocaching.enumerations.CacheListType; +import cgeo.geocaching.enumerations.CacheSize; +import cgeo.geocaching.enumerations.WaypointType; + +import org.apache.commons.lang3.StringUtils; + +import android.content.Context; +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 { + + /** Text separator used for formatting texts */ + public static final String SEPARATOR = " · "; + + private static final Context context = CgeoApplication.getInstance().getBaseContext(); + + /** + * Generate a time string according to system-wide settings (locale, 12/24 hour) + * such as "13:24". + * + * @param date + * milliseconds since the epoch + * @return the formatted string + */ + public static String formatTime(long date) { + return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_TIME); + } + + /** + * Generate a date string according to system-wide settings (locale, date format) + * such as "20 December" or "20 December 2010". The year will only be included when necessary. + * + * @param date + * milliseconds since the epoch + * @return the formatted string + */ + public static String formatDate(long date) { + return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE); + } + + /** + * Generate a date string according to system-wide settings (locale, date format) + * such as "20 December 2010". The year will always be included, making it suitable + * to generate long-lived log entries. + * + * @param date + * milliseconds since the epoch + * @return the formatted string + */ + public static String formatFullDate(long date) { + return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE + | DateUtils.FORMAT_SHOW_YEAR); + } + + /** + * Generate a numeric date string according to system-wide settings (locale, date format) + * such as "10/20/2010". + * + * @param date + * milliseconds since the epoch + * @return the formatted string + */ + public static String formatShortDate(long date) { + DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context); + return dateFormat.format(date); + } + + /** + * Generate a numeric date string according to system-wide settings (locale, date format) + * such as "10/20/2010". Today and yesterday will be presented as strings "today" and "yesterday". + * + * @param date + * milliseconds since the epoch + * @return the formatted string + */ + public static String formatShortDateVerbally(long date) { + int diff = cgeo.geocaching.utils.DateUtils.daysSince(date); + switch (diff) { + case 0: + return CgeoApplication.getInstance().getString(R.string.log_today); + case 1: + return CgeoApplication.getInstance().getString(R.string.log_yesterday); + default: + return formatShortDate(date); + } + } + + /** + * Generate a numeric date and time string according to system-wide settings (locale, + * date format) such as "7 sept. at 12:35". + * + * @param date + * milliseconds since the epoch + * @return the formatted string + */ + public static String formatShortDateTime(long date) { + 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 infos = new ArrayList<>(); + if (StringUtils.isNotBlank(cache.getGeocode())) { + infos.add(cache.getGeocode()); + } + + addShortInfos(cache, infos); + + if (cache.isPremiumMembersOnly()) { + 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)); + } + return StringUtils.join(infos, Formatter.SEPARATOR); + } + + public static String formatCacheInfoShort(Geocache cache) { + final ArrayList infos = new ArrayList<>(); + addShortInfos(cache, infos); + return StringUtils.join(infos, Formatter.SEPARATOR); + } + + private static void addShortInfos(Geocache cache, final ArrayList infos) { + if (cache.hasDifficulty()) { + infos.add("D " + String.format("%.1f", cache.getDifficulty())); + } + if (cache.hasTerrain()) { + infos.add("T " + String.format("%.1f", cache.getTerrain())); + } + + // 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()) { + final Date hiddenDate = cache.getHiddenDate(); + if (hiddenDate != null) { + infos.add(Formatter.formatShortDate(hiddenDate.getTime())); + } + } + } + + public static String formatCacheInfoHistory(Geocache cache) { + final ArrayList infos = new ArrayList<>(3); + infos.add(StringUtils.upperCase(cache.getGeocode())); + infos.add(Formatter.formatDate(cache.getVisitedDate())); + infos.add(Formatter.formatTime(cache.getVisitedDate())); + return StringUtils.join(infos, Formatter.SEPARATOR); + } + + public static String formatWaypointInfo(Waypoint waypoint) { + final List infos = new ArrayList<>(3); + WaypointType waypointType = waypoint.getWaypointType(); + if (waypointType != WaypointType.OWN && waypointType != null) { + infos.add(waypointType.getL10n()); + } + if (Waypoint.PREFIX_OWN.equalsIgnoreCase(waypoint.getPrefix())) { + infos.add(CgeoApplication.getInstance().getString(R.string.waypoint_custom)); + } else { + if (StringUtils.isNotBlank(waypoint.getPrefix())) { + infos.add(waypoint.getPrefix()); + } + if (StringUtils.isNotBlank(waypoint.getLookup())) { + infos.add(waypoint.getLookup()); + } + } + return StringUtils.join(infos, Formatter.SEPARATOR); + } +} diff --git a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java index 8867609..ff4013c 100644 --- a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java +++ b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java @@ -8,7 +8,6 @@ import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; import cgeo.geocaching.connector.capability.ILogin; import cgeo.geocaching.settings.Settings; -import cgeo.geocaching.ui.Formatter; import org.apache.commons.lang3.StringUtils; diff --git a/main/src/cgeo/geocaching/utils/UncertainProperty.java b/main/src/cgeo/geocaching/utils/UncertainProperty.java deleted file mode 100644 index e8686e3..0000000 --- a/main/src/cgeo/geocaching/utils/UncertainProperty.java +++ /dev/null @@ -1,53 +0,0 @@ -package cgeo.geocaching.utils; - -import cgeo.geocaching.connector.gc.Tile; - -/** - * Property with certainty. When merging properties, the one with higher certainty wins. - * - * @param - */ -public class UncertainProperty { - - private final T value; - private final int certaintyLevel; - - public UncertainProperty(T value) { - this(value, Tile.ZOOMLEVEL_MAX + 1); - } - - public UncertainProperty(T value, int certaintyLevel) { - this.value = value; - this.certaintyLevel = certaintyLevel; - } - - public T getValue() { - return value; - } - - public int getCertaintyLevel() { - return certaintyLevel; - } - - public UncertainProperty getMergedProperty(final UncertainProperty other) { - if (null == other || null == other.value) { - return this; - } - if (null == this.value) { - return other; - } - if (other.certaintyLevel > certaintyLevel) { - return other; - } - - return this; - } - - public static UncertainProperty getMergedProperty(UncertainProperty property, UncertainProperty otherProperty) { - if (null == property) { - return otherProperty; - } - return property.getMergedProperty(otherProperty); - } - -} -- cgit v1.1