forked from github/szkolny
[UI] Fix date dropdown selecting wrong month. Refactor event dialogs a bit.
This commit is contained in:
parent
c7950c53da
commit
e8da249353
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -8,6 +8,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
@ -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"/>
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
@ -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" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
@ -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" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
@ -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" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user