diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 7b12f3903c..4a00adb7f7 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -421,16 +421,18 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB db.message().resetSearch(); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + if (prefs.getBoolean("search_local", false)) + return null; + EntityFolder archive = db.folder().getPrimaryArchive(); - if (archive == null) - throw new IllegalArgumentException("No primary archive"); - return archive.id; + return (archive == null ? null : archive.id); } @Override protected void onExecuted(Bundle args, Long archive) { Bundle sargs = new Bundle(); - sargs.putLong("folder", archive); + sargs.putLong("folder", archive == null ? -1 : archive); sargs.putString("search", args.getString("search")); FragmentMessages fragment = new FragmentMessages(); diff --git a/app/src/main/java/eu/faircode/email/DaoFolder.java b/app/src/main/java/eu/faircode/email/DaoFolder.java index 5499de24f3..d90af0bb39 100644 --- a/app/src/main/java/eu/faircode/email/DaoFolder.java +++ b/app/src/main/java/eu/faircode/email/DaoFolder.java @@ -86,11 +86,6 @@ public interface DaoFolder { " WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'") LiveData livePrimaryDrafts(); - @Query("SELECT folder.* FROM folder" + - " JOIN account ON account.id = folder.account" + - " WHERE `primary` AND type = '" + EntityFolder.ARCHIVE + "'") - LiveData livePrimaryArchive(); - @Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" + ", COUNT(message.id) AS messages" + ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" + diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index a416259983..f6e2e0f344 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -97,6 +97,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O private SwitchCompat swAutoSend; private SwitchCompat swNotifyPreview; + private SwitchCompat swSearchLocal; private SwitchCompat swLight; private Button btnSound; @@ -117,7 +118,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O "unified", "date", "threading", "avatars", "identicons", "name_email", "preview", "addresses", "autoimages", "actionbar", "pull", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove", "autoresize", "sender", "autosend", - "notify_preview", "light", "sound", + "notify_preview", "search_local", "light", "sound", "updates", "debug", "first", "why", "last_update_check", "app_support", "message_swipe", "message_select", "folder_actions", "folder_sync", "edit_ref_confirmed", "show_html_confirmed", "show_images_confirmed" @@ -166,6 +167,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O swAutoSend = view.findViewById(R.id.swAutoSend); swNotifyPreview = view.findViewById(R.id.swNotifyPreview); + swSearchLocal = view.findViewById(R.id.swSearchLocal); swLight = view.findViewById(R.id.swLight); btnSound = view.findViewById(R.id.btnSound); @@ -450,6 +452,13 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O } }); + swSearchLocal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("search_local", checked).apply(); + } + }); + swLight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -584,6 +593,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O swAutoSend.setChecked(!prefs.getBoolean("autosend", false)); swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true)); + swSearchLocal.setChecked(prefs.getBoolean("search_local", false)); swLight.setChecked(prefs.getBoolean("light", false)); swUpdates.setChecked(prefs.getBoolean("updates", true)); swUpdates.setVisibility(Helper.isPlayStoreInstall(getContext()) ? View.GONE : View.VISIBLE); diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index 0e891b7510..913070380d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -273,7 +273,6 @@ public class FragmentSetup extends FragmentBase { db.account().liveSynchronizingAccounts().observe(getViewLifecycleOwner(), new Observer>() { private boolean done = false; private LiveData livePrimaryDrafts = null; - private LiveData livePrimaryArchive = null; @Override public void onChanged(@Nullable List accounts) { @@ -293,30 +292,12 @@ public class FragmentSetup extends FragmentBase { else livePrimaryDrafts.removeObservers(getViewLifecycleOwner()); - if (livePrimaryArchive == null) - livePrimaryArchive = db.folder().livePrimaryArchive(); - else - livePrimaryArchive.removeObservers(getViewLifecycleOwner()); - livePrimaryDrafts.observe(getViewLifecycleOwner(), new Observer() { @Override public void onChanged(EntityFolder drafts) { tvNoPrimaryDrafts.setVisibility(done && drafts == null ? View.VISIBLE : View.GONE); } }); - - livePrimaryArchive.observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(EntityFolder archive) { - PackageManager pm = getContext().getPackageManager(); - pm.setComponentEnabledSetting( - new ComponentName(getContext(), ActivitySearch.class), - archive == null - ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED - : PackageManager.COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP); - } - }); } }); @@ -329,6 +310,13 @@ public class FragmentSetup extends FragmentBase { tvIdentityDone.setCompoundDrawablesWithIntrinsicBounds(done ? check : null, null, null, null); } }); + + // Backward compatibility + PackageManager pm = getContext().getPackageManager(); + pm.setComponentEnabledSetting( + new ComponentName(getContext(), ActivitySearch.class), + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP); } @Override diff --git a/app/src/main/java/eu/faircode/email/ViewModelBrowse.java b/app/src/main/java/eu/faircode/email/ViewModelBrowse.java index 72c76c85b9..cbd040e6e8 100644 --- a/app/src/main/java/eu/faircode/email/ViewModelBrowse.java +++ b/app/src/main/java/eu/faircode/email/ViewModelBrowse.java @@ -97,7 +97,7 @@ public class ViewModelBrowse extends ViewModel { if (state.messages == null) { state.messages = db.message().getMessageIdsByFolder(state.fid); - Log.i("Messages=" + state.messages.size()); + Log.i("Boundary search folder=" + state.fid + " messages=" + state.messages.size()); } for (int i = state.local; i < state.messages.size() && local < state.pageSize; i++) { diff --git a/app/src/main/res/layout/fragment_options.xml b/app/src/main/res/layout/fragment_options.xml index 760d2beb43..5cd784a729 100644 --- a/app/src/main/res/layout/fragment_options.xml +++ b/app/src/main/res/layout/fragment_options.xml @@ -675,7 +675,7 @@ app:switchPadding="12dp" /> + app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewHint" /> + + + +