Added setting to search local

This commit is contained in:
M66B
2019-02-18 09:49:59 +00:00
parent f3aaeca24c
commit 459f084890
7 changed files with 57 additions and 35 deletions

View File

@@ -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();

View File

@@ -86,11 +86,6 @@ public interface DaoFolder {
" WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'")
LiveData<EntityFolder> livePrimaryDrafts();
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
" WHERE `primary` AND type = '" + EntityFolder.ARCHIVE + "'")
LiveData<EntityFolder> 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" +

View File

@@ -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);

View File

@@ -273,7 +273,6 @@ public class FragmentSetup extends FragmentBase {
db.account().liveSynchronizingAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
private boolean done = false;
private LiveData<EntityFolder> livePrimaryDrafts = null;
private LiveData<EntityFolder> livePrimaryArchive = null;
@Override
public void onChanged(@Nullable List<EntityAccount> 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<EntityFolder>() {
@Override
public void onChanged(EntityFolder drafts) {
tvNoPrimaryDrafts.setVisibility(done && drafts == null ? View.VISIBLE : View.GONE);
}
});
livePrimaryArchive.observe(getViewLifecycleOwner(), new Observer<EntityFolder>() {
@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

View File

@@ -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++) {