From cce43233262a8eb54b123e0359113ac8a7e611a4 Mon Sep 17 00:00:00 2001 From: Pablo Ortigosa <55493443+PabloOQ@users.noreply.github.com> Date: Sat, 2 Jul 2022 13:46:50 +0100 Subject: [PATCH] Added info messages --- .../modules/list/ClearUrlModule.java | 30 +++++++++++-------- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/trianguloy/urlchecker/modules/list/ClearUrlModule.java b/app/src/main/java/com/trianguloy/urlchecker/modules/list/ClearUrlModule.java index 31d9eb5..d984704 100644 --- a/app/src/main/java/com/trianguloy/urlchecker/modules/list/ClearUrlModule.java +++ b/app/src/main/java/com/trianguloy/urlchecker/modules/list/ClearUrlModule.java @@ -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(); } } + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 41c60d8..ab4cb27 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -102,6 +102,7 @@ This module can\'t be disabled." URL of the custom database JSON file with the rules: URL of the hash of the custom database, must be in lowercase. Can be ignored if the checkbox is disabled: Download + Custom DB successfully downloaded data.minify.json Uses the Clear URL database from https://docs.clearurls.xyz/latest/specs/rules/ Apply @@ -119,6 +120,7 @@ This module can\'t be disabled." Enable referral marketing (referral parameters won\'t be cleared) Enable verbose info for the matching process An error occurred while checking rules + Custom DB load failed, falling back to built-in DB Remove Queries 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!