From ab5d19e7774b826f40c546054c0974c98815e23a Mon Sep 17 00:00:00 2001 From: xynngh Date: Sun, 6 Sep 2020 18:01:27 +0400 Subject: [PATCH] Add option to change primary DB download URL --- app/build.gradle | 2 +- .../yetanothercallblocker/GenericSettings.java | 7 +++++++ .../dummydomain/yetanothercallblocker/Settings.java | 10 ++++++++++ .../yetanothercallblocker/work/TaskService.java | 2 +- app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/root_preferences.xml | 3 +++ 7 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2085542..ba12e25 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,7 +44,7 @@ dependencies { implementation 'org.conscrypt:conscrypt-android:2.4.0' //noinspection GradleDependency: 3.12.* is the latest version compatible with Android <5 implementation 'com.squareup.okhttp3:okhttp:3.12.12' - implementation 'com.gitlab.xynngh:LibPhoneNumberInfo:fd60ad9583' + implementation 'com.gitlab.xynngh:LibPhoneNumberInfo:5b0b9fcbee' implementation 'org.apache.commons:commons-csv:1.8' implementation 'androidx.appcompat:appcompat:1.2.0' diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/GenericSettings.java b/app/src/main/java/dummydomain/yetanothercallblocker/GenericSettings.java index 8289230..43bf77c 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/GenericSettings.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/GenericSettings.java @@ -2,6 +2,7 @@ package dummydomain.yetanothercallblocker; import android.content.Context; import android.content.SharedPreferences; +import android.text.TextUtils; public class GenericSettings { @@ -53,6 +54,12 @@ public class GenericSettings { return pref.getString(key, defValue); } + public String getNonEmptyString(String key, String defValue) { + String value = getString(key); + if (TextUtils.isEmpty(value)) value = defValue; + return value; + } + public void setString(String key, String value) { pref.edit().putString(key, value).apply(); } diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/Settings.java b/app/src/main/java/dummydomain/yetanothercallblocker/Settings.java index dca4ee7..eb02203 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/Settings.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/Settings.java @@ -10,6 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import dummydomain.yetanothercallblocker.data.CountryHelper; +import dummydomain.yetanothercallblocker.sia.model.database.DbManager; public class Settings extends GenericSettings { @@ -27,6 +28,7 @@ public class Settings extends GenericSettings { public static final String PREF_LAST_UPDATE_CHECK_TIME = "lastUpdateCheckTime"; public static final String PREF_COUNTRY_CODE_OVERRIDE = "countryCodeOverride"; public static final String PREF_COUNTRY_CODE_FOR_REVIEWS_OVERRIDE = "countryCodeForReviewsOverride"; + public static final String PREF_DATABASE_DOWNLOAD_URL = "databaseDownloadUrl"; public static final String PREF_SAVE_CRASHES_TO_EXTERNAL_STORAGE = "saveCrashesToExternalStorage"; public static final String PREF_SAVE_LOGCAT_ON_CRASH = "saveLogcatOnCrash"; @@ -207,6 +209,14 @@ public class Settings extends GenericSettings { setString(PREF_COUNTRY_CODE_FOR_REVIEWS_OVERRIDE, code); } + public String getDatabaseDownloadUrl() { + return getNonEmptyString(PREF_DATABASE_DOWNLOAD_URL, DbManager.DEFAULT_URL); + } + + public void setDatabaseDownloadUrl(String url) { + setString(PREF_DATABASE_DOWNLOAD_URL, url); + } + public String getCountryCode() { String override = getCountryCodeOverride(); if (!TextUtils.isEmpty(override)) return override.toUpperCase(); diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/work/TaskService.java b/app/src/main/java/dummydomain/yetanothercallblocker/work/TaskService.java index 76bddab..b027804 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/work/TaskService.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/work/TaskService.java @@ -88,7 +88,7 @@ public class TaskService extends IntentService { postStickyEvent(sticky); try { - YacbHolder.getDbManager().downloadMainDb(); + YacbHolder.getDbManager().downloadMainDb(App.getSettings().getDatabaseDownloadUrl()); YacbHolder.getCommunityDatabase().reload(); YacbHolder.getFeaturedDatabase().reload(); YacbHolder.getSiaMetadata().reload(); diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 6b3f407..d659596 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -109,6 +109,7 @@ Код страны для отзывов Код страны, используемый для запроса онлайн-отзывов. Предназначен для представления страны звонящего. Оставьте пустым для автоопределения Некорректный формат кода страны. Значение не обновлено + URL для загрузки основной базы Отладка Сохранять отчёты в общее хранилище Сохранять отчёты об ошибках и логи в общее хранилище. В противном случае отчёты сохраняются в личную папку приложения. Отчёты могут содержать конфиденциальные данные (номера телефонов, имена контактов). Другие приложения с разрешением на доступ к хранилищу могут иметь доступ к этим данным в общем хранилище diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3f7ac15..11942c1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -124,6 +124,7 @@ Country code for reviews Country code used in requests for online reviews. Meant to represent the country of the caller. Leave empty for auto-detection Incorrect country code format. Value is not updated + Primary DB download URL Debugging Save reports to public storage Save crash reports and logs to public storage, otherwise crash reports are saved to a private app folder. The reports may contain sensitive data (phone numbers, contact names). Other apps with storage permission may have access to this data in public storage diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index eac32b2..71dc876 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -88,6 +88,9 @@ app:summary="@string/country_code_for_reviews_override_summary" app:title="@string/country_code_for_reviews_override" /> +