Improvements to logout logic

pull/14/head
Sam Bosley 12 years ago
parent 339093793f
commit 1826417c77

@ -599,9 +599,8 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
} }
// Successful login, create outstanding entries // Successful login, create outstanding entries
long lastId = Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, 0); long lastId = Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, 0);
long newUser = result.optLong("id");
if (!TextUtils.isEmpty(token) && (lastId == 0 || lastId == newUser)) { if (!TextUtils.isEmpty(token) && lastId == 0) {
constructOutstandingTables(); constructOutstandingTables();
} }
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@ -636,7 +635,10 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
@SuppressWarnings("nls") @SuppressWarnings("nls")
private void postAuthenticate(final JSONObject result, final String token) { private void postAuthenticate(final JSONObject result, final String token) {
long lastLoggedInUser = Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, 0); long lastLoggedInUser = Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, 0);
if (lastLoggedInUser > 0) { boolean clearedOnLastLogOut = Preferences.getBoolean(ActFmPreferenceService.PREF_CLEARED_TASKS_ON_LOGOUT, false);
Preferences.setBoolean(ActFmPreferenceService.PREF_CLEARED_TASKS_ON_LOGOUT, false);
if (lastLoggedInUser > 0 && !clearedOnLastLogOut) {
long newUserId = result.optLong("id"); long newUserId = result.optLong("id");
if (lastLoggedInUser != newUserId) { if (lastLoggedInUser != newUserId) {
// In this case, we need to either make all data private or clear all data // In this case, we need to either make all data private or clear all data
@ -650,38 +652,12 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
// TODO: Make all data private
final ProgressDialog pd = DialogUtilities.progressDialog(ActFmLoginActivity.this, getString(R.string.actfm_logged_in_different_user_processing)); final ProgressDialog pd = DialogUtilities.progressDialog(ActFmLoginActivity.this, getString(R.string.actfm_logged_in_different_user_processing));
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
// Delete all tasks not assigned to self rebuildAllSyncData();
taskService.deleteWhere(Criterion.or(Task.USER_ID.neq(0), Task.DELETION_DATE.gt(0)));
// Delete user table
userDao.deleteWhere(Criterion.all);
// Delete attachments table
taskAttachmentDao.deleteWhere(Criterion.all);
// Delete deleted tags
tagDataDao.deleteWhere(TagData.DELETION_DATE.gt(0));
// Delete deleted metadata
metadataDao.deleteWhere(Metadata.DELETION_DATE.gt(0));
// Clear all outstanding tables
taskOutstandingDao.deleteWhere(Criterion.all);
tagOutstandingDao.deleteWhere(Criterion.all);
userActivityOutstandingDao.deleteWhere(Criterion.all);
taskListMetadataOutstandingDao.deleteWhere(Criterion.all);
taskAttachmentOutstandingDao.deleteWhere(Criterion.all);
// Make all tags private
tagMetadataDao.deleteWhere(Criterion.all);
// Generate new uuids for all tasks/tags/user activity/task list metadata and update links
generateNewUuids();
clearTablePushedAtValues();
constructOutstandingTables();
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -708,6 +684,35 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
} }
} }
private void rebuildAllSyncData() {
// Delete all tasks not assigned to self
taskService.deleteWhere(Criterion.or(Task.USER_ID.neq(0), Task.DELETION_DATE.gt(0)));
// Delete user table
userDao.deleteWhere(Criterion.all);
// Delete attachments table
taskAttachmentDao.deleteWhere(Criterion.all);
// Delete deleted tags
tagDataDao.deleteWhere(TagData.DELETION_DATE.gt(0));
// Delete deleted metadata
metadataDao.deleteWhere(Metadata.DELETION_DATE.gt(0));
// Clear all outstanding tables
taskOutstandingDao.deleteWhere(Criterion.all);
tagOutstandingDao.deleteWhere(Criterion.all);
userActivityOutstandingDao.deleteWhere(Criterion.all);
taskListMetadataOutstandingDao.deleteWhere(Criterion.all);
taskAttachmentOutstandingDao.deleteWhere(Criterion.all);
// Make all tags private
tagMetadataDao.deleteWhere(Criterion.all);
// Generate new uuids for all tasks/tags/user activity/task list metadata and update links
generateNewUuids();
clearTablePushedAtValues();
constructOutstandingTables();
}
private void generateNewUuids() { private void generateNewUuids() {
final HashMap<String, String> uuidTaskMap = new HashMap<String, String>(); final HashMap<String, String> uuidTaskMap = new HashMap<String, String>();
HashMap<String, String> uuidTagMap = new HashMap<String, String>(); HashMap<String, String> uuidTagMap = new HashMap<String, String>();

@ -64,6 +64,13 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
RemoteModelDao.outstandingEntryFlag = 1; RemoteModelDao.outstandingEntryFlag = 1;
} }
/**
* @return true if the user is now or has ever been logged in
*/
public boolean wasLoggedIn() {
return Preferences.getLong(PREF_USER_ID, 0) > 0;
}
/** /**
* @return get user id * @return get user id
*/ */
@ -105,6 +112,9 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
/** Act.fm last sync server time */ /** Act.fm last sync server time */
public static final String PREF_SERVER_TIME = IDENTIFIER + "_time"; //$NON-NLS-1$ public static final String PREF_SERVER_TIME = IDENTIFIER + "_time"; //$NON-NLS-1$
/** Whether the user kept existing tasks after last logout */
public static final String PREF_CLEARED_TASKS_ON_LOGOUT = IDENTIFIER + "_logout_cleared_tasks"; //$NON-NLS-1$
private static JSONObject user = null; private static JSONObject user = null;
@Override @Override

