Fixed some bugs, now we actually are able to synchronize producteev workspaces and responsible parties. Todo: edit dashboard / responsible, filters, hide tasks you aren't able to edit

pull/14/head
Tim Su 16 years ago
parent aa2fe7db1b
commit 5472e0da2c

@ -15,6 +15,7 @@ import android.util.Log;
import com.todoroo.andlib.data.Property.PropertyVisitor; import com.todoroo.andlib.data.Property.PropertyVisitor;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.AndroidUtilities;
/** /**
* AbstractDatabase is a database abstraction which wraps a SQLite database. * AbstractDatabase is a database abstraction which wraps a SQLite database.
@ -160,8 +161,10 @@ abstract public class AbstractDatabase {
* @return sql database. opens database if not yet open * @return sql database. opens database if not yet open
*/ */
public synchronized final SQLiteDatabase getDatabase() { public synchronized final SQLiteDatabase getDatabase() {
if(database == null) if(database == null) {
AndroidUtilities.sleepDeep(300L);
openForWriting(); openForWriting();
}
return database; return database;
} }

@ -297,4 +297,16 @@ public class AndroidUtilities {
} }
} }
} }
/**
* Sleep, ignoring interruption
* @param l
*/
public static void sleepDeep(long l) {
try {
Thread.sleep(l);
} catch (InterruptedException e) {
// ignore
}
}
} }

