Add an option to disable blocked call notifications

on Android versions older than 8
This commit is contained in:
xynngh 2020-11-01 16:10:15 +04:00
parent 63961e004f
commit e8721807f6
16 changed files with 67 additions and 14 deletions

View File

@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- An option to disable notifications for blocked calls on old Android versions.
- Portuguese (Brazil) translation thanks to APL ([@APL](https://hosted.weblate.org/user/APL/)).
### Changed

View File

@ -84,6 +84,12 @@ public class NotificationHelper {
}
public static void showBlockedCallNotification(Context context, NumberInfo numberInfo) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
if (!App.getSettings().getNotificationsForBlockedCalls()) {
return;
}
}
Notification notification = createBlockedCallNotification(context, numberInfo);
String tag = NOTIFICATION_TAG_BLOCKED_CALL

View File

@ -27,6 +27,7 @@ public class Settings extends GenericSettings {
public static final String PREF_USE_MONITORING_SERVICE = "useMonitoringService";
public static final String PREF_NOTIFICATIONS_KNOWN = "showNotificationsForKnownCallers";
public static final String PREF_NOTIFICATIONS_UNKNOWN = "showNotificationsForUnknownCallers";
public static final String PREF_NOTIFICATIONS_BLOCKED = "showNotificationsForBlockedCalls";
public static final String PREF_LAST_UPDATE_TIME = "lastUpdateTime";
public static final String PREF_LAST_UPDATE_CHECK_TIME = "lastUpdateCheckTime";
public static final String PREF_COUNTRY_CODE_OVERRIDE = "countryCodeOverride";
@ -192,6 +193,14 @@ public class Settings extends GenericSettings {
setBoolean(PREF_NOTIFICATIONS_UNKNOWN, show);
}
public boolean getNotificationsForBlockedCalls() {
return getBoolean(PREF_NOTIFICATIONS_BLOCKED, true);
}
public void setNotificationsForBlockedCalls(boolean show) {
setBoolean(PREF_NOTIFICATIONS_BLOCKED, show);
}
public long getLastUpdateTime() {
return getLong(PREF_LAST_UPDATE_TIME, 0);
}

View File

@ -136,6 +136,7 @@ public class SettingsActivity extends AppCompatActivity
private static final String PREF_AUTO_UPDATE_ENABLED = "autoUpdateEnabled";
private static final String PREF_NOTIFICATION_CHANNEL_SETTINGS = "notificationChannelSettings";
private static final String PREF_CATEGORY_NOTIFICATIONS = "categoryNotifications";
private static final String PREF_NOTIFICATIONS_BLOCKED_NON_PERSISTENT = "showNotificationsForBlockedCallsNonPersistent";
private static final String PREF_SCREEN_ADVANCED = "screenAdvanced";
private static final String PREF_COUNTRY_CODES_INFO = "countryCodesInfo";
private static final String PREF_EXPORT_LOGCAT = "exportLogcat";
@ -149,6 +150,8 @@ public class SettingsActivity extends AppCompatActivity
super.onStart();
requireActivity().setTitle(getPreferenceScreen().getTitle());
updateBlockedCallNotificationsPreference();
}
@Override
@ -284,6 +287,38 @@ public class SettingsActivity extends AppCompatActivity
category.setVisible(false);
} else {
notificationChannelSettings.setVisible(false);
SwitchPreferenceCompat blockedCallNotificationsPref =
requireNonNull(findPreference(PREF_NOTIFICATIONS_BLOCKED_NON_PERSISTENT));
blockedCallNotificationsPref.setChecked(
App.getSettings().getNotificationsForBlockedCalls());
blockedCallNotificationsPref.setOnPreferenceChangeListener((pref, newValue) -> {
if (Boolean.TRUE.equals(newValue)) {
App.getSettings().setNotificationsForBlockedCalls(true);
} else {
new AlertDialog.Builder(requireActivity())
.setTitle(R.string.are_you_sure)
.setMessage(R.string.blocked_call_notifications_disable_message)
.setPositiveButton(R.string.blocked_call_notifications_disable_confirmation,
(d, w) -> App.getSettings().setNotificationsForBlockedCalls(false))
.setNegativeButton(android.R.string.cancel, null)
.setOnDismissListener(d -> updateBlockedCallNotificationsPreference())
.show();
}
return true;
});
}
}
private void updateBlockedCallNotificationsPreference() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return;
SwitchPreferenceCompat notificationsForBlockedPref =
findPreference(PREF_NOTIFICATIONS_BLOCKED_NON_PERSISTENT);
if (notificationsForBlockedPref != null) {
notificationsForBlockedPref.setChecked(
App.getSettings().getNotificationsForBlockedCalls());
}
}

View File

