provide contacts to show at SelectContactsDialog explicitly

This commit is contained in:
tibbi 2018-03-20 10:54:35 +01:00
parent ce917560da
commit 5e585eec71
4 changed files with 32 additions and 24 deletions

View File

@ -16,6 +16,8 @@ import com.simplemobiletools.contacts.models.Group
import kotlinx.android.synthetic.main.activity_group_contacts.*
class GroupContactsActivity : SimpleActivity() {
private var allContacts = ArrayList<Contact>()
private var groupContacts = ArrayList<Contact>()
lateinit var group: Group
override fun onCreate(savedInstanceState: Bundle?) {
@ -28,7 +30,7 @@ class GroupContactsActivity : SimpleActivity() {
refreshContacts()
group_contacts_fab.setOnClickListener {
SelectContactsDialog(this) { displayedContacts, selectedContacts ->
SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts ->
refreshContacts()
}
}
@ -36,15 +38,17 @@ class GroupContactsActivity : SimpleActivity() {
private fun refreshContacts() {
ContactsHelper(this).getContacts {
val contacts = it.filter { it.groups.map { it.id }.contains(group.id) } as ArrayList<Contact>
updateContacts(contacts)
allContacts = it
groupContacts = it.filter { it.groups.map { it.id }.contains(group.id) } as ArrayList<Contact>
Contact.sorting = config.sorting
groupContacts.sort()
updateContacts(groupContacts)
}
}
private fun updateContacts(contacts: ArrayList<Contact>) {
Contact.sorting = config.sorting
contacts.sort()
ContactsAdapter(this, contacts, null, LOCATION_GROUP_CONTACTS, group_contacts_list, group_contacts_fastscroller) {
when (config.onContactClick) {
ON_CLICK_CALL_CONTACT -> {

View File

@ -7,35 +7,36 @@ import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.SimpleActivity
import com.simplemobiletools.contacts.adapters.SelectContactsAdapter
import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.helpers.ContactsHelper
import com.simplemobiletools.contacts.models.Contact
import kotlinx.android.synthetic.main.layout_select_contact.view.*
class SelectContactsDialog(val activity: SimpleActivity, private val callback: (addedContacts: ArrayList<Contact>, removedContacts: ArrayList<Contact>) -> Unit) {
class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayList<Contact>, val selectContacts: ArrayList<Contact>? = null,
val callback: (addedContacts: ArrayList<Contact>, removedContacts: ArrayList<Contact>) -> Unit) {
private var view = activity.layoutInflater.inflate(R.layout.layout_select_contact, null)
private var initiallySelectedContacts = ArrayList<Contact>()
init {
ContactsHelper(activity).getContacts {
var allContacts = it
var allContacts = initialContacts
if (selectContacts == null) {
val contactSources = activity.config.displayContactSources
if (!activity.config.showAllContacts()) {
allContacts = allContacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
}
initiallySelectedContacts = allContacts.filter { it.starred == 1 } as ArrayList<Contact>
} else {
initiallySelectedContacts = selectContacts
}
Contact.sorting = activity.config.sorting
allContacts.sort()
Contact.sorting = activity.config.sorting
allContacts.sort()
activity.runOnUiThread {
view.apply {
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, initiallySelectedContacts, true)
select_contact_fastscroller.allowBubbleDisplay = activity.baseConfig.showInfoBubble
select_contact_fastscroller.setViews(select_contact_list) {
select_contact_fastscroller.updateBubbleText(allContacts[it].getBubbleText())
}
activity.runOnUiThread {
view.apply {
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, initiallySelectedContacts, true)
select_contact_fastscroller.allowBubbleDisplay = activity.baseConfig.showInfoBubble
select_contact_fastscroller.setViews(select_contact_list) {
select_contact_fastscroller.updateBubbleText(allContacts[it].getBubbleText())
}
}
}

View File

@ -17,7 +17,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
}
private fun showAddFavoritesDialog() {
SelectContactsDialog(activity!!) { addedContacts, removedContacts ->
SelectContactsDialog(activity!!, allContacts) { addedContacts, removedContacts ->
ContactsHelper(activity as SimpleActivity).apply {
addFavorites(addedContacts)
removeFavorites(removedContacts)

View File

@ -22,6 +22,8 @@ import kotlinx.android.synthetic.main.fragment_layout.view.*
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet), FragmentInterface {
protected var activity: MainActivity? = null
protected var allContacts = ArrayList<Contact>()
private var lastHashCode = 0
private var contactsIgnoringSearch = ArrayList<Contact>()
private lateinit var config: Config
@ -75,6 +77,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
config.lastUsedContactSource = grouped?.key ?: ""
}
Contact.sorting = config.sorting
contacts.sort()
allContacts = contacts
val filtered = if (this is FavoritesFragment) {
contacts.filter { it.starred == 1 } as ArrayList<Contact>
} else {
@ -86,9 +92,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
}
Contact.sorting = config.sorting
filtered.sort()
if (filtered.hashCode() != lastHashCode) {
lastHashCode = filtered.hashCode()
activity?.runOnUiThread {