Merge pull request #1684 from esafirm/develop

Move account choice from startup to menu item. Add subtitle for account name
This commit is contained in:
Andy Scherzinger 2017-10-19 15:58:49 +02:00 committed by GitHub
commit 7234efc802
8 changed files with 107 additions and 68 deletions

View file

@ -134,15 +134,11 @@ public class ReceiveExternalFilesActivity extends FileActivity
private SyncBroadcastReceiver mSyncBroadcastReceiver; private SyncBroadcastReceiver mSyncBroadcastReceiver;
private boolean mSyncInProgress = false; 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 int REQUEST_CODE__SETUP_ACCOUNT = REQUEST_CODE__LAST_SHARED + 1;
private final static String KEY_PARENTS = "PARENTS"; private final static String KEY_PARENTS = "PARENTS";
private final static String KEY_FILE = "FILE"; 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 boolean mUploadFromTmpFile = false;
private String mSubjectText; private String mSubjectText;
@ -162,22 +158,13 @@ public class ReceiveExternalFilesActivity extends FileActivity
if (savedInstanceState == null) { if (savedInstanceState == null) {
mParents = new Stack<>(); mParents = new Stack<>();
mAccountSelected = false;
mAccountSelectionShowing = false;
} else { } else {
mParents = (Stack<String>) savedInstanceState.getSerializable(KEY_PARENTS); mParents = (Stack<String>) savedInstanceState.getSerializable(KEY_PARENTS);
mFile = savedInstanceState.getParcelable(KEY_FILE); mFile = savedInstanceState.getParcelable(KEY_FILE);
mAccountSelected = savedInstanceState.getBoolean(KEY_ACCOUNT_SELECTED);
mAccountSelectionShowing = savedInstanceState.getBoolean(KEY_ACCOUNT_SELECTION_SHOWING);
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (mAccountSelected) {
setAccount(savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT));
}
// Listen for sync messages // Listen for sync messages
IntentFilter syncIntentFilter = new IntentFilter(RefreshFolderOperation. IntentFilter syncIntentFilter = new IntentFilter(RefreshFolderOperation.
EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
@ -205,11 +192,6 @@ public class ReceiveExternalFilesActivity extends FileActivity
Log_OC.i(TAG, "No ownCloud account is available"); Log_OC.i(TAG, "No ownCloud account is available");
DialogNoAccount dialog = new DialogNoAccount(); DialogNoAccount dialog = new DialogNoAccount();
dialog.show(getSupportFragmentManager(), null); 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 { } else {
if (!savedAccount) { if (!savedAccount) {
setAccount(accounts[0]); setAccount(accounts[0]);
@ -225,6 +207,11 @@ public class ReceiveExternalFilesActivity extends FileActivity
super.setAccount(account, savedAccount); super.setAccount(account, savedAccount);
} }
private void showAccountChooserDialog() {
DialogMultipleAccount dialog = new DialogMultipleAccount();
dialog.show(getSupportFragmentManager(), null);
}
@Override @Override
protected void onAccountSet(boolean stateWasRecovered) { protected void onAccountSet(boolean stateWasRecovered) {
super.onAccountSet(mAccountWasRestored); super.onAccountSet(mAccountWasRestored);
@ -238,8 +225,6 @@ public class ReceiveExternalFilesActivity extends FileActivity
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putSerializable(KEY_PARENTS, mParents); outState.putSerializable(KEY_PARENTS, mParents);
outState.putParcelable(KEY_FILE, mFile); outState.putParcelable(KEY_FILE, mFile);
outState.putBoolean(KEY_ACCOUNT_SELECTED, mAccountSelected);
outState.putBoolean(KEY_ACCOUNT_SELECTION_SHOWING, mAccountSelectionShowing);
outState.putParcelable(FileActivity.EXTRA_ACCOUNT, getAccount()); outState.putParcelable(FileActivity.EXTRA_ACCOUNT, getAccount());
Log_OC.d(TAG, "onSaveInstanceState() end"); Log_OC.d(TAG, "onSaveInstanceState() end");
@ -308,11 +293,9 @@ public class ReceiveExternalFilesActivity extends FileActivity
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
final ReceiveExternalFilesActivity parent = (ReceiveExternalFilesActivity) getActivity(); 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); parent.onAccountSet(parent.mAccountWasRestored);
dialog.dismiss(); dialog.dismiss();
parent.mAccountSelected = true;
parent.mAccountSelectionShowing = false;
} }
}); });
builder.setCancelable(true); builder.setCancelable(true);
@ -333,13 +316,6 @@ public class ReceiveExternalFilesActivity extends FileActivity
return adapterAccountList; 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 { public static class DialogInputUploadFilename extends DialogFragment {
@ -722,11 +698,21 @@ public class ReceiveExternalFilesActivity extends FileActivity
} }
} }
private void setupActionBarSubtitle() {
if (isHaveMultipleAccount()) {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setSubtitle(getAccount().name);
}
}
}
private void populateDirectoryList() { private void populateDirectoryList() {
setContentView(R.layout.uploader_layout); setContentView(R.layout.uploader_layout);
setupEmptyList(); setupEmptyList();
setupToolbar(); setupToolbar();
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
setupActionBarSubtitle();
ListView mListView = (ListView) findViewById(android.R.id.list); ListView mListView = (ListView) findViewById(android.R.id.list);
@ -1030,13 +1016,20 @@ public class ReceiveExternalFilesActivity extends FileActivity
} }
} }
private boolean isHaveMultipleAccount() {
return mAccountManager.getAccountsByType(MainApp.getAccountType()).length > 1;
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu); inflater.inflate(R.menu.receive_file_menu, menu);
menu.findItem(R.id.action_sort).setVisible(false);
menu.findItem(R.id.action_switch_view).setVisible(false); if (!isHaveMultipleAccount()) {
menu.findItem(R.id.action_sync_account).setVisible(false); MenuItem switchAccountMenu = menu.findItem(R.id.action_switch_account);
switchAccountMenu.setVisible(false);
}
return true; return true;
} }
@ -1055,6 +1048,9 @@ public class ReceiveExternalFilesActivity extends FileActivity
onBackPressed(); onBackPressed();
} }
break; break;
case R.id.action_switch_account:
showAccountChooserDialog();
break;
default: default:
retval = super.onOptionsItemSelected(item); retval = super.onOptionsItemSelected(item);

