mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 05:35:39 +03:00
Merge pull request #1196 from jsrck/master
Feature request: Select all (particularly in search) #637
This commit is contained in:
commit
8072e4cdd2
8 changed files with 77 additions and 3 deletions
|
@ -47,6 +47,7 @@ public class FileMenuFilter {
|
|||
|
||||
private static final int SINGLE_SELECT_ITEMS = 1;
|
||||
|
||||
private int mNumberOfAllFiles;
|
||||
private Collection<OCFile> mFiles;
|
||||
private ComponentsGetter mComponentsGetter;
|
||||
private Account mAccount;
|
||||
|
@ -55,12 +56,15 @@ public class FileMenuFilter {
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param numberOfAllFiles Number of all displayed files
|
||||
* @param targetFiles Collection of {@link OCFile} file targets of the action to filter in the {@link Menu}.
|
||||
* @param account ownCloud {@link Account} holding targetFile.
|
||||
* @param cg Accessor to app components, needed to access synchronization services
|
||||
* @param context Android {@link Context}, needed to access build setup resources.
|
||||
*/
|
||||
public FileMenuFilter(Collection<OCFile> targetFiles, Account account, ComponentsGetter cg, Context context) {
|
||||
public FileMenuFilter(int numberOfAllFiles, Collection<OCFile> targetFiles, Account account,
|
||||
ComponentsGetter cg, Context context) {
|
||||
mNumberOfAllFiles = numberOfAllFiles;
|
||||
mFiles = targetFiles;
|
||||
mAccount = account;
|
||||
mComponentsGetter = cg;
|
||||
|
@ -76,7 +80,7 @@ public class FileMenuFilter {
|
|||
* @param context Android {@link Context}, needed to access build setup resources.
|
||||
*/
|
||||
public FileMenuFilter(OCFile targetFile, Account account, ComponentsGetter cg, Context context) {
|
||||
this(Collections.singletonList(targetFile), account, cg, context);
|
||||
this(1, Collections.singletonList(targetFile), account, cg, context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,6 +173,22 @@ public class FileMenuFilter {
|
|||
toShow.add(R.id.action_remove_file);
|
||||
}
|
||||
|
||||
// SELECT ALL
|
||||
// Show only if at least one item isn't selected.
|
||||
if (mFiles.size() >= mNumberOfAllFiles) {
|
||||
toHide.add(R.id.action_select_all);
|
||||
} else {
|
||||
toShow.add(R.id.action_select_all);
|
||||
}
|
||||
|
||||
// DESELECT ALL
|
||||
// Show only if at least one item is selected.
|
||||
if (mFiles.isEmpty()) {
|
||||
toHide.add(R.id.action_deselect_all);
|
||||
} else {
|
||||
toShow.add(R.id.action_deselect_all);
|
||||
}
|
||||
|
||||
// OPEN WITH (different to preview!)
|
||||
if (!isSingleFile() || !anyFileDown() || synchronizing) {
|
||||
toHide.add(R.id.action_open_file_with);
|
||||
|
|
|
@ -786,6 +786,10 @@ public class FileDisplayActivity extends HookActivity
|
|||
}
|
||||
break;
|
||||
}
|
||||
case R.id.action_select_all: {
|
||||
getListOfFilesFragment().selectAllFiles(true);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
retval = super.onOptionsItemSelected(item);
|
||||
break;
|
||||
|
|
|
@ -648,6 +648,10 @@ public class FileListListAdapter extends BaseAdapter {
|
|||
return files;
|
||||
}
|
||||
|
||||
public Vector<OCFile> getFiles() {
|
||||
return mFiles;
|
||||
}
|
||||
|
||||
public Filter getFilter() {
|
||||
if (mFilesFilter == null) {
|
||||
mFilesFilter = new FilesFilter();
|
||||
|
|
|
@ -625,6 +625,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
|
|||
);
|
||||
mode.setTitle(title);
|
||||
FileMenuFilter mf = new FileMenuFilter(
|
||||
mAdapter.getFiles().size(),
|
||||
checkedFiles,
|
||||
((FileActivity) getActivity()).getAccount(),
|
||||
mContainerActivity,
|
||||
|
@ -991,12 +992,21 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
|
|||
getActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__MOVE_FILES);
|
||||
return true;
|
||||
}
|
||||
case R.id.action_copy:
|
||||
case R.id.action_copy: {
|
||||
Intent action = new Intent(getActivity(), FolderPickerActivity.class);
|
||||
action.putParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES, checkedFiles);
|
||||
action.putExtra(FolderPickerActivity.EXTRA_ACTION, getResources().getText(R.string.copy_to));
|
||||
getActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__COPY_FILES);
|
||||
return true;
|
||||
}
|
||||
case R.id.action_select_all: {
|
||||
selectAllFiles(true);
|
||||
return true;
|
||||
}
|
||||
case R.id.action_deselect_all: {
|
||||
selectAllFiles(false);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -1594,4 +1604,17 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
|
|||
public boolean getIsSearchFragment() {
|
||||
return searchFragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* De-/select all elements in the current list view.
|
||||
*
|
||||
* @param select <code>true</code> to select all, <code>false</code> to deselect all
|
||||
*/
|
||||
public void selectAllFiles(boolean select) {
|
||||
AbsListView listView = getListView();
|
||||
for (int position = 0; position < listView.getCount(); position++) {
|
||||
listView.setItemChecked(position, select);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -85,6 +85,20 @@
|
|||
app:showAsAction="never"
|
||||
android:showAsAction="never"
|
||||
android:orderInCategory="1" />
|
||||
<item
|
||||
android:id="@+id/action_select_all"
|
||||
android:title="@string/select_all"
|
||||
android:icon="@drawable/ic_select_all"
|
||||
app:showAsAction="never"
|
||||
android:showAsAction="never"
|
||||
android:orderInCategory="1" />
|
||||
<item
|
||||
android:id="@+id/action_deselect_all"
|
||||
android:title="@string/deselect_all"
|
||||
android:icon="@drawable/ic_select_all"
|
||||
app:showAsAction="never"
|
||||
android:showAsAction="never"
|
||||
android:orderInCategory="1" />
|
||||
<item
|
||||
android:id="@+id/action_send_file"
|
||||
android:title="@string/actionbar_send_file"
|
||||
|
|
|
@ -54,6 +54,13 @@
|
|||
app:showAsAction="never"
|
||||
android:title="@string/actionbar_sort"
|
||||
android:contentDescription="@string/actionbar_sort"/>
|
||||
<item
|
||||
android:id="@+id/action_select_all"
|
||||
android:icon="@drawable/ic_select_all"
|
||||
android:orderInCategory="1"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/select_all"
|
||||
android:contentDescription="@string/select_all"/>
|
||||
|
||||
<!-- <item android:id="@+id/search"
|
||||
android:title="@string/actionbar_search"
|
||||
|
|
|
@ -491,6 +491,7 @@
|
|||
<string name="upload_copy_files">kopiere Datei</string>
|
||||
<string name="upload_move_files">verschiebe Datei</string>
|
||||
<string name="select_all">Alle auswählen</string>
|
||||
<string name="deselect_all">Auswahl aufheben</string>
|
||||
|
||||
<string name="pref_behaviour_entries_keep_file">im Originalordner behalten</string>
|
||||
<string name="pref_behaviour_entries_move">in den App-Ordner verschoben</string>
|
||||
|
|
|
@ -492,6 +492,7 @@
|
|||
<string name="upload_copy_files">Copy file</string>
|
||||
<string name="upload_move_files">Move file</string>
|
||||
<string name="select_all">Select all</string>
|
||||
<string name="deselect_all">Deselect all</string>
|
||||
|
||||
<string name="pref_behaviour_entries_keep_file">kept in original folder</string>
|
||||
<string name="pref_behaviour_entries_move">moved to app folder</string>
|
||||
|
|
Loading…
Reference in a new issue