@@ -7,75 +7,59 @@ const val SPAM_PREFS = "SPAM_PREFS"
77const val BLOCK_NUMBERS_KEY = " BLOCK_NUMBERS"
88const val WHITELIST_NUMBERS_KEY = " WHITELIST_NUMBERS"
99
10- fun isBlockingEnabled (context : Context ): Boolean {
11- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
12- return sharedPreferences.getBoolean(" pref_enable_blocking" , true )
13- }
10+ private fun getPrefs (context : Context ) = PreferenceManager .getDefaultSharedPreferences(context)
1411
15- fun shouldBlockHiddenNumbers (context : Context ): Boolean {
16- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
17- return sharedPreferences.getBoolean(" pref_block_hidden_numbers" , true )
18- }
12+ private fun getBooleanPref (context : Context , key : String , defaultValue : Boolean ): Boolean =
13+ getPrefs(context).getBoolean(key, defaultValue)
1914
20- fun shouldBlockInternationalNumbers (context : Context ): Boolean {
21- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
22- return sharedPreferences.getBoolean(" pref_block_international_numbers" , false )
23- }
15+ private fun getStringPref (context : Context , key : String ): String? =
16+ getPrefs(context).getString(key, null )
2417
25- fun shouldFilterWithListaSpamApi (context : Context ): Boolean {
26- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
27- return sharedPreferences.getBoolean(" pref_filter_lista_spam_api" , true )
18+ private fun setStringPref (context : Context , key : String , value : String ) {
19+ getPrefs(context).edit().putString(key, value).apply ()
2820}
2921
30- fun getListaSpamApiLang (context : Context ): String? {
31- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
32- return sharedPreferences.getString(" pref_language" , null )?.uppercase()
33- }
22+ fun isBlockingEnabled (context : Context ): Boolean =
23+ getBooleanPref(context, " pref_enable_blocking" , true )
3424
35- fun setListaSpamApiLang (context : Context , languageCode : String ) {
36- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
37- sharedPreferences.edit().putString(" pref_language" , languageCode.uppercase()).apply ()
38- }
25+ fun shouldBlockHiddenNumbers (context : Context ): Boolean =
26+ getBooleanPref(context, " pref_block_hidden_numbers" , true )
3927
40- fun shouldFilterWithTellowsApi (context : Context ): Boolean {
41- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
42- return sharedPreferences.getBoolean(" pref_filter_tellows_api" , true )
43- }
28+ fun shouldBlockInternationalNumbers (context : Context ): Boolean =
29+ getBooleanPref(context, " pref_block_international_numbers" , false )
4430
45- fun getTellowsApiCountry (context : Context ): String? {
46- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
47- return sharedPreferences.getString(" pref_tellows_country" , null )?.lowercase()
48- }
31+ fun shouldFilterWithListaSpamApi (context : Context ): Boolean =
32+ getBooleanPref(context, " pref_filter_lista_spam_api" , true )
4933
50- fun setTellowsApiCountry (context : Context , countryCode : String ) {
51- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
52- sharedPreferences.edit().putString(" pref_tellows_country" , countryCode.lowercase()).apply ()
53- }
34+ fun getListaSpamApiLang (context : Context ): String? =
35+ getStringPref(context, " pref_language" )?.uppercase()
5436
55- fun shouldFilterWithListaSpamScraper (context : Context ): Boolean {
56- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
57- return sharedPreferences.getBoolean(" pref_filter_lista_spam_scraper" , false )
58- }
37+ fun setListaSpamApiLang (context : Context , languageCode : String ) =
38+ setStringPref(context, " pref_language" , languageCode.uppercase())
5939
60- fun shouldFilterWithResponderONo (context : Context ): Boolean {
61- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
62- return sharedPreferences.getBoolean(" pref_filter_responder_o_no" , false )
63- }
40+ fun shouldFilterWithTellowsApi (context : Context ): Boolean =
41+ getBooleanPref(context, " pref_filter_tellows_api" , true )
6442
65- fun shouldFilterWithCleverdialer (context : Context ): Boolean {
66- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
67- return sharedPreferences.getBoolean(" pref_filter_cleverdialer" , false )
68- }
43+ fun getTellowsApiCountry (context : Context ): String? =
44+ getStringPref(context, " pref_tellows_country" )?.lowercase()
6945
70- fun shouldBlockNonContacts (context : Context ): Boolean {
71- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
72- return sharedPreferences.getBoolean(" pref_block_non_contacts" , false )
73- }
46+ fun setTellowsApiCountry (context : Context , countryCode : String ) =
47+ setStringPref(context, " pref_tellows_country" , countryCode.lowercase())
7448
75- fun shouldShowNotification (context : Context ): Boolean {
76- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
77- return sharedPreferences.getBoolean(" pref_show_notification" , true )
78- }
49+ fun shouldFilterWithListaSpamScraper (context : Context ): Boolean =
50+ getBooleanPref(context, " pref_filter_lista_spam_scraper" , false )
51+
52+ fun shouldFilterWithResponderONo (context : Context ): Boolean =
53+ getBooleanPref(context, " pref_filter_responder_o_no" , false )
54+
55+ fun shouldFilterWithCleverdialer (context : Context ): Boolean =
56+ getBooleanPref(context, " pref_filter_cleverdialer" , false )
57+
58+ fun shouldBlockNonContacts (context : Context ): Boolean =
59+ getBooleanPref(context, " pref_block_non_contacts" , false )
60+
61+ fun shouldShowNotification (context : Context ): Boolean =
62+ getBooleanPref(context, " pref_show_notification" , true )
7963
8064/* *
8165 * Saves a phone number as spam in SharedPreferences by adding it to the blocked numbers set.
@@ -90,7 +74,8 @@ fun saveSpamNumber(context: Context, number: String) {
9074
9175 // Get the SharedPreferences and update the blocked numbers set
9276 val sharedPreferences = context.getSharedPreferences(SPAM_PREFS , Context .MODE_PRIVATE )
93- val blockedNumbers = sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
77+ val blockedNumbers =
78+ sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
9479 blockedNumbers?.add(number)
9580
9681 // Save the updated blocked numbers set to SharedPreferences
@@ -109,7 +94,8 @@ fun saveSpamNumber(context: Context, number: String) {
10994fun removeSpamNumber (context : Context , number : String ) {
11095 // Get the SharedPreferences and update the blocked numbers set
11196 val sharedPreferences = context.getSharedPreferences(SPAM_PREFS , Context .MODE_PRIVATE )
112- val blockedNumbers = sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
97+ val blockedNumbers =
98+ sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
11399 blockedNumbers?.remove(number)
114100
115101 // Save the updated blocked numbers set to SharedPreferences
@@ -132,7 +118,8 @@ fun addNumberToWhitelist(context: Context, number: String) {
132118
133119 // Get the SharedPreferences and update the whitelist numbers set
134120 val sharedPreferences = context.getSharedPreferences(SPAM_PREFS , Context .MODE_PRIVATE )
135- val whitelistNumbers = sharedPreferences.getStringSet(WHITELIST_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
121+ val whitelistNumbers =
122+ sharedPreferences.getStringSet(WHITELIST_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
136123 whitelistNumbers?.add(number)
137124
138125 // Save the updated whitelist numbers set to SharedPreferences
@@ -151,7 +138,8 @@ fun addNumberToWhitelist(context: Context, number: String) {
151138fun removeWhitelistNumber (context : Context , number : String ) {
152139 // Get the SharedPreferences and update the whitelist numbers set
153140 val sharedPreferences = context.getSharedPreferences(SPAM_PREFS , Context .MODE_PRIVATE )
154- val whitelistNumbers = sharedPreferences.getStringSet(WHITELIST_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
141+ val whitelistNumbers =
142+ sharedPreferences.getStringSet(WHITELIST_NUMBERS_KEY , mutableSetOf ())?.toMutableSet()
155143 whitelistNumbers?.remove(number)
156144
157145 // Save the updated whitelist numbers set to SharedPreferences
0 commit comments