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

ClearUrlModule: fix url decoder, added trademark.

VirusTotalModule: change layout for consistency.
General: renamed Setup to Modules
This commit is contained in:
TrianguloY 2021-09-02 20:17:49 +02:00
parent b847497144
commit 93bcde9137
9 changed files with 76 additions and 44 deletions

View File

@ -20,6 +20,7 @@ import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Iterator;
import java.util.regex.Matcher;
@ -172,14 +173,14 @@ class ClearUrlDialog extends AModuleDialog implements View.OnClickListener {
for (int i = 0; i < redirections.length(); i++) {
String redirection = redirections.getString(i);
Matcher matcher = Pattern.compile(redirection).matcher(cleared);
if (matcher.find()) {
if (matcher.find() && matcher.groupCount() >= 1) {
if (providerData.optBoolean("forceRedirection", false)) {
// maybe do something special?
append(R.string.mClear_forcedRedirection);
} else {
append(R.string.mClear_redirection);
}
cleared = URLDecoder.decode(matcher.group(1));
cleared = decodeURIComponent(matcher.group(1));
setColor(R.color.warning);
continue whileProvider;
}
@ -228,7 +229,7 @@ class ClearUrlDialog extends AModuleDialog implements View.OnClickListener {
}
}
}
} catch (JSONException e) {
} catch (JSONException | UnsupportedEncodingException e) {
e.printStackTrace();
append(R.string.mClear_error);
}
@ -244,6 +245,28 @@ class ClearUrlDialog extends AModuleDialog implements View.OnClickListener {
}
}
@Override
public void onClick(View v) {
// pressed the fix button
if (cleared != null) setUrl(cleared);
}
// ------------------- utils -------------------
/**
* Hopefully the same as javascript's decodeURIComponent
* Idea from https://stackoverflow.com/a/6926987, but using own implementation
*/
private static String decodeURIComponent(String text) throws UnsupportedEncodingException {
StringBuilder result = new StringBuilder();
String[] parts = text.split("\\+");
for (String part : parts) {
if (result.length() != 0) result.append('+');
result.append(URLDecoder.decode(part, "UTF-8"));
}
return result.toString();
}
/**
* Utility to append a line to the info textview, manages linebreaks
*/
@ -261,12 +284,6 @@ class ClearUrlDialog extends AModuleDialog implements View.OnClickListener {
info.setBackgroundColor(getActivity().getResources().getColor(color));
}
@Override
public void onClick(View v) {
// pressed the fix button
if (cleared != null) setUrl(cleared);
}
/**
* Reads a JSON file and returns its content
* From https://www.bezkoder.com/java-android-read-json-file-assets-gson/

View File

@ -5,8 +5,8 @@ import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import com.trianguloy.urlchecker.R;
@ -99,7 +99,7 @@ class VirusTotalConfig extends AModuleConfig implements TextWatcher {
class VirusTotalDialog extends AModuleDialog implements View.OnClickListener, View.OnLongClickListener {
private static final int RETRY_TIMEOUT = 5000;
private ImageButton btn_scan;
private Button btn_scan;
private TextView txt_result;
private boolean scanning = false;
@ -206,15 +206,15 @@ class VirusTotalDialog extends AModuleDialog implements View.OnClickListener, Vi
private void updateUI() {
if (scanning) {
// scanning in progress, show cancel
btn_scan.setImageResource(android.R.drawable.ic_menu_close_clear_cancel);
btn_scan.setText(R.string.mVT_cancel);
setResult(getActivity().getString(R.string.mVT_scanning), 0);
btn_scan.setEnabled(true);
} else {
// not a scanning in progress
btn_scan.setImageResource(android.R.drawable.ic_menu_search);
btn_scan.setText(R.string.mVT_scan);
if (result == null) {
// no result available, new url
setResult(getActivity().getString(R.string.mVT_scan), 0);
setResult(getActivity().getString(R.string.mVT_pressScan), 0);
btn_scan.setEnabled(true);
} else {
// result available

View File

@ -25,6 +25,15 @@
android:gravity="center"
android:text="@string/mVT_tm" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:linksClickable="true"
android:gravity="center"
android:text="@string/mClear_tm" />
<Button
android:id="@+id/btn_blog"
android:layout_width="wrap_content"

View File

@ -63,7 +63,7 @@
android:onClick="onClick"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:text="@string/a_setup" />
android:text="@string/a_modules" />
<Button
android:id="@+id/about"

View File

@ -5,11 +5,8 @@
android:orientation="vertical">
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:linksClickable="true"
android:text="@string/mClear_desc" />
<CheckBox
@ -23,4 +20,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mClear_toggleVerbose" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:linksClickable="true"
android:text="@string/mClear_tm" />
</LinearLayout>

View File

@ -1,20 +1,21 @@
<?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:layout_height="match_parent"
android:gravity="center_vertical">
<Button
android:id="@+id/fix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:text="@string/mClear_clear" />
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
android:layout_weight="1"
android:gravity="center_vertical" />
</LinearLayout>

View File

@ -6,14 +6,14 @@
<Button
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/mStatus_check" />
<TextView
android:id="@+id/info"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical" />

View File

@ -4,20 +4,18 @@
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:onClick="onClick" />
<ImageButton
<Button
android:id="@+id/scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:contentDescription="@string/mVT_scan"
android:onClick="onClick"
android:src="@android:drawable/ic_menu_search" />
android:text="@string/mVT_scan" />
<TextView
android:id="@+id/result"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical" />
</LinearLayout>

View File

@ -1,13 +1,13 @@
<resources>
<!-- main -->
<string name="app_name">Url checker</string>
<string name="txt_info">This app acts as an intermediate step towards opening url links. When you click on a link and choose this app to open it, it will show a dialog with some information about the link. Check the setup screen for the available modules and what they do.</string>
<string name="txt_info">This app acts as an intermediate step towards opening url links. When you click on a link and choose this app to open it, it will show a dialog with some information about the link. Press the module button below to see the available modules and what they do.</string>
<string name="txt_sample">Press the link below to test it:\nhttp://www.google.com/?ref=referrer</string>
<string name="a_setup">Setup</string>
<string name="a_modules">Modules</string>
<string name="a_about">About</string>
<!-- about -->
<string name="txt_about">"App created by TrianguloY."</string>
<string name="txt_about">App created by TrianguloY.</string>
<string name="btn_blog">TrianguloY\'s blog</string>
<string name="btn_openStore">Open Play Store</string>
<string name="btn_shareStore">Share App</string>
@ -73,7 +73,9 @@
<string name="mVT_desc">When this module is enabled you can scan the url using VirusTotal and check the report.\nA personal VirusTotal API key is needed for it to work, you can get one after registering for a free account here: https://www.virustotal.com/gui/join-us.</string>
<string name="mVT_apiKey">api key</string>
<string name="mVT_tm">VirusTotal™ is a trademark of Google, Inc.</string>
<string name="mVT_scan">Press to scan</string>
<string name="mVT_pressScan">Press to scan</string>
<string name="mVT_scan">Scan</string>
<string name="mVT_cancel">Cancel</string>
<string name="mVT_scanning">Scanning…</string>
<string name="mVT_goodUrl">None of the %d engines detected the url (as of date %s)</string>
<string name="mVT_warningUrl">Warning, %d/%d engines detected the url (as of date %s)</string>
@ -86,11 +88,12 @@
<string name="mD_ctabs">Show debug messages from the custom tabs service</string>
<string name="mHist_name">History</string>
<string name="mHist_desc">When the url is edited, either manually or by other modules, this module allows you to view and revert changes.</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>
<string name="mClear_name">Clear URL</string>
<string name="mClear_desc">This module uses the Clear URL data (https://docs.clearurls.xyz/latest/) to remove tracking elements from urls, and other referrers and useless parameters from the url. It also allows for offline url redirections.</string>
<string name="mClear_clear">Clear</string>
<string name="mClear_desc">This module removes tracking, referrer and other useless parameters from the url. It also allows for common offline url redirections.</string>
<string name="mClear_tm">Uses the Clear URL database (version Dec 25, 2020) from https://docs.clearurls.xyz/latest/specs/rules/</string>
<string name="mClear_clear">Apply</string>
<string name="mClear_matches">Matches %s</string>
<string name="mClear_blocked">- BLOCKED!</string>
<string name="mClear_exception">- ignored due to exception</string>
@ -102,6 +105,6 @@
<string name="mClear_noRules">Nothing found</string>
<string name="mClear_toggleReferral">Enable referral marketing (referral parameters won\'t be cleared)</string>
<string name="mClear_toggleVerbose">Enable verbose info for the matching process</string>
<string name="mClear_error">An error ocurred while checking rules</string>
<string name="mClear_error">An error occurred while checking rules</string>
</resources>