diff --git a/api/res/values/keys.xml b/api/res/values/keys.xml
index ed660ae6b..1cb65b7e4 100644
--- a/api/res/values/keys.xml
+++ b/api/res/values/keys.xml
@@ -29,5 +29,7 @@
sync_sync
sync_forget
+
+ sync_options
diff --git a/api/res/values/strings.xml b/api/res/values/strings.xml
index 178a739e7..a98de36e0 100644
--- a/api/res/values/strings.xml
+++ b/api/res/values/strings.xml
@@ -155,8 +155,10 @@
Status
+
+ Status: %s
- Not Logged In!
+ Not Logged In
Sync Ongoing...
@@ -191,7 +193,7 @@
Actions
- Synchronize Now!
+ Synchronize Now
Log In & Synchronize!
diff --git a/api/src/com/todoroo/astrid/sync/SyncProviderPreferences.java b/api/src/com/todoroo/astrid/sync/SyncProviderPreferences.java
index 5e9bbb6aa..9cad00c1c 100644
--- a/api/src/com/todoroo/astrid/sync/SyncProviderPreferences.java
+++ b/api/src/com/todoroo/astrid/sync/SyncProviderPreferences.java
@@ -4,11 +4,13 @@ import java.util.Date;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceCategory;
import android.view.View;
import android.view.ViewGroup.OnHierarchyChangeListener;
@@ -30,6 +32,8 @@ abstract public class SyncProviderPreferences extends TodorooPreferenceActivity
// --- interface
+ public static final int RESULT_CODE_SYNCHRONIZE = 2;
+
/**
* @return your preference resource
*/
@@ -52,6 +56,8 @@ abstract public class SyncProviderPreferences extends TodorooPreferenceActivity
abstract public SyncProviderUtilities getUtilities();
+ protected static final int REQUEST_LOGIN = 0;
+
// --- implementation
private int statusColor = Color.BLACK;
@@ -106,18 +112,12 @@ abstract public class SyncProviderPreferences extends TodorooPreferenceActivity
else if (r.getString(R.string.sync_SPr_status_key).equals(preference.getKey())) {
boolean loggedIn = getUtilities().isLoggedIn();
String status;
- String subtitle = ""; //$NON-NLS-1$
+ //String subtitle = ""; //$NON-NLS-1$
// ! logged in - display message, click -> sync
if(!loggedIn) {
status = r.getString(R.string.sync_status_loggedout);
- statusColor = Color.RED;
- preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- public boolean onPreferenceClick(Preference p) {
- startSync();
- return true;
- }
- });
+ statusColor = Color.rgb(19, 132, 165);
}
// sync is occurring
else if(getUtilities().isOngoing()) {
@@ -134,9 +134,9 @@ abstract public class SyncProviderPreferences extends TodorooPreferenceActivity
statusColor = Color.rgb(100, 0, 0);
if(getUtilities().getLastSyncDate() > 0) {
- subtitle = r.getString(R.string.sync_status_failed_subtitle,
- DateUtilities.getDateStringWithTime(SyncProviderPreferences.this,
- new Date(getUtilities().getLastSyncDate())));
+// subtitle = r.getString(R.string.sync_status_failed_subtitle,
+// DateUtilities.getDateStringWithTime(SyncProviderPreferences.this,
+// new Date(getUtilities().getLastSyncDate())));
}
} else {
long lastSyncDate = getUtilities().getLastSyncDate();
@@ -146,14 +146,6 @@ abstract public class SyncProviderPreferences extends TodorooPreferenceActivity
status = r.getString(R.string.sync_status_errors, dateString);
statusColor = Color.rgb(100, 100, 0);
}
- preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- public boolean onPreferenceClick(Preference p) {
- String error = getUtilities().getLastError();
- if(error != null)
- DialogUtilities.okDialog(SyncProviderPreferences.this, error, null);
- return true;
- }
- });
}
else if(getUtilities().getLastSyncDate() > 0) {
status = r.getString(R.string.sync_status_success,
@@ -163,38 +155,21 @@ abstract public class SyncProviderPreferences extends TodorooPreferenceActivity
} else {
status = r.getString(R.string.sync_status_never);
statusColor = Color.rgb(0, 0, 100);
- preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- public boolean onPreferenceClick(Preference p) {
- startSync();
- return true;
- }
- });
}
- preference.setTitle(status);
- preference.setSummary(subtitle);
+ preference.setTitle(R.string.sync_SPr_sync);
+ preference.setSummary(r.getString(R.string.sync_SPr_status_subtitle, status));
- View view = findViewById(R.id.status);
- if(view != null)
- view.setBackgroundColor(statusColor);
- }
-
- // sync button
- else if (r.getString(R.string.sync_SPr_sync_key).equals(preference.getKey())) {
- boolean loggedIn = getUtilities().isLoggedIn();
preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference p) {
startSync();
return true;
}
});
- if(!loggedIn) {
- preference.setTitle(R.string.sync_SPr_sync_log_in);
- preference.setSummary("");
- }
- else
- preference.setSummary(r.getString(R.string.sync_SPr_logged_in_prefix) + " " + getUtilities().getLoggedInUserName());
- }
+ View view = findViewById(R.id.status);
+ if(view != null)
+ view.setBackgroundColor(statusColor);
+ }
// log out button
else if (r.getString(R.string.sync_SPr_forget_key).equals(preference.getKey())) {
boolean loggedIn = getUtilities().isLoggedIn();
@@ -212,8 +187,21 @@ abstract public class SyncProviderPreferences extends TodorooPreferenceActivity
return true;
}
});
- if(!loggedIn)
- preference.setEnabled(false);
+ if(!loggedIn) {
+ PreferenceCategory category = (PreferenceCategory) findPreference(r.getString(R.string.sync_SPr_key_options));
+ category.removePreference(preference);
+ }
+
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_LOGIN && resultCode == RESULT_OK) {
+ setResult(RESULT_CODE_SYNCHRONIZE);
+ finish();
+ } else {
+ super.onActivityResult(requestCode, resultCode, data);
}
}
diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java
index 80e4637e3..1e590fed0 100644
--- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java
+++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java
@@ -76,14 +76,12 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmInvoker;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.activity.Eula;
-import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.gtasks.auth.ModernAuthManager;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.service.TaskService;
-import com.todoroo.astrid.sync.SyncResultCallbackAdapter;
/**
* This activity allows users to sign in or log in to Astrid.com
@@ -109,7 +107,6 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
private Facebook facebook;
private AsyncFacebookRunner facebookRunner;
private TextView errors;
- protected boolean noSync = false;
public static final String SHOW_TOAST = "show_toast"; //$NON-NLS-1$
@@ -122,8 +119,6 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
AstridDependencyInjector.initialize();
}
- public static final String EXTRA_DO_NOT_SYNC = "nosync"; //$NON-NLS-1$
-
protected int getContentViewResource() {
return R.layout.actfm_login_activity;
}
@@ -151,8 +146,6 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
rand = new Random(DateUtilities.now());
- noSync = getIntent().getBooleanExtra(EXTRA_DO_NOT_SYNC, false);
-
initializeUI();
getWindow().setFormat(PixelFormat.RGBA_8888);
@@ -538,20 +531,6 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
setResult(RESULT_OK);
finish();
- if (!noSync) {
- new Thread() {
- @Override
- public void run() {
- syncService.synchronizeActiveTasks(false, new SyncResultCallbackAdapter() {
- @Override
- public void finished() {
- ContextManager.getContext().sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH));
- }
- });
- }
- }.start();
- }
-
try {
C2DMReceiver.register();
} catch (Exception e) {
diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmPreferences.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmPreferences.java
index 63460c1cc..746329e08 100644
--- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmPreferences.java
+++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmPreferences.java
@@ -34,7 +34,7 @@ public class ActFmPreferences extends SyncProviderPreferences {
public void startSync() {
if (!actFmPreferenceService.isLoggedIn()) {
Intent intent = new Intent(this, ActFmLoginActivity.class);
- startActivityForResult(intent, 0);
+ startActivityForResult(intent, REQUEST_LOGIN);
} else {
new ActFmSyncV2Provider().synchronizeActiveTasks(true, new SyncResultCallbackAdapter() {
@Override
diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java
index 79d8be4cd..774b5d73f 100644
--- a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java
+++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java
@@ -44,7 +44,7 @@ public class GtasksPreferences extends SyncProviderPreferences {
public void startSync() {
if (!gtasksPreferenceService.isLoggedIn()) {
Intent intent = new Intent(this, GtasksLoginActivity.class);
- startActivityForResult(intent, 0);
+ startActivityForResult(intent, REQUEST_LOGIN);
} else {
new GtasksSyncV2Provider().synchronizeActiveTasks(true, new SyncResultCallbackAdapter() {
@Override
diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java
index c532d9c3f..815912e41 100644
--- a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java
+++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java
@@ -47,13 +47,11 @@ import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
-import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.SyncV2Service;
-import com.todoroo.astrid.sync.SyncResultCallbackAdapter;
/**
* This activity allows users to sign in or log in to Google Tasks
@@ -172,24 +170,6 @@ public class GtasksLoginActivity extends ListActivity {
private void onAuthTokenSuccess() {
gtasksPreferenceService.setToken(authToken);
Preferences.setString(GtasksPreferenceService.PREF_USER_NAME, accountName);
- synchronize();
- }
-
- /**
- * Perform synchronization
- */
- protected void synchronize() {
- new Thread() {
- @Override
- public void run() {
- syncService.synchronizeActiveTasks(false, new SyncResultCallbackAdapter() {
- @Override
- public void finished() {
- ContextManager.getContext().sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH));
- }
- });
- }
- }.start();
setResult(RESULT_OK);
finish();
}
diff --git a/astrid/res/values/keys.xml b/astrid/res/values/keys.xml
index ce9a2d7d4..158996ea0 100644
--- a/astrid/res/values/keys.xml
+++ b/astrid/res/values/keys.xml
@@ -300,6 +300,8 @@
sync_sync
sync_forget
+
+ sync_options
actfmHttps
diff --git a/astrid/res/xml/preferences_actfm.xml b/astrid/res/xml/preferences_actfm.xml
index cdd238280..de8364955 100644
--- a/astrid/res/xml/preferences_actfm.xml
+++ b/astrid/res/xml/preferences_actfm.xml
@@ -14,6 +14,7 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/astrid/res/xml/preferences_producteev.xml b/astrid/res/xml/preferences_producteev.xml
index eac379611..de5150d24 100644
--- a/astrid/res/xml/preferences_producteev.xml
+++ b/astrid/res/xml/preferences_producteev.xml
@@ -14,6 +14,7 @@
-
-
-
-
-
intentComponent = Class.forName(intent.getComponent().getClassName());
+ if (SyncProviderPreferences.class.equals(intentComponent.getSuperclass())) {
+ preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference pref) {
+ startActivityForResult(intent, REQUEST_CODE_SYNC);
+ return true;
+ }
+ });
+ } else {
+ preference.setIntent(intent);
+ }
+ } catch (ClassNotFoundException e) {
+ preference.setIntent(intent);
+ }
String category = MetadataHelper.resolveActivityCategoryName(resolveInfo, pm);
@@ -359,6 +377,11 @@ public class EditPreferences extends TodorooPreferenceActivity {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_CODE_SYNC && resultCode == SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE) {
+ setResult(SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE);
+ finish();
+ return;
+ }
try {
VoiceOutputService.getVoiceOutputInstance().handleActivityResult(requestCode, resultCode, data);
} catch (VerifyError e) {
diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java
index c9da45092..175542e1d 100644
--- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java
+++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java
@@ -87,6 +87,7 @@ import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.service.UpgradeService;
import com.todoroo.astrid.subtasks.SubtasksListFragment;
+import com.todoroo.astrid.sync.SyncProviderPreferences;
import com.todoroo.astrid.ui.QuickAddBar;
import com.todoroo.astrid.utility.AstridPreferences;
import com.todoroo.astrid.utility.Constants;
@@ -690,14 +691,17 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
if(quickAddBar.onActivityResult(requestCode, resultCode, data))
return;
- if (requestCode == ACTIVITY_SETTINGS
- && resultCode == EditPreferences.RESULT_CODE_THEME_CHANGED) {
- getActivity().finish();
- if (overrideFinishAnim) {
- AndroidUtilities.callOverridePendingTransition(getActivity(),
- R.anim.slide_right_in, R.anim.slide_right_out);
+ if (requestCode == ACTIVITY_SETTINGS) {
+ if (resultCode == EditPreferences.RESULT_CODE_THEME_CHANGED) {
+ getActivity().finish();
+ if (overrideFinishAnim) {
+ AndroidUtilities.callOverridePendingTransition(getActivity(),
+ R.anim.slide_right_in, R.anim.slide_right_out);
+ }
+ getActivity().startActivity(getActivity().getIntent());
+ } else if (resultCode == SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE) {
+ Preferences.setLong(SyncActionHelper.PREF_LAST_AUTO_SYNC, 0); // Forces autosync to occur after login
}
- getActivity().startActivity(getActivity().getIntent());
}
super.onActivityResult(requestCode, resultCode, data);
@@ -815,7 +819,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
setListAdapter(taskAdapter);
getListView().setOnScrollListener(this);
registerForContextMenu(getListView());
- syncActionHelper = new SyncActionHelper(getActivity());
+ syncActionHelper = new SyncActionHelper(getActivity(), this);
loadTaskListContent(true);
}
diff --git a/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java b/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java
index 8641db909..c73950519 100644
--- a/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java
+++ b/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java
@@ -18,6 +18,7 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
+import android.support.v4.app.Fragment;
import android.widget.ArrayAdapter;
import android.widget.Toast;
@@ -28,6 +29,7 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
+import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.SyncAction;
@@ -48,7 +50,7 @@ import com.todoroo.astrid.sync.SyncV2Provider;
*/
public class SyncActionHelper {
- private static final String PREF_LAST_AUTO_SYNC = "taskListLastAutoSync"; //$NON-NLS-1$
+ public static final String PREF_LAST_AUTO_SYNC = "taskListLastAutoSync"; //$NON-NLS-1$
private final LinkedHashSet syncActions = new LinkedHashSet();
@@ -56,6 +58,8 @@ public class SyncActionHelper {
private final Activity activity;
+ private final Fragment fragment;
+
protected SyncActionReceiver syncActionReceiver = new SyncActionReceiver();
@Autowired SyncV2Service syncService;
@@ -63,10 +67,11 @@ public class SyncActionHelper {
// --- boilerplate
- public SyncActionHelper(Activity activity) {
+ public SyncActionHelper(Activity activity, Fragment fragment) {
DependencyInjectionService.getInstance().inject(this);
this.activity = activity;
+ this.fragment = fragment;
syncResultCallback = new ProgressBarSyncResultCallback(activity,
R.id.progressBar, new Runnable() {
@Override
@@ -201,7 +206,7 @@ public class SyncActionHelper {
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface click, int which) {
- activity.startActivity(actions[which]);
+ fragment.startActivityForResult(actions[which], TaskListFragment.ACTIVITY_SETTINGS);
}
};
diff --git a/astrid/src/com/todoroo/astrid/service/SyncV2Service.java b/astrid/src/com/todoroo/astrid/service/SyncV2Service.java
index 2b8af7a16..d96b6cc8e 100644
--- a/astrid/src/com/todoroo/astrid/service/SyncV2Service.java
+++ b/astrid/src/com/todoroo/astrid/service/SyncV2Service.java
@@ -42,6 +42,13 @@ public class SyncV2Service {
return Collections.unmodifiableList(actives);
}
+ public boolean hasActiveProvider() {
+ for (SyncV2Provider provider : providers) {
+ if (provider.isActive()) return true;
+ }
+ return false;
+ }
+
/**
* Initiate synchronization of active tasks
*