Added empty trash

Fixes #106
pull/145/head
M66B 6 years ago
parent 78811ccd34
commit 0035b0e9fe

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
@ -40,6 +41,7 @@ import java.util.List;
import java.util.Locale;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.lifecycle.LifecycleOwner;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -68,7 +70,8 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private final static int action_synchronize_now = 1;
private final static int action_delete_local = 2;
private final static int action_edit_properties = 3;
private final static int action_empty_trash = 3;
private final static int action_edit_properties = 4;
ViewHolder(View itemView) {
super(itemView);
@ -168,9 +171,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (!EntityFolder.DRAFTS.equals(folder.type))
popupMenu.getMenu().add(Menu.NONE, action_delete_local, 2, R.string.title_delete_local);
if (EntityFolder.TRASH.equals(folder.type))
popupMenu.getMenu().add(Menu.NONE, action_empty_trash, 3, R.string.title_empty_trash);
if (folder.account != null)
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 3, R.string.title_edit_properties);
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 4, R.string.title_edit_properties);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
@ -211,6 +216,51 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
break;
case action_empty_trash:
new AlertDialog.Builder(context)
.setMessage(R.string.title_empty_trash_ask)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle args = new Bundle();
args.putLong("id", folder.id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
for (EntityMessage message : db.message().getMessageByFolder(id)) {
db.message().setMessageUiHide(message.id, true);
EntityOperation.queue(db, message, EntityOperation.DELETE);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
EntityOperation.process(context);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, ex);
}
}.load(context, owner, args);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
break;
case action_edit_properties:
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_EDIT_FOLDER)

@ -133,6 +133,11 @@ public interface DaoMessage {
" AND folder.type <> '" + EntityFolder.DRAFTS + "'")
List<EntityMessage> getMessageByThread(long account, String thread);
@Query("SELECT *" +
" FROM message" +
" WHERE folder = :folder")
List<EntityMessage> getMessageByFolder(long folder);
@Query("SELECT id FROM message" +
" WHERE folder = :folder" +
" ORDER BY message.received DESC, message.sent DESC")

@ -132,8 +132,11 @@
<string name="title_synchronize_now">Synchronize now</string>
<string name="title_delete_local">Delete local messages</string>
<string name="title_empty_trash">Empty trash</string>
<string name="title_edit_properties">Edit properties</string>
<string name="title_empty_trash_ask">Delete all trashed messages permanently?</string>
<string name="title_folder_name">Folder name</string>
<string name="title_synchronize_folder">Synchronize (receive messages)</string>
<string name="title_unified_folder">Show in unified inbox</string>

Loading…
Cancel
Save