Prevent deleting folders with children

This commit is contained in:
M66B
2025-04-21 11:56:53 +02:00
parent 9496192648
commit 161f96dc05
4 changed files with 10 additions and 4 deletions

View File

@@ -730,7 +730,8 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (folder.selectable && Shortcuts.can(context))
popupMenu.getMenu().add(Menu.NONE, R.string.title_pin, order++, R.string.title_pin);
if (!folder.read_only && EntityFolder.USER.equals(folder.type))
if (!folder.read_only && EntityFolder.USER.equals(folder.type) &&
(folder.child_refs == null || folder.child_refs.isEmpty()))
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete, order++, R.string.title_delete);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

View File

@@ -52,6 +52,7 @@ import androidx.preference.PreferenceManager;
import com.google.android.material.snackbar.Snackbar;
import java.util.List;
import java.util.Objects;
public class FragmentFolder extends FragmentBase {
@@ -301,6 +302,9 @@ public class FragmentFolder extends FragmentBase {
EntityFolder parent = db.folder().getFolderByName(aid, parentName);
EntityFolder folder = db.folder().getFolder(id);
List<EntityFolder> children = db.folder().getChildFolders(id);
args.putBoolean("children", (children != null && !children.isEmpty()));
if (folder != null) {
EntityAccount account = db.account().getAccount(folder.account);
if (account != null) {
@@ -377,7 +381,8 @@ public class FragmentFolder extends FragmentBase {
deletable = (folder != null &&
!folder.read_only &&
EntityFolder.USER.equals(folder.type));
EntityFolder.USER.equals(folder.type) &&
!args.getBoolean("children"));
invalidateOptionsMenu();
}