Merge "Keeps track of "last account used""
This commit is contained in:
commit
7d1324a6df
@ -22,6 +22,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.provider.Account;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -48,6 +49,7 @@ public class Preferences {
|
||||
private static final String TEXT_ZOOM = "textZoom";
|
||||
private static final String BACKGROUND_ATTACHMENTS = "backgroundAttachments";
|
||||
private static final String TRUSTED_SENDERS = "trustedSenders";
|
||||
private static final String LAST_ACCOUNT_USED = "lastAccountUsed";
|
||||
|
||||
public static final int AUTO_ADVANCE_NEWER = 0;
|
||||
public static final int AUTO_ADVANCE_OLDER = 1;
|
||||
@ -262,6 +264,29 @@ public class Preferences {
|
||||
return new JSONArray(set).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last used account ID as set by {@link #setLastUsedAccountId}.
|
||||
* The system makes no attempt to automatically track what is considered a "use" - clients
|
||||
* are expected to call {@link #setLastUsedAccountId} manually.
|
||||
*
|
||||
* Note that the last used account may have been deleted in the background so there is also
|
||||
* no guarantee that the account exists.
|
||||
*/
|
||||
public long getLastUsedAccountId() {
|
||||
return mSharedPreferences.getLong(LAST_ACCOUNT_USED, Account.NO_ACCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified ID of the last account used. Treated as an opaque ID and does not
|
||||
* validate the value. Value is saved asynchronously.
|
||||
*/
|
||||
public void setLastUsedAccountId(long accountId) {
|
||||
mSharedPreferences
|
||||
.edit()
|
||||
.putLong(LAST_ACCOUNT_USED, accountId)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
mSharedPreferences.edit().clear().apply();
|
||||
}
|
||||
|
@ -206,6 +206,7 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
||||
if (mNfcHandler != null) {
|
||||
mNfcHandler.onAccountChanged(); // workaround for email not set on initial load
|
||||
}
|
||||
Preferences.getPreferences(mActivity).setLastUsedAccountId(getUIAccountId());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -556,6 +557,7 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
||||
if (mNfcHandler != null) {
|
||||
mNfcHandler.onAccountChanged();
|
||||
}
|
||||
Preferences.getPreferences(mActivity).setLastUsedAccountId(accountId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,6 +30,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.Preferences;
|
||||
import com.android.email.R;
|
||||
import com.android.email.activity.setup.AccountSettings;
|
||||
import com.android.email.activity.setup.AccountSetupBasics;
|
||||
@ -314,8 +315,18 @@ public class Welcome extends Activity {
|
||||
}
|
||||
} else {
|
||||
// Neither an accountID or a UUID is specified.
|
||||
// Use the default, without showing the "account removed?" toast.
|
||||
accountId = Account.getDefaultAccountId(context);
|
||||
// Use the last account used, falling back to the default.
|
||||
long lastUsedId = Preferences.getPreferences(context).getLastUsedAccountId();
|
||||
if (lastUsedId != Account.NO_ACCOUNT) {
|
||||
if (!Account.isValidId(context, lastUsedId)) {
|
||||
// The last account that was used has since been deleted.
|
||||
lastUsedId = Account.NO_ACCOUNT;
|
||||
Preferences.getPreferences(context).setLastUsedAccountId(Account.NO_ACCOUNT);
|
||||
}
|
||||
}
|
||||
accountId = (lastUsedId == Account.NO_ACCOUNT)
|
||||
? Account.getDefaultAccountId(context)
|
||||
: lastUsedId;
|
||||
}
|
||||
if (accountId != Account.NO_ACCOUNT) {
|
||||
// Okay, the given account is valid.
|
||||
|
Loading…
Reference in New Issue
Block a user