allow editing blocked numbers

This commit is contained in:
tibbi 2018-11-30 16:13:07 +01:00
parent 841a13b068
commit b6e00fba44
3 changed files with 22 additions and 11 deletions

View file

@ -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()
}
}

View file

@ -105,6 +105,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
getSelectedItems().forEach {
activity.addBlockedNumber(it.number)
}
refreshListener?.refreshContacts(RECENTS_TAB_MASK)
activity.runOnUiThread {
finishActMode()

View file

@ -7,12 +7,17 @@ import com.simplemobiletools.commons.extensions.showKeyboard
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.extensions.addBlockedNumber
import com.simplemobiletools.contacts.pro.extensions.deleteBlockedNumber
import com.simplemobiletools.contacts.pro.models.BlockedNumber
import kotlinx.android.synthetic.main.dialog_add_blocked_number.view.*
class AddBlockedNumberDialog(val activity: BaseSimpleActivity, val callback: () -> 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()