forked from github/szkolny
[Dialog/EventManual] Add process dialog and fix some things.
This commit is contained in:
parent
4480a7e486
commit
b5502478e4
@ -76,6 +76,8 @@ 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
|
||||||
|
|
||||||
init { run {
|
init { run {
|
||||||
if (activity.isFinishing)
|
if (activity.isFinishing)
|
||||||
return@run
|
return@run
|
||||||
@ -95,6 +97,8 @@ class EventManualDialog(
|
|||||||
.setOnDismissListener {
|
.setOnDismissListener {
|
||||||
onDismissListener?.invoke(TAG)
|
onDismissListener?.invoke(TAG)
|
||||||
EventBus.getDefault().unregister(this@EventManualDialog)
|
EventBus.getDefault().unregister(this@EventManualDialog)
|
||||||
|
enqueuedWeekDialog?.dismiss()
|
||||||
|
enqueuedProcessDialog?.dismiss()
|
||||||
}
|
}
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.create()
|
.create()
|
||||||
@ -178,11 +182,36 @@ class EventManualDialog(
|
|||||||
).enqueue(activity)
|
).enqueue(activity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showSharingProcessDialog() {
|
||||||
|
if (enqueuedProcessDialog != null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
enqueuedProcessDialog = MaterialAlertDialogBuilder(activity)
|
||||||
|
.setTitle(R.string.please_wait)
|
||||||
|
.setMessage(R.string.event_sharing_text)
|
||||||
|
.setCancelable(false)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showRemovingProcessDialog() {
|
||||||
|
if (enqueuedProcessDialog != null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
enqueuedProcessDialog = MaterialAlertDialogBuilder(activity)
|
||||||
|
.setTitle(R.string.please_wait)
|
||||||
|
.setMessage(R.string.event_removing_text)
|
||||||
|
.setCancelable(false)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
fun onApiTaskFinishedEvent(event: ApiTaskFinishedEvent) {
|
fun onApiTaskFinishedEvent(event: ApiTaskFinishedEvent) {
|
||||||
if (event.profileId == App.profileId) {
|
if (event.profileId == App.profileId) {
|
||||||
enqueuedWeekDialog?.dismiss()
|
enqueuedWeekDialog?.dismiss()
|
||||||
enqueuedWeekDialog = null
|
enqueuedWeekDialog = null
|
||||||
|
enqueuedProcessDialog?.dismiss()
|
||||||
launch {
|
launch {
|
||||||
b.timeDropdown.loadItems()
|
b.timeDropdown.loadItems()
|
||||||
}
|
}
|
||||||
@ -193,6 +222,7 @@ class EventManualDialog(
|
|||||||
fun onApiTaskAllFinishedEvent(event: ApiTaskAllFinishedEvent) {
|
fun onApiTaskAllFinishedEvent(event: ApiTaskAllFinishedEvent) {
|
||||||
enqueuedWeekDialog?.dismiss()
|
enqueuedWeekDialog?.dismiss()
|
||||||
enqueuedWeekDialog = null
|
enqueuedWeekDialog = null
|
||||||
|
enqueuedProcessDialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
@ -200,6 +230,7 @@ class EventManualDialog(
|
|||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
enqueuedWeekDialog?.dismiss()
|
enqueuedWeekDialog?.dismiss()
|
||||||
enqueuedWeekDialog = null
|
enqueuedWeekDialog = null
|
||||||
|
enqueuedProcessDialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadLists() { launch {
|
private fun loadLists() { launch {
|
||||||
@ -241,6 +272,8 @@ class EventManualDialog(
|
|||||||
if (!loadItems())
|
if (!loadItems())
|
||||||
syncTimetable(lessonsDate ?: Date.getToday())
|
syncTimetable(lessonsDate ?: Date.getToday())
|
||||||
selectDefault(editingEvent?.startTime)
|
selectDefault(editingEvent?.startTime)
|
||||||
|
if (editingEvent != null && editingEvent.startTime == null)
|
||||||
|
select(0L)
|
||||||
selectDefault(defaultLesson?.displayStartTime ?: defaultTime)
|
selectDefault(defaultLesson?.displayStartTime ?: defaultTime)
|
||||||
onLessonSelected = { lesson ->
|
onLessonSelected = { lesson ->
|
||||||
lesson.displaySubjectId?.let { b.subjectDropdown.selectSubject(it) } ?: b.subjectDropdown.deselect()
|
lesson.displaySubjectId?.let { b.subjectDropdown.selectSubject(it) } ?: b.subjectDropdown.deselect()
|
||||||
@ -323,7 +356,7 @@ class EventManualDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
b.typeColor.onClick {
|
b.typeColor.onClick {
|
||||||
val currentColor = (b.typeDropdown?.selected?.tag as EventType?)?.color ?: Event.COLOR_DEFAULT
|
val currentColor = (b.typeDropdown.selected?.tag as EventType?)?.color ?: Event.COLOR_DEFAULT
|
||||||
val colorPickerDialog = ColorPickerDialog.newBuilder()
|
val colorPickerDialog = ColorPickerDialog.newBuilder()
|
||||||
.setColor(currentColor)
|
.setColor(currentColor)
|
||||||
.create()
|
.create()
|
||||||
@ -386,8 +419,8 @@ class EventManualDialog(
|
|||||||
isError = true
|
isError = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeSelected == null || timeSelected !is Pair<*, *>) {
|
if (timeSelected !is Pair<*, *> && timeSelected != 0L) {
|
||||||
b.dateDropdown.error = app.getString(R.string.dialog_event_manual_time_choose)
|
b.timeDropdown.error = app.getString(R.string.dialog_event_manual_time_choose)
|
||||||
isError = true
|
isError = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,7 +486,7 @@ class EventManualDialog(
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
else if (!share && editingShared) {
|
else if (!share && editingShared) {
|
||||||
Toast.makeText(activity, R.string.event_manual_unshare, Toast.LENGTH_SHORT).show()
|
showSharingProcessDialog()
|
||||||
|
|
||||||
eventObject.apply {
|
eventObject.apply {
|
||||||
sharedBy = null
|
sharedBy = null
|
||||||
@ -468,7 +501,7 @@ class EventManualDialog(
|
|||||||
finishAdding(eventObject, metadataObject)
|
finishAdding(eventObject, metadataObject)
|
||||||
}
|
}
|
||||||
else if (share) {
|
else if (share) {
|
||||||
Toast.makeText(activity, R.string.event_manual_share, Toast.LENGTH_SHORT).show()
|
showSharingProcessDialog()
|
||||||
|
|
||||||
eventObject.apply {
|
eventObject.apply {
|
||||||
sharedBy = profile?.userCode
|
sharedBy = profile?.userCode
|
||||||
@ -488,13 +521,14 @@ class EventManualDialog(
|
|||||||
Toast.makeText(activity, "Unknown action :(", Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, "Unknown action :(", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
enqueuedProcessDialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeEvent() {
|
private fun removeEvent() {
|
||||||
launch {
|
launch {
|
||||||
if (editingShared && editingOwn) {
|
if (editingShared && editingOwn) {
|
||||||
// unshare + remove own event
|
// unshare + remove own event
|
||||||
Toast.makeText(activity, R.string.event_manual_unshare_remove, Toast.LENGTH_SHORT).show()
|
showRemovingProcessDialog()
|
||||||
|
|
||||||
api.runCatching(activity) {
|
api.runCatching(activity) {
|
||||||
unshareEvent(editingEvent!!)
|
unshareEvent(editingEvent!!)
|
||||||
@ -511,6 +545,7 @@ class EventManualDialog(
|
|||||||
finishRemoving()
|
finishRemoving()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
enqueuedProcessDialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun finishAdding(eventObject: Event, metadataObject: Metadata) {
|
private fun finishAdding(eventObject: Event, metadataObject: Metadata) {
|
||||||
|
@ -960,4 +960,6 @@
|
|||||||
<string name="other">Other</string>
|
<string name="other">Other</string>
|
||||||
<string name="menu_grades_config">Grades settings</string>
|
<string name="menu_grades_config">Grades settings</string>
|
||||||
<string name="dialog_day_lessons_info">%s - %s (%s lessons - %s hours %s minutes)</string>
|
<string name="dialog_day_lessons_info">%s - %s (%s lessons - %s hours %s minutes)</string>
|
||||||
|
<string name="event_sharing_text">Sharing the event…</string>
|
||||||
|
<string name="event_removing_text">Removing shared event…</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1268,4 +1268,6 @@
|
|||||||
<string name="card_type_grades">Ostatnie oceny</string>
|
<string name="card_type_grades">Ostatnie oceny</string>
|
||||||
<string name="card_type_events">Najbliższe wydarzenia</string>
|
<string name="card_type_events">Najbliższe wydarzenia</string>
|
||||||
<string name="dialog_event_manual_time_choose">Wybierz godzinę</string>
|
<string name="dialog_event_manual_time_choose">Wybierz godzinę</string>
|
||||||
|
<string name="event_sharing_text">Udostępnianie wydarzenia…</string>
|
||||||
|
<string name="event_removing_text">Usuwanie udostępnionego wydarzenia…</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user