mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Handle drag multiple events in a one-time interval
This commit is contained in:
@@ -31,7 +31,6 @@ import com.simplemobiletools.commons.extensions.*
|
|||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.views.MyTextView
|
import com.simplemobiletools.commons.views.MyTextView
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlinx.android.synthetic.main.activity_event.event_all_day
|
|
||||||
import kotlinx.android.synthetic.main.fragment_week.*
|
import kotlinx.android.synthetic.main.fragment_week.*
|
||||||
import kotlinx.android.synthetic.main.fragment_week.view.*
|
import kotlinx.android.synthetic.main.fragment_week.view.*
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
@@ -73,6 +72,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
private var dayColumns = ArrayList<RelativeLayout>()
|
private var dayColumns = ArrayList<RelativeLayout>()
|
||||||
private var eventTypeColors = LongSparseArray<Int>()
|
private var eventTypeColors = LongSparseArray<Int>()
|
||||||
private var eventTimeRanges = LinkedHashMap<String, ArrayList<EventWeeklyView>>()
|
private var eventTimeRanges = LinkedHashMap<String, ArrayList<EventWeeklyView>>()
|
||||||
|
private var currentlyDraggedView: View? = null
|
||||||
|
|
||||||
private lateinit var inflater: LayoutInflater
|
private lateinit var inflater: LayoutInflater
|
||||||
private lateinit var mView: View
|
private lateinit var mView: View
|
||||||
@@ -278,6 +278,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DragEvent.ACTION_DRAG_ENTERED -> {
|
DragEvent.ACTION_DRAG_ENTERED -> {
|
||||||
|
Log.w(TAG, "initGrid: ACTION_DRAG_ENTERED")
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,6 +588,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setOnLongClickListener { view ->
|
setOnLongClickListener { view ->
|
||||||
|
currentlyDraggedView = view
|
||||||
val shadowBuilder = View.DragShadowBuilder(view)
|
val shadowBuilder = View.DragShadowBuilder(view)
|
||||||
val clipData = ClipData.newPlainText(WEEK_VIEW_DRAG_EVENT_ID_LABEL, event.id.toString())
|
val clipData = ClipData.newPlainText(WEEK_VIEW_DRAG_EVENT_ID_LABEL, event.id.toString())
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
@@ -848,6 +850,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setOnLongClickListener { view ->
|
setOnLongClickListener { view ->
|
||||||
|
currentlyDraggedView = view
|
||||||
val shadowBuilder = View.DragShadowBuilder(view)
|
val shadowBuilder = View.DragShadowBuilder(view)
|
||||||
val clipData = ClipData.newPlainText(WEEK_VIEW_DRAG_EVENT_ID_LABEL, event.id.toString())
|
val clipData = ClipData.newPlainText(WEEK_VIEW_DRAG_EVENT_ID_LABEL, event.id.toString())
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
@@ -895,17 +898,21 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||||||
addEvents(currEvents)
|
addEvents(currEvents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inner class DragListener : View.OnDragListener {
|
||||||
class DragListener : View.OnDragListener {
|
|
||||||
override fun onDrag(view: View, dragEvent: DragEvent): Boolean {
|
override fun onDrag(view: View, dragEvent: DragEvent): Boolean {
|
||||||
when (dragEvent.action) {
|
return when (dragEvent.action) {
|
||||||
// hide view when drag has been started
|
DragEvent.ACTION_DRAG_STARTED -> currentlyDraggedView == view
|
||||||
DragEvent.ACTION_DRAG_ENTERED -> view.visibility = View.INVISIBLE
|
DragEvent.ACTION_DRAG_ENTERED -> {
|
||||||
// show view when drag has been ended
|
view.beGone()
|
||||||
DragEvent.ACTION_DRAG_ENDED -> view.visibility = View.VISIBLE
|
false
|
||||||
|
}
|
||||||
|
DragEvent.ACTION_DRAG_ENDED -> {
|
||||||
|
currentlyDraggedView = null
|
||||||
|
view.beVisible()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user