From 34fe393ea7ac51e523eaa94c5024f7ab66e3f8d5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 6 Apr 2020 10:12:49 +0200 Subject: [PATCH] remove the selected contact at pressing X --- .../activities/NewMessageActivity.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/NewMessageActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/NewMessageActivity.kt index faa48334..c741b25c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/NewMessageActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/NewMessageActivity.kt @@ -78,14 +78,21 @@ class NewMessageActivity : SimpleActivity() { } selectedContacts.add(contact) + showSelectedContacts() + } - selected_contacts.beVisible() - message_divider_one.beVisible() + private fun showSelectedContacts() { + selected_contacts.beVisibleIf(selectedContacts.isNotEmpty()) + message_divider_one.beVisibleIf(selectedContacts.isNotEmpty()) val views = ArrayList() selectedContacts.forEach { + val contact = it layoutInflater.inflate(R.layout.item_selected_contact, null).apply { - selected_contact_name.text = it.name + selected_contact_name.text = contact.name + selected_contact_remove.setOnClickListener { + removeSelectedContact(contact.contactId) + } views.add(this) } } @@ -139,6 +146,11 @@ class NewMessageActivity : SimpleActivity() { selected_contacts.addView(newLinearLayout) } + private fun removeSelectedContact(id: Int) { + selectedContacts = selectedContacts.filter { it.contactId != id }.toMutableList() as ArrayList + showSelectedContacts() + } + private fun getNames(): List { val contacts = ArrayList() val uri = ContactsContract.Data.CONTENT_URI