From e8da249353e8c4a0c4ba6d005e08f44474b8a04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sun, 15 Mar 2020 14:54:26 +0100 Subject: [PATCH] [UI] Fix date dropdown selecting wrong month. Refactor event dialogs a bit. --- .../ui/dialogs/event/EventDetailsDialog.kt | 23 +++++++- .../ui/dialogs/event/EventManualDialog.kt | 56 ++++++++++++------- .../ui/modules/views/DateDropdown.kt | 4 +- .../res/layout/dialog_event_manual_v2.xml | 9 +++ 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt index 2f050bf3..26983861 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt @@ -47,6 +47,8 @@ class EventDetailsDialog( SzkolnyApi(app) } + private var progressDialog: AlertDialog? = null + init { run { if (activity.isFinishing) return@run @@ -64,6 +66,7 @@ class EventDetailsDialog( } .setOnDismissListener { onDismissListener?.invoke(TAG) + progressDialog?.dismiss() } .show() @@ -158,6 +161,18 @@ class EventDetailsDialog( } } + private fun showRemovingProgressDialog() { + if (progressDialog != null) { + return + } + + progressDialog = MaterialAlertDialogBuilder(activity) + .setTitle(R.string.please_wait) + .setMessage(R.string.event_removing_text) + .setCancelable(false) + .show() + } + private fun showRemoveEventDialog() { val shareNotice = when { eventShared && eventOwn -> "\n\n"+activity.getString(R.string.dialog_event_manual_remove_shared_self) @@ -186,11 +201,14 @@ class EventDetailsDialog( launch { if (eventShared && eventOwn) { // unshare + remove own event - Toast.makeText(activity, R.string.event_manual_unshare_remove, Toast.LENGTH_SHORT).show() + showRemovingProgressDialog() api.runCatching(activity) { unshareEvent(event) - } ?: return@launch + } ?: run { + progressDialog?.dismiss() + return@launch + } finishRemoving() } else if (eventShared && !eventOwn) { @@ -202,6 +220,7 @@ class EventDetailsDialog( Toast.makeText(activity, R.string.event_manual_remove, Toast.LENGTH_SHORT).show() finishRemoving() } + progressDialog?.dismiss() } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.kt index bb68a784..c6b95cb8 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.kt @@ -67,7 +67,6 @@ class EventManualDialog( private val editingShared = editingEvent?.sharedBy != null private val editingOwn = editingEvent?.sharedBy == "self" private var removeEventDialog: AlertDialog? = null - private var defaultLoaded = false private val api by lazy { SzkolnyApi(app) @@ -76,7 +75,7 @@ class EventManualDialog( private var enqueuedWeekDialog: AlertDialog? = null private var enqueuedWeekStart = Date.getToday() - private var enqueuedProcessDialog: AlertDialog? = null + private var progressDialog: AlertDialog? = null init { run { if (activity.isFinishing) @@ -98,7 +97,7 @@ class EventManualDialog( onDismissListener?.invoke(TAG) EventBus.getDefault().unregister(this@EventManualDialog) enqueuedWeekDialog?.dismiss() - enqueuedProcessDialog?.dismiss() + progressDialog?.dismiss() } .setCancelable(false) .create() @@ -182,24 +181,24 @@ class EventManualDialog( ).enqueue(activity) } - private fun showSharingProcessDialog() { - if (enqueuedProcessDialog != null) { + private fun showSharingProgressDialog() { + if (progressDialog != null) { return } - enqueuedProcessDialog = MaterialAlertDialogBuilder(activity) + progressDialog = MaterialAlertDialogBuilder(activity) .setTitle(R.string.please_wait) .setMessage(R.string.event_sharing_text) .setCancelable(false) .show() } - private fun showRemovingProcessDialog() { - if (enqueuedProcessDialog != null) { + private fun showRemovingProgressDialog() { + if (progressDialog != null) { return } - enqueuedProcessDialog = MaterialAlertDialogBuilder(activity) + progressDialog = MaterialAlertDialogBuilder(activity) .setTitle(R.string.please_wait) .setMessage(R.string.event_removing_text) .setCancelable(false) @@ -211,9 +210,11 @@ class EventManualDialog( if (event.profileId == App.profileId) { enqueuedWeekDialog?.dismiss() enqueuedWeekDialog = null - enqueuedProcessDialog?.dismiss() + progressDialog?.dismiss() launch { b.timeDropdown.loadItems() + b.timeDropdown.selectDefault(editingEvent?.startTime) + b.timeDropdown.selectDefault(defaultLesson?.displayStartTime ?: defaultTime) } } } @@ -222,15 +223,14 @@ class EventManualDialog( fun onApiTaskAllFinishedEvent(event: ApiTaskAllFinishedEvent) { enqueuedWeekDialog?.dismiss() enqueuedWeekDialog = null - enqueuedProcessDialog?.dismiss() + progressDialog?.dismiss() } @Subscribe(threadMode = ThreadMode.MAIN) fun onApiTaskErrorEvent(event: ApiTaskErrorEvent) { - dialog.dismiss() enqueuedWeekDialog?.dismiss() enqueuedWeekDialog = null - enqueuedProcessDialog?.dismiss() + progressDialog?.dismiss() } private fun loadLists() { launch { @@ -416,26 +416,31 @@ class EventManualDialog( if (date == null) { b.dateDropdown.error = app.getString(R.string.dialog_event_manual_date_choose) + b.dateDropdown.requestFocus() isError = true } if (timeSelected !is Pair<*, *> && timeSelected != 0L) { b.timeDropdown.error = app.getString(R.string.dialog_event_manual_time_choose) + if (!isError) b.timeDropdown.parent.requestChildFocus(b.timeDropdown, b.timeDropdown) isError = true } if (share && teamId == null) { b.teamDropdown.error = app.getString(R.string.dialog_event_manual_team_choose) + if (!isError) b.teamDropdown.parent.requestChildFocus(b.teamDropdown, b.teamDropdown) isError = true } if (type == null) { b.typeDropdown.error = app.getString(R.string.dialog_event_manual_type_choose) + if (!isError) b.typeDropdown.requestFocus() isError = true } if (topic.isNullOrBlank()) { b.topic.error = app.getString(R.string.dialog_event_manual_topic_choose) + if (!isError) b.topic.requestFocus() isError = true } @@ -486,7 +491,7 @@ class EventManualDialog( // TODO } else if (!share && editingShared) { - showSharingProcessDialog() + showSharingProgressDialog() eventObject.apply { sharedBy = null @@ -495,13 +500,16 @@ class EventManualDialog( api.runCatching(activity) { unshareEvent(eventObject) - } ?: return@launch + } ?: run { + progressDialog?.dismiss() + return@launch + } eventObject.sharedByName = null finishAdding(eventObject, metadataObject) } else if (share) { - showSharingProcessDialog() + showSharingProgressDialog() eventObject.apply { sharedBy = profile?.userCode @@ -512,7 +520,10 @@ class EventManualDialog( api.runCatching(activity) { shareEvent(eventObject.withMetadata(metadataObject)) - } ?: return@launch + } ?: run { + progressDialog?.dismiss() + return@launch + } eventObject.sharedBy = "self" finishAdding(eventObject, metadataObject) @@ -520,19 +531,22 @@ class EventManualDialog( else { Toast.makeText(activity, "Unknown action :(", Toast.LENGTH_SHORT).show() } + progressDialog?.dismiss() } - enqueuedProcessDialog?.dismiss() } private fun removeEvent() { launch { if (editingShared && editingOwn) { // unshare + remove own event - showRemovingProcessDialog() + showRemovingProgressDialog() api.runCatching(activity) { unshareEvent(editingEvent!!) - } ?: return@launch + } ?: run { + progressDialog?.dismiss() + return@launch + } finishRemoving() } else if (editingShared && !editingOwn) { @@ -544,8 +558,8 @@ class EventManualDialog( Toast.makeText(activity, R.string.event_manual_remove, Toast.LENGTH_SHORT).show() finishRemoving() } + progressDialog?.dismiss() } - enqueuedProcessDialog?.dismiss() } private fun finishAdding(eventObject: Event, metadataObject: Metadata) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/DateDropdown.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/DateDropdown.kt index b6fbad95..3d3ef4c7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/DateDropdown.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/DateDropdown.kt @@ -181,10 +181,10 @@ class DateDropdown : TextInputDropDown { DatePickerDialog .newInstance({ _, year, monthOfYear, dayOfMonth -> - val dateSelected = Date(year, monthOfYear, dayOfMonth) + val dateSelected = Date(year, monthOfYear+1, dayOfMonth) selectDate(dateSelected) onDateSelected?.invoke(dateSelected, null) - }, date.year, date.month, date.day) + }, date.year, date.month-1, date.day) .apply { this@DateDropdown.activity ?: return@apply accentColor = R.attr.colorPrimary.resolveAttr(this@DateDropdown.activity) diff --git a/app/src/main/res/layout/dialog_event_manual_v2.xml b/app/src/main/res/layout/dialog_event_manual_v2.xml index 8f0f6154..0c091883 100644 --- a/app/src/main/res/layout/dialog_event_manual_v2.xml +++ b/app/src/main/res/layout/dialog_event_manual_v2.xml @@ -8,6 +8,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> @@ -43,6 +44,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:enabled="false" + android:focusable="true" + android:focusableInTouchMode="true" tools:text="8:10 - język polski"/> @@ -58,6 +61,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:enabled="false" + android:focusable="true" + android:focusableInTouchMode="true" tools:text="2b3T" /> @@ -94,6 +99,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:enabled="false" + android:focusable="true" + android:focusableInTouchMode="true" tools:text="2b3T" /> @@ -123,6 +130,8 @@ android:layout_height="wrap_content" android:inputType="textLongMessage|textMultiLine|textImeMultiLine" android:minLines="2" + android:focusable="true" + android:focusableInTouchMode="true" tools:text="2b3T" />