Skip to content
This repository
Browse code

[#25216199] do not show the duplicated tasks at first sync.

  • Loading branch information...
commit ec61bda94c1103739b65998163b2aa20b4c2b572 1 parent 8c26550
Motohiro Takayama authored
4 src/net/mootoh/toggltouch/Task.java
@@ -216,4 +216,8 @@ public static void clear(Context context) {
216 216 db.delete(Task.TABLE_NAME, null, null);
217 217 db.close();
218 218 }
  219 +
  220 + public Date getStartedAt() {
  221 + return startedAt;
  222 + }
219 223 }
31 src/net/mootoh/toggltouch/TogglApi.java
@@ -9,6 +9,8 @@
9 9 import java.net.MalformedURLException;
10 10 import java.net.ProtocolException;
11 11 import java.net.URL;
  12 +import java.util.Collection;
  13 +import java.util.HashMap;
12 14
13 15 import javax.net.ssl.HttpsURLConnection;
14 16
@@ -91,17 +93,29 @@ public void onHttpResponse(JSONObject response) {
91 93 apiResponseDelegate.onFailed(null);
92 94 return;
93 95 }
  96 +
94 97 try {
  98 + HashMap<String, Task> taskMap = new HashMap<String, Task>();
  99 +
95 100 JSONArray data = response.getJSONArray("data");
96   - Task[] entries = new Task[data.length()];
97 101 for (int i=0; i<data.length(); i++) {
98 102 JSONObject obj = (JSONObject)data.get(i);
99 103 String description = obj.getString("description");
100 104 int id = obj.getInt("id");
101 105 String started = obj.getString("start");
102   - entries[i] = new Task(id, description, started);
  106 + Task task = new Task(id, description, started);
  107 + Task existingTask = taskMap.get(description);
  108 + if (existingTask == null) {
  109 + taskMap.put(description, task);
  110 + } else if (task.getStartedAt().compareTo(existingTask.getStartedAt()) > 0) {
  111 + taskMap.remove(description);
  112 + taskMap.put(description, task);
  113 + }
103 114 }
104   - apiResponseDelegate.onSucceeded(entries);
  115 + Collection <Task> values = taskMap.values();
  116 + Task[] tasks = new Task[values.size()];
  117 + values.toArray(tasks);
  118 + apiResponseDelegate.onSucceeded(tasks);
105 119 } catch (JSONException e) {
106 120 apiResponseDelegate.onFailed(e);
107 121 }
@@ -183,17 +197,6 @@ public String __debug__getValidEmail() {
183 197 public String __debug__getValidPassword() {
184 198 return context.getString(R.string.valid_password);
185 199 }
186   -
187   - public void syncTasks() {
188   - assert(hasToken());
189   - getTimeEntries(new ApiResponseDelegate<Task[]>() {
190   - public void onSucceeded(Task[] result) {
191   - }
192   -
193   - public void onFailed(Exception e) {
194   - }
195   - });
196   - }
197 200 }
198 201
199 202 class JsonHttpReequestTask extends AsyncTask<String, Integer, JSONObject> {

0 comments on commit ec61bda

Please sign in to comment.
Something went wrong with that request. Please try again.