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

Update preferences logic of ClearURLs

This commit is contained in:
Pablo Ortigosa 2022-06-28 20:06:02 +01:00
parent efdfb7e086
commit 091d92c603
3 changed files with 69 additions and 12 deletions

View File

@ -1,9 +1,12 @@
package com.trianguloy.urlchecker.modules.list;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import com.trianguloy.urlchecker.R;
@ -46,6 +49,17 @@ public class ClearUrlModule extends AModuleData {
return new GenericPref.Bool("clearurl_auto", false);
}
static GenericPref.Str DATABASE_URL() {
return new GenericPref.Str("clearurl_databaseURL", "https://rules2.clearurls.xyz/data.minify.json");
}
static GenericPref.Str HASH_URL() {
return new GenericPref.Str("clearurl_hashURL", "https://rules2.clearurls.xyz/rules.minify.hash");
}
public static GenericPref.Bool HASH_PREF() {
return new GenericPref.Bool("clearurl_hash", true);
}
@Override
public String getId() {
return "clearUrl";
@ -72,12 +86,19 @@ class ClearUrlConfig extends AModuleConfig {
private final GenericPref.Bool referralPref = ClearUrlModule.REFERRAL_PREF();
private final GenericPref.Bool verbosePref = ClearUrlModule.VERBOSE_PREF();
private final GenericPref.Bool autoPref = ClearUrlModule.AUTO_PREF();
final GenericPref.Str databaseURL = ClearUrlModule.DATABASE_URL();
final GenericPref.Str hashURL = ClearUrlModule.HASH_URL();
private final GenericPref.Bool hashPref = ClearUrlModule.HASH_PREF();
private Button update;
public ClearUrlConfig(ConfigActivity activity) {
super(activity);
referralPref.init(activity);
verbosePref.init(activity);
autoPref.init(activity);
hashPref.init(activity);
databaseURL.init(activity);
hashURL.init(activity);
}
@Override
@ -95,6 +116,19 @@ class ClearUrlConfig extends AModuleConfig {
attach(views, R.id.referral, referralPref);
attach(views, R.id.verbose, verbosePref);
attach(views, R.id.auto, autoPref);
attach(views, R.id.checkHash, hashPref);
final EditText edit_database = textEditor(R.id.database_URL, databaseURL, views);
final EditText edit_hash = textEditor(R.id.hash_URL, hashURL, views);
update = views.findViewById(R.id.update);
update.setOnClickListener(v -> {
updateDatabase();
});
}
private void updateDatabase(){
// TODO
}
/**
@ -105,6 +139,31 @@ class ClearUrlConfig extends AModuleConfig {
chxbx.setChecked(config.get());
chxbx.setOnCheckedChangeListener((buttonView, isChecked) -> config.set(isChecked));
}
/**
* Initializes a text pref
*/
private EditText textEditor(int id, GenericPref.Str strPref, View views){
EditText res = (EditText) views.findViewById(id);
res.setText(strPref.get());
TextWatcher textWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
strPref.set(s.toString());
if (!canBeEnabled()) disable();
}
};
res.addTextChangedListener(textWatcher);
return res;
}
}
class ClearUrlDialog extends AModuleDialog implements View.OnClickListener {
@ -124,7 +183,7 @@ class ClearUrlDialog extends AModuleDialog implements View.OnClickListener {
public ClearUrlDialog(MainDialog dialog) {
super(dialog);
try {
data = new JSONObject(getJsonFromAssets(dialog, "data.minify.json")).getJSONObject("providers");
data = new JSONObject(getJsonFromAssets(dialog, getActivity().getString(R.string.mClear_database))).getJSONObject("providers");
} catch (JSONException | IOException e) {
e.printStackTrace();
}

View File

@ -33,12 +33,12 @@
android:text="@string/mClear_sourceDesc" />
<EditText
android:id="@+id/clear_source"
android:id="@+id/database_URL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:ems="10"
android:hint="@string/mClear_source"
android:hint="database_URL"
android:inputType="none|text" />
<TextView
@ -53,23 +53,22 @@
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkBox"
android:id="@+id/checkHash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
android:layout_height="wrap_content" />
<EditText
android:id="@+id/clear_hash"
android:id="@+id/hash_URL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:ems="10"
android:hint="@string/mClear_hash"
android:hint="hash_URL"
android:inputType="none|text" />
</LinearLayout>
<Button
android:id="@+id/clear_update"
android:id="@+id/update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mClear_update" />

View File

@ -98,10 +98,9 @@ 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_source">https://rules2.clearurls.xyz/data.minify.json</string>
<string name="mClear_hashDesc">URL of the hash of the source:</string>
<string name="mClear_hash">https://rules2.clearurls.xyz/rules.minify.hash</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_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>
<string name="mClear_matches">Matches %s</string>