properly handle removing blocked numbers from the managing activity

This commit is contained in:
tibbi 2018-11-30 15:38:18 +01:00
parent 64db7ac053
commit fa7a447369
2 changed files with 18 additions and 6 deletions

View file

@ -9,6 +9,7 @@ import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.extensions.deleteBlockedNumber
import com.simplemobiletools.contacts.pro.models.BlockedNumber
import kotlinx.android.synthetic.main.item_manage_blocked_number.view.*
import java.util.*
@ -43,9 +44,9 @@ class ManageBlockedNumbersAdapter(activity: BaseSimpleActivity, var blockedNumbe
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_manage_blocked_number, parent)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val folder = blockedNumbers[position]
holder.bindView(folder, true, true) { itemView, adapterPosition ->
setupView(itemView, folder)
val blockedNumber = blockedNumbers[position]
holder.bindView(blockedNumber, true, true) { itemView, adapterPosition ->
setupView(itemView, blockedNumber)
}
bindViewHolder(holder)
}
@ -65,14 +66,17 @@ class ManageBlockedNumbersAdapter(activity: BaseSimpleActivity, var blockedNumbe
}
private fun removeSelection() {
val removeFolders = ArrayList<BlockedNumber>(selectedKeys.size)
val removeBlockedNumbers = ArrayList<BlockedNumber>(selectedKeys.size)
val positions = getSelectedItemPositions()
getSelectedItems().forEach {
removeFolders.add(it)
removeBlockedNumbers.add(it)
Thread {
activity.deleteBlockedNumber(it.number)
}.start()
}
blockedNumbers.removeAll(removeFolders)
blockedNumbers.removeAll(removeBlockedNumbers)
removeSelectedItems(positions)
if (blockedNumbers.isEmpty()) {
listener?.refreshItems()

View file

@ -330,3 +330,11 @@ fun Context.addBlockedNumber(number: String) {
contentResolver.insert(BlockedNumbers.CONTENT_URI, this)
}
}
@TargetApi(Build.VERSION_CODES.N)
fun Context.deleteBlockedNumber(number: String) {
val values = ContentValues()
values.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, number)
val uri = contentResolver.insert(BlockedNumbers.CONTENT_URI, values)
contentResolver.delete(uri, null, null)
}