Added auto sync for birthdays and anniversaries on the app start (#906)

This commit is contained in:
Agnieszka C 2021-10-29 19:58:45 +02:00
parent 17671d6413
commit 2d5ae168fe
46 changed files with 117 additions and 0 deletions

View file

@ -122,6 +122,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
checkCalDAVUpdateListener()
}
if (config.addBdaysAnnivAutomatically) {
addBirthdaysAnniversaries()
}
if (!config.wasUpgradedFromFreeShown && isPackageInstalled("com.simplemobiletools.calendar")) {
ConfirmationDialog(this, "", R.string.upgraded_from_free, R.string.ok, 0) {}
config.wasUpgradedFromFreeShown = true
@ -589,6 +593,37 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
}
private fun addBirthdaysAnniversaries() {
if (!hasPermission(PERMISSION_READ_CONTACTS)) {
return
}
val reminders = arrayListOf(REMINDER_OFF, REMINDER_OFF, REMINDER_OFF)
val privateCursor = getMyContactsCursor(false, false)?.loadInBackground()
ensureBackgroundThread {
val privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
addPrivateEvents(true, privateContacts, reminders) { eventsFound, eventsAdded ->
addContactEvents(true, reminders, eventsFound, eventsAdded) {
if (it > 0) {
toast(R.string.birthdays_added)
updateViewPager()
setupQuickFilter()
}
}
}
addPrivateEvents(false, privateContacts, reminders) { eventsFound, eventsAdded ->
addContactEvents(false, reminders, eventsFound, eventsAdded) {
if (it > 0) {
toast(R.string.anniversaries_added)
updateViewPager()
setupQuickFilter()
}
}
}
}
}
private fun handleParseResult(result: ImportResult) {
toast(
when (result) {

View file

@ -81,6 +81,7 @@ class SettingsActivity : SimpleActivity() {
setupViewToOpenFromListWidget()
setupDimEvents()
setupAllowChangingTimeZones()
setupAddBdaysAnnivAutomatically()
updateTextColors(settings_holder)
checkPrimaryColor()
setupSectionColors()
@ -621,6 +622,20 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupAddBdaysAnnivAutomatically() {
settings_add_bdays_anniv_automatically.isChecked = config.addBdaysAnnivAutomatically
settings_add_bdays_anniv_automatically_holder.setOnClickListener {
handlePermission(PERMISSION_READ_CONTACTS) {
if (it) {
settings_add_bdays_anniv_automatically.toggle()
config.addBdaysAnnivAutomatically = settings_add_bdays_anniv_automatically.isChecked
} else {
toast(R.string.no_contacts_permission)
}
}
}
}
private fun setupDefaultStartTime() {
updateDefaultStartTimeText()
settings_default_start_time_holder.setOnClickListener {

View file

@ -193,6 +193,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(ALLOW_CHANGING_TIME_ZONES, false)
set(allowChangingTimeZones) = prefs.edit().putBoolean(ALLOW_CHANGING_TIME_ZONES, allowChangingTimeZones).apply()
var addBdaysAnnivAutomatically: Boolean
get() = prefs.getBoolean(ADD_BDAYS_ANNIV_AUTOMATICALLY, false)
set(addBdaysAnnivAutomatically) = prefs.edit().putBoolean(ADD_BDAYS_ANNIV_AUTOMATICALLY, addBdaysAnnivAutomatically).apply()
var lastExportPath: String
get() = prefs.getString(LAST_EXPORT_PATH, "")!!
set(lastExportPath) = prefs.edit().putString(LAST_EXPORT_PATH, lastExportPath).apply()

View file

@ -80,6 +80,7 @@ const val DEFAULT_START_TIME = "default_start_time"
const val DEFAULT_DURATION = "default_duration"
const val DEFAULT_EVENT_TYPE_ID = "default_event_type_id"
const val ALLOW_CHANGING_TIME_ZONES = "allow_changing_time_zones"
const val ADD_BDAYS_ANNIV_AUTOMATICALLY = "add_bdays_anniv_automatically"
const val LAST_EXPORT_PATH = "last_export_path"
const val EXPORT_PAST_EVENTS = "export_past_events"
const val WEEKLY_VIEW_ITEM_HEIGHT_MULTIPLIER = "weekly_view_item_height_multiplier"

View file

@ -1027,6 +1027,27 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_add_bdays_anniv_automatically_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/normal_margin"
android:paddingBottom="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_add_bdays_anniv_automatically"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingStart="@dimen/medium_margin"
android:text="@string/add_bdays_anniv_automatically" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_delete_all_events_holder"
android:layout_width="match_parent"

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">ظلل نهايات الأسبوع في بعض العروض</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -206,6 +206,7 @@
<string name="highlight_weekends">কিছু ভিউতে সাপ্তাহিক ছুটি হাইলাইট করুন</string>
<string name="allow_changing_time_zones">ইভেন্টের টাইম জোন পরিবর্তন করার অনুমতি দিন</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Zvýraznit víkendy na některých pohledech</string>
<string name="allow_changing_time_zones">Povolit změny časových pásem událostí</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Fremhæv weekender i visse visninger</string>
<string name="allow_changing_time_zones">Tillad ændring af en begivenheds tidszone</string>
<string name="manage_quick_filter_event_types">Håndter begivenhedstyper med hurtigt filter</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Wochenenden in einigen Ansichten hervorheben</string>
<string name="allow_changing_time_zones">Zeitzone kann geändert werden</string>
<string name="manage_quick_filter_event_types">Termintypen zur schnellen Filterung verwalten</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Επισήμανση Σαββατοκύριακων σε ορισμένες προβολές</string>
<string name="allow_changing_time_zones">Να επιτρέπεται η αλλαγή ζωνών ώρας συμβάντος</string>
<string name="manage_quick_filter_event_types">Διαχείριση γρήγορου φίλτρου τύπων συμβάντων</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Destacar los fines de semana en algunas vistas</string>
<string name="allow_changing_time_zones">Permitir cambiar zona horaria del evento</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Nabarmendu asteburuak ikuspegi batzuetan</string>
<string name="allow_changing_time_zones">Baimendu gertaeren ordu-zonak aldatzea</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Korosta viikonloppuja joistakin näkymistä</string>
<string name="allow_changing_time_zones">Salli tapahtumien aikavyöhykkeiden muuttaminen</string>
<string name="manage_quick_filter_event_types">Hallitse pikasuodatuksen tapahtumatyyppejä</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -203,6 +203,7 @@
<string name="highlight_weekends">Mettre les week-ends en surbrillance</string>
<string name="allow_changing_time_zones">Autoriser la modification des fuseaux horaires des événements</string>
<string name="manage_quick_filter_event_types">Gérer les filtres selon le type d\'événement</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Resaltar fins de semana nalgunhas vistas</string>
<string name="allow_changing_time_zones">Permitir cambiar as zonas horarias do evento</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">הדגש סופי שבוע בחלק מהתצוגות</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Sorot akhir pekan pada beberapa tampilan</string>
<string name="allow_changing_time_zones">Izinkan mengubah zona waktu acara</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Sorot akhir pekan pada beberapa tampilan</string>
<string name="allow_changing_time_zones">Izinkan mengubah zona waktu acara</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Evidenzia il fine-settimana in alcune viste</string>
<string name="allow_changing_time_zones">Abilita il cambio del fuso orario negli eventi</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">הדגש סופי שבוע בחלק מהתצוגות</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">화면에서 주말 표시</string>
<string name="allow_changing_time_zones">이벤트 시간대 변경 허용</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Iezīmēt/izcelt nedēļas nogales dažos skatos/režīmos</string>
<string name="allow_changing_time_zones">Atļaut mainīt notikuma laika joslu</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Fremhev helger på noen visninger</string>
<string name="allow_changing_time_zones">Tillat å endre tidssoner for hendelser</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Weekends markeren</string>
<string name="allow_changing_time_zones">Bewerken van tijdzone voor afspraken toestaan</string>
<string name="manage_quick_filter_event_types">Snelfilter gebeurtenistypes beheren</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Wyróżniaj weekendy w niektórych widokach</string>
<string name="allow_changing_time_zones">Zezwalaj na zmienianie stref czasowych wydarzeń</string>
<string name="manage_quick_filter_event_types">Zarządzaj szybkim filtrowaniem typów wydarzeń</string>
<string name="add_bdays_anniv_automatically">Dodawaj urodziny i rocznice automatycznie przy uruchomieniu aplikacji</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Destacar os finais de semana em algumas vistas</string>
<string name="allow_changing_time_zones">Permitir a alteração de fuso horário do evento</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Destacar fim de semana em algumas vistas</string>
<string name="allow_changing_time_zones">Permitir alteração do fuso horário dos eventos</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Evidențiază weekend-urile în anumite vizualizări</string>
<string name="allow_changing_time_zones">Permite modificarea zonele orare ale evenimentului</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Выделять выходные дни в соответствующих режимах</string>
<string name="allow_changing_time_zones">Разрешить изменение часового пояса событий</string>
<string name="manage_quick_filter_event_types">Управление типами событий быстрого фильтра</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Zvýrazniť víkendy na niektorých pohľadoch</string>
<string name="allow_changing_time_zones">Povoliť zmenu časových pásem udalostí</string>
<string name="manage_quick_filter_event_types">Spravovať typy udalostí v rýchlom filtrovaní</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Markera veckoslut i vissa vyer</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Bazı görünümlerde hafta sonlarını vurgula</string>
<string name="allow_changing_time_zones">Etkinlik saat dilimlerini değiştirmeye izin ver</string>
<string name="manage_quick_filter_event_types">Hızlı filtre etkinlik türlerini yönet</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Виділяти вихідні дні на деяких переглядах</string>
<string name="allow_changing_time_zones">Дозволити змінювати часові пояси подій</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -204,6 +204,7 @@
<string name="highlight_weekends">在部分视图高亮周末</string>
<string name="allow_changing_time_zones">允许更改活动时区</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
    <!-- CalDAV sync -->
    <string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">在檢視畫面突顯假日</string>
<string name="allow_changing_time_zones">允許改變活動的時區</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -202,6 +202,7 @@
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<string name="add_bdays_anniv_automatically">Add birthdays and anniversaries automatically after launching the app</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>