Allow direct server search

pull/207/head
M66B 3 years ago
parent 9c0b93ab82
commit 272bd16ec3

@ -321,6 +321,11 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
continue; continue;
} }
if (criteria.with_attachments) {
if (message.attachments == 0)
continue;
}
if (excluded.contains(message.folder)) if (excluded.contains(message.folder))
continue; continue;

@ -81,6 +81,7 @@ public class FragmentDialogSearch extends FragmentDialogBase {
boolean last_search_notes = prefs.getBoolean("last_search_notes", true); boolean last_search_notes = prefs.getBoolean("last_search_notes", true);
boolean last_search_trash = prefs.getBoolean("last_search_trash", true); boolean last_search_trash = prefs.getBoolean("last_search_trash", true);
boolean last_search_junk = prefs.getBoolean("last_search_junk", true); boolean last_search_junk = prefs.getBoolean("last_search_junk", true);
boolean last_search_device = prefs.getBoolean("last_search_device", true);
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_search, null); View dview = LayoutInflater.from(context).inflate(R.layout.dialog_search, null);
@ -120,6 +121,7 @@ public class FragmentDialogSearch extends FragmentDialogBase {
Button btnAfter = dview.findViewById(R.id.btnAfter); Button btnAfter = dview.findViewById(R.id.btnAfter);
TextView tvBefore = dview.findViewById(R.id.tvBefore); TextView tvBefore = dview.findViewById(R.id.tvBefore);
TextView tvAfter = dview.findViewById(R.id.tvAfter); TextView tvAfter = dview.findViewById(R.id.tvAfter);
CheckBox cbSearchDevice = dview.findViewById(R.id.cbSearchDevice);
Group grpMore = dview.findViewById(R.id.grpMore); Group grpMore = dview.findViewById(R.id.grpMore);
ibInfo.setOnClickListener(new View.OnClickListener() { ibInfo.setOnClickListener(new View.OnClickListener() {
@ -236,6 +238,7 @@ public class FragmentDialogSearch extends FragmentDialogBase {
cbHtml.setVisibility(View.GONE); cbHtml.setVisibility(View.GONE);
cbSearchTrash.setVisibility(View.GONE); cbSearchTrash.setVisibility(View.GONE);
cbSearchJunk.setVisibility(View.GONE); cbSearchJunk.setVisibility(View.GONE);
cbSearchDevice.setVisibility(View.GONE);
} else { } else {
ibMore.setImageLevel(0); ibMore.setImageLevel(0);
grpMore.setVisibility(View.VISIBLE); grpMore.setVisibility(View.VISIBLE);
@ -247,6 +250,8 @@ public class FragmentDialogSearch extends FragmentDialogBase {
cbSearchTrash.setVisibility(View.VISIBLE); cbSearchTrash.setVisibility(View.VISIBLE);
cbSearchJunk.setVisibility(View.VISIBLE); cbSearchJunk.setVisibility(View.VISIBLE);
} }
if (account > 0 && folder > 0)
cbSearchDevice.setVisibility(View.VISIBLE);
} }
} }
}; };
@ -258,10 +263,6 @@ public class FragmentDialogSearch extends FragmentDialogBase {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("last_fts", isChecked).apply(); prefs.edit().putBoolean("last_fts", isChecked).apply();
cbHeaders.setEnabled(!isChecked);
cbHtml.setEnabled(!isChecked);
cbAttachments.setEnabled(!isChecked);
spMessageSize.setEnabled(!isChecked);
} }
}); });
@ -352,6 +353,13 @@ public class FragmentDialogSearch extends FragmentDialogBase {
} }
}); });
cbSearchDevice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
prefs.edit().putBoolean("last_search_device", isChecked).apply();
}
});
ibMore.setImageLevel(1); ibMore.setImageLevel(1);
cbSearchIndex.setChecked(last_fts && fts && pro); cbSearchIndex.setChecked(last_fts && fts && pro);
cbSearchIndex.setEnabled(fts && pro); cbSearchIndex.setEnabled(fts && pro);
@ -363,16 +371,18 @@ public class FragmentDialogSearch extends FragmentDialogBase {
tvSearchTextUnsupported.setText(getString(R.string.title_search_text_unsupported, tvSearchTextUnsupported.setText(getString(R.string.title_search_text_unsupported,
"full text search not supported")); "full text search not supported"));
cbNotes.setChecked(last_search_notes); cbNotes.setChecked(last_search_notes);
tvAfter.setText(null);
tvBefore.setText(null);
cbSearchTrash.setChecked(last_search_trash); cbSearchTrash.setChecked(last_search_trash);
cbSearchJunk.setChecked(last_search_junk); cbSearchJunk.setChecked(last_search_junk);
tvAfter.setText(null);
tvBefore.setText(null);
cbSearchDevice.setChecked(last_search_device);
grpMore.setVisibility(View.GONE); grpMore.setVisibility(View.GONE);
cbHeaders.setVisibility(View.GONE); cbHeaders.setVisibility(View.GONE);
cbHtml.setVisibility(View.GONE); cbHtml.setVisibility(View.GONE);
cbSearchTrash.setVisibility(View.GONE); cbSearchTrash.setVisibility(View.GONE);
cbSearchJunk.setVisibility(View.GONE); cbSearchJunk.setVisibility(View.GONE);
cbSearchDevice.setVisibility(View.GONE);
final AlertDialog dialog = new AlertDialog.Builder(context) final AlertDialog dialog = new AlertDialog.Builder(context)
.setView(dview) .setView(dview)
@ -385,20 +395,20 @@ public class FragmentDialogSearch extends FragmentDialogBase {
if (TextUtils.isEmpty(criteria.query)) if (TextUtils.isEmpty(criteria.query))
criteria.query = null; criteria.query = null;
criteria.fts = cbSearchIndex.isChecked(); criteria.fts = (cbSearchIndex.isChecked() && cbSearchIndex.isEnabled());
criteria.in_senders = cbSenders.isChecked(); criteria.in_senders = cbSenders.isChecked();
criteria.in_recipients = cbRecipients.isChecked(); criteria.in_recipients = cbRecipients.isChecked();
criteria.in_subject = cbSubject.isChecked(); criteria.in_subject = cbSubject.isChecked();
criteria.in_keywords = cbKeywords.isChecked(); criteria.in_keywords = cbKeywords.isChecked();
criteria.in_message = cbMessage.isChecked(); criteria.in_message = cbMessage.isChecked();
criteria.in_notes = cbNotes.isChecked(); criteria.in_notes = cbNotes.isChecked();
criteria.in_headers = (!criteria.fts && cbHeaders.isChecked()); criteria.in_headers = cbHeaders.isChecked();
criteria.in_html = (!criteria.fts && cbHtml.isChecked()); criteria.in_html = cbHtml.isChecked();
criteria.with_unseen = cbUnseen.isChecked(); criteria.with_unseen = cbUnseen.isChecked();
criteria.with_flagged = cbFlagged.isChecked(); criteria.with_flagged = cbFlagged.isChecked();
criteria.with_hidden = cbHidden.isChecked(); criteria.with_hidden = cbHidden.isChecked();
criteria.with_encrypted = cbEncrypted.isChecked(); criteria.with_encrypted = cbEncrypted.isChecked();
criteria.with_attachments = (!criteria.fts && cbAttachments.isChecked()); criteria.with_attachments = cbAttachments.isChecked();
if (!criteria.fts) { if (!criteria.fts) {
int pos = spMessageSize.getSelectedItemPosition(); int pos = spMessageSize.getSelectedItemPosition();
@ -419,6 +429,8 @@ public class FragmentDialogSearch extends FragmentDialogBase {
if (before != null) if (before != null)
criteria.before = ((Calendar) before).getTimeInMillis(); criteria.before = ((Calendar) before).getTimeInMillis();
boolean device = (cbSearchDevice.isChecked() || account < 0 || folder < 0);
if (criteria.query != null) { if (criteria.query != null) {
List<String> searches = new ArrayList<>(); List<String> searches = new ArrayList<>();
for (int i = 1; i <= 3; i++) for (int i = 1; i <= 3; i++)
@ -471,7 +483,7 @@ public class FragmentDialogSearch extends FragmentDialogBase {
context, getViewLifecycleOwner(), getParentFragmentManager(), context, getViewLifecycleOwner(), getParentFragmentManager(),
account, account,
archive == null ? folder : archive.id, archive == null ? folder : archive.id,
archive != null, archive != null || !device,
criteria); criteria);
} }
@ -483,7 +495,9 @@ public class FragmentDialogSearch extends FragmentDialogBase {
else else
FragmentMessages.search( FragmentMessages.search(
context, getViewLifecycleOwner(), getParentFragmentManager(), context, getViewLifecycleOwner(), getParentFragmentManager(),
account, folder, false, criteria); account, folder,
!device,
criteria);
} }
}) })
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@ -513,9 +527,13 @@ public class FragmentDialogSearch extends FragmentDialogBase {
else if (id == R.id.ibNotes) else if (id == R.id.ibNotes)
criteria.with_notes = true; criteria.with_notes = true;
boolean device = (cbSearchDevice.isChecked() || account < 0 || folder < 0);
FragmentMessages.search( FragmentMessages.search(
context, getViewLifecycleOwner(), getParentFragmentManager(), context, getViewLifecycleOwner(), getParentFragmentManager(),
account, folder, false, criteria); account, folder,
!device,
criteria);
} }
}; };

@ -541,6 +541,17 @@
app:layout_constraintStart_toStartOf="@id/btnBefore" app:layout_constraintStart_toStartOf="@id/btnBefore"
app:layout_constraintTop_toBottomOf="@id/btnBefore" /> app:layout_constraintTop_toBottomOf="@id/btnBefore" />
<CheckBox
android:id="@+id/cbSearchDevice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_search_device_first"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvBefore" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpMore" android:id="@+id/grpMore"
android:layout_width="0dp" android:layout_width="0dp"

@ -1454,6 +1454,7 @@
<string name="title_search_in_junk">In spam</string> <string name="title_search_in_junk">In spam</string>
<string name="title_search_with_before">Before</string> <string name="title_search_with_before">Before</string>
<string name="title_search_with_after">After</string> <string name="title_search_with_after">After</string>
<string name="title_search_device_first">Search the device first</string>
<string name="title_search_flag_unseen">unread</string> <string name="title_search_flag_unseen">unread</string>
<string name="title_search_flag_flagged">starred</string> <string name="title_search_flag_flagged">starred</string>
<string name="title_search_flag_hidden">hidden</string> <string name="title_search_flag_hidden">hidden</string>

Loading…
Cancel
Save