@ -101,7 +101,6 @@
<string name="block_blacklisted_short">Αποκλεισμός μαύρης λίστας</string>
<string name="block_hidden_number_summary">Αποκλεισμός κλήσεων από κρυφούς αριθμούς. Ίσως να λειτουργεί διαφορετικά (καλύτερα ή χειρότερα) στη \"Σύνθετη λειτουργία αποκλεισμού κλήσεων\"</string>
<string name="block_hidden_number">Αποκλεισμός κρυφών αριθμών</string>
<string name="settings_category_notifications_incoming_calls">Ειδοποιήσεις εισερχόμενων κλήσεων</string>
<string name="incoming_call_notifications">Ειδοποιήσεις εισερχόμενων κλήσεων</string>
<string name="show_notifications_for_unknown_callers">Ειδοποιήσεις για άγνωστους καλούντες</string>
<string name="show_notifications_for_known_callers_summary">Εμφάνιση ειδοποιήσεων για γνωστούς καλούντες (αριθμοί στις Επαφές)</string>

View File

@ -60,7 +60,6 @@
<string name="open_settings_activity">Ajustes</string>
<string name="title_settings_activity">Ajustes</string>
<string name="settings_category_main">Inicio</string>
<string name="settings_category_notifications_incoming_calls">Notificaciones de llamadas entrantes</string>
<string name="show_notifications_for_known_callers">Notificaciones de llamadas conocidas</string>
<string name="show_notifications_for_known_callers_summary">Mostrar notificaciones de llamadas conocidas (números en Contactos)</string>
<string name="show_notifications_for_unknown_callers">Notificaciones de llamadas desconocidas</string>

View File

@ -65,7 +65,6 @@
<string name="title_settings_activity">Paramètres</string>
<string name="settings_category_main">Principaux</string>
<string name="settings_category_call_blocking">Blocage d\'appel</string>
<string name="settings_category_notifications_incoming_calls">Notifications d\'appels entrants</string>
<string name="show_notifications_for_known_callers">Notifications pour les appelants identifiés</string>
<string name="show_notifications_for_known_callers_summary">Afficher les notifications pour les appelants identifiés (numéros dans les contacts))</string>
<string name="show_notifications_for_unknown_callers">Notifications pour les appelants inconnus</string>

View File

@ -106,7 +106,6 @@
<string name="sia_category_safe_nonprofit">Sigurna neprofitna organizacija</string>
<string name="blacklist_export">Izvezi</string>
<string name="sia_category_political">Politika</string>
<string name="settings_category_notifications_incoming_calls">Obavijesti o dolaznim pozivima</string>
<string name="notification_incoming_call_contact">Kontakt</string>
<string name="use_contacts_summary">Brojevi koji su prisutni u kontaktima nikada se ne blokiraju, a ime kontakta prikazuje se uz broj ili umjesto broja</string>
<string name="blacklist_import">Uvezi</string>

View File

@ -43,7 +43,6 @@
<string name="show_notifications_for_unknown_callers_summary">Vis merknader for ukjente oppringere (hverken i kontakter eller i nummerdatabase)</string>
<string name="show_notifications_for_unknown_callers">Merknader for ukjente oppringere</string>
<string name="show_notifications_for_known_callers_summary">Vis merknader for kjente oppringere (nummer i kontaktliste)</string>
<string name="settings_category_notifications_incoming_calls">Merknader for innkommende anrop</string>
<string name="show_notifications_for_known_callers">Merknader for kjente oppringere</string>
<string name="add_web_review">Legg til vurdering (nettbasert)</string>
<string name="no_main_db_text">Databasen finnes ikke. For at programmet skal utføre brorparten av dets funksjoner må du laste ned databasen. Den er omtrent 25 MB.</string>

View File

@ -136,7 +136,6 @@
<string name="incoming_call_notifications">Wyświetlaj powiadomienia</string>
<string name="show_notifications_for_unknown_callers">Powiadomienia dla nieznanych połączeń</string>
<string name="show_notifications_for_known_callers">Powiadomienia dla znanych połączeń</string>
<string name="settings_category_notifications_incoming_calls">Powiadomienia o połączeniach przychodzących</string>
<string name="call_log_permission_message">Przyznaj uprawnienie „Telefon”, aby zobaczyć ostatnie połączenia</string>
<string name="notification_channel_name_monitoring_service">Usługa monitorowania</string>
<string name="notification_channel_group_name_services">Usługi</string>

View File

@ -138,7 +138,6 @@
<string name="show_notifications_for_unknown_callers">Notificações de chamadas desconhecidas</string>
<string name="show_notifications_for_known_callers_summary">Exibir notificações para chamadas conhecidas (números de Contatos)</string>
<string name="show_notifications_for_known_callers">Notificações de chamadas conhecidas</string>
<string name="settings_category_notifications_incoming_calls">Notificações de chamadas recebidas</string>
<string name="settings_category_call_blocking">Bloqueio de chamadas</string>
<string name="settings_category_main">Principal</string>
<string name="title_settings_activity">Configurações</string>

