From 798e77b4e7d761581301161466aa41939aa7b846 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 5 Mar 2017 15:38:33 +0100 Subject: [PATCH] create a new confirmation dialog for deleting events --- .../calendar/activities/EventActivity.kt | 3 ++- .../calendar/adapters/DayEventsAdapter.kt | 4 +-- .../calendar/adapters/EventListAdapter.kt | 4 +-- .../calendar/dialogs/DeleteEventDialog.kt | 27 +++++++++++++++++++ .../main/res/layout/dialog_delete_event.xml | 17 ++++++++++++ 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt create mode 100644 app/src/main/res/layout/dialog_delete_event.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index 2fd01ac41..00996c959 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -8,6 +8,7 @@ import android.view.Menu import android.view.MenuItem import android.view.WindowManager import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.dialogs.DeleteEventDialog import com.simplemobiletools.calendar.dialogs.EventReminderDialog import com.simplemobiletools.calendar.dialogs.EventRepeatIntervalDialog import com.simplemobiletools.calendar.dialogs.SelectEventTypeDialog @@ -257,7 +258,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { } private fun deleteEvent() { - ConfirmationDialog(this) { + DeleteEventDialog(this) { DBHelper.newInstance(applicationContext, this).deleteEvents(arrayOf(mEvent.id.toString())) finish() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt index f346c14fe..d6a393746 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt @@ -8,11 +8,11 @@ import com.bignerdranch.android.multiselector.MultiSelector import com.bignerdranch.android.multiselector.SwappingHolder import com.simplemobiletools.calendar.R 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.models.Event -import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.extensions.beInvisible import com.simplemobiletools.commons.extensions.beInvisibleIf import kotlinx.android.synthetic.main.event_item_day_view.view.* @@ -72,7 +72,7 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List, va } private fun askConfirmDelete() { - ConfirmationDialog(activity) { + DeleteEventDialog(activity) { actMode?.finish() deleteEvents() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt index 42850b56c..29a208ab2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt @@ -9,13 +9,13 @@ import com.bignerdranch.android.multiselector.MultiSelector import com.bignerdranch.android.multiselector.SwappingHolder import com.simplemobiletools.calendar.R 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.models.ListEvent import com.simplemobiletools.calendar.models.ListItem import com.simplemobiletools.calendar.models.ListSection -import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.extensions.beInvisible import com.simplemobiletools.commons.extensions.beInvisibleIf import kotlinx.android.synthetic.main.event_list_item.view.* @@ -88,7 +88,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List, } private fun askConfirmDelete() { - ConfirmationDialog(activity) { + DeleteEventDialog(activity) { actMode?.finish() prepareForDeleting() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt new file mode 100644 index 000000000..8e6f7af23 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt @@ -0,0 +1,27 @@ +package com.simplemobiletools.calendar.dialogs + +import android.app.Activity +import android.support.v7.app.AlertDialog +import android.view.LayoutInflater +import com.simplemobiletools.calendar.R +import com.simplemobiletools.commons.extensions.setupDialogStuff + +class DeleteEventDialog(val activity: Activity, val callback: () -> Unit) : AlertDialog.Builder(activity) { + val dialog: AlertDialog? + + init { + val view = LayoutInflater.from(activity).inflate(R.layout.dialog_delete_event, null) + + dialog = AlertDialog.Builder(activity) + .setPositiveButton(R.string.yes, { dialog, which -> dialogConfirmed() }) + .setNegativeButton(R.string.no, null) + .create().apply { + activity.setupDialogStuff(view, this) + } + } + + private fun dialogConfirmed() { + dialog?.dismiss() + callback.invoke() + } +} diff --git a/app/src/main/res/layout/dialog_delete_event.xml b/app/src/main/res/layout/dialog_delete_event.xml new file mode 100644 index 000000000..a6263b86a --- /dev/null +++ b/app/src/main/res/layout/dialog_delete_event.xml @@ -0,0 +1,17 @@ + + + + + +