mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-04 08:08:16 +02:00
Added dialog to set swipe actions for all accounts
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user