0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 11:52:14 +02:00

show debug data only when requested

This commit is contained in:
TrianguloY 2024-05-19 20:45:01 +02:00
parent 85231c5a58
commit 95a264f3ef
4 changed files with 46 additions and 35 deletions

View File

@ -3,6 +3,7 @@ package com.trianguloy.urlchecker.modules.list;
import static java.util.Objects.requireNonNullElse;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.trianguloy.urlchecker.R;
@ -22,7 +23,6 @@ import java.util.List;
/**
* This modules marks the insertion point of new modules
* If enabled, shows a textview with debug info.
* Currently shows the original intent (as uri)
* Allows also to enable/disable ctabs toasts
*/
public class DebugModule extends AModuleData {
@ -57,11 +57,9 @@ public class DebugModule extends AModuleData {
class DebugDialog extends AModuleDialog {
public static final String SEPARATOR = "";
private TextView textView;
// cached
private String intentUri;
private String referrer;
private Button showData;
private TextView data;
private UrlData urlData;
public DebugDialog(MainDialog dialog) {
super(dialog);
@ -74,29 +72,24 @@ class DebugDialog extends AModuleDialog {
@Override
public void onInitialize(View views) {
textView = views.findViewById(R.id.data);
showData = views.findViewById(R.id.showData);
data = views.findViewById(R.id.data);
// expand when touched (not only clicked, to avoid a double-click-required bug and because it feels better)
textView.setOnTouchListener((v, event) -> {
if (textView.getMaxHeight() != Integer.MAX_VALUE) textView.setMaxHeight(Integer.MAX_VALUE);
return false;
});
// cached values
intentUri = getActivity().getIntent().toUri(0);
referrer = requireNonNullElse(AndroidUtils.getReferrer(getActivity()), "null");
showData.setOnClickListener(v -> showData());
}
@Override
public void onDisplayUrl(UrlData urlData) {
// collapse module to show exactly 5 lines and a half (to indicate there is more data)
var fontMetrics = textView.getPaint().getFontMetrics();
textView.setMaxHeight(Math.round((fontMetrics.bottom - fontMetrics.top) * 5.5f));
private void showData() {
showData.setVisibility(View.GONE);
data.setVisibility(View.VISIBLE);
// data to display
textView.setText(String.join("\n", List.of(
data.setText(String.join("\n", List.of(
"Intent:",
intentUri,
getActivity().getIntent().toUri(0),
SEPARATOR,
"queryIntentActivityOptions:",
IntentApp.getOtherPackages(UrlUtils.getViewIntent(urlData.url, null), getActivity()).toString(),
SEPARATOR,
@ -111,14 +104,20 @@ class DebugDialog extends AModuleDialog {
SEPARATOR,
"Referrer:",
referrer,
SEPARATOR,
"queryIntentActivityOptions:",
IntentApp.getOtherPackages(UrlUtils.getViewIntent(urlData.url, null), getActivity()).toString()
requireNonNullElse(AndroidUtils.getReferrer(getActivity()), "null")
)));
}
@Override
public void onPrepareUrl(UrlData urlData) {
data.setVisibility(View.GONE);
showData.setVisibility(View.VISIBLE);
}
@Override
public void onDisplayUrl(UrlData urlData) {
this.urlData = urlData;
}
}
class DebugConfig extends AModuleConfig {

View File

@ -1,9 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/data"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="11sp">
android:orientation="vertical">
</TextView>
<Button
android:id="@+id/showData"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mD_show" />
<TextView
android:id="@+id/data"
android:textIsSelectable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -206,6 +206,7 @@ Hay algunos enlaces cuyo único propósito es redirigirte a otro enlace. Si el e
\n
\nPuede mantener pulsado para seleccionar el texto.</string>
<string name="mD_ctabs">Mostrar mensajes de debug del servicio custom tabs</string>
<string name="mD_show">Mostrar datos de debug</string>
<!-- -->
<string name="mHist_name">Historial</string>
<string name="mHist_desc">Cuando la URL cambia, tanto manualmente como por otros módulos, éste te permite ver y revertir los cambios.</string>

View File

@ -255,6 +255,7 @@ If you enable this it will display some internal debug data (like original inten
You can hold to select text."</string>
<string name="mD_ctabs">Show debug messages from the custom tabs service</string>
<string name="mD_show">Show debug data</string>
<!-- -->
<string name="mHist_name">History</string>
<string name="mHist_desc">When the URL is edited, either manually or by other modules, this one allows you to view and revert changes.</string>