From 3ef8ed04feadd801b6970e5030c0507fffbc4ceb Mon Sep 17 00:00:00 2001 From: Jessie Chatham Spencer Date: Sun, 29 Jul 2018 13:05:08 +0200 Subject: [PATCH 1/2] Clear selection after deleting files - issue#2463 Now we exit the selection mode after deleting files. --- .../ui/dialog/RemoveFilesDialogFragment.java | 30 ++++++++++++++++++- .../ui/fragment/OCFileListFragment.java | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.java index 1da1065c94..66c3b0e51b 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.java +++ b/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.java @@ -30,6 +30,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.os.Bundle; import android.support.annotation.NonNull; +import android.view.ActionMode; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; @@ -47,6 +48,21 @@ implements ConfirmationDialogFragmentListener { private static final String ARG_TARGET_FILES = "TARGET_FILES"; + private ActionMode actionMode; + + /** + * Public factory method to create new RemoveFilesDialogFragment instances. + * + * @param files Files to remove. + * @param actionMode ActionMode to finish on confirmation + * @return Dialog ready to show. + */ + public static RemoveFilesDialogFragment newInstance(ArrayList files, ActionMode actionMode) { + RemoveFilesDialogFragment dialogFragment = newInstance(files); + dialogFragment.setActionMode(actionMode); + return dialogFragment; + } + /** * Public factory method to create new RemoveFilesDialogFragment instances. * @@ -137,12 +153,20 @@ implements ConfirmationDialogFragmentListener { } /** - * Performs the removal of the target file, both locally and in the server. + * Performs the removal of the target file, both locally and in the server and + * finishes the supplied ActionMode if one was given. */ @Override public void onConfirmation(String callerTag) { ComponentsGetter cg = (ComponentsGetter) getActivity(); cg.getFileOperationsHelper().removeFiles(mTargetFiles, false, false); + + // This is used when finishing an actionMode, + // for example if we want to exit the selection mode + // after deleting the target files. + if (actionMode != null) { + actionMode.finish(); + } } /** @@ -158,4 +182,8 @@ implements ConfirmationDialogFragmentListener { public void onNeutral(String callerTag) { // nothing to do here } + + private void setActionMode(ActionMode actionMode) { + this.actionMode = actionMode; + } } diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index af8a566894..2934032678 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -940,7 +940,7 @@ public class OCFileListFragment extends ExtendedListFragment implements /// actions possible on a batch of files switch (menuId) { case R.id.action_remove_file: { - RemoveFilesDialogFragment dialog = RemoveFilesDialogFragment.newInstance(new ArrayList<>(checkedFiles)); + RemoveFilesDialogFragment dialog = RemoveFilesDialogFragment.newInstance(new ArrayList<>(checkedFiles), mActiveActionMode); dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION); return true; } From 584fde2bf21bd8988d602f8ae15b257268e0e63c Mon Sep 17 00:00:00 2001 From: AndyScherzinger Date: Wed, 1 Aug 2018 13:16:02 +0200 Subject: [PATCH 2/2] minor code formatting --- .../ui/dialog/RemoveFilesDialogFragment.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.java index 66c3b0e51b..3fafe2ad59 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.java +++ b/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.java @@ -1,4 +1,4 @@ -/** +/* * ownCloud Android client application * * @author David A. Velasco @@ -15,17 +15,10 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * */ package com.owncloud.android.ui.dialog; -/** - * Dialog requiring confirmation before removing a collection of given OCFiles. - * - * Triggers the removal according to the user response. - */ - import android.app.AlertDialog; import android.app.Dialog; import android.os.Bundle; @@ -41,8 +34,13 @@ import com.owncloud.android.utils.ThemeUtils; import java.util.ArrayList; import java.util.Collection; -public class RemoveFilesDialogFragment extends ConfirmationDialogFragment -implements ConfirmationDialogFragmentListener { +/** + * Dialog requiring confirmation before removing a collection of given OCFiles. + * + * Triggers the removal according to the user response. + */ +public class RemoveFilesDialogFragment extends ConfirmationDialogFragment implements + ConfirmationDialogFragmentListener { private Collection mTargetFiles;