Added during day reminder for all-day events

This commit is contained in:
Acácio Correia 2021-01-09 11:11:38 +00:00
parent d2a18ca3b9
commit dead5b6ee5
15 changed files with 373 additions and 79 deletions

View File

@ -44,6 +44,7 @@ import kotlinx.android.synthetic.main.activity_event.view.*
import kotlinx.android.synthetic.main.item_attendee.view.*
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.joda.time.LocalTime
import java.util.*
import java.util.regex.Pattern
import kotlin.collections.ArrayList
@ -59,6 +60,7 @@ class EventActivity : SimpleActivity() {
private val REMINDER_1_TYPE = "REMINDER_1_TYPE"
private val REMINDER_2_TYPE = "REMINDER_2_TYPE"
private val REMINDER_3_TYPE = "REMINDER_3_TYPE"
private val ALL_DAY_REMINDER_MINUTES = "ALL_DAY_REMINDER_MINUTES"
private val REPEAT_INTERVAL = "REPEAT_INTERVAL"
private val REPEAT_LIMIT = "REPEAT_LIMIT"
private val REPEAT_RULE = "REPEAT_RULE"
@ -73,6 +75,7 @@ class EventActivity : SimpleActivity() {
private var mReminder1Type = REMINDER_NOTIFICATION
private var mReminder2Type = REMINDER_NOTIFICATION
private var mReminder3Type = REMINDER_NOTIFICATION
private var mAllDayReminderTime: LocalTime? = null
private var mRepeatInterval = 0
private var mRepeatLimit = 0L
private var mRepeatRule = 0
@ -162,6 +165,7 @@ class EventActivity : SimpleActivity() {
if (savedInstanceState == null) {
updateTexts()
updateEventType()
updateAllDayReminderDeleteButton()
updateCalDAVCalendar()
}
@ -171,6 +175,8 @@ class EventActivity : SimpleActivity() {
event_end_date.setOnClickListener { setupEndDate() }
event_end_time.setOnClickListener { setupEndTime() }
event_time_zone.setOnClickListener { setupTimeZone() }
event_all_day_reminder.setOnClickListener { setupAllDayReminderTime() }
event_all_day_reminder_delete.setOnClickListener { deleteAllDayReminder() }
event_all_day.setOnCheckedChangeListener { compoundButton, isChecked -> toggleAllDay(isChecked) }
event_repetition.setOnClickListener { showRepeatIntervalDialog() }
@ -265,11 +271,12 @@ class EventActivity : SimpleActivity() {
private fun getReminders(): ArrayList<Reminder> {
var reminders = arrayListOf(
Reminder(mReminder1Minutes, mReminder1Type),
Reminder(mReminder2Minutes, mReminder2Type),
Reminder(mReminder3Minutes, mReminder3Type)
Reminder(mReminder1Minutes, mReminder1Type),
Reminder(mReminder2Minutes, mReminder2Type),
Reminder(mReminder3Minutes, mReminder3Type),
Reminder(getMinutes(mAllDayReminderTime), ALL_DAY_REMINDER_NOTIFICATION)
)
reminders = reminders.filter { it.minutes != REMINDER_OFF }.sortedBy { it.minutes }.toMutableList() as ArrayList<Reminder>
reminders = reminders.filter { (it.minutes != REMINDER_OFF && it.type == REMINDER_NOTIFICATION) || (it.minutes != ALL_DAY_REMINDER_OFF && it.type == ALL_DAY_REMINDER_NOTIFICATION) }.sortedBy { it.minutes }.toMutableList() as ArrayList<Reminder>
return reminders
}
@ -318,6 +325,22 @@ class EventActivity : SimpleActivity() {
}
}
private fun getMinutes(localTime: LocalTime?): Int {
if (localTime != null) {
return - (localTime.hourOfDay * 60 + localTime.minuteOfHour)
} else {
return ALL_DAY_REMINDER_OFF
}
}
private fun getLocalTime(minutes: Int): LocalTime? {
if (minutes != ALL_DAY_REMINDER_OFF) {
return LocalTime().withMinuteOfHour(-minutes % 60).withHourOfDay(-minutes / 60)
}else{
return null
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
if (!mWasActivityInitialized) {
@ -338,6 +361,8 @@ class EventActivity : SimpleActivity() {
putInt(REMINDER_2_TYPE, mReminder2Type)
putInt(REMINDER_3_TYPE, mReminder3Type)
putInt(ALL_DAY_REMINDER_MINUTES, getMinutes(mAllDayReminderTime))
putInt(REPEAT_INTERVAL, mRepeatInterval)
putInt(REPEAT_RULE, mRepeatRule)
putLong(REPEAT_LIMIT, mRepeatLimit)
@ -370,6 +395,8 @@ class EventActivity : SimpleActivity() {
mReminder2Type = getInt(REMINDER_2_TYPE)
mReminder3Type = getInt(REMINDER_3_TYPE)
mAllDayReminderTime = getLocalTime(getInt(ALL_DAY_REMINDER_MINUTES))
mRepeatInterval = getInt(REPEAT_INTERVAL)
mRepeatRule = getInt(REPEAT_RULE)
mRepeatLimit = getLong(REPEAT_LIMIT)
@ -384,6 +411,7 @@ class EventActivity : SimpleActivity() {
checkRepeatTexts(mRepeatInterval)
checkRepeatRule()
updateTexts()
updateAllDayReminderDeleteButton()
updateEventType()
updateCalDAVCalendar()
checkAttendees()
@ -440,6 +468,7 @@ class EventActivity : SimpleActivity() {
mReminder1Type = mEvent.reminder1Type
mReminder2Type = mEvent.reminder2Type
mReminder3Type = mEvent.reminder3Type
mAllDayReminderTime = getLocalTime(mEvent.allDayReminderMinutes)
mRepeatInterval = mEvent.repeatInterval
mRepeatLimit = mEvent.repeatLimit
mRepeatRule = mEvent.repeatRule
@ -795,6 +824,7 @@ class EventActivity : SimpleActivity() {
updateReminder1Text()
updateReminder2Text()
updateReminder3Text()
updateAllDayReminderText()
updateReminderTypeImages()
}
@ -828,6 +858,18 @@ class EventActivity : SimpleActivity() {
}
}
private fun updateAllDayReminderText() {
event_all_day_reminder.apply {
if (mAllDayReminderTime != null) {
text = Formatter.getTime(applicationContext, mAllDayReminderTime!!)
alpha = 1f
} else {
text = resources.getString(R.string.add_during_day_reminder)
alpha = 0.4f
}
}
}
private fun showReminderTypePicker(currentValue: Int, callback: (Int) -> Unit) {
val items = arrayListOf(
RadioItem(REMINDER_NOTIFICATION, getString(R.string.notification)),
@ -858,6 +900,10 @@ class EventActivity : SimpleActivity() {
view.setImageDrawable(icon)
}
private fun updateAllDayReminderDeleteButton() {
event_all_day_reminder_delete.beGoneIf(mAllDayReminderTime == null)
}
private fun updateRepetitionText() {
event_repetition.text = getRepetitionText(mRepeatInterval)
}
@ -958,10 +1004,23 @@ class EventActivity : SimpleActivity() {
}
}
private fun removeAllDayReminder() {
mAllDayReminderTime = null
updateAllDayReminderText()
updateAllDayReminderDeleteButton()
}
private fun toggleAllDay(isChecked: Boolean) {
hideKeyboard()
event_start_time.beGoneIf(isChecked)
event_end_time.beGoneIf(isChecked)
event_all_day_reminder_layout.beGoneIf(!isChecked)
if (!isChecked) {
removeAllDayReminder()
}
resetTime()
}
@ -1057,7 +1116,7 @@ class EventActivity : SimpleActivity() {
"$CALDAV-$mEventCalendarId"
}
val reminders = getReminders()
val reminders = getReminders().filter { it.type == REMINDER_NOTIFICATION }
val reminder1 = reminders.getOrNull(0) ?: Reminder(REMINDER_OFF, REMINDER_NOTIFICATION)
val reminder2 = reminders.getOrNull(1) ?: Reminder(REMINDER_OFF, REMINDER_NOTIFICATION)
val reminder3 = reminders.getOrNull(2) ?: Reminder(REMINDER_OFF, REMINDER_NOTIFICATION)
@ -1085,6 +1144,7 @@ class EventActivity : SimpleActivity() {
reminder1Type = mReminder1Type
reminder2Type = mReminder2Type
reminder3Type = mReminder3Type
allDayReminderMinutes = getMinutes(mAllDayReminderTime)
repeatInterval = mRepeatInterval
importId = newImportId
timeZone = if (mEvent.timeZone.isEmpty()) TimeZone.getDefault().id else timeZone
@ -1110,7 +1170,7 @@ class EventActivity : SimpleActivity() {
if (mEvent.id == null || mEvent.id == null) {
eventsHelper.insertEvent(mEvent, true, true) {
if (DateTime.now().isAfter(mEventStartDateTime.millis)) {
if (mEvent.repeatInterval == 0 && mEvent.getReminders().any { it.type == REMINDER_NOTIFICATION }) {
if (mEvent.repeatInterval == 0 && mEvent.getReminders().any { it.type == REMINDER_NOTIFICATION || it.type == ALL_DAY_REMINDER_NOTIFICATION }) {
notifyEvent(mEvent)
}
}
@ -1253,6 +1313,25 @@ class EventActivity : SimpleActivity() {
TimePickerDialog(this, mDialogTheme, endTimeSetListener, mEventEndDateTime.hourOfDay, mEventEndDateTime.minuteOfHour, config.use24HourFormat).show()
}
private fun setupAllDayReminderTime() {
var hours = 9
var minutes = 0
if (mAllDayReminderTime != null) {
hours = mAllDayReminderTime!!.hourOfDay
minutes = mAllDayReminderTime!!.minuteOfHour
}
hideKeyboard()
TimePickerDialog(this, mDialogTheme, allDayReminderTimeSetListener, hours, minutes, config.use24HourFormat).show()
}
private fun deleteAllDayReminder() {
mAllDayReminderTime = null
updateAllDayReminderText()
updateAllDayReminderDeleteButton()
}
private val startDateSetListener = DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
dateSet(year, monthOfYear, dayOfMonth, true)
}
@ -1265,6 +1344,10 @@ class EventActivity : SimpleActivity() {
private val endTimeSetListener = TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute -> timeSet(hourOfDay, minute, false) }
private val allDayReminderTimeSetListener = TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute ->
allDayReminderTimeSet(hourOfDay, minute)
}
private fun dateSet(year: Int, month: Int, day: Int, isStart: Boolean) {
if (isStart) {
val diff = mEventEndDateTime.seconds() - mEventStartDateTime.seconds()
@ -1301,6 +1384,13 @@ class EventActivity : SimpleActivity() {
}
}
private fun allDayReminderTimeSet(hours: Int, minutes: Int) {
mAllDayReminderTime = LocalTime()
mAllDayReminderTime = mAllDayReminderTime!!.withHourOfDay(hours).withMinuteOfHour(minutes)
updateAllDayReminderText()
updateAllDayReminderDeleteButton()
}
private fun setupTimeZone() {
Intent(this, SelectTimeZoneActivity::class.java).apply {
putExtra(CURRENT_TIME_ZONE, mEvent.getTimeZoneString())

View File

@ -49,6 +49,7 @@ import com.simplemobiletools.commons.models.SimpleContact
import kotlinx.android.synthetic.main.activity_main.*
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.joda.time.LocalTime
import java.io.FileOutputStream
import java.io.OutputStream
import java.text.SimpleDateFormat
@ -499,14 +500,13 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun tryAddBirthdays() {
handlePermission(PERMISSION_READ_CONTACTS) {
if (it) {
SetRemindersDialog(this) {
val reminders = it
SetRemindersDialog(this) { reminders: ArrayList<Int>, all_day_reminder: LocalTime? ->
val privateCursor = getMyContactsCursor()?.loadInBackground()
ensureBackgroundThread {
val privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
addPrivateEvents(true, privateContacts, reminders) { eventsFound, eventsAdded ->
addContactEvents(true, reminders, eventsFound, eventsAdded) {
addPrivateEvents(true, privateContacts, reminders, all_day_reminder) { eventsFound, eventsAdded ->
addContactEvents(true, reminders, all_day_reminder, eventsFound, eventsAdded) {
when {
it > 0 -> {
toast(R.string.birthdays_added)
@ -528,14 +528,13 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun tryAddAnniversaries() {
handlePermission(PERMISSION_READ_CONTACTS) {
if (it) {
SetRemindersDialog(this) {
val reminders = it
SetRemindersDialog(this) { reminders: ArrayList<Int>, all_day_reminder: LocalTime? ->
val privateCursor = getMyContactsCursor()?.loadInBackground()
ensureBackgroundThread {
val privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
addPrivateEvents(false, privateContacts, reminders) { eventsFound, eventsAdded ->
addContactEvents(false, reminders, eventsFound, eventsAdded) {
addPrivateEvents(false, privateContacts, reminders, all_day_reminder) { eventsFound, eventsAdded ->
addContactEvents(false, reminders, all_day_reminder, eventsFound, eventsAdded) {
when {
it > 0 -> {
toast(R.string.anniversaries_added)
@ -563,7 +562,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}, Toast.LENGTH_LONG)
}
private fun addContactEvents(birthdays: Boolean, reminders: ArrayList<Int>, initEventsFound: Int, initEventsAdded: Int, callback: (Int) -> Unit) {
private fun addContactEvents(birthdays: Boolean, reminders: ArrayList<Int>, allDayReminder: LocalTime?, initEventsFound: Int, initEventsAdded: Int, callback: (Int) -> Unit) {
var eventsFound = initEventsFound
var eventsAdded = initEventsAdded
val uri = Data.CONTENT_URI
@ -602,8 +601,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
val timestamp = date.time / 1000L
val lastUpdated = cursor.getLongValue(CommonDataKinds.Event.CONTACT_LAST_UPDATED_TIMESTAMP)
val event = Event(null, timestamp, timestamp, name, reminder1Minutes = reminders[0], reminder2Minutes = reminders[1],
reminder3Minutes = reminders[2], importId = contactId, timeZone = DateTimeZone.getDefault().id, flags = FLAG_ALL_DAY,
repeatInterval = YEAR, repeatRule = REPEAT_SAME_DAY, eventType = eventTypeId, source = source, lastUpdated = lastUpdated)
reminder3Minutes = reminders[2], allDayReminderMinutes = getMinutes(allDayReminder), importId = contactId, timeZone = DateTimeZone.getDefault().id, flags = FLAG_ALL_DAY,
repeatInterval = YEAR, repeatRule = REPEAT_SAME_DAY, eventType = eventTypeId, source = source, lastUpdated = lastUpdated)
val importIDsToDelete = ArrayList<String>()
for ((key, value) in importIDs) {
@ -636,7 +635,15 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
}
private fun addPrivateEvents(birthdays: Boolean, contacts: ArrayList<SimpleContact>, reminders: ArrayList<Int>, callback: (eventsFound: Int, eventsAdded: Int) -> Unit) {
private fun getMinutes(localTime: LocalTime?): Int {
if (localTime != null) {
return - (localTime.hourOfDay * 60 + localTime.minuteOfHour)
} else {
return ALL_DAY_REMINDER_OFF
}
}
private fun addPrivateEvents(birthdays: Boolean, contacts: ArrayList<SimpleContact>, reminders: ArrayList<Int>, allDayReminder: LocalTime?, callback: (eventsFound: Int, eventsAdded: Int) -> Unit) {
var eventsAdded = 0
var eventsFound = 0
if (contacts.isEmpty()) {
@ -673,8 +680,9 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
val timestamp = date.time / 1000L
val lastUpdated = System.currentTimeMillis()
val event = Event(null, timestamp, timestamp, contact.name, reminder1Minutes = reminders[0], reminder2Minutes = reminders[1],
reminder3Minutes = reminders[2], importId = contact.contactId.toString(), timeZone = DateTimeZone.getDefault().id, flags = FLAG_ALL_DAY,
repeatInterval = YEAR, repeatRule = REPEAT_SAME_DAY, eventType = eventTypeId, source = source, lastUpdated = lastUpdated)
reminder3Minutes = reminders[2], allDayReminderMinutes = getMinutes(allDayReminder), importId = contact.contactId.toString(),
timeZone = DateTimeZone.getDefault().id, flags = FLAG_ALL_DAY, repeatInterval = YEAR, repeatRule = REPEAT_SAME_DAY,
eventType = eventTypeId, source = source, lastUpdated = lastUpdated)
val importIDsToDelete = ArrayList<String>()
for ((key, value) in importIDs) {

View File

@ -17,7 +17,7 @@ import com.simplemobiletools.calendar.pro.models.Event
import com.simplemobiletools.calendar.pro.models.EventType
import java.util.concurrent.Executors
@Database(entities = [Event::class, EventType::class], version = 3)
@Database(entities = [Event::class, EventType::class], version = 4)
@TypeConverters(Converters::class)
abstract class EventsDatabase : RoomDatabase() {
@ -41,6 +41,7 @@ abstract class EventsDatabase : RoomDatabase() {
})
.addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_2_3)
.addMigrations(MIGRATION_3_4)
.build()
db!!.openHelper.setWriteAheadLoggingEnabled(true)
}
@ -80,5 +81,13 @@ abstract class EventsDatabase : RoomDatabase() {
}
}
}
private val MIGRATION_3_4 = object : Migration(3, 4) {
override fun migrate(database: SupportSQLiteDatabase) {
database.apply {
execSQL("ALTER TABLE events ADD COLUMN all_day_reminder_minutes INTEGER NOT NULL DEFAULT ''")
}
}
}
}
}

View File

@ -1,17 +1,26 @@
package com.simplemobiletools.calendar.pro.dialogs
import android.app.Activity
import android.app.TimePickerDialog
import android.widget.ImageView
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.helpers.REMINDER_OFF
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.views.MyTextView
import kotlinx.android.synthetic.main.dialog_set_reminders.view.*
import org.joda.time.LocalTime
class SetRemindersDialog(val activity: Activity, val callback: (reminders: ArrayList<Int>) -> Unit) {
class SetRemindersDialog(val activity: Activity, val callback: (reminders: ArrayList<Int>, allDayReminder: LocalTime?) -> Unit) {
private var mReminder1Minutes = -1
private var mReminder2Minutes = -1
private var mReminder3Minutes = -1
private var mAllDayReminderTime: LocalTime? = null
private var setAllDayRemindersTextView: MyTextView? = null
private var setAllDayRemindersDeleteButton: ImageView? = null
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_set_reminders, null).apply {
@ -20,6 +29,11 @@ class SetRemindersDialog(val activity: Activity, val callback: (reminders: Array
set_reminders_2.text = activity.getFormattedMinutes(mReminder1Minutes)
set_reminders_3.text = activity.getFormattedMinutes(mReminder1Minutes)
setAllDayRemindersTextView = set_all_day_reminders
setAllDayRemindersDeleteButton = set_all_day_reminder_delete
updateAllDayReminderText()
set_reminders_1.setOnClickListener {
activity.showPickSecondsDialogHelper(mReminder1Minutes) {
mReminder1Minutes = if (it <= 0) it else it / 60
@ -46,6 +60,12 @@ class SetRemindersDialog(val activity: Activity, val callback: (reminders: Array
set_reminders_3.text = activity.getFormattedMinutes(mReminder3Minutes)
}
}
set_all_day_reminders.setOnClickListener {
setupAllDayReminderTime()
}
set_all_day_reminder_delete.setOnClickListener { deleteAllDayReminder() }
}
AlertDialog.Builder(activity)
@ -56,6 +76,50 @@ class SetRemindersDialog(val activity: Activity, val callback: (reminders: Array
}
}
private fun setupAllDayReminderTime() {
var hours = 9
var minutes = 0
if (mAllDayReminderTime != null) {
hours = mAllDayReminderTime!!.hourOfDay
minutes = mAllDayReminderTime!!.minuteOfHour
}
activity.hideKeyboard()
TimePickerDialog(activity, activity.getDialogTheme(), allDayReminderTimeSetListener, hours, minutes, activity.config.use24HourFormat).show()
}
private val allDayReminderTimeSetListener = TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute ->
allDayReminderTimeSet(hourOfDay, minute)
}
private fun allDayReminderTimeSet(hours: Int, minutes: Int) {
mAllDayReminderTime = LocalTime()
mAllDayReminderTime = mAllDayReminderTime!!.withHourOfDay(hours).withMinuteOfHour(minutes)
updateAllDayReminderText()
updateAllDayReminderDeleteButton()
}
private fun updateAllDayReminderText() {
setAllDayRemindersTextView!!.apply {
if (mAllDayReminderTime != null) {
text = Formatter.getTime(activity, mAllDayReminderTime!!)
} else {
text = activity.resources.getString(R.string.add_during_day_reminder)
}
}
}
private fun updateAllDayReminderDeleteButton() {
setAllDayRemindersDeleteButton!!.beGoneIf(mAllDayReminderTime == null)
}
private fun deleteAllDayReminder() {
mAllDayReminderTime = null;
updateAllDayReminderText()
updateAllDayReminderDeleteButton()
}
private fun dialogConfirmed() {
val tempReminders = arrayListOf(mReminder1Minutes, mReminder2Minutes, mReminder3Minutes).filter { it != REMINDER_OFF }.sorted()
val reminders = arrayListOf(
@ -64,6 +128,6 @@ class SetRemindersDialog(val activity: Activity, val callback: (reminders: Array
tempReminders.getOrNull(2) ?: REMINDER_OFF
)
callback(reminders)
callback(reminders, mAllDayReminderTime)
}
}

View File

@ -90,7 +90,7 @@ fun Context.scheduleAllEvents() {
}
fun Context.scheduleNextEventReminder(event: Event, showToasts: Boolean) {
val validReminders = event.getReminders().filter { it.type == REMINDER_NOTIFICATION }
val validReminders = event.getReminders().filter { it.type == REMINDER_NOTIFICATION || it.type == ALL_DAY_REMINDER_NOTIFICATION }
if (validReminders.isEmpty()) {
if (showToasts) {
toast(R.string.saving)
@ -170,7 +170,7 @@ fun Context.getRepetitionText(seconds: Int) = when (seconds) {
}
fun Context.notifyRunningEvents() {
eventsHelper.getRunningEvents().filter { it.getReminders().any { it.type == REMINDER_NOTIFICATION } }.forEach {
eventsHelper.getRunningEvents().filter { it.getReminders().any { it.type == REMINDER_NOTIFICATION || it.type == ALL_DAY_REMINDER_NOTIFICATION } }.forEach {
notifyEvent(it)
}
}

View File

@ -210,7 +210,7 @@ class CalDAVHelper(val context: Context) {
val event = Event(null, startTS, endTS, title, location, description, reminder1?.minutes ?: REMINDER_OFF,
reminder2?.minutes ?: REMINDER_OFF, reminder3?.minutes ?: REMINDER_OFF, reminder1?.type
?: REMINDER_NOTIFICATION, reminder2?.type ?: REMINDER_NOTIFICATION, reminder3?.type
?: REMINDER_NOTIFICATION, repeatRule.repeatInterval, repeatRule.repeatRule,
?: REMINDER_NOTIFICATION, ALL_DAY_REMINDER_OFF, repeatRule.repeatInterval, repeatRule.repeatRule,
repeatRule.repeatLimit, ArrayList(), attendees, importId, eventTimeZone, allDay, eventTypeId, source = source)
if (event.getIsAllDay()) {

View File

@ -28,6 +28,7 @@ const val DAILY_VIEW = 5
const val LAST_VIEW = 6
const val REMINDER_OFF = -1
const val ALL_DAY_REMINDER_OFF = 1
const val ITEM_EVENT = 0
const val ITEM_EVENT_SIMPLE = 1
@ -155,5 +156,6 @@ const val DELETE_ALL_OCCURRENCES = 2
const val REMINDER_NOTIFICATION = 0
const val REMINDER_EMAIL = 1
const val ALL_DAY_REMINDER_NOTIFICATION = 2
fun getNowSeconds() = System.currentTimeMillis() / 1000L

View File

@ -7,6 +7,7 @@ import com.simplemobiletools.calendar.pro.extensions.seconds
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.joda.time.LocalDate
import org.joda.time.LocalTime
import org.joda.time.format.DateTimeFormat
object Formatter {
@ -69,6 +70,8 @@ object Formatter {
fun getTime(context: Context, dateTime: DateTime) = dateTime.toString(getTimePattern(context))
fun getTime(context: Context, time: LocalTime) = time.toString(getTimePattern(context))
fun getDateTimeFromCode(dayCode: String) = DateTimeFormat.forPattern(DAYCODE_PATTERN).withZone(DateTimeZone.UTC).parseDateTime(dayCode)
fun getLocalDateTimeFromCode(dayCode: String) = DateTimeFormat.forPattern(DAYCODE_PATTERN).withZone(DateTimeZone.getDefault()).parseLocalDate(dayCode).toDateTimeAtStartOfDay()

View File

@ -81,7 +81,7 @@ class IcsExporter {
val reminder = it
out.apply {
writeLn(BEGIN_ALARM)
if (reminder.type == REMINDER_NOTIFICATION) {
if (reminder.type == REMINDER_NOTIFICATION || reminder.type == ALL_DAY_REMINDER_NOTIFICATION) {
writeLn("$ACTION$DISPLAY")
} else {
writeLn("$ACTION$EMAIL")

View File

@ -185,7 +185,7 @@ class IcsImporter(val activity: SimpleActivity) {
val eventType = eventTypes.firstOrNull { it.id == curEventTypeId }
val source = if (calDAVCalendarId == 0 || eventType?.isSyncedEventType() == false) SOURCE_IMPORTED_ICS else "$CALDAV-$calDAVCalendarId"
val event = Event(null, curStart, curEnd, curTitle, curLocation, curDescription, reminders[0].minutes,
reminders[1].minutes, reminders[2].minutes, reminders[0].type, reminders[1].type, reminders[2].type, curRepeatInterval, curRepeatRule,
reminders[1].minutes, reminders[2].minutes, reminders[0].type, reminders[1].type, reminders[2].type, ALL_DAY_REMINDER_OFF, curRepeatInterval, curRepeatRule,
curRepeatLimit, curRepeatExceptions, "", curImportId, DateTimeZone.getDefault().id, curFlags, curEventTypeId, 0, curLastModified, source)
if (event.getIsAllDay() && curEnd > curStart) {

View File

@ -20,12 +20,13 @@ data class Event(
@ColumnInfo(name = "title") var title: String = "",
@ColumnInfo(name = "location") var location: String = "",
@ColumnInfo(name = "description") var description: String = "",
@ColumnInfo(name = "reminder_1_minutes") var reminder1Minutes: Int = -1,
@ColumnInfo(name = "reminder_2_minutes") var reminder2Minutes: Int = -1,
@ColumnInfo(name = "reminder_3_minutes") var reminder3Minutes: Int = -1,
@ColumnInfo(name = "reminder_1_minutes") var reminder1Minutes: Int = REMINDER_OFF,
@ColumnInfo(name = "reminder_2_minutes") var reminder2Minutes: Int = REMINDER_OFF,
@ColumnInfo(name = "reminder_3_minutes") var reminder3Minutes: Int = REMINDER_OFF,
@ColumnInfo(name = "reminder_1_type") var reminder1Type: Int = REMINDER_NOTIFICATION,
@ColumnInfo(name = "reminder_2_type") var reminder2Type: Int = REMINDER_NOTIFICATION,
@ColumnInfo(name = "reminder_3_type") var reminder3Type: Int = REMINDER_NOTIFICATION,
@ColumnInfo(name = "all_day_reminder_minutes") var allDayReminderMinutes: Int = ALL_DAY_REMINDER_OFF,
@ColumnInfo(name = "repeat_interval") var repeatInterval: Int = 0,
@ColumnInfo(name = "repeat_rule") var repeatRule: Int = 0,
@ColumnInfo(name = "repeat_limit") var repeatLimit: Long = 0L,
@ -129,8 +130,9 @@ data class Event(
fun getReminders() = setOf(
Reminder(reminder1Minutes, reminder1Type),
Reminder(reminder2Minutes, reminder2Type),
Reminder(reminder3Minutes, reminder3Type)
).filter { it.minutes != REMINDER_OFF }
Reminder(reminder3Minutes, reminder3Type),
Reminder(allDayReminderMinutes, ALL_DAY_REMINDER_NOTIFICATION)
).filter { (it.minutes != REMINDER_OFF && it.type == REMINDER_NOTIFICATION) || (it.minutes != ALL_DAY_REMINDER_OFF && it.type == ALL_DAY_REMINDER_NOTIFICATION) }
// properly return the start time of all-day events as midnight
fun getEventStartTS(): Long {

View File

@ -8,6 +8,7 @@ import com.simplemobiletools.calendar.pro.extensions.eventsDB
import com.simplemobiletools.calendar.pro.extensions.notifyEvent
import com.simplemobiletools.calendar.pro.extensions.scheduleNextEventReminder
import com.simplemobiletools.calendar.pro.extensions.updateListWidget
import com.simplemobiletools.calendar.pro.helpers.ALL_DAY_REMINDER_NOTIFICATION
import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.helpers.REMINDER_NOTIFICATION
@ -32,7 +33,7 @@ class NotificationReceiver : BroadcastReceiver() {
context.updateListWidget()
val event = context.eventsDB.getEventWithId(id)
if (event == null || event.getReminders().none { it.type == REMINDER_NOTIFICATION } || event.repetitionExceptions.contains(Formatter.getTodayCode())) {
if (event == null || event.getReminders().none { it.type == REMINDER_NOTIFICATION || it.type == ALL_DAY_REMINDER_NOTIFICATION } || event.repetitionExceptions.contains(Formatter.getTodayCode())) {
return
}

View File

@ -304,6 +304,62 @@
android:background="@color/divider_grey"
android:importantForAccessibility="no" />
<RelativeLayout
android:id="@+id/event_all_day_reminder_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/event_reminder_divider"
android:visibility="gone">
<ImageView
android:id="@+id/event_all_day_reminder_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignTop="@+id/event_all_day_reminder"
android:layout_alignBottom="@+id/event_all_day_reminder"
android:layout_marginStart="@dimen/normal_margin"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_bell_vector" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/event_all_day_reminder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/small_margin"
android:layout_toEndOf="@+id/event_all_day_reminder_image"
android:alpha="0.4"
android:background="?attr/selectableItemBackground"
android:ellipsize="end"
android:lines="1"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingBottom="@dimen/activity_margin"
android:textSize="@dimen/day_text_size"
tools:text="@string/add_another_reminder" />
<ImageView
android:id="@+id/event_all_day_reminder_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/event_all_day_reminder"
android:layout_alignBottom="@+id/event_all_day_reminder"
android:layout_alignParentEnd="true"
android:layout_marginStart="@dimen/small_margin"
android:padding="16dp"
android:src="@drawable/ic_delete_vector"
android:visibility="gone" />
<ImageView
android:id="@+id/event_all_day_reminder_divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@+id/event_all_day_reminder"
android:layout_marginTop="@dimen/medium_margin"
android:layout_marginBottom="@dimen/medium_margin"
android:background="@color/divider_grey"
android:importantForAccessibility="no" />
</RelativeLayout>
<ImageView
android:id="@+id/event_repetition_image"
android:layout_width="wrap_content"
@ -319,7 +375,7 @@
android:id="@+id/event_repetition"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/event_reminder_divider"
android:layout_below="@+id/event_all_day_reminder_layout"
android:layout_marginStart="@dimen/small_margin"
android:layout_toEndOf="@+id/event_repetition_image"
android:background="?attr/selectableItemBackground"

View File

@ -1,59 +1,117 @@
<?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"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin">
<RelativeLayout
android:id="@+id/set_reminders_dialog_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<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_vector" />
<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>
<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_vector"/>
android:id="@+id/event_description_divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@+id/set_reminders_dialog_holder"
android:layout_marginTop="@dimen/activity_margin"
android:layout_marginBottom="@dimen/normal_margin"
android:background="@color/divider_grey"
android:importantForAccessibility="no" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/set_reminders_1"
<RelativeLayout
android:id="@+id/set_all_day_reminders_dialog_holder"
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"/>
android:layout_below="@+id/event_description_divider"
android:orientation="vertical">
<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"/>
<ImageView
android:id="@+id/set_all_day_reminders_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignTop="@+id/set_all_day_reminders"
android:layout_alignBottom="@+id/set_all_day_reminders"
android:layout_marginStart="@dimen/normal_margin"
android:alpha="0.8"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_bell_vector" />
<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"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/set_all_day_reminders"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/small_margin"
android:layout_toEndOf="@+id/set_all_day_reminders_image"
android:background="?attr/selectableItemBackground"
android:paddingTop="@dimen/activity_margin"
android:paddingBottom="@dimen/activity_margin"
android:textSize="@dimen/day_text_size" />
<ImageView
android:id="@+id/set_all_day_reminder_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/set_all_day_reminders"
android:layout_alignBottom="@+id/set_all_day_reminders"
android:layout_alignParentEnd="true"
android:layout_marginStart="@dimen/small_margin"
android:padding="16dp"
android:src="@drawable/ic_delete_vector"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>

View File

@ -100,6 +100,7 @@
<string name="reminder">Reminder</string>
<string name="before">before</string>
<string name="add_another_reminder">Add another reminder</string>
<string name="add_during_day_reminder">Add during day reminder</string>
<string name="event_reminders">Event reminders</string>
<!-- Event attendees -->