@ -10,11 +10,13 @@ import java.io.IOException;
import org.json.JSONObject; import org.json.JSONObject;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface;
import com.timsu.astrid.GCMIntentService; import com.timsu.astrid.GCMIntentService;
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.service.ContextManager;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.billing.BillingConstants; import com.todoroo.astrid.billing.BillingConstants;
import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.Database;
@ -61,11 +63,27 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
} }
@Override @Override
public void signOut(Activity activity) { public void signOut(final Activity activity) {
actFmPreferenceService.setToken(null); actFmPreferenceService.setToken(null);
actFmPreferenceService.clearLastSyncDate(); actFmPreferenceService.clearLastSyncDate();
ActFmPreferenceService.premiumLogout(); ActFmPreferenceService.premiumLogout();
GCMIntentService.unregister(ContextManager.getContext()); GCMIntentService.unregister(ContextManager.getContext());
DialogUtilities.okCancelCustomDialog(activity,
activity.getString(R.string.actfm_logout_clear_tasks_title),
activity.getString(R.string.actfm_logout_clear_tasks_body),
R.string.actfm_logout_clear_tasks_yes,
R.string.actfm_logout_clear_tasks_no,
android.R.drawable.ic_dialog_alert,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
activity.deleteDatabase(database.getName());
Preferences.setBoolean(ActFmPreferenceService.PREF_CLEARED_TASKS_ON_LOGOUT, true);
System.exit(0);
}
},
null);
} }
@Override @Override

@ -358,8 +358,13 @@
<string name="sync_upgr_logged_out">You have been logged out of Astrid</string> <string name="sync_upgr_logged_out">You have been logged out of Astrid</string>
<string name="actfm_logged_in_different_user_title">Warning! Logging in as different user</string> <string name="actfm_logout_clear_tasks_title">Clear data?</string>
<string name="actfm_logged_in_different_user_body">This device was previously signed in under a different user account. Do you want to keep existing data or clear everything? (This cannot be undone, and Astrid will restart when you make your choice)</string> <string name="actfm_logout_clear_tasks_body">Would you like to clear your tasks and lists?</string>
<string name="actfm_logout_clear_tasks_yes">Clear data</string>
<string name="actfm_logout_clear_tasks_no">Keep data</string>
<string name="actfm_logged_in_different_user_title">Logging in as different user</string>
<string name="actfm_logged_in_different_user_body">Would you like to delete existing phone tasks before syncing?</string>
<string name="actfm_logged_in_different_user_keep_data">Keep data</string> <string name="actfm_logged_in_different_user_keep_data">Keep data</string>
<string name="actfm_logged_in_different_user_clear_data">Clear all data</string> <string name="actfm_logged_in_different_user_clear_data">Clear all data</string>
<string name="actfm_logged_in_different_user_processing">Processing existing data...</string> <string name="actfm_logged_in_different_user_processing">Processing existing data...</string>

@ -37,7 +37,7 @@ public class RemoteModelDao<RTYPE extends RemoteModel> extends DatabaseDao<RTYPE
public static boolean getOutstandingEntryFlag() { public static boolean getOutstandingEntryFlag() {
if (outstandingEntryFlag == -1) { if (outstandingEntryFlag == -1) {
synchronized (RemoteModelDao.class) { synchronized (RemoteModelDao.class) {
if (PluginServices.getActFmPreferenceService().isLoggedIn()) if (PluginServices.getActFmPreferenceService().wasLoggedIn())
outstandingEntryFlag = 1; outstandingEntryFlag = 1;
else else
outstandingEntryFlag = 0; outstandingEntryFlag = 0;

Loading…
Cancel
Save