mirror of https://github.com/M66B/FairEmail.git
Added menu to delete non-selectable folders
This commit is contained in:
parent
febab8c196
commit
2dfabba508
|
@ -414,6 +414,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
return false;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean debug = prefs.getBoolean("debug", false);
|
||||
|
||||
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view);
|
||||
|
||||
|
@ -479,6 +480,10 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
popupMenu.getMenu().add(Menu.NONE, R.string.title_create_sub_folder, 16, R.string.title_create_sub_folder)
|
||||
.setEnabled(folder.inferiors);
|
||||
|
||||
if (!folder.selectable && debug)
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete, 17, R.string.title_delete)
|
||||
.setEnabled(folder.inferiors);
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
|
@ -545,6 +550,10 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
onActionCreateFolder();
|
||||
return true;
|
||||
|
||||
case R.string.title_delete:
|
||||
onActionDeleteFolder();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -713,6 +722,17 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
.putExtra("account", folder.account)
|
||||
.putExtra("parent", folder.name));
|
||||
}
|
||||
|
||||
private void onActionDeleteFolder() {
|
||||
Bundle aargs = new Bundle();
|
||||
aargs.putLong("id", folder.id);
|
||||
aargs.putString("question", context.getString(R.string.title_folder_delete));
|
||||
|
||||
FragmentDialogAsk ask = new FragmentDialogAsk();
|
||||
ask.setArguments(aargs);
|
||||
ask.setTargetFragment(parentFragment, FragmentFolders.REQUEST_DELETE_FOLDER);
|
||||
ask.show(parentFragment.getParentFragmentManager(), "folder:delete");
|
||||
}
|
||||
});
|
||||
|
||||
popupMenu.show();
|
||||
|
|
|
@ -90,6 +90,7 @@ public class FragmentFolders extends FragmentBase {
|
|||
static final int REQUEST_SYNC = 1;
|
||||
static final int REQUEST_DELETE_LOCAL = 2;
|
||||
static final int REQUEST_EMPTY_FOLDER = 3;
|
||||
static final int REQUEST_DELETE_FOLDER = 4;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -526,6 +527,10 @@ public class FragmentFolders extends FragmentBase {
|
|||
if (resultCode == RESULT_OK && data != null)
|
||||
onEmptyFolder(data.getBundleExtra("args"));
|
||||
break;
|
||||
case REQUEST_DELETE_FOLDER:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
onDeleteFolder(data.getBundleExtra("args"));
|
||||
break;
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
|
@ -690,6 +695,41 @@ public class FragmentFolders extends FragmentBase {
|
|||
}.execute(this, args, "folder:delete");
|
||||
}
|
||||
|
||||
private void onDeleteFolder(Bundle args) {
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
|
||||
EntityFolder folder;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
folder = db.folder().getFolder(id);
|
||||
if (folder == null)
|
||||
return null;
|
||||
|
||||
db.folder().setFolderTbd(folder.id);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
ServiceSynchronize.reload(context, folder.account, false, "delete folder");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, args, "folder:delete");
|
||||
}
|
||||
|
||||
public static class FragmentDialogApply extends FragmentDialogBase {
|
||||
@NonNull
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue