Merge pull request #1485 from KryptKode/feat/add-reminder-on-holiday-import
Show reminder dialog on importing holidays
This commit is contained in:
commit
155da25db6
2 changed files with 34 additions and 23 deletions
|
@ -49,14 +49,14 @@ import com.simplemobiletools.commons.models.FAQItem
|
|||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.commons.models.Release
|
||||
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.OutputStream
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
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 {
|
||||
private val PICK_IMPORT_SOURCE_INTENT = 1
|
||||
|
@ -502,22 +502,24 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
|
||||
private fun addHolidays() {
|
||||
val items = getHolidayRadioItems()
|
||||
RadioGroupDialog(this, items) {
|
||||
toast(R.string.importing)
|
||||
ensureBackgroundThread {
|
||||
val holidays = getString(R.string.holidays)
|
||||
var eventTypeId = eventsHelper.getEventTypeIdWithTitle(holidays)
|
||||
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)
|
||||
if (result != ImportResult.IMPORT_FAIL) {
|
||||
runOnUiThread {
|
||||
updateViewPager()
|
||||
setupQuickFilter()
|
||||
RadioGroupDialog(this, items) { selectedHoliday ->
|
||||
SetRemindersDialog(this) {
|
||||
val reminders = it
|
||||
toast(R.string.importing)
|
||||
ensureBackgroundThread {
|
||||
val holidays = getString(R.string.holidays)
|
||||
var eventTypeId = eventsHelper.getEventTypeIdWithTitle(holidays)
|
||||
if (eventTypeId == -1L) {
|
||||
val eventType = EventType(null, holidays, resources.getColor(R.color.default_holidays_color))
|
||||
eventTypeId = eventsHelper.insertOrUpdateEventTypeSync(eventType)
|
||||
}
|
||||
val result = IcsImporter(this).importEvents(selectedHoliday as String, eventTypeId, 0, false, reminders)
|
||||
handleParseResult(result)
|
||||
if (result != ImportResult.IMPORT_FAIL) {
|
||||
runOnUiThread {
|
||||
updateViewPager()
|
||||
setupQuickFilter()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,14 +5,17 @@ import com.simplemobiletools.calendar.pro.R
|
|||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsDB
|
||||
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.EventType
|
||||
import com.simplemobiletools.calendar.pro.models.Reminder
|
||||
import com.simplemobiletools.commons.extensions.areDigitsOnly
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import org.joda.time.DateTimeZone
|
||||
import java.io.File
|
||||
import org.joda.time.DateTimeZone
|
||||
|
||||
class IcsImporter(val activity: SimpleActivity) {
|
||||
enum class ImportResult {
|
||||
|
@ -50,7 +53,13 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
private var eventsFailed = 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 {
|
||||
val eventTypes = eventsHelper.getEventTypesSync()
|
||||
val existingEvents = activity.eventsDB.getEventsWithImportIds().toMutableList() as ArrayList<Event>
|
||||
|
@ -192,7 +201,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
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(1) { REMINDER_OFF }, curReminderActions.getOrElse(1) { REMINDER_NOTIFICATION }),
|
||||
Reminder(curReminderMinutes.getOrElse(2) { REMINDER_OFF }, curReminderActions.getOrElse(2) { REMINDER_NOTIFICATION })
|
||||
|
|
Loading…
Reference in a new issue