Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 50 additions and 1 deletion.
  1. +7 −0 res/values/strings.xml
  2. +7 −1 src/appmonk/net/SimpleFileCache.java
  3. +36 −0 src/appmonk/tricks/TimeTricks.java
View
7 res/values/strings.xml
@@ -16,4 +16,11 @@
<string name="one_day_ago">a day ago</string>
<string name="n_days_ago">%d days ago</string>
<string name="in_the_future">in_the_future</string>
+
+ <string name="current">current</string>
+ <string name="less_than_one_hour_old">less than one hour old</string>
+ <string name="one_hour_old">one hour old</string>
+ <string name="n_hours_old">%d hours old</string>
+ <string name="one_day_old">one day old</string>
+ <string name="n_days_old">%d days old</string>
</resources>
View
8 src/appmonk/net/SimpleFileCache.java
@@ -99,8 +99,14 @@ public Object fetch(String name, int maxAge) {
String cleanName = IOTricks.sanitizeFileName(name);
File cacheFile = new File(mCacheDir, cleanName);
+ if (!cacheFile.canRead()) {
+ if (debug)
+ Log.d(TAG, "Cache file not found for " + name + " (" + cacheFile.getPath() + ")");
+ return null;
+ }
+
try {
- if (System.currentTimeMillis() - cacheFile.lastModified() < maxAge) {
+ if (maxAge <= 0 || (System.currentTimeMillis() - cacheFile.lastModified() < maxAge)) {
if (debug)
Log.d(TAG, "Loading " + name + " (" + cacheFile.getPath() + ")");
View
36 src/appmonk/tricks/TimeTricks.java
@@ -36,6 +36,13 @@
protected static String str_n_days_ago = "";
protected static String str_in_the_future = "";
+ protected static String str_current = "";
+ protected static String str_less_than_one_hour_old = "";
+ protected static String str_one_hour_old = "";
+ protected static String str_n_hours_old = "";
+ protected static String str_one_day_old = "";
+ protected static String str_n_days_old = "";
+
public static void initializeResources() {
if (initialized)
return;
@@ -57,6 +64,13 @@ public static void initializeResources() {
str_one_day_ago = AppMonk.getString(R.string.one_day_ago);
str_n_days_ago = AppMonk.getString(R.string.one_day_ago);
str_in_the_future = AppMonk.getString(R.string.in_the_future);
+
+ str_current = AppMonk.getString(R.string.current);
+ str_less_than_one_hour_old = AppMonk.getString(R.string.less_than_one_hour_old);
+ str_one_hour_old = AppMonk.getString(R.string.one_hour_old);
+ str_n_hours_old = AppMonk.getString(R.string.n_hours_old);
+ str_one_day_old = AppMonk.getString(R.string.one_day_old);
+ str_n_days_old = AppMonk.getString(R.string.n_days_old);
}
public static Calendar isoStringToCalendar(String dateStr) {
@@ -150,4 +164,26 @@ else if (diff < (60 * 1000 * 60 * 24 * 2)) {
return String.format(str_n_days_ago, (diff / (60 * 1000 * 60 * 24)));
}
}
+
+ public static String ageInWords(long millis) {
+ long diff = System.currentTimeMillis() - millis;
+ if (diff < 0) {
+ return str_current;
+ }
+ else if (diff < (60 * 1000 * 60)) {
+ return str_less_than_one_hour_old;
+ }
+ else if (diff < (60 * 1000 * 60 * 2)) {
+ return str_one_hour_old;
+ }
+ else if (diff < (60 * 1000 * 60 * 24)) {
+ return String.format(str_n_hours_old, (diff / (60 * 1000 * 60)));
+ }
+ else if (diff < (60 * 1000 * 60 * 24 * 2)) {
+ return str_one_day_old;
+ }
+ else {
+ return String.format(str_n_days_old, (diff / (60 * 1000 * 60 * 24)));
+ }
+ }
}

No commit comments for this range

Something went wrong with that request. Please try again.