Skip to content

Commit

Permalink
Merge pull request #12026 from nextcloud/feature/combine-move-and-cop…
Browse files Browse the repository at this point in the history
…y-in-menu

Feature/combine move and copy in menu
  • Loading branch information
AndyScherzinger authored Oct 30, 2023
2 parents 3d5ee8a + f378d61 commit 84f3e6c
Show file tree
Hide file tree
Showing 79 changed files with 83 additions and 583 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void open() {
sut.setFile(origin);

sut.runOnUiThread(() -> {
sut.findViewById(R.id.folder_picker_btn_choose).requestFocus();
sut.findViewById(R.id.folder_picker_btn_copy).requestFocus();
});
waitForIdleSync();
screenshot(sut);
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/com/nextcloud/ui/fileactions/FileAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ enum class FileAction(@IdRes val id: Int, @StringRes val title: Int, @DrawableRe

// File moving
RENAME_FILE(R.id.action_rename_file, R.string.common_rename, R.drawable.ic_rename),
MOVE(R.id.action_move, R.string.actionbar_move, R.drawable.ic_move),
COPY(R.id.action_copy, R.string.actionbar_copy, R.drawable.ic_content_copy),
MOVE_OR_COPY(R.id.action_move_or_copy, R.string.actionbar_move_or_copy, R.drawable.ic_external),

// favorites
FAVORITE(R.id.action_favorite, R.string.favorite, R.drawable.ic_star),
Expand Down Expand Up @@ -83,8 +82,7 @@ enum class FileAction(@IdRes val id: Int, @StringRes val title: Int, @DrawableRe
SEE_DETAILS,
LOCK_FILE,
RENAME_FILE,
MOVE,
COPY,
MOVE_OR_COPY,
DOWNLOAD_FILE,
EXPORT_FILE,
STREAM_MEDIA,
Expand Down
14 changes: 3 additions & 11 deletions app/src/main/java/com/owncloud/android/files/FileMenuFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ private List<Integer> filter(boolean inSingleFileFragment) {
filterDownload(toHide, synchronizing);
filterExport(toHide);
filterRename(toHide, synchronizing);
filterCopy(toHide, synchronizing);
filterMove(toHide, synchronizing);
filterMoveOrCopy(toHide, synchronizing);
filterRemove(toHide, synchronizing);
filterSelectAll(toHide, inSingleFileFragment);
filterDeselectAll(toHide, inSingleFileFragment);
Expand Down Expand Up @@ -346,19 +345,12 @@ private void filterRemove(List<Integer> toHide, boolean synchronizing) {
}
}

private void filterMove(List<Integer> toHide, boolean synchronizing) {
private void filterMoveOrCopy(List<Integer> toHide, boolean synchronizing) {
if (files.isEmpty() || synchronizing || containsEncryptedFile() || containsEncryptedFolder() || containsLockedFile()) {
toHide.add(R.id.action_move);
toHide.add(R.id.action_move_or_copy);
}
}

private void filterCopy(List<Integer> toHide, boolean synchronizing) {
if (files.isEmpty() || synchronizing || containsEncryptedFile() || containsEncryptedFolder()) {
toHide.add(R.id.action_copy);
}
}


private void filterRename(Collection<Integer> toHide, boolean synchronizing) {
if (!isSingleSelection() || synchronizing || containsEncryptedFile() || containsEncryptedFolder() || containsLockedFile()) {
toHide.add(R.id.action_rename_file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ public class FileDisplayActivity extends FileActivity

public static final int REQUEST_CODE__SELECT_CONTENT_FROM_APPS = REQUEST_CODE__LAST_SHARED + 1;
public static final int REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM = REQUEST_CODE__LAST_SHARED + 2;
public static final int REQUEST_CODE__MOVE_FILES = REQUEST_CODE__LAST_SHARED + 3;
public static final int REQUEST_CODE__COPY_FILES = REQUEST_CODE__LAST_SHARED + 4;
public static final int REQUEST_CODE__MOVE_OR_COPY_FILES = REQUEST_CODE__LAST_SHARED + 3;
public static final int REQUEST_CODE__UPLOAD_FROM_CAMERA = REQUEST_CODE__LAST_SHARED + 5;
public static final int REQUEST_CODE__UPLOAD_SCAN_DOC_FROM_CAMERA = REQUEST_CODE__LAST_SHARED + 6;

Expand Down Expand Up @@ -884,32 +883,9 @@ public void onCheckAvailableSpaceFinish(boolean hasEnoughSpaceAvailable, String.
FileUploader.LOCAL_BEHAVIOUR_DELETE);
}
}
}, new String[]{FileOperationsHelper.createImageFile(getActivity()).getAbsolutePath()}).execute();
} else if (requestCode == REQUEST_CODE__MOVE_FILES && resultCode == RESULT_OK) {
}, new String[] { FileOperationsHelper.createImageFile(getActivity()).getAbsolutePath() }).execute();
} else if (requestCode == REQUEST_CODE__MOVE_OR_COPY_FILES && resultCode == RESULT_OK) {
exitSelectionMode();
final Intent fData = data;
getHandler().postDelayed(
new Runnable() {
@Override
public void run() {
requestMoveOperation(fData);
}
},
DELAY_TO_REQUEST_OPERATIONS_LATER
);

} else if (requestCode == REQUEST_CODE__COPY_FILES && resultCode == RESULT_OK) {
exitSelectionMode();
final Intent fData = data;
getHandler().postDelayed(
new Runnable() {
@Override
public void run() {
requestCopyOperation(fData);
}
},
DELAY_TO_REQUEST_OPERATIONS_LATER
);
} else if (requestCode == PermissionUtil.REQUEST_CODE_MANAGE_ALL_FILES) {
syncAndUpdateFolder(true);
} else {
Expand Down Expand Up @@ -1016,28 +992,6 @@ private void requestUploadOfContentFromApps(Intent contentIntent, int resultCode

}

/**
* Request the operation for moving the file/folder from one path to another
*
* @param data Intent received
*/
private void requestMoveOperation(Intent data) {
final OCFile folderToMoveAt = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
final List<String> filePaths = data.getStringArrayListExtra(FolderPickerActivity.EXTRA_FILE_PATHS);
getFileOperationsHelper().moveFiles(filePaths, folderToMoveAt);
}

/**
* Request the operation for copying the file/folder from one path to another
*
* @param data Intent received
*/
private void requestCopyOperation(Intent data) {
final OCFile targetFolder = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
final List<String> filePaths = data.getStringArrayListExtra(FolderPickerActivity.EXTRA_FILE_PATHS);
getFileOperationsHelper().copyFiles(filePaths, targetFolder);
}

private boolean isSearchOpen() {
if (searchView == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.resources.files.SearchRemoteOperation
import com.owncloud.android.operations.CreateFolderOperation
import com.owncloud.android.operations.RefreshFolderOperation
import com.owncloud.android.services.OperationsService
import com.owncloud.android.syncadapter.FileSyncAdapter
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment
import com.owncloud.android.ui.dialog.SortingOrderDialogFragment.OnSortingOrderListener
Expand Down Expand Up @@ -73,7 +74,9 @@ open class FolderPickerActivity :
var isDoNotEnterEncryptedFolder = false
private set
private var mCancelBtn: MaterialButton? = null
private var mChooseBtn: MaterialButton? = null
private var mCopyBtn: MaterialButton? = null
private var mMoveBtn: MaterialButton? = null

private var caption: String? = null

private var mAction: String? = null
Expand All @@ -85,6 +88,7 @@ open class FolderPickerActivity :
override fun onCreate(savedInstanceState: Bundle?) {
Log_OC.d(TAG, "onCreate() start")
super.onCreate(savedInstanceState)

if (this is FilePickerActivity) {
setContentView(R.layout.files_picker)
} else {
Expand All @@ -101,29 +105,15 @@ open class FolderPickerActivity :
findViewById<View>(R.id.switch_grid_view_button).visibility =
View.GONE
mAction = intent.getStringExtra(EXTRA_ACTION)

if (mAction != null) {
when (mAction) {
MOVE -> {
caption = resources.getText(R.string.move_to).toString()
mSearchOnlyFolders = true
isDoNotEnterEncryptedFolder = true
}
COPY -> {
caption = resources.getText(R.string.copy_to).toString()
mSearchOnlyFolders = true
isDoNotEnterEncryptedFolder = true
}
CHOOSE_LOCATION -> {
caption = resources.getText(R.string.choose_location).toString()
mSearchOnlyFolders = true
isDoNotEnterEncryptedFolder = true
mChooseBtn!!.text = resources.getString(R.string.common_select)
}
else -> caption = themeUtils.getDefaultDisplayNameForRootFolder(this)
}
caption = resources.getText(R.string.folder_picker_choose_caption_text).toString()
mSearchOnlyFolders = true
isDoNotEnterEncryptedFolder = true
} else {
caption = themeUtils.getDefaultDisplayNameForRootFolder(this)
}

mTargetFilePaths = intent.getStringArrayListExtra(EXTRA_FILE_PATHS)

if (savedInstanceState == null) {
Expand Down Expand Up @@ -351,13 +341,14 @@ open class FolderPickerActivity :
}

private fun toggleChooseEnabled() {
mChooseBtn?.isEnabled = checkFolderSelectable()
mCopyBtn?.isEnabled = checkFolderSelectable()
mMoveBtn?.isEnabled = checkFolderSelectable()
}

// for copy and move, disable selecting parent folder of target files
private fun checkFolderSelectable(): Boolean {
return when {
mAction != COPY && mAction != MOVE -> true
mAction != MOVE_OR_COPY -> true
mTargetFilePaths.isNullOrEmpty() -> true
file?.isFolder != true -> true
// all of the target files are already in the selected directory
Expand Down Expand Up @@ -385,16 +376,23 @@ open class FolderPickerActivity :
*/
private fun initControls() {
mCancelBtn = findViewById(R.id.folder_picker_btn_cancel)
mChooseBtn = findViewById(R.id.folder_picker_btn_choose)
if (mChooseBtn != null) {
viewThemeUtils.material.colorMaterialButtonPrimaryFilled(mChooseBtn!!)
mChooseBtn!!.setOnClickListener(this)
mCopyBtn = findViewById(R.id.folder_picker_btn_copy)
mMoveBtn = findViewById(R.id.folder_picker_btn_move)

if (mCopyBtn != null) {
viewThemeUtils.material.colorMaterialButtonPrimaryFilled(mCopyBtn!!)
mCopyBtn!!.setOnClickListener(this)
}
if (mMoveBtn != null) {
viewThemeUtils.material.colorMaterialButtonPrimaryTonal(mMoveBtn!!)
mMoveBtn!!.setOnClickListener(this)
}

if (mCancelBtn != null) {
if (this is FilePickerActivity) {
viewThemeUtils.material.colorMaterialButtonPrimaryFilled(mCancelBtn!!)
} else {
viewThemeUtils.material.colorMaterialButtonPrimaryOutlined(mCancelBtn!!)
viewThemeUtils.material.colorMaterialButtonText(mCancelBtn!!)
}
mCancelBtn!!.setOnClickListener(this)
}
Expand All @@ -403,15 +401,24 @@ open class FolderPickerActivity :
override fun onClick(v: View) {
if (v == mCancelBtn) {
finish()
} else if (v == mChooseBtn) {
} else if (v == mCopyBtn || v == mMoveBtn) {
val i = intent
val resultData = Intent()
resultData.putExtra(EXTRA_FOLDER, listOfFilesFragment!!.currentFile)
val targetFiles = i.getParcelableArrayListExtra<Parcelable>(EXTRA_FILES)
if (targetFiles != null) {
resultData.putParcelableArrayListExtra(EXTRA_FILES, targetFiles)
}

mTargetFilePaths.let {
if (it != null) {
if (v == mCopyBtn) {
fileOperationsHelper.moveOrCopyFiles(OperationsService.ACTION_COPY_FILE, it, file)
} else {
fileOperationsHelper.moveOrCopyFiles(OperationsService.ACTION_MOVE_FILE, it, file)
}
}

resultData.putStringArrayListExtra(EXTRA_FILE_PATHS, it)
}
setResult(RESULT_OK, resultData)
Expand Down Expand Up @@ -592,8 +599,7 @@ open class FolderPickerActivity :
@JvmField
val EXTRA_ACTION = FolderPickerActivity::class.java.canonicalName?.plus(".EXTRA_ACTION")

const val MOVE = "MOVE"
const val COPY = "COPY"
const val MOVE_OR_COPY = "MOVE_OR_COPY"
const val CHOOSE_LOCATION = "CHOOSE_LOCATION"
private val TAG = FolderPickerActivity::class.java.simpleName
protected const val TAG_LIST_OF_FOLDERS = "LIST_OF_FOLDERS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ private void onOverflowIconClicked() {
R.id.action_favorite,
R.id.action_unset_favorite,
R.id.action_see_details,
R.id.action_move,
R.id.action_copy,
R.id.action_move_or_copy,
R.id.action_stream_media,
R.id.action_send_share_file,
R.id.action_pin_to_homescreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,11 +1235,8 @@ public boolean onFileActionChosen(@IdRes final int itemId, Set<OCFile> checkedFi
} else if (itemId == R.id.action_unset_favorite) {
mContainerActivity.getFileOperationsHelper().toggleFavoriteFiles(checkedFiles, false);
return true;
} else if (itemId == R.id.action_move) {
pickFolderForMoveOrCopy(FolderPickerActivity.MOVE, checkedFiles);
return true;
} else if (itemId == R.id.action_copy) {
pickFolderForMoveOrCopy(FolderPickerActivity.COPY, checkedFiles);
} else if (itemId == R.id.action_move_or_copy) {
pickFolderForMoveOrCopy(checkedFiles);
return true;
} else if (itemId == R.id.action_select_all_action_menu) {
selectAllFiles(true);
Expand All @@ -1257,18 +1254,9 @@ public boolean onFileActionChosen(@IdRes final int itemId, Set<OCFile> checkedFi
return false;
}

private void pickFolderForMoveOrCopy(final String extraAction, final Set<OCFile> checkedFiles) {
int requestCode;
switch (extraAction) {
case FolderPickerActivity.MOVE:
requestCode = FileDisplayActivity.REQUEST_CODE__MOVE_FILES;
break;
case FolderPickerActivity.COPY:
requestCode = FileDisplayActivity.REQUEST_CODE__COPY_FILES;
break;
default:
throw new IllegalArgumentException("Unknown extra action: " + extraAction);
}
private void pickFolderForMoveOrCopy(final Set<OCFile> checkedFiles) {
int requestCode = FileDisplayActivity.REQUEST_CODE__MOVE_OR_COPY_FILES;
String extraAction = FolderPickerActivity.MOVE_OR_COPY;

final Intent action = new Intent(getActivity(), FolderPickerActivity.class);
final ArrayList<String> paths = new ArrayList<>(checkedFiles.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,27 +1007,7 @@ public void cancelTransference(OCFile file) {
}
}

/**
* Start operations to move one or several files
*
* @param filePaths Remote paths of files to move
* @param targetFolder Folder where the files while be moved into
*/
public void moveFiles(final List<String> filePaths, final OCFile targetFolder) {
copyOrMoveFiles(OperationsService.ACTION_MOVE_FILE, filePaths, targetFolder);
}

/**
* Start operations to copy one or several files
*
* @param filePaths Remote paths of files to move
* @param targetFolder Folder where the files while be copied into
*/
public void copyFiles(final List<String> filePaths, final OCFile targetFolder) {
copyOrMoveFiles(OperationsService.ACTION_COPY_FILE, filePaths, targetFolder);
}

private void copyOrMoveFiles(final String action, final List<String> filePaths, final OCFile targetFolder) {
public void moveOrCopyFiles(String action, final List<String> filePaths, final OCFile targetFolder) {
for (String path : filePaths) {
Intent service = new Intent(fileActivity, OperationsService.class);
service.setAction(action);
Expand All @@ -1039,7 +1019,6 @@ private void copyOrMoveFiles(final String action, final List<String> filePaths,
fileActivity.showLoadingDialog(fileActivity.getString(R.string.wait_a_moment));
}


public void exportFiles(Collection<OCFile> files,
Context context,
View view,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ private void showFileActions(OCFile file) {
Arrays.asList(
R.id.action_rename_file,
R.id.action_sync_file,
R.id.action_move,
R.id.action_copy,
R.id.action_move_or_copy,
R.id.action_favorite,
R.id.action_unset_favorite,
R.id.action_pin_to_homescreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ private void showFileActions(OCFile file) {
Arrays.asList(
R.id.action_rename_file,
R.id.action_sync_file,
R.id.action_move,
R.id.action_copy,
R.id.action_move_or_copy,
R.id.action_favorite,
R.id.action_unset_favorite,
R.id.action_pin_to_homescreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ private void showFileActions(OCFile file) {
Arrays.asList(
R.id.action_rename_file,
R.id.action_sync_file,
R.id.action_move,
R.id.action_copy,
R.id.action_move_or_copy,
R.id.action_favorite,
R.id.action_unset_favorite,
R.id.action_pin_to_homescreen
Expand Down
Loading

0 comments on commit 84f3e6c

Please sign in to comment.