Added swipe configuration to POP3 accounts

pull/183/head
M66B 5 years ago
parent f601c943fa
commit 212d92f9e4

@ -1727,7 +1727,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return; return;
if (message.accountProtocol != EntityAccount.TYPE_IMAP) { if (message.accountProtocol != EntityAccount.TYPE_IMAP) {
if (swipes.swipe_right == null)
swipes.swipe_right = FragmentAccount.SWIPE_ACTION_SEEN; swipes.swipe_right = FragmentAccount.SWIPE_ACTION_SEEN;
if (swipes.swipe_left == null)
swipes.swipe_left = FragmentAccount.SWIPE_ACTION_DELETE; swipes.swipe_left = FragmentAccount.SWIPE_ACTION_DELETE;
} }
@ -1822,12 +1824,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
if (message.accountProtocol != EntityAccount.TYPE_IMAP) { if (message.accountProtocol != EntityAccount.TYPE_IMAP) {
if (direction == ItemTouchHelper.LEFT) { if (swipes.swipe_right == null)
adapter.notifyItemChanged(pos); swipes.swipe_right = FragmentAccount.SWIPE_ACTION_SEEN;
onSwipeDelete(message); if (swipes.swipe_left == null)
} else swipes.swipe_left = FragmentAccount.SWIPE_ACTION_DELETE;
onActionSeenSelection(!message.ui_seen, message.id);
return;
} }
Long action = (direction == ItemTouchHelper.LEFT ? swipes.swipe_left : swipes.swipe_right); Long action = (direction == ItemTouchHelper.LEFT ? swipes.swipe_left : swipes.swipe_right);

@ -36,12 +36,14 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -52,7 +54,9 @@ import androidx.lifecycle.Lifecycle;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
@ -86,6 +90,10 @@ public class FragmentPop extends FragmentBase {
private EditText etMax; private EditText etMax;
private EditText etInterval; private EditText etInterval;
private ArrayAdapter<EntityFolder> adapterSwipe;
private Spinner spLeft;
private Spinner spRight;
private Button btnSave; private Button btnSave;
private ContentLoadingProgressBar pbSave; private ContentLoadingProgressBar pbSave;
private TextView tvError; private TextView tvError;
@ -141,6 +149,9 @@ public class FragmentPop extends FragmentBase {
etMax = view.findViewById(R.id.etMax); etMax = view.findViewById(R.id.etMax);
etInterval = view.findViewById(R.id.etInterval); etInterval = view.findViewById(R.id.etInterval);
spLeft = view.findViewById(R.id.spLeft);
spRight = view.findViewById(R.id.spRight);
btnSave = view.findViewById(R.id.btnSave); btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave); pbSave = view.findViewById(R.id.pbSave);
@ -206,6 +217,12 @@ public class FragmentPop extends FragmentBase {
etInterval.setHint(Integer.toString(EntityAccount.DEFAULT_POLL_INTERVAL)); 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() { btnSave.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -248,6 +265,9 @@ public class FragmentPop extends FragmentBase {
args.putString("max", etMax.getText().toString()); args.putString("max", etMax.getText().toString());
args.putString("interval", etInterval.getText().toString()); args.putString("interval", etInterval.getText().toString());
args.putLong("left", ((EntityFolder) spLeft.getSelectedItem()).id);
args.putLong("right", ((EntityFolder) spRight.getSelectedItem()).id);
new SimpleTask<Boolean>() { new SimpleTask<Boolean>() {
@Override @Override
protected void onPreExecute(Bundle args) { protected void onPreExecute(Bundle args) {
@ -289,6 +309,9 @@ public class FragmentPop extends FragmentBase {
String max = args.getString("max"); String max = args.getString("max");
String interval = args.getString("interval"); String interval = args.getString("interval");
long left = args.getLong("left");
long right = args.getLong("right");
boolean pro = ActivityBilling.isPro(context); boolean pro = ActivityBilling.isPro(context);
if (host.contains(":")) { if (host.contains(":")) {
@ -381,6 +404,9 @@ public class FragmentPop extends FragmentBase {
account.max_messages = (TextUtils.isEmpty(max) ? null : Integer.parseInt(max)); account.max_messages = (TextUtils.isEmpty(max) ? null : Integer.parseInt(max));
account.poll_interval = Math.max(1, Integer.parseInt(interval)); account.poll_interval = Math.max(1, Integer.parseInt(interval));
account.swipe_left = left;
account.swipe_right = right;
if (!update) if (!update)
account.created = now; account.created = now;
@ -564,6 +590,21 @@ public class FragmentPop extends FragmentBase {
? EntityAccount.DEFAULT_MAX_MESSAGES : account.max_messages)); ? EntityAccount.DEFAULT_MAX_MESSAGES : account.max_messages));
etInterval.setText(account == null ? "" : Long.toString(account.poll_interval)); etInterval.setText(account == null ? "" : Long.toString(account.poll_interval));
List<EntityFolder> 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<EntityAccount>() { new SimpleTask<EntityAccount>() {
@Override @Override
protected EntityAccount onExecute(Context context, Bundle args) { protected EntityAccount onExecute(Context context, Bundle args) {
@ -693,4 +734,35 @@ public class FragmentPop extends FragmentBase {
} }
}.execute(this, args, "account:delete"); }.execute(this, args, "account:delete");
} }
private List<EntityFolder> getSwipeActions() {
List<EntityFolder> 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;
}
} }

@ -379,6 +379,42 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etInterval" /> app:layout_constraintTop_toBottomOf="@id/etInterval" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_account_left"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvIntervalRemark" />
<Spinner
android:id="@+id/spLeft"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLeft" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_account_right"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spLeft" />
<Spinner
android:id="@+id/spRight"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRight" />
<!-- save --> <!-- save -->
<Button <Button
@ -389,7 +425,7 @@
android:tag="disable" android:tag="disable"
android:text="@string/title_save" android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvIntervalRemark" /> app:layout_constraintTop_toBottomOf="@id/spRight" />
<eu.faircode.email.ContentLoadingProgressBar <eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbSave" android:id="@+id/pbSave"

Loading…
Cancel
Save