implement deleting of single occurrences of repeatable events in other screens

This commit is contained in:
tibbi 2017-03-05 20:36:12 +01:00
parent 897aa82c3f
commit f2386f8f18
6 changed files with 47 additions and 13 deletions

View file

@ -11,14 +11,14 @@ import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.dialogs.DeleteEventDialog
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.DeleteItemsListener
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.extensions.beInvisible
import com.simplemobiletools.commons.extensions.beInvisibleIf
import kotlinx.android.synthetic.main.event_item_day_view.view.*
import java.util.*
class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val listener: DeleteItemsListener?, val itemClick: (Event) -> Unit) :
class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val listener: DeleteEventsListener?, val itemClick: (Event) -> Unit) :
RecyclerView.Adapter<DayEventsAdapter.ViewHolder>() {
val multiSelector = MultiSelector()
val views = ArrayList<View>()
@ -74,13 +74,17 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, va
private fun askConfirmDelete() {
val selections = multiSelector.selectedPositions
val eventIds = ArrayList<Int>(selections.size)
selections.forEach { eventIds.add(mItems[it].id) }
val timestamps = ArrayList<Int>(selections.size)
selections.forEach {
eventIds.add(mItems[it].id)
timestamps.add(mItems[it].startTS)
}
DeleteEventDialog(activity, eventIds) {
if (it) {
listener?.deleteItems(eventIds)
} else {
listener?.deleteEventOccurrences(eventIds, timestamps)
}
actMode?.finish()
}

View file

@ -12,7 +12,7 @@ import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.dialogs.DeleteEventDialog
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.DeleteItemsListener
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
import com.simplemobiletools.calendar.models.ListEvent
import com.simplemobiletools.calendar.models.ListItem
import com.simplemobiletools.calendar.models.ListSection
@ -21,7 +21,7 @@ import com.simplemobiletools.commons.extensions.beInvisibleIf
import kotlinx.android.synthetic.main.event_list_item.view.*
import java.util.*
class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>, val listener: DeleteItemsListener?, val itemClick: (Int, Int) -> Unit) :
class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>, val listener: DeleteEventsListener?, val itemClick: (Int, Int) -> Unit) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
val multiSelector = MultiSelector()
val views = ArrayList<View>()
@ -90,13 +90,18 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
private fun askConfirmDelete() {
val selections = multiSelector.selectedPositions
val eventIds = ArrayList<Int>(selections.size)
selections.forEach { eventIds.add((mItems[it] as ListEvent).id) }
val timestamps = ArrayList<Int>(selections.size)
selections.forEach {
eventIds.add((mItems[it] as ListEvent).id)
timestamps.add((mItems[it] as ListEvent).startTS)
}
DeleteEventDialog(activity, eventIds) {
if (it) {
listener?.deleteItems(eventIds)
} else {
listener?.deleteEventOccurrences(eventIds, timestamps)
}
actMode?.finish()
}

View file

@ -10,7 +10,7 @@ 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, val eventIds: List<Int>, val callback: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) {
class DeleteEventDialog(val activity: Activity, eventIds: List<Int>, val callback: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) {
val dialog: AlertDialog?
init {

View file

@ -21,7 +21,7 @@ import com.simplemobiletools.calendar.extensions.getAppropriateTheme
import com.simplemobiletools.calendar.extensions.getFilteredEvents
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.DeleteItemsListener
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.extensions.setupDialogStuff
@ -32,7 +32,7 @@ import org.joda.time.DateTime
import java.util.*
import kotlin.comparisons.compareBy
class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEventsListener, DeleteItemsListener {
class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEventsListener, DeleteEventsListener {
private var mTextColor = 0
private var mDayCode = ""
private var mListener: NavigationListener? = null
@ -141,6 +141,14 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
DBHelper.newInstance(activity.applicationContext, this).deleteEvents(eventIDs)
}
override fun deleteEventOccurrences(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
val db = DBHelper.newInstance(context)
parentIds.forEachIndexed { index, value ->
db.deleteEventOccurrence(parentIds[index], timestamps[index])
}
(activity as DayActivity).recheckEvents()
}
override fun eventInserted(event: Event) {
}

View file

@ -17,7 +17,7 @@ import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.EVENT_ID
import com.simplemobiletools.calendar.helpers.EVENT_OCCURRENCE_TS
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.DeleteItemsListener
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.models.ListEvent
import com.simplemobiletools.calendar.models.ListItem
@ -29,7 +29,7 @@ import org.joda.time.DateTime
import java.util.*
import kotlin.comparisons.compareBy
class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, DeleteItemsListener {
class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, DeleteEventsListener {
private var mEvents: List<Event> = ArrayList()
private var prevEventsHash = 0
lateinit var mView: View
@ -110,6 +110,14 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
DBHelper.newInstance(activity.applicationContext, this).deleteEvents(eventIDs)
}
override fun deleteEventOccurrences(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
val db = DBHelper.newInstance(context)
parentIds.forEachIndexed { index, value ->
db.deleteEventOccurrence(parentIds[index], timestamps[index])
}
checkEvents()
}
override fun eventInserted(event: Event) {
checkEvents()
}

View file

@ -0,0 +1,9 @@
package com.simplemobiletools.calendar.interfaces
import java.util.*
interface DeleteEventsListener {
fun deleteItems(ids: ArrayList<Int>)
fun deleteEventOccurrences(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>)
}