From 02e01755dbfe3c08c87d19f4ebfbde9916d697ca Mon Sep 17 00:00:00 2001 From: Esa Firman Date: Wed, 4 Oct 2017 23:07:00 +0700 Subject: [PATCH] Move account chooser in ReceiveExternalFilesActivity Showing it in overflow menu instead of when the page is open https://github.com/nextcloud/android/issues/344 --- .../ReceiveExternalFilesActivity.java | 44 ++++------------ src/main/res/menu/receive_file_menu.xml | 51 +++++++++++++++++++ 2 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 src/main/res/menu/receive_file_menu.xml diff --git a/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java b/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java index 878f1ceae9..1caacd8275 100755 --- a/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java @@ -134,15 +134,11 @@ public class ReceiveExternalFilesActivity extends FileActivity private SyncBroadcastReceiver mSyncBroadcastReceiver; private boolean mSyncInProgress = false; - private boolean mAccountSelected; - private boolean mAccountSelectionShowing; private final static int REQUEST_CODE__SETUP_ACCOUNT = REQUEST_CODE__LAST_SHARED + 1; private final static String KEY_PARENTS = "PARENTS"; private final static String KEY_FILE = "FILE"; - private final static String KEY_ACCOUNT_SELECTED = "ACCOUNT_SELECTED"; - private final static String KEY_ACCOUNT_SELECTION_SHOWING = "ACCOUNT_SELECTION_SHOWING"; private boolean mUploadFromTmpFile = false; private String mSubjectText; @@ -162,22 +158,13 @@ public class ReceiveExternalFilesActivity extends FileActivity if (savedInstanceState == null) { mParents = new Stack<>(); - mAccountSelected = false; - mAccountSelectionShowing = false; - } else { mParents = (Stack) savedInstanceState.getSerializable(KEY_PARENTS); mFile = savedInstanceState.getParcelable(KEY_FILE); - mAccountSelected = savedInstanceState.getBoolean(KEY_ACCOUNT_SELECTED); - mAccountSelectionShowing = savedInstanceState.getBoolean(KEY_ACCOUNT_SELECTION_SHOWING); } super.onCreate(savedInstanceState); - if (mAccountSelected) { - setAccount(savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT)); - } - // Listen for sync messages IntentFilter syncIntentFilter = new IntentFilter(RefreshFolderOperation. EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); @@ -205,11 +192,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 (accounts.length > 1 && !mAccountSelected && !mAccountSelectionShowing) { - Log_OC.i(TAG, "More than one ownCloud is available"); - DialogMultipleAccount dialog = new DialogMultipleAccount(); - dialog.show(getSupportFragmentManager(), null); - mAccountSelectionShowing = true; } else { if (!savedAccount) { setAccount(accounts[0]); @@ -225,6 +207,11 @@ public class ReceiveExternalFilesActivity extends FileActivity super.setAccount(account, savedAccount); } + private void showAccountChooserDialog() { + DialogMultipleAccount dialog = new DialogMultipleAccount(); + dialog.show(getSupportFragmentManager(), null); + } + @Override protected void onAccountSet(boolean stateWasRecovered) { super.onAccountSet(mAccountWasRestored); @@ -238,8 +225,6 @@ public class ReceiveExternalFilesActivity extends FileActivity super.onSaveInstanceState(outState); outState.putSerializable(KEY_PARENTS, mParents); outState.putParcelable(KEY_FILE, mFile); - outState.putBoolean(KEY_ACCOUNT_SELECTED, mAccountSelected); - outState.putBoolean(KEY_ACCOUNT_SELECTION_SHOWING, mAccountSelectionShowing); outState.putParcelable(FileActivity.EXTRA_ACCOUNT, getAccount()); Log_OC.d(TAG, "onSaveInstanceState() end"); @@ -308,11 +293,9 @@ public class ReceiveExternalFilesActivity extends FileActivity @Override public void onClick(DialogInterface dialog, int which) { final ReceiveExternalFilesActivity parent = (ReceiveExternalFilesActivity) getActivity(); - parent.setAccount(parent.mAccountManager.getAccountsByType(MainApp.getAccountType())[which]); + parent.setAccount(parent.mAccountManager.getAccountsByType(MainApp.getAccountType())[which], false); parent.onAccountSet(parent.mAccountWasRestored); dialog.dismiss(); - parent.mAccountSelected = true; - parent.mAccountSelectionShowing = false; } }); builder.setCancelable(true); @@ -333,13 +316,6 @@ public class ReceiveExternalFilesActivity extends FileActivity return adapterAccountList; } - - public void onCancel(DialogInterface dialog) { - super.onCancel(dialog); - final ReceiveExternalFilesActivity parent = (ReceiveExternalFilesActivity) getActivity(); - parent.mAccountSelectionShowing = false; - parent.finish(); - } } public static class DialogInputUploadFilename extends DialogFragment { @@ -1033,10 +1009,7 @@ public class ReceiveExternalFilesActivity extends FileActivity @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.main_menu, menu); - menu.findItem(R.id.action_sort).setVisible(false); - menu.findItem(R.id.action_switch_view).setVisible(false); - menu.findItem(R.id.action_sync_account).setVisible(false); + inflater.inflate(R.menu.receive_file_menu, menu); return true; } @@ -1055,6 +1028,9 @@ public class ReceiveExternalFilesActivity extends FileActivity onBackPressed(); } break; + case R.id.action_choose_account: + showAccountChooserDialog(); + break; default: retval = super.onOptionsItemSelected(item); diff --git a/src/main/res/menu/receive_file_menu.xml b/src/main/res/menu/receive_file_menu.xml new file mode 100644 index 0000000000..68ca9e799b --- /dev/null +++ b/src/main/res/menu/receive_file_menu.xml @@ -0,0 +1,51 @@ + + + + + + + + + +