Combine Move and Copy feature

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2023-10-12 09:46:39 +02:00 committed by Alper Öztürk (Rebase PR Action)
parent 78fa3851fd
commit 3657488332
12 changed files with 28 additions and 108 deletions

View file

@ -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_move),
// favorites
FAVORITE(R.id.action_favorite, R.string.favorite, R.drawable.ic_star),
@ -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,

View file

@ -161,8 +161,7 @@ public class FileMenuFilter {
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);
@ -346,19 +345,12 @@ public class FileMenuFilter {
}
}
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);

View file

@ -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;
@ -887,31 +886,10 @@ public class FileDisplayActivity extends FileActivity
}
}
}, new String[]{FileOperationsHelper.createImageFile(getActivity()).getAbsolutePath()}).execute();
} else if (requestCode == REQUEST_CODE__MOVE_FILES && resultCode == RESULT_OK) {
} 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
);
getHandler().postDelayed(() -> requestMoveOrCopyOperation(fData), DELAY_TO_REQUEST_OPERATIONS_LATER);
} else if (requestCode == PermissionUtil.REQUEST_CODE_MANAGE_ALL_FILES) {
syncAndUpdateFolder(true);
} else {
@ -1018,26 +996,11 @@ public class FileDisplayActivity extends FileActivity
}
/**
* 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);
private void requestMoveOrCopyOperation(Intent data) {
final OCFile file = 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);
assert filePaths != null;
getFileOperationsHelper().moveOrCopyFiles(filePaths, file);
}
private boolean isSearchOpen() {

View file

@ -347,7 +347,7 @@ open class FolderPickerActivity :
// 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
@ -588,8 +588,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"

View file

@ -278,8 +278,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
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

View file

@ -1235,11 +1235,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
} 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(FolderPickerActivity.MOVE_OR_COPY, checkedFiles);
return true;
} else if (itemId == R.id.action_select_all_action_menu) {
selectAllFiles(true);
@ -1259,15 +1256,10 @@ public class OCFileListFragment extends ExtendedListFragment implements
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);
if (extraAction.equals(FolderPickerActivity.MOVE_OR_COPY)) {
requestCode = FileDisplayActivity.REQUEST_CODE__MOVE_OR_COPY_FILES;
} else {
throw new IllegalArgumentException("Unknown extra action: " + extraAction);
}
final Intent action = new Intent(getActivity(), FolderPickerActivity.class);

View file

@ -1007,30 +1007,10 @@ public class FileOperationsHelper {
}
}
/**
* 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(final List<String> filePaths, final OCFile targetFolder) {
for (String path : filePaths) {
Intent service = new Intent(fileActivity, OperationsService.class);
service.setAction(action);
//service.setAction(OperationsService.ACTION_MOVE_OR_COPY_FILE);
service.putExtra(OperationsService.EXTRA_NEW_PARENT_PATH, targetFolder.getRemotePath());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, path);
service.putExtra(OperationsService.EXTRA_ACCOUNT, fileActivity.getAccount());

View file

@ -375,8 +375,7 @@ public class PreviewImageFragment extends FileFragment implements Injectable {
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

View file

@ -424,8 +424,7 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
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

View file

@ -300,8 +300,7 @@ public class PreviewTextFileFragment extends PreviewTextFragment {
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

View file

@ -30,8 +30,7 @@
<item name="action_see_details" type="id"/>
<item name="action_lock_file" type="id"/>
<item name="action_rename_file" type="id"/>
<item name="action_move" type="id"/>
<item name="action_copy" type="id"/>
<item name="action_move_or_copy" type="id"/>
<item name="action_download_file" type="id"/>
<item name="action_export_file" type="id"/>
<item name="action_stream_media" type="id"/>

View file

@ -428,6 +428,7 @@
<string name="log_send_no_mail_app">No app for sending logs found. Please install an email client.</string>
<string name="log_send_mail_subject">%1$s Android app logs</string>
<string name="actionbar_move_or_copy">Move or Copy</string>
<string name="actionbar_move">Move</string>
<string name="actionbar_copy">Copy</string>
<string name="file_list_empty_moving">Nothing in here. You can add a folder.</string>