View file

@ -1,4 +1,4 @@
/** /*
* ownCloud Android client application * ownCloud Android client application
* *
* @author David A. Velasco * @author David A. Velasco
@ -29,6 +29,8 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -77,6 +79,7 @@ public class ShareLinkToDialog extends DialogFragment {
} }
@Override @Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
mIntent = getArguments().getParcelable(ARG_INTENT); mIntent = getArguments().getParcelable(ARG_INTENT);
String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE); String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE);
@ -84,8 +87,7 @@ public class ShareLinkToDialog extends DialogFragment {
packagesToExclude : new String[0]); packagesToExclude : new String[0]);
PackageManager pm= getActivity().getPackageManager(); PackageManager pm= getActivity().getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY);
PackageManager.MATCH_DEFAULT_ONLY);
Iterator<ResolveInfo> it = activities.iterator(); Iterator<ResolveInfo> it = activities.iterator();
ResolveInfo resolveInfo; ResolveInfo resolveInfo;
while (it.hasNext()) { while (it.hasNext()) {
@ -110,7 +112,6 @@ public class ShareLinkToDialog extends DialogFragment {
mAdapter = new ActivityAdapter(getActivity(), pm, activities); mAdapter = new ActivityAdapter(getActivity(), pm, activities);
return createSelector(sendAction); return createSelector(sendAction);
} }
private AlertDialog createSelector(final boolean sendAction) { private AlertDialog createSelector(final boolean sendAction) {
@ -152,7 +153,7 @@ public class ShareLinkToDialog extends DialogFragment {
} }
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public @NonNull View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
if (convertView == null) { if (convertView == null) {
convertView = newView(parent); convertView = newView(parent);
} }

View file

@ -21,39 +21,29 @@
android:id="@+id/list_item" android:id="@+id/list_item"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="48dp"
android:paddingStart="@dimen/standard_padding_independent" android:paddingStart="@dimen/standard_padding"
android:paddingEnd="@dimen/standard_padding_independent" android:paddingEnd="@dimen/standard_padding"
android:paddingRight="@dimen/standard_padding_independent" android:paddingRight="@dimen/standard_padding"
android:paddingLeft="@dimen/standard_padding_independent" android:paddingLeft="@dimen/standard_padding"
android:minWidth="@dimen/activity_row_layout_min_width_independent" android:minWidth="@dimen/activity_row_layout_min_width_independent"
android:background="?android:attr/activatedBackgroundIndicator" android:background="?android:attr/activatedBackgroundIndicator"
android:orientation="vertical" > android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:duplicateParentState="true" >
<ImageView <ImageView
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="@dimen/user_icon_size_independent" android:layout_width="@dimen/user_icon_size_independent"
android:layout_height="@dimen/user_icon_size_independent" android:layout_height="@dimen/user_icon_size_independent"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/standard_half_padding_independent" android:layout_marginEnd="@dimen/standard_padding"
android:layout_marginRight="@dimen/standard_half_padding_independent" android:layout_marginRight="@dimen/standard_padding"/>
android:duplicateParentState="true" />
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceLargePopupMenu" android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
android:duplicateParentState="true"
android:singleLine="true" android:singleLine="true"
android:ellipsize="marquee" android:ellipsize="marquee"/>
android:fadingEdge="horizontal" />
</LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -78,7 +78,7 @@
</RelativeLayout> </RelativeLayout>
<LinearLayout <LinearLayout
android:layout_width="@dimen/zero" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:gravity="top" android:gravity="top"

View file

@ -28,6 +28,6 @@
android:contentDescription="@string/select_all" android:contentDescription="@string/select_all"
android:title="@string/select_all" android:title="@string/select_all"
android:icon="@drawable/ic_select_all" android:icon="@drawable/ic_select_all"
app:showAsAction="always"/> app:showAsAction="ifRoom"/>
</menu> </menu>

View file

@ -26,7 +26,7 @@
android:title="@string/actionbar_search" android:title="@string/actionbar_search"
android:contentDescription="@string/actionbar_search" android:contentDescription="@string/actionbar_search"
app:actionViewClass="android.support.v7.widget.SearchView" app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always"/> app:showAsAction="ifRoom"/>
<item <item
android:id="@+id/action_create_dir" android:id="@+id/action_create_dir"
android:icon="@drawable/ic_action_create_dir" android:icon="@drawable/ic_action_create_dir"

View file

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Nextcloud Android client application
Copyright (C) 2017 Esa Firman
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
License as published by the Free Software Foundation; either
version 3 of the License, or any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU AFFERO GENERAL PUBLIC LICENSE for more details.
You should have received a copy of the GNU Affero General Public
License along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:contentDescription="@string/actionbar_search"
android:icon="@drawable/ic_search"
android:title="@string/actionbar_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_switch_account"
android:contentDescription="@string/common_switch_account"
android:orderInCategory="1"
android:title="@string/common_switch_account"
app:showAsAction="never"/>
<item
android:id="@+id/action_create_dir"
android:contentDescription="@string/actionbar_mkdir"
android:icon="@drawable/ic_action_create_dir"
android:orderInCategory="1"
android:title="@string/actionbar_mkdir"
app:showAsAction="never"/>
<item
android:id="@+id/action_select_all"
android:contentDescription="@string/select_all"
android:icon="@drawable/ic_select_all"
android:orderInCategory="1"
android:title="@string/select_all"
app:showAsAction="never"/>
</menu>

View file

@ -184,6 +184,7 @@
<string name="downloader_not_downloaded_yet">Not downloaded yet</string> <string name="downloader_not_downloaded_yet">Not downloaded yet</string>
<string name="downloader_download_failed_credentials_error">Download failed, you need to log in again</string> <string name="downloader_download_failed_credentials_error">Download failed, you need to log in again</string>
<string name="common_choose_account">Choose account</string> <string name="common_choose_account">Choose account</string>
<string name="common_switch_account">Switch Account</string>
<string name="sync_fail_ticker">Sync failed</string> <string name="sync_fail_ticker">Sync failed</string>
<string name="sync_fail_ticker_unauthorized">Sync failed, you need to log in again</string> <string name="sync_fail_ticker_unauthorized">Sync failed, you need to log in again</string>
<string name="sync_fail_content">Could not complete sync of %1$s</string> <string name="sync_fail_content">Could not complete sync of %1$s</string>