export private contact birthdays and anniversaries, for the calendar
This commit is contained in:
parent
ed5605f7ea
commit
76ac4b58fb
|
@ -57,7 +57,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.31.10'
|
||||
implementation 'com.simplemobiletools:commons:5.31.11'
|
||||
implementation 'joda-time:joda-time:2.10.1'
|
||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a'
|
||||
|
|
|
@ -22,17 +22,24 @@ class MyContactsContentProvider : ContentProvider() {
|
|||
MyContactsContentProvider.COL_CONTACT_ID,
|
||||
MyContactsContentProvider.COL_NAME,
|
||||
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 {
|
||||
val phoneNumbers = Gson().toJson(it.phoneNumbers)
|
||||
val birthdays = Gson().toJson(it.birthdays)
|
||||
val anniversaries = Gson().toJson(it.anniversaries)
|
||||
|
||||
matrixCursor.newRow()
|
||||
.add(MyContactsContentProvider.COL_RAW_ID, it.rawId)
|
||||
.add(MyContactsContentProvider.COL_CONTACT_ID, it.contactId)
|
||||
.add(MyContactsContentProvider.COL_NAME, it.name)
|
||||
.add(MyContactsContentProvider.COL_PHOTO_URI, it.photoUri)
|
||||
.add(MyContactsContentProvider.COL_PHONE_NUMBERS, phoneNumbers)
|
||||
.add(MyContactsContentProvider.COL_BIRTHDAYS, birthdays)
|
||||
.add(MyContactsContentProvider.COL_ANNIVERSARIES, anniversaries)
|
||||
}
|
||||
|
||||
return matrixCursor
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import android.provider.ContactsContract.CommonDataKinds.Event
|
||||
import android.provider.MediaStore
|
||||
import com.simplemobiletools.commons.extensions.getChoppedList
|
||||
import com.simplemobiletools.commons.models.SimpleContact
|
||||
|
@ -158,7 +159,9 @@ class LocalContactsHelper(val context: Context) {
|
|||
null
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@ import android.provider.ContactsContract.CommonDataKinds
|
|||
import android.provider.ContactsContract.CommonDataKinds.*
|
||||
import android.provider.MediaStore
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.getDateTimeFromDateString
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
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.models.Contact
|
||||
import ezvcard.Ezvcard
|
||||
|
|
Loading…
Reference in New Issue