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

Added custom database preference

Update GUI of ClearURLs

No need to have an option to remove the custom database if the user can choose which one to use
This commit is contained in:
Pablo Ortigosa 2022-07-02 00:04:03 +01:00
parent 5b7e56d7ff
commit 918ffb4014
3 changed files with 45 additions and 14 deletions

View File

@ -41,7 +41,6 @@ import java.util.regex.Pattern;
/**
* This module clears the url using the ClearUrl database (an asset copy)
* TODO: add option to delete custom database?
*/
public class ClearUrlModule extends AModuleData {
@ -68,6 +67,10 @@ public class ClearUrlModule extends AModuleData {
return new GenericPref.Bool("clearurl_hash", true);
}
public static GenericPref.Bool CUSTOM_PREF() {
return new GenericPref.Bool("clearurl_custom", false);
}
@Override
public String getId() {
return "clearUrl";
@ -97,6 +100,7 @@ class ClearUrlConfig extends AModuleConfig {
final GenericPref.Str databaseURL = ClearUrlModule.DATABASE_URL();
final GenericPref.Str hashURL = ClearUrlModule.HASH_URL();
private final GenericPref.Bool hashPref = ClearUrlModule.HASH_PREF();
private final GenericPref.Bool customPref = ClearUrlModule.CUSTOM_PREF();
private Button update;
private volatile boolean downloading = false;
@ -108,6 +112,7 @@ class ClearUrlConfig extends AModuleConfig {
hashPref.init(activity);
databaseURL.init(activity);
hashURL.init(activity);
customPref.init(activity);
}
@Override
@ -126,6 +131,7 @@ class ClearUrlConfig extends AModuleConfig {
attach(views, R.id.verbose, verbosePref);
attach(views, R.id.auto, autoPref);
attach(views, R.id.checkHash, hashPref);
attach(views, R.id.customDB, customPref);
textEditor(R.id.database_URL, databaseURL, views);
textEditor(R.id.hash_URL, hashURL, views);
@ -259,6 +265,7 @@ class ClearUrlDialog extends AModuleDialog implements View.OnClickListener {
private final GenericPref.Bool allowReferral = ClearUrlModule.REFERRAL_PREF();
private final GenericPref.Bool verbose = ClearUrlModule.VERBOSE_PREF();
private final GenericPref.Bool auto = ClearUrlModule.AUTO_PREF();
private final GenericPref.Bool customPref = ClearUrlModule.CUSTOM_PREF();
private JSONObject data = null;
private TextView info;
@ -268,21 +275,31 @@ class ClearUrlDialog extends AModuleDialog implements View.OnClickListener {
public ClearUrlDialog(MainDialog dialog) {
super(dialog);
try {
// TODO fall back if file is downloading?
data = new JSONObject(getJsonFromStorage(dialog, getActivity().getString(R.string.mClear_database))).getJSONObject("providers");
} catch (Exception ignore) {
// FIXME warn user
// downloaded database failed, falling back to bundled database
allowReferral.init(dialog);
verbose.init(dialog);
auto.init(dialog);
customPref.init(dialog);
boolean error = false;
if (customPref.get()) {
// use custom database
try {
// TODO fall back if file is downloading?
data = new JSONObject(getJsonFromStorage(dialog, getActivity().getString(R.string.mClear_database))).getJSONObject("providers");
} catch (Exception ignore) {
// TODO warn user
// downloaded database failed, falling back to built-in database
error = true;
}
}
if (!customPref.get() || error) {
// use built-in database
try {
data = new JSONObject(getJsonFromAssets(dialog, getActivity().getString(R.string.mClear_database))).getJSONObject("providers");
} catch (JSONException | IOException e) {
e.printStackTrace();
}
}
allowReferral.init(dialog);
verbose.init(dialog);
auto.init(dialog);
}

View File

@ -26,6 +26,18 @@
android:layout_height="wrap_content"
android:text="@string/mClear_toggleVerbose" />
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mClear_customDBdesc" />
<CheckBox
android:id="@+id/customDB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mClear_customDB" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
@ -71,7 +83,7 @@
android:id="@+id/update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mClear_update" />
android:text="@string/mClear_download" />
<TextView
android:layout_width="match_parent"

View File

@ -97,9 +97,11 @@ This module can\'t be disabled."</string>
<string name="mClear_name">Clear URL</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_sourceDesc">URL of the database JSON file with the rules:</string>
<string name="mClear_hashDesc">URL of the hash of the source, can be ignored if the checkbox is deactivated:</string>
<string name="mClear_update">Update</string>
<string name="mClear_customDBdesc">By default the app uses a built-in database, but you can download a new one and use that instead. The default values of the urls are the source of the built-in database, so it can be used to download a newer version as a custom database, a hash (SHA256) can be used to ensure a correct download.</string>
<string name="mClear_customDB">Use custom database</string>
<string name="mClear_sourceDesc">URL of the custom database JSON file with the rules:</string>
<string name="mClear_hashDesc">URL of the hash of the custom database, can be ignored if the checkbox is disabled:</string>
<string name="mClear_download">Download</string>
<string name="mClear_database">data.minify.json</string>
<string name="mClear_tm">Uses the Clear URL database from https://docs.clearurls.xyz/latest/specs/rules/</string>
<string name="mClear_clear">Apply</string>