mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-19 13:10:51 +01:00
optimize the way of checking if the selected events contain a repeatable event
This commit is contained in:
parent
83e0006f0f
commit
c62e08ada9
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user