aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/res/values-de/strings.xml2
-rw-r--r--main/res/values/strings.xml2
-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
7 files changed, 52 insertions, 16 deletions
diff --git a/main/res/values-de/strings.xml b/main/res/values-de/strings.xml
index 68c7969..c345f96 100644
--- a/main/res/values-de/strings.xml
+++ b/main/res/values-de/strings.xml
@@ -114,6 +114,8 @@
<string name="log_new_log">Loggen</string>
<string name="log_new_log_text">Log-Text</string>
<string name="log_announcement">Ankündigung</string>
+ <string name="log_today">Heute</string>
+ <string name="log_yesterday">Gestern</string>
<!-- translation -->
<string name="translate_to_sys_lang">Übersetze in %s</string>
diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml
index 517c4c5..bc7c2d9 100644
--- a/main/res/values/strings.xml
+++ b/main/res/values/strings.xml
@@ -114,6 +114,8 @@
<string name="log_new_log">Log</string>
<string name="log_new_log_text">Log Text</string>
<string name="log_announcement">Announcement</string>
+ <string name="log_today">Today</string>
+ <string name="log_yesterday">Yesterday</string>
<!-- translation -->
<string name="translate_to_sys_lang">Translate to %s</string>
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);
+ }
+}