some code style updates at the dialogs

This commit is contained in:
tibbi 2017-09-24 00:08:17 +02:00
parent dd4c525880
commit 2c535015ba
14 changed files with 43 additions and 48 deletions

View file

@ -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()
}

View file

@ -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<Int>, val callback: (allOccurrences: Boolean) -> Unit) : AlertDialog.Builder(activity) {
class DeleteEventDialog(val activity: Activity, eventIds: List<Int>, val callback: (allOccurrences: Boolean) -> Unit) {
val dialog: AlertDialog?
init {
@ -36,6 +36,6 @@ class DeleteEventDialog(val activity: Activity, eventIds: List<Int>, 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)
}
}

View file

@ -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 {

View file

@ -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<String>) -> Unit)
: AlertDialog.Builder(activity) {
class ExportEventsDialog(val activity: SimpleActivity, val path: String, val callback: (exportPastEvents: Boolean, file: File, eventTypes: HashSet<String>) -> 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)
}
})
}

View file

@ -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<EventType>()
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()
}

View file

@ -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)
}
}

View file

@ -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()

View file

@ -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)

View file

@ -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)

View file

@ -63,7 +63,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
if (!wasInit)
return
callback.invoke(typeId)
callback(typeId)
dialog?.dismiss()
}
}

View file

@ -55,7 +55,7 @@ class SelectEventTypeColorDialog(val activity: Activity, val eventType: EventTyp
if (!wasInit)
return
callback.invoke(colors[colorKey])
callback(colors[colorKey])
dialog?.dismiss()
}
}

View file

@ -69,12 +69,12 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Int, val
if (typeId == NEW_TYPE_ID) {
UpdateEventTypeDialog(activity) {
callback.invoke(it)
callback(it)
activity.hideKeyboard()
dialog?.dismiss()
}
} else {
callback.invoke(typeId)
callback(typeId)
dialog?.dismiss()
}
}

View file

@ -9,8 +9,7 @@ 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)
: 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()

View file

@ -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)
}