SayWhen a separate class
authorEugene Crosser <crosser@average.org>
Fri, 3 Feb 2012 21:19:20 +0000 (01:19 +0400)
committerEugene Crosser <crosser@average.org>
Fri, 3 Feb 2012 21:19:20 +0000 (01:19 +0400)
res/values/strings.xml
src/org/average/whereami/LastLocation.java
src/org/average/whereami/PhoneLog.java
src/org/average/whereami/SayWhen.java [new file with mode: 0644]

index 11b7827b1cf5d86c2eb2dc34516ddde3f3fe724c..32d38e3d1683c9e06cc588cb96c712bcf68e1cad 100644 (file)
@@ -9,21 +9,18 @@
     <string name="failtry">Неудачная попытка</string>
     <string name="nocalendar">Нет календаря с именем</string>
     <string name="noevents">Нет записей за последнюю неделю</string>
-    <string name="autherror">Ð\9dеобÑ\85одимо Ð°Ð²Ñ\82оÑ\80изоваÑ\82Ñ\8cÑ\81Ñ\8f (Ñ\87еÑ\80ез Ð¼ÐµÐ½Ñ\8e)</string>
+    <string name="autherror">Ð\9eÑ\88ибка Ð°Ð²Ñ\82оÑ\80изаÑ\86ии</string>
     <string name="myname">Женя</string>
-    <string name="timestamp">отметка</string>
+    <string name="registered">отмечено</string>
     <string name="last_call">Последний звонок</string>
     <string name="in_call">к Жене</string>
     <string name="out_call">от Жени</string>
-    <string name="duration">длительностью</string>
+    <string name="duration">длиной</string>
     <string name="minutes1">минуту</string>
     <string name="minutes2to4">минуты</string>
     <string name="minutes5up">минут</string>
-    <string name="longago">больше суток назад</string>
-    <string name="lessthanhour">меньше часа назад</string>
-    <string name="onehour">час с лишним назад</string>
-    <string name="hours2to4">часа назад</string>
-    <string name="hours5up">часов назад</string>
+    <string name="s_at">в</string>
+    <string name="yesterday">вчера</string>
     <string name="quit">Выход</string>
     <string name="authorize">Авторизация</string>
     <string name="settings">Конфигурация</string>
index 4b82564fae272d9e5261fb170f07014295c141cc..76e8ef28c73e02c82288f2a71eaefd0398592e69 100644 (file)
@@ -1,6 +1,7 @@
 package org.average.whereami;
 
 import org.average.whereami.PersistentStore;
+import org.average.whereami.SayWhen;
 
 import java.lang.Math;
 import java.io.IOException;
@@ -27,12 +28,8 @@ public final class LastLocation extends Oracle {
        private String[] loc_lons;
        private String[] loc_dists;
        private String myname;
-       private String timestamp;
-       private String longago;
-       private String lessthanhour;
-       private String onehour;
-       private String hours2to4;
-       private String hours5up;
+       private String registered;
+       private SayWhen sayWhen;
 
        public LastLocation(final Resources res, final PersistentStore store) {
                super(res, store);
@@ -41,12 +38,8 @@ public final class LastLocation extends Oracle {
                loc_lons = res.getStringArray(R.array.loc_lons);
                loc_dists = res.getStringArray(R.array.loc_dists);
                myname = res.getString(R.string.myname);
-               timestamp = res.getString(R.string.timestamp);
-               longago = res.getString(R.string.longago);
-               lessthanhour = res.getString(R.string.lessthanhour);
-               onehour = res.getString(R.string.onehour);
-               hours2to4 = res.getString(R.string.hours2to4);
-               hours5up = res.getString(R.string.hours5up);
+               registered = res.getString(R.string.registered);
+               sayWhen = new SayWhen(res);
 
                latitude = Latitude.builder(httpTransport, jsonFactory)
                        .setHttpRequestInitializer(accessProtectedResource)
@@ -101,20 +94,8 @@ public final class LastLocation extends Oracle {
                                break;
                        }
                }
-               Long ago = (System.currentTimeMillis() - tsm) / 3600000;
-               if (ago < 1) {
-                       agomsg = lessthanhour;
-               } else if (ago < 2) {
-                       agomsg = onehour;
-               } else if (ago < 5) {
-                       agomsg = "" + ago + " " + hours2to4;
-               } else if (ago < 24) {
-                       agomsg = "" + ago + " " + hours5up;
-               } else {
-                       agomsg = longago;
-               }
-               return myname + " " + locmsg + ", " + timestamp +
-                       " " + agomsg;
+               return myname + " " + locmsg + ", " + registered +
+                       " " + sayWhen.say(tsm);
        }
 
        private Double toRad(Double deg) {
index 708b88ef3d072d4f6213a3af82f3b481167d7986..fb319a46a494441188226dfdfac600783c454487 100644 (file)
@@ -1,6 +1,7 @@
 package org.average.whereami;
 
 import org.average.whereami.PersistentStore;
+import org.average.whereami.SayWhen;
 
 import java.io.IOException;
 
@@ -39,6 +40,7 @@ public final class PhoneLog extends Oracle {
        private String minutes1;
        private String minutes2to4;
        private String minutes5up;
+       private SayWhen sayWhen;
 
        public PhoneLog(final Resources res, final PersistentStore store) {
                super(res, store);
@@ -52,6 +54,7 @@ public final class PhoneLog extends Oracle {
                minutes1 = res.getString(R.string.minutes1);
                minutes2to4 = res.getString(R.string.minutes2to4);
                minutes5up = res.getString(R.string.minutes5up);
+               sayWhen = new SayWhen(res);
                calendar_name = store.get("calendar_name");
                peer_name = store.get("peer_name");
                calendar_id = store.get("calendar_id");
@@ -192,9 +195,9 @@ public final class PhoneLog extends Oracle {
                } else {
                        minutes = minutes5up;
                }
-               return last_call + " " +
-                       (latestWasOutgoing?out_call:in_call) +
-                       " " + duration + " " + dur + " " + minutes +
-                       " " + stime.format("%H:%M");
+               return last_call +
+                       " " + (latestWasOutgoing?out_call:in_call) +
+                       " " + sayWhen.say(latestStartTime) +
+                       " " + duration + " " + dur + " " + minutes;
        }
 }
diff --git a/src/org/average/whereami/SayWhen.java b/src/org/average/whereami/SayWhen.java
new file mode 100644 (file)
index 0000000..21196ff
--- /dev/null
@@ -0,0 +1,33 @@
+package org.average.whereami;
+
+import android.content.res.Resources;
+import android.text.format.Time;
+import android.util.Log;
+
+public class SayWhen {
+
+       private String s_at;
+       private String yesterday;
+
+       public SayWhen(final Resources res) {
+               s_at = res.getString(R.string.s_at);
+               yesterday = res.getString(R.string.yesterday);
+       }
+
+       public String say(Long when) {
+               Long now = System.currentTimeMillis();
+               Time tnow = new Time();
+               tnow.set(now);
+               Time twhen = new Time();
+               twhen.set(when);
+               Boolean datechange = tnow.monthDay != twhen.monthDay;
+               Long hoursago = (System.currentTimeMillis() - when) / 3600000;
+               if (hoursago > 24) {
+                       return s_at + twhen.format(" %H:%M %d/%m/%Y");
+               } else if ((tnow.hour > 4 || hoursago > 12) && datechange) {
+                       return yesterday + " " + s_at + twhen.format(" %H:%M");
+               } else {
+                       return s_at + twhen.format(" %H:%M");
+               }
+       }
+}