Permanently delete conversations when no trash

pull/172/head
M66B 6 years ago
parent ba127e9e1d
commit 30613e52e3

@ -699,6 +699,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) { switch (menuItem.getItemId()) {
case R.id.action_delete: case R.id.action_delete:
if ((Boolean) bottom_navigation.getTag())
onActionDelete();
else
onActionMove(EntityFolder.TRASH); onActionMove(EntityFolder.TRASH);
return true; return true;
@ -723,6 +726,58 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
} }
private void onActionDelete() {
Bundle args = new Bundle();
args.putLong("account", account);
args.putString("thread", thread);
args.putLong("id", id);
new SimpleTask<List<Long>>() {
@Override
protected List<Long> onExecute(Context context, Bundle args) throws Throwable {
long aid = args.getLong("account");
String thread = args.getString("thread");
long id = args.getLong("id");
ArrayList<Long> result = new ArrayList<>();
DB db = DB.getInstance(context);
try {
db.beginTransaction();
List<EntityMessage> messages = db.message().getMessagesByThread(
aid, thread, threading ? null : id, null);
for (EntityMessage threaded : messages)
result.add(threaded.id);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return result;
}
@Override
protected void onExecuted(Bundle args, List<Long> ids) {
Bundle aargs = new Bundle();
aargs.putString("question", getResources()
.getQuantityString(R.plurals.title_deleting_messages, ids.size(), ids.size()));
aargs.putLongArray("ids", Helper.toLongArray(ids));
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);
ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGES_DELETE);
ask.show(getParentFragmentManager(), "messages:delete");
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentMessages.this, args, "messages:delete");
}
private void onActionMove(String folderType) { private void onActionMove(String folderType) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("account", account); args.putLong("account", account);
@ -3540,17 +3595,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
EntityFolder trash = db.folder().getFolderByType(account, EntityFolder.TRASH); EntityFolder trash = db.folder().getFolderByType(account, EntityFolder.TRASH);
EntityFolder archive = db.folder().getFolderByType(account, EntityFolder.ARCHIVE); EntityFolder archive = db.folder().getFolderByType(account, EntityFolder.ARCHIVE);
trashable = (trashable && trash != null); return new Boolean[]{
archivable = (archivable && archive != null); trash == null,
trashable,
return new Boolean[]{trashable, snoozable, archivable}; snoozable,
archivable && archive != null};
} }
@Override @Override
protected void onExecuted(Bundle args, Boolean[] data) { protected void onExecuted(Bundle args, Boolean[] data) {
bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(data[0]); bottom_navigation.setTag(data[0]);
bottom_navigation.getMenu().findItem(R.id.action_snooze).setVisible(data[1]); bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(data[1]);
bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(data[2]); bottom_navigation.getMenu().findItem(R.id.action_snooze).setVisible(data[2]);
bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(data[3]);
bottom_navigation.setVisibility(View.VISIBLE); bottom_navigation.setVisibility(View.VISIBLE);
} }
@ -4942,6 +4999,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
private void onDelete(Bundle args) { private void onDelete(Bundle args) {
if (selectionTracker != null)
selectionTracker.clearSelection(); selectionTracker.clearSelection();
new SimpleTask<Void>() { new SimpleTask<Void>() {

Loading…
Cancel
Save