Fixed a bunch of producteev issues as we move forward

pull/14/head
Tim Su 16 years ago
parent 5c0d050069
commit aa6f01e730

@ -292,7 +292,7 @@
<!-- producteev --> <!-- producteev -->
<activity android:name="com.todoroo.astrid.producteev.ProducteevPreferences" <activity android:name="com.todoroo.astrid.producteev.ProducteevPreferences"
android:icon="@drawable/ic_menu_rmilk" android:icon="@drawable/ic_menu_producteev"
android:label="@string/producteev_PPr_header"> android:label="@string/producteev_PPr_header">
<intent-filter> <intent-filter>
<action android:name="com.todoroo.astrid.TASK_LIST_MENU" /> <action android:name="com.todoroo.astrid.TASK_LIST_MENU" />

@ -2,6 +2,7 @@ package com.todoroo.astrid.api;
import java.util.ArrayList; import java.util.ArrayList;
import com.todoroo.astrid.common.SyncProvider;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
@ -9,7 +10,7 @@ import com.todoroo.astrid.model.Task;
* Container class for transmitting tasks and including local and remote * Container class for transmitting tasks and including local and remote
* metadata. Synchronization Providers can subclass this class if desired. * metadata. Synchronization Providers can subclass this class if desired.
* *
* @see {@link SynchronizationProvider} * @see {@link SyncProvider}
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */

@ -4,7 +4,7 @@
<booleanAttribute key="ch.zork.quicklaunch" value="true"/> <booleanAttribute key="ch.zork.quicklaunch" value="true"/>
<stringAttribute key="ch.zork.quicklaunch.icon" value="14.gif"/> <stringAttribute key="ch.zork.quicklaunch.icon" value="14.gif"/>
<intAttribute key="ch.zork.quicklaunch.index" value="0"/> <intAttribute key="ch.zork.quicklaunch.index" value="0"/>
<stringAttribute key="ch.zork.quicklaunch.mode" value="run"/> <stringAttribute key="ch.zork.quicklaunch.mode" value="debug"/>
<intAttribute key="com.android.ide.eclipse.adt.action" value="0"/> <intAttribute key="com.android.ide.eclipse.adt.action" value="0"/>
<stringAttribute key="com.android.ide.eclipse.adt.commandline" value="-scale 0.7"/> <stringAttribute key="com.android.ide.eclipse.adt.commandline" value="-scale 0.7"/>
<intAttribute key="com.android.ide.eclipse.adt.delay" value="0"/> <intAttribute key="com.android.ide.eclipse.adt.delay" value="0"/>

