Hightlight partial search results

pull/215/head
M66B 6 months ago
parent 0d2ebeb133
commit a0fa0b487c

@ -2567,6 +2567,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
args.putBoolean("filter_archive", intent.getBooleanExtra("filter_archive", true));
args.putBoolean("found", found);
args.putString("searched", intent.getStringExtra("searched"));
args.putBoolean("searchedPartial", intent.getBooleanExtra("searchedPartial", false));
args.putBoolean("pinned", intent.getBooleanExtra("pinned", false));
args.putString("msgid", intent.getStringExtra("msgid"));

@ -210,6 +210,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private String type;
private boolean found;
private String searched;
private boolean searchedPartial;
private ViewType viewType;
private boolean compact;
private int zoom;
@ -3328,7 +3329,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
HtmlHelper.autoLink(document);
if (message.ui_found && found && !TextUtils.isEmpty(searched))
HtmlHelper.highlightSearched(context, document, searched);
HtmlHelper.highlightSearched(context, document, searched, searchedPartial);
boolean overview_mode = prefs.getBoolean("overview_mode", false);
HtmlHelper.setViewport(document, overview_mode);
@ -3357,7 +3358,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
HtmlHelper.autoLink(document);
if (message.ui_found && found && !TextUtils.isEmpty(searched))
HtmlHelper.highlightSearched(context, document, searched);
HtmlHelper.highlightSearched(context, document, searched, searchedPartial);
// Cleanup message
document = HtmlHelper.sanitizeView(context, document, show_images);
@ -4686,7 +4687,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
.putExtra("lpos", getAdapterPosition())
.putExtra("filter_archive", filter_archive)
.putExtra("found", viewType == ViewType.SEARCH)
.putExtra("searched", searched);
.putExtra("searched", searched)
.putExtra("searchedPartial", searchedPartial);
boolean doubletap = prefs.getBoolean("doubletap", false);
@ -8176,7 +8178,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
AdapterMessage(Fragment parentFragment,
String type, boolean found, String searched, ViewType viewType,
String type, boolean found, String searched, boolean searchedPartial, ViewType viewType,
boolean compact, int zoom, boolean large_buttons, String sort, boolean ascending,
boolean filter_duplicates, boolean filter_trash,
final IProperties properties) {
@ -8184,6 +8186,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.type = type;
this.found = found;
this.searched = searched;
this.searchedPartial = searchedPartial;
this.viewType = viewType;
this.compact = compact;
this.zoom = zoom;

@ -1283,6 +1283,10 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
return term;
}
boolean isPartial() {
return !this.fts;
}
String getTitle(Context context) {
List<String> flags = new ArrayList<>();
if (with_unseen)

@ -327,6 +327,7 @@ public class FragmentMessages extends FragmentBase
private boolean filter_archive;
private boolean found;
private String searched;
private boolean searchedPartial;
private boolean pinned;
private String msgid;
private BoundaryCallbackMessages.SearchCriteria criteria = null;
@ -471,11 +472,14 @@ public class FragmentMessages extends FragmentBase
filter_archive = args.getBoolean("filter_archive", true);
found = args.getBoolean("found", false);
searched = args.getString("searched");
searchedPartial = args.getBoolean("searchedPartial");
pinned = args.getBoolean("pinned", false);
msgid = args.getString("msgid");
criteria = (BoundaryCallbackMessages.SearchCriteria) args.getSerializable("criteria");
if (criteria != null)
if (criteria != null) {
searched = criteria.query;
searchedPartial = criteria.isPartial();
}
pane = args.getBoolean("pane", false);
primary = args.getLong("primary", -1);
connected = args.getBoolean("connected", false);
@ -1260,7 +1264,7 @@ public class FragmentMessages extends FragmentBase
filter_trash = false;
adapter = new AdapterMessage(
this, type, found, searched, viewType,
this, type, found, searched, searchedPartial, viewType,
compact, zoom, large_buttons, sort, ascending,
filter_duplicates, filter_trash,
iProperties);
@ -8082,6 +8086,7 @@ public class FragmentMessages extends FragmentBase
nargs.putInt("lpos", forward ^ reversed ? lpos + 1 : lpos - 1);
nargs.putBoolean("found", found);
nargs.putString("searched", searched);
nargs.putBoolean("searchedPartial", searchedPartial);
nargs.putBoolean("pane", pane);
nargs.putLong("primary", primary);
nargs.putBoolean("connected", connected);

@ -3199,7 +3199,7 @@ public class HtmlHelper {
return ssb;
}
static void highlightSearched(Context context, Document document, String query) {
static void highlightSearched(Context context, Document document, String query, boolean partial) {
try {
int color = Helper.resolveColor(context, R.attr.colorHighlight);
@ -3213,8 +3213,13 @@ public class HtmlHelper {
sb.append(Pattern.quote(w));
}
}
sb.insert(0, ".*?\\b(");
sb.append(")\\b.*?");
if (partial) {
sb.insert(0, ".*?(");
sb.append(").*?");
} else {
sb.insert(0, ".*?\\b(");
sb.append(")\\b.*?");
}
// TODO: match für for fur
Pattern p = Pattern.compile(sb.toString(), Pattern.DOTALL | Pattern.CASE_INSENSITIVE);

Loading…
Cancel
Save