allow removing contacts from groups by long pressing them and selecting Remove

This commit is contained in:
tibbi 2018-03-20 15:13:49 +01:00
parent 40f1fc82dd
commit 6d4f9912fd
4 changed files with 25 additions and 10 deletions

View File

@ -11,11 +11,12 @@ import com.simplemobiletools.contacts.extensions.editContact
import com.simplemobiletools.contacts.extensions.tryStartCall
import com.simplemobiletools.contacts.extensions.viewContact
import com.simplemobiletools.contacts.helpers.*
import com.simplemobiletools.contacts.interfaces.RemoveFromGroupListener
import com.simplemobiletools.contacts.models.Contact
import com.simplemobiletools.contacts.models.Group
import kotlinx.android.synthetic.main.activity_group_contacts.*
class GroupContactsActivity : SimpleActivity() {
class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener {
private var allContacts = ArrayList<Contact>()
private var groupContacts = ArrayList<Contact>()
lateinit var group: Group
@ -53,7 +54,7 @@ class GroupContactsActivity : SimpleActivity() {
}
private fun updateContacts(contacts: ArrayList<Contact>) {
ContactsAdapter(this, contacts, null, LOCATION_GROUP_CONTACTS, group_contacts_list, group_contacts_fastscroller) {
ContactsAdapter(this, contacts, null, LOCATION_GROUP_CONTACTS, this, group_contacts_list, group_contacts_fastscroller) {
when (config.onContactClick) {
ON_CLICK_CALL_CONTACT -> {
val contact = it as Contact
@ -78,4 +79,8 @@ class GroupContactsActivity : SimpleActivity() {
group_contacts_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
}
}
override fun removeFromGroup(contacts: ArrayList<Contact>) {
ContactsHelper(this).removeContactsFromGroup(contacts, group.id)
}
}

View File

@ -26,12 +26,14 @@ import com.simplemobiletools.contacts.helpers.LOCATION_CONTACTS_TAB
import com.simplemobiletools.contacts.helpers.LOCATION_FAVORITES_TAB
import com.simplemobiletools.contacts.helpers.LOCATION_GROUP_CONTACTS
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
import com.simplemobiletools.contacts.interfaces.RemoveFromGroupListener
import com.simplemobiletools.contacts.models.Contact
import kotlinx.android.synthetic.main.item_contact_with_number.view.*
import java.util.*
class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Contact>, private val listener: RefreshContactsListener?,
private val location: Int, recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) :
class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Contact>, private val refreshListener: RefreshContactsListener?,
private val location: Int, private val removeListener: RemoveFromGroupListener?, recyclerView: MyRecyclerView,
fastScroller: FastScroller, itemClick: (Any) -> Unit) :
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
private lateinit var contactDrawable: Drawable
@ -136,11 +138,11 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
ContactsHelper(activity).deleteContacts(contactsToRemove)
if (contactItems.isEmpty()) {
listener?.refreshContacts(true, true)
refreshListener?.refreshContacts(true, true)
finishActMode()
} else {
removeSelectedItems()
listener?.refreshFavorites()
refreshListener?.refreshFavorites()
}
}
@ -154,13 +156,14 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
if (location == LOCATION_FAVORITES_TAB) {
ContactsHelper(activity).removeFavorites(contactsToRemove)
if (contactItems.isEmpty()) {
listener?.refreshFavorites()
refreshListener?.refreshFavorites()
finishActMode()
} else {
removeSelectedItems()
}
} else if (location == LOCATION_GROUP_CONTACTS) {
removeListener?.removeFromGroup(contactsToRemove)
removeSelectedItems()
}
}
@ -168,7 +171,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
val newFavorites = ArrayList<Contact>()
selectedPositions.forEach { newFavorites.add(contactItems[it]) }
ContactsHelper(activity).addFavorites(newFavorites)
listener?.refreshFavorites()
refreshListener?.refreshFavorites()
finishActMode()
}

View File

@ -109,7 +109,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
if (currAdapter == null || forceListRedraw) {
forceListRedraw = false
val location = if (this is FavoritesFragment) LOCATION_FAVORITES_TAB else LOCATION_CONTACTS_TAB
ContactsAdapter(activity as SimpleActivity, contacts, activity, location, fragment_list, fragment_fastscroller) {
ContactsAdapter(activity as SimpleActivity, contacts, activity, location, null, fragment_list, fragment_fastscroller) {
when (config.onContactClick) {
ON_CLICK_CALL_CONTACT -> {
val contact = it as Contact

View File

@ -0,0 +1,7 @@
package com.simplemobiletools.contacts.interfaces
import com.simplemobiletools.contacts.models.Contact
interface RemoveFromGroupListener {
fun removeFromGroup(contacts: ArrayList<Contact>)
}