From 212d92f9e462e30257cf57324b51643ad3169a87 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 30 Jun 2020 21:09:37 +0200 Subject: [PATCH] Added swipe configuration to POP3 accounts --- .../eu/faircode/email/FragmentMessages.java | 16 ++--- .../java/eu/faircode/email/FragmentPop.java | 72 +++++++++++++++++++ app/src/main/res/layout/fragment_pop.xml | 38 +++++++++- 3 files changed, 117 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index ba8c6b4b8f..027b2712cf 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -1727,8 +1727,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. return; if (message.accountProtocol != EntityAccount.TYPE_IMAP) { - swipes.swipe_right = FragmentAccount.SWIPE_ACTION_SEEN; - swipes.swipe_left = FragmentAccount.SWIPE_ACTION_DELETE; + if (swipes.swipe_right == null) + swipes.swipe_right = FragmentAccount.SWIPE_ACTION_SEEN; + if (swipes.swipe_left == null) + swipes.swipe_left = FragmentAccount.SWIPE_ACTION_DELETE; } Long action = (dX > 0 ? swipes.swipe_right : swipes.swipe_left); @@ -1822,12 +1824,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } if (message.accountProtocol != EntityAccount.TYPE_IMAP) { - if (direction == ItemTouchHelper.LEFT) { - adapter.notifyItemChanged(pos); - onSwipeDelete(message); - } else - onActionSeenSelection(!message.ui_seen, message.id); - return; + if (swipes.swipe_right == null) + swipes.swipe_right = FragmentAccount.SWIPE_ACTION_SEEN; + if (swipes.swipe_left == null) + swipes.swipe_left = FragmentAccount.SWIPE_ACTION_DELETE; } Long action = (direction == ItemTouchHelper.LEFT ? swipes.swipe_left : swipes.swipe_right); diff --git a/app/src/main/java/eu/faircode/email/FragmentPop.java b/app/src/main/java/eu/faircode/email/FragmentPop.java index 8e414e1787..d09c32ec7d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentPop.java +++ b/app/src/main/java/eu/faircode/email/FragmentPop.java @@ -36,12 +36,14 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.RadioGroup; import android.widget.ScrollView; +import android.widget.Spinner; import android.widget.TextView; import androidx.annotation.NonNull; @@ -52,7 +54,9 @@ import androidx.lifecycle.Lifecycle; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.textfield.TextInputLayout; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Objects; import static android.app.Activity.RESULT_OK; @@ -86,6 +90,10 @@ public class FragmentPop extends FragmentBase { private EditText etMax; private EditText etInterval; + private ArrayAdapter adapterSwipe; + private Spinner spLeft; + private Spinner spRight; + private Button btnSave; private ContentLoadingProgressBar pbSave; private TextView tvError; @@ -141,6 +149,9 @@ public class FragmentPop extends FragmentBase { etMax = view.findViewById(R.id.etMax); etInterval = view.findViewById(R.id.etInterval); + spLeft = view.findViewById(R.id.spLeft); + spRight = view.findViewById(R.id.spRight); + btnSave = view.findViewById(R.id.btnSave); pbSave = view.findViewById(R.id.pbSave); @@ -206,6 +217,12 @@ public class FragmentPop extends FragmentBase { etInterval.setHint(Integer.toString(EntityAccount.DEFAULT_POLL_INTERVAL)); + adapterSwipe = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, getSwipeActions()); + adapterSwipe.setDropDownViewResource(R.layout.spinner_item1_dropdown); + + spLeft.setAdapter(adapterSwipe); + spRight.setAdapter(adapterSwipe); + btnSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -248,6 +265,9 @@ public class FragmentPop extends FragmentBase { args.putString("max", etMax.getText().toString()); args.putString("interval", etInterval.getText().toString()); + args.putLong("left", ((EntityFolder) spLeft.getSelectedItem()).id); + args.putLong("right", ((EntityFolder) spRight.getSelectedItem()).id); + new SimpleTask() { @Override protected void onPreExecute(Bundle args) { @@ -289,6 +309,9 @@ public class FragmentPop extends FragmentBase { String max = args.getString("max"); String interval = args.getString("interval"); + long left = args.getLong("left"); + long right = args.getLong("right"); + boolean pro = ActivityBilling.isPro(context); if (host.contains(":")) { @@ -381,6 +404,9 @@ public class FragmentPop extends FragmentBase { account.max_messages = (TextUtils.isEmpty(max) ? null : Integer.parseInt(max)); account.poll_interval = Math.max(1, Integer.parseInt(interval)); + account.swipe_left = left; + account.swipe_right = right; + if (!update) account.created = now; @@ -564,6 +590,21 @@ public class FragmentPop extends FragmentBase { ? EntityAccount.DEFAULT_MAX_MESSAGES : account.max_messages)); etInterval.setText(account == null ? "" : Long.toString(account.poll_interval)); + List folders = getSwipeActions(); + for (int pos = 0; pos < folders.size(); pos++) { + EntityFolder folder = folders.get(pos); + + if (account == null || account.swipe_left == null + ? FragmentAccount.SWIPE_ACTION_DELETE.equals(folder.id) + : account.swipe_left.equals(folder.id)) + spLeft.setSelection(pos); + + if (account == null || account.swipe_right == null + ? FragmentAccount.SWIPE_ACTION_SEEN.equals(folder.id) + : account.swipe_right.equals(folder.id)) + spRight.setSelection(pos); + } + new SimpleTask() { @Override protected EntityAccount onExecute(Context context, Bundle args) { @@ -693,4 +734,35 @@ public class FragmentPop extends FragmentBase { } }.execute(this, args, "account:delete"); } + + private List getSwipeActions() { + List folders = new ArrayList<>(); + + EntityFolder seen = new EntityFolder(); + seen.id = FragmentAccount.SWIPE_ACTION_SEEN; + seen.name = getString(R.string.title_seen); + folders.add(seen); + + EntityFolder flag = new EntityFolder(); + flag.id = FragmentAccount.SWIPE_ACTION_FLAG; + flag.name = getString(R.string.title_flag); + folders.add(flag); + + EntityFolder snooze = new EntityFolder(); + snooze.id = FragmentAccount.SWIPE_ACTION_SNOOZE; + snooze.name = getString(R.string.title_snooze_now); + folders.add(snooze); + + EntityFolder hide = new EntityFolder(); + hide.id = FragmentAccount.SWIPE_ACTION_HIDE; + hide.name = getString(R.string.title_hide); + folders.add(hide); + + EntityFolder delete = new EntityFolder(); + delete.id = FragmentAccount.SWIPE_ACTION_DELETE; + delete.name = getString(R.string.title_delete_permanently); + folders.add(delete); + + return folders; + } } diff --git a/app/src/main/res/layout/fragment_pop.xml b/app/src/main/res/layout/fragment_pop.xml index 59aad05fda..ca38f0c8ef 100644 --- a/app/src/main/res/layout/fragment_pop.xml +++ b/app/src/main/res/layout/fragment_pop.xml @@ -379,6 +379,42 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/etInterval" /> + + + + + + + +