mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
provide contacts to show at SelectContactsDialog explicitly
This commit is contained in:
@ -16,6 +16,8 @@ import com.simplemobiletools.contacts.models.Group
|
|||||||
import kotlinx.android.synthetic.main.activity_group_contacts.*
|
import kotlinx.android.synthetic.main.activity_group_contacts.*
|
||||||
|
|
||||||
class GroupContactsActivity : SimpleActivity() {
|
class GroupContactsActivity : SimpleActivity() {
|
||||||
|
private var allContacts = ArrayList<Contact>()
|
||||||
|
private var groupContacts = ArrayList<Contact>()
|
||||||
lateinit var group: Group
|
lateinit var group: Group
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@ -28,7 +30,7 @@ class GroupContactsActivity : SimpleActivity() {
|
|||||||
|
|
||||||
refreshContacts()
|
refreshContacts()
|
||||||
group_contacts_fab.setOnClickListener {
|
group_contacts_fab.setOnClickListener {
|
||||||
SelectContactsDialog(this) { displayedContacts, selectedContacts ->
|
SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts ->
|
||||||
refreshContacts()
|
refreshContacts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,15 +38,17 @@ class GroupContactsActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun refreshContacts() {
|
private fun refreshContacts() {
|
||||||
ContactsHelper(this).getContacts {
|
ContactsHelper(this).getContacts {
|
||||||
val contacts = it.filter { it.groups.map { it.id }.contains(group.id) } as ArrayList<Contact>
|
allContacts = it
|
||||||
updateContacts(contacts)
|
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>) {
|
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) {
|
ContactsAdapter(this, contacts, null, LOCATION_GROUP_CONTACTS, group_contacts_list, group_contacts_fastscroller) {
|
||||||
when (config.onContactClick) {
|
when (config.onContactClick) {
|
||||||
ON_CLICK_CALL_CONTACT -> {
|
ON_CLICK_CALL_CONTACT -> {
|
||||||
|
@ -7,35 +7,36 @@ import com.simplemobiletools.contacts.R
|
|||||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||||
import com.simplemobiletools.contacts.adapters.SelectContactsAdapter
|
import com.simplemobiletools.contacts.adapters.SelectContactsAdapter
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
|
||||||
import com.simplemobiletools.contacts.models.Contact
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
import kotlinx.android.synthetic.main.layout_select_contact.view.*
|
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 view = activity.layoutInflater.inflate(R.layout.layout_select_contact, null)
|
||||||
private var initiallySelectedContacts = ArrayList<Contact>()
|
private var initiallySelectedContacts = ArrayList<Contact>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
ContactsHelper(activity).getContacts {
|
var allContacts = initialContacts
|
||||||
var allContacts = it
|
if (selectContacts == null) {
|
||||||
|
|
||||||
val contactSources = activity.config.displayContactSources
|
val contactSources = activity.config.displayContactSources
|
||||||
if (!activity.config.showAllContacts()) {
|
if (!activity.config.showAllContacts()) {
|
||||||
allContacts = allContacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
allContacts = allContacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
||||||
}
|
}
|
||||||
|
|
||||||
initiallySelectedContacts = allContacts.filter { it.starred == 1 } as ArrayList<Contact>
|
initiallySelectedContacts = allContacts.filter { it.starred == 1 } as ArrayList<Contact>
|
||||||
|
} else {
|
||||||
|
initiallySelectedContacts = selectContacts
|
||||||
|
}
|
||||||
|
|
||||||
Contact.sorting = activity.config.sorting
|
Contact.sorting = activity.config.sorting
|
||||||
allContacts.sort()
|
allContacts.sort()
|
||||||
|
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
view.apply {
|
view.apply {
|
||||||
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, initiallySelectedContacts, true)
|
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, initiallySelectedContacts, true)
|
||||||
select_contact_fastscroller.allowBubbleDisplay = activity.baseConfig.showInfoBubble
|
select_contact_fastscroller.allowBubbleDisplay = activity.baseConfig.showInfoBubble
|
||||||
select_contact_fastscroller.setViews(select_contact_list) {
|
select_contact_fastscroller.setViews(select_contact_list) {
|
||||||
select_contact_fastscroller.updateBubbleText(allContacts[it].getBubbleText())
|
select_contact_fastscroller.updateBubbleText(allContacts[it].getBubbleText())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showAddFavoritesDialog() {
|
private fun showAddFavoritesDialog() {
|
||||||
SelectContactsDialog(activity!!) { addedContacts, removedContacts ->
|
SelectContactsDialog(activity!!, allContacts) { addedContacts, removedContacts ->
|
||||||
ContactsHelper(activity as SimpleActivity).apply {
|
ContactsHelper(activity as SimpleActivity).apply {
|
||||||
addFavorites(addedContacts)
|
addFavorites(addedContacts)
|
||||||
removeFavorites(removedContacts)
|
removeFavorites(removedContacts)
|
||||||
|
@ -22,6 +22,8 @@ import kotlinx.android.synthetic.main.fragment_layout.view.*
|
|||||||
|
|
||||||
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet), FragmentInterface {
|
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet), FragmentInterface {
|
||||||
protected var activity: MainActivity? = null
|
protected var activity: MainActivity? = null
|
||||||
|
protected var allContacts = ArrayList<Contact>()
|
||||||
|
|
||||||
private var lastHashCode = 0
|
private var lastHashCode = 0
|
||||||
private var contactsIgnoringSearch = ArrayList<Contact>()
|
private var contactsIgnoringSearch = ArrayList<Contact>()
|
||||||
private lateinit var config: Config
|
private lateinit var config: Config
|
||||||
@ -75,6 +77,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||||||
config.lastUsedContactSource = grouped?.key ?: ""
|
config.lastUsedContactSource = grouped?.key ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Contact.sorting = config.sorting
|
||||||
|
contacts.sort()
|
||||||
|
allContacts = contacts
|
||||||
|
|
||||||
val filtered = if (this is FavoritesFragment) {
|
val filtered = if (this is FavoritesFragment) {
|
||||||
contacts.filter { it.starred == 1 } as ArrayList<Contact>
|
contacts.filter { it.starred == 1 } as ArrayList<Contact>
|
||||||
} else {
|
} else {
|
||||||
@ -86,9 +92,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact.sorting = config.sorting
|
|
||||||
filtered.sort()
|
|
||||||
|
|
||||||
if (filtered.hashCode() != lastHashCode) {
|
if (filtered.hashCode() != lastHashCode) {
|
||||||
lastHashCode = filtered.hashCode()
|
lastHashCode = filtered.hashCode()
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
|
Reference in New Issue
Block a user