|
|
|
@ -12,10 +12,12 @@ import org.json.JSONArray;
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.Notification;
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
import com.flurry.android.FlurryAgent;
|
|
|
|
@ -33,12 +35,15 @@ import com.todoroo.astrid.api.TaskContainer;
|
|
|
|
|
import com.todoroo.astrid.common.SyncProvider;
|
|
|
|
|
import com.todoroo.astrid.model.Metadata;
|
|
|
|
|
import com.todoroo.astrid.model.Task;
|
|
|
|
|
import com.todoroo.astrid.producteev.ProducteevLoginActivity;
|
|
|
|
|
import com.todoroo.astrid.producteev.ProducteevPreferences;
|
|
|
|
|
import com.todoroo.astrid.producteev.ProducteevUtilities;
|
|
|
|
|
import com.todoroo.astrid.producteev.ProducteevLoginActivity.SyncLoginCallback;
|
|
|
|
|
import com.todoroo.astrid.producteev.api.ApiResponseParseException;
|
|
|
|
|
import com.todoroo.astrid.producteev.api.ApiServiceException;
|
|
|
|
|
import com.todoroo.astrid.producteev.api.ApiUtilities;
|
|
|
|
|
import com.todoroo.astrid.producteev.api.ProducteevInvoker;
|
|
|
|
|
import com.todoroo.astrid.rmilk.api.ServiceInternalException;
|
|
|
|
|
import com.todoroo.astrid.rmilk.data.MilkNote;
|
|
|
|
|
import com.todoroo.astrid.service.AstridDependencyInjector;
|
|
|
|
|
import com.todoroo.astrid.tags.TagService;
|
|
|
|
@ -150,18 +155,46 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
|
|
|
|
|
|
|
|
|
|
String email = Preferences.getStringValue(R.string.producteev_PPr_email);
|
|
|
|
|
String password = Preferences.getStringValue(R.string.producteev_PPr_password);
|
|
|
|
|
email = "astrid@todoroo.com"; // TODO
|
|
|
|
|
password = "astrid"; // TODO
|
|
|
|
|
|
|
|
|
|
// check if we have a token & it works
|
|
|
|
|
if(authToken != null) {
|
|
|
|
|
invoker.setCredentials(authToken, email, password);
|
|
|
|
|
performSync();
|
|
|
|
|
} else {
|
|
|
|
|
invoker.authenticate(email, password);
|
|
|
|
|
preferences.setToken(invoker.getToken());
|
|
|
|
|
if (email == null && password == null) {
|
|
|
|
|
// display login-activity
|
|
|
|
|
final Context context = ContextManager.getContext();
|
|
|
|
|
Intent intent = new Intent(context, ProducteevLoginActivity.class);
|
|
|
|
|
ProducteevLoginActivity.setCallback(new SyncLoginCallback() {
|
|
|
|
|
public String verifyLogin(final Handler syncLoginHandler, String em, String pass) {
|
|
|
|
|
try {
|
|
|
|
|
invoker.authenticate(em, pass);
|
|
|
|
|
preferences.setToken(invoker.getToken());
|
|
|
|
|
Preferences.setString(R.string.producteev_PPr_email, em);
|
|
|
|
|
Preferences.setString(R.string.producteev_PPr_password, pass);
|
|
|
|
|
performSync();
|
|
|
|
|
return null;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// didn't work
|
|
|
|
|
exceptionService.reportError("producteev-verify-login", e);
|
|
|
|
|
if(e instanceof ServiceInternalException)
|
|
|
|
|
e = ((ServiceInternalException)e).getEnclosedException();
|
|
|
|
|
return context.getString(R.string.producteev_ioerror, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if(context instanceof Activity)
|
|
|
|
|
((Activity)context).startActivityForResult(intent, 0);
|
|
|
|
|
else {
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
invoker.authenticate(email, password);
|
|
|
|
|
preferences.setToken(invoker.getToken());
|
|
|
|
|
performSync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
performSync();
|
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
|
// occurs when application was closed
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|