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

Option for delete permanently on single click #4290

Open
wants to merge 5 commits into
base: release/4.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
15 changes: 13 additions & 2 deletions app/src/main/java/com/amaze/filemanager/ui/ItemPopupMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,19 @@ public boolean onMenuItemClick(MenuItem item) {
case R.id.delete:
ArrayList<LayoutElementParcelable> positions = new ArrayList<>();
positions.add(rowItem);
GeneralDialogCreation.deleteFilesDialog(
context, mainActivity, positions, utilitiesProvider.getAppTheme());
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context);
boolean deletePermanently =
sharedPreferences.getBoolean(
PreferencesConstants.PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION,
PreferencesConstants.DEFAULT_PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION);
VishnuSanal marked this conversation as resolved.
Show resolved Hide resolved
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());
}
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 @@ -59,6 +59,7 @@
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 @@ -506,11 +507,29 @@ private void initLeftAndRightDragListeners(boolean destroy) {
new DragToTrashListener(
() -> {
if (mainFragment != null) {
GeneralDialogCreation.deleteFilesDialog(
requireContext(),
requireMainActivity(),
mainFragment.adapter.getCheckedItems(),
requireMainActivity().getAppTheme());
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());
}
} else {
AppConfig.toast(requireContext(), getString(R.string.operation_unsuccesful));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ object PreferencesConstants {
const val PREFERENCE_ZIP_EXTRACT_PATH = "extractpath"
const val PREFERENCE_TEXTEDITOR_NEWSTACK = "texteditor_newstack"
const val PREFERENCE_DELETE_CONFIRMATION = "delete_confirmation"
const val PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION = "delete_permanently_without_confirmation"
const val PREFERENCE_DISABLE_PLAYER_INTENT_FILTERS = "disable_player_intent_filters"
const val PREFERENCE_TRASH_BIN_RETENTION_NUM_OF_FILES = "retention_num_of_files"
const val PREFERENCE_TRASH_BIN_RETENTION_DAYS = "retention_days"
Expand Down Expand Up @@ -122,4 +123,5 @@ object PreferencesConstants {
const val KEY_TRASH_BIN_CLEANUP_INTERVAL_HOURS = "trash_bin_cleanup_interval_hours"

const val DEFAULT_PREFERENCE_DELETE_CONFIRMATION = true
const val DEFAULT_PREFERENCE_DELETE_PERMANENTLY_WITHOUT_CONFIRMATION = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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 @@ -38,6 +39,7 @@ 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 @@ -237,12 +239,28 @@ class MainActivityActionMode(private val mainActivityReference: WeakReference<Ma
true
}
R.id.delete -> {
GeneralDialogCreation.deleteFilesDialog(
mainActivity,
mainActivity,
checkedItems,
mainActivity.utilsProvider.appTheme,
)
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,
)
}
true
}
R.id.restore -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

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 @@ -685,6 +686,15 @@ 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
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ You only need to do this once, until the next time you select a new location for
<string name="error_cannot_get_package_info">Unable to get package info from file \"%s\". Either the specified file is not an APK, or the package file is corrupt.</string>
<string name="preference_delete_confirmation">Delete confirmation</string>
<string name="preference_delete_confirmation_summary">Ask for confirmation before deleting files. Disabling this is highly discouraged!</string>
<string name="preference_delete_permanently_without_confirmation">Delete permanently</string>
VishnuSanal marked this conversation as resolved.
Show resolved Hide resolved
<string name="preference_delete_permanently_without_confirmation_summary">Delete files permanently without asking confirmation. Enabling this is highly discouraged!</string>
<string name="protocol_ssh" translatable="false">SSH/SFTP</string>
<string name="protocol_ftp" translatable="false">FTP</string>
<string name="protocol_ftps">Secure FTP</string>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/behavior_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
app:key="delete_confirmation"
app:summary="@string/preference_delete_confirmation_summary"
app:title="@string/preference_delete_confirmation" />
<com.amaze.filemanager.ui.views.preference.CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:defaultValue="false"
app:key="delete_permanently_without_confirmation"
app:summary="@string/preference_delete_permanently_without_confirmation_summary"
app:title="@string/preference_delete_permanently_without_confirmation" />
<Preference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
Loading