Refactored sync preferences to go straight back to task list and autosync after logging in, other polish

pull/14/head
Sam Bosley 12 years ago
parent 338e818933
commit 8b0f3e80cc

@ -29,5 +29,7 @@
<string name="sync_SPr_sync_key">sync_sync</string>
<!-- Preference Key (do not translate) -->
<string name="sync_SPr_forget_key">sync_forget</string>
<!-- Preference Key (do not translate) -->
<string name="sync_SPr_key_options">sync_options</string>
</resources>

@ -155,8 +155,10 @@
<!-- Status Group Label -->
<string name="sync_SPr_group_status">Status</string>
<!-- Sync status subtitle, %s-> status message -->
<string name="sync_SPr_status_subtitle">Status: %s</string>
<!-- Sync Status: log in -->
<string name="sync_status_loggedout">Not Logged In!</string>
<string name="sync_status_loggedout">Not Logged In</string>
<!-- Status: ongoing -->
<string name="sync_status_ongoing">Sync Ongoing...</string>
<!-- Sync Status: success status (%s -> last sync date). Keep it short!-->
@ -191,7 +193,7 @@
<string name="sync_SPr_group_actions">Actions</string>
<!-- Synchronize Now Button -->
<string name="sync_SPr_sync">Synchronize Now!</string>
<string name="sync_SPr_sync">Synchronize Now</string>
<!-- Synchronize Now Button if not logged in-->
<string name="sync_SPr_sync_log_in">Log In &amp; Synchronize!</string>

@ -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);
}
}

@ -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) {

@ -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

@ -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

@ -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();
}

@ -300,6 +300,8 @@
<string name="sync_SPr_sync_key">sync_sync</string>
<!-- Preference Key (do not translate) -->
<string name="sync_SPr_forget_key">sync_forget</string>
<!-- Preference Key (do not translate) -->
<string name="sync_SPr_key_options">sync_options</string>
<!-- ===========================================================ACTFM == -->
<string name="actfm_https_key">actfmHttps</string>

@ -14,6 +14,7 @@
</PreferenceCategory>
<PreferenceCategory
android:key="@string/sync_SPr_key_options"
android:title="@string/sync_SPr_group_options">
<com.todoroo.astrid.ui.MultilineListPreference
@ -21,19 +22,11 @@
android:entries="@array/sync_SPr_interval_entries"
android:entryValues="@array/sync_SPr_interval_values"
android:title="@string/sync_SPr_interval_title" />
<com.todoroo.astrid.ui.MultilineCheckboxPreference
android:key="@string/actfm_https_key"
android:title="@string/actfm_https_title"
android:defaultValue="false"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/sync_SPr_group_actions">
<com.todoroo.astrid.ui.MultilinePreference
android:key="@string/sync_SPr_sync_key"
android:title="@string/sync_SPr_sync" />
<com.todoroo.astrid.ui.MultilinePreference
android:key="@string/sync_SPr_forget_key"

@ -14,6 +14,7 @@
</PreferenceCategory>
<PreferenceCategory
android:key="@string/sync_SPr_key_options"
android:title="@string/sync_SPr_group_options">
<com.todoroo.astrid.ui.MultilineListPreference
@ -21,22 +22,12 @@
android:entries="@array/sync_SPr_interval_entries"
android:entryValues="@array/sync_SPr_interval_values"
android:title="@string/sync_SPr_interval_title" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/sync_SPr_group_actions">
<com.todoroo.astrid.ui.MultilinePreference
android:key="@string/sync_SPr_sync_key"
android:title="@string/sync_SPr_sync"
android:summary=""/>
<com.todoroo.astrid.ui.MultilinePreference
android:key="@string/sync_SPr_forget_key"
android:title="@string/sync_SPr_forget"
android:summary="@string/sync_SPr_forget_description" />
</PreferenceCategory>
</PreferenceScreen>

@ -14,6 +14,7 @@
</PreferenceCategory>
<PreferenceCategory
android:key="@string/sync_SPr_key_options"
android:title="@string/sync_SPr_group_options">
<com.todoroo.astrid.ui.MultilineListPreference
@ -25,14 +26,6 @@
<com.todoroo.astrid.ui.MultilineListPreference
android:key="@string/producteev_PPr_defaultdash_key"
android:title="@string/producteev_PPr_defaultdash_title" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/sync_SPr_group_actions">
<com.todoroo.astrid.ui.MultilinePreference
android:key="@string/sync_SPr_sync_key"
android:title="@string/sync_SPr_sync" />
<com.todoroo.astrid.ui.MultilinePreference
android:key="@string/sync_SPr_forget_key"

@ -49,6 +49,7 @@ import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.sync.SyncProviderPreferences;
import com.todoroo.astrid.ui.ContactListAdapter;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Flags;
@ -67,6 +68,8 @@ public class EditPreferences extends TodorooPreferenceActivity {
private static final int APPEARANCE_PREFERENCE = 3;
private static final int POWER_PACK_PREFERENCE = 4;
private static final int REQUEST_CODE_SYNC = 0;
public static final int RESULT_CODE_THEME_CHANGED = 1;
// --- instance variables
@ -186,7 +189,7 @@ public class EditPreferences extends TodorooPreferenceActivity {
// that have a settings action
for(int i = 0; i < length; i++) {
ResolveInfo resolveInfo = resolveInfoList.get(i);
Intent intent = new Intent(AstridApiConstants.ACTION_SETTINGS);
final Intent intent = new Intent(AstridApiConstants.ACTION_SETTINGS);
intent.setClassName(resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
@ -196,7 +199,22 @@ public class EditPreferences extends TodorooPreferenceActivity {
Preference preference = new Preference(this);
preference.setTitle(resolveInfo.activityInfo.loadLabel(pm));
preference.setIntent(intent);
try {
Class<?> 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) {

@ -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);
}

@ -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<SyncAction> syncActions = new LinkedHashSet<SyncAction>();
@ -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);
}
};

@ -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
*

Loading…
Cancel
Save