[UI] Fix date dropdown selecting wrong month. Refactor event dialogs a bit.

This commit is contained in:
Kuba Szczodrzyński 2020-03-15 14:54:26 +01:00
parent c7950c53da
commit e8da249353
4 changed files with 67 additions and 25 deletions

View File

@ -47,6 +47,8 @@ class EventDetailsDialog(
SzkolnyApi(app) SzkolnyApi(app)
} }
private var progressDialog: AlertDialog? = null
init { run { init { run {
if (activity.isFinishing) if (activity.isFinishing)
return@run return@run
@ -64,6 +66,7 @@ class EventDetailsDialog(
} }
.setOnDismissListener { .setOnDismissListener {
onDismissListener?.invoke(TAG) onDismissListener?.invoke(TAG)
progressDialog?.dismiss()
} }
.show() .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() { private fun showRemoveEventDialog() {
val shareNotice = when { val shareNotice = when {
eventShared && eventOwn -> "\n\n"+activity.getString(R.string.dialog_event_manual_remove_shared_self) eventShared && eventOwn -> "\n\n"+activity.getString(R.string.dialog_event_manual_remove_shared_self)
@ -186,11 +201,14 @@ class EventDetailsDialog(
launch { launch {
if (eventShared && eventOwn) { if (eventShared && eventOwn) {
// unshare + remove own event // unshare + remove own event
Toast.makeText(activity, R.string.event_manual_unshare_remove, Toast.LENGTH_SHORT).show() showRemovingProgressDialog()
api.runCatching(activity) { api.runCatching(activity) {
unshareEvent(event) unshareEvent(event)
} ?: return@launch } ?: run {
progressDialog?.dismiss()
return@launch
}
finishRemoving() finishRemoving()
} else if (eventShared && !eventOwn) { } else if (eventShared && !eventOwn) {
@ -202,6 +220,7 @@ class EventDetailsDialog(
Toast.makeText(activity, R.string.event_manual_remove, Toast.LENGTH_SHORT).show() Toast.makeText(activity, R.string.event_manual_remove, Toast.LENGTH_SHORT).show()
finishRemoving() finishRemoving()
} }
progressDialog?.dismiss()
} }
} }

View File

@ -67,7 +67,6 @@ class EventManualDialog(
private val editingShared = editingEvent?.sharedBy != null private val editingShared = editingEvent?.sharedBy != null
private val editingOwn = editingEvent?.sharedBy == "self" private val editingOwn = editingEvent?.sharedBy == "self"
private var removeEventDialog: AlertDialog? = null private var removeEventDialog: AlertDialog? = null
private var defaultLoaded = false
private val api by lazy { private val api by lazy {
SzkolnyApi(app) SzkolnyApi(app)
@ -76,7 +75,7 @@ class EventManualDialog(
private var enqueuedWeekDialog: AlertDialog? = null private var enqueuedWeekDialog: AlertDialog? = null
private var enqueuedWeekStart = Date.getToday() private var enqueuedWeekStart = Date.getToday()
private var enqueuedProcessDialog: AlertDialog? = null private var progressDialog: AlertDialog? = null
init { run { init { run {
if (activity.isFinishing) if (activity.isFinishing)
@ -98,7 +97,7 @@ class EventManualDialog(
onDismissListener?.invoke(TAG) onDismissListener?.invoke(TAG)
EventBus.getDefault().unregister(this@EventManualDialog) EventBus.getDefault().unregister(this@EventManualDialog)
enqueuedWeekDialog?.dismiss() enqueuedWeekDialog?.dismiss()
enqueuedProcessDialog?.dismiss() progressDialog?.dismiss()
} }
.setCancelable(false) .setCancelable(false)
.create() .create()
@ -182,24 +181,24 @@ class EventManualDialog(
).enqueue(activity) ).enqueue(activity)
} }
private fun showSharingProcessDialog() { private fun showSharingProgressDialog() {
if (enqueuedProcessDialog != null) { if (progressDialog != null) {
return return
} }
enqueuedProcessDialog = MaterialAlertDialogBuilder(activity) progressDialog = MaterialAlertDialogBuilder(activity)
.setTitle(R.string.please_wait) .setTitle(R.string.please_wait)
.setMessage(R.string.event_sharing_text) .setMessage(R.string.event_sharing_text)
.setCancelable(false) .setCancelable(false)
.show() .show()
} }
private fun showRemovingProcessDialog() { private fun showRemovingProgressDialog() {
if (enqueuedProcessDialog != null) { if (progressDialog != null) {
return return
} }
enqueuedProcessDialog = MaterialAlertDialogBuilder(activity) progressDialog = MaterialAlertDialogBuilder(activity)
.setTitle(R.string.please_wait) .setTitle(R.string.please_wait)
.setMessage(R.string.event_removing_text) .setMessage(R.string.event_removing_text)
.setCancelable(false) .setCancelable(false)
@ -211,9 +210,11 @@ class EventManualDialog(
if (event.profileId == App.profileId) { if (event.profileId == App.profileId) {
enqueuedWeekDialog?.dismiss() enqueuedWeekDialog?.dismiss()
enqueuedWeekDialog = null enqueuedWeekDialog = null
enqueuedProcessDialog?.dismiss() progressDialog?.dismiss()
launch { launch {
b.timeDropdown.loadItems() b.timeDropdown.loadItems()
b.timeDropdown.selectDefault(editingEvent?.startTime)
b.timeDropdown.selectDefault(defaultLesson?.displayStartTime ?: defaultTime)
} }
} }
} }
@ -222,15 +223,14 @@ class EventManualDialog(
fun onApiTaskAllFinishedEvent(event: ApiTaskAllFinishedEvent) { fun onApiTaskAllFinishedEvent(event: ApiTaskAllFinishedEvent) {
enqueuedWeekDialog?.dismiss() enqueuedWeekDialog?.dismiss()
enqueuedWeekDialog = null enqueuedWeekDialog = null
enqueuedProcessDialog?.dismiss() progressDialog?.dismiss()
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onApiTaskErrorEvent(event: ApiTaskErrorEvent) { fun onApiTaskErrorEvent(event: ApiTaskErrorEvent) {
dialog.dismiss()
enqueuedWeekDialog?.dismiss() enqueuedWeekDialog?.dismiss()
enqueuedWeekDialog = null enqueuedWeekDialog = null
enqueuedProcessDialog?.dismiss() progressDialog?.dismiss()
} }
private fun loadLists() { launch { private fun loadLists() { launch {
@ -416,26 +416,31 @@ class EventManualDialog(
if (date == null) { if (date == null) {
b.dateDropdown.error = app.getString(R.string.dialog_event_manual_date_choose) b.dateDropdown.error = app.getString(R.string.dialog_event_manual_date_choose)
b.dateDropdown.requestFocus()
isError = true isError = true
} }
if (timeSelected !is Pair<*, *> && timeSelected != 0L) { if (timeSelected !is Pair<*, *> && timeSelected != 0L) {
b.timeDropdown.error = app.getString(R.string.dialog_event_manual_time_choose) b.timeDropdown.error = app.getString(R.string.dialog_event_manual_time_choose)
if (!isError) b.timeDropdown.parent.requestChildFocus(b.timeDropdown, b.timeDropdown)
isError = true isError = true
} }
if (share && teamId == null) { if (share && teamId == null) {
b.teamDropdown.error = app.getString(R.string.dialog_event_manual_team_choose) b.teamDropdown.error = app.getString(R.string.dialog_event_manual_team_choose)
if (!isError) b.teamDropdown.parent.requestChildFocus(b.teamDropdown, b.teamDropdown)
isError = true isError = true
} }
if (type == null) { if (type == null) {
b.typeDropdown.error = app.getString(R.string.dialog_event_manual_type_choose) b.typeDropdown.error = app.getString(R.string.dialog_event_manual_type_choose)
if (!isError) b.typeDropdown.requestFocus()
isError = true isError = true
} }
if (topic.isNullOrBlank()) { if (topic.isNullOrBlank()) {
b.topic.error = app.getString(R.string.dialog_event_manual_topic_choose) b.topic.error = app.getString(R.string.dialog_event_manual_topic_choose)
if (!isError) b.topic.requestFocus()
isError = true isError = true
} }
@ -486,7 +491,7 @@ class EventManualDialog(
// TODO // TODO
} }
else if (!share && editingShared) { else if (!share && editingShared) {
showSharingProcessDialog() showSharingProgressDialog()
eventObject.apply { eventObject.apply {
sharedBy = null sharedBy = null
@ -495,13 +500,16 @@ class EventManualDialog(
api.runCatching(activity) { api.runCatching(activity) {
unshareEvent(eventObject) unshareEvent(eventObject)
} ?: return@launch } ?: run {
progressDialog?.dismiss()
return@launch
}
eventObject.sharedByName = null eventObject.sharedByName = null
finishAdding(eventObject, metadataObject) finishAdding(eventObject, metadataObject)
} }
else if (share) { else if (share) {
showSharingProcessDialog() showSharingProgressDialog()
eventObject.apply { eventObject.apply {
sharedBy = profile?.userCode sharedBy = profile?.userCode
@ -512,7 +520,10 @@ class EventManualDialog(
api.runCatching(activity) { api.runCatching(activity) {
shareEvent(eventObject.withMetadata(metadataObject)) shareEvent(eventObject.withMetadata(metadataObject))
} ?: return@launch } ?: run {
progressDialog?.dismiss()
return@launch
}
eventObject.sharedBy = "self" eventObject.sharedBy = "self"
finishAdding(eventObject, metadataObject) finishAdding(eventObject, metadataObject)
@ -520,19 +531,22 @@ class EventManualDialog(
else { else {
Toast.makeText(activity, "Unknown action :(", Toast.LENGTH_SHORT).show() Toast.makeText(activity, "Unknown action :(", Toast.LENGTH_SHORT).show()
} }
progressDialog?.dismiss()
} }
enqueuedProcessDialog?.dismiss()
} }
private fun removeEvent() { private fun removeEvent() {
launch { launch {
if (editingShared && editingOwn) { if (editingShared && editingOwn) {
// unshare + remove own event // unshare + remove own event
showRemovingProcessDialog() showRemovingProgressDialog()
api.runCatching(activity) { api.runCatching(activity) {
unshareEvent(editingEvent!!) unshareEvent(editingEvent!!)
} ?: return@launch } ?: run {
progressDialog?.dismiss()
return@launch
}
finishRemoving() finishRemoving()
} else if (editingShared && !editingOwn) { } else if (editingShared && !editingOwn) {
@ -544,8 +558,8 @@ class EventManualDialog(
Toast.makeText(activity, R.string.event_manual_remove, Toast.LENGTH_SHORT).show() Toast.makeText(activity, R.string.event_manual_remove, Toast.LENGTH_SHORT).show()
finishRemoving() finishRemoving()
} }
progressDialog?.dismiss()
} }
enqueuedProcessDialog?.dismiss()
} }
private fun finishAdding(eventObject: Event, metadataObject: Metadata) { private fun finishAdding(eventObject: Event, metadataObject: Metadata) {

View File

@ -181,10 +181,10 @@ class DateDropdown : TextInputDropDown {
DatePickerDialog DatePickerDialog
.newInstance({ _, year, monthOfYear, dayOfMonth -> .newInstance({ _, year, monthOfYear, dayOfMonth ->
val dateSelected = Date(year, monthOfYear, dayOfMonth) val dateSelected = Date(year, monthOfYear+1, dayOfMonth)
selectDate(dateSelected) selectDate(dateSelected)
onDateSelected?.invoke(dateSelected, null) onDateSelected?.invoke(dateSelected, null)
}, date.year, date.month, date.day) }, date.year, date.month-1, date.day)
.apply { .apply {
this@DateDropdown.activity ?: return@apply this@DateDropdown.activity ?: return@apply
accentColor = R.attr.colorPrimary.resolveAttr(this@DateDropdown.activity) accentColor = R.attr.colorPrimary.resolveAttr(this@DateDropdown.activity)

View File

@ -8,6 +8,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView <ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -43,6 +44,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:enabled="false" android:enabled="false"
android:focusable="true"
android:focusableInTouchMode="true"
tools:text="8:10 - język polski"/> tools:text="8:10 - język polski"/>
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -58,6 +61,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:enabled="false" android:enabled="false"
android:focusable="true"
android:focusableInTouchMode="true"
tools:text="2b3T" /> tools:text="2b3T" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -94,6 +99,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:enabled="false" android:enabled="false"
android:focusable="true"
android:focusableInTouchMode="true"
tools:text="2b3T" /> tools:text="2b3T" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -123,6 +130,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textLongMessage|textMultiLine|textImeMultiLine" android:inputType="textLongMessage|textMultiLine|textImeMultiLine"
android:minLines="2" android:minLines="2"
android:focusable="true"
android:focusableInTouchMode="true"
tools:text="2b3T" /> tools:text="2b3T" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>