|
47 | 47 | import com.amaze.filemanager.adapters.holders.SpecialViewHolder; |
48 | 48 | import com.amaze.filemanager.application.AppConfig; |
49 | 49 | import com.amaze.filemanager.fileoperations.filesystem.OpenMode; |
| 50 | +import com.amaze.filemanager.filesystem.PasteHelper; |
50 | 51 | import com.amaze.filemanager.filesystem.files.CryptUtil; |
51 | 52 | import com.amaze.filemanager.ui.ItemPopupMenu; |
| 53 | +import com.amaze.filemanager.ui.activities.MainActivity; |
52 | 54 | import com.amaze.filemanager.ui.activities.superclasses.PreferenceActivity; |
53 | 55 | import com.amaze.filemanager.ui.colors.ColorUtils; |
54 | 56 | import com.amaze.filemanager.ui.drag.RecyclerAdapterDragListener; |
|
62 | 64 | import com.amaze.filemanager.ui.views.CircleGradientDrawable; |
63 | 65 | import com.amaze.filemanager.utils.AnimUtils; |
64 | 66 | import com.amaze.filemanager.utils.GlideConstants; |
| 67 | +import com.amaze.filemanager.utils.MainActivityActionMode; |
65 | 68 | import com.amaze.filemanager.utils.Utils; |
66 | 69 | import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader; |
67 | 70 | import com.bumptech.glide.load.DataSource; |
|
85 | 88 | import android.view.animation.Animation; |
86 | 89 | import android.view.animation.AnimationUtils; |
87 | 90 | import android.widget.PopupMenu; |
| 91 | +import android.widget.Toast; |
88 | 92 |
|
89 | 93 | import androidx.annotation.IntDef; |
90 | 94 | import androidx.annotation.NonNull; |
@@ -763,6 +767,7 @@ private void bindViewHolderList(@NonNull final ItemViewHolder holder, int positi |
763 | 767 |
|
764 | 768 | holder.baseItemView.setOnLongClickListener( |
765 | 769 | p1 -> { |
| 770 | + if (hasPendingPasteOperation()) return false; |
766 | 771 | if (!isBackButton) { |
767 | 772 | if (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_DEFAULT |
768 | 773 | || (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_TO_MOVE_COPY |
@@ -976,6 +981,7 @@ private void bindViewHolderGrid(@NonNull final ItemViewHolder holder, int positi |
976 | 981 |
|
977 | 982 | holder.baseItemView.setOnLongClickListener( |
978 | 983 | p1 -> { |
| 984 | + if (hasPendingPasteOperation()) return false; |
979 | 985 | if (!isBackButton) { |
980 | 986 | if (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_DEFAULT |
981 | 987 | || (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_TO_MOVE_COPY |
@@ -1366,6 +1372,7 @@ public boolean onResourceReady( |
1366 | 1372 | } |
1367 | 1373 |
|
1368 | 1374 | private void showPopup(@NonNull View view, @NonNull final LayoutElementParcelable rowItem) { |
| 1375 | + if (hasPendingPasteOperation()) return; |
1369 | 1376 | Context currentContext = this.context; |
1370 | 1377 | if (mainFragment.getMainActivity().getAppTheme().getSimpleTheme(mainFragment.requireContext()) |
1371 | 1378 | == AppTheme.BLACK) { |
@@ -1428,6 +1435,31 @@ private void showPopup(@NonNull View view, @NonNull final LayoutElementParcelabl |
1428 | 1435 | popupMenu.show(); |
1429 | 1436 | } |
1430 | 1437 |
|
| 1438 | + /** |
| 1439 | + * Helps in deciding whether to allow file modification or not, depending on the state of the |
| 1440 | + * copy/paste operation. |
| 1441 | + * |
| 1442 | + * @return true if there is an unfinished copy/paste operation, false otherwise. |
| 1443 | + */ |
| 1444 | + private boolean hasPendingPasteOperation() { |
| 1445 | + MainActivity mainActivity = mainFragment.getMainActivity(); |
| 1446 | + if (mainActivity == null) return false; |
| 1447 | + MainActivityActionMode mainActivityActionMode = mainActivity.mainActivityActionMode; |
| 1448 | + PasteHelper pasteHelper = mainActivityActionMode.getPasteHelper(); |
| 1449 | + |
| 1450 | + if (pasteHelper != null |
| 1451 | + && pasteHelper.getSnackbar() != null |
| 1452 | + && pasteHelper.getSnackbar().isShown()) { |
| 1453 | + Toast.makeText( |
| 1454 | + mainFragment.requireContext(), |
| 1455 | + mainFragment.getString(R.string.complete_paste_warning), |
| 1456 | + Toast.LENGTH_LONG) |
| 1457 | + .show(); |
| 1458 | + return true; |
| 1459 | + } |
| 1460 | + return false; |
| 1461 | + } |
| 1462 | + |
1431 | 1463 | private boolean getBoolean(String key) { |
1432 | 1464 | return preferenceActivity.getBoolean(key); |
1433 | 1465 | } |
|
0 commit comments