Commit 491f70e5 by zhangchengbo

feat:[加入黑名单]-[管理黑名单]功能

parent 87bf7fab
...@@ -135,6 +135,14 @@ ...@@ -135,6 +135,14 @@
android:parentActivityName=".activities.SettingsActivity" /> android:parentActivityName=".activities.SettingsActivity" />
<activity <activity
android:name="com.simplemobiletools.commons.activities.ManageBlockedNumbersActivity"
android:configChanges="orientation"
android:exported="false"
android:label="@string/blocked_numbers"
android:parentActivityName=".activities.SettingsActivity"
tools:replace="android:label" />
<activity
android:name=".activities.ManageBlockedKeywordsActivity" android:name=".activities.ManageBlockedKeywordsActivity"
android:configChanges="orientation" android:configChanges="orientation"
android:exported="false" android:exported="false"
......
...@@ -201,17 +201,17 @@ class MainActivity : SimpleActivity() { ...@@ -201,17 +201,17 @@ class MainActivity : SimpleActivity() {
searchTextChanged(text) searchTextChanged(text)
} }
/* binding.mainMenu.getToolbar().setOnMenuItemClickListener { menuItem -> binding.mainMenu.getToolbar().setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent() /* R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
R.id.show_recycle_bin -> launchRecycleBin() R.id.show_recycle_bin -> launchRecycleBin()
R.id.show_archived -> launchArchivedConversations() R.id.show_archived -> launchArchivedConversations()
R.id.about -> launchAbout()*/
R.id.settings -> launchSettings() R.id.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return@setOnMenuItemClickListener false else -> return@setOnMenuItemClickListener false
} }
return@setOnMenuItemClickListener true return@setOnMenuItemClickListener true
}*/ }
} }
private fun refreshMenuItems() { private fun refreshMenuItems() {
......
...@@ -13,6 +13,7 @@ import com.secspace.sms.extensions.config ...@@ -13,6 +13,7 @@ import com.secspace.sms.extensions.config
import com.secspace.sms.extensions.emptyMessagesRecycleBin import com.secspace.sms.extensions.emptyMessagesRecycleBin
import com.secspace.sms.extensions.messagesDB import com.secspace.sms.extensions.messagesDB
import com.secspace.sms.helpers.* import com.secspace.sms.helpers.*
import com.simplemobiletools.commons.activities.ManageBlockedNumbersActivity
import com.simplemobiletools.commons.dialogs.* import com.simplemobiletools.commons.dialogs.*
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
...@@ -48,27 +49,28 @@ class SettingsActivity : SimpleActivity() { ...@@ -48,27 +49,28 @@ class SettingsActivity : SimpleActivity() {
super.onResume() super.onResume()
setupToolbar(binding.settingsToolbar, NavigationIcon.Arrow) setupToolbar(binding.settingsToolbar, NavigationIcon.Arrow)
setupPurchaseThankYou() // setupPurchaseThankYou()
setupCustomizeColors() // setupCustomizeColors()
// setupCustomizeNotifications() // setupCustomizeNotifications()
setupUseEnglish() // setupUseEnglish()
// setupLanguage() // setupLanguage()
setupManageBlockedKeywords() setupManageBlockedNumbers()
setupChangeDateTimeFormat() // setupManageBlockedKeywords()
setupFontSize() // setupChangeDateTimeFormat()
setupShowCharacterCounter() // setupFontSize()
setupUseSimpleCharacters() // setupShowCharacterCounter()
setupSendOnEnter() // setupUseSimpleCharacters()
setupEnableDeliveryReports() // setupSendOnEnter()
setupSendLongMessageAsMMS() // setupEnableDeliveryReports()
setupGroupMessageAsMMS() // setupSendLongMessageAsMMS()
setupLockScreenVisibility() // setupGroupMessageAsMMS()
setupMMSFileSizeLimit() // setupLockScreenVisibility()
setupUseRecycleBin() // setupMMSFileSizeLimit()
setupEmptyRecycleBin() // setupUseRecycleBin()
setupAppPasswordProtection() // setupEmptyRecycleBin()
setupMessagesExport() // setupAppPasswordProtection()
setupMessagesImport() // setupMessagesExport()
// setupMessagesImport()
updateTextColors(binding.settingsNestedScrollview) updateTextColors(binding.settingsNestedScrollview)
if (blockedNumbersAtPause != -1 && blockedNumbersAtPause != getBlockedNumbers().hashCode()) { if (blockedNumbersAtPause != -1 && blockedNumbersAtPause != getBlockedNumbers().hashCode()) {
...@@ -185,20 +187,20 @@ class SettingsActivity : SimpleActivity() { ...@@ -185,20 +187,20 @@ class SettingsActivity : SimpleActivity() {
} }
// support for device-wise blocking came on Android 7, rely only on that // support for device-wise blocking came on Android 7, rely only on that
/* private fun setupManageBlockedNumbers() = binding.apply { private fun setupManageBlockedNumbers() = binding.apply {
settingsManageBlockedNumbers.text = addLockedLabelIfNeeded(com.simplemobiletools.commons.R.string.manage_blocked_numbers) settingsManageBlockedNumbers.text = addLockedLabelIfNeeded(com.simplemobiletools.commons.R.string.manage_blocked_numbers)
settingsManageBlockedNumbersHolder.beVisibleIf(isNougatPlus()) settingsManageBlockedNumbersHolder.beVisibleIf(isNougatPlus())
settingsManageBlockedNumbersHolder.setOnClickListener { settingsManageBlockedNumbersHolder.setOnClickListener {
if (isOrWasThankYouInstalled()) { // if (isOrWasThankYouInstalled()) {
Intent(this@SettingsActivity, ManageBlockedNumbersActivity::class.java).apply { Intent(this@SettingsActivity, ManageBlockedNumbersActivity::class.java).apply {
startActivity(this) startActivity(this)
} }
} else { // } else {
FeatureLockedDialog(this@SettingsActivity) { } // FeatureLockedDialog(this@SettingsActivity) { }
} // }
} }
}*/ }
private fun setupManageBlockedKeywords() = binding.apply { private fun setupManageBlockedKeywords() = binding.apply {
settingsManageBlockedKeywords.text = addLockedLabelIfNeeded(R.string.manage_blocked_keywords) settingsManageBlockedKeywords.text = addLockedLabelIfNeeded(R.string.manage_blocked_keywords)
......
...@@ -259,8 +259,8 @@ class ThreadActivity : SimpleActivity() { ...@@ -259,8 +259,8 @@ class ThreadActivity : SimpleActivity() {
findItem(R.id.unarchive).isVisible = /*threadItems.isNotEmpty() && conversation?.isArchived == true && !isRecycleBin && archiveAvailable*/false findItem(R.id.unarchive).isVisible = /*threadItems.isNotEmpty() && conversation?.isArchived == true && !isRecycleBin && archiveAvailable*/false
findItem(R.id.rename_conversation).isVisible = /*participants.size > 1 && conversation != null && !isRecycleBin*/ false findItem(R.id.rename_conversation).isVisible = /*participants.size > 1 && conversation != null && !isRecycleBin*/ false
findItem(R.id.conversation_details).isVisible = /*conversation != null && !isRecycleBin*/ false findItem(R.id.conversation_details).isVisible = /*conversation != null && !isRecycleBin*/ false
findItem(R.id.block_number).title = /*addLockedLabelIfNeeded(com.simplemobiletools.commons.R.string.block_number)*/ "" findItem(R.id.block_number).title = addLockedLabelIfNeeded(com.simplemobiletools.commons.R.string.block_number)
findItem(R.id.block_number).isVisible = /*isNougatPlus() && !isRecycleBin*/ false findItem(R.id.block_number).isVisible = isNougatPlus() && !isRecycleBin
findItem(R.id.dial_number).isVisible = /*participants.size == 1 && !isSpecialNumber() && !isRecycleBin*/ false findItem(R.id.dial_number).isVisible = /*participants.size == 1 && !isSpecialNumber() && !isRecycleBin*/ false
findItem(R.id.manage_people).isVisible = /*!isSpecialNumber() && !isRecycleBin */false findItem(R.id.manage_people).isVisible = /*!isSpecialNumber() && !isRecycleBin */false
findItem(R.id.mark_as_unread).isVisible = /*threadItems.isNotEmpty() && !isRecycleBin*/ false findItem(R.id.mark_as_unread).isVisible = /*threadItems.isNotEmpty() && !isRecycleBin*/ false
...@@ -280,8 +280,8 @@ class ThreadActivity : SimpleActivity() { ...@@ -280,8 +280,8 @@ class ThreadActivity : SimpleActivity() {
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.delete -> askConfirmDelete() R.id.delete -> askConfirmDelete()
/* R.id.block_number -> tryBlocking() R.id.block_number -> tryBlocking()
R.id.restore -> askConfirmRestoreAll() /* R.id.restore -> askConfirmRestoreAll()
R.id.archive -> archiveConversation() R.id.archive -> archiveConversation()
R.id.unarchive -> unarchiveConversation() R.id.unarchive -> unarchiveConversation()
R.id.rename_conversation -> renameConversation() R.id.rename_conversation -> renameConversation()
...@@ -945,11 +945,11 @@ class ThreadActivity : SimpleActivity() { ...@@ -945,11 +945,11 @@ class ThreadActivity : SimpleActivity() {
} }
private fun tryBlocking() { private fun tryBlocking() {
if (isOrWasThankYouInstalled()) { // if (isOrWasThankYouInstalled()) {
blockNumber() blockNumber()
} else { // } else {
FeatureLockedDialog(this) { } // FeatureLockedDialog(this) { }
} // }
} }
private fun blockNumber() { private fun blockNumber() {
......
...@@ -33,13 +33,15 @@ ...@@ -33,13 +33,15 @@
style="@style/SettingsSectionLabelStyle" style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/color_customization" /> android:text="@string/color_customization"
android:visibility="gone" />
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/settings_color_customization_holder" android:id="@+id/settings_color_customization_holder"
style="@style/SettingsHolderTextViewOneLinerStyle" style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_color_customization_label" android:id="@+id/settings_color_customization_label"
...@@ -61,13 +63,14 @@ ...@@ -61,13 +63,14 @@
style="@style/SettingsSectionLabelStyle" style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/general_settings" /> android:text="@string/blocked_numbers" />
<RelativeLayout <RelativeLayout
android:id="@+id/settings_purchase_thank_you_holder" android:id="@+id/settings_purchase_thank_you_holder"
style="@style/SettingsHolderTextViewOneLinerStyle" style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_purchase_thank_you" android:id="@+id/settings_purchase_thank_you"
...@@ -82,7 +85,8 @@ ...@@ -82,7 +85,8 @@
android:id="@+id/settings_use_english_holder" android:id="@+id/settings_use_english_holder"
style="@style/SettingsHolderCheckboxStyle" style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox <com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_use_english" android:id="@+id/settings_use_english"
...@@ -97,7 +101,8 @@ ...@@ -97,7 +101,8 @@
android:id="@+id/settings_language_holder" android:id="@+id/settings_language_holder"
style="@style/SettingsHolderTextViewStyle" style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_language_label" android:id="@+id/settings_language_label"
...@@ -120,7 +125,8 @@ ...@@ -120,7 +125,8 @@
android:id="@+id/settings_change_date_time_format_holder" android:id="@+id/settings_change_date_time_format_holder"
style="@style/SettingsHolderTextViewOneLinerStyle" style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_change_date_time_format" android:id="@+id/settings_change_date_time_format"
...@@ -150,7 +156,8 @@ ...@@ -150,7 +156,8 @@
android:id="@+id/settings_manage_blocked_keywords_holder" android:id="@+id/settings_manage_blocked_keywords_holder"
style="@style/SettingsHolderTextViewOneLinerStyle" style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_manage_blocked_keywords" android:id="@+id/settings_manage_blocked_keywords"
...@@ -165,7 +172,8 @@ ...@@ -165,7 +172,8 @@
android:id="@+id/settings_font_size_holder" android:id="@+id/settings_font_size_holder"
style="@style/SettingsHolderTextViewStyle" style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_font_size_label" android:id="@+id/settings_font_size_label"
...@@ -186,20 +194,23 @@ ...@@ -186,20 +194,23 @@
<include <include
android:id="@+id/settings_general_settings_divider" android:id="@+id/settings_general_settings_divider"
layout="@layout/divider" /> layout="@layout/divider"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/settings_notifications_label" android:id="@+id/settings_notifications_label"
style="@style/SettingsSectionLabelStyle" style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/notifications" /> android:text="@string/notifications"
android:visibility="gone" />
<RelativeLayout <RelativeLayout
android:id="@+id/settings_customize_notifications_holder" android:id="@+id/settings_customize_notifications_holder"
style="@style/SettingsHolderTextViewOneLinerStyle" style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_customize_notifications_label" android:id="@+id/settings_customize_notifications_label"
...@@ -214,7 +225,8 @@ ...@@ -214,7 +225,8 @@
android:id="@+id/settings_lock_screen_visibility_holder" android:id="@+id/settings_lock_screen_visibility_holder"
style="@style/SettingsHolderTextViewStyle" style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_lock_screen_visibility_label" android:id="@+id/settings_lock_screen_visibility_label"
...@@ -235,20 +247,23 @@ ...@@ -235,20 +247,23 @@
<include <include
android:id="@+id/settings_notifications_divider" android:id="@+id/settings_notifications_divider"
layout="@layout/divider" /> layout="@layout/divider"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/settings_outgoing_messages_label" android:id="@+id/settings_outgoing_messages_label"
style="@style/SettingsSectionLabelStyle" style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/outgoing_messages" /> android:text="@string/outgoing_messages"
android:visibility="gone" />
<RelativeLayout <RelativeLayout
android:id="@+id/settings_show_character_counter_holder" android:id="@+id/settings_show_character_counter_holder"
style="@style/SettingsHolderCheckboxStyle" style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox <com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_show_character_counter" android:id="@+id/settings_show_character_counter"
...@@ -263,7 +278,8 @@ ...@@ -263,7 +278,8 @@
android:id="@+id/settings_use_simple_characters_holder" android:id="@+id/settings_use_simple_characters_holder"
style="@style/SettingsHolderCheckboxStyle" style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox <com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_use_simple_characters" android:id="@+id/settings_use_simple_characters"
...@@ -278,7 +294,8 @@ ...@@ -278,7 +294,8 @@
android:id="@+id/settings_send_on_enter_holder" android:id="@+id/settings_send_on_enter_holder"
style="@style/SettingsHolderCheckboxStyle" style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox <com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_send_on_enter" android:id="@+id/settings_send_on_enter"
...@@ -293,7 +310,8 @@ ...@@ -293,7 +310,8 @@
android:id="@+id/settings_enable_delivery_reports_holder" android:id="@+id/settings_enable_delivery_reports_holder"
style="@style/SettingsHolderCheckboxStyle" style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox <com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_enable_delivery_reports" android:id="@+id/settings_enable_delivery_reports"
...@@ -308,7 +326,8 @@ ...@@ -308,7 +326,8 @@
android:id="@+id/settings_send_long_message_mms_holder" android:id="@+id/settings_send_long_message_mms_holder"
style="@style/SettingsHolderCheckboxStyle" style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox <com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_send_long_message_mms" android:id="@+id/settings_send_long_message_mms"
...@@ -323,7 +342,8 @@ ...@@ -323,7 +342,8 @@
android:id="@+id/settings_send_group_message_mms_holder" android:id="@+id/settings_send_group_message_mms_holder"
style="@style/SettingsHolderCheckboxStyle" style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox <com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_send_group_message_mms" android:id="@+id/settings_send_group_message_mms"
...@@ -338,7 +358,8 @@ ...@@ -338,7 +358,8 @@
android:id="@+id/settings_mms_file_size_limit_holder" android:id="@+id/settings_mms_file_size_limit_holder"
style="@style/SettingsHolderTextViewStyle" style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_mms_file_size_limit_label" android:id="@+id/settings_mms_file_size_limit_label"
...@@ -359,20 +380,23 @@ ...@@ -359,20 +380,23 @@
<include <include
android:id="@+id/settings_outgoing_messages_divider" android:id="@+id/settings_outgoing_messages_divider"
layout="@layout/divider" /> layout="@layout/divider"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/settings_recycle_bin_label" android:id="@+id/settings_recycle_bin_label"
style="@style/SettingsSectionLabelStyle" style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/recycle_bin" /> android:text="@string/recycle_bin"
android:visibility="gone" />
<RelativeLayout <RelativeLayout
android:id="@+id/settings_use_recycle_bin_holder" android:id="@+id/settings_use_recycle_bin_holder"
style="@style/SettingsHolderCheckboxStyle" style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox <com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_use_recycle_bin" android:id="@+id/settings_use_recycle_bin"
...@@ -387,7 +411,8 @@ ...@@ -387,7 +411,8 @@
android:id="@+id/settings_empty_recycle_bin_holder" android:id="@+id/settings_empty_recycle_bin_holder"
style="@style/SettingsHolderTextViewStyle" style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_empty_recycle_bin_label" android:id="@+id/settings_empty_recycle_bin_label"
...@@ -408,20 +433,23 @@ ...@@ -408,20 +433,23 @@
<include <include
android:id="@+id/settings_recycle_bin_divider" android:id="@+id/settings_recycle_bin_divider"
layout="@layout/divider" /> layout="@layout/divider"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/settings_security_label" android:id="@+id/settings_security_label"
style="@style/SettingsSectionLabelStyle" style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/security" /> android:text="@string/security"
android:visibility="gone" />
<RelativeLayout <RelativeLayout
android:id="@+id/settings_app_password_protection_holder" android:id="@+id/settings_app_password_protection_holder"
style="@style/SettingsHolderCheckboxStyle" style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox <com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_app_password_protection" android:id="@+id/settings_app_password_protection"
...@@ -434,20 +462,23 @@ ...@@ -434,20 +462,23 @@
<include <include
android:id="@+id/settings_migrating_divider" android:id="@+id/settings_migrating_divider"
layout="@layout/divider" /> layout="@layout/divider"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/settings_migrating_label" android:id="@+id/settings_migrating_label"
style="@style/SettingsSectionLabelStyle" style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/migrating" /> android:text="@string/migrating"
android:visibility="gone" />
<RelativeLayout <RelativeLayout
android:id="@+id/settings_export_messages_holder" android:id="@+id/settings_export_messages_holder"
style="@style/SettingsHolderTextViewOneLinerStyle" style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_export_messages" android:id="@+id/settings_export_messages"
...@@ -462,7 +493,8 @@ ...@@ -462,7 +493,8 @@
android:id="@+id/settings_import_messages_holder" android:id="@+id/settings_import_messages_holder"
style="@style/SettingsHolderTextViewOneLinerStyle" style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_import_messages" android:id="@+id/settings_import_messages"
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
android:id="@+id/settings" android:id="@+id/settings"
android:icon="@drawable/ic_settings_cog_vector" android:icon="@drawable/ic_settings_cog_vector"
android:title="@string/settings" android:title="@string/settings"
android:visible="false"
app:showAsAction="always" /> app:showAsAction="always" />
<item <item
android:id="@+id/about" android:id="@+id/about"
......
package com.simplemobiletools.commons.activities
import android.app.Activity
import android.app.Application
import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.runtime.*
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewModelScope
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
import com.simplemobiletools.commons.compose.extensions.onEventValue
import com.simplemobiletools.commons.compose.screens.ManageBlockedNumbersScreen
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.dialogs.AddOrEditBlockedNumberAlertDialog
import com.simplemobiletools.commons.dialogs.ExportBlockedNumbersDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.BlockedNumber
import java.io.FileOutputStream
import java.io.OutputStream
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class ManageBlockedNumbersActivity : BaseSimpleActivity() {
private val config by lazy {
baseConfig
}
private companion object {
private const val PICK_IMPORT_SOURCE_INTENT = 11
private const val PICK_EXPORT_FILE_INTENT = 21
}
override fun getAppIconIDs() = intent.getIntegerArrayListExtra(APP_ICON_IDS) ?: ArrayList()
//
override fun getAppLauncherName() = intent.getStringExtra(APP_LAUNCHER_NAME) ?: ""
private val manageBlockedNumbersViewModel by viewModels<ManageBlockedNumbersViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdgeSimple()
setContent {
val context = LocalContext.current
val blockedNumbers by manageBlockedNumbersViewModel.blockedNumbers.collectAsStateWithLifecycle()
LaunchedEffect(blockedNumbers) {
if (blockedNumbers?.any { blockedNumber -> blockedNumber.number.isBlockedNumberPattern() } == true) {
maybeSetDefaultCallerIdApp()
}
}
val isBlockingHiddenNumbers by config.isBlockingHiddenNumbers.collectAsStateWithLifecycle(initialValue = config.blockHiddenNumbers)
val isBlockingUnknownNumbers by config.isBlockingUnknownNumbers.collectAsStateWithLifecycle(initialValue = config.blockUnknownNumbers)
val isDialer = remember {
config.appId.startsWith("com.secspace.dialer")
}
val isDefaultDialer: Boolean = onEventValue {
context.isDefaultDialer()
}
AppThemeSurface {
var clickedBlockedNumber by remember { mutableStateOf<BlockedNumber?>(null) }
val addBlockedNumberDialogState = rememberAlertDialogState()
addBlockedNumberDialogState.DialogMember {
AddOrEditBlockedNumberAlertDialog(
alertDialogState = addBlockedNumberDialogState,
blockedNumber = clickedBlockedNumber,
deleteBlockedNumber = { blockedNumber ->
deleteBlockedNumber(blockedNumber)
updateBlockedNumbers()
}
) { blockedNumber ->
addBlockedNumber(blockedNumber)
clickedBlockedNumber = null
updateBlockedNumbers()
}
}
ManageBlockedNumbersScreen(
goBack = ::finish,
onAdd = {
clickedBlockedNumber = null
addBlockedNumberDialogState.show()
},
onImportBlockedNumbers = ::tryImportBlockedNumbers,
onExportBlockedNumbers = ::tryExportBlockedNumbers,
setAsDefault = ::maybeSetDefaultCallerIdApp,
isDialer = isDialer,
hasGivenPermissionToBlock = isDefaultDialer,
isBlockUnknownSelected = isBlockingUnknownNumbers,
onBlockUnknownSelectedChange = { isChecked ->
config.blockUnknownNumbers = isChecked
onCheckedSetCallerIdAsDefault(isChecked)
},
isHiddenSelected = isBlockingHiddenNumbers,
onHiddenSelectedChange = { isChecked ->
config.blockHiddenNumbers = isChecked
onCheckedSetCallerIdAsDefault(isChecked)
},
blockedNumbers = blockedNumbers,
onDelete = { selectedKeys ->
deleteBlockedNumbers(blockedNumbers, selectedKeys)
},
onEdit = { blockedNumber ->
clickedBlockedNumber = blockedNumber
addBlockedNumberDialogState.show()
},
onCopy = { blockedNumber ->
copyToClipboard(blockedNumber.number)
}
)
}
}
}
private fun deleteBlockedNumbers(
blockedNumbers: ImmutableList<BlockedNumber>?,
selectedKeys: Set<Long>
) {
if (blockedNumbers.isNullOrEmpty()) return
blockedNumbers.filter { blockedNumber -> selectedKeys.contains(blockedNumber.id) }
.forEach { blockedNumber ->
deleteBlockedNumber(blockedNumber.number)
}
manageBlockedNumbersViewModel.updateBlockedNumbers()
}
private fun tryImportBlockedNumbers() {
if (isQPlus()) {
Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "text/plain"
try {
startActivityForResult(this, PICK_IMPORT_SOURCE_INTENT)
} catch (e: ActivityNotFoundException) {
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: Exception) {
showErrorToast(e)
}
}
} else {
handlePermission(PERMISSION_READ_STORAGE) { isAllowed ->
if (isAllowed) {
pickFileToImportBlockedNumbers()
}
}
}
}
private fun pickFileToImportBlockedNumbers() {
FilePickerDialog(this) {
importBlockedNumbers(it)
}
}
private fun tryImportBlockedNumbersFromFile(uri: Uri) {
when (uri.scheme) {
"file" -> importBlockedNumbers(uri.path!!)
"content" -> {
val tempFile = getTempFile("blocked", "blocked_numbers.txt")
if (tempFile == null) {
toast(R.string.unknown_error_occurred)
return
}
try {
val inputStream = contentResolver.openInputStream(uri)
val out = FileOutputStream(tempFile)
inputStream!!.copyTo(out)
importBlockedNumbers(tempFile.absolutePath)
} catch (e: Exception) {
showErrorToast(e)
}
}
else -> toast(R.string.invalid_file_format)
}
}
private fun importBlockedNumbers(path: String) {
ensureBackgroundThread {
val result = BlockedNumbersImporter(this).importBlockedNumbers(path)
toast(
when (result) {
BlockedNumbersImporter.ImportResult.IMPORT_OK -> R.string.importing_successful
BlockedNumbersImporter.ImportResult.IMPORT_FAIL -> R.string.no_items_found
}
)
updateBlockedNumbers()
}
}
private fun updateBlockedNumbers() {
manageBlockedNumbersViewModel.updateBlockedNumbers()
}
private fun onCheckedSetCallerIdAsDefault(isChecked: Boolean) {
if (isChecked) {
maybeSetDefaultCallerIdApp()
}
}
private fun maybeSetDefaultCallerIdApp() {
if (isQPlus() && baseConfig.appId.startsWith("com.simplemobiletools.dialer")) {
setDefaultCallerIdApp()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
super.onActivityResult(requestCode, resultCode, resultData)
when {
requestCode == REQUEST_CODE_SET_DEFAULT_DIALER && isDefaultDialer() -> {
updateBlockedNumbers()
}
requestCode == PICK_IMPORT_SOURCE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null -> {
tryImportBlockedNumbersFromFile(resultData.data!!)
}
requestCode == PICK_EXPORT_FILE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null -> {
val outputStream = contentResolver.openOutputStream(resultData.data!!)
exportBlockedNumbersTo(outputStream)
}
requestCode == REQUEST_CODE_SET_DEFAULT_CALLER_ID && resultCode != Activity.RESULT_OK -> {
toast(R.string.must_make_default_caller_id_app, length = Toast.LENGTH_LONG)
baseConfig.blockUnknownNumbers = false
baseConfig.blockHiddenNumbers = false
}
}
}
private fun exportBlockedNumbersTo(outputStream: OutputStream?) {
ensureBackgroundThread {
val blockedNumbers = getBlockedNumbers()
if (blockedNumbers.isEmpty()) {
toast(R.string.no_entries_for_exporting)
} else {
BlockedNumbersExporter.exportBlockedNumbers(blockedNumbers, outputStream) {
toast(
when (it) {
ExportResult.EXPORT_OK -> R.string.exporting_successful
else -> R.string.exporting_failed
}
)
}
}
}
}
private fun tryExportBlockedNumbers() {
if (isQPlus()) {
ExportBlockedNumbersDialog(this, baseConfig.lastBlockedNumbersExportPath, true) { file ->
Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TITLE, file.name)
addCategory(Intent.CATEGORY_OPENABLE)
try {
startActivityForResult(this, PICK_EXPORT_FILE_INTENT)
} catch (e: ActivityNotFoundException) {
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: Exception) {
showErrorToast(e)
}
}
}
} else {
handlePermission(PERMISSION_WRITE_STORAGE) { isAllowed ->
if (isAllowed) {
ExportBlockedNumbersDialog(this, baseConfig.lastBlockedNumbersExportPath, false) { file ->
getFileOutputStream(file.toFileDirItem(this), true) { out ->
exportBlockedNumbersTo(out)
}
}
}
}
}
}
internal class ManageBlockedNumbersViewModel(
private val application: Application
) : AndroidViewModel(application) {
private val _blockedNumbers: MutableStateFlow<ImmutableList<BlockedNumber>?> = MutableStateFlow(null)
val blockedNumbers = _blockedNumbers.asStateFlow()
init {
updateBlockedNumbers()
}
fun updateBlockedNumbers() {
viewModelScope.launch {
withContext(Dispatchers.IO) {
application.getBlockedNumbersWithContact { list ->
_blockedNumbers.update { list.toImmutableList() }
}
}
}
}
}
}
...@@ -141,7 +141,7 @@ internal fun ManageBlockedNumbersScreen( ...@@ -141,7 +141,7 @@ internal fun ManageBlockedNumbersScreen(
} }
} }
SettingsCheckBoxComponent( /* SettingsCheckBoxComponent(
label = if (isDialer) stringResource(id = R.string.block_not_stored_calls) else stringResource(id = R.string.block_not_stored_messages), label = if (isDialer) stringResource(id = R.string.block_not_stored_calls) else stringResource(id = R.string.block_not_stored_messages),
initialValue = isBlockUnknownSelected, initialValue = isBlockUnknownSelected,
onChange = onBlockUnknownSelectedChange, onChange = onBlockUnknownSelectedChange,
...@@ -152,7 +152,7 @@ internal fun ManageBlockedNumbersScreen( ...@@ -152,7 +152,7 @@ internal fun ManageBlockedNumbersScreen(
initialValue = isHiddenSelected, initialValue = isHiddenSelected,
onChange = onHiddenSelectedChange, onChange = onHiddenSelectedChange,
modifier = startingPadding.then(Modifier.topAppBarPaddings()), modifier = startingPadding.then(Modifier.topAppBarPaddings()),
) )*/
SettingsHorizontalDivider(modifier = Modifier.topAppBarPaddings()) SettingsHorizontalDivider(modifier = Modifier.topAppBarPaddings())
} }
}, },
...@@ -565,8 +565,8 @@ private fun NonActionModeToolbar( ...@@ -565,8 +565,8 @@ private fun NonActionModeToolbar(
val actionMenus = remember { val actionMenus = remember {
listOf( listOf(
ActionItem(R.string.add_a_blocked_number, icon = Icons.Filled.Add, doAction = onAdd), ActionItem(R.string.add_a_blocked_number, icon = Icons.Filled.Add, doAction = onAdd),
ActionItem(R.string.import_blocked_numbers, doAction = onImportBlockedNumbers, overflowMode = OverflowMode.ALWAYS_OVERFLOW), /* ActionItem(R.string.import_blocked_numbers, doAction = onImportBlockedNumbers, overflowMode = OverflowMode.ALWAYS_OVERFLOW),
ActionItem(R.string.export_blocked_numbers, doAction = onExportBlockedNumbers, overflowMode = OverflowMode.ALWAYS_OVERFLOW), ActionItem(R.string.export_blocked_numbers, doAction = onExportBlockedNumbers, overflowMode = OverflowMode.ALWAYS_OVERFLOW),*/
).toImmutableList() ).toImmutableList()
} }
var isMenuVisible by remember { mutableStateOf(false) } var isMenuVisible by remember { mutableStateOf(false) }
......
...@@ -523,11 +523,12 @@ fun Context.getCustomizeColorsString(): String { ...@@ -523,11 +523,12 @@ fun Context.getCustomizeColorsString(): String {
} }
fun Context.addLockedLabelIfNeeded(stringId: Int): String { fun Context.addLockedLabelIfNeeded(stringId: Int): String {
return if (isOrWasThankYouInstalled()) { /*return if (isOrWasThankYouInstalled()) {
getString(stringId) getString(stringId)
} else { } else {
"${getString(stringId)} (${getString(R.string.feature_locked)})" "${getString(stringId)} (${getString(R.string.feature_locked)})"
} }*/
return getString(stringId)
} }
fun Context.isPackageInstalled(pkgName: String): Boolean { fun Context.isPackageInstalled(pkgName: String): Boolean {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment