diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt index f24cbf587..69de4ebec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/CustomEventReminderDialog.kt @@ -10,7 +10,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff 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) : AlertDialog.Builder(activity) { +class CustomEventReminderDialog(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 { if (selectedMinutes == 0) { @@ -41,7 +41,7 @@ class CustomEventReminderDialog(val activity: Activity, val selectedMinutes: Int val value = view.dialog_custom_reminder_value.value val multiplier = getMultiplier(view.dialog_radio_view.checkedRadioButtonId) val minutes = Integer.valueOf(if (value.isEmpty()) "0" else value) - callback.invoke(minutes * multiplier) + callback(minutes * multiplier) activity.hideKeyboard() dialog.dismiss() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt index ba0640f1f..9654b4885 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/DeleteEventDialog.kt @@ -9,7 +9,7 @@ import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.setupDialogStuff import kotlinx.android.synthetic.main.dialog_delete_event.view.* -class DeleteEventDialog(val activity: Activity, eventIds: List, val callback: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) { +class DeleteEventDialog(val activity: Activity, eventIds: List, val callback: (allOccurrences: Boolean) -> Unit) { val dialog: AlertDialog? init { @@ -36,6 +36,6 @@ class DeleteEventDialog(val activity: Activity, eventIds: List, val callbac private fun dialogConfirmed(view: ViewGroup, hasRepeatableEvent: Boolean) { val deleteAllOccurrences = !hasRepeatableEvent || view.delete_event_radio_view.checkedRadioButtonId == R.id.delete_event_all dialog?.dismiss() - callback.invoke(deleteAllOccurrences) + callback(deleteAllOccurrences) } } 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 818e85778..1cd34ff80 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EditRepeatingEventDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EditRepeatingEventDialog.kt @@ -8,7 +8,7 @@ import com.simplemobiletools.calendar.activities.SimpleActivity import com.simplemobiletools.commons.extensions.setupDialogStuff import kotlinx.android.synthetic.main.dialog_edit_repeating_event.view.* -class EditRepeatingEventDialog(val activity: SimpleActivity, val callback: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) { +class EditRepeatingEventDialog(val activity: SimpleActivity, val callback: (allOccurrences: Boolean) -> Unit) { var dialog: AlertDialog init { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ExportEventsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ExportEventsDialog.kt index 46da7258c..ddfc95c73 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ExportEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ExportEventsDialog.kt @@ -11,8 +11,7 @@ import com.simplemobiletools.commons.extensions.* import kotlinx.android.synthetic.main.dialog_export_events.view.* import java.io.File -class ExportEventsDialog(val activity: SimpleActivity, val path: String, val callback: (exportPastEvents: Boolean, file: File, eventTypes: HashSet) -> Unit) - : AlertDialog.Builder(activity) { +class ExportEventsDialog(val activity: SimpleActivity, val path: String, val callback: (exportPastEvents: Boolean, file: File, eventTypes: HashSet) -> Unit) { init { val view = (activity.layoutInflater.inflate(R.layout.dialog_export_events, null) as ViewGroup).apply { @@ -42,20 +41,20 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val cal activity.setupDialogStuff(view, this, R.string.export_events) getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ val filename = view.export_events_filename.value - if (filename.isEmpty()) { - activity.toast(R.string.empty_name) - } else if (filename.isAValidFilename()) { - val file = File(path, "$filename.ics") - if (file.exists()) { - activity.toast(R.string.name_taken) - return@setOnClickListener - } + when { + filename.isEmpty() -> activity.toast(R.string.empty_name) + filename.isAValidFilename() -> { + val file = File(path, "$filename.ics") + if (file.exists()) { + activity.toast(R.string.name_taken) + return@setOnClickListener + } - val eventTypes = (view.export_events_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsSet() - callback(view.export_events_checkbox.isChecked, file, eventTypes) - dismiss() - } else { - activity.toast(R.string.invalid_name) + val eventTypes = (view.export_events_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsSet() + callback(view.export_events_checkbox.isChecked, file, eventTypes) + dismiss() + } + else -> activity.toast(R.string.invalid_name) } }) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt index 6feb4dc53..fb1b50d59 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt @@ -11,7 +11,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff import kotlinx.android.synthetic.main.dialog_filter_event_types.view.* import java.util.* -class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> Unit) : AlertDialog.Builder(activity) { +class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> Unit) { var dialog: AlertDialog var eventTypes = ArrayList() val view = activity.layoutInflater.inflate(R.layout.dialog_filter_event_types, null) @@ -35,7 +35,7 @@ class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> U val selectedItems = (view.filter_event_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsSet() if (activity.config.displayEventTypes != selectedItems) { activity.config.displayEventTypes = selectedItems - callback.invoke() + callback() } dialog.dismiss() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt index e14d7b8bf..075b82123 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt @@ -14,7 +14,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.toast import kotlinx.android.synthetic.main.dialog_import_events.view.* -class ImportEventsDialog(val activity: SimpleActivity, val path: String, val callback: (refreshView: Boolean) -> Unit) : AlertDialog.Builder(activity) { +class ImportEventsDialog(val activity: SimpleActivity, val path: String, val callback: (refreshView: Boolean) -> Unit) { var currEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID init { @@ -45,7 +45,7 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal } private fun updateEventType(view: ViewGroup) { - val eventType = context.dbHelper.getEventType(currEventTypeId) + val eventType = activity.dbHelper.getEventType(currEventTypeId) view.import_event_type_title.text = eventType!!.getDisplayTitle() view.import_event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor) } @@ -56,6 +56,6 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal IMPORT_PARTIAL -> R.string.importing_some_events_failed else -> R.string.importing_events_failed }) - callback.invoke(result != IMPORT_FAIL) + callback(result != IMPORT_FAIL) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatLimitTypePickerDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatLimitTypePickerDialog.kt index 6c577ecbf..29b5988de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatLimitTypePickerDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatLimitTypePickerDialog.kt @@ -17,8 +17,7 @@ import kotlinx.android.synthetic.main.dialog_repeat_limit_type_picker.view.* import org.joda.time.DateTime import java.util.* -class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int, val startTS: Int, val callback: (repeatLimit: Int) -> Unit) : - AlertDialog.Builder(activity) { +class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int, val startTS: Int, val callback: (repeatLimit: Int) -> Unit) { lateinit var dialog: AlertDialog var view: View @@ -45,14 +44,13 @@ class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int, } } - private fun getCheckedItem(): Int { - return if (repeatLimit > 0) - R.id.repeat_type_till_date - else if (repeatLimit < 0) { + private fun getCheckedItem() = when { + repeatLimit > 0 -> R.id.repeat_type_till_date + repeatLimit < 0 -> { view.repeat_type_count.setText((-repeatLimit).toString()) R.id.repeat_type_x_times - } else - R.id.repeat_type_forever + } + else -> R.id.repeat_type_forever } private fun updateRepeatLimitText() { @@ -95,10 +93,10 @@ class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int, private val repetitionLimitDateSetListener = DatePickerDialog.OnDateSetListener { v, year, monthOfYear, dayOfMonth -> val repeatLimitDateTime = DateTime().withDate(year, monthOfYear + 1, dayOfMonth).withTime(23, 59, 59, 0) - if (repeatLimitDateTime.seconds() < startTS) { - repeatLimit = 0 + repeatLimit = if (repeatLimitDateTime.seconds() < startTS) { + 0 } else { - repeatLimit = repeatLimitDateTime.seconds() + repeatLimitDateTime.seconds() } callback(repeatLimit) dialog.dismiss() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatRuleWeeklyDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatRuleWeeklyDialog.kt index d69ce0ddb..18e694065 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatRuleWeeklyDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatRuleWeeklyDialog.kt @@ -8,8 +8,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.views.MyAppCompatCheckbox import kotlinx.android.synthetic.main.dialog_vertical_linear_layout.view.* -class RepeatRuleWeeklyDialog(val activity: Activity, val curRepeatRule: Int, val callback: (repeatRule: Int) -> Unit) : - AlertDialog.Builder(activity) { +class RepeatRuleWeeklyDialog(val activity: Activity, val curRepeatRule: Int, val callback: (repeatRule: Int) -> Unit) { val dialog: AlertDialog val view = activity.layoutInflater.inflate(R.layout.dialog_vertical_linear_layout, null) @@ -46,7 +45,7 @@ class RepeatRuleWeeklyDialog(val activity: Activity, val curRepeatRule: Int, val private fun getRepeatRuleSum(): Int { var sum = 0 val cnt = view.dialog_vertical_linear_layout.childCount - for (i in 0..cnt - 1) { + for (i in 0 until cnt) { val child = view.dialog_vertical_linear_layout.getChildAt(i) if (child is MyAppCompatCheckbox) { if (child.isChecked) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectCalendarsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectCalendarsDialog.kt index 509cb4284..cf0fda542 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectCalendarsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectCalendarsDialog.kt @@ -14,7 +14,7 @@ import kotlinx.android.synthetic.main.calendar_item_account.view.* import kotlinx.android.synthetic.main.calendar_item_calendar.view.* import kotlinx.android.synthetic.main.dialog_select_calendars.view.* -class SelectCalendarsDialog(val activity: Activity, val callback: () -> Unit) : AlertDialog.Builder(activity) { +class SelectCalendarsDialog(val activity: Activity, val callback: () -> Unit) { var prevAccount = "" var dialog: AlertDialog var view = (activity.layoutInflater.inflate(R.layout.dialog_select_calendars, null) as ViewGroup) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventCalendarDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventCalendarDialog.kt index 0b6a5a954..0ae96e8d6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventCalendarDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventCalendarDialog.kt @@ -63,7 +63,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List Unit) - : AlertDialog.Builder(activity) { +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() 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 055e54d47..641035672 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/UpdateEventTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/UpdateEventTypeDialog.kt @@ -15,7 +15,7 @@ import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.value import kotlinx.android.synthetic.main.dialog_event_type.view.* -class UpdateEventTypeDialog(val activity: Activity, var eventType: EventType? = null, val callback: (eventTypeId: Int) -> Unit) : AlertDialog.Builder(activity) { +class UpdateEventTypeDialog(val activity: Activity, var eventType: EventType? = null, val callback: (eventTypeId: Int) -> Unit) { var isNewEvent = eventType == null init { @@ -73,7 +73,7 @@ class UpdateEventTypeDialog(val activity: Activity, var eventType: EventType? = if (eventTypeId != -1) { dismiss() - callback.invoke(eventTypeId) + callback(eventTypeId) } else { activity.toast(R.string.editing_calendar_failed) }