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.

pull/14/head
Tim Su 17 years ago
parent bf282c128b
commit 8bb97a73df

@ -21,7 +21,6 @@ package com.mdt.rtm;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -94,7 +93,7 @@ public class Invoker {
public static final String ENCODING = "UTF-8"; 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; public static final long INVOCATION_INTERVAL = 750;
@ -104,18 +103,8 @@ public class Invoker {
private final MessageDigest digest; private final MessageDigest digest;
private String proxyHostName;
private int proxyPortNumber;
private String proxyLogin;
private String proxyPassword;
private String serviceRelativeUri; private String serviceRelativeUri;
private HttpHost host;
private HttpContext context; private HttpContext context;
private BasicHttpParams globalHttpParams; private BasicHttpParams globalHttpParams;
@ -132,7 +121,7 @@ public class Invoker {
throws ServiceInternalException throws ServiceInternalException
{ {
this.serviceRelativeUri = serviceRelativeUri; this.serviceRelativeUri = serviceRelativeUri;
host = new HttpHost(serverHostName, serverPortNumber); new HttpHost(serverHostName, serverPortNumber);
context = new BasicHttpContext(); context = new BasicHttpContext();
globalHttpParams = new BasicHttpParams(); globalHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(globalHttpParams, HttpVersion.HTTP_1_1); 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) private StringBuffer computeRequestUri(Param... params)
throws ServiceInternalException throws ServiceInternalException
{ {

@ -47,6 +47,7 @@ import com.mdt.rtm.data.RtmTask.Priority;
* *
* @author Will Ross Jun 21, 2007 * @author Will Ross Jun 21, 2007
* @author Edouard Mercier, since 2008.04.15 * @author Edouard Mercier, since 2008.04.15
* @author timsu January 2009
*/ */
public class ServiceImpl implements Service 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 <code>null</code>, 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 <code>null</code>, no authentication will be performed and the HTTP is
* considered working anonymously, and the last <code>proxyPassword</code> 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() public boolean isServiceAuthorized()
throws ServiceException throws ServiceException
{ {

@ -631,7 +631,7 @@ public class TaskList extends Activity {
return; return;
sortReverse = sortId < 0; sortReverse = sortId < 0;
sortMode = SortMode.values()[Math.abs(sortId)]; sortMode = SortMode.values()[Math.abs(sortId - 1)];
} }
@Override @Override
@ -688,43 +688,43 @@ public class TaskList extends Activity {
return true; return true;
case CONTEXT_FILTER_HIDDEN: case CONTEXT_FILTER_HIDDEN:
filterShowHidden = !filterShowHidden; TaskList.filterShowHidden = !filterShowHidden;
fillData(); fillData();
return true; return true;
case CONTEXT_FILTER_DONE: case CONTEXT_FILTER_DONE:
filterShowDone = !filterShowDone; TaskList.filterShowDone = !filterShowDone;
fillData(); fillData();
return true; return true;
case CONTEXT_FILTER_TAG: case CONTEXT_FILTER_TAG:
filterTag = null; TaskList.filterTag = null;
fillData(); fillData();
return true; return true;
case CONTEXT_SORT_AUTO: case CONTEXT_SORT_AUTO:
if(sortMode == SortMode.AUTO) if(sortMode == SortMode.AUTO)
return true; return true;
sortReverse = false; TaskList.sortReverse = false;
sortMode = SortMode.AUTO; TaskList.sortMode = SortMode.AUTO;
saveTaskListSort(); saveTaskListSort();
fillData(); fillData();
return true; return true;
case CONTEXT_SORT_ALPHA: case CONTEXT_SORT_ALPHA:
if(sortMode == SortMode.ALPHA) if(sortMode == SortMode.ALPHA)
return true; return true;
sortReverse = false; TaskList.sortReverse = false;
sortMode = SortMode.ALPHA; TaskList.sortMode = SortMode.ALPHA;
saveTaskListSort(); saveTaskListSort();
fillData(); fillData();
return true; return true;
case CONTEXT_SORT_DUEDATE: case CONTEXT_SORT_DUEDATE:
if(sortMode == SortMode.DUEDATE) if(sortMode == SortMode.DUEDATE)
return true; return true;
sortReverse = false; TaskList.sortReverse = false;
sortMode = SortMode.DUEDATE; TaskList.sortMode = SortMode.DUEDATE;
saveTaskListSort(); saveTaskListSort();
fillData(); fillData();
return true; return true;
case CONTEXT_SORT_REVERSE: case CONTEXT_SORT_REVERSE:
sortReverse = !sortReverse; TaskList.sortReverse = !sortReverse;
saveTaskListSort(); saveTaskListSort();
fillData(); fillData();
return true; return true;

@ -32,8 +32,8 @@ public class TagModelForView extends AbstractTagModel {
NAME, NAME,
}; };
public static TagModelForView UNTAGGED_TASKS = new TagModelForView("[untagged]"); public static final TagModelForView UNTAGGED_TASKS = new TagModelForView("[untagged]");
public static String HIDDEN_FROM_MAIN_LIST_PREFIX = "_"; public static final String HIDDEN_FROM_MAIN_LIST_PREFIX = "_";
// --- constructors // --- constructors

@ -51,6 +51,10 @@ public class TaskModelForList extends AbstractTaskModel {
public int getTaskWeight() { public int getTaskWeight() {
int weight = 0; int weight = 0;
// bubble tasks with timers to the top
if(getTimerStart() != null)
weight -= 10000;
// importance // importance
weight += getImportance().ordinal() * 80; weight += getImportance().ordinal() * 80;

@ -45,7 +45,7 @@ public abstract class SynchronizationService {
// called off the UI thread. does some setup // called off the UI thread. does some setup
void synchronizeService(final Activity activity) { void synchronizeService(final Activity activity) {
syncHandler = new Handler(); syncHandler = new Handler();
progressDialog = new ProgressDialog(activity); SynchronizationService.progressDialog = new ProgressDialog(activity);
progressDialog.setIcon(android.R.drawable.ic_dialog_alert); progressDialog.setIcon(android.R.drawable.ic_dialog_alert);
progressDialog.setTitle("Synchronization"); progressDialog.setTitle("Synchronization");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
@ -333,6 +333,7 @@ public abstract class SynchronizationService {
mapping); mapping);
} catch (Exception e) { } catch (Exception e) {
// unique violation: ignore - it'll get merged later // unique violation: ignore - it'll get merged later
Log.e("astrid-sync", "Exception creating mapping", e);
} }
} }
stats.localCreatedTasks++; stats.localCreatedTasks++;
@ -490,7 +491,7 @@ public abstract class SynchronizationService {
} }
} }
protected class ProgressUpdater implements Runnable { protected static class ProgressUpdater implements Runnable {
int step, outOf; int step, outOf;
public ProgressUpdater(int step, int outOf) { public ProgressUpdater(int step, int outOf) {
this.step = step; this.step = step;
@ -501,7 +502,7 @@ public abstract class SynchronizationService {
} }
} }
protected class ProgressLabelUpdater implements Runnable { protected static class ProgressLabelUpdater implements Runnable {
String label; String label;
public ProgressLabelUpdater(String label) { public ProgressLabelUpdater(String label) {
this.label = label; this.label = label;

@ -67,15 +67,15 @@ public class DateControlSet implements OnTimeSetListener,
/** Initialize the components for the given date field */ /** Initialize the components for the given date field */
public void setDate(Date newDate) { public void setDate(Date newDate) {
this.date = newDate;
if(newDate == null) { if(newDate == null) {
date = new Date(); date = new Date();
Integer days = Preferences.getDefaultDeadlineDays(activity); Integer days = Preferences.getDefaultDeadlineDays(activity);
if(days == null) if(days == null)
days = 1; days = 1;
date.setTime(date.getTime() + days*24*3600*1000); date.setTime(date.getTime() + days*24L*3600*1000);
date.setMinutes(0); date.setMinutes(0);
} } else
this.date = new Date(newDate.getTime());
updateDate(); updateDate();
updateTime(); updateTime();

@ -295,7 +295,7 @@ public class NumberPicker extends LinearLayout implements OnClickListener,
/* /*
* When focus is lost check that the text field has valid values. * 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()); String str = String.valueOf(((TextView) v).getText());
if ("".equals(str)) { if ("".equals(str)) {

Loading…
Cancel
Save