Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3886 #3898

Merged
merged 14 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.amaze.filemanager.adapters.holders.SpecialViewHolder;
import com.amaze.filemanager.application.AppConfig;
import com.amaze.filemanager.fileoperations.filesystem.OpenMode;
import com.amaze.filemanager.filesystem.PasteHelper;
import com.amaze.filemanager.filesystem.files.CryptUtil;
import com.amaze.filemanager.ui.ItemPopupMenu;
import com.amaze.filemanager.ui.activities.superclasses.PreferenceActivity;
Expand All @@ -62,6 +63,7 @@
import com.amaze.filemanager.ui.views.CircleGradientDrawable;
import com.amaze.filemanager.utils.AnimUtils;
import com.amaze.filemanager.utils.GlideConstants;
import com.amaze.filemanager.utils.MainActivityActionMode;
import com.amaze.filemanager.utils.Utils;
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader;
import com.bumptech.glide.load.DataSource;
Expand All @@ -85,6 +87,7 @@
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.PopupMenu;
import android.widget.Toast;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -763,6 +766,20 @@ private void bindViewHolderList(@NonNull final ItemViewHolder holder, int positi

holder.baseItemView.setOnLongClickListener(
p1 -> {
MainActivityActionMode mainActivityActionMode =
mainFragment.getMainActivity().mainActivityActionMode;
PasteHelper pasteHelper = mainActivityActionMode.getPasteHelper();

if (pasteHelper != null
&& pasteHelper.getSnackbar() != null
&& pasteHelper.getSnackbar().isShown()) {
Toast.makeText(
mainFragment.requireContext(),
mainFragment.getString(R.string.complete_paste_warning),
Toast.LENGTH_LONG)
.show();
return false;
}
if (!isBackButton) {
if (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_DEFAULT
|| (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_TO_MOVE_COPY
Expand Down Expand Up @@ -976,6 +993,20 @@ private void bindViewHolderGrid(@NonNull final ItemViewHolder holder, int positi

holder.baseItemView.setOnLongClickListener(
p1 -> {
MainActivityActionMode mainActivityActionMode =
yatiksihag01 marked this conversation as resolved.
Show resolved Hide resolved
mainFragment.getMainActivity().mainActivityActionMode;
PasteHelper pasteHelper = mainActivityActionMode.getPasteHelper();

if (pasteHelper != null
&& pasteHelper.getSnackbar() != null
&& pasteHelper.getSnackbar().isShown()) {
Toast.makeText(
mainFragment.requireContext(),
mainFragment.getString(R.string.complete_paste_warning),
Toast.LENGTH_LONG)
.show();
return false;
}
if (!isBackButton) {
if (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_DEFAULT
|| (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_TO_MOVE_COPY
Expand Down Expand Up @@ -1366,6 +1397,21 @@ public boolean onResourceReady(
}

private void showPopup(@NonNull View view, @NonNull final LayoutElementParcelable rowItem) {

MainActivityActionMode mainActivityActionMode =
mainFragment.getMainActivity().mainActivityActionMode;
PasteHelper pasteHelper = mainActivityActionMode.getPasteHelper();

if (pasteHelper != null
&& pasteHelper.getSnackbar() != null
&& pasteHelper.getSnackbar().isShown()) {
Toast.makeText(
mainFragment.requireContext(),
mainFragment.getString(R.string.complete_paste_warning),
Toast.LENGTH_LONG)
.show();
return;
}
Context currentContext = this.context;
if (mainFragment.getMainActivity().getAppTheme().getSimpleTheme(mainFragment.requireContext())
== AppTheme.BLACK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.LinkedList;
import java.util.Set;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.amaze.filemanager.R;
import com.amaze.filemanager.asynchronous.asynctasks.TaskKt;
Expand All @@ -51,7 +50,6 @@
import android.content.Intent;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.IntDef;
Expand Down Expand Up @@ -88,6 +86,7 @@ public class PrepareCopyTask extends AsyncTask<Void, String, PrepareCopyTask.Cop
private static final int UNKNOWN = -1;
private static final int DO_NOT_REPLACE = 0;
private static final int REPLACE = 1;
private boolean doRenaming = false;

@IntDef({UNKNOWN, DO_NOT_REPLACE, REPLACE})
@interface DialogState {}
Expand Down Expand Up @@ -227,7 +226,13 @@ private void showDialog(
dialogBuilder.theme(mainActivity.get().getAppTheme().getMaterialDialogTheme(context.get()));
dialogBuilder.title(context.get().getResources().getString(R.string.paste));
dialogBuilder.positiveText(R.string.skip);
dialogBuilder.negativeText(R.string.overwrite);
if (filesToCopy.get(0).getParent(context.get()).equals(path)) {
doRenaming = true;
dialogBuilder.negativeText(
context.get().getString(R.string.rename)
+ " & "
+ context.get().getString(R.string.save));
} else dialogBuilder.negativeText(R.string.overwrite);
dialogBuilder.neutralText(R.string.cancel);
dialogBuilder.positiveColor(accentColor);
dialogBuilder.negativeColor(accentColor);
Expand All @@ -245,10 +250,6 @@ private void showDialog(

final MaterialDialog dialog = dialogBuilder.build();
dialog.show();
if (filesToCopy.get(0).getParent(context.get()).equals(path)) {
View negative = dialog.getActionButton(DialogAction.NEGATIVE);
negative.setEnabled(false);
}
}

private void onEndDialog(
Expand Down Expand Up @@ -310,7 +311,15 @@ private void replaceFiles(
String path,
ArrayList<HybridFileParcelable> filesToCopy,
ArrayList<HybridFileParcelable> conflictingFiles) {
if (counter < conflictingFiles.size()) {

if (doRenaming && dialogState != UNKNOWN) {
while (!conflictingFiles.isEmpty()) {
resolveByRenaming(filesToCopy, conflictingFiles);
}
} else if (doRenaming) {
resolveByRenaming(filesToCopy, conflictingFiles);
doRenaming = false;
} else if (counter < conflictingFiles.size()) {
if (dialogState != UNKNOWN) {
counter++;
} else {
Expand All @@ -321,6 +330,29 @@ private void replaceFiles(
onEndDialog(path, filesToCopy, conflictingFiles);
}

private void resolveByRenaming(
ArrayList<HybridFileParcelable> filesToCopy,
ArrayList<HybridFileParcelable> conflictingFiles) {
int appendInt = 1;
String newName;
File targetFile;

int conflictingFileIndex = filesToCopy.indexOf(conflictingFiles.get(0));
String oldName = filesToCopy.get(conflictingFileIndex).getName();
do {
newName =
oldName.substring(0, oldName.lastIndexOf("."))
+ "("
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TranceLove @VishnuSanal your inputs here. Do we have a library or a utility class that we can utilise for this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related #2078 sorry but still need some time to work on it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to see if #3913 can help.

+ appendInt
+ ")"
+ oldName.substring(oldName.lastIndexOf("."));
appendInt++;
targetFile = new File(path, newName);
} while (targetFile.exists());
filesToCopy.get(conflictingFileIndex).setName(newName);
conflictingFiles.remove(0);
}

private void finishCopying(
ArrayList<String> paths, ArrayList<ArrayList<HybridFileParcelable>> filesToCopyPerFolder) {
for (int i = 0; i < filesToCopyPerFolder.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public class MainActivity extends PermissionsActivity
public static final int REQUEST_CODE_CLOUD_LIST_KEY = 5472;

private PasteHelper pasteHelper;
private MainActivityActionMode mainActivityActionMode;
public MainActivityActionMode mainActivityActionMode;

private static final String DEFAULT_FALLBACK_STORAGE_PATH = "/storage/sdcard0";
private static final String INTERNAL_SHARED_STORAGE = "Internal shared storage";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MainActivityActionMode(private val mainActivityReference: WeakReference<Ma

var actionModeView: View? = null
var actionMode: ActionMode? = null
var pasteHelper: PasteHelper? = null

private fun hideOption(id: Int, menu: Menu) {
val item = menu.findItem(id)
Expand Down Expand Up @@ -377,7 +378,7 @@ class MainActivityActionMode(private val mainActivityReference: WeakReference<Ma
// Making sure we don't cause an IllegalArgumentException
// when passing copies to PasteHelper
if (copies.isNotEmpty()) {
val pasteHelper = PasteHelper(mainActivity, op, copies)
pasteHelper = PasteHelper(mainActivity, op, copies)
mainActivity.paste = pasteHelper
}
mode.finish()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -813,5 +813,6 @@ You only need to do this once, until the next time you select a new location for
<string name="try_indexed_search">Try Indexed Search!</string>
<string name="search_recent">Recent</string>
<string name="results">Results</string>
<string name="complete_paste_warning">Please complete paste operation first</string>
</resources>