mirror of https://github.com/M66B/FairEmail.git
Added dialog to set swipe actions for all accounts
This commit is contained in:
parent
b45cce9a32
commit
0557b305ff
|
@ -167,6 +167,9 @@ public interface DaoAccount {
|
|||
@Query("UPDATE account SET error = :error WHERE id = :id")
|
||||
int setAccountError(long id, String error);
|
||||
|
||||
@Query("UPDATE account SET swipe_left = :left, swipe_right = :right WHERE id = :id")
|
||||
int setAccountSwipes(long id, Long left, Long right);
|
||||
|
||||
@Query("UPDATE account SET `primary` = 0")
|
||||
void resetPrimary();
|
||||
|
||||
|
|
|
@ -1693,53 +1693,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
}
|
||||
|
||||
{
|
||||
List<EntityFolder> folders = new ArrayList<>();
|
||||
|
||||
EntityFolder none = new EntityFolder();
|
||||
none.id = 0L;
|
||||
none.name = "-";
|
||||
folders.add(none);
|
||||
|
||||
EntityFolder ask = new EntityFolder();
|
||||
ask.id = SWIPE_ACTION_ASK;
|
||||
ask.name = getString(R.string.title_ask_what);
|
||||
folders.add(ask);
|
||||
|
||||
EntityFolder seen = new EntityFolder();
|
||||
seen.id = SWIPE_ACTION_SEEN;
|
||||
seen.name = getString(R.string.title_seen);
|
||||
folders.add(seen);
|
||||
|
||||
EntityFolder flag = new EntityFolder();
|
||||
flag.id = SWIPE_ACTION_FLAG;
|
||||
flag.name = getString(R.string.title_flag);
|
||||
folders.add(flag);
|
||||
|
||||
EntityFolder snooze = new EntityFolder();
|
||||
snooze.id = SWIPE_ACTION_SNOOZE;
|
||||
snooze.name = getString(R.string.title_snooze_now);
|
||||
folders.add(snooze);
|
||||
|
||||
EntityFolder hide = new EntityFolder();
|
||||
hide.id = SWIPE_ACTION_HIDE;
|
||||
hide.name = getString(R.string.title_hide);
|
||||
folders.add(hide);
|
||||
|
||||
EntityFolder move = new EntityFolder();
|
||||
move.id = SWIPE_ACTION_MOVE;
|
||||
move.name = getString(R.string.title_move);
|
||||
folders.add(move);
|
||||
|
||||
EntityFolder junk = new EntityFolder();
|
||||
junk.id = SWIPE_ACTION_JUNK;
|
||||
junk.name = getString(R.string.title_report_spam);
|
||||
folders.add(junk);
|
||||
|
||||
EntityFolder delete = new EntityFolder();
|
||||
delete.id = SWIPE_ACTION_DELETE;
|
||||
delete.name = getString(R.string.title_delete_permanently);
|
||||
folders.add(delete);
|
||||
|
||||
List<EntityFolder> folders = getFolderActions(getContext());
|
||||
folders.addAll(_folders);
|
||||
|
||||
adapterSwipe.clear();
|
||||
|
@ -1777,6 +1731,57 @@ public class FragmentAccount extends FragmentBase {
|
|||
cbTrust.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
static List<EntityFolder> getFolderActions(Context context) {
|
||||
List<EntityFolder> folders = new ArrayList<>();
|
||||
|
||||
EntityFolder none = new EntityFolder();
|
||||
none.id = 0L;
|
||||
none.name = "-";
|
||||
folders.add(none);
|
||||
|
||||
EntityFolder ask = new EntityFolder();
|
||||
ask.id = SWIPE_ACTION_ASK;
|
||||
ask.name = context.getString(R.string.title_ask_what);
|
||||
folders.add(ask);
|
||||
|
||||
EntityFolder seen = new EntityFolder();
|
||||
seen.id = SWIPE_ACTION_SEEN;
|
||||
seen.name = context.getString(R.string.title_seen);
|
||||
folders.add(seen);
|
||||
|
||||
EntityFolder flag = new EntityFolder();
|
||||
flag.id = SWIPE_ACTION_FLAG;
|
||||
flag.name = context.getString(R.string.title_flag);
|
||||
folders.add(flag);
|
||||
|
||||
EntityFolder snooze = new EntityFolder();
|
||||
snooze.id = SWIPE_ACTION_SNOOZE;
|
||||
snooze.name = context.getString(R.string.title_snooze_now);
|
||||
folders.add(snooze);
|
||||
|
||||
EntityFolder hide = new EntityFolder();
|
||||
hide.id = SWIPE_ACTION_HIDE;
|
||||
hide.name = context.getString(R.string.title_hide);
|
||||
folders.add(hide);
|
||||
|
||||
EntityFolder move = new EntityFolder();
|
||||
move.id = SWIPE_ACTION_MOVE;
|
||||
move.name = context.getString(R.string.title_move);
|
||||
folders.add(move);
|
||||
|
||||
EntityFolder junk = new EntityFolder();
|
||||
junk.id = SWIPE_ACTION_JUNK;
|
||||
junk.name = context.getString(R.string.title_report_spam);
|
||||
folders.add(junk);
|
||||
|
||||
EntityFolder delete = new EntityFolder();
|
||||
delete.id = SWIPE_ACTION_DELETE;
|
||||
delete.name = context.getString(R.string.title_delete_permanently);
|
||||
folders.add(delete);
|
||||
|
||||
return folders;
|
||||
}
|
||||
|
||||
private class CheckResult {
|
||||
EntityAccount account;
|
||||
List<EntityFolder> folders;
|
||||
|
|
|
@ -19,6 +19,9 @@ package eu.faircode.email;
|
|||
Copyright 2018-2020 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -32,6 +35,8 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
|
@ -39,11 +44,15 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FragmentOptionsBehavior extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private SwitchCompat swDoubleBack;
|
||||
private SwitchCompat swConversationActions;
|
||||
|
@ -54,6 +63,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
private SwitchCompat swAutoScroll;
|
||||
private SwitchCompat swQuickFilter;
|
||||
private SwitchCompat swQuickScroll;
|
||||
private Button btnSwipes;
|
||||
private SwitchCompat swDoubleTap;
|
||||
private SwitchCompat swSwipeNav;
|
||||
private SwitchCompat swVolumeNav;
|
||||
|
@ -101,6 +111,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
swAutoScroll = view.findViewById(R.id.swAutoScroll);
|
||||
swQuickFilter = view.findViewById(R.id.swQuickFilter);
|
||||
swQuickScroll = view.findViewById(R.id.swQuickScroll);
|
||||
btnSwipes = view.findViewById(R.id.btnSwipes);
|
||||
swDoubleTap = view.findViewById(R.id.swDoubleTap);
|
||||
swSwipeNav = view.findViewById(R.id.swSwipeNav);
|
||||
swVolumeNav = view.findViewById(R.id.swVolumeNav);
|
||||
|
@ -207,6 +218,13 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
}
|
||||
});
|
||||
|
||||
btnSwipes.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new FragmentDialogSwipes().show(getParentFragmentManager(), "setup:swipe");
|
||||
}
|
||||
});
|
||||
|
||||
swDoubleTap.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
|
@ -431,4 +449,109 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
|
||||
grpConversationActions.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
public static class FragmentDialogSwipes extends FragmentDialogBase {
|
||||
private Spinner spLeft;
|
||||
private Spinner spRight;
|
||||
private ArrayAdapter<EntityFolder> adapter;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_swipes, null);
|
||||
spLeft = dview.findViewById(R.id.spLeft);
|
||||
spRight = dview.findViewById(R.id.spRight);
|
||||
|
||||
adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<EntityFolder>());
|
||||
adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown);
|
||||
|
||||
spLeft.setAdapter(adapter);
|
||||
spRight.setAdapter(adapter);
|
||||
|
||||
List<EntityFolder> folders = FragmentAccount.getFolderActions(getContext());
|
||||
|
||||
EntityFolder trash = new EntityFolder();
|
||||
trash.id = 2L;
|
||||
trash.name = getString(R.string.title_trash);
|
||||
folders.add(1, trash);
|
||||
|
||||
EntityFolder archive = new EntityFolder();
|
||||
archive.id = 1L;
|
||||
archive.name = getString(R.string.title_archive);
|
||||
folders.add(1, archive);
|
||||
|
||||
adapter.addAll(folders);
|
||||
|
||||
spLeft.setSelection(2); // Trash
|
||||
spRight.setSelection(1); // Archive
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setView(dview)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EntityFolder left = (EntityFolder) spLeft.getSelectedItem();
|
||||
EntityFolder right = (EntityFolder) spRight.getSelectedItem();
|
||||
|
||||
final Context context = getContext();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("left", left == null ? 0 : left.id);
|
||||
args.putLong("right", right == null ? 0 : right.id);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
long left = args.getLong("left");
|
||||
long right = args.getLong("right");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
List<EntityAccount> accounts = db.account().getAccounts();
|
||||
for (EntityAccount account : accounts)
|
||||
if (account.protocol == EntityAccount.TYPE_IMAP)
|
||||
db.account().setAccountSwipes(
|
||||
account.id,
|
||||
getAction(context, left, account.id),
|
||||
getAction(context, right, account.id));
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Void data) {
|
||||
ToastEx.makeText(context, R.string.title_completed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
|
||||
private Long getAction(Context context, long selection, long account) {
|
||||
if (selection < 0)
|
||||
return selection;
|
||||
else if (selection == 0)
|
||||
return null;
|
||||
else {
|
||||
DB db = DB.getInstance(context);
|
||||
String type = (selection == 2 ? EntityFolder.TRASH : EntityFolder.ARCHIVE);
|
||||
EntityFolder archive = db.folder().getFolderByType(account, type);
|
||||
return (archive == null ? null : archive.id);
|
||||
}
|
||||
}
|
||||
}.execute(getContext(), getViewLifecycleOwner(), args, "dialog:swipe");
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="24dp"
|
||||
android:scrollbarStyle="outsideOverlay">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_advanced_swipe_actions"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvHint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_swipe_actions_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvTitle" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvLeft"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/title_account_left"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvHint" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spLeft"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
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="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvRight" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
|
@ -167,6 +167,17 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/swQuickFilter"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSwipes"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:tag="disable"
|
||||
android:text="@string/title_advanced_swipe_actions"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swQuickScroll" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvCaptionConversation"
|
||||
android:layout_width="0dp"
|
||||
|
@ -177,7 +188,7 @@
|
|||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/swQuickScroll" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnSwipes" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swDoubleTap"
|
||||
|
|
|
@ -519,6 +519,9 @@
|
|||
|
||||
<string name="title_advanced_never_favorite">Never favorite</string>
|
||||
|
||||
<string name="title_advanced_swipe_actions">Set swipe actions</string>
|
||||
<string name="title_advanced_swipe_actions_hint">This will set the swipe left and right action for all IMAP accounts</string>
|
||||
|
||||
<string name="title_select">Select …</string>
|
||||
<string name="title_identity_name">Your name</string>
|
||||
<string name="title_identity_email">Your email address</string>
|
||||
|
|
Loading…
Reference in New Issue