View File

@ -100,11 +100,14 @@
<string name="title_settings_activity">Настройки</string>
<string name="settings_category_main">Основные</string>
<string name="settings_category_call_blocking">Блокирование вызовов</string>
<string name="settings_category_notifications_incoming_calls">Уведомления на входящие</string>
<string name="show_notifications_for_known_callers">Уведомления для известных звонящих</string>
<string name="show_notifications_for_known_callers_summary">Показывать уведомления для известных звонящих (номеров из телефонной книги)</string>
<string name="show_notifications_for_unknown_callers">Уведомления для неизвестных звонящих</string>
<string name="show_notifications_for_unknown_callers_summary">Показывать уведомления для неизвестных звонящих (отсутствующих в телефонной книге и в базе номеров)</string>
<string name="show_notifications_for_blocked_calls">Уведомлять о заблокированных вызовах</string>
<string name="show_notifications_for_blocked_calls_summary">Показывать уведомление после блокировки вызова</string>
<string name="blocked_call_notifications_disable_message">Вы можете случайно пропустить вызов, если уведомления о блокированных вызовах выключены</string>
<string name="blocked_call_notifications_disable_confirmation">Всё равно выключить</string>
<string name="notification_settings">Настройки уведомлений</string>
<string name="settings_screen_advanced">Продвинутые настройки</string>
<string name="settings_category_country_codes">Коды страны</string>

View File

@ -96,7 +96,6 @@
<string name="show_notifications_for_unknown_callers">Bilinmeyen arayanlar için bildirimler</string>
<string name="show_notifications_for_known_callers">Bilinen arayanlar için bildirimler</string>
<string name="show_notifications_for_known_callers_summary">Bilinen arayanlar için bildirimleri görüntüle (Kişilerde kayıtlı numaralar)</string>
<string name="settings_category_notifications_incoming_calls">Gelen arama bildirimleri</string>
<string name="settings_category_call_blocking">Arama engelleme</string>
<string name="settings_category_main">Ana kategori</string>
<string name="title_settings_activity">Ayarlar</string>

View File

@ -88,7 +88,6 @@
<string name="title_settings_activity">Налаштування</string>
<string name="settings_category_main">Основні</string>
<string name="settings_category_call_blocking">Блокування викликів</string>
<string name="settings_category_notifications_incoming_calls">Повідомлення на вхідні</string>
<string name="show_notifications_for_known_callers">Повідомлення для відомих тих, що дзвонять</string>
<string name="show_notifications_for_known_callers_summary">Показувати сповіщення для відомих тих, що дзвонять (номерів з телефонної книги)</string>
<string name="show_notifications_for_unknown_callers">Повідомлення для невідомих, що дзвонять</string>

View File

@ -90,11 +90,14 @@
<string name="title_settings_activity">Settings</string>
<string name="settings_category_main">Main</string>
<string name="settings_category_call_blocking">Call blocking</string>
<string name="settings_category_notifications_incoming_calls">Incoming calls notifications</string>
<string name="show_notifications_for_known_callers">Notifications for known callers</string>
<string name="show_notifications_for_known_callers_summary">Display notifications for known callers (numbers in Contacts)</string>
<string name="show_notifications_for_unknown_callers">Notifications for unknown callers</string>
<string name="show_notifications_for_unknown_callers_summary">Display notifications for unknown callers (neither in Contacts nor in number database)</string>
<string name="show_notifications_for_blocked_calls">Notify about blocked calls</string>
<string name="show_notifications_for_blocked_calls_summary">Display a notification after a call was blocked</string>
<string name="blocked_call_notifications_disable_message">You may accidentally miss a call if calls are blocked without notifications</string>
<string name="blocked_call_notifications_disable_confirmation">Disable anyway</string>
<string name="notification_settings">Notification settings</string>
<string name="incoming_call_notifications">Incoming call notifications</string>

View File

@ -1,5 +1,5 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:title="@string/title_settings_activity">
<PreferenceCategory app:title="@string/settings_category_main">
@ -66,7 +66,7 @@
<PreferenceCategory
app:key="categoryNotifications"
app:title="@string/settings_category_notifications_incoming_calls">
app:title="@string/notification_settings">
<SwitchPreferenceCompat
app:key="showNotificationsForKnownCallers"
app:summary="@string/show_notifications_for_known_callers_summary"
@ -75,6 +75,11 @@
app:key="showNotificationsForUnknownCallers"
app:summary="@string/show_notifications_for_unknown_callers_summary"
app:title="@string/show_notifications_for_unknown_callers" />
<SwitchPreferenceCompat
app:key="showNotificationsForBlockedCallsNonPersistent"
app:persistent="false"
app:summary="@string/show_notifications_for_blocked_calls_summary"
app:title="@string/show_notifications_for_blocked_calls" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/settings_screen_advanced">