From f90165ce715caca68a77f8a85287bcb1f9c34066 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 22 Oct 2018 08:33:11 +0000 Subject: [PATCH] Removed setting swipe targets --- .../eu/faircode/email/FragmentMessages.java | 122 ++---------------- app/src/main/res/layout/fragment_messages.xml | 7 - app/src/main/res/menu/menu_messages.xml | 5 - app/src/main/res/values/strings.xml | 3 - 4 files changed, 12 insertions(+), 125 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 373118fd..9caf97cc 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -36,7 +36,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; -import android.widget.PopupMenu; import android.widget.ProgressBar; import android.widget.TextView; @@ -45,12 +44,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import java.io.Serializable; -import java.text.Collator; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; -import java.util.Locale; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -75,7 +70,6 @@ public class FragmentMessages extends FragmentEx { private TextView tvSupport; private ImageButton ibHintSupport; private ImageButton ibHintActions; - private View popupAnchor; private TextView tvNoEmail; private RecyclerView rvMessage; private BottomNavigationView bottom_navigation; @@ -100,7 +94,6 @@ public class FragmentMessages extends FragmentEx { private int autoCount = 0; private boolean autoExpand = true; - private long swipeTarget = -1; private List expanded = new ArrayList<>(); private List headers = new ArrayList<>(); private List images = new ArrayList<>(); @@ -147,7 +140,6 @@ public class FragmentMessages extends FragmentEx { tvSupport = view.findViewById(R.id.tvSupport); ibHintSupport = view.findViewById(R.id.ibHintSupport); ibHintActions = view.findViewById(R.id.ibHintActions); - popupAnchor = view.findViewById(R.id.popupAnchor); tvNoEmail = view.findViewById(R.id.tvNoEmail); rvMessage = view.findViewById(R.id.rvFolder); bottom_navigation = view.findViewById(R.id.bottom_navigation); @@ -159,8 +151,6 @@ public class FragmentMessages extends FragmentEx { fab = view.findViewById(R.id.fab); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - if (folder >= 0) - swipeTarget = prefs.getLong("swipe." + folder, -1); // Wire controls @@ -277,9 +267,8 @@ public class FragmentMessages extends FragmentEx { if (dX > margin) { // Right swipe - Drawable d = getResources().getDrawable(swipeTarget < 0 - ? (inbox ? R.drawable.baseline_move_to_inbox_24 : R.drawable.baseline_archive_24) - : R.drawable.baseline_folder_24, + Drawable d = getResources().getDrawable( + inbox ? R.drawable.baseline_move_to_inbox_24 : R.drawable.baseline_archive_24, getContext().getTheme()); int padding = (itemView.getHeight() - d.getIntrinsicHeight()); d.setBounds( @@ -316,16 +305,13 @@ public class FragmentMessages extends FragmentEx { Bundle args = new Bundle(); args.putLong("id", message.id); - args.putLong("folder", folder); args.putBoolean("thread", viewType != AdapterMessage.ViewType.THREAD); args.putInt("direction", direction); - args.putLong("swipeTarget", swipeTarget); new SimpleTask() { @Override protected MessageTarget onLoad(Context context, Bundle args) { long id = args.getLong("id"); - long fid = args.getLong("folder"); boolean thread = args.getBoolean("thread"); int direction = args.getInt("direction"); @@ -339,21 +325,17 @@ public class FragmentMessages extends FragmentEx { EntityMessage message = db.message().getMessage(id); - if (fid < 0 || swipeTarget < 0 || direction == ItemTouchHelper.LEFT) { - EntityFolder folder = db.folder().getFolder(message.folder); - if (EntityFolder.ARCHIVE.equals(folder.type) || EntityFolder.TRASH.equals(folder.type)) + EntityFolder folder = db.folder().getFolder(message.folder); + if (EntityFolder.ARCHIVE.equals(folder.type) || EntityFolder.TRASH.equals(folder.type)) + target = db.folder().getFolderByType(message.account, EntityFolder.INBOX); + else { + if (direction == ItemTouchHelper.RIGHT) + target = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE); + if (direction == ItemTouchHelper.LEFT || target == null) + target = db.folder().getFolderByType(message.account, EntityFolder.TRASH); + if (target == null) target = db.folder().getFolderByType(message.account, EntityFolder.INBOX); - else { - if (direction == ItemTouchHelper.RIGHT) - target = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE); - else if (direction == ItemTouchHelper.LEFT) - target = db.folder().getFolderByType(message.account, EntityFolder.TRASH); - } - } else - target = db.folder().getFolder(swipeTarget); - - if (target == null || !target.account.equals((message.account))) - throw new IllegalArgumentException(getString(R.string.title_no_target)); + } result.target = target.name; result.display = (target.display == null ? target.name : target.display); @@ -521,7 +503,6 @@ public class FragmentMessages extends FragmentEx { super.onSaveInstanceState(outState); outState.putBoolean("autoExpand", autoExpand); outState.putInt("autoCount", autoCount); - outState.putLong("swipeTarget", swipeTarget); outState.putLongArray("expanded", Helper.toLongArray(expanded)); outState.putLongArray("headers", Helper.toLongArray(headers)); outState.putLongArray("images", Helper.toLongArray(images)); @@ -534,7 +515,6 @@ public class FragmentMessages extends FragmentEx { if (savedInstanceState != null) { autoExpand = savedInstanceState.getBoolean("autoExpand"); autoCount = savedInstanceState.getInt("autoCount"); - swipeTarget = savedInstanceState.getLong("swipeTarget"); expanded = Helper.fromLongArray(savedInstanceState.getLongArray("expanded")); headers = Helper.fromLongArray(savedInstanceState.getLongArray("headers")); images = Helper.fromLongArray(savedInstanceState.getLongArray("images")); @@ -711,7 +691,6 @@ public class FragmentMessages extends FragmentEx { menu.findItem(R.id.menu_sort_on).setVisible(TextUtils.isEmpty(search)); menu.findItem(R.id.menu_folders).setVisible(primary >= 0); menu.findItem(R.id.menu_folders).setIcon(connected ? R.drawable.baseline_folder_24 : R.drawable.baseline_folder_open_24); - menu.findItem(R.id.menu_swipe).setVisible(folder >= 0); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); String sort = prefs.getString("sort", "time"); @@ -754,10 +733,6 @@ public class FragmentMessages extends FragmentEx { loadMessages(); return true; - case R.id.menu_swipe: - onMenuSwipeTarget(); - return true; - default: return super.onOptionsItemSelected(item); } @@ -777,79 +752,6 @@ public class FragmentMessages extends FragmentEx { fragmentTransaction.commit(); } - private void onMenuSwipeTarget() { - Bundle args = new Bundle(); - args.putLong("folder", folder); - - new SimpleTask>() { - @Override - protected List onLoad(Context context, Bundle args) { - long fid = args.getLong("folder"); - - DB db = DB.getInstance(context); - EntityFolder folder = db.folder().getFolder(fid); - List folders = db.folder().getUserFolders(folder.account); - - final Collator collator = Collator.getInstance(Locale.getDefault()); - collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc - - Collections.sort(folders, new Comparator() { - @Override - public int compare(EntityFolder f1, EntityFolder f2) { - return collator.compare(f1.name, f2.name); - } - }); - - EntityFolder junk = db.folder().getFolderByType(folder.account, EntityFolder.JUNK); - if (junk != null && !junk.id.equals(fid)) - folders.add(0, junk); - - EntityFolder trash = db.folder().getFolderByType(folder.account, EntityFolder.TRASH); - if (trash != null && !trash.id.equals(fid)) - folders.add(0, trash); - - EntityFolder archive = db.folder().getFolderByType(folder.account, EntityFolder.ARCHIVE); - if (archive != null && !archive.id.equals(fid)) - folders.add(0, archive); - - EntityFolder sent = db.folder().getFolderByType(folder.account, EntityFolder.SENT); - if (sent != null && !sent.id.equals(fid)) - folders.add(0, sent); - - EntityFolder inbox = db.folder().getFolderByType(folder.account, EntityFolder.INBOX); - if (inbox != null && !inbox.id.equals(fid)) - folders.add(0, inbox); - - return folders; - } - - @Override - protected void onLoaded(final Bundle args, List folders) { - PopupMenu popupMenu = new PopupMenu(getContext(), popupAnchor); - - int order = 0; - for (EntityFolder folder : folders) { - String name = (folder.display == null - ? Helper.localizeFolderName(getContext(), folder.name) - : folder.display); - popupMenu.getMenu().add(Menu.NONE, folder.id.intValue(), order++, name); - } - - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(final MenuItem target) { - swipeTarget = target.getItemId(); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - prefs.edit().putLong("swipe." + folder, swipeTarget).apply(); - return true; - } - }); - - popupMenu.show(); - } - }.load(this, args); - } - private void loadMessages() { final DB db = DB.getInstance(getContext()); diff --git a/app/src/main/res/layout/fragment_messages.xml b/app/src/main/res/layout/fragment_messages.xml index 6052f715..b32b996d 100644 --- a/app/src/main/res/layout/fragment_messages.xml +++ b/app/src/main/res/layout/fragment_messages.xml @@ -93,13 +93,6 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvHintActions" /> - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 90ad02f3..4aa1186c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -127,7 +127,6 @@ Password missing No primary account or no drafts folder No primary account or no archive folder - Target folder not set or missing This provider does not support push messages. Reception of new messages can be delayed. IMAP UIDPLUS not supported, see the FAQ Delete this account permanently? @@ -234,8 +233,6 @@ Unread Starred - Set right swipe target - Previous Next