@ -83,10 +83,10 @@ public class ProducteevDetailExposer extends BroadcastReceiver implements Detail
// display responsible user if not current one // display responsible user if not current one
if(responsibleId > 0 && ownerDashboard != null && responsibleId != if(responsibleId > 0 && ownerDashboard != null && responsibleId !=
Preferences.getLong(ProducteevUtilities.PREF_USER_ID, 0L)) { Preferences.getLong(ProducteevUtilities.PREF_USER_ID, 0L)) {
String users = ownerDashboard.getValue(ProducteevDashboard.USERS); String users = ";" + ownerDashboard.getValue(ProducteevDashboard.USERS); //$NON-NLS-1$
int index = users.indexOf(";" + responsibleId + ","); //$NON-NLS-1$ //$NON-NLS-2$ int index = users.indexOf(";" + responsibleId + ","); //$NON-NLS-1$ //$NON-NLS-2$
if(index > -1) { if(index > -1) {
String user = users.substring(users.indexOf(',', index), String user = users.substring(users.indexOf(',', index) + 1,
users.indexOf(';', index + 1)); users.indexOf(';', index + 1));
builder.append(context.getString(R.string.producteev_TLA_responsible, builder.append(context.getString(R.string.producteev_TLA_responsible,
user)).append(TaskAdapter.DETAIL_SEPARATOR); user)).append(TaskAdapter.DETAIL_SEPARATOR);

@ -36,6 +36,7 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.producteev.api.ApiAuthenticationException;
import com.todoroo.astrid.producteev.api.ProducteevInvoker; import com.todoroo.astrid.producteev.api.ProducteevInvoker;
import com.todoroo.astrid.producteev.sync.ProducteevSyncProvider; import com.todoroo.astrid.producteev.sync.ProducteevSyncProvider;
import com.todoroo.astrid.utility.Preferences; import com.todoroo.astrid.utility.Preferences;
@ -152,6 +153,8 @@ public class ProducteevLoginActivity extends Activity {
ProducteevUtilities.INSTANCE.setToken(invoker.getToken()); ProducteevUtilities.INSTANCE.setToken(invoker.getToken());
synchronize(); synchronize();
} catch (ApiAuthenticationException e) {
errorMessage.append(getString(R.string.producteev_PLA_errorAuth));
} catch (Exception e) { } catch (Exception e) {
errorMessage.append(e.getMessage()); errorMessage.append(e.getMessage());
} finally { } finally {

@ -51,8 +51,8 @@ public class ProducteevPreferences extends SyncProviderPreferences {
ListPreference defaultDash = (ListPreference)findPreference(getString(R.string.producteev_PPr_defaultdash_key)); ListPreference defaultDash = (ListPreference)findPreference(getString(R.string.producteev_PPr_defaultdash_key));
String[] entries, entryValues; String[] entries, entryValues;
if(ProducteevUtilities.INSTANCE.isLoggedIn()) { StoreObject[] dashboards = ProducteevDataService.getInstance().getDashboards();
StoreObject[] dashboards = ProducteevDataService.getInstance().getDashboards(); if(ProducteevUtilities.INSTANCE.isLoggedIn() && dashboards.length > 0) {
entries = new String[dashboards.length + 1]; entries = new String[dashboards.length + 1];
entryValues = new String[dashboards.length + 1]; entryValues = new String[dashboards.length + 1];
for(int i = 0; i < dashboards.length; i++) { for(int i = 0; i < dashboards.length; i++) {

@ -18,6 +18,7 @@ import org.apache.http.params.HttpParams;
import org.json.JSONObject; import org.json.JSONObject;
import com.todoroo.andlib.service.RestClient; import com.todoroo.andlib.service.RestClient;
import com.todoroo.astrid.utility.Constants;
/** /**
* RestClient allows Android to consume web requests. * RestClient allows Android to consume web requests.
@ -85,6 +86,8 @@ public class ProducteevRestClient implements RestClient {
contentStream.close(); contentStream.close();
} }
} }
if(Constants.DEBUG)
System.err.println(body);
int statusCode = response.getStatusLine().getStatusCode(); int statusCode = response.getStatusLine().getStatusCode();
if(statusCode != HTTP_OK || (body != null && body.startsWith("{\"error\":"))) { //$NON-NLS-1$ if(statusCode != HTTP_OK || (body != null && body.startsWith("{\"error\":"))) { //$NON-NLS-1$
@ -100,7 +103,10 @@ public class ProducteevRestClient implements RestClient {
else else
error = new ApiServiceException(errorMessage); error = new ApiServiceException(errorMessage);
} catch (Exception e) { } catch (Exception e) {
error = new ApiServiceException(response.getStatusLine() + if(statusCode == 401)
error = new ApiAuthenticationException(response.getStatusLine().getReasonPhrase());
else
error = new ApiServiceException(response.getStatusLine() +
"\n" + body); //$NON-NLS-1$ "\n" + body); //$NON-NLS-1$
} }
throw error; throw error;
@ -120,7 +126,8 @@ public class ProducteevRestClient implements RestClient {
public synchronized String get(String url) throws IOException { public synchronized String get(String url) throws IOException {
initializeHttpClient(); initializeHttpClient();
System.err.println("GET: " + url); //$NON-NLS-1$ // (debug) if(Constants.DEBUG)
System.err.println("GET: " + url); //$NON-NLS-1$ // (debug)
try { try {
HttpGet httpGet = new HttpGet(url); HttpGet httpGet = new HttpGet(url);
@ -147,7 +154,8 @@ public class ProducteevRestClient implements RestClient {
public synchronized String post(String url, String data) throws IOException { public synchronized String post(String url, String data) throws IOException {
initializeHttpClient(); initializeHttpClient();
System.err.println("POST: " + url); //$NON-NLS-1$ // (debug) if(Constants.DEBUG)
System.err.println("POST: " + url); //$NON-NLS-1$ // (debug)
try { try {
HttpPost httpPost = new HttpPost(url); HttpPost httpPost = new HttpPost(url);

@ -182,7 +182,7 @@ public final class ProducteevDataService {
*/ */
public Metadata getTaskMetadata(long taskId) { public Metadata getTaskMetadata(long taskId) {
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select( TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(
ProducteevTask.ID, ProducteevTask.DASHBOARD_ID).where( Metadata.PROPERTIES).where(
MetadataCriteria.byTaskAndwithKey(taskId, ProducteevTask.METADATA_KEY))); MetadataCriteria.byTaskAndwithKey(taskId, ProducteevTask.METADATA_KEY)));
try { try {
if(cursor.getCount() == 0) if(cursor.getCount() == 0)
@ -270,9 +270,10 @@ public final class ProducteevDataService {
JSONArray accessList = remote.getJSONArray("accesslist"); JSONArray accessList = remote.getJSONArray("accesslist");
for(int j = 0; j < accessList.length(); j++) { for(int j = 0; j < accessList.length(); j++) {
JSONObject user = accessList.getJSONObject(j).getJSONObject("user"); JSONObject user = accessList.getJSONObject(j).getJSONObject("user");
users.append(user.getLong("id_user")).append(','). users.append(user.getLong("id_user")).append(',');
append(user.getString("firstName")).append(' '). String name = user.optString("firstname", "") + ' ' +
append(user.getString("lastName")).append(';'); user.optString("lastname", "");
users.append(name.trim()).append(';');
} }
local.setValue(ProducteevDashboard.USERS, users.toString()); local.setValue(ProducteevDashboard.USERS, users.toString());
storeObjectDao.persist(local); storeObjectDao.persist(local);

@ -5,10 +5,10 @@
<!-- ====================== Plugin Boilerplate ========================= --> <!-- ====================== Plugin Boilerplate ========================= -->
<!-- task detail showing Producteev dashboard information (%s => workspace name) --> <!-- task detail showing Producteev dashboard information (%s => workspace name) -->
<string name="producteev_TLA_dashboard">Workspace: %s</string> <string name="producteev_TLA_dashboard">W: %s</string>
<!-- task detail showing Producteev responsible information (%s => responsible user) --> <!-- task detail showing Producteev responsible information (%s => responsible user) -->
<string name="producteev_TLA_responsible">Responsible: %s</string> <string name="producteev_TLA_responsible">R: %s</string>
<!-- ==================================================== Preferences == --> <!-- ==================================================== Preferences == -->
@ -69,6 +69,9 @@
<!-- Error Message when passwords don't match --> <!-- Error Message when passwords don't match -->
<string name="producteev_PLA_errorMatch">Error: passwords don\'t match!</string> <string name="producteev_PLA_errorMatch">Error: passwords don\'t match!</string>
<!-- Error Message when we receive a HTTP 401 Unauthorized -->
<string name="producteev_PLA_errorAuth">Error: e-mail or password incorrect!</string>
<!-- ================================================ Synchronization == --> <!-- ================================================ Synchronization == -->
<!-- title for notification tray when synchronizing --> <!-- title for notification tray when synchronizing -->

@ -77,8 +77,8 @@ public class Database extends AbstractDatabase {
sql.append("CREATE INDEX IF NOT EXISTS so_id ON "). sql.append("CREATE INDEX IF NOT EXISTS so_id ON ").
append(StoreObject.TABLE).append('('). append(StoreObject.TABLE).append('(').
append(StoreObject.TYPE).append(','). append(StoreObject.TYPE.name).append(',').
append(StoreObject.ITEM). append(StoreObject.ITEM.name).
append(')'); append(')');
database.execSQL(sql.toString()); database.execSQL(sql.toString());
sql.setLength(0); sql.setLength(0);
@ -114,8 +114,8 @@ public class Database extends AbstractDatabase {
sql.append("CREATE INDEX IF NOT EXISTS so_id ON "). sql.append("CREATE INDEX IF NOT EXISTS so_id ON ").
append(StoreObject.TABLE).append('('). append(StoreObject.TABLE).append('(').
append(StoreObject.TYPE).append(','). append(StoreObject.TYPE.name).append(',').
append(StoreObject.ITEM). append(StoreObject.ITEM.name).
append(')'); append(')');
database.execSQL(sql.toString()); database.execSQL(sql.toString());
} }

@ -35,7 +35,7 @@ public final class Constants {
/** /**
* Whether to turn on debugging logging and UI * Whether to turn on debugging logging and UI
*/ */
public static final boolean DEBUG = false; public static final boolean DEBUG = true;
/** /**
* Upgrade time * Upgrade time

Loading…
Cancel
Save