Skip to content

Commit

Permalink
corrected functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
yashwanthgajji committed Dec 17, 2024
1 parent 1be7ec0 commit ab9310a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 72 deletions.
15 changes: 2 additions & 13 deletions app/src/main/java/com/amaze/filemanager/ui/ItemPopupMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,8 @@ public boolean onMenuItemClick(MenuItem item) {
case R.id.delete:
ArrayList<LayoutElementParcelable> positions = new ArrayList<>();
positions.add(rowItem);
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context);
boolean deletePermanently =
sharedPreferences.getBoolean(
PreferencesConstants.PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION,
PreferencesConstants.DEFAULT_PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION);
if (deletePermanently) {
Toast.makeText(context, context.getString(R.string.deleting), Toast.LENGTH_SHORT).show();
mainActivity.mainActivityHelper.deleteFilesPermanently(positions);
} else {
GeneralDialogCreation.deleteFilesDialog(
context, mainActivity, positions, utilitiesProvider.getAppTheme());
}
GeneralDialogCreation.deleteFilesDialog(
context, mainActivity, positions, utilitiesProvider.getAppTheme());
return true;
case R.id.restore:
ArrayList<LayoutElementParcelable> p2 = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,22 @@ public static void deleteFilesDialog(
sharedPreferences.getBoolean(
PreferencesConstants.PREFERENCE_DELETE_CONFIRMATION,
PreferencesConstants.DEFAULT_PREFERENCE_DELETE_CONFIRMATION);
boolean deletePermanently =
sharedPreferences.getBoolean(
PreferencesConstants.PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION,
PreferencesConstants.DEFAULT_PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION);
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_delete, null);
TextView deleteDisclaimerTextView = dialogView.findViewById(R.id.dialog_delete_disclaimer);
final AppCompatCheckBox deletePermanentlyCheckbox =
dialogView.findViewById(R.id.delete_permanently_checkbox);
if (positions.get(0).generateBaseFile().isLocal()) {
// FIXME: make sure dialog is not shown for zero items
// allow trash bin delete only for local files for now
deletePermanentlyCheckbox.setVisibility(View.VISIBLE);
if (deletePermanently) {
deletePermanentlyCheckbox.setVisibility(View.GONE);
} else {
deletePermanentlyCheckbox.setVisibility(View.VISIBLE);
}
} else {
deleteDisclaimerTextView.setText(context.getString(R.string.dialog_delete_disclaimer));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.Toast;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -507,29 +506,11 @@ private void initLeftAndRightDragListeners(boolean destroy) {
new DragToTrashListener(
() -> {
if (mainFragment != null) {
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(requireContext());
boolean deletePermanently =
sharedPreferences.getBoolean(
PreferencesConstants.PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION,
PreferencesConstants
.DEFAULT_PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION);
if (deletePermanently) {
Toast.makeText(
requireContext(),
requireContext().getString(R.string.deleting),
Toast.LENGTH_SHORT)
.show();
requireMainActivity()
.mainActivityHelper
.deleteFilesPermanently(mainFragment.adapter.getCheckedItems());
} else {
GeneralDialogCreation.deleteFilesDialog(
requireContext(),
requireMainActivity(),
mainFragment.adapter.getCheckedItems(),
requireMainActivity().getAppTheme());
}
GeneralDialogCreation.deleteFilesDialog(
requireContext(),
requireMainActivity(),
mainFragment.adapter.getCheckedItems(),
requireMainActivity().getAppTheme());
} else {
AppConfig.toast(requireContext(), getString(R.string.operation_unsuccesful));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import android.widget.Toast
import androidx.appcompat.view.ActionMode
import androidx.appcompat.widget.AppCompatTextView
import androidx.drawerlayout.widget.DrawerLayout
import androidx.preference.PreferenceManager
import com.amaze.filemanager.R
import com.amaze.filemanager.adapters.data.LayoutElementParcelable
import com.amaze.filemanager.fileoperations.filesystem.OpenMode
Expand All @@ -39,7 +38,6 @@ import com.amaze.filemanager.filesystem.PasteHelper
import com.amaze.filemanager.filesystem.files.FileUtils
import com.amaze.filemanager.ui.activities.MainActivity
import com.amaze.filemanager.ui.dialogs.GeneralDialogCreation
import com.amaze.filemanager.ui.fragments.preferencefragments.PreferencesConstants
import com.amaze.filemanager.ui.selection.SelectionPopupMenu.Companion.invokeSelectionDropdown
import java.io.File
import java.lang.ref.WeakReference
Expand Down Expand Up @@ -239,28 +237,12 @@ class MainActivityActionMode(private val mainActivityReference: WeakReference<Ma
true
}
R.id.delete -> {
val sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(mainActivity)
val deletePermanently =
sharedPreferences.getBoolean(
PreferencesConstants.PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION,
PreferencesConstants.DEFAULT_PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION,
)
if (deletePermanently) {
Toast.makeText(
mainActivity,
mainActivity.getString(R.string.deleting),
Toast.LENGTH_SHORT,
).show()
mainActivity.mainActivityHelper.deleteFilesPermanently(checkedItems)
} else {
GeneralDialogCreation.deleteFilesDialog(
mainActivity,
mainActivity,
checkedItems,
mainActivity.utilsProvider.appTheme,
)
}
GeneralDialogCreation.deleteFilesDialog(
mainActivity,
mainActivity,
checkedItems,
mainActivity.utilsProvider.appTheme,
)
true
}
R.id.restore -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import com.afollestad.materialdialogs.MaterialDialog;
import com.amaze.filemanager.R;
import com.amaze.filemanager.adapters.data.LayoutElementParcelable;
import com.amaze.filemanager.application.AppConfig;
import com.amaze.filemanager.asynchronous.asynctasks.DeleteTask;
import com.amaze.filemanager.asynchronous.management.ServiceWatcherUtil;
Expand Down Expand Up @@ -686,15 +685,6 @@ public void deleteFiles(ArrayList<HybridFileParcelable> files, boolean doDeleteP
else Toast.makeText(mainActivity, R.string.not_allowed, Toast.LENGTH_SHORT).show();
}

public void deleteFilesPermanently(ArrayList<LayoutElementParcelable> files) {
final ArrayList<HybridFileParcelable> itemsToDelete = new ArrayList<>();
for (int i = 0; i < files.size(); i++) {
final LayoutElementParcelable layoutElement = files.get(i);
itemsToDelete.add(layoutElement.generateBaseFile());
}
deleteFiles(itemsToDelete, true);
}

public void extractFile(@NonNull File file) {
final File parent = file.getParentFile();
if (parent == null) {
Expand Down

0 comments on commit ab9310a

Please sign in to comment.