export private contact birthdays and anniversaries, for the calendar

This commit is contained in:
tibbi 2020-10-27 19:54:10 +01:00
parent ed5605f7ea
commit 76ac4b58fb
5 changed files with 14 additions and 38 deletions

View File

@ -57,7 +57,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:5.31.10' implementation 'com.simplemobiletools:commons:5.31.11'
implementation 'joda-time:joda-time:2.10.1' implementation 'joda-time:joda-time:2.10.1'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5' implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a' implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a'

View File

@ -22,17 +22,24 @@ class MyContactsContentProvider : ContentProvider() {
MyContactsContentProvider.COL_CONTACT_ID, MyContactsContentProvider.COL_CONTACT_ID,
MyContactsContentProvider.COL_NAME, MyContactsContentProvider.COL_NAME,
MyContactsContentProvider.COL_PHOTO_URI, MyContactsContentProvider.COL_PHOTO_URI,
MyContactsContentProvider.COL_PHONE_NUMBERS) MyContactsContentProvider.COL_PHONE_NUMBERS,
MyContactsContentProvider.COL_BIRTHDAYS,
MyContactsContentProvider.COL_ANNIVERSARIES)
) )
LocalContactsHelper(context!!).getPrivateSimpleContactsSync(selection == MyContactsContentProvider.FAVORITES_ONLY).forEach { LocalContactsHelper(context!!).getPrivateSimpleContactsSync(selection == MyContactsContentProvider.FAVORITES_ONLY).forEach {
val phoneNumbers = Gson().toJson(it.phoneNumbers) val phoneNumbers = Gson().toJson(it.phoneNumbers)
val birthdays = Gson().toJson(it.birthdays)
val anniversaries = Gson().toJson(it.anniversaries)
matrixCursor.newRow() matrixCursor.newRow()
.add(MyContactsContentProvider.COL_RAW_ID, it.rawId) .add(MyContactsContentProvider.COL_RAW_ID, it.rawId)
.add(MyContactsContentProvider.COL_CONTACT_ID, it.contactId) .add(MyContactsContentProvider.COL_CONTACT_ID, it.contactId)
.add(MyContactsContentProvider.COL_NAME, it.name) .add(MyContactsContentProvider.COL_NAME, it.name)
.add(MyContactsContentProvider.COL_PHOTO_URI, it.photoUri) .add(MyContactsContentProvider.COL_PHOTO_URI, it.photoUri)
.add(MyContactsContentProvider.COL_PHONE_NUMBERS, phoneNumbers) .add(MyContactsContentProvider.COL_PHONE_NUMBERS, phoneNumbers)
.add(MyContactsContentProvider.COL_BIRTHDAYS, birthdays)
.add(MyContactsContentProvider.COL_ANNIVERSARIES, anniversaries)
} }
return matrixCursor return matrixCursor

View File

@ -1,34 +0,0 @@
package com.simplemobiletools.contacts.pro.extensions
import android.widget.TextView
import com.simplemobiletools.commons.helpers.getDateFormats
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*
fun String.getDateTimeFromDateString(viewToUpdate: TextView? = null): DateTime {
val dateFormats = getDateFormats()
var date = DateTime()
for (format in dateFormats) {
try {
date = DateTime.parse(this, DateTimeFormat.forPattern(format))
val formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault())
var localPattern = (formatter as SimpleDateFormat).toLocalizedPattern()
val hasYear = format.contains("y")
if (!hasYear) {
localPattern = localPattern.replace("y", "").replace(",", "").trim()
date = date.withYear(DateTime().year)
}
val formattedString = date.toString(localPattern)
viewToUpdate?.text = formattedString
break
} catch (ignored: Exception) {
}
}
return date
}

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.net.Uri import android.net.Uri
import android.provider.ContactsContract.CommonDataKinds.Event
import android.provider.MediaStore import android.provider.MediaStore
import com.simplemobiletools.commons.extensions.getChoppedList import com.simplemobiletools.commons.extensions.getChoppedList
import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.commons.models.SimpleContact
@ -158,7 +159,9 @@ class LocalContactsHelper(val context: Context) {
null null
} else { } else {
val phoneNumbers = contact.phoneNumbers.map { it.value }.toMutableList() as ArrayList<String> val phoneNumbers = contact.phoneNumbers.map { it.value }.toMutableList() as ArrayList<String>
SimpleContact(contact.id, contact.id, contact.getNameToDisplay(), contact.photoUri, phoneNumbers) val birthdays = contact.events.filter { it.type == Event.TYPE_BIRTHDAY }.map { it.value }.toMutableList() as ArrayList<String>
val anniversaries = contact.events.filter { it.type == Event.TYPE_ANNIVERSARY }.map { it.value }.toMutableList() as ArrayList<String>
SimpleContact(contact.id, contact.id, contact.getNameToDisplay(), contact.photoUri, phoneNumbers, birthdays, anniversaries)
} }
} }

View File

@ -5,11 +5,11 @@ import android.provider.ContactsContract.CommonDataKinds
import android.provider.ContactsContract.CommonDataKinds.* import android.provider.ContactsContract.CommonDataKinds.*
import android.provider.MediaStore import android.provider.MediaStore
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.getDateTimeFromDateString
import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.extensions.getByteArray import com.simplemobiletools.contacts.pro.extensions.getByteArray
import com.simplemobiletools.contacts.pro.extensions.getDateTimeFromDateString
import com.simplemobiletools.contacts.pro.helpers.VcfExporter.ExportResult.EXPORT_FAIL import com.simplemobiletools.contacts.pro.helpers.VcfExporter.ExportResult.EXPORT_FAIL
import com.simplemobiletools.contacts.pro.models.Contact import com.simplemobiletools.contacts.pro.models.Contact
import ezvcard.Ezvcard import ezvcard.Ezvcard