fix #719, allow adding birthdays/anniversaries reminders at importing
This commit is contained in:
parent
42aed15397
commit
29b566360b
|
@ -21,6 +21,7 @@ import com.simplemobiletools.calendar.pro.databases.EventsDatabase
|
||||||
import com.simplemobiletools.calendar.pro.dialogs.ExportEventsDialog
|
import com.simplemobiletools.calendar.pro.dialogs.ExportEventsDialog
|
||||||
import com.simplemobiletools.calendar.pro.dialogs.FilterEventTypesDialog
|
import com.simplemobiletools.calendar.pro.dialogs.FilterEventTypesDialog
|
||||||
import com.simplemobiletools.calendar.pro.dialogs.ImportEventsDialog
|
import com.simplemobiletools.calendar.pro.dialogs.ImportEventsDialog
|
||||||
|
import com.simplemobiletools.calendar.pro.dialogs.SetRemindersDialog
|
||||||
import com.simplemobiletools.calendar.pro.extensions.*
|
import com.simplemobiletools.calendar.pro.extensions.*
|
||||||
import com.simplemobiletools.calendar.pro.fragments.*
|
import com.simplemobiletools.calendar.pro.fragments.*
|
||||||
import com.simplemobiletools.calendar.pro.helpers.*
|
import com.simplemobiletools.calendar.pro.helpers.*
|
||||||
|
@ -407,8 +408,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
private fun tryAddBirthdays() {
|
private fun tryAddBirthdays() {
|
||||||
handlePermission(PERMISSION_READ_CONTACTS) {
|
handlePermission(PERMISSION_READ_CONTACTS) {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
SetRemindersDialog(this) {
|
||||||
|
val reminders = it
|
||||||
Thread {
|
Thread {
|
||||||
addContactEvents(true) {
|
addContactEvents(true, reminders) {
|
||||||
if (it > 0) {
|
if (it > 0) {
|
||||||
toast(R.string.birthdays_added)
|
toast(R.string.birthdays_added)
|
||||||
updateViewPager()
|
updateViewPager()
|
||||||
|
@ -417,6 +420,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.no_contacts_permission)
|
toast(R.string.no_contacts_permission)
|
||||||
}
|
}
|
||||||
|
@ -426,8 +430,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
private fun tryAddAnniversaries() {
|
private fun tryAddAnniversaries() {
|
||||||
handlePermission(PERMISSION_READ_CONTACTS) {
|
handlePermission(PERMISSION_READ_CONTACTS) {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
SetRemindersDialog(this) {
|
||||||
|
val reminders = it
|
||||||
Thread {
|
Thread {
|
||||||
addContactEvents(false) {
|
addContactEvents(false, reminders) {
|
||||||
if (it > 0) {
|
if (it > 0) {
|
||||||
toast(R.string.anniversaries_added)
|
toast(R.string.anniversaries_added)
|
||||||
updateViewPager()
|
updateViewPager()
|
||||||
|
@ -436,6 +442,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.no_contacts_permission)
|
toast(R.string.no_contacts_permission)
|
||||||
}
|
}
|
||||||
|
@ -450,7 +457,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
}, Toast.LENGTH_LONG)
|
}, Toast.LENGTH_LONG)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addContactEvents(birthdays: Boolean, callback: (Int) -> Unit) {
|
private fun addContactEvents(birthdays: Boolean, reminders: ArrayList<Int>, callback: (Int) -> Unit) {
|
||||||
var eventsAdded = 0
|
var eventsAdded = 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,
|
||||||
|
@ -486,7 +493,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
val timestamp = date.time / 1000L
|
val timestamp = date.time / 1000L
|
||||||
val source = if (birthdays) SOURCE_CONTACT_BIRTHDAY else SOURCE_CONTACT_ANNIVERSARY
|
val source = if (birthdays) SOURCE_CONTACT_BIRTHDAY else SOURCE_CONTACT_ANNIVERSARY
|
||||||
val lastUpdated = cursor.getLongValue(ContactsContract.CommonDataKinds.Event.CONTACT_LAST_UPDATED_TIMESTAMP)
|
val lastUpdated = cursor.getLongValue(ContactsContract.CommonDataKinds.Event.CONTACT_LAST_UPDATED_TIMESTAMP)
|
||||||
val event = Event(null, timestamp, timestamp, name, importId = contactId, flags = FLAG_ALL_DAY, repeatInterval = YEAR,
|
val event = Event(null, timestamp, timestamp, name, reminder1Minutes = reminders[0], reminder2Minutes = reminders[1],
|
||||||
|
reminder3Minutes = reminders[2], importId = contactId, flags = FLAG_ALL_DAY, repeatInterval = YEAR,
|
||||||
eventType = eventTypeId, source = source, lastUpdated = lastUpdated)
|
eventType = eventTypeId, source = source, lastUpdated = lastUpdated)
|
||||||
|
|
||||||
if (!importIDs.contains(contactId)) {
|
if (!importIDs.contains(contactId)) {
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.simplemobiletools.calendar.pro.dialogs
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import com.simplemobiletools.calendar.pro.R
|
||||||
|
import com.simplemobiletools.calendar.pro.extensions.config
|
||||||
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import kotlinx.android.synthetic.main.dialog_set_reminders.view.*
|
||||||
|
|
||||||
|
class SetRemindersDialog(val activity: Activity, val callback: (reminders: ArrayList<Int>) -> Unit) {
|
||||||
|
private var mReminder1Minutes = -1
|
||||||
|
private var mReminder2Minutes = -1
|
||||||
|
private var mReminder3Minutes = -1
|
||||||
|
|
||||||
|
init {
|
||||||
|
val view = activity.layoutInflater.inflate(R.layout.dialog_set_reminders, null).apply {
|
||||||
|
set_reminders_image.applyColorFilter(context.config.textColor)
|
||||||
|
set_reminders_1.text = activity.getFormattedMinutes(mReminder1Minutes)
|
||||||
|
set_reminders_2.text = activity.getFormattedMinutes(mReminder1Minutes)
|
||||||
|
set_reminders_3.text = activity.getFormattedMinutes(mReminder1Minutes)
|
||||||
|
|
||||||
|
set_reminders_1.setOnClickListener {
|
||||||
|
activity.showPickSecondsDialogHelper(mReminder1Minutes) {
|
||||||
|
mReminder1Minutes = if (it <= 0) it else it / 60
|
||||||
|
set_reminders_1.text = activity.getFormattedMinutes(mReminder1Minutes)
|
||||||
|
if (mReminder1Minutes != -1) {
|
||||||
|
set_reminders_2.beVisible()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set_reminders_2.setOnClickListener {
|
||||||
|
activity.showPickSecondsDialogHelper(mReminder2Minutes) {
|
||||||
|
mReminder2Minutes = if (it <= 0) it else it / 60
|
||||||
|
set_reminders_2.text = activity.getFormattedMinutes(mReminder2Minutes)
|
||||||
|
if (mReminder2Minutes != -1) {
|
||||||
|
set_reminders_3.beVisible()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set_reminders_3.setOnClickListener {
|
||||||
|
activity.showPickSecondsDialogHelper(mReminder3Minutes) {
|
||||||
|
mReminder3Minutes = if (it <= 0) it else it / 60
|
||||||
|
set_reminders_3.text = activity.getFormattedMinutes(mReminder3Minutes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog.Builder(activity)
|
||||||
|
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.create().apply {
|
||||||
|
activity.setupDialogStuff(view, this, R.string.event_reminders)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dialogConfirmed() {
|
||||||
|
val reminders = arrayListOf(mReminder1Minutes, mReminder2Minutes, mReminder3Minutes)
|
||||||
|
reminders.sort()
|
||||||
|
callback(reminders)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/set_reminders_holder_dialog_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingEnd="@dimen/activity_margin">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/set_reminders_image"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_alignTop="@+id/set_reminders_1"
|
||||||
|
android:layout_alignBottom="@+id/set_reminders_1"
|
||||||
|
android:layout_marginStart="@dimen/normal_margin"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:padding="@dimen/medium_margin"
|
||||||
|
android:src="@drawable/ic_bell"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/set_reminders_1"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/small_margin"
|
||||||
|
android:layout_toEndOf="@+id/set_reminders_image"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingBottom="@dimen/activity_margin"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/set_reminders_2"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/set_reminders_1"
|
||||||
|
android:layout_alignStart="@+id/set_reminders_1"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingBottom="@dimen/activity_margin"
|
||||||
|
android:text="@string/add_another_reminder"
|
||||||
|
android:textSize="@dimen/day_text_size"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/set_reminders_3"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/set_reminders_2"
|
||||||
|
android:layout_alignStart="@+id/set_reminders_1"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingBottom="@dimen/activity_margin"
|
||||||
|
android:text="@string/add_another_reminder"
|
||||||
|
android:textSize="@dimen/day_text_size"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
Loading…
Reference in New Issue