From 7f737c7021afa62b31c3f4fedfebc869946dab1f Mon Sep 17 00:00:00 2001 From: Tim Su Date: Wed, 28 Jan 2009 07:22:32 +0000 Subject: [PATCH] Retry if invoke fails the first time, minor bugfixes. --- src/com/mdt/rtm/Invoker.java | 28 +++++++++++-------- src/com/timsu/astrid/activities/TaskList.java | 2 +- .../astrid/activities/TaskListAdapter.java | 7 +++-- src/com/timsu/astrid/activities/TaskView.java | 9 +++--- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/com/mdt/rtm/Invoker.java b/src/com/mdt/rtm/Invoker.java index f7bc21f57..5533aa746 100644 --- a/src/com/mdt/rtm/Invoker.java +++ b/src/com/mdt/rtm/Invoker.java @@ -179,7 +179,12 @@ public class Invoker { return requestUri; } - public Element invoke(Param... params) + /** Call invoke with a false repeat */ + public Element invoke(Param... params) throws ServiceException { + return invoke(false, params); + } + + public Element invoke(boolean repeat, Param... params) throws ServiceException { long timeSinceLastInvocation = System.currentTimeMillis() - lastInvocation; @@ -208,16 +213,6 @@ public class Invoker { final HttpGet request = new HttpGet("http://" + ServiceImpl.SERVER_HOST_NAME + requestUri.toString()); request.setHeader(new BasicHeader(HTTP.CHARSET_PARAM, ENCODING)); final String methodUri = request.getRequestLine().getUri(); - // TODO: put that back! - // if (proxyHostName != null) - // { - // // Sets an HTTP proxy and the credentials for authentication - // client.getHostConfiguration().setProxy(proxyHostName, proxyPortNumber); - // if (proxyLogin != null) - // { - // client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxyLogin, proxyPassword)); - // } - // } Element result; try @@ -229,6 +224,17 @@ public class Invoker { if (statusCode != HttpStatus.SC_OK) { Log.e(TAG, "Method failed: " + response.getStatusLine()); + + // Tim: HTTP error. Let's wait a little bit + if(!repeat) { + try { + Thread.sleep(1500); + } catch (InterruptedException e) { + // ignore + } + return invoke(true, params); + } + throw new ServiceInternalException("method failed: " + response.getStatusLine()); } diff --git a/src/com/timsu/astrid/activities/TaskList.java b/src/com/timsu/astrid/activities/TaskList.java index 7f68fb336..8dfef6980 100644 --- a/src/com/timsu/astrid/activities/TaskList.java +++ b/src/com/timsu/astrid/activities/TaskList.java @@ -749,12 +749,12 @@ public class TaskList extends Activity { long postponeMillis = (values[0] * 24 + values[1]) * 3600L * 1000; Date preferred = task.getPreferredDueDate(); - Date definite = task.getDefiniteDueDate(); if(preferred != null) { preferred = new Date(preferred.getTime() + postponeMillis); task.setPreferredDueDate(preferred); } + Date definite = task.getDefiniteDueDate(); if(definite != null) { definite = new Date(definite.getTime() + postponeMillis); diff --git a/src/com/timsu/astrid/activities/TaskListAdapter.java b/src/com/timsu/astrid/activities/TaskListAdapter.java index 5a3331a00..a57cc9f83 100644 --- a/src/com/timsu/astrid/activities/TaskListAdapter.java +++ b/src/com/timsu/astrid/activities/TaskListAdapter.java @@ -74,6 +74,8 @@ public class TaskListAdapter extends ArrayAdapter { private static final int KEY_TAGS = 6; private static final int KEY_HIDDEN = 7; + private static final String CACHE_TRUE = "y"; + private final Activity activity; private List objects; private int resource; @@ -211,7 +213,7 @@ public class TaskListAdapter extends ArrayAdapter { } else { taskOverdue = true; label.append(r.getString(R.string.taskList_overdueBy)).append(" "); - task.putCachedLabel(KEY_OVERDUE, "y"); + task.putCachedLabel(KEY_OVERDUE, CACHE_TRUE); } label.append(DateUtilities.getDurationString(r, (int)Math.abs(timeLeft/1000), 1)); @@ -227,6 +229,7 @@ public class TaskListAdapter extends ArrayAdapter { } else { label.append(r.getString(R.string.taskList_overdueBy)).append(" "); deadlines.setTextColor(r.getColor(R.color.taskList_dueDateOverdue)); + task.putCachedLabel(KEY_OVERDUE, CACHE_TRUE); } label.append(DateUtilities.getDurationString(r, (int)Math.abs(timeLeft/1000), 1)).append(" "); @@ -236,7 +239,7 @@ public class TaskListAdapter extends ArrayAdapter { task.putCachedLabel(KEY_DEADLINE, cachedResult); } deadlines.setText(cachedResult); - if(task.getCachedLabel(KEY_OVERDUE) != null) + if(CACHE_TRUE.equals(task.getCachedLabel(KEY_OVERDUE))) deadlines.setTextColor(r.getColor(R.color.taskList_dueDateOverdue)); } setVisibility(deadlines); diff --git a/src/com/timsu/astrid/activities/TaskView.java b/src/com/timsu/astrid/activities/TaskView.java index e07ee2238..868d7ae7d 100644 --- a/src/com/timsu/astrid/activities/TaskView.java +++ b/src/com/timsu/astrid/activities/TaskView.java @@ -31,6 +31,7 @@ import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.Window; import android.widget.Button; import android.widget.TextView; @@ -76,6 +77,7 @@ public class TaskView extends TaskModificationActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.task_view); handler = new Handler(); @@ -124,7 +126,7 @@ public class TaskView extends TaskModificationActivity { int secondsToDeadline = (int) ((deadline.getTime() - System.currentTimeMillis())/1000); String text = DateUtilities.getDurationString(r, - Math.abs(secondsToDeadline), 2); + Math.abs(secondsToDeadline), 2) + " "; if(secondsToDeadline < 0) { view.setTextColor(r.getColor(R.color.view_table_overdue)); view.setText(text + r.getString(R.string.overdue_suffix)); @@ -141,8 +143,8 @@ public class TaskView extends TaskModificationActivity { int secondsAgo = (int) ((System.currentTimeMillis() - date.getTime())/1000); String text = DateUtilities.getDurationString(r, - Math.abs(secondsAgo), 2); - view.setText(text + " " + r.getString(R.string.ago_suffix)); + Math.abs(secondsAgo), 2) + " "; + view.setText(text + r.getString(R.string.ago_suffix)); } /* ====================================================================== @@ -151,7 +153,6 @@ public class TaskView extends TaskModificationActivity { private void setUpUIComponents() { Resources r = getResources(); - setTitle(r.getString(R.string.taskView_title)); name = (TextView)findViewById(R.id.name); elapsed = (TextView)findViewById(R.id.cell_elapsed);