add a selector for deleting or keeping affected events at deleting event type
This commit is contained in:
parent
c0042ac0c9
commit
67135b0122
|
@ -8,14 +8,14 @@ import com.simplemobiletools.calendar.adapters.EventTypeAdapter
|
||||||
import com.simplemobiletools.calendar.dialogs.NewEventTypeDialog
|
import com.simplemobiletools.calendar.dialogs.NewEventTypeDialog
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
import com.simplemobiletools.calendar.helpers.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.calendar.models.EventType
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
import kotlinx.android.synthetic.main.activity_manage_event_types.*
|
import kotlinx.android.synthetic.main.activity_manage_event_types.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ManageEventTypesActivity : SimpleActivity(), DeleteItemsListener {
|
class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_manage_event_types)
|
setContentView(R.layout.activity_manage_event_types)
|
||||||
|
@ -53,7 +53,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteItemsListener {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun deleteItems(ids: ArrayList<Int>) {
|
override fun deleteEventTypes(ids: ArrayList<Int>, deleteEvents: Boolean) {
|
||||||
if (ids.contains(DBHelper.REGULAR_EVENT_TYPE_ID)) {
|
if (ids.contains(DBHelper.REGULAR_EVENT_TYPE_ID)) {
|
||||||
toast(R.string.cannot_delete_default_type)
|
toast(R.string.cannot_delete_default_type)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,15 @@ import com.bignerdranch.android.multiselector.SwappingHolder
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
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.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.extensions.setBackgroundWithStroke
|
||||||
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import kotlinx.android.synthetic.main.item_event_type.view.*
|
import kotlinx.android.synthetic.main.item_event_type.view.*
|
||||||
import java.util.*
|
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>() {
|
RecyclerView.Adapter<EventTypeAdapter.ViewHolder>() {
|
||||||
val multiSelector = MultiSelector()
|
val multiSelector = MultiSelector()
|
||||||
val views = ArrayList<View>()
|
val views = ArrayList<View>()
|
||||||
|
@ -68,17 +69,24 @@ class EventTypeAdapter(val activity: SimpleActivity, val mItems: List<EventType>
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun askConfirmDelete() {
|
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()
|
actMode?.finish()
|
||||||
deleteEventTypes()
|
deleteEventTypes(it == DELETE_EVENTS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteEventTypes() {
|
private fun deleteEventTypes(deleteEvents: Boolean) {
|
||||||
val selections = multiSelector.selectedPositions
|
val selections = multiSelector.selectedPositions
|
||||||
val ids = ArrayList<Int>(selections.size)
|
val ids = ArrayList<Int>(selections.size)
|
||||||
selections.forEach { ids.add((mItems[it]).id) }
|
selections.forEach { ids.add((mItems[it]).id) }
|
||||||
listener?.deleteItems(ids)
|
listener?.deleteEventTypes(ids, deleteEvents)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.simplemobiletools.calendar.interfaces
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
interface DeleteEventTypesListener {
|
||||||
|
fun deleteEventTypes(ids: ArrayList<Int>, deleteEvents: Boolean)
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
package com.simplemobiletools.calendar.interfaces
|
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
interface DeleteItemsListener {
|
|
||||||
fun deleteItems(ids: ArrayList<Int>)
|
|
||||||
}
|
|
Loading…
Reference in New Issue