From 75f1af1c985c8e9e8a7178550f322a2d6cabde43 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 4 Nov 2022 13:07:50 +0100 Subject: [PATCH] Experiment: leave on device for IMAP --- app/src/main/java/eu/faircode/email/Core.java | 20 +++++++++++++++---- .../eu/faircode/email/FragmentAccount.java | 11 ++++++++++ .../eu/faircode/email/FragmentMessages.java | 2 +- app/src/main/res/layout/fragment_account.xml | 13 ++++++++++-- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 354bfa391f..96ad6ac26e 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1847,8 +1847,14 @@ class Core { } } - int count = db.message().deleteMessage(folder.id, uid); - Log.i(folder.name + " delete local uid=" + uid + " count=" + count); + if (BuildConfig.DEBUG && account.leave_on_device) { + EntityMessage message = db.message().getMessageByUid(folder.id, uid); + if (message != null) + db.message().setMessageUiDeleted(message.id, true); + } else { + int count = db.message().deleteMessage(folder.id, uid); + Log.i(folder.name + " delete local uid=" + uid + " count=" + count); + } } else throw ex; } finally { @@ -3890,8 +3896,14 @@ class Core { // Delete local messages not at remote Log.i(folder.name + " delete=" + uids.size()); for (Long uid : uids) { - int count = db.message().deleteMessage(folder.id, uid); - Log.i(folder.name + " delete local uid=" + uid + " count=" + count); + if (BuildConfig.DEBUG && account.leave_on_device) { + EntityMessage message = db.message().getMessageByUid(folder.id, uid); + if (message != null) + db.message().setMessageUiDeleted(message.id, true); + } else { + int count = db.message().deleteMessage(folder.id, uid); + Log.i(folder.name + " delete local uid=" + uid + " count=" + count); + } } List rules = db.rule().getEnabledRules(folder.id); diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 0aa00c91fe..307b072253 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -125,6 +125,7 @@ public class FragmentAccount extends FragmentBase { private TextView tvNotifyPro; private CheckBox cbBrowse; private CheckBox cbAutoSeen; + private CheckBox cbLeaveDevice; private EditText etInterval; private CheckBox cbNoop; private CheckBox cbPartialFetch; @@ -244,6 +245,7 @@ public class FragmentAccount extends FragmentBase { tvNotifyPro = view.findViewById(R.id.tvNotifyPro); cbBrowse = view.findViewById(R.id.cbBrowse); cbAutoSeen = view.findViewById(R.id.cbAutoSeen); + cbLeaveDevice = view.findViewById(R.id.cbLeaveDevice); etInterval = view.findViewById(R.id.etInterval); cbNoop = view.findViewById(R.id.cbNoop); cbPartialFetch = view.findViewById(R.id.cbPartialFetch); @@ -511,6 +513,9 @@ public class FragmentAccount extends FragmentBase { etInterval.setHint(Integer.toString(EntityAccount.DEFAULT_KEEP_ALIVE_INTERVAL)); + if (!BuildConfig.DEBUG) + Helper.hide(cbLeaveDevice); + btnCheck.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -933,6 +938,7 @@ public class FragmentAccount extends FragmentBase { args.putBoolean("notify", cbNotify.isChecked()); args.putBoolean("browse", cbBrowse.isChecked()); args.putBoolean("auto_seen", cbAutoSeen.isChecked()); + args.putBoolean("leave_device", cbLeaveDevice.isChecked()); args.putString("interval", etInterval.getText().toString()); args.putBoolean("noop", cbNoop.isChecked()); args.putBoolean("partial_fetch", cbPartialFetch.isChecked()); @@ -1008,6 +1014,7 @@ public class FragmentAccount extends FragmentBase { boolean notify = args.getBoolean("notify"); boolean browse = args.getBoolean("browse"); boolean auto_seen = args.getBoolean("auto_seen"); + boolean leave_device = args.getBoolean("leave_device"); String interval = args.getString("interval"); boolean noop = args.getBoolean("noop"); boolean partial_fetch = args.getBoolean("partial_fetch"); @@ -1115,6 +1122,8 @@ public class FragmentAccount extends FragmentBase { return true; if (!Objects.equals(account.auto_seen, auto_seen)) return true; + if (!Objects.equals(account.leave_on_device, leave_device)) + return true; if (!Objects.equals(account.poll_interval, poll_interval)) return true; if (!Objects.equals(account.keep_alive_noop, noop)) @@ -1262,6 +1271,7 @@ public class FragmentAccount extends FragmentBase { account.notify = notify; account.browse = browse; account.auto_seen = auto_seen; + account.leave_on_device = leave_device; if (account.poll_interval != poll_interval) { account.keep_alive_ok = false; @@ -1636,6 +1646,7 @@ public class FragmentAccount extends FragmentBase { cbPrimary.setChecked(account == null ? false : account.primary); cbBrowse.setChecked(account == null ? true : account.browse); cbAutoSeen.setChecked(account == null ? true : account.auto_seen); + cbLeaveDevice.setChecked(account == null ? true : account.leave_on_device); etInterval.setText(account == null ? "" : Long.toString(account.poll_interval)); cbNoop.setChecked(account == null ? true : account.keep_alive_noop); cbPartialFetch.setChecked(account == null ? true : account.partial_fetch); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index b7e4f0fc2e..76d09350b9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -5312,7 +5312,7 @@ public class FragmentMessages extends FragmentBase menu.findItem(R.id.menu_filter_unflagged).setVisible(folder); menu.findItem(R.id.menu_filter_unknown).setVisible(folder && !drafts && !sent); menu.findItem(R.id.menu_filter_snoozed).setVisible(folder && !drafts); - menu.findItem(R.id.menu_filter_deleted).setVisible(folder && !perform_expunge); + menu.findItem(R.id.menu_filter_deleted).setVisible(folder && (!perform_expunge || BuildConfig.DEBUG)); menu.findItem(R.id.menu_filter_duplicates).setVisible(viewType == AdapterMessage.ViewType.THREAD); menu.findItem(R.id.menu_filter_trash).setVisible(viewType == AdapterMessage.ViewType.THREAD); diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index b2a8ff576d..a463c3a821 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -611,6 +611,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvBrowseHint" /> + + + app:layout_constraintTop_toBottomOf="@id/cbLeaveDevice" />