handle deleting speed dials

This commit is contained in:
tibbi 2020-01-20 14:50:02 +01:00
parent 021d87c89f
commit 7c2ca77e7a
3 changed files with 34 additions and 4 deletions

View File

@ -8,11 +8,12 @@ import com.simplemobiletools.contacts.pro.adapters.SpeedDialAdapter
import com.simplemobiletools.contacts.pro.dialogs.SelectContactsDialog
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
import com.simplemobiletools.contacts.pro.interfaces.RemoveSpeedDialListener
import com.simplemobiletools.contacts.pro.models.Contact
import com.simplemobiletools.contacts.pro.models.SpeedDial
import kotlinx.android.synthetic.main.activity_manage_speed_dial.*
class ManageSpeedDialActivity : SimpleActivity() {
class ManageSpeedDialActivity : SimpleActivity(), RemoveSpeedDialListener {
private var allContacts = ArrayList<Contact>()
private var speedDialValues = ArrayList<SpeedDial>()
@ -42,7 +43,7 @@ class ManageSpeedDialActivity : SimpleActivity() {
}
private fun updateAdapter() {
SpeedDialAdapter(this, speedDialValues, speed_dial_list) {
SpeedDialAdapter(this, speedDialValues, this, speed_dial_list) {
val clickedContact = it as SpeedDial
if (allContacts.isEmpty()) {
return@SpeedDialAdapter
@ -60,4 +61,15 @@ class ManageSpeedDialActivity : SimpleActivity() {
speed_dial_list.adapter = this
}
}
override fun removeSpeedDial(ids: ArrayList<Int>) {
ids.forEach {
val dialId = it
speedDialValues.first { it.id == dialId }.apply {
displayName = ""
number = ""
}
}
updateAdapter()
}
}

View File

@ -7,12 +7,13 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.interfaces.RemoveSpeedDialListener
import com.simplemobiletools.contacts.pro.models.SpeedDial
import kotlinx.android.synthetic.main.item_speed_dial.view.*
import java.util.*
class SpeedDialAdapter(activity: SimpleActivity, var speedDialValues: ArrayList<SpeedDial>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
class SpeedDialAdapter(activity: SimpleActivity, var speedDialValues: ArrayList<SpeedDial>, private val removeListener: RemoveSpeedDialListener,
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
init {
setupDragListener(true)
@ -26,6 +27,10 @@ class SpeedDialAdapter(activity: SimpleActivity, var speedDialValues: ArrayList<
if (selectedKeys.isEmpty()) {
return
}
when (id) {
R.id.cab_delete -> deleteSpeedDial()
}
}
override fun getSelectableItemCount() = speedDialValues.size
@ -52,6 +57,14 @@ class SpeedDialAdapter(activity: SimpleActivity, var speedDialValues: ArrayList<
override fun getItemCount() = speedDialValues.size
private fun getSelectedItems() = speedDialValues.filter { selectedKeys.contains(it.hashCode()) } as ArrayList<SpeedDial>
private fun deleteSpeedDial() {
val ids = getSelectedItems().map { it.id }.toMutableList() as ArrayList<Int>
removeListener.removeSpeedDial(ids)
finishActMode()
}
private fun setupView(view: View, speedDial: SpeedDial) {
view.apply {
var text = "${speedDial.id}. "

View File

@ -0,0 +1,5 @@
package com.simplemobiletools.contacts.pro.interfaces
interface RemoveSpeedDialListener {
fun removeSpeedDial(ids: ArrayList<Int>)
}