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

Added info messages

This commit is contained in:
Pablo Ortigosa 2022-07-02 13:46:50 +01:00
parent ea2bf796e4
commit cce4323326
2 changed files with 20 additions and 12 deletions

View File

@ -8,6 +8,7 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.trianguloy.urlchecker.R;
import com.trianguloy.urlchecker.activities.ConfigActivity;
@ -154,7 +155,7 @@ class ClearUrlConfig extends AModuleConfig {
private void replaceDatabase(String fileName, String databaseSource, String hashSource, boolean checkHash, Context context){
// In case something fails, which can be: file writing, url reading, file download
int retries = 5;
for (int i = 0; i < retries; i++) {
for (int i = 1; i <= retries; i++) {
try (FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE)) {
String jsonString = readFromUrl(databaseSource);
JSONObject sourceJson = new JSONObject(jsonString);
@ -186,11 +187,14 @@ class ClearUrlConfig extends AModuleConfig {
}
fos.write(jsonString.getBytes(Charset.forName("UTF-8")));
break;
} catch (Exception e) {
e.printStackTrace();
} catch (Exception e){
if (i == retries) {
e.printStackTrace();
}
}
}
// FIXME inform user if it succeeded or not and why
// TODO inform user if it succeeded or not and why
downloading = false;
}
@ -281,27 +285,29 @@ class ClearUrlDialog extends AModuleDialog implements View.OnClickListener {
verbose.init(dialog);
auto.init(dialog);
custom.init(dialog);
boolean error = false;
if (custom.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;
// custom database load failed, falling back to built-in database
Toast.makeText(dialog, dialog.getString(R.string.mClear_customDBLoadError), Toast.LENGTH_LONG).show();
try {
data = new JSONObject(getJsonFromAssets(dialog, getActivity().getString(R.string.mClear_database))).getJSONObject("providers");
} catch (JSONException | IOException e) {
e.printStackTrace();
}
}
}
if (!custom.get() || error) {
// use built-in database
}else{
try {
data = new JSONObject(getJsonFromAssets(dialog, getActivity().getString(R.string.mClear_database))).getJSONObject("providers");
} catch (JSONException | IOException e) {
e.printStackTrace();
}
}
}

View File

@ -102,6 +102,7 @@ This module can\'t be disabled."</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, must be in lowercase. Can be ignored if the checkbox is disabled:</string>
<string name="mClear_download">Download</string>
<string name="mClear_downloadSuccess">Custom DB successfully downloaded</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>
@ -119,6 +120,7 @@ This module can\'t be disabled."</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 occurred while checking rules</string>
<string name="mClear_customDBLoadError">Custom DB load failed, falling back to built-in DB</string>
<string name="mRemove_name">Remove Queries</string>
<string name="mRemove_desc">With this module you can remove queries from the URL.\nPress the button to remove all queries or press the arrow to remove queries one at a time.\nThanks to PabloOQ for the idea and original implementation!</string>