From 8bb97a73df3d9fa3002ec885e8e04dfd04fc01e1 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Sun, 18 Jan 2009 08:29:55 +0000 Subject: [PATCH] Ran findbugs on my code, fixed some bugs. Also, changed the auto sort algorithm to move "in progress" tasks to the top, and also fixed a bug with sync remembering. --- src/com/mdt/rtm/Invoker.java | 46 +------------------ src/com/mdt/rtm/Param.java | 2 +- src/com/mdt/rtm/ServiceImpl.java | 19 +------- src/com/timsu/astrid/activities/TaskList.java | 22 ++++----- .../astrid/data/tag/TagModelForView.java | 4 +- .../astrid/data/task/TaskModelForList.java | 4 ++ .../astrid/sync/SynchronizationService.java | 7 +-- .../timsu/astrid/widget/DateControlSet.java | 6 +-- src/com/timsu/astrid/widget/NumberPicker.java | 2 +- 9 files changed, 29 insertions(+), 83 deletions(-) diff --git a/src/com/mdt/rtm/Invoker.java b/src/com/mdt/rtm/Invoker.java index fba548f65..ddc74fcca 100644 --- a/src/com/mdt/rtm/Invoker.java +++ b/src/com/mdt/rtm/Invoker.java @@ -21,7 +21,6 @@ package com.mdt.rtm; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.net.Socket; import java.net.URLEncoder; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -94,7 +93,7 @@ public class Invoker { public static final String ENCODING = "UTF-8"; - public static String API_SIG_PARAM = "api_sig"; + public static final String API_SIG_PARAM = "api_sig"; public static final long INVOCATION_INTERVAL = 750; @@ -104,18 +103,8 @@ public class Invoker { private final MessageDigest digest; - private String proxyHostName; - - private int proxyPortNumber; - - private String proxyLogin; - - private String proxyPassword; - private String serviceRelativeUri; - private HttpHost host; - private HttpContext context; private BasicHttpParams globalHttpParams; @@ -132,7 +121,7 @@ public class Invoker { throws ServiceInternalException { this.serviceRelativeUri = serviceRelativeUri; - host = new HttpHost(serverHostName, serverPortNumber); + new HttpHost(serverHostName, serverPortNumber); context = new BasicHttpContext(); globalHttpParams = new BasicHttpParams(); HttpProtocolParams.setVersion(globalHttpParams, HttpVersion.HTTP_1_1); @@ -165,37 +154,6 @@ public class Invoker { } } - public void setHttpProxySettings(String proxyHostName, int proxyPortNumber, String proxyLogin, String proxyPassword) - { - this.proxyHostName = proxyHostName; - this.proxyPortNumber = proxyPortNumber; - this.proxyLogin = proxyLogin; - this.proxyPassword = proxyPassword; - } - - private void prepareConnection() - throws ServiceInternalException - { - connection = new DefaultHttpClientConnection(); - - // We open the necessary socket connection - try - { - if (connection.isOpen() == false) - { - final Socket socket = new Socket(host.getHostName(), host.getPort()); - connection.bind(socket, globalHttpParams); - } - } - catch (Exception exception) - { - final StringBuffer message = new StringBuffer("Cannot open a socket connection to '").append(host.getHostName()).append("' on port number ").append( - host.getPort()).append(": cannot execute query"); - Log.e(TAG, message.toString(), exception); - throw new ServiceInternalException(message.toString()); - } - } - private StringBuffer computeRequestUri(Param... params) throws ServiceInternalException { diff --git a/src/com/mdt/rtm/Param.java b/src/com/mdt/rtm/Param.java index 2a3e221bd..faa0eec82 100644 --- a/src/com/mdt/rtm/Param.java +++ b/src/com/mdt/rtm/Param.java @@ -24,7 +24,7 @@ import java.util.Date; import com.mdt.rtm.data.RtmData; /** - * + * * @author Will Ross Jun 21, 2007 */ public class Param diff --git a/src/com/mdt/rtm/ServiceImpl.java b/src/com/mdt/rtm/ServiceImpl.java index 79ddba3b5..21b61abfb 100644 --- a/src/com/mdt/rtm/ServiceImpl.java +++ b/src/com/mdt/rtm/ServiceImpl.java @@ -47,6 +47,7 @@ import com.mdt.rtm.data.RtmTask.Priority; * * @author Will Ross Jun 21, 2007 * @author Edouard Mercier, since 2008.04.15 + * @author timsu January 2009 */ public class ServiceImpl implements Service { @@ -83,24 +84,6 @@ public class ServiceImpl implements Service } } - /** - * If you want to go through an HTTP proxy. - * - * @param proxyHostName - * the host name of the HTTP proxy machine (if null, no proxy is set, and all parameters are ignored) - * @param proxyPortNumber - * the port number the HTTP proxy listens to - * @param proxyLogin - * the account identifier against the HTTP proxy: if set to null, no authentication will be performed and the HTTP is - * considered working anonymously, and the last proxyPassword parameter is not taken into account - * @param proxyPassword - * the previous identifier related password - */ - public void setHttpProxySettings(String proxyHostName, int proxyPortNumber, String proxyLogin, String proxyPassword) - { - invoker.setHttpProxySettings(proxyHostName, proxyPortNumber, proxyLogin, proxyPassword); - } - public boolean isServiceAuthorized() throws ServiceException { diff --git a/src/com/timsu/astrid/activities/TaskList.java b/src/com/timsu/astrid/activities/TaskList.java index c68bb86b6..8fcf57cf5 100644 --- a/src/com/timsu/astrid/activities/TaskList.java +++ b/src/com/timsu/astrid/activities/TaskList.java @@ -631,7 +631,7 @@ public class TaskList extends Activity { return; sortReverse = sortId < 0; - sortMode = SortMode.values()[Math.abs(sortId)]; + sortMode = SortMode.values()[Math.abs(sortId - 1)]; } @Override @@ -688,43 +688,43 @@ public class TaskList extends Activity { return true; case CONTEXT_FILTER_HIDDEN: - filterShowHidden = !filterShowHidden; + TaskList.filterShowHidden = !filterShowHidden; fillData(); return true; case CONTEXT_FILTER_DONE: - filterShowDone = !filterShowDone; + TaskList.filterShowDone = !filterShowDone; fillData(); return true; case CONTEXT_FILTER_TAG: - filterTag = null; + TaskList.filterTag = null; fillData(); return true; case CONTEXT_SORT_AUTO: if(sortMode == SortMode.AUTO) return true; - sortReverse = false; - sortMode = SortMode.AUTO; + TaskList.sortReverse = false; + TaskList.sortMode = SortMode.AUTO; saveTaskListSort(); fillData(); return true; case CONTEXT_SORT_ALPHA: if(sortMode == SortMode.ALPHA) return true; - sortReverse = false; - sortMode = SortMode.ALPHA; + TaskList.sortReverse = false; + TaskList.sortMode = SortMode.ALPHA; saveTaskListSort(); fillData(); return true; case CONTEXT_SORT_DUEDATE: if(sortMode == SortMode.DUEDATE) return true; - sortReverse = false; - sortMode = SortMode.DUEDATE; + TaskList.sortReverse = false; + TaskList.sortMode = SortMode.DUEDATE; saveTaskListSort(); fillData(); return true; case CONTEXT_SORT_REVERSE: - sortReverse = !sortReverse; + TaskList.sortReverse = !sortReverse; saveTaskListSort(); fillData(); return true; diff --git a/src/com/timsu/astrid/data/tag/TagModelForView.java b/src/com/timsu/astrid/data/tag/TagModelForView.java index c12c98f66..e6c73584c 100644 --- a/src/com/timsu/astrid/data/tag/TagModelForView.java +++ b/src/com/timsu/astrid/data/tag/TagModelForView.java @@ -32,8 +32,8 @@ public class TagModelForView extends AbstractTagModel { NAME, }; - public static TagModelForView UNTAGGED_TASKS = new TagModelForView("[untagged]"); - public static String HIDDEN_FROM_MAIN_LIST_PREFIX = "_"; + public static final TagModelForView UNTAGGED_TASKS = new TagModelForView("[untagged]"); + public static final String HIDDEN_FROM_MAIN_LIST_PREFIX = "_"; // --- constructors diff --git a/src/com/timsu/astrid/data/task/TaskModelForList.java b/src/com/timsu/astrid/data/task/TaskModelForList.java index e12ada50a..2427b1b13 100644 --- a/src/com/timsu/astrid/data/task/TaskModelForList.java +++ b/src/com/timsu/astrid/data/task/TaskModelForList.java @@ -51,6 +51,10 @@ public class TaskModelForList extends AbstractTaskModel { public int getTaskWeight() { int weight = 0; + // bubble tasks with timers to the top + if(getTimerStart() != null) + weight -= 10000; + // importance weight += getImportance().ordinal() * 80; diff --git a/src/com/timsu/astrid/sync/SynchronizationService.java b/src/com/timsu/astrid/sync/SynchronizationService.java index 9cdf63985..fc6e03372 100644 --- a/src/com/timsu/astrid/sync/SynchronizationService.java +++ b/src/com/timsu/astrid/sync/SynchronizationService.java @@ -45,7 +45,7 @@ public abstract class SynchronizationService { // called off the UI thread. does some setup void synchronizeService(final Activity activity) { syncHandler = new Handler(); - progressDialog = new ProgressDialog(activity); + SynchronizationService.progressDialog = new ProgressDialog(activity); progressDialog.setIcon(android.R.drawable.ic_dialog_alert); progressDialog.setTitle("Synchronization"); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); @@ -333,6 +333,7 @@ public abstract class SynchronizationService { mapping); } catch (Exception e) { // unique violation: ignore - it'll get merged later + Log.e("astrid-sync", "Exception creating mapping", e); } } stats.localCreatedTasks++; @@ -490,7 +491,7 @@ public abstract class SynchronizationService { } } - protected class ProgressUpdater implements Runnable { + protected static class ProgressUpdater implements Runnable { int step, outOf; public ProgressUpdater(int step, int outOf) { this.step = step; @@ -501,7 +502,7 @@ public abstract class SynchronizationService { } } - protected class ProgressLabelUpdater implements Runnable { + protected static class ProgressLabelUpdater implements Runnable { String label; public ProgressLabelUpdater(String label) { this.label = label; diff --git a/src/com/timsu/astrid/widget/DateControlSet.java b/src/com/timsu/astrid/widget/DateControlSet.java index d65739d26..5e30857b0 100644 --- a/src/com/timsu/astrid/widget/DateControlSet.java +++ b/src/com/timsu/astrid/widget/DateControlSet.java @@ -67,15 +67,15 @@ public class DateControlSet implements OnTimeSetListener, /** Initialize the components for the given date field */ public void setDate(Date newDate) { - this.date = newDate; if(newDate == null) { date = new Date(); Integer days = Preferences.getDefaultDeadlineDays(activity); if(days == null) days = 1; - date.setTime(date.getTime() + days*24*3600*1000); + date.setTime(date.getTime() + days*24L*3600*1000); date.setMinutes(0); - } + } else + this.date = new Date(newDate.getTime()); updateDate(); updateTime(); diff --git a/src/com/timsu/astrid/widget/NumberPicker.java b/src/com/timsu/astrid/widget/NumberPicker.java index f4aff923a..18bdd1aa2 100644 --- a/src/com/timsu/astrid/widget/NumberPicker.java +++ b/src/com/timsu/astrid/widget/NumberPicker.java @@ -295,7 +295,7 @@ public class NumberPicker extends LinearLayout implements OnClickListener, /* * When focus is lost check that the text field has valid values. */ - if (!hasFocus) { + if (!hasFocus && v instanceof TextView) { String str = String.valueOf(((TextView) v).getText()); if ("".equals(str)) {