mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Remove out-of-band setAccount/onAccountSet calls
Activity account is set in FilesActivity.onAccount(), but related components are updated in BaseActivity.onStart(). 1. Initialize account in BaseActivity.onCreate() 2. Update storage manager and capabilities immediately on account set, not waiting for onStart() lifecycle. 3. inline storage manager and capabilities update in setAccount() 4. Remove setAccount()/onAccountSet() calls that sets default account, as this duplicates BaseActivity.onCreate() Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
parent
df6d847f29
commit
fb615ef279
9 changed files with 22 additions and 49 deletions
|
@ -217,17 +217,19 @@ public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageCh
|
|||
return;
|
||||
}
|
||||
|
||||
setAccount(account);
|
||||
userAccountManager.setCurrentOwnCloudAccount(account.name);
|
||||
onAccountSet();
|
||||
|
||||
Intent i = new Intent(this, FileDisplayActivity.class);
|
||||
i.setAction(FileDisplayActivity.RESTART);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(i);
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static FeatureItem[] getFirstRun() {
|
||||
return new FeatureItem[]{
|
||||
new FeatureItem(R.drawable.logo, R.string.first_run_1_text, R.string.empty, true, false),
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.PersistableBundle;
|
||||
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
|
@ -96,9 +97,10 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
super.onPostResume();
|
||||
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
|
||||
super.onCreate(savedInstanceState, persistentState);
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
setAccount(account, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,6 +154,11 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
} else {
|
||||
swapToDefaultAccount();
|
||||
}
|
||||
|
||||
if(currentAccount != null) {
|
||||
storageManager = new FileDataStorageManager(currentAccount, getContentResolver());
|
||||
capabilities = storageManager.getCapability(currentAccount.name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,26 +195,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
new Handler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the ownCloud {@link Account} associated to the Activity was just updated.
|
||||
*
|
||||
* Child classes must grant that state depending on the {@link Account} is updated.
|
||||
*/
|
||||
@Deprecated
|
||||
protected void onAccountSet() {
|
||||
if (getAccount() != null) {
|
||||
storageManager = new FileDataStorageManager(getAccount(), getContentResolver());
|
||||
capabilities = storageManager.getCapability(currentAccount.name);
|
||||
} else {
|
||||
Log_OC.e(TAG, "onAccountChanged was called with NULL account associated!");
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void setAccount(Account account) {
|
||||
currentAccount = account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the capabilities of the server where the current OC account lives.
|
||||
*
|
||||
|
@ -228,16 +215,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
public Account getAccount() {
|
||||
return currentAccount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if(currentAccount != null) {
|
||||
onAccountSet();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public FileDataStorageManager getStorageManager() {
|
||||
return storageManager;
|
||||
}
|
||||
|
|
|
@ -1293,7 +1293,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
|
||||
// current account has changed
|
||||
if (data.getBooleanExtra(ManageAccountsActivity.KEY_CURRENT_ACCOUNT_CHANGED, false)) {
|
||||
setAccount(accountManager.getCurrentAccount());
|
||||
setAccount(accountManager.getCurrentAccount(), false);
|
||||
updateAccountList();
|
||||
restart();
|
||||
} else {
|
||||
|
|
|
@ -2621,7 +2621,8 @@ public class FileDisplayActivity extends FileActivity
|
|||
return;
|
||||
}
|
||||
|
||||
setAccount(newAccount);
|
||||
setAccount(newAccount, false);
|
||||
updateAccountList();
|
||||
}
|
||||
|
||||
String fileId = String.valueOf(intent.getStringExtra(KEY_FILE_ID));
|
||||
|
|
|
@ -126,15 +126,12 @@ public class ManageAccountsActivity extends FileActivity implements AccountListA
|
|||
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
originalAccounts = DisplayUtils.toAccountNameSet(Arrays.asList(accountList));
|
||||
|
||||
Account currentAccount = getUserAccountManager().getCurrentAccount();
|
||||
Account currentAccount = getAccount();
|
||||
|
||||
if (currentAccount != null) {
|
||||
originalCurrentAccount = currentAccount.name;
|
||||
}
|
||||
|
||||
setAccount(currentAccount);
|
||||
onAccountSet();
|
||||
|
||||
arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
||||
|
||||
multipleAccountsSupported = getResources().getBoolean(R.bool.multiaccount_support);
|
||||
|
|
|
@ -127,7 +127,7 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
|||
|
||||
if (account != null && (currentAccount == null || !account.equalsIgnoreCase(currentAccount.name))) {
|
||||
accountManager.setCurrentOwnCloudAccount(account);
|
||||
setAccount(getUserAccountManager().getCurrentAccount());
|
||||
setAccount(getUserAccountManager().getCurrentAccount(), false);
|
||||
currentAccount = getAccount();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -208,8 +208,6 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
Log_OC.i(TAG, "No ownCloud account is available");
|
||||
DialogNoAccount dialog = new DialogNoAccount();
|
||||
dialog.show(getSupportFragmentManager(), null);
|
||||
} else if (!savedAccount) {
|
||||
setAccount(accounts[0]);
|
||||
}
|
||||
|
||||
if (!somethingToUpload()) {
|
||||
|
@ -680,7 +678,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
// there is no need for checking for is there more then one
|
||||
// account at this point
|
||||
// since account setup can set only one account at time
|
||||
setAccount(accounts[0]);
|
||||
setAccount(accounts[0], false);
|
||||
populateDirectoryList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
|
||||
if (account != null && currentAccount != null && !account.equalsIgnoreCase(currentAccount.name)) {
|
||||
accountManager.setCurrentOwnCloudAccount(account);
|
||||
setAccount(getUserAccountManager().getCurrentAccount());
|
||||
setAccount(getUserAccountManager().getCurrentAccount(), false);
|
||||
}
|
||||
|
||||
path = getIntent().getStringExtra(MediaFoldersDetectionJob.KEY_MEDIA_FOLDER_PATH);
|
||||
|
|
|
@ -135,9 +135,6 @@ public class UserInfoActivity extends FileActivity implements Injectable {
|
|||
setContentView(R.layout.user_info_layout);
|
||||
unbinder = ButterKnife.bind(this);
|
||||
|
||||
setAccount(getUserAccountManager().getCurrentAccount());
|
||||
onAccountSet();
|
||||
|
||||
boolean useBackgroundImage = URLUtil.isValidUrl(
|
||||
getStorageManager().getCapability(account.name).getServerBackground());
|
||||
|
||||
|
|
Loading…
Reference in a new issue