add Deleting events
This commit is contained in:
parent
2a25995bfc
commit
9203d679f6
|
@ -13,6 +13,7 @@ import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
import com.simplemobiletools.calendar.models.ListEvent
|
import com.simplemobiletools.calendar.models.ListEvent
|
||||||
import com.simplemobiletools.calendar.models.ListItem
|
import com.simplemobiletools.calendar.models.ListItem
|
||||||
import com.simplemobiletools.calendar.models.ListSection
|
import com.simplemobiletools.calendar.models.ListSection
|
||||||
|
import com.simplemobiletools.filepicker.dialogs.ConfirmationDialog
|
||||||
import kotlinx.android.synthetic.main.event_item.view.*
|
import kotlinx.android.synthetic.main.event_item.view.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -56,6 +57,10 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
||||||
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
|
R.id.cab_delete -> {
|
||||||
|
askConfirmDelete()
|
||||||
|
true
|
||||||
|
}
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,6 +81,20 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun askConfirmDelete() {
|
||||||
|
ConfirmationDialog(activity) {
|
||||||
|
actMode?.finish()
|
||||||
|
prepareForDeleting()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun prepareForDeleting() {
|
||||||
|
val selections = multiSelector.selectedPositions
|
||||||
|
val ids = ArrayList<Int>(selections.size)
|
||||||
|
selections.forEach { ids.add((mItems[it] as ListEvent).id) }
|
||||||
|
listener?.prepareForDeleting(ids)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getItemViewType(position: Int) = if (mItems[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
|
override fun getItemViewType(position: Int) = if (mItems[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
|
||||||
|
|
Loading…
Reference in New Issue