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
1 changed files with 15 additions and 6 deletions

View File

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