From d63b7036747143b1eda760bf595f657c5d56228c Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 16 Nov 2019 12:53:36 +0100 Subject: [PATCH] Search improvements --- .../java/eu/faircode/email/ActivityView.java | 5 +- .../eu/faircode/email/AdapterMessage.java | 1 + .../eu/faircode/email/FragmentAccounts.java | 2 +- .../eu/faircode/email/FragmentFolders.java | 2 +- .../eu/faircode/email/FragmentMessages.java | 120 ++++++++++-------- app/src/main/res/values/strings.xml | 2 + 6 files changed, 77 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 8d9d9fefdc..f102b13018 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -820,7 +820,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB searching = true; FragmentMessages.search( ActivityView.this, ActivityView.this, getSupportFragmentManager(), - -1, false, search); + -1, -1, false, search); } intent.removeExtra(Intent.EXTRA_PROCESS_TEXT); @@ -1040,11 +1040,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void onSearchMessages(Intent intent) { + long account = intent.getLongExtra("account", -1); long folder = intent.getLongExtra("folder", -1); String query = intent.getStringExtra("query"); FragmentMessages.search( this, this, getSupportFragmentManager(), - folder, false, query); + account, folder, false, query); } private void onViewThread(Intent intent) { diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 9c3e820d01..87c9794889 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -2304,6 +2304,7 @@ public class AdapterMessage extends RecyclerView.Adapter>() { - @Override - protected List onExecute(Context context, Bundle args) { - Map> result = new LinkedHashMap<>(); + new SimpleTask>() { + @Override + protected List onExecute(Context context, Bundle args) { + long aid = args.getLong("account"); - DB db = DB.getInstance(context); - return db.account().getSynchronizingAccounts(); + List result = new ArrayList<>(); + DB db = DB.getInstance(context); + if (aid < 0) { + List accounts = db.account().getSynchronizingAccounts(); + for (EntityAccount account : accounts) + if (!account.pop) + result.add(account); + } else { + EntityAccount account = db.account().getAccount(aid); + if (account != null && !account.pop) + result.add(account); } - @Override - protected void onExecuted(Bundle args, List accounts) { - PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabSearch); + if (result.size() == 0) + throw new IllegalArgumentException(context.getString(R.string.title_no_search)); + else + return result; + } - popupMenu.getMenu().add(Menu.NONE, 0, 0, R.string.title_search_server).setEnabled(false); + @Override + protected void onExecuted(Bundle args, List accounts) { + PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabSearch); - int order = 1; - for (EntityAccount account : accounts) - if (!account.pop) - popupMenu.getMenu().add(Menu.NONE, 0, order++, account.name) - .setIntent(new Intent().putExtra("account", account.id)); - - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem target) { - Intent intent = target.getIntent(); - if (intent == null) - return false; - - Bundle args = new Bundle(); - args.putString("title", getString(R.string.title_search_in)); - args.putLong("account", intent.getLongExtra("account", -1)); - args.putLongArray("disabled", new long[]{}); - args.putString("query", query); - - FragmentDialogFolder fragment = new FragmentDialogFolder(); - fragment.setArguments(args); - fragment.setTargetFragment(FragmentMessages.this, FragmentMessages.REQUEST_SEARCH); - fragment.show(getParentFragmentManager(), "messages:search"); - - return true; - } - }); + popupMenu.getMenu().add(Menu.NONE, 0, 0, R.string.title_search_server).setEnabled(false); - popupMenu.show(); - } + int order = 1; + for (EntityAccount account : accounts) + popupMenu.getMenu().add(Menu.NONE, 0, order++, account.name) + .setIntent(new Intent().putExtra("account", account.id)); - @Override - protected void onException(Bundle args, Throwable ex) { + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem target) { + Intent intent = target.getIntent(); + if (intent == null) + return false; + + Bundle args = new Bundle(); + args.putString("title", getString(R.string.title_search_in)); + args.putLong("account", intent.getLongExtra("account", -1)); + args.putLongArray("disabled", new long[]{}); + args.putString("query", query); + + FragmentDialogFolder fragment = new FragmentDialogFolder(); + fragment.setArguments(args); + fragment.setTargetFragment(FragmentMessages.this, FragmentMessages.REQUEST_SEARCH); + fragment.show(getParentFragmentManager(), "messages:search"); + + return true; + } + }); + + popupMenu.show(); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + if (ex instanceof IllegalArgumentException) + ToastEx.makeText(getContext(), ex.getMessage(), Toast.LENGTH_LONG).show(); + else Helper.unexpectedError(getParentFragmentManager(), ex); - } - }.execute(FragmentMessages.this, args, "messages:search"); - } else - search(getContext(), getViewLifecycleOwner(), getParentFragmentManager(), folder, true, query); + } + }.execute(FragmentMessages.this, args, "messages:search"); } }); @@ -2682,7 +2696,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. public void onSearch(String query) { FragmentMessages.search( getContext(), getViewLifecycleOwner(), getParentFragmentManager(), - folder, false, query); + account, folder, false, query); } }); @@ -3920,7 +3934,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. Bundle args = data.getBundleExtra("args"); search( getContext(), getViewLifecycleOwner(), getParentFragmentManager(), - args.getLong("folder"), true, args.getString("query")); + args.getLong("account"), + args.getLong("folder"), + true, + args.getString("query")); } break; case REQUEST_ACCOUNT: @@ -4725,7 +4742,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. static void search( final Context context, final LifecycleOwner owner, final FragmentManager manager, - long folder, boolean server, String query) { + long account, long folder, boolean server, String query) { if (server && !ActivityBilling.isPro(context)) { context.startActivity(new Intent(context, ActivityBilling.class)); return; @@ -4735,6 +4752,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. manager.popBackStack("search", FragmentManager.POP_BACK_STACK_INCLUSIVE); Bundle args = new Bundle(); + args.putLong("account", account); args.putLong("folder", folder); args.putBoolean("server", server); args.putString("query", query); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 75e929e099..2428640481 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -604,6 +604,7 @@ Folder does not exist The originally received message will be included Image could not be decoded + Search on server is not available for this account Unused inline images will be removed on save/send Messages moved across accounts will be downloaded again resulting in extra data usage Raw message saved @@ -1071,6 +1072,7 @@ Extra large + 1080 1440