diff --git a/app/build.gradle b/app/build.gradle index 056d2cb57..da72aa4af 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.0.12' + implementation 'com.simplemobiletools:commons:3.0.17' implementation 'joda-time:joda-time:2.9.9' implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.android.support:multidex:1.0.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index 0a791146f..37d60127c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -294,7 +294,7 @@ class MainActivity : SimpleActivity(), NavigationListener { val items = getHolidayRadioItems() RadioGroupDialog(this, items, -1) { toast(R.string.importing) - Thread({ + Thread { val holidays = getString(R.string.holidays) var eventTypeId = dbHelper.getEventTypeIdWithTitle(holidays) if (eventTypeId == -1) { @@ -308,14 +308,14 @@ class MainActivity : SimpleActivity(), NavigationListener { updateViewPager() } } - }).start() + }.start() } } private fun tryAddBirthdays() { handlePermission(PERMISSION_READ_CONTACTS) { if (it) { - Thread({ + Thread { addContactEvents(true) { if (it > 0) { toast(R.string.birthdays_added) @@ -324,7 +324,7 @@ class MainActivity : SimpleActivity(), NavigationListener { toast(R.string.no_birthdays) } } - }).start() + }.start() } else { toast(R.string.no_contacts_permission) } @@ -334,7 +334,7 @@ class MainActivity : SimpleActivity(), NavigationListener { private fun tryAddAnniversaries() { handlePermission(PERMISSION_READ_CONTACTS) { if (it) { - Thread({ + Thread { addContactEvents(false) { if (it > 0) { toast(R.string.anniversaries_added) @@ -343,7 +343,7 @@ class MainActivity : SimpleActivity(), NavigationListener { toast(R.string.no_anniversaries) } } - }).start() + }.start() } else { toast(R.string.no_contacts_permission) } @@ -541,7 +541,7 @@ class MainActivity : SimpleActivity(), NavigationListener { FilePickerDialog(this, pickFile = false) { val path = it ExportEventsDialog(this, path) { exportPastEvents, file, eventTypes -> - Thread({ + Thread { val events = dbHelper.getEventsToExport(exportPastEvents).filter { eventTypes.contains(it.eventType.toString()) } if (events.isEmpty()) { toast(R.string.no_events_for_exporting) @@ -555,7 +555,7 @@ class MainActivity : SimpleActivity(), NavigationListener { }) } } - }).start() + }.start() } } } @@ -665,7 +665,7 @@ class MainActivity : SimpleActivity(), NavigationListener { weeklyAdapter.updateScrollY(week_view_view_pager.currentItem, y) } }) - week_view_hours_scrollview.setOnTouchListener({ view, motionEvent -> true }) + week_view_hours_scrollview.setOnTouchListener{ view, motionEvent -> true } } fun updateHoursTopMargin(margin: Int) { 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 fa039b9f7..fa64a3bff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -156,7 +156,7 @@ class SettingsActivity : SimpleActivity() { config.caldavSync = newCalendarIds.isNotEmpty() toast(R.string.syncing) - Thread({ + Thread { if (newCalendarIds.isNotEmpty()) { val existingEventTypeNames = dbHelper.fetchEventTypes().map { it.getDisplayTitle().toLowerCase() } as ArrayList getSyncedCalDAVCalendars().forEach { @@ -179,7 +179,7 @@ class SettingsActivity : SimpleActivity() { } dbHelper.deleteEventTypesWithCalendarId(TextUtils.join(",", removedCalendarIds)) toast(R.string.synchronization_completed) - }).start() + }.start() } } 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 1cd34ff80..31a9ba25c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EditRepeatingEventDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/EditRepeatingEventDialog.kt @@ -19,8 +19,9 @@ 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) { + window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) + } } } 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 ddfc95c73..dcd920919 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ExportEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ExportEventsDialog.kt @@ -38,25 +38,26 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val cal .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .create().apply { - activity.setupDialogStuff(view, this, R.string.export_events) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ - val filename = view.export_events_filename.value - 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 - } + activity.setupDialogStuff(view, this, R.string.export_events) { + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val filename = view.export_events_filename.value + 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() + 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) } - else -> activity.toast(R.string.invalid_name) } - }) + } } } } 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 075b82123..20db15212 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt @@ -32,15 +32,16 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .create().apply { - activity.setupDialogStuff(view, this, R.string.import_events) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ - activity.toast(R.string.importing) - Thread({ - val result = IcsImporter().importEvents(activity, path, currEventTypeId) - handleParseResult(result) - dismiss() - }).start() - }) + activity.setupDialogStuff(view, this, R.string.import_events) { + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + activity.toast(R.string.importing) + Thread { + val result = IcsImporter().importEvents(activity, path, currEventTypeId) + handleParseResult(result) + dismiss() + }.start() + } + } } } 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 29b5988de..55cfc26fd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatLimitTypePickerDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/RepeatLimitTypePickerDialog.kt @@ -39,8 +39,9 @@ class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Int, .setPositiveButton(R.string.ok, { dialogInterface, i -> confirmRepetition() }) .setNegativeButton(R.string.cancel, null) .create().apply { - activity.setupDialogStuff(view, this) - activity.currentFocus?.clearFocus() + activity.setupDialogStuff(view, this) { + activity.currentFocus?.clearFocus() + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt index 0a655d0aa..fc6c47552 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt @@ -20,14 +20,15 @@ class SnoozePickerDialog(val activity: SimpleActivity, val minutes: Int, val cal .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() - }) + 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 641035672..c5bc43ba4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/UpdateEventTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/UpdateEventTypeDialog.kt @@ -45,39 +45,40 @@ class UpdateEventTypeDialog(val activity: Activity, var eventType: EventType? = .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) { + 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 + + val eventTypeId = if (isNewEvent) { + activity.dbHelper.insertEventType(eventType!!) + } else { + activity.dbHelper.updateEventType(eventType!!) + } + + if (eventTypeId != -1) { + dismiss() + callback(eventTypeId) + } else { + activity.toast(R.string.editing_calendar_failed) + } } - - eventType!!.title = title - if (eventType!!.caldavCalendarId != 0) - eventType!!.caldavDisplayName = title - - val eventTypeId = if (isNewEvent) { - activity.dbHelper.insertEventType(eventType!!) - } else { - activity.dbHelper.updateEventType(eventType!!) - } - - if (eventTypeId != -1) { - dismiss() - callback(eventTypeId) - } else { - activity.toast(R.string.editing_calendar_failed) - } - }) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index ff1c1d28c..0a444ef28 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -237,10 +237,10 @@ fun Context.getSyncedCalDAVCalendars() = CalDAVHandler(applicationContext).getCa fun Context.recheckCalDAVCalendars(callback: () -> Unit) { if (config.caldavSync) { - Thread({ + Thread { CalDAVHandler(applicationContext).refreshCalendars(null, callback) updateWidgets() - }).start() + }.start() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt index af3f5b3de..8d640f7c7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt @@ -95,7 +95,7 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DeleteEventsListen .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.ok) { dialog, which -> positivePressed(dateTime, datePicker) } .create().apply { - context.setupDialogStuff(view, this) + activity?.setupDialogStuff(view, this) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt index a84d2d734..c7d39cd48 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt @@ -137,7 +137,7 @@ class MonthFragment : Fragment(), MonthlyCalendar { .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.ok) { dialog, which -> positivePressed(dateTime, datePicker) } .create().apply { - context.setupDialogStuff(view, this) + activity?.setupDialogStuff(view, this) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index ab1d16d28..5832b0e63 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -573,9 +573,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } fun getEvents(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: MutableList) -> Unit) { - Thread({ + Thread { getEventsInBackground(fromTS, toTS, eventId, callback) - }).start() + }.start() } fun getEventsInBackground(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: MutableList) -> Unit) { @@ -847,9 +847,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } fun getEventTypes(callback: (types: ArrayList) -> Unit) { - Thread({ + Thread { callback(fetchEventTypes()) - }).start() + }.start() } fun fetchEventTypes(): ArrayList {