Reverting dragged view instead of refreshing calendar

This commit is contained in:
Agnieszka C 2023-07-16 17:27:40 +02:00
parent 1e2ba7d0d5
commit 33cd18099b

View file

@ -191,6 +191,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
fun updateCalendar() {
if (context != null) {
currentlyDraggedView = null
WeeklyCalendarImpl(this, requireContext()).updateWeeklyCalendar(weekTimestamp)
}
}
@ -299,9 +300,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
activity.hideKeyboard()
when (it) {
null -> {
// force update by removing hash
lastHash = 0
updateCalendar()
revertDraggedEvent()
}
EDIT_SELECTED_OCCURRENCE -> {
context?.eventsHelper?.editSelectedOccurrence(newEvent, false) {
@ -323,8 +322,12 @@ class WeekFragment : Fragment(), WeeklyCalendar {
}
}
} else {
context?.eventsHelper?.updateEvent(newEvent, updateAtCalDAV = true, showToasts = false) {
updateCalendar()
if (event.startTS == newEvent.startTS && event.endTS == newEvent.endTS) {
revertDraggedEvent()
} else {
context?.eventsHelper?.updateEvent(newEvent, updateAtCalDAV = true, showToasts = false) {
updateCalendar()
}
}
}
}
@ -340,6 +343,13 @@ class WeekFragment : Fragment(), WeeklyCalendar {
}
}
private fun revertDraggedEvent() {
activity?.runOnUiThread {
currentlyDraggedView?.beVisible()
currentlyDraggedView = null
}
}
private fun getViewGestureDetector(view: ViewGroup, index: Int): GestureDetector {
return GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapUp(event: MotionEvent): Boolean {
@ -932,7 +942,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
if (!dragEvent.result) {
view.beVisible()
}
currentlyDraggedView = null
true
}
else -> false