optimize the way of checking if the selected events contain a repeatable event

This commit is contained in:
tibbi 2018-06-13 15:22:24 +02:00
parent 83e0006f0f
commit c62e08ada9
4 changed files with 6 additions and 8 deletions

View File

@ -562,7 +562,7 @@ class EventActivity : SimpleActivity() {
}
private fun deleteEvent() {
DeleteEventDialog(this, arrayListOf(mEvent.id)) {
DeleteEventDialog(this, arrayListOf(mEvent.id), mEvent.repeatInterval > 0) {
when (it) {
DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id, mEventOccurrenceTS)

View File

@ -118,7 +118,8 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
timestamps.add(event.startTS)
}
DeleteEventDialog(activity, eventIds) {
val hasRepeatableEvent = eventsToDelete.any { it.repeatInterval > 0 }
DeleteEventDialog(activity, eventIds, hasRepeatableEvent) {
events.removeAll(eventsToDelete)
when (it) {

View File

@ -212,7 +212,8 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
}
}
DeleteEventDialog(activity, eventIds) {
val hasRepeatableEvent = eventsToDelete.any { it.isRepeatable }
DeleteEventDialog(activity, eventIds, hasRepeatableEvent) {
listItems.removeAll(eventsToDelete)
when (it) {

View File

@ -4,7 +4,6 @@ import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.ViewGroup
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.helpers.DELETE_ALL_OCCURRENCES
import com.simplemobiletools.calendar.helpers.DELETE_FUTURE_OCCURRENCES
import com.simplemobiletools.calendar.helpers.DELETE_SELECTED_OCCURRENCE
@ -12,13 +11,10 @@ import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_delete_event.view.*
class DeleteEventDialog(val activity: Activity, eventIds: List<Int>, val callback: (deleteRule: Int) -> Unit) {
class DeleteEventDialog(val activity: Activity, eventIds: List<Int>, hasRepeatableEvent: Boolean, val callback: (deleteRule: Int) -> Unit) {
val dialog: AlertDialog?
init {
val events = activity.dbHelper.getEventsWithIds(eventIds)
val hasRepeatableEvent = events.any { it.repeatInterval > 0 }
val view = activity.layoutInflater.inflate(R.layout.dialog_delete_event, null).apply {
delete_event_repeat_description.beVisibleIf(hasRepeatableEvent)
delete_event_radio_view.beVisibleIf(hasRepeatableEvent)