Skip to content

Commit

Permalink
Merge branch 'release/4.0' into bugfix/path-param-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VishalNehra authored Oct 29, 2023
2 parents 4255d49 + 8cb7f00 commit c167e8b
Show file tree
Hide file tree
Showing 27 changed files with 824 additions and 775 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
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.MainActivity;
import com.amaze.filemanager.ui.activities.superclasses.PreferenceActivity;
import com.amaze.filemanager.ui.colors.ColorUtils;
import com.amaze.filemanager.ui.drag.RecyclerAdapterDragListener;
Expand All @@ -62,6 +64,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 +88,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 +767,7 @@ private void bindViewHolderList(@NonNull final ItemViewHolder holder, int positi

holder.baseItemView.setOnLongClickListener(
p1 -> {
if (hasPendingPasteOperation()) return false;
if (!isBackButton) {
if (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_DEFAULT
|| (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_TO_MOVE_COPY
Expand Down Expand Up @@ -976,6 +981,7 @@ private void bindViewHolderGrid(@NonNull final ItemViewHolder holder, int positi

holder.baseItemView.setOnLongClickListener(
p1 -> {
if (hasPendingPasteOperation()) return false;
if (!isBackButton) {
if (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_DEFAULT
|| (dragAndDropPreference == PreferencesConstants.PREFERENCE_DRAG_TO_MOVE_COPY
Expand Down Expand Up @@ -1366,6 +1372,7 @@ public boolean onResourceReady(
}

private void showPopup(@NonNull View view, @NonNull final LayoutElementParcelable rowItem) {
if (hasPendingPasteOperation()) return;
Context currentContext = this.context;
if (mainFragment.getMainActivity().getAppTheme().getSimpleTheme(mainFragment.requireContext())
== AppTheme.BLACK) {
Expand Down Expand Up @@ -1428,6 +1435,31 @@ private void showPopup(@NonNull View view, @NonNull final LayoutElementParcelabl
popupMenu.show();
}

/**
* Helps in deciding whether to allow file modification or not, depending on the state of the
* copy/paste operation.
*
* @return true if there is an unfinished copy/paste operation, false otherwise.
*/
private boolean hasPendingPasteOperation() {
MainActivity mainActivity = mainFragment.getMainActivity();
if (mainActivity == null) return false;
MainActivityActionMode mainActivityActionMode = mainActivity.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 true;
}
return false;
}

private boolean getBoolean(String key) {
return preferenceActivity.getBoolean(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import com.amaze.filemanager.filesystem.SafRootHolder;
import com.amaze.filemanager.filesystem.cloud.CloudUtil;
import com.amaze.filemanager.filesystem.files.CryptUtil;
import com.amaze.filemanager.filesystem.files.FileUtils;
import com.amaze.filemanager.filesystem.files.MediaConnectionUtils;
import com.amaze.filemanager.ui.activities.MainActivity;
import com.amaze.filemanager.ui.fragments.CompressedExplorerFragment;
import com.amaze.filemanager.ui.fragments.preferencefragments.PreferencesConstants;
Expand All @@ -48,12 +48,9 @@
import com.cloudrail.si.interfaces.CloudStorage;

import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.MediaStore;
import android.widget.Toast;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -112,13 +109,9 @@ protected final AsyncTaskResult<Boolean> doInBackground(
}

// delete file from media database
if (!file.isSmb()) {
try {
deleteFromMediaDatabase(applicationContext, file.getPath());
} catch (Exception e) {
FileUtils.scanFile(applicationContext, files.toArray(new HybridFile[files.size()]));
}
}
if (!file.isSmb())
MediaConnectionUtils.scanFile(
applicationContext, files.toArray(new HybridFile[files.size()]));

// delete file entry from encrypted database
if (file.getName(applicationContext).endsWith(CryptUtil.CRYPT_EXTENSION)) {
Expand Down Expand Up @@ -194,13 +187,4 @@ private boolean doDeleteFile(@NonNull HybridFileParcelable file) throws Exceptio
}
}
}

private void deleteFromMediaDatabase(final Context context, final String file) {
final String where = MediaStore.MediaColumns.DATA + "=?";
final String[] selectionArgs = new String[] {file};
final ContentResolver contentResolver = context.getContentResolver();
final Uri filesUri = MediaStore.Files.getContentUri("external");
// Delete the entry from the media database. This will actually delete media files.
contentResolver.delete(filesUri, where, selectionArgs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
/**
* AsyncTask that moves files from source to destination by trying to rename files first, if they're
* in the same filesystem, else starting the copy service. Be advised - do not start this AsyncTask
* directly but use {@link PrepareCopyTask} instead
* directly but use {@link PreparePasteTask} instead
*/
public class MoveFiles implements Callable<MoveFilesReturn> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import com.amaze.filemanager.fileoperations.filesystem.OpenMode
import com.amaze.filemanager.filesystem.HybridFile
import com.amaze.filemanager.filesystem.HybridFileParcelable
import com.amaze.filemanager.filesystem.files.CryptUtil
import com.amaze.filemanager.filesystem.files.FileUtils
import com.amaze.filemanager.filesystem.files.MediaConnectionUtils
import com.amaze.filemanager.ui.activities.MainActivity
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -106,8 +106,8 @@ class MoveFilesTask(
for (hybridFileParcelables in files) {
sourcesFiles.addAll(hybridFileParcelables)
}
FileUtils.scanFile(applicationContext, sourcesFiles.toTypedArray())
FileUtils.scanFile(applicationContext, targetFiles.toTypedArray())
MediaConnectionUtils.scanFile(applicationContext, sourcesFiles.toTypedArray())
MediaConnectionUtils.scanFile(applicationContext, targetFiles.toTypedArray())
}

// updating encrypted db entry if any encrypted file was moved
Expand Down
Loading

0 comments on commit c167e8b

Please sign in to comment.