diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index de25b02d4..eacb31910 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -307,6 +307,7 @@ class MainActivity : SimpleActivity(), NavigationListener { eventTypeId = dbHelper.insertEventType(eventType) } + val birthdayImportIDs = dbHelper.getBirthdays().map { it.importId } var birthdaysAdded = 0 val uri = ContactsContract.Data.CONTENT_URI val projection = arrayOf(ContactsContract.Contacts.DISPLAY_NAME, @@ -330,10 +331,11 @@ class MainActivity : SimpleActivity(), NavigationListener { 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++ + if (!birthdayImportIDs.contains(contactId)) { + dbHelper.insert(event, false) { + birthdaysAdded++ + } } - } while (cursor.moveToNext()) } } catch (e: Exception) { @@ -344,6 +346,7 @@ class MainActivity : SimpleActivity(), NavigationListener { runOnUiThread { toast(if (birthdaysAdded > 0) R.string.birthdays_added else R.string.no_birthdays) + updateViewPager() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index cf5fe4546..19596c6c9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -394,6 +394,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont return null } + fun getBirthdays(): List { + val selection = "$MAIN_TABLE_NAME.$COL_EVENT_SOURCE = ?" + val selectionArgs = arrayOf(SOURCE_CONTACT_BIRTHDAY) + val cursor = getEventsCursor(selection, selectionArgs) + return fillEvents(cursor) + } + fun deleteEvents(ids: Array, deleteFromCalDAV: Boolean) { val args = TextUtils.join(", ", ids) val selection = "$MAIN_TABLE_NAME.$COL_ID IN ($args)" @@ -547,10 +554,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val selectionArgs = arrayOf(id.toString()) val cursor = getEventsCursor(selection, selectionArgs) val events = fillEvents(cursor) - return if (!events.isEmpty()) + return if (events.isNotEmpty()) { events[0] - else + } else { null + } } fun getEvents(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: MutableList) -> Unit) {