aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2012-06-01 08:10:01 +0200
committerBananeweizen <bananeweizen@gmx.de>2012-06-01 08:10:01 +0200
commit47ff78ef9f780da1880b1997c68cf55f444b3f86 (patch)
tree246a3408ffc474c10b6cbafdf1b20688a6fd67f2 /main/src/cgeo/geocaching
parent55546fcc11cb011245566907651f93e1b25ff29a (diff)
downloadcgeo-47ff78ef9f780da1880b1997c68cf55f444b3f86.zip
cgeo-47ff78ef9f780da1880b1997c68cf55f444b3f86.tar.gz
cgeo-47ff78ef9f780da1880b1997c68cf55f444b3f86.tar.bz2
fix #1658: show today literally
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r--main/src/cgeo/geocaching/LogEntry.java12
-rw-r--r--main/src/cgeo/geocaching/LogTrackableActivity.java4
-rw-r--r--main/src/cgeo/geocaching/VisitCacheActivity.java7
-rw-r--r--main/src/cgeo/geocaching/ui/Formatter.java23
-rw-r--r--main/src/cgeo/geocaching/utils/DateUtils.java18
5 files changed, 48 insertions, 16 deletions
diff --git a/main/src/cgeo/geocaching/LogEntry.java b/main/src/cgeo/geocaching/LogEntry.java
index 31a9703..e03dc66 100644
--- a/main/src/cgeo/geocaching/LogEntry.java
+++ b/main/src/cgeo/geocaching/LogEntry.java
@@ -1,6 +1,7 @@
package cgeo.geocaching;
import cgeo.geocaching.enumerations.LogType;
+import cgeo.geocaching.utils.DateUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -94,15 +95,6 @@ public final class LogEntry {
}
public int daysSinceLog() {
- final Calendar logDate = Calendar.getInstance();
- logDate.setTimeInMillis(date);
- logDate.set(Calendar.SECOND, 0);
- logDate.set(Calendar.MINUTE, 0);
- logDate.set(Calendar.HOUR, 0);
- final Calendar today = Calendar.getInstance();
- today.set(Calendar.SECOND, 0);
- today.set(Calendar.MINUTE, 0);
- today.set(Calendar.HOUR, 0);
- return (int) Math.round((today.getTimeInMillis() - logDate.getTimeInMillis()) / 86400000d);
+ return DateUtils.daysSince(date);
}
}
diff --git a/main/src/cgeo/geocaching/LogTrackableActivity.java b/main/src/cgeo/geocaching/LogTrackableActivity.java
index 2a0d503..578bd62 100644
--- a/main/src/cgeo/geocaching/LogTrackableActivity.java
+++ b/main/src/cgeo/geocaching/LogTrackableActivity.java
@@ -247,8 +247,8 @@ public class LogTrackableActivity extends AbstractActivity implements DateDialog
});
final Button dateButton = (Button) findViewById(R.id.date);
- dateButton.setText(Formatter.formatShortDate(date.getTime().getTime()));
dateButton.setOnClickListener(new DateListener());
+ setDate(date);
if (tweetBox == null) {
tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
@@ -281,7 +281,7 @@ public class LogTrackableActivity extends AbstractActivity implements DateDialog
date = dateIn;
final Button dateButton = (Button) findViewById(R.id.date);
- dateButton.setText(Formatter.formatShortDate(date.getTime().getTime()));
+ dateButton.setText(Formatter.formatShortDateVerbally(date.getTime().getTime()));
}
public void setType(LogType type) {
diff --git a/main/src/cgeo/geocaching/VisitCacheActivity.java b/main/src/cgeo/geocaching/VisitCacheActivity.java
index c211157..e5410e7 100644
--- a/main/src/cgeo/geocaching/VisitCacheActivity.java
+++ b/main/src/cgeo/geocaching/VisitCacheActivity.java
@@ -510,7 +510,7 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D
});
final Button dateButton = (Button) findViewById(R.id.date);
- dateButton.setText(Formatter.formatShortDate(date.getTime().getTime()));
+ setDate(date);
dateButton.setOnClickListener(new DateListener());
final EditText logView = (EditText) findViewById(R.id.log);
@@ -548,7 +548,7 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D
date = dateIn;
final Button dateButton = (Button) findViewById(R.id.date);
- dateButton.setText(Formatter.formatShortDate(date.getTime().getTime()));
+ dateButton.setText(Formatter.formatShortDateVerbally(date.getTime().getTime()));
}
public void setType(LogType type) {
@@ -602,6 +602,7 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D
@Override
public void onClick(View arg0) {
+ //TODO: unify this method and the code in init()
app.clearLogOffline(geocode);
if (alreadyFound) {
@@ -615,8 +616,8 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D
setType(typeSelected);
final Button dateButton = (Button) findViewById(R.id.date);
- dateButton.setText(Formatter.formatShortDate(date.getTime().getTime()));
dateButton.setOnClickListener(new DateListener());
+ setDate(date);
final EditText logView = (EditText) findViewById(R.id.log);
logView.setText("");
diff --git a/main/src/cgeo/geocaching/ui/Formatter.java b/main/src/cgeo/geocaching/ui/Formatter.java
index 6ee1a65..33793c1 100644
--- a/main/src/cgeo/geocaching/ui/Formatter.java
+++ b/main/src/cgeo/geocaching/ui/Formatter.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.ui;
+import cgeo.geocaching.R;
import cgeo.geocaching.cgeoapplication;
import android.content.Context;
@@ -64,9 +65,29 @@ public abstract class Formatter {
}
/**
+ * 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 context
* a Context
* @param date
diff --git a/main/src/cgeo/geocaching/utils/DateUtils.java b/main/src/cgeo/geocaching/utils/DateUtils.java
new file mode 100644
index 0000000..3004bdb
--- /dev/null
+++ b/main/src/cgeo/geocaching/utils/DateUtils.java
@@ -0,0 +1,18 @@
+package cgeo.geocaching.utils;
+
+import java.util.Calendar;
+
+public class DateUtils {
+ public static int daysSince(long date) {
+ final Calendar logDate = Calendar.getInstance();
+ logDate.setTimeInMillis(date);
+ logDate.set(Calendar.SECOND, 0);
+ logDate.set(Calendar.MINUTE, 0);
+ logDate.set(Calendar.HOUR, 0);
+ final Calendar today = Calendar.getInstance();
+ today.set(Calendar.SECOND, 0);
+ today.set(Calendar.MINUTE, 0);
+ today.set(Calendar.HOUR, 0);
+ return (int) Math.round((today.getTimeInMillis() - logDate.getTimeInMillis()) / 86400000d);
+ }
+}