properly update contact groups after modifying them

This commit is contained in:
tibbi 2018-03-18 17:33:43 +01:00
parent fe6a98815c
commit 9d9495ea80
2 changed files with 59 additions and 1 deletions

View File

@ -244,6 +244,7 @@ class EditContactActivity : ContactActivity() {
setupAddresses()
setupNotes()
setupEvents()
setupGroups()
}
private fun setupPhoneNumbers() {
@ -324,6 +325,56 @@ class EditContactActivity : ContactActivity() {
}
}
private fun setupGroups() {
contact_groups_holder.removeAllViews()
val groups = contact!!.groups
groups.forEachIndexed { index, group ->
var groupHolder = contact_groups_holder.getChildAt(index)
if (groupHolder == null) {
groupHolder = layoutInflater.inflate(R.layout.item_group, contact_groups_holder, false)
contact_groups_holder.addView(groupHolder)
}
(groupHolder as ViewGroup).apply {
contact_group.apply {
text = group.title
setTextColor(config.textColor)
tag = group.id
alpha = 1f
}
setOnClickListener {
showSelectGroupsDialog()
}
contact_group_remove.apply {
beVisible()
applyColorFilter(getAdjustedPrimaryColor())
background.applyColorFilter(config.textColor)
setOnClickListener {
removeGroup(group.id)
}
}
}
}
if (groups.isEmpty()) {
layoutInflater.inflate(R.layout.item_group, contact_groups_holder, false).apply {
contact_group.apply {
alpha = 0.5f
text = getString(R.string.no_groups)
setTextColor(config.textColor)
}
contact_groups_holder.addView(this)
contact_group_remove.beGone()
setOnClickListener {
showSelectGroupsDialog()
}
}
}
}
private fun setupNewContact() {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
supportActionBar?.title = resources.getString(R.string.new_contact)
@ -454,6 +505,11 @@ class EditContactActivity : ContactActivity() {
removeContactEventButton.beGone()
}
private fun removeGroup(id: Int) {
contact!!.groups = contact!!.groups.filter { it.id != id } as ArrayList<Group>
setupGroups()
}
private fun showNumberTypePicker(numberTypeField: TextView) {
val items = arrayListOf(
RadioItem(CommonDataKinds.Phone.TYPE_MOBILE, getString(R.string.mobile)),
@ -514,7 +570,8 @@ class EditContactActivity : ContactActivity() {
private fun showSelectGroupsDialog() {
SelectGroupsDialog(this@EditContactActivity, contact!!.groups) {
contact!!.groups = it
setupGroups()
}
}

View File

@ -26,6 +26,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/contact_group"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/contact_group"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/medium_margin"