mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 08:47:46 +00:00
Fixes #1346
This commit is contained in:
parent
cfe2dbca7b
commit
09e48fdc5c
@ -69,12 +69,7 @@ public class SearchToolbar extends LinearLayout {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
|
||||
Log.d("[ACL]", "IT'S NOT THIS ONE - Search text changed to: " + newText);
|
||||
|
||||
return onQueryTextSubmit(newText);
|
||||
}
|
||||
public boolean onQueryTextChange(String newText) { return onQueryTextSubmit(newText); }
|
||||
});
|
||||
|
||||
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||
|
@ -2066,11 +2066,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
|
||||
fun onSearchQueryUpdated(query: String) {
|
||||
Log.d("[ACL]", "1")
|
||||
searchViewModel.onQueryUpdated(query, viewModel.threadId)
|
||||
Log.d("[ACL]", "2")
|
||||
binding?.searchBottomBar?.showLoading()
|
||||
Log.d("[ACL]", "3")
|
||||
adapter.onSearchQueryUpdated(query)
|
||||
}
|
||||
|
||||
|
@ -269,9 +269,7 @@ class ConversationAdapter(
|
||||
}
|
||||
|
||||
fun onSearchQueryUpdated(query: String?) {
|
||||
Log.d("[ACL]", "4")
|
||||
this.searchQuery = query
|
||||
Log.d("[ACL]", "5")
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
|
@ -125,10 +125,6 @@ object ConversationMenuHelper {
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(query: String): Boolean {
|
||||
|
||||
// *** Crashes when searching for non-alphanumeric first char ***
|
||||
Log.d("[ACL]", "[ConversationMenuHelper] Query text changed to: $query")
|
||||
|
||||
context.onSearchQueryUpdated(query)
|
||||
return true
|
||||
}
|
||||
|
@ -116,11 +116,7 @@ public class SearchDatabase extends Database {
|
||||
public Cursor queryMessages(@NonNull String query) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String prefixQuery = adjustQuery(query);
|
||||
|
||||
int queryLimit = Math.min(query.length()*50,500);
|
||||
|
||||
Log.d("[ACL]", "[SearchDatabase] Query is:\n" + MESSAGES_QUERY);
|
||||
|
||||
Cursor cursor = db.rawQuery(MESSAGES_QUERY, new String[] { prefixQuery, prefixQuery, String.valueOf(queryLimit) });
|
||||
setNotifyConverationListListeners(cursor);
|
||||
return cursor;
|
||||
|
@ -293,10 +293,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
||||
}
|
||||
|
||||
val newData = contactResults + messageResults
|
||||
|
||||
|
||||
Log.d("[ACL]", "THIS IS THE GLOBAL SEARCH - Result query is: ${result.query}")
|
||||
|
||||
globalSearchAdapter.setNewData(result.query, newData)
|
||||
}
|
||||
}
|
||||
|
@ -124,28 +124,15 @@ public class SearchRepository {
|
||||
|
||||
public void query(@NonNull String query, long threadId, @NonNull Callback<CursorList<MessageResult>> callback) {
|
||||
if (TextUtils.isEmpty(query)) {
|
||||
Log.d("[ACL]", "Recognised empty query!");
|
||||
|
||||
callback.onResult(CursorList.emptyList());
|
||||
return;
|
||||
}
|
||||
else {
|
||||
Log.d("[ACL]", "Non-empty query is: " + query);
|
||||
}
|
||||
|
||||
executor.execute(() -> {
|
||||
|
||||
Log.d("[ACL]", "Hit query.execute!");
|
||||
|
||||
// If the search is for a single character and it was stripped by `sanitizeQuery` then abort
|
||||
// the search for an empty string to avoid SQLite error.
|
||||
// If the sanitized search query is empty or just contains a single space (" ") then abort
|
||||
// the search to prevent SQLite errors.
|
||||
String cleanQuery = sanitizeQuery(query);
|
||||
Log.d("[ACL]", "clean query is: \"" + cleanQuery + "\"");
|
||||
if (cleanQuery.isEmpty() || cleanQuery.equalsIgnoreCase(" "))
|
||||
{
|
||||
Log.d("[ACL]", "Aborting empty search query.");
|
||||
return;
|
||||
}
|
||||
if (cleanQuery.equalsIgnoreCase(" ") || cleanQuery.isEmpty()) { return; }
|
||||
|
||||
CursorList<MessageResult> messages = queryMessages(cleanQuery, threadId);
|
||||
callback.onResult(messages);
|
||||
@ -211,19 +198,12 @@ public class SearchRepository {
|
||||
}
|
||||
|
||||
private CursorList<MessageResult> queryMessages(@NonNull String query) {
|
||||
|
||||
Log.d("[ACL]", "[SearchRepository] Query is:\n" + query);
|
||||
|
||||
|
||||
Cursor messages = searchDatabase.queryMessages(query);
|
||||
return messages != null ? new CursorList<>(messages, new MessageModelBuilder(context))
|
||||
: CursorList.emptyList();
|
||||
}
|
||||
|
||||
private CursorList<MessageResult> queryMessages(@NonNull String query, long threadId) {
|
||||
|
||||
Log.d("[ACL]", "[SearchRepository] 6 - query is: " + query);
|
||||
|
||||
Cursor messages = searchDatabase.queryMessages(query, threadId);
|
||||
return messages != null ? new CursorList<>(messages, new MessageModelBuilder(context))
|
||||
: CursorList.emptyList();
|
||||
@ -237,11 +217,7 @@ public class SearchRepository {
|
||||
* However, if we replace the apostrophe with a space, then the query will find the match.
|
||||
*/
|
||||
private String sanitizeQuery(@NonNull String query) {
|
||||
|
||||
Log.d("[ACL]", "[SearchRepository] Hit sanitizeQuery - initial query is: " + query);
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < query.length(); i++) {
|
||||
char c = query.charAt(i);
|
||||
if (!BANNED_CHARACTERS.contains(c)) {
|
||||
@ -250,11 +226,7 @@ public class SearchRepository {
|
||||
out.append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
Log.d("[ACL]", "[SearchRepository] Hit sanitizeQuery - sanitized query is: " + out.toString());
|
||||
|
||||
// Querying for an empty string causes a crash so we'll que
|
||||
if (out.toString().length() > 0) { return out.toString(); } else { return " "; }
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private static class ContactModelBuilder implements CursorList.ModelBuilder<Contact> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user