From 67135b0122cf5bc6454e4150ac8f6549f4e080c4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 7 Jun 2017 21:50:23 +0200 Subject: [PATCH] add a selector for deleting or keeping affected events at deleting event type --- .../activities/ManageEventTypesActivity.kt | 6 ++--- .../calendar/adapters/EventTypeAdapter.kt | 22 +++++++++++++------ .../interfaces/DeleteEventTypesListener.kt | 7 ++++++ .../interfaces/DeleteItemsListener.kt | 7 ------ 4 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteEventTypesListener.kt delete mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteItemsListener.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt index e7aac1b7a..4c0181bf3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/ManageEventTypesActivity.kt @@ -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) { + override fun deleteEventTypes(ids: ArrayList, deleteEvents: Boolean) { if (ids.contains(DBHelper.REGULAR_EVENT_TYPE_ID)) { toast(R.string.cannot_delete_default_type) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventTypeAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventTypeAdapter.kt index bee30eb8d..e382381b5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventTypeAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventTypeAdapter.kt @@ -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, val listener: DeleteItemsListener?, val itemClick: (EventType) -> Unit) : +class EventTypeAdapter(val activity: SimpleActivity, val mItems: List, val listener: DeleteEventTypesListener?, val itemClick: (EventType) -> Unit) : RecyclerView.Adapter() { val multiSelector = MultiSelector() val views = ArrayList() @@ -68,17 +69,24 @@ class EventTypeAdapter(val activity: SimpleActivity, val mItems: List } private fun askConfirmDelete() { - ConfirmationDialog(activity) { + val MOVE_EVENTS = 0 + val DELETE_EVENTS = 1 + val res = activity.resources + val items = ArrayList().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(selections.size) selections.forEach { ids.add((mItems[it]).id) } - listener?.deleteItems(ids) + listener?.deleteEventTypes(ids, deleteEvents) } override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteEventTypesListener.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteEventTypesListener.kt new file mode 100644 index 000000000..9fec9d6a8 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteEventTypesListener.kt @@ -0,0 +1,7 @@ +package com.simplemobiletools.calendar.interfaces + +import java.util.* + +interface DeleteEventTypesListener { + fun deleteEventTypes(ids: ArrayList, deleteEvents: Boolean) +} diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteItemsListener.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteItemsListener.kt deleted file mode 100644 index 63ec06a5e..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteItemsListener.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.simplemobiletools.calendar.interfaces - -import java.util.* - -interface DeleteItemsListener { - fun deleteItems(ids: ArrayList) -}