Merge pull request #1485 from KryptKode/feat/add-reminder-on-holiday-import

Show reminder dialog on importing holidays
This commit is contained in:
Tibor Kaputa
2021-09-30 15:48:58 +02:00
committed by GitHub
2 changed files with 34 additions and 23 deletions

View File

@ -49,14 +49,14 @@ import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.models.Release import com.simplemobiletools.commons.models.Release
import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.commons.models.SimpleContact
import kotlinx.android.synthetic.main.activity_main.*
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.OutputStream import java.io.OutputStream
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlinx.android.synthetic.main.activity_main.*
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private val PICK_IMPORT_SOURCE_INTENT = 1 private val PICK_IMPORT_SOURCE_INTENT = 1
@ -502,22 +502,24 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun addHolidays() { private fun addHolidays() {
val items = getHolidayRadioItems() val items = getHolidayRadioItems()
RadioGroupDialog(this, items) { RadioGroupDialog(this, items) { selectedHoliday ->
toast(R.string.importing) SetRemindersDialog(this) {
ensureBackgroundThread { val reminders = it
val holidays = getString(R.string.holidays) toast(R.string.importing)
var eventTypeId = eventsHelper.getEventTypeIdWithTitle(holidays) ensureBackgroundThread {
if (eventTypeId == -1L) { val holidays = getString(R.string.holidays)
val eventType = EventType(null, holidays, resources.getColor(R.color.default_holidays_color)) var eventTypeId = eventsHelper.getEventTypeIdWithTitle(holidays)
eventTypeId = eventsHelper.insertOrUpdateEventTypeSync(eventType) if (eventTypeId == -1L) {
} val eventType = EventType(null, holidays, resources.getColor(R.color.default_holidays_color))
eventTypeId = eventsHelper.insertOrUpdateEventTypeSync(eventType)
val result = IcsImporter(this).importEvents(it as String, eventTypeId, 0, false) }
handleParseResult(result) val result = IcsImporter(this).importEvents(selectedHoliday as String, eventTypeId, 0, false, reminders)
if (result != ImportResult.IMPORT_FAIL) { handleParseResult(result)
runOnUiThread { if (result != ImportResult.IMPORT_FAIL) {
updateViewPager() runOnUiThread {
setupQuickFilter() updateViewPager()
setupQuickFilter()
}
} }
} }
} }

View File

@ -5,14 +5,17 @@ import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.SimpleActivity import com.simplemobiletools.calendar.pro.activities.SimpleActivity
import com.simplemobiletools.calendar.pro.extensions.eventsDB import com.simplemobiletools.calendar.pro.extensions.eventsDB
import com.simplemobiletools.calendar.pro.extensions.eventsHelper import com.simplemobiletools.calendar.pro.extensions.eventsHelper
import com.simplemobiletools.calendar.pro.helpers.IcsImporter.ImportResult.* import com.simplemobiletools.calendar.pro.helpers.IcsImporter.ImportResult.IMPORT_FAIL
import com.simplemobiletools.calendar.pro.helpers.IcsImporter.ImportResult.IMPORT_NOTHING_NEW
import com.simplemobiletools.calendar.pro.helpers.IcsImporter.ImportResult.IMPORT_OK
import com.simplemobiletools.calendar.pro.helpers.IcsImporter.ImportResult.IMPORT_PARTIAL
import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.calendar.pro.models.Event
import com.simplemobiletools.calendar.pro.models.EventType import com.simplemobiletools.calendar.pro.models.EventType
import com.simplemobiletools.calendar.pro.models.Reminder import com.simplemobiletools.calendar.pro.models.Reminder
import com.simplemobiletools.commons.extensions.areDigitsOnly import com.simplemobiletools.commons.extensions.areDigitsOnly
import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.extensions.showErrorToast
import org.joda.time.DateTimeZone
import java.io.File import java.io.File
import org.joda.time.DateTimeZone
class IcsImporter(val activity: SimpleActivity) { class IcsImporter(val activity: SimpleActivity) {
enum class ImportResult { enum class ImportResult {
@ -50,7 +53,13 @@ class IcsImporter(val activity: SimpleActivity) {
private var eventsFailed = 0 private var eventsFailed = 0
private var eventsAlreadyExist = 0 private var eventsAlreadyExist = 0
fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult { fun importEvents(
path: String,
defaultEventTypeId: Long,
calDAVCalendarId: Int,
overrideFileEventTypes: Boolean,
eventReminders: ArrayList<Int>? = null,
): ImportResult {
try { try {
val eventTypes = eventsHelper.getEventTypesSync() val eventTypes = eventsHelper.getEventTypesSync()
val existingEvents = activity.eventsDB.getEventsWithImportIds().toMutableList() as ArrayList<Event> val existingEvents = activity.eventsDB.getEventsWithImportIds().toMutableList() as ArrayList<Event>
@ -192,7 +201,7 @@ class IcsImporter(val activity: SimpleActivity) {
continue continue
} }
var reminders = arrayListOf( var reminders = eventReminders?.map { reminderMinutes -> Reminder(reminderMinutes, REMINDER_NOTIFICATION) } ?: arrayListOf(
Reminder(curReminderMinutes.getOrElse(0) { REMINDER_OFF }, curReminderActions.getOrElse(0) { REMINDER_NOTIFICATION }), Reminder(curReminderMinutes.getOrElse(0) { REMINDER_OFF }, curReminderActions.getOrElse(0) { REMINDER_NOTIFICATION }),
Reminder(curReminderMinutes.getOrElse(1) { REMINDER_OFF }, curReminderActions.getOrElse(1) { REMINDER_NOTIFICATION }), Reminder(curReminderMinutes.getOrElse(1) { REMINDER_OFF }, curReminderActions.getOrElse(1) { REMINDER_NOTIFICATION }),
Reminder(curReminderMinutes.getOrElse(2) { REMINDER_OFF }, curReminderActions.getOrElse(2) { REMINDER_NOTIFICATION }) Reminder(curReminderMinutes.getOrElse(2) { REMINDER_OFF }, curReminderActions.getOrElse(2) { REMINDER_NOTIFICATION })