+
+ /**
+ * Sets and validates the ownCloud {@link Account} associated to the Activity.
+ *
+ * If not valid, tries to swap it for other valid and existing ownCloud {@link Account}.
+ *
+ * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
+ *
+ * @param account New {@link Account} to set.
+ * @param savedAccount When 'true', account was retrieved from a saved instance state.
+ */
+ private void setAccount(Account account, boolean savedAccount) {
+ Account oldAccount = mAccount;
+ boolean validAccount = (account != null && AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), account.name));
+ if (validAccount) {
+ mAccount = account;
+ mAccountWasSet = true;
+ mAccountWasRestored = (savedAccount || mAccount.equals(oldAccount));
+
+ } else {
+ swapToDefaultAccount();
+ }
+ }
+
+
+ /**
+ * Tries to swap the current ownCloud {@link Account} for other valid and existing.
+ *
+ * If no valid ownCloud {@link Account} exists, the the user is requested
+ * to create a new ownCloud {@link Account}.
+ *
+ * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
+ *
+ * @return 'True' if the checked {@link Account} was valid.
+ */
+ private void swapToDefaultAccount() {
+ // default to the most recently used account
+ Account newAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
+ if (newAccount == null) {
+ /// no account available: force account creation
+ createFirstAccount();
+ mRedirectingToSetupAccount = true;
+ mAccountWasSet = false;
+ mAccountWasRestored = false;
+
+ } else {
+ mAccountWasSet = true;
+ mAccountWasRestored = (newAccount.equals(mAccount));
+ mAccount = newAccount;
+ }
+ }
+
+