|
@@ -87,15 +87,15 @@ public class ManageAccountsActivity extends FileActivity
|
|
|
private static final int SINGLE_ACCOUNT = 1;
|
|
|
private static final int MIN_MULTI_ACCOUNT_SIZE = 2;
|
|
|
|
|
|
- private RecyclerView mRecyclerView;
|
|
|
- private final Handler mHandler = new Handler();
|
|
|
- private String mAccountName;
|
|
|
- private AccountListAdapter mAccountListAdapter;
|
|
|
- private ServiceConnection mDownloadServiceConnection;
|
|
|
- private ServiceConnection mUploadServiceConnection;
|
|
|
- private Set<String> mOriginalAccounts;
|
|
|
- private String mOriginalCurrentAccount;
|
|
|
- private Drawable mTintedCheck;
|
|
|
+ private RecyclerView recyclerView;
|
|
|
+ private final Handler handler = new Handler();
|
|
|
+ private String accountName;
|
|
|
+ private AccountListAdapter accountListAdapter;
|
|
|
+ private ServiceConnection downloadServiceConnection;
|
|
|
+ private ServiceConnection uploadServiceConnection;
|
|
|
+ private Set<String> originalAccounts;
|
|
|
+ private String originalCurrentAccount;
|
|
|
+ private Drawable tintedCheck;
|
|
|
|
|
|
private ArbitraryDataProvider arbitraryDataProvider;
|
|
|
|
|
@@ -105,24 +105,24 @@ public class ManageAccountsActivity extends FileActivity
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
- mTintedCheck = DrawableCompat.wrap(ContextCompat.getDrawable(this, R.drawable.account_circle_white));
|
|
|
+ tintedCheck = DrawableCompat.wrap(ContextCompat.getDrawable(this, R.drawable.account_circle_white));
|
|
|
int tint = ThemeUtils.elementColor(this);
|
|
|
- DrawableCompat.setTint(mTintedCheck, tint);
|
|
|
+ DrawableCompat.setTint(tintedCheck, tint);
|
|
|
|
|
|
setContentView(R.layout.accounts_layout);
|
|
|
|
|
|
- mRecyclerView = findViewById(R.id.account_list);
|
|
|
+ recyclerView = findViewById(R.id.account_list);
|
|
|
|
|
|
setupToolbar();
|
|
|
updateActionBarTitleAndHomeButtonByString(getResources().getString(R.string.prefs_manage_accounts));
|
|
|
|
|
|
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
|
|
- mOriginalAccounts = DisplayUtils.toAccountNameSet(Arrays.asList(accountList));
|
|
|
+ originalAccounts = DisplayUtils.toAccountNameSet(Arrays.asList(accountList));
|
|
|
|
|
|
Account currentAccount = getUserAccountManager().getCurrentAccount();
|
|
|
|
|
|
if (currentAccount != null) {
|
|
|
- mOriginalCurrentAccount = currentAccount.name;
|
|
|
+ originalCurrentAccount = currentAccount.name;
|
|
|
}
|
|
|
|
|
|
setAccount(currentAccount);
|
|
@@ -130,29 +130,23 @@ public class ManageAccountsActivity extends FileActivity
|
|
|
|
|
|
arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
|
|
|
|
|
- mAccountListAdapter = new AccountListAdapter(this, accountManager, getAccountListItems(), mTintedCheck);
|
|
|
+ accountListAdapter = new AccountListAdapter(this, accountManager, getAccountListItems(), tintedCheck);
|
|
|
|
|
|
- mRecyclerView.setAdapter(mAccountListAdapter);
|
|
|
- mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
|
+ recyclerView.setAdapter(accountListAdapter);
|
|
|
+ recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
|
initializeComponentGetters();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
- switch (resultCode) {
|
|
|
- case KEY_DELETE_CODE:
|
|
|
- if (data != null) {
|
|
|
- Bundle bundle = data.getExtras();
|
|
|
- if (bundle.containsKey(UserInfoActivity.KEY_ACCOUNT)) {
|
|
|
- Account account = Parcels.unwrap(bundle.getParcelable(UserInfoActivity.KEY_ACCOUNT));
|
|
|
- mAccountName = account.name;
|
|
|
- performAccountRemoval(account);
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ if (resultCode == KEY_DELETE_CODE && data != null) {
|
|
|
+ Bundle bundle = data.getExtras();
|
|
|
+ if (bundle != null && bundle.containsKey(UserInfoActivity.KEY_ACCOUNT)) {
|
|
|
+ Account account = Parcels.unwrap(bundle.getParcelable(UserInfoActivity.KEY_ACCOUNT));
|
|
|
+ accountName = account.name;
|
|
|
+ performAccountRemoval(account);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -184,7 +178,7 @@ public class ManageAccountsActivity extends FileActivity
|
|
|
}
|
|
|
|
|
|
Set<String> actualAccounts = DisplayUtils.toAccountNameSet(newList);
|
|
|
- return !mOriginalAccounts.equals(actualAccounts);
|
|
|
+ return !originalAccounts.equals(actualAccounts);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -197,7 +191,7 @@ public class ManageAccountsActivity extends FileActivity
|
|
|
if (account == null) {
|
|
|
return true;
|
|
|
} else {
|
|
|
- return !account.name.equals(mOriginalCurrentAccount);
|
|
|
+ return !account.name.equals(originalCurrentAccount);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -205,15 +199,15 @@ public class ManageAccountsActivity extends FileActivity
|
|
|
* Initialize ComponentsGetters.
|
|
|
*/
|
|
|
private void initializeComponentGetters() {
|
|
|
- mDownloadServiceConnection = newTransferenceServiceConnection();
|
|
|
- if (mDownloadServiceConnection != null) {
|
|
|
- bindService(new Intent(this, FileDownloader.class), mDownloadServiceConnection,
|
|
|
- Context.BIND_AUTO_CREATE);
|
|
|
+ downloadServiceConnection = newTransferenceServiceConnection();
|
|
|
+ if (downloadServiceConnection != null) {
|
|
|
+ bindService(new Intent(this, FileDownloader.class), downloadServiceConnection,
|
|
|
+ Context.BIND_AUTO_CREATE);
|
|
|
}
|
|
|
- mUploadServiceConnection = newTransferenceServiceConnection();
|
|
|
- if (mUploadServiceConnection != null) {
|
|
|
- bindService(new Intent(this, FileUploader.class), mUploadServiceConnection,
|
|
|
- Context.BIND_AUTO_CREATE);
|
|
|
+ uploadServiceConnection = newTransferenceServiceConnection();
|
|
|
+ if (uploadServiceConnection != null) {
|
|
|
+ bindService(new Intent(this, FileUploader.class), uploadServiceConnection,
|
|
|
+ Context.BIND_AUTO_CREATE);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -273,36 +267,36 @@ public class ManageAccountsActivity extends FileActivity
|
|
|
Bundle result = future.getResult();
|
|
|
String name = result.getString(AccountManager.KEY_ACCOUNT_NAME);
|
|
|
accountManager.setCurrentOwnCloudAccount(name);
|
|
|
- mAccountListAdapter = new AccountListAdapter(
|
|
|
+ accountListAdapter = new AccountListAdapter(
|
|
|
this,
|
|
|
accountManager,
|
|
|
getAccountListItems(),
|
|
|
- mTintedCheck
|
|
|
+ tintedCheck
|
|
|
);
|
|
|
- mRecyclerView.setAdapter(mAccountListAdapter);
|
|
|
- runOnUiThread(() -> mAccountListAdapter.notifyDataSetChanged());
|
|
|
+ recyclerView.setAdapter(accountListAdapter);
|
|
|
+ runOnUiThread(() -> accountListAdapter.notifyDataSetChanged());
|
|
|
} catch (OperationCanceledException e) {
|
|
|
Log_OC.d(TAG, "Account creation canceled");
|
|
|
} catch (Exception e) {
|
|
|
Log_OC.e(TAG, "Account creation finished in exception: ", e);
|
|
|
}
|
|
|
}
|
|
|
- }, mHandler);
|
|
|
+ }, handler);
|
|
|
}
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
public void onAccountRemovedEvent(AccountRemovedEvent event) {
|
|
|
List<AccountListItem> accountListItemArray = getAccountListItems();
|
|
|
- mAccountListAdapter.clear();
|
|
|
- mAccountListAdapter.addAll(accountListItemArray);
|
|
|
- mAccountListAdapter.notifyDataSetChanged();
|
|
|
+ accountListAdapter.clear();
|
|
|
+ accountListAdapter.addAll(accountListItemArray);
|
|
|
+ accountListAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run(AccountManagerFuture<Boolean> future) {
|
|
|
if (future.isDone()) {
|
|
|
// after remove account
|
|
|
- Account account = new Account(mAccountName, MainApp.getAccountType(this));
|
|
|
+ Account account = new Account(accountName, MainApp.getAccountType(this));
|
|
|
if (!accountManager.exists(account)) {
|
|
|
// Cancel transfers of the removed account
|
|
|
if (mUploaderBinder != null) {
|
|
@@ -324,8 +318,8 @@ public class ManageAccountsActivity extends FileActivity
|
|
|
|
|
|
List<AccountListItem> accountListItemArray = getAccountListItems();
|
|
|
if (accountListItemArray.size() > SINGLE_ACCOUNT) {
|
|
|
- mAccountListAdapter = new AccountListAdapter(this, accountManager, accountListItemArray, mTintedCheck);
|
|
|
- mRecyclerView.setAdapter(mAccountListAdapter);
|
|
|
+ accountListAdapter = new AccountListAdapter(this, accountManager, accountListItemArray, tintedCheck);
|
|
|
+ recyclerView.setAdapter(accountListAdapter);
|
|
|
} else {
|
|
|
onBackPressed();
|
|
|
}
|
|
@@ -334,19 +328,19 @@ public class ManageAccountsActivity extends FileActivity
|
|
|
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
- if (mDownloadServiceConnection != null) {
|
|
|
- unbindService(mDownloadServiceConnection);
|
|
|
- mDownloadServiceConnection = null;
|
|
|
+ if (downloadServiceConnection != null) {
|
|
|
+ unbindService(downloadServiceConnection);
|
|
|
+ downloadServiceConnection = null;
|
|
|
}
|
|
|
- if (mUploadServiceConnection != null) {
|
|
|
- unbindService(mUploadServiceConnection);
|
|
|
- mUploadServiceConnection = null;
|
|
|
+ if (uploadServiceConnection != null) {
|
|
|
+ unbindService(uploadServiceConnection);
|
|
|
+ uploadServiceConnection = null;
|
|
|
}
|
|
|
|
|
|
super.onDestroy();
|
|
|
}
|
|
|
|
|
|
- public Handler getHandler() { return mHandler; }
|
|
|
+ public Handler getHandler() { return handler; }
|
|
|
|
|
|
@Override
|
|
|
public FileUploader.FileUploaderBinder getFileUploaderBinder() {
|
|
@@ -374,15 +368,15 @@ public class ManageAccountsActivity extends FileActivity
|
|
|
|
|
|
private void performAccountRemoval(Account account) {
|
|
|
// disable account in recycler view
|
|
|
- for (int i = 0; i < mAccountListAdapter.getItemCount(); i++) {
|
|
|
- AccountListItem item = mAccountListAdapter.getItem(i);
|
|
|
+ for (int i = 0; i < accountListAdapter.getItemCount(); i++) {
|
|
|
+ AccountListItem item = accountListAdapter.getItem(i);
|
|
|
|
|
|
if (item != null && item.getAccount().equals(account)) {
|
|
|
item.setEnabled(false);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- mAccountListAdapter.notifyDataSetChanged();
|
|
|
+ accountListAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
|
|
|
// store pending account removal
|