add a selector for deleting or keeping affected events at deleting event type

This commit is contained in:
tibbi 2017-06-07 21:50:23 +02:00
parent c0042ac0c9
commit 67135b0122
4 changed files with 25 additions and 17 deletions

View File

@ -8,14 +8,14 @@ import com.simplemobiletools.calendar.adapters.EventTypeAdapter
import com.simplemobiletools.calendar.dialogs.NewEventTypeDialog
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.interfaces.DeleteItemsListener
import com.simplemobiletools.calendar.interfaces.DeleteEventTypesListener
import com.simplemobiletools.calendar.models.EventType
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import kotlinx.android.synthetic.main.activity_manage_event_types.*
import java.util.*
class ManageEventTypesActivity : SimpleActivity(), DeleteItemsListener {
class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_manage_event_types)
@ -53,7 +53,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteItemsListener {
return true
}
override fun deleteItems(ids: ArrayList<Int>) {
override fun deleteEventTypes(ids: ArrayList<Int>, deleteEvents: Boolean) {
if (ids.contains(DBHelper.REGULAR_EVENT_TYPE_ID)) {
toast(R.string.cannot_delete_default_type)
}

View File

@ -9,14 +9,15 @@ import com.bignerdranch.android.multiselector.SwappingHolder
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.interfaces.DeleteItemsListener
import com.simplemobiletools.calendar.interfaces.DeleteEventTypesListener
import com.simplemobiletools.calendar.models.EventType
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.setBackgroundWithStroke
import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.item_event_type.view.*
import java.util.*
class EventTypeAdapter(val activity: SimpleActivity, val mItems: List<EventType>, val listener: DeleteItemsListener?, val itemClick: (EventType) -> Unit) :
class EventTypeAdapter(val activity: SimpleActivity, val mItems: List<EventType>, val listener: DeleteEventTypesListener?, val itemClick: (EventType) -> Unit) :
RecyclerView.Adapter<EventTypeAdapter.ViewHolder>() {
val multiSelector = MultiSelector()
val views = ArrayList<View>()
@ -68,17 +69,24 @@ class EventTypeAdapter(val activity: SimpleActivity, val mItems: List<EventType>
}
private fun askConfirmDelete() {
ConfirmationDialog(activity) {
val MOVE_EVENTS = 0
val DELETE_EVENTS = 1
val res = activity.resources
val items = ArrayList<RadioItem>().apply {
add(RadioItem(MOVE_EVENTS, res.getString(R.string.move_events_into_default)))
add(RadioItem(DELETE_EVENTS, res.getString(R.string.remove_affected_events)))
}
RadioGroupDialog(activity, items, -1) {
actMode?.finish()
deleteEventTypes()
deleteEventTypes(it == DELETE_EVENTS)
}
}
private fun deleteEventTypes() {
private fun deleteEventTypes(deleteEvents: Boolean) {
val selections = multiSelector.selectedPositions
val ids = ArrayList<Int>(selections.size)
selections.forEach { ids.add((mItems[it]).id) }
listener?.deleteItems(ids)
listener?.deleteEventTypes(ids, deleteEvents)
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {

View File

@ -0,0 +1,7 @@
package com.simplemobiletools.calendar.interfaces
import java.util.*
interface DeleteEventTypesListener {
fun deleteEventTypes(ids: ArrayList<Int>, deleteEvents: Boolean)
}

View File

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