diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ManageBlockedNumbersActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ManageBlockedNumbersActivity.kt index a189df05..947a179b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ManageBlockedNumbersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ManageBlockedNumbersActivity.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.adapters.ManageBlockedNumbersAdapter import com.simplemobiletools.contacts.pro.dialogs.AddBlockedNumberDialog import com.simplemobiletools.contacts.pro.extensions.getBlockedNumbers +import com.simplemobiletools.contacts.pro.models.BlockedNumber import kotlinx.android.synthetic.main.activity_manage_blocked_numbers.* class ManageBlockedNumbersActivity : SimpleActivity(), RefreshRecyclerViewListener { @@ -25,7 +26,7 @@ class ManageBlockedNumbersActivity : SimpleActivity(), RefreshRecyclerViewListen underlineText() setTextColor(getAdjustedPrimaryColor()) setOnClickListener { - addBlockedNumber() + addOrEditBlockedNumber() } } } @@ -35,7 +36,7 @@ class ManageBlockedNumbersActivity : SimpleActivity(), RefreshRecyclerViewListen val blockedNumbers = getBlockedNumbers() runOnUiThread { ManageBlockedNumbersAdapter(this, blockedNumbers, this, manage_blocked_numbers_list) { - + addOrEditBlockedNumber(it as BlockedNumber) }.apply { manage_blocked_numbers_list.adapter = this } @@ -53,7 +54,7 @@ class ManageBlockedNumbersActivity : SimpleActivity(), RefreshRecyclerViewListen override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.add_blocked_number -> addBlockedNumber() + R.id.add_blocked_number -> addOrEditBlockedNumber() else -> return super.onOptionsItemSelected(item) } return true @@ -63,8 +64,8 @@ class ManageBlockedNumbersActivity : SimpleActivity(), RefreshRecyclerViewListen updateBlockedNumbers() } - private fun addBlockedNumber() { - AddBlockedNumberDialog(this) { + private fun addOrEditBlockedNumber(currentNumber: BlockedNumber? = null) { + AddBlockedNumberDialog(this, currentNumber) { updateBlockedNumbers() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/RecentCallsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/RecentCallsAdapter.kt index c6a29f07..41b24af4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/RecentCallsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/RecentCallsAdapter.kt @@ -105,6 +105,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList Unit) { +class AddBlockedNumberDialog(val activity: BaseSimpleActivity, val originalNumber: BlockedNumber? = null, val callback: () -> Unit) { init { - - val view = activity.layoutInflater.inflate(R.layout.dialog_add_blocked_number, null) + val view = activity.layoutInflater.inflate(R.layout.dialog_add_blocked_number, null).apply { + if (originalNumber != null) { + add_blocked_number_edittext.setText(originalNumber.number) + } + } AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, null) @@ -21,9 +26,13 @@ class AddBlockedNumberDialog(val activity: BaseSimpleActivity, val callback: () activity.setupDialogStuff(view, this) { showKeyboard(view.add_blocked_number_edittext) getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val phoneNumber = view.add_blocked_number_edittext.value - if (phoneNumber.isNotEmpty()) { - activity.addBlockedNumber(phoneNumber) + val newBlockedNumber = view.add_blocked_number_edittext.value + if (originalNumber != null && newBlockedNumber != originalNumber.number) { + activity.deleteBlockedNumber(originalNumber.number) + } + + if (newBlockedNumber.isNotEmpty()) { + activity.addBlockedNumber(newBlockedNumber) } callback()