list the blocked numbers at the particular activity

This commit is contained in:
tibbi 2018-11-30 15:28:57 +01:00
parent bf95eccce3
commit 64db7ac053
3 changed files with 88 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import com.simplemobiletools.commons.extensions.underlineText
import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.adapters.ManageBlockedNumbersAdapter
import com.simplemobiletools.contacts.pro.extensions.getBlockedNumbers import com.simplemobiletools.contacts.pro.extensions.getBlockedNumbers
import kotlinx.android.synthetic.main.activity_manage_blocked_numbers.* import kotlinx.android.synthetic.main.activity_manage_blocked_numbers.*
@ -31,6 +32,12 @@ class ManageBlockedNumbersActivity : SimpleActivity(), RefreshRecyclerViewListen
private fun updateBlockedNumbers() { private fun updateBlockedNumbers() {
Thread { Thread {
val blockedNumbers = getBlockedNumbers() val blockedNumbers = getBlockedNumbers()
ManageBlockedNumbersAdapter(this, blockedNumbers, this, manage_blocked_numbers_list) {
}.apply {
manage_blocked_numbers_list.adapter = this
}
runOnUiThread { runOnUiThread {
manage_blocked_numbers_placeholder.beVisibleIf(blockedNumbers.isEmpty()) manage_blocked_numbers_placeholder.beVisibleIf(blockedNumbers.isEmpty())
manage_blocked_numbers_placeholder_2.beVisibleIf(blockedNumbers.isEmpty()) manage_blocked_numbers_placeholder_2.beVisibleIf(blockedNumbers.isEmpty())

View File

@ -0,0 +1,81 @@
package com.simplemobiletools.contacts.pro.adapters
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
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.models.BlockedNumber
import kotlinx.android.synthetic.main.item_manage_blocked_number.view.*
import java.util.*
class ManageBlockedNumbersAdapter(activity: BaseSimpleActivity, var blockedNumbers: ArrayList<BlockedNumber>, val listener: RefreshRecyclerViewListener?,
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
private val config = activity.config
init {
setupDragListener(true)
}
override fun getActionMenuId() = R.menu.cab_remove_only
override fun prepareActionMode(menu: Menu) {}
override fun actionItemPressed(id: Int) {
when (id) {
R.id.cab_remove -> removeSelection()
}
}
override fun getSelectableItemCount() = blockedNumbers.size
override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = blockedNumbers.getOrNull(position)?.id?.toInt()
override fun getItemKeyPosition(key: Int) = blockedNumbers.indexOfFirst { it.id.toInt() == key }
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)
}
bindViewHolder(holder)
}
override fun getItemCount() = blockedNumbers.size
private fun getSelectedItems() = blockedNumbers.filter { selectedKeys.contains(it.id.toInt()) } as ArrayList<BlockedNumber>
private fun setupView(view: View, blockedNumber: BlockedNumber) {
view.apply {
manage_blocked_number_holder?.isSelected = selectedKeys.contains(blockedNumber.id.toInt())
manage_blocked_number_title.apply {
text = blockedNumber.number
setTextColor(config.textColor)
}
}
}
private fun removeSelection() {
val removeFolders = ArrayList<BlockedNumber>(selectedKeys.size)
val positions = getSelectedItemPositions()
getSelectedItems().forEach {
removeFolders.add(it)
}
blockedNumbers.removeAll(removeFolders)
removeSelectedItems(positions)
if (blockedNumbers.isEmpty()) {
listener?.refreshItems()
}
}
}