0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-20 04:12:14 +02:00

Merge branch 'TrianguloY:master' into master

This commit is contained in:
Ilithy 2022-08-13 19:11:21 +02:00 committed by GitHub
commit 3e071ae670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 247 additions and 29 deletions

View File

@ -118,7 +118,6 @@ public class MainDialog extends Activity {
// add
final List<AModuleData> middleModules = ModuleManager.getModules(false, this);
for (AModuleData module : middleModules) {
if (ll_mods.getChildCount() != 0) addSeparator();
initializeModule(module);
}
}
@ -132,24 +131,35 @@ public class MainDialog extends Activity {
try {
// enabled, add
AModuleDialog module = moduleData.getDialog(this);
int layoutId = module.getLayoutId();
ViewGroup parent;
// set module block
if (moduleData.canBeDisabled()) {
// init decorations
View block = Inflater.inflate(R.layout.dialog_module, ll_mods, this);
final TextView title = block.findViewById(R.id.title);
title.setText(getString(R.string.dd, getString(moduleData.getName())));
parent = block.findViewById(R.id.mod);
} else {
// non-disable modules are considered internal and won't show decorations
parent = ll_mods;
View child = null;
// set content if required
if (layoutId >= 0) {
// separator if necessary
if (ll_mods.getChildCount() != 0) addSeparator();
ViewGroup parent;
// set module block
if (moduleData.canBeDisabled()) {
// init decorations
View block = Inflater.inflate(R.layout.dialog_module, ll_mods, this);
final TextView title = block.findViewById(R.id.title);
title.setText(getString(R.string.dd, getString(moduleData.getName())));
parent = block.findViewById(R.id.mod);
} else {
// non-disable modules are considered internal and won't show decorations
parent = ll_mods;
}
// set module content
child = Inflater.inflate(layoutId, parent, this);
}
// set module content
View child = Inflater.inflate(module.getLayoutId(), parent, this);
// init
module.onInitialize(child);
modules.add(module);
} catch (Exception e) {
// can't add module

View File

@ -1,5 +1,7 @@
package com.trianguloy.urlchecker.modules;
import android.app.Activity;
import com.trianguloy.urlchecker.activities.ConfigActivity;
import com.trianguloy.urlchecker.utilities.Fragment;
@ -38,4 +40,11 @@ public abstract class AModuleConfig implements Fragment {
if (activity != null) activity.disableModule(this);
}
/**
* Returns the config activity. Will be null when initialized with empty constructor
*/
public final Activity getActivity() {
return activity;
}
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import com.trianguloy.urlchecker.modules.list.ClearUrlModule;
import com.trianguloy.urlchecker.modules.list.DebugModule;
import com.trianguloy.urlchecker.modules.list.HistoryModule;
import com.trianguloy.urlchecker.modules.list.LogModule;
import com.trianguloy.urlchecker.modules.list.OpenModule;
import com.trianguloy.urlchecker.modules.list.PatternModule;
import com.trianguloy.urlchecker.modules.list.RemoveQueriesModule;
@ -26,6 +27,7 @@ public class ModuleManager {
static {
// TODO: auto-load with reflection?
modules.add(new LogModule());
modules.add(new TextInputModule());
modules.add(new HistoryModule());
@ -44,7 +46,7 @@ public class ModuleManager {
* User defined order of the modules
*/
public static GenericPref.LstStr ORDER_PREF() {
return new GenericPref.LstStr("order", Collections.emptyList());
return new GenericPref.LstStr("order", ";", Collections.emptyList());
}

View File

@ -0,0 +1,142 @@
package com.trianguloy.urlchecker.modules.list;
import android.app.AlertDialog;
import android.text.util.Linkify;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.trianguloy.urlchecker.R;
import com.trianguloy.urlchecker.activities.ConfigActivity;
import com.trianguloy.urlchecker.dialogs.MainDialog;
import com.trianguloy.urlchecker.modules.AModuleConfig;
import com.trianguloy.urlchecker.modules.AModuleData;
import com.trianguloy.urlchecker.modules.AModuleDialog;
import com.trianguloy.urlchecker.url.UrlData;
import com.trianguloy.urlchecker.utilities.GenericPref;
import java.util.Date;
/**
* A module that logs all urls that passes through it
*/
public class LogModule extends AModuleData {
public static GenericPref.Str LOG_DATA() {
return new GenericPref.Str("log_data", "");
}
@Override
public String getId() {
return "log";
}
@Override
public int getName() {
return R.string.mLog_name;
}
@Override
public AModuleDialog getDialog(MainDialog cntx) {
return new LogDialog(cntx);
}
@Override
public AModuleConfig getConfig(ConfigActivity cntx) {
return new LogConfig(cntx);
}
}
class LogDialog extends AModuleDialog {
private final GenericPref.Str log = LogModule.LOG_DATA();
public LogDialog(MainDialog dialog) {
super(dialog);
log.init(dialog);
}
@Override
public int getLayoutId() {
return -1;
}
@Override
public void onInitialize(View views) {
// new instance, log date
log.add((log.get().isEmpty() ? "" : "\n")
+ "--- " + new Date().toLocaleString() + " ---\n"
);
}
@Override
public void onNewUrl(UrlData urlData) {
// new url, log it
log.add("> " + urlData.url + "\n");
}
}
class LogConfig extends AModuleConfig {
private final GenericPref.Str log = LogModule.LOG_DATA();
public LogConfig(ConfigActivity activity) {
super(activity);
log.init(activity);
}
@Override
public boolean canBeEnabled() {
return true;
}
@Override
public int getLayoutId() {
return R.layout.config_log;
}
@Override
public void onInitialize(View views) {
views.findViewById(R.id.view).setOnClickListener(v -> showLog(false));
views.findViewById(R.id.edit).setOnClickListener(v -> showLog(true));
}
/**
* Display the log, editable or clickable
*/
public void showLog(boolean editable) {
// init textview and content
// on editable: an editText
// on non-editable: a textview with links
TextView content = editable ? new EditText(getActivity()) : new TextView(getActivity());
content.setText(
!log.get().isEmpty() ? log.get()
: editable ? ""
: getActivity().getString(R.string.mLog_empty)
);
if (!editable) Linkify.addLinks(content, Linkify.WEB_URLS);
int pad = getActivity().getResources().getDimensionPixelSize(R.dimen.smallPadding);
content.setPadding(pad, pad, pad, pad);
// common dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.mLog_name)
.setView(content)
.setNegativeButton(R.string.close, null);
if (editable) {
// editable: add save and clear buttons
builder = builder
.setPositiveButton(R.string.save, (dialog, which) ->
log.set(content.getText().toString())
)
.setNeutralButton(R.string.clear, (dialog, which) ->
log.set("")
);
}
// show
builder.show();
}
}

View File

@ -146,6 +146,13 @@ public abstract class GenericPref<T> {
prefs.edit().putString(prefName, value).apply();
}
/**
* Adds the value to the existing content
*/
public void add(String value) {
set(get() + value);
}
/**
* This editText will be set to the pref value, and when the editText changes the value will too
*/
@ -174,10 +181,11 @@ public abstract class GenericPref<T> {
*/
static public class LstStr extends GenericPref<List<String>> {
static final String SEPARATOR = ";";
final String separator;
public LstStr(String prefName, List<String> defaultValue) {
public LstStr(String prefName, String separator, List<String> defaultValue) {
super(prefName, defaultValue);
this.separator = separator;
}
@Override
@ -190,18 +198,18 @@ public abstract class GenericPref<T> {
prefs.edit().putString(prefName, join(value)).apply();
}
private static String join(List<String> value) {
private String join(List<String> value) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < value.size(); i++) {
if (i != 0) sb.append(SEPARATOR);
if (i != 0) sb.append(separator);
sb.append(value.get(i));
}
return sb.toString();
}
private static List<String> split(String value) {
private List<String> split(String value) {
ArrayList<String> list = new ArrayList<>();
if (value != null) list.addAll(Arrays.asList(value.split(SEPARATOR)));
if (value != null) list.addAll(Arrays.asList(value.split(separator)));
return list;
}
}

View File

@ -3,8 +3,6 @@
android:color="@color/transparent">
<item
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp">
<shape android:shape="rectangle">
<corners android:radius="10dp" />

View File

@ -2,7 +2,6 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="5dp"
android:left="5dp"
android:top="5dp"
android:drawable="?android:attr/selectableItemBackground" />
</layer-list>

View File

@ -5,8 +5,7 @@
<!-- Normal button -->
<item
android:bottom="7dp"
android:right="7dp"
android:left="5dp"
android:right="2dp"
android:top="7dp">
<shape android:shape="rectangle">
<corners

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mLog_desc" /><LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/view"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/mLog_view" /><Button
android:id="@+id/edit"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/mLog_edit" /></LinearLayout></LinearLayout>

View File

@ -24,8 +24,12 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/open_left"
android:minHeight="60dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/mOpen_open"
android:textColor="?android:attr/colorBackground" />
android:textColor="?android:attr/colorBackground"
android:textStyle="bold" />
<ImageButton
android:id="@+id/open_with"

View File

@ -26,6 +26,8 @@ Traducciones: Tiago Carmo, Ilithy, Idris, Metezd."</string>
<string name="toast_invalid">Invalido</string>
<string name="save">Guardar</string>
<string name="reset">Reiniciar</string>
<string name="close">Cerrar</string>
<string name="clear">Borrar</string>
<string name="json_desc">[Funcionalidad beta] Este es un editor avanzado, el contenido debe ser JSON válido. Puedes pulsar el botón de arriba a la derecha para formatearlo y validarlo.</string>
<string name="json_edit">Editor avanzado</string>
@ -37,7 +39,8 @@ Traducciones: Tiago Carmo, Ilithy, Idris, Metezd."</string>
* Carácteres no-ascii, como letras griegas. Pueden ser usadas para phising: googĺe.com vs google.com
* Enlaces http, deberías usar https
* Enlaces sin esquema http(s)"</string>
<string name="mPttrn_fix">Arreglar</string>
<string name="mPttrn_fix">Aplicar</string>
<string name="mPttrn_fixed">Aplicado - %s</string>
<string name="mPttrn_ascii">¡Aviso! Carácteres no-ascii encontrados</string>
<string name="mPttrn_http">Enlace http, considera usar https</string>
<string name="mPttrn_noSchemeHttp">Falta esquema http.</string>
@ -161,4 +164,12 @@ Púlsa el botón para borrarlos todos o la flecha para ir uno a uno.
<string name="mRemove_one">Eliminar %s</string>
<string name="mRemove_empty">Eliminar vacío</string>
<string name="mLog_name">Registro (log)</string>
<string name="mLog_desc">"Este módulo registra todas las urls que aparecen, se recomienda que sea el primero de la lista (en caso contrario algunas redirecciones automáticas puede que no se guarden).
El log puede verse y editarse aquí, no se mostrará nada en la ventana principal.
Para deshabilitar el registro, deshabilita el módulo."</string>
<string name="mLog_view">View log</string>
<string name="mLog_edit">Edit log</string>
<string name="mLog_empty">No data</string>
</resources>

View File

@ -26,6 +26,8 @@ Translations: Tiago Carmo, Ilithy, Idris, Metezd."</string>
<string name="toast_invalid">Invalid</string>
<string name="save">Save</string>
<string name="reset">Reset</string>
<string name="close">Close</string>
<string name="clear">Clear</string>
<string name="json_desc">[Beta feature] This is an advanced editor, the content must be formatted into valid JSON. You can press the top-right button to format and validate it.</string>
<string name="json_edit">Advanced editor</string>
@ -162,4 +164,12 @@ Thanks to PabloOQ for the idea and original implementation!"</string>
<string name="mRemove_one">Remove %s</string>
<string name="mRemove_empty">Remove empty</string>
<string name="mLog_name">Log</string>
<string name="mLog_desc">"This module registers all urls that appear, it is recommended that it is the first module in the list (otherwise automatic redirections may not be logged).
You can view or clear the log here, no visual indication will appear on the main dialog.
To disable logging, just disable the module."</string>
<string name="mLog_view">View log</string>
<string name="mLog_edit">Edit log</string>
<string name="mLog_empty">No data</string>
</resources>