From 559539dc3b29f7259e5f18edbf30e1c9f63f38f7 Mon Sep 17 00:00:00 2001 From: lisa-signal Date: Tue, 15 Jul 2025 14:52:16 -0400 Subject: [PATCH] Create search functionality for debug log page. --- .../logsubmit/SubmitDebugLogActivity.java | 141 ++++++++++-------- 1 file changed, 75 insertions(+), 66 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/logsubmit/SubmitDebugLogActivity.java b/app/src/main/java/org/thoughtcrime/securesms/logsubmit/SubmitDebugLogActivity.java index c8bb64582f..7736d87166 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/logsubmit/SubmitDebugLogActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/logsubmit/SubmitDebugLogActivity.java @@ -95,13 +95,12 @@ public class SubmitDebugLogActivity extends BaseActivity { SearchView.OnQueryTextListener queryListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { - viewModel.onQueryUpdated(query); return true; } @Override public boolean onQueryTextChange(String query) { - viewModel.onQueryUpdated(query); + onQueryChanged(query); return true; } }; @@ -116,7 +115,7 @@ public class SubmitDebugLogActivity extends BaseActivity { @Override public boolean onMenuItemActionCollapse(MenuItem item) { searchView.setOnQueryTextListener(null); - viewModel.onSearchClosed(); + onQueryChanged(""); return true; } }); @@ -173,55 +172,6 @@ public class SubmitDebugLogActivity extends BaseActivity { // } private void initWebView() { - StringBuilder body = new StringBuilder(); - - int backgroundColor = ContextCompat.getColor(this, R.color.signal_colorBackground); - int noneColor = ContextCompat.getColor(this, R.color.debuglog_color_none); - int verboseColor = ContextCompat.getColor(this, R.color.debuglog_color_verbose); - int debugColor = ContextCompat.getColor(this, R.color.debuglog_color_debug); - int infoColor = ContextCompat.getColor(this, R.color.debuglog_color_info); - int warningColor = ContextCompat.getColor(this, R.color.debuglog_color_warn); - int errorColor = ContextCompat.getColor(this, R.color.debuglog_color_error); - - String css = String.format(""" - - """, - intToCssHex(backgroundColor), - intToCssHex(noneColor), - intToCssHex(verboseColor), - intToCssHex(debugColor), - intToCssHex(infoColor), - intToCssHex(warningColor), - intToCssHex(errorColor) - ); - - String js = """ - - """; - - body.append(String.format("%s%s
", css, js)); - - String htmlContent = body.toString(); - - logWebView.loadDataWithBaseURL(null, htmlContent, "text/html", "UTF-8", null); - logWebView.getSettings().setBuiltInZoomControls(true); logWebView.getSettings().setDisplayZoomControls(false); logWebView.getSettings().setUseWideViewPort(true); @@ -279,6 +229,10 @@ public class SubmitDebugLogActivity extends BaseActivity { } private void presentLines(@NonNull List lines) { + if (!isPageLoaded) { + initWebView(); + } + if (progressCard != null && lines.size() > 0) { progressCard.setVisibility(View.GONE); @@ -286,11 +240,63 @@ public class SubmitDebugLogActivity extends BaseActivity { submitButton.setVisibility(View.VISIBLE); } - if (!isPageLoaded) { - initWebView(); - } + StringBuilder body = new StringBuilder(); - StringBuilder appendScript = new StringBuilder(); + int backgroundColor = ContextCompat.getColor(this, R.color.signal_colorBackground); + int noneColor = ContextCompat.getColor(this, R.color.debuglog_color_none); + int verboseColor = ContextCompat.getColor(this, R.color.debuglog_color_verbose); + int debugColor = ContextCompat.getColor(this, R.color.debuglog_color_debug); + int infoColor = ContextCompat.getColor(this, R.color.debuglog_color_info); + int warningColor = ContextCompat.getColor(this, R.color.debuglog_color_warn); + int errorColor = ContextCompat.getColor(this, R.color.debuglog_color_error); + + String css = String.format(""" + + """, + intToCssHex(backgroundColor), + intToCssHex(noneColor), + intToCssHex(verboseColor), + intToCssHex(debugColor), + intToCssHex(infoColor), + intToCssHex(warningColor), + intToCssHex(errorColor) + ); + + String js = """ + + """; + + body.append(String.format("%s%s
", css, js)); for (LogLine line : lines) { if (line == null) continue; @@ -305,17 +311,20 @@ public class SubmitDebugLogActivity extends BaseActivity { default -> "none"; }; - String script = String.format( - "appendLine(%s, %s);\n", - JSONObject.quote(newLine), - JSONObject.quote(lineClass) - ); - - appendScript.append(script); + body.append(String.format("
%s
", lineClass, newLine)); } - String scriptContent = appendScript.toString(); - logWebView.evaluateJavascript(scriptContent, null); + body.append("
"); + + String htmlContent = body.toString(); + + logWebView.loadDataWithBaseURL(null, htmlContent, "text/html", "UTF-8", null); + } + + private void onQueryChanged(String query) { + String script = String.format("filterLogLines(%s);\n", JSONObject.quote(query)); + + logWebView.evaluateJavascript(script, null); } private void presentMode(@NonNull SubmitDebugLogViewModel.Mode mode) { @@ -328,7 +337,7 @@ public class SubmitDebugLogActivity extends BaseActivity { // TODO [greyson][log] Not yet implemented // editMenuItem.setVisible(true); // doneMenuItem.setVisible(false); -// searchMenuItem.setVisible(true); + searchMenuItem.setVisible(true); break; case SUBMITTING: editBanner.setVisibility(View.GONE);