From 0c28d4f5edc594e28d7703180088c2441dcbec91 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 6 Mar 2018 23:03:02 +0100 Subject: [PATCH] rename CustomEventReminderDialog to CustomIntervalPickerDialog --- .../calendar/activities/SettingsActivity.kt | 4 +- .../CustomEventRepeatIntervalDialog.kt | 9 +-- ...ialog.kt => CustomIntervalPickerDialog.kt} | 16 +++-- .../dialogs/EditRepeatingEventDialog.kt | 10 +-- .../calendar/dialogs/SnoozePickerDialog.kt | 34 ---------- .../calendar/dialogs/UpdateEventTypeDialog.kt | 66 +++++++++---------- .../calendar/extensions/Activity.kt | 4 +- .../main/res/layout/dialog_snooze_picker.xml | 30 --------- 8 files changed, 54 insertions(+), 119 deletions(-) rename app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/{CustomEventReminderDialog.kt => CustomIntervalPickerDialog.kt} (79%) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt delete mode 100644 app/src/main/res/layout/dialog_snooze_picker.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index 8f74a1535..0cbd86405 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -9,7 +9,7 @@ import android.os.Parcelable import android.text.TextUtils import com.simplemobiletools.calendar.BuildConfig import com.simplemobiletools.calendar.R -import com.simplemobiletools.calendar.dialogs.CustomEventReminderDialog +import com.simplemobiletools.calendar.dialogs.CustomIntervalPickerDialog import com.simplemobiletools.calendar.dialogs.SelectCalendarsDialog import com.simplemobiletools.calendar.extensions.* import com.simplemobiletools.calendar.helpers.CalDAVHandler @@ -336,7 +336,7 @@ class SettingsActivity : SimpleActivity() { var displayPastEvents = config.displayPastEvents updatePastEventsText(displayPastEvents) settings_display_past_events_holder.setOnClickListener { - CustomEventReminderDialog(this, displayPastEvents) { + CustomIntervalPickerDialog(this, displayPastEvents) { displayPastEvents = it config.displayPastEvents = it updatePastEventsText(it) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventRepeatIntervalDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventRepeatIntervalDialog.kt index 6791c92c6..18d1fd8b0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventRepeatIntervalDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventRepeatIntervalDialog.kt @@ -3,7 +3,6 @@ package com.simplemobiletools.calendar.dialogs import android.app.Activity import android.support.v7.app.AlertDialog import android.view.ViewGroup -import android.view.WindowManager import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.helpers.DAY import com.simplemobiletools.calendar.helpers.MONTH @@ -11,6 +10,7 @@ import com.simplemobiletools.calendar.helpers.WEEK import com.simplemobiletools.calendar.helpers.YEAR import com.simplemobiletools.commons.extensions.hideKeyboard import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.showKeyboard import com.simplemobiletools.commons.extensions.value import kotlinx.android.synthetic.main.dialog_custom_event_repeat_interval.view.* @@ -25,9 +25,10 @@ class CustomEventRepeatIntervalDialog(val activity: Activity, val callback: (sec .setPositiveButton(R.string.ok, { dialogInterface, i -> confirmRepeatInterval() }) .setNegativeButton(R.string.cancel, null) .create().apply { - window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - activity.setupDialogStuff(view, this) - } + activity.setupDialogStuff(view, this) { + showKeyboard(view.dialog_custom_repeat_interval_value) + } + } } private fun confirmRepeatInterval() { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomIntervalPickerDialog.kt similarity index 79% rename from app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt rename to app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomIntervalPickerDialog.kt index 3ffc50d1e..1821cef0c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomIntervalPickerDialog.kt @@ -3,21 +3,22 @@ package com.simplemobiletools.calendar.dialogs import android.app.Activity import android.support.v7.app.AlertDialog import android.view.ViewGroup -import android.view.WindowManager import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.helpers.DAY_MINUTES import com.simplemobiletools.commons.extensions.hideKeyboard import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.showKeyboard import com.simplemobiletools.commons.extensions.value import kotlinx.android.synthetic.main.dialog_custom_event_reminder.view.* -class CustomEventReminderDialog(val activity: Activity, val selectedMinutes: Int = 0, val callback: (minutes: Int) -> Unit) { +class CustomIntervalPickerDialog(val activity: Activity, val selectedMinutes: Int = 0, val callback: (minutes: Int) -> Unit) { var dialog: AlertDialog var view = (activity.layoutInflater.inflate(R.layout.dialog_custom_event_reminder, null) as ViewGroup).apply { when { selectedMinutes == 0 -> dialog_radio_view.check(R.id.dialog_radio_minutes) - selectedMinutes % 1440 == 0 -> { + selectedMinutes % DAY_MINUTES == 0 -> { dialog_radio_view.check(R.id.dialog_radio_days) - dialog_custom_reminder_value.setText((selectedMinutes / 1440).toString()) + dialog_custom_reminder_value.setText((selectedMinutes / DAY_MINUTES).toString()) } selectedMinutes % 60 == 0 -> { dialog_radio_view.check(R.id.dialog_radio_hours) @@ -35,9 +36,10 @@ class CustomEventReminderDialog(val activity: Activity, val selectedMinutes: Int .setPositiveButton(R.string.ok, { dialogInterface, i -> confirmReminder() }) .setNegativeButton(R.string.cancel, null) .create().apply { - window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - activity.setupDialogStuff(view, this) - } + activity.setupDialogStuff(view, this) { + showKeyboard(view.dialog_custom_reminder_value) + } + } } private fun confirmReminder() { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EditRepeatingEventDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EditRepeatingEventDialog.kt index 31a9ba25c..8edae6610 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EditRepeatingEventDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EditRepeatingEventDialog.kt @@ -2,9 +2,9 @@ package com.simplemobiletools.calendar.dialogs import android.support.v7.app.AlertDialog import android.view.ViewGroup -import android.view.WindowManager import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.activities.SimpleActivity +import com.simplemobiletools.commons.extensions.hideKeyboard import com.simplemobiletools.commons.extensions.setupDialogStuff import kotlinx.android.synthetic.main.dialog_edit_repeating_event.view.* @@ -19,10 +19,10 @@ class EditRepeatingEventDialog(val activity: SimpleActivity, val callback: (allO dialog = AlertDialog.Builder(activity) .create().apply { - activity.setupDialogStuff(view, this) { - window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) - } - } + activity.setupDialogStuff(view, this) { + hideKeyboard() + } + } } private fun sendResult(allOccurrences: Boolean) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt deleted file mode 100644 index fc6c47552..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.simplemobiletools.calendar.dialogs - -import android.support.v7.app.AlertDialog -import android.view.ViewGroup -import android.view.WindowManager -import com.simplemobiletools.calendar.R -import com.simplemobiletools.calendar.activities.SimpleActivity -import com.simplemobiletools.commons.extensions.setupDialogStuff -import com.simplemobiletools.commons.extensions.value -import kotlinx.android.synthetic.main.dialog_snooze_picker.view.* - -class SnoozePickerDialog(val activity: SimpleActivity, val minutes: Int, val callback: (newMinutes: Int) -> Unit) { - init { - val view = (activity.layoutInflater.inflate(R.layout.dialog_snooze_picker, null) as ViewGroup).apply { - snooze_picker_label.text = snooze_picker_label.text.toString().capitalize() - snooze_picker.setText(minutes.toString()) - } - - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) { - window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val value = view.snooze_picker.value - val minutes = Integer.valueOf(if (value.isEmpty() || value == "0") "1" else value) - callback(minutes) - dismiss() - } - } - } - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/UpdateEventTypeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/UpdateEventTypeDialog.kt index c9388ab91..c7693ede3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/UpdateEventTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/UpdateEventTypeDialog.kt @@ -2,17 +2,13 @@ package com.simplemobiletools.calendar.dialogs import android.app.Activity import android.support.v7.app.AlertDialog -import android.view.WindowManager import android.widget.ImageView import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.models.EventType import com.simplemobiletools.commons.dialogs.ColorPickerDialog -import com.simplemobiletools.commons.extensions.setBackgroundWithStroke -import com.simplemobiletools.commons.extensions.setupDialogStuff -import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.commons.extensions.value +import com.simplemobiletools.commons.extensions.* import kotlinx.android.synthetic.main.dialog_event_type.view.* class UpdateEventTypeDialog(val activity: Activity, var eventType: EventType? = null, val callback: (eventType: EventType) -> Unit) { @@ -44,42 +40,42 @@ class UpdateEventTypeDialog(val activity: Activity, var eventType: EventType? = .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .create().apply { - window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - activity.setupDialogStuff(view, this, if (isNewEvent) R.string.add_new_type else R.string.edit_type) { - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val title = view.type_title.value - val eventIdWithTitle = activity.dbHelper.getEventTypeIdWithTitle(title) - var isEventTypeTitleTaken = isNewEvent && eventIdWithTitle != -1 - if (!isEventTypeTitleTaken) - isEventTypeTitleTaken = !isNewEvent && eventType!!.id != eventIdWithTitle && eventIdWithTitle != -1 + activity.setupDialogStuff(view, this, if (isNewEvent) R.string.add_new_type else R.string.edit_type) { + showKeyboard(view.type_title) + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val title = view.type_title.value + val eventIdWithTitle = activity.dbHelper.getEventTypeIdWithTitle(title) + var isEventTypeTitleTaken = isNewEvent && eventIdWithTitle != -1 + if (!isEventTypeTitleTaken) + isEventTypeTitleTaken = !isNewEvent && eventType!!.id != eventIdWithTitle && eventIdWithTitle != -1 - if (title.isEmpty()) { - activity.toast(R.string.title_empty) - return@setOnClickListener - } else if (isEventTypeTitleTaken) { - activity.toast(R.string.type_already_exists) - return@setOnClickListener - } + if (title.isEmpty()) { + activity.toast(R.string.title_empty) + return@setOnClickListener + } else if (isEventTypeTitleTaken) { + activity.toast(R.string.type_already_exists) + return@setOnClickListener + } - eventType!!.title = title - if (eventType!!.caldavCalendarId != 0) - eventType!!.caldavDisplayName = title + eventType!!.title = title + if (eventType!!.caldavCalendarId != 0) + eventType!!.caldavDisplayName = title - eventType!!.id = if (isNewEvent) { - activity.dbHelper.insertEventType(eventType!!) - } else { - activity.dbHelper.updateEventType(eventType!!) - } + eventType!!.id = if (isNewEvent) { + activity.dbHelper.insertEventType(eventType!!) + } else { + activity.dbHelper.updateEventType(eventType!!) + } - if (eventType!!.id != -1) { - dismiss() - callback(eventType!!) - } else { - activity.toast(R.string.editing_calendar_failed) + if (eventType!!.id != -1) { + dismiss() + callback(eventType!!) + } else { + activity.toast(R.string.editing_calendar_failed) + } + } } } - } - } } private fun setupColor(view: ImageView) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt index f7fb1815b..c79ac73f4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt @@ -3,8 +3,8 @@ package com.simplemobiletools.calendar.extensions import android.app.Activity import com.simplemobiletools.calendar.BuildConfig import com.simplemobiletools.calendar.R -import com.simplemobiletools.calendar.dialogs.CustomEventReminderDialog import com.simplemobiletools.calendar.dialogs.CustomEventRepeatIntervalDialog +import com.simplemobiletools.calendar.dialogs.CustomIntervalPickerDialog import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.RadioGroupDialog @@ -75,7 +75,7 @@ fun Activity.showEventReminderDialog(curMinutes: Int, isSnoozePicker: Boolean = RadioGroupDialog(this, items, selectedIndex, showOKButton = isSnoozePicker, cancelCallback = cancelCallback) { if (it == -2) { - CustomEventReminderDialog(this) { + CustomIntervalPickerDialog(this) { callback(it) } } else { diff --git a/app/src/main/res/layout/dialog_snooze_picker.xml b/app/src/main/res/layout/dialog_snooze_picker.xml deleted file mode 100644 index 84792d64e..000000000 --- a/app/src/main/res/layout/dialog_snooze_picker.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - -