gather events from all contacts at displaying

This commit is contained in:
tibbi 2019-09-15 20:50:55 +02:00
parent a52bed4228
commit 70d03f35b9
6 changed files with 65 additions and 22 deletions

View File

@ -180,8 +180,8 @@ abstract class ContactActivity : SimpleActivity() {
}
fun getEventTextId(type: Int) = when (type) {
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY -> R.string.birthday
ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY -> R.string.anniversary
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY -> R.string.birthday
else -> R.string.other
}
}

View File

@ -821,8 +821,8 @@ class EditContactActivity : ContactActivity() {
private fun showEventTypePicker(eventTypeField: TextView) {
val items = arrayListOf(
RadioItem(CommonDataKinds.Event.TYPE_BIRTHDAY, getString(R.string.birthday)),
RadioItem(CommonDataKinds.Event.TYPE_ANNIVERSARY, getString(R.string.anniversary)),
RadioItem(CommonDataKinds.Event.TYPE_BIRTHDAY, getString(R.string.birthday)),
RadioItem(CommonDataKinds.Event.TYPE_OTHER, getString(R.string.other))
)
@ -1221,8 +1221,8 @@ class EditContactActivity : ContactActivity() {
}
private fun getEventTypeId(value: String) = when (value) {
getString(R.string.birthday) -> CommonDataKinds.Event.TYPE_BIRTHDAY
getString(R.string.anniversary) -> CommonDataKinds.Event.TYPE_ANNIVERSARY
getString(R.string.birthday) -> CommonDataKinds.Event.TYPE_BIRTHDAY
else -> CommonDataKinds.Event.TYPE_OTHER
}

View File

@ -207,11 +207,11 @@ class ViewContactActivity : ContactActivity() {
setupEmails()
setupAddresses()
setupIMs()
setupEvents()
setupContactSources()
}
}
setupEvents()
setupNotes()
setupOrganization()
setupWebsites()
@ -423,20 +423,28 @@ class ViewContactActivity : ContactActivity() {
private fun setupEvents() {
contact_events_holder.removeAllViews()
val events = contact!!.events
if (events.isNotEmpty() && showFields and SHOW_EVENTS_FIELD != 0) {
events.forEach {
layoutInflater.inflate(R.layout.item_event, contact_events_holder, false).apply {
contact_events_holder.addView(this)
contact_event.alpha = 1f
it.value.getDateTimeFromDateString(contact_event)
contact_event_type.setText(getEventTextId(it.type))
contact_event_remove.beGone()
copyOnLongClick(it.value)
}
if (showFields and SHOW_EVENTS_FIELD != 0) {
var events = contact!!.events.toMutableSet() as LinkedHashSet<Event>
duplicateContacts.forEach {
events.addAll(it.events)
}
events = events.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Event>
if (events.isNotEmpty()) {
events.forEach {
layoutInflater.inflate(R.layout.item_view_event, contact_events_holder, false).apply {
contact_events_holder.addView(this)
it.value.getDateTimeFromDateString(contact_event)
contact_event_type.setText(getEventTextId(it.type))
copyOnLongClick(it.value)
}
}
contact_events_image.beVisible()
contact_events_holder.beVisible()
} else {
contact_events_image.beGone()
contact_events_holder.beGone()
}
contact_events_image.beVisible()
contact_events_holder.beVisible()
} else {
contact_events_image.beGone()
contact_events_holder.beGone()

View File

@ -70,7 +70,7 @@ class VcfExporter {
}
contact.events.forEach {
if (it.type == CommonDataKinds.Event.TYPE_BIRTHDAY || it.type == CommonDataKinds.Event.TYPE_ANNIVERSARY) {
if (it.type == CommonDataKinds.Event.TYPE_ANNIVERSARY || it.type == CommonDataKinds.Event.TYPE_BIRTHDAY) {
val dateTime = it.value.getDateTimeFromDateString()
if (it.value.startsWith("--")) {
val partialDate = PartialDate.builder().year(null).month(dateTime.monthOfYear).date(dateTime.dayOfMonth).build()

View File

@ -88,13 +88,13 @@ class VcfImporter(val activity: SimpleActivity) {
}
val events = ArrayList<Event>()
ezContact.birthdays.forEach {
val event = Event(formatDateToDayCode(it.date), CommonDataKinds.Event.TYPE_BIRTHDAY)
ezContact.anniversaries.forEach {
val event = Event(formatDateToDayCode(it.date), CommonDataKinds.Event.TYPE_ANNIVERSARY)
events.add(event)
}
ezContact.anniversaries.forEach {
val event = Event(formatDateToDayCode(it.date), CommonDataKinds.Event.TYPE_ANNIVERSARY)
ezContact.birthdays.forEach {
val event = Event(formatDateToDayCode(it.date), CommonDataKinds.Event.TYPE_BIRTHDAY)
events.add(event)
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contact_event_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingTop="@dimen/normal_margin"
android:paddingBottom="@dimen/normal_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/contact_event"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/contact_event_type"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:textSize="@dimen/bigger_text_size" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/contact_event_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/contact_event"
android:layout_alignBottom="@+id/contact_event"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:gravity="center"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:text="@string/home"
android:textSize="@dimen/bigger_text_size" />
</RelativeLayout>