insert the birthdays in db
This commit is contained in:
parent
d55c0eac62
commit
0b1b6281d2
|
@ -300,10 +300,18 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
}
|
||||
|
||||
private fun addBirthdays() {
|
||||
val birthdays = getString(R.string.birthdays)
|
||||
var eventTypeId = dbHelper.getEventTypeIdWithTitle(birthdays)
|
||||
if (eventTypeId == -1) {
|
||||
val eventType = EventType(0, birthdays, resources.getColor(R.color.default_birthdays_color))
|
||||
eventTypeId = dbHelper.insertEventType(eventType)
|
||||
}
|
||||
|
||||
var birthdaysAdded = 0
|
||||
val uri = ContactsContract.Data.CONTENT_URI
|
||||
val projection = arrayOf(ContactsContract.Contacts.DISPLAY_NAME,
|
||||
ContactsContract.CommonDataKinds.Event.CONTACT_ID,
|
||||
ContactsContract.CommonDataKinds.Event.CONTACT_LAST_UPDATED_TIMESTAMP,
|
||||
ContactsContract.CommonDataKinds.Event.START_DATE)
|
||||
|
||||
val selection = "${ContactsContract.Data.MIMETYPE} = ? AND ${ContactsContract.CommonDataKinds.Event.TYPE} = ?"
|
||||
|
@ -313,12 +321,19 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
cursor = contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val contactId = cursor.getIntValue(ContactsContract.CommonDataKinds.Event.CONTACT_ID)
|
||||
val contactId = cursor.getIntValue(ContactsContract.CommonDataKinds.Event.CONTACT_ID).toString()
|
||||
val name = cursor.getStringValue(ContactsContract.Contacts.DISPLAY_NAME)
|
||||
val birthDay = cursor.getStringValue(ContactsContract.CommonDataKinds.Event.START_DATE)
|
||||
val formatter = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||
val timestamp = formatter.parse(birthDay).time / 1000
|
||||
birthdaysAdded++
|
||||
val timestamp = (formatter.parse(birthDay).time / 1000).toInt()
|
||||
val lastUpdated = cursor.getLongValue(ContactsContract.CommonDataKinds.Event.CONTACT_LAST_UPDATED_TIMESTAMP)
|
||||
val event = Event(0, timestamp, timestamp, name, importId = contactId, flags = FLAG_ALL_DAY, repeatInterval = YEAR,
|
||||
eventType = eventTypeId, source = SOURCE_CONTACT_BIRTHDAY, lastUpdated = lastUpdated)
|
||||
|
||||
dbHelper.insert(event, false) {
|
||||
birthdaysAdded++
|
||||
}
|
||||
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -124,6 +124,7 @@ val FONT_SIZE_LARGE = 2
|
|||
|
||||
val SOURCE_SIMPLE_CALENDAR = "simple-calendar"
|
||||
val SOURCE_IMPORTED_ICS = "imported-ics"
|
||||
val SOURCE_CONTACT_BIRTHDAY = "contact-birthday"
|
||||
|
||||
// deprecated
|
||||
val SOURCE_GOOGLE_CALENDAR = 1
|
||||
|
|
|
@ -421,7 +421,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_caldav_calendar_divider"
|
||||
android:layout_marginBottom="@dimen/medium_margin"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:layout_toEndOf="@+id/event_type_image"
|
||||
android:layout_toRightOf="@+id/event_type_image"
|
||||
|
@ -451,5 +450,15 @@
|
|||
android:clickable="false"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/event_type_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:layout_below="@+id/event_type_holder"
|
||||
android:layout_marginBottom="@dimen/medium_margin"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="@color/darker_divider"
|
||||
android:importantForAccessibility="no"/>
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
|
|
|
@ -3,4 +3,5 @@
|
|||
<color name="dark_theme_dialog_background">#ff444444</color>
|
||||
<color name="darker_divider">#66808080</color>
|
||||
<color name="red_text">#FFF62F2F</color>
|
||||
<color name="default_birthdays_color">#FF303DF6</color>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue