check if we should delete all repeatable event occurrences, or just one

This commit is contained in:
tibbi 2017-03-05 18:16:18 +01:00
parent 81301babf0
commit 66a9c31830
4 changed files with 21 additions and 7 deletions

View File

@ -258,7 +258,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
private fun deleteEvent() {
DeleteEventDialog(this, arrayListOf(mEvent.id)) {
if (it) {
DBHelper.newInstance(applicationContext, this).deleteEvents(arrayOf(mEvent.id.toString()))
} else {
}
finish()
}
}

View File

@ -77,8 +77,12 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, va
selections.forEach { eventIds.add(mItems[it].id) }
DeleteEventDialog(activity, eventIds) {
actMode?.finish()
if (it) {
listener?.deleteItems(eventIds)
} else {
}
actMode?.finish()
}
}

View File

@ -93,8 +93,12 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
selections.forEach { eventIds.add((mItems[it] as ListEvent).id) }
DeleteEventDialog(activity, eventIds) {
actMode?.finish()
if (it) {
listener?.deleteItems(eventIds)
} else {
}
actMode?.finish()
}
}

View File

@ -3,13 +3,14 @@ package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.ViewGroup
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.helpers.DBHelper
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: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) {
class DeleteEventDialog(val activity: Activity, val eventIds: List<Int>, val callback: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) {
val dialog: AlertDialog?
init {
@ -22,15 +23,16 @@ class DeleteEventDialog(val activity: Activity, eventIds: List<Int>, val callbac
}
dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.yes, { dialog, which -> dialogConfirmed() })
.setPositiveButton(R.string.yes, { dialog, which -> dialogConfirmed(view as ViewGroup, hasRepeatableEvent) })
.setNegativeButton(R.string.no, null)
.create().apply {
activity.setupDialogStuff(view, this)
}
}
private fun dialogConfirmed() {
private fun dialogConfirmed(view: ViewGroup, hasRepeatableEvent: Boolean) {
val deleteAllOccurrences = !hasRepeatableEvent || view.delete_event_radio_view.checkedRadioButtonId == R.id.delete_event_all
dialog?.dismiss()
callback.invoke(true)
callback.invoke(deleteAllOccurrences)
}
}