mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-01 11:16:48 +01:00
properly differentiate between no birthdays/no new birthdays found
This commit is contained in:
parent
842f054407
commit
a8caa291b2
@ -476,11 +476,13 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
val reminders = it
|
val reminders = it
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
addContactEvents(true, reminders) {
|
addContactEvents(true, reminders) {
|
||||||
if (it > 0) {
|
when {
|
||||||
toast(R.string.birthdays_added)
|
it > 0 -> {
|
||||||
updateViewPager()
|
toast(R.string.birthdays_added)
|
||||||
} else {
|
updateViewPager()
|
||||||
toast(R.string.no_birthdays)
|
}
|
||||||
|
it == -1 -> toast(R.string.no_new_birthdays)
|
||||||
|
else -> toast(R.string.no_birthdays)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -498,11 +500,13 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
val reminders = it
|
val reminders = it
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
addContactEvents(false, reminders) {
|
addContactEvents(false, reminders) {
|
||||||
if (it > 0) {
|
when {
|
||||||
toast(R.string.anniversaries_added)
|
it > 0 -> {
|
||||||
updateViewPager()
|
toast(R.string.anniversaries_added)
|
||||||
} else {
|
updateViewPager()
|
||||||
toast(R.string.no_anniversaries)
|
}
|
||||||
|
it == -1 -> toast(R.string.no_new_anniversaries)
|
||||||
|
else -> toast(R.string.no_anniversaries)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -524,6 +528,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
|
|
||||||
private fun addContactEvents(birthdays: Boolean, reminders: ArrayList<Int>, callback: (Int) -> Unit) {
|
private fun addContactEvents(birthdays: Boolean, reminders: ArrayList<Int>, callback: (Int) -> Unit) {
|
||||||
var eventsAdded = 0
|
var eventsAdded = 0
|
||||||
|
var eventsFound = 0
|
||||||
val uri = ContactsContract.Data.CONTENT_URI
|
val uri = ContactsContract.Data.CONTENT_URI
|
||||||
val projection = arrayOf(ContactsContract.Contacts.DISPLAY_NAME,
|
val projection = arrayOf(ContactsContract.Contacts.DISPLAY_NAME,
|
||||||
ContactsContract.CommonDataKinds.Event.CONTACT_ID,
|
ContactsContract.CommonDataKinds.Event.CONTACT_ID,
|
||||||
@ -580,6 +585,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
importIDs.remove(it)
|
importIDs.remove(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eventsFound++
|
||||||
if (!importIDs.containsKey(contactId)) {
|
if (!importIDs.containsKey(contactId)) {
|
||||||
eventsHelper.insertEvent(event, false, false) {
|
eventsHelper.insertEvent(event, false, false) {
|
||||||
eventsAdded++
|
eventsAdded++
|
||||||
@ -598,7 +604,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
callback(eventsAdded)
|
callback(if (eventsAdded == 0 && eventsFound > 0) -1 else eventsAdded)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user