lets lock number blocking

This commit is contained in:
tibbi 2022-11-13 20:14:46 +01:00
parent 3092253022
commit c8818bfa57
4 changed files with 33 additions and 4 deletions

View File

@ -63,7 +63,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:9162225f33'
implementation 'com.github.SimpleMobileTools:Simple-Commons:5b5a6b083f'
implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
implementation 'com.github.tibbi:android-smsmms:3581774c39'

View File

@ -6,6 +6,7 @@ import android.os.Build
import android.os.Bundle
import com.simplemobiletools.commons.activities.ManageBlockedNumbersActivity
import com.simplemobiletools.commons.dialogs.ChangeDateTimeFormatDialog
import com.simplemobiletools.commons.dialogs.FeatureLockedDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
@ -128,9 +129,17 @@ class SettingsActivity : SimpleActivity() {
// support for device-wise blocking came on Android 7, rely only on that
@TargetApi(Build.VERSION_CODES.N)
private fun setupManageBlockedNumbers() {
settings_manage_blocked_numbers.text = addLockedLabelIfNeeded(R.string.manage_blocked_numbers)
settings_manage_blocked_numbers_holder.beVisibleIf(isNougatPlus())
settings_manage_blocked_numbers_holder.setOnClickListener {
startActivity(Intent(this, ManageBlockedNumbersActivity::class.java))
if (isOrWasThankYouInstalled()) {
Intent(this, ManageBlockedNumbersActivity::class.java).apply {
startActivity(this)
}
} else {
FeatureLockedDialog(this) { }
}
}
}

View File

@ -39,6 +39,7 @@ import androidx.core.view.*
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.FeatureLockedDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
@ -182,6 +183,7 @@ class ThreadActivity : SimpleActivity() {
val firstPhoneNumber = participants.firstOrNull()?.phoneNumbers?.firstOrNull()?.value
thread_toolbar.menu.apply {
findItem(R.id.delete).isVisible = threadItems.isNotEmpty()
findItem(R.id.block_number).title = addLockedLabelIfNeeded(R.string.block_number)
findItem(R.id.block_number).isVisible = isNougatPlus()
findItem(R.id.dial_number).isVisible = participants.size == 1
findItem(R.id.mark_as_unread).isVisible = threadItems.isNotEmpty()
@ -200,7 +202,7 @@ class ThreadActivity : SimpleActivity() {
}
when (menuItem.itemId) {
R.id.block_number -> blockNumber()
R.id.block_number -> tryBlocking()
R.id.delete -> askConfirmDelete()
R.id.add_number_to_contact -> addNumberToContact()
R.id.dial_number -> dialNumber()
@ -652,6 +654,14 @@ class ThreadActivity : SimpleActivity() {
return userPreferredSimIdx ?: senderPreferredSimIdx ?: systemPreferredSimIdx ?: 0
}
private fun tryBlocking() {
if (isOrWasThankYouInstalled()) {
blockNumber()
} else {
FeatureLockedDialog(this) { }
}
}
private fun blockNumber() {
val numbers = participants.getAddresses()
val numbersString = TextUtils.join(", ", numbers)

View File

@ -12,6 +12,7 @@ import com.bumptech.glide.Glide
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.FeatureLockedDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.KEY_PHONE
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
@ -42,6 +43,7 @@ class ConversationsAdapter(
val selectedItems = getSelectedItems()
menu.apply {
findItem(R.id.cab_block_number).title = activity.addLockedLabelIfNeeded(R.string.block_number)
findItem(R.id.cab_block_number).isVisible = isNougatPlus()
findItem(R.id.cab_add_number_to_contact).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.isGroupConversation == false
findItem(R.id.cab_dial_number).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.isGroupConversation == false
@ -59,7 +61,7 @@ class ConversationsAdapter(
when (id) {
R.id.cab_add_number_to_contact -> addNumberToContact()
R.id.cab_block_number -> askConfirmBlock()
R.id.cab_block_number -> tryBlocking()
R.id.cab_dial_number -> dialNumber()
R.id.cab_copy_number -> copyNumberToClipboard()
R.id.cab_delete -> askConfirmDelete()
@ -102,6 +104,14 @@ class ConversationsAdapter(
}
}
private fun tryBlocking() {
if (activity.isOrWasThankYouInstalled()) {
askConfirmBlock()
} else {
FeatureLockedDialog(activity) { }
}
}
private fun askConfirmBlock() {
val numbers = getSelectedItems().distinctBy { it.phoneNumber }.map { it.phoneNumber }
val numbersString = TextUtils.join(", ", numbers)