@ -9,8 +9,8 @@ import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log; import android.util.Log;
import com.todoroo.andlib.data.Property.PropertyVisitor; import com.todoroo.andlib.data.Property.PropertyVisitor;
@ -111,6 +111,9 @@ abstract public class AbstractDatabase {
try { try {
database = helper.getWritableDatabase(); database = helper.getWritableDatabase();
} catch (NullPointerException e) {
// don't know why this happens
throw new IllegalStateException(e);
} catch (final RuntimeException original) { } catch (final RuntimeException original) {
Log.e("database-" + getName(), "Error opening db", Log.e("database-" + getName(), "Error opening db",
original); original);

@ -1,7 +1,7 @@
/** /**
* See the file "LICENSE" for the full license governing this code. * See the file "LICENSE" for the full license governing this code.
*/ */
package com.todoroo.astrid.api; package com.todoroo.astrid.common;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,6 +21,7 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.service.NotificationManager; import com.todoroo.andlib.service.NotificationManager;
import com.todoroo.astrid.api.TaskContainer;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Constants;
@ -35,7 +36,7 @@ import com.todoroo.astrid.utility.Constants;
* @author timsu * @author timsu
* *
*/ */
public abstract class SynchronizationProvider<TYPE extends TaskContainer> { public abstract class SyncProvider<TYPE extends TaskContainer> {
// --- abstract methods - your services should implement these // --- abstract methods - your services should implement these
@ -129,7 +130,7 @@ public abstract class SynchronizationProvider<TYPE extends TaskContainer> {
private final Notification notification; private final Notification notification;
public SynchronizationProvider() { public SyncProvider() {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
// initialize notification // initialize notification

@ -4,20 +4,16 @@ import java.util.Date;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceManager;
import android.view.View; import android.view.View;
import android.view.ViewGroup.OnHierarchyChangeListener; import android.view.ViewGroup.OnHierarchyChangeListener;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
@ -34,22 +30,12 @@ abstract public class SyncProviderPreferences extends TodorooPreferences {
// --- interface // --- interface
/**
* @return your plugin identifier
*/
abstract public String getIdentifier();
/** /**
* @return your preference resource * @return your preference resource
*/ */
@Override @Override
abstract public int getPreferenceResource(); abstract public int getPreferenceResource();
/**
* @return key for sync interval
*/
abstract public int getSyncIntervalKey();
/** /**
* kick off synchronization * kick off synchronization
*/ */
@ -60,117 +46,11 @@ abstract public class SyncProviderPreferences extends TodorooPreferences {
*/ */
abstract public void logOut(); abstract public void logOut();
// --- preference utility methods
private static final String PREF_TOKEN = "_token"; //$NON-NLS-1$
private static final String PREF_LAST_SYNC = "_last_sync"; //$NON-NLS-1$
private static final String PREF_LAST_ATTEMPTED_SYNC = "_last_attempted"; //$NON-NLS-1$
private static final String PREF_LAST_ERROR = "_last_error"; //$NON-NLS-1$
private static final String PREF_ONGOING = "_ongoing"; //$NON-NLS-1$
/** Get preferences object from the context */
protected static SharedPreferences getPrefs() {
return PreferenceManager.getDefaultSharedPreferences(ContextManager.getContext());
}
/** /**
* @return true if we have a token for this user, false otherwise * @return get preference utilities
*/ */
public boolean isLoggedIn() { abstract public SyncProviderUtilities getUtilities();
return getPrefs().getString(getIdentifier() + PREF_TOKEN, null) != null;
}
/** authentication token, or null if doesn't exist */
public String getToken() {
return getPrefs().getString(getIdentifier() + PREF_TOKEN, null);
}
/** Sets the authentication token. Set to null to clear. */
public void setToken(String setting) {
Editor editor = getPrefs().edit();
editor.putString(getIdentifier() + PREF_TOKEN, setting);
editor.commit();
}
/** @return Last Successful Sync Date, or 0 */
public long getLastSyncDate() {
return getPrefs().getLong(getIdentifier() + PREF_LAST_SYNC, 0);
}
/** @return Last Attempted Sync Date, or 0 if it was successful */
public long getLastAttemptedSyncDate() {
return getPrefs().getLong(getIdentifier() + PREF_LAST_ATTEMPTED_SYNC, 0);
}
/** @return Last Error, or null if no last error */
public String getLastError() {
return getPrefs().getString(PREF_LAST_ERROR, null);
}
/** @return Last Error, or null if no last error */
public boolean isOngoing() {
return getPrefs().getBoolean(getIdentifier() + PREF_ONGOING, false);
}
/** Deletes Last Successful Sync Date */
public void clearLastSyncDate() {
Editor editor = getPrefs().edit();
editor.remove(getIdentifier() + PREF_LAST_SYNC);
editor.commit();
}
/** Set Last Successful Sync Date */
public void setLastError(String error) {
Editor editor = getPrefs().edit();
editor.putString(getIdentifier() + PREF_LAST_ERROR, error);
editor.commit();
}
/** Set Ongoing */
public void stopOngoing() {
Editor editor = getPrefs().edit();
editor.putBoolean(getIdentifier() + PREF_ONGOING, false);
editor.commit();
}
/** Set Last Successful Sync Date */
public void recordSuccessfulSync() {
Editor editor = getPrefs().edit();
editor.putLong(getIdentifier() + PREF_LAST_SYNC, DateUtilities.now());
editor.putLong(getIdentifier() + PREF_LAST_ATTEMPTED_SYNC, 0);
editor.commit();
}
/** Set Last Attempted Sync Date */
public void recordSyncStart() {
Editor editor = getPrefs().edit();
editor.putLong(getIdentifier() + PREF_LAST_ATTEMPTED_SYNC, DateUtilities.now());
editor.putString(getIdentifier() + PREF_LAST_ERROR, null);
editor.putBoolean(getIdentifier() + PREF_ONGOING, true);
editor.commit();
}
/**
* Reads the frequency, in seconds, auto-sync should occur.
*
* @return seconds duration, or 0 if not desired
*/
public static int getSyncAutoSyncFrequency() {
String value = getPrefs().getString(
ContextManager.getContext().getString(
R.string.rmilk_MPr_interval_key), null);
if (value == null)
return 0;
try {
return Integer.parseInt(value);
} catch (Exception e) {
return 0;
}
}
// --- implementation // --- implementation
@ -208,7 +88,7 @@ abstract public class SyncProviderPreferences extends TodorooPreferences {
final Resources r = getResources(); final Resources r = getResources();
// interval // interval
if (r.getString(getSyncIntervalKey()).equals( if (r.getString(getUtilities().getSyncIntervalKey()).equals(
preference.getKey())) { preference.getKey())) {
int index = AndroidUtilities.indexOf( int index = AndroidUtilities.indexOf(
r.getStringArray(R.array.rmilk_MPr_interval_values), r.getStringArray(R.array.rmilk_MPr_interval_values),
@ -223,7 +103,7 @@ abstract public class SyncProviderPreferences extends TodorooPreferences {
// status // status
else if (r.getString(R.string.rmilk_MPr_status_key).equals(preference.getKey())) { else if (r.getString(R.string.rmilk_MPr_status_key).equals(preference.getKey())) {
boolean loggedIn = isLoggedIn(); boolean loggedIn = getUtilities().isLoggedIn();
String status; String status;
String subtitle = ""; //$NON-NLS-1$ String subtitle = ""; //$NON-NLS-1$
@ -240,33 +120,33 @@ abstract public class SyncProviderPreferences extends TodorooPreferences {
}); });
} }
// sync is occurring // sync is occurring
else if(isOngoing()) { else if(getUtilities().isOngoing()) {
status = r.getString(R.string.rmilk_status_ongoing); status = r.getString(R.string.rmilk_status_ongoing);
statusColor = Color.rgb(0, 0, 100); statusColor = Color.rgb(0, 0, 100);
} }
// last sync was error // last sync was error
else if(getLastAttemptedSyncDate() != 0) { else if(getUtilities().getLastAttemptedSyncDate() != 0) {
status = r.getString(R.string.rmilk_status_failed, status = r.getString(R.string.rmilk_status_failed,
DateUtilities.getDateWithTimeFormat(SyncProviderPreferences.this). DateUtilities.getDateWithTimeFormat(SyncProviderPreferences.this).
format(new Date(getLastAttemptedSyncDate()))); format(new Date(getUtilities().getLastAttemptedSyncDate())));
if(getLastSyncDate() > 0) { if(getUtilities().getLastSyncDate() > 0) {
subtitle = r.getString(R.string.rmilk_status_failed_subtitle, subtitle = r.getString(R.string.rmilk_status_failed_subtitle,
DateUtilities.getDateWithTimeFormat(SyncProviderPreferences.this). DateUtilities.getDateWithTimeFormat(SyncProviderPreferences.this).
format(new Date(getLastSyncDate()))); format(new Date(getUtilities().getLastSyncDate())));
} }
statusColor = Color.rgb(100, 0, 0); statusColor = Color.rgb(100, 0, 0);
preference.setOnPreferenceClickListener(new OnPreferenceClickListener() { preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference p) { public boolean onPreferenceClick(Preference p) {
String error = getLastError(); String error = getUtilities().getLastError();
if(error != null) if(error != null)
dialogUtilities.okDialog(SyncProviderPreferences.this, error, null); dialogUtilities.okDialog(SyncProviderPreferences.this, error, null);
return true; return true;
} }
}); });
} else if(getLastSyncDate() > 0) { } else if(getUtilities().getLastSyncDate() > 0) {
status = r.getString(R.string.rmilk_status_success, status = r.getString(R.string.rmilk_status_success,
DateUtilities.getDateWithTimeFormat(SyncProviderPreferences.this). DateUtilities.getDateWithTimeFormat(SyncProviderPreferences.this).
format(new Date(getLastSyncDate()))); format(new Date(getUtilities().getLastSyncDate())));
statusColor = Color.rgb(0, 100, 0); statusColor = Color.rgb(0, 100, 0);
} else { } else {
status = r.getString(R.string.rmilk_status_never); status = r.getString(R.string.rmilk_status_never);
@ -289,7 +169,7 @@ abstract public class SyncProviderPreferences extends TodorooPreferences {
// sync button // sync button
else if (r.getString(R.string.rmilk_MPr_sync_key).equals(preference.getKey())) { else if (r.getString(R.string.rmilk_MPr_sync_key).equals(preference.getKey())) {
boolean loggedIn = isLoggedIn(); boolean loggedIn = getUtilities().isLoggedIn();
preference.setOnPreferenceClickListener(new OnPreferenceClickListener() { preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference p) { public boolean onPreferenceClick(Preference p) {
startSync(); startSync();
@ -303,7 +183,7 @@ abstract public class SyncProviderPreferences extends TodorooPreferences {
// log out button // log out button
else if (r.getString(R.string.rmilk_MPr_forget_key).equals(preference.getKey())) { else if (r.getString(R.string.rmilk_MPr_forget_key).equals(preference.getKey())) {
boolean loggedIn = isLoggedIn(); boolean loggedIn = getUtilities().isLoggedIn();
preference.setOnPreferenceClickListener(new OnPreferenceClickListener() { preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference p) { public boolean onPreferenceClick(Preference p) {
dialogUtilities.okCancelDialog(SyncProviderPreferences.this, dialogUtilities.okCancelDialog(SyncProviderPreferences.this,

@ -0,0 +1,137 @@
package com.todoroo.astrid.common;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities;
/**
* Sync Provider Utility class for accessing preferences
*/
abstract public class SyncProviderUtilities {
/**
* @return your plugin identifier
*/
abstract public String getIdentifier();
/**
* @return key for sync interval
*/
abstract public int getSyncIntervalKey();
// --- implementation
private static final String PREF_TOKEN = "_token"; //$NON-NLS-1$
private static final String PREF_LAST_SYNC = "_last_sync"; //$NON-NLS-1$
private static final String PREF_LAST_ATTEMPTED_SYNC = "_last_attempted"; //$NON-NLS-1$
private static final String PREF_LAST_ERROR = "_last_error"; //$NON-NLS-1$
private static final String PREF_ONGOING = "_ongoing"; //$NON-NLS-1$
/** Get preferences object from the context */
protected static SharedPreferences getPrefs() {
return PreferenceManager.getDefaultSharedPreferences(ContextManager.getContext());
}
/**
* @return true if we have a token for this user, false otherwise
*/
public boolean isLoggedIn() {
return getPrefs().getString(getIdentifier() + PREF_TOKEN, null) != null;
}
/** authentication token, or null if doesn't exist */
public String getToken() {
return getPrefs().getString(getIdentifier() + PREF_TOKEN, null);
}
/** Sets the authentication token. Set to null to clear. */
public void setToken(String setting) {
Editor editor = getPrefs().edit();
editor.putString(getIdentifier() + PREF_TOKEN, setting);
editor.commit();
}
/** @return Last Successful Sync Date, or 0 */
public long getLastSyncDate() {
return getPrefs().getLong(getIdentifier() + PREF_LAST_SYNC, 0);
}
/** @return Last Attempted Sync Date, or 0 if it was successful */
public long getLastAttemptedSyncDate() {
return getPrefs().getLong(getIdentifier() + PREF_LAST_ATTEMPTED_SYNC, 0);
}
/** @return Last Error, or null if no last error */
public String getLastError() {
return getPrefs().getString(PREF_LAST_ERROR, null);
}
/** @return Last Error, or null if no last error */
public boolean isOngoing() {
return getPrefs().getBoolean(getIdentifier() + PREF_ONGOING, false);
}
/** Deletes Last Successful Sync Date */
public void clearLastSyncDate() {
Editor editor = getPrefs().edit();
editor.remove(getIdentifier() + PREF_LAST_SYNC);
editor.commit();
}
/** Set Last Successful Sync Date */
public void setLastError(String error) {
Editor editor = getPrefs().edit();
editor.putString(getIdentifier() + PREF_LAST_ERROR, error);
editor.commit();
}
/** Set Ongoing */
public void stopOngoing() {
Editor editor = getPrefs().edit();
editor.putBoolean(getIdentifier() + PREF_ONGOING, false);
editor.commit();
}
/** Set Last Successful Sync Date */
public void recordSuccessfulSync() {
Editor editor = getPrefs().edit();
editor.putLong(getIdentifier() + PREF_LAST_SYNC, DateUtilities.now());
editor.putLong(getIdentifier() + PREF_LAST_ATTEMPTED_SYNC, 0);
editor.commit();
}
/** Set Last Attempted Sync Date */
public void recordSyncStart() {
Editor editor = getPrefs().edit();
editor.putLong(getIdentifier() + PREF_LAST_ATTEMPTED_SYNC,
DateUtilities.now());
editor.putString(getIdentifier() + PREF_LAST_ERROR, null);
editor.putBoolean(getIdentifier() + PREF_ONGOING, true);
editor.commit();
}
/**
* Reads the frequency, in seconds, auto-sync should occur.
*
* @return seconds duration, or 0 if not desired
*/
public int getSyncAutoSyncFrequency() {
String value = getPrefs().getString(
ContextManager.getContext().getString(
getSyncIntervalKey()), null);
if (value == null)
return 0;
try {
return Integer.parseInt(value);
} catch (Exception e) {
return 0;
}
}
}

@ -1,9 +1,8 @@
package com.todoroo.astrid.producteev; package com.todoroo.astrid.producteev;
import android.content.SharedPreferences.Editor;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.astrid.common.SyncProviderPreferences; import com.todoroo.astrid.common.SyncProviderPreferences;
import com.todoroo.astrid.common.SyncProviderUtilities;
import com.todoroo.astrid.producteev.sync.ProducteevSyncProvider; import com.todoroo.astrid.producteev.sync.ProducteevSyncProvider;
/** /**
@ -15,21 +14,11 @@ import com.todoroo.astrid.producteev.sync.ProducteevSyncProvider;
*/ */
public class ProducteevPreferences extends SyncProviderPreferences { public class ProducteevPreferences extends SyncProviderPreferences {
@Override
public String getIdentifier() {
return "pdv"; //$NON-NLS-1$
}
@Override @Override
public int getPreferenceResource() { public int getPreferenceResource() {
return R.xml.preferences_producteev; return R.xml.preferences_producteev;
} }
@Override
public int getSyncIntervalKey() {
return R.string.producteev_PPr_interval_key;
}
@Override @Override
public void startSync() { public void startSync() {
new ProducteevSyncProvider().synchronize(this); new ProducteevSyncProvider().synchronize(this);
@ -40,20 +29,9 @@ public class ProducteevPreferences extends SyncProviderPreferences {
new ProducteevSyncProvider().signOut(); new ProducteevSyncProvider().signOut();
} }
// --- producteev-specific preferences @Override
public SyncProviderUtilities getUtilities() {
private static final String PREF_SERVER_LAST_SYNC = "_last_server"; //$NON-NLS-1$ return ProducteevUtilities.INSTANCE;
/** @return last sync date, or null if no last */
public String getLastServerSync() {
return getPrefs().getString(getIdentifier() + PREF_SERVER_LAST_SYNC, null);
}
/** Deletes Last Successful Sync Date */
public void setLastServerSync(String value) {
Editor editor = getPrefs().edit();
editor.putString(getIdentifier() + PREF_SERVER_LAST_SYNC, value);
editor.commit();
} }

@ -0,0 +1,46 @@
package com.todoroo.astrid.producteev;
import android.content.SharedPreferences.Editor;
import com.timsu.astrid.R;
import com.todoroo.astrid.common.SyncProviderUtilities;
/**
* Displays synchronization preferences and an action panel so users can
* initiate actions from the menu.
*
* @author timsu
*
*/
public class ProducteevUtilities extends SyncProviderUtilities {
public static final ProducteevUtilities INSTANCE = new ProducteevUtilities();
@Override
public String getIdentifier() {
return "pdv"; //$NON-NLS-1$
}
@Override
public int getSyncIntervalKey() {
return R.string.producteev_PPr_interval_key;
}
// --- producteev-specific preferences
private static final String PREF_SERVER_LAST_SYNC = "_last_server"; //$NON-NLS-1$
/** @return last sync date, or null if no last */
public String getLastServerSync() {
return getPrefs().getString(getIdentifier() + PREF_SERVER_LAST_SYNC, null);
}
/** Deletes Last Successful Sync Date */
public void setLastServerSync(String value) {
Editor editor = getPrefs().edit();
editor.putString(getIdentifier() + PREF_SERVER_LAST_SYNC, value);
editor.commit();
}
}

@ -34,7 +34,7 @@ public class ProducteevInvoker {
this.apiSecret = apiSecret; this.apiSecret = apiSecret;
} }
// --- authentication // --- authentication and time
/** /**
* Authenticate the given user * Authenticate the given user
@ -58,6 +58,23 @@ public class ProducteevInvoker {
this.token = token; this.token = token;
} }
public String getToken() {
return token;
}
/**
* Gets Server time
*/
public String time() throws IOException, ApiServiceException {
JSONObject response = invokeGet("time.json");
try {
return response.getJSONObject("time").getString("value");
} catch (JSONException e) {
throw new ApiServiceException(e);
}
}
// --- tasks // --- tasks
/** /**

@ -4,7 +4,6 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -36,7 +35,7 @@ public class ProducteevRestClient implements RestClient {
private static final int TIMEOUT_MILLIS = 30000; private static final int TIMEOUT_MILLIS = 30000;
private static WeakReference<HttpClient> httpClient = null; private static HttpClient httpClient = null;
private static String convertStreamToString(InputStream is) { private static String convertStreamToString(InputStream is) {
/* /*
@ -67,11 +66,11 @@ public class ProducteevRestClient implements RestClient {
} }
private synchronized static void initializeHttpClient() { private synchronized static void initializeHttpClient() {
if (httpClient == null || httpClient.get() == null) { if (httpClient == null) {
HttpParams params = new BasicHttpParams(); HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_MILLIS); HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_MILLIS);
HttpConnectionParams.setSoTimeout(params, TIMEOUT_MILLIS); HttpConnectionParams.setSoTimeout(params, TIMEOUT_MILLIS);
httpClient = new WeakReference<HttpClient>(new DefaultHttpClient(params)); httpClient = new DefaultHttpClient(params);
} }
} }
@ -117,7 +116,7 @@ public class ProducteevRestClient implements RestClient {
try { try {
HttpGet httpGet = new HttpGet(url); HttpGet httpGet = new HttpGet(url);
HttpResponse response = httpClient.get().execute(httpGet); HttpResponse response = httpClient.execute(httpGet);
return processHttpResponse(response); return processHttpResponse(response);
} catch (IOException e) { } catch (IOException e) {
@ -145,7 +144,7 @@ public class ProducteevRestClient implements RestClient {
try { try {
HttpPost httpPost = new HttpPost(url); HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(data)); httpPost.setEntity(new StringEntity(data));
HttpResponse response = httpClient.get().execute(httpPost); HttpResponse response = httpClient.execute(httpPost);
return processHttpResponse(response); return processHttpResponse(response);
} catch (IOException e) { } catch (IOException e) {

@ -22,7 +22,7 @@ import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.producteev.ProducteevPreferences; import com.todoroo.astrid.producteev.ProducteevUtilities;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
public final class ProducteevDataService { public final class ProducteevDataService {
@ -52,7 +52,7 @@ public final class ProducteevDataService {
@Autowired @Autowired
private MetadataDao metadataDao; private MetadataDao metadataDao;
private final ProducteevPreferences preferences = new ProducteevPreferences(); private final ProducteevUtilities preferences = ProducteevUtilities.INSTANCE;
static final Random random = new Random(); static final Random random = new Random();

@ -31,6 +31,11 @@ public class ProducteevNote {
public static final LongProperty CREATED = new LongProperty(Metadata.TABLE, public static final LongProperty CREATED = new LongProperty(Metadata.TABLE,
Metadata.VALUE3.name); Metadata.VALUE3.name);
/**
* Create metadata from json object
* @param note JSON object with params id_note and message
* @return
*/
@SuppressWarnings("nls") @SuppressWarnings("nls")
public static Metadata create(JSONObject note) { public static Metadata create(JSONObject note) {
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();

@ -29,28 +29,27 @@ import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.api.SynchronizationProvider;
import com.todoroo.astrid.api.TaskContainer; import com.todoroo.astrid.api.TaskContainer;
import com.todoroo.astrid.common.SyncProvider;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.producteev.ProducteevPreferences; import com.todoroo.astrid.producteev.ProducteevPreferences;
import com.todoroo.astrid.producteev.ProducteevUtilities;
import com.todoroo.astrid.producteev.api.ApiResponseParseException; import com.todoroo.astrid.producteev.api.ApiResponseParseException;
import com.todoroo.astrid.producteev.api.ApiServiceException; import com.todoroo.astrid.producteev.api.ApiServiceException;
import com.todoroo.astrid.producteev.api.ApiUtilities; import com.todoroo.astrid.producteev.api.ApiUtilities;
import com.todoroo.astrid.producteev.api.ProducteevInvoker; import com.todoroo.astrid.producteev.api.ProducteevInvoker;
import com.todoroo.astrid.rmilk.MilkUtilities;
import com.todoroo.astrid.rmilk.api.ServiceInternalException;
import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.utility.Preferences; import com.todoroo.astrid.utility.Preferences;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class ProducteevSyncProvider extends SynchronizationProvider<ProducteevTaskContainer> { public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer> {
private ProducteevDataService dataService = null; private ProducteevDataService dataService = null;
private ProducteevInvoker invoker = null; private ProducteevInvoker invoker = null;
private long defaultDashboard; private long defaultDashboard;
private final ProducteevPreferences preferences = new ProducteevPreferences(); private final ProducteevUtilities preferences = ProducteevUtilities.INSTANCE;
/** map of producteev labels to id's */ /** map of producteev labels to id's */
private final HashMap<String, Long> labelMap = new HashMap<String, Long>(); private final HashMap<String, Long> labelMap = new HashMap<String, Long>();
@ -109,19 +108,13 @@ public class ProducteevSyncProvider extends SynchronizationProvider<ProducteevTa
exceptionService.reportError(tag + "-caught", e); //$NON-NLS-1$ exceptionService.reportError(tag + "-caught", e); //$NON-NLS-1$
// occurs when network error // occurs when network error
} else if(e instanceof ServiceInternalException && } else if(!(e instanceof ApiServiceException) && e instanceof IOException) {
((ServiceInternalException)e).getEnclosedException() instanceof exceptionService.reportError(tag + "-ioexception", e); //$NON-NLS-1$
IOException) {
Exception enclosedException = ((ServiceInternalException)e).getEnclosedException();
exceptionService.reportError(tag + "-ioexception", enclosedException); //$NON-NLS-1$
if(showError) { if(showError) {
Context context = ContextManager.getContext(); Context context = ContextManager.getContext();
showError(context, enclosedException, showError(context, e, context.getString(R.string.rmilk_ioerror));
context.getString(R.string.rmilk_ioerror));
} }
} else { } else {
if(e instanceof ServiceInternalException)
e = ((ServiceInternalException)e).getEnclosedException();
exceptionService.reportError(tag + "-unhandled", e); //$NON-NLS-1$ exceptionService.reportError(tag + "-unhandled", e); //$NON-NLS-1$
if(showError) { if(showError) {
Context context = ContextManager.getContext(); Context context = ContextManager.getContext();
@ -165,6 +158,7 @@ public class ProducteevSyncProvider extends SynchronizationProvider<ProducteevTa
password = "astrid"; password = "astrid";
invoker.authenticate(email, password); invoker.authenticate(email, password);
preferences.setToken(invoker.getToken());
} }
performSync(); performSync();
@ -203,7 +197,8 @@ public class ProducteevSyncProvider extends SynchronizationProvider<ProducteevTa
syncData.localUpdated.close(); syncData.localUpdated.close();
} }
MilkUtilities.recordSuccessfulSync(); preferences.setLastServerSync(invoker.time());
preferences.recordSuccessfulSync();
FlurryAgent.onEvent("pdv-sync-finished"); //$NON-NLS-1$ FlurryAgent.onEvent("pdv-sync-finished"); //$NON-NLS-1$
} catch (IllegalStateException e) { } catch (IllegalStateException e) {

@ -30,8 +30,8 @@ import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.api.SynchronizationProvider;
import com.todoroo.astrid.api.TaskContainer; import com.todoroo.astrid.api.TaskContainer;
import com.todoroo.astrid.common.SyncProvider;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.rmilk.MilkLoginActivity; import com.todoroo.astrid.rmilk.MilkLoginActivity;
@ -55,7 +55,7 @@ import com.todoroo.astrid.rmilk.data.MilkNote;
import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
public class RTMSyncProvider extends SynchronizationProvider<RTMTaskContainer> { public class RTMSyncProvider extends SyncProvider<RTMTaskContainer> {
private ServiceImpl rtmService = null; private ServiceImpl rtmService = null;
private String timeline = null; private String timeline = null;

@ -43,7 +43,12 @@ public class TimerDecorationExposer extends BroadcastReceiver {
if(taskId == -1) if(taskId == -1)
return; return;
Task task = PluginServices.getTaskService().fetchById(taskId, Task.ELAPSED_SECONDS, Task.TIMER_START); Task task;
try {
task = PluginServices.getTaskService().fetchById(taskId, Task.ELAPSED_SECONDS, Task.TIMER_START);
} catch (IllegalStateException e) {
return;
}
if(task == null || (task.getValue(Task.ELAPSED_SECONDS) == 0 && if(task == null || (task.getValue(Task.ELAPSED_SECONDS) == 0 &&
task.getValue(Task.TIMER_START) == 0)) task.getValue(Task.TIMER_START) == 0))
return; return;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

@ -12,6 +12,8 @@
<!-- title for notification tray when synchronizing --> <!-- title for notification tray when synchronizing -->
<string name="producteev_notification_title">Astrid: Producteev</string> <string name="producteev_notification_title">Astrid: Producteev</string>
<!-- Error msg when io exception -->
<string name="producteev_ioerror">Connection Error! Check your Internet connection.</string>
</resources> </resources>

@ -91,7 +91,7 @@
<!-- Sync: Clear Data Title --> <!-- Sync: Clear Data Title -->
<string name="rmilk_MPr_forget">Log Out</string> <string name="rmilk_MPr_forget">Log Out</string>
<!-- Sync: Clear Data Description --> <!-- Sync: Clear Data Description -->
<string name="rmilk_MPr_forget_description">Clears all RTM synchronization data</string> <string name="rmilk_MPr_forget_description">Clears all synchronization data</string>
<!-- ======================= MilkLoginActivity ========================= --> <!-- ======================= MilkLoginActivity ========================= -->

Loading…
Cancel
Save