From 5a221ec17a7bbc2c74deb93aa8ea5d71eea50f8b Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 4 Feb 2017 23:49:50 +0100 Subject: [PATCH] detect clicks on the grid --- .../calendar/fragments/WeekFragment.kt | 56 ++++++++++++++----- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt index cf4f5ab0b..22573d134 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt @@ -6,10 +6,7 @@ import android.graphics.Rect import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.support.v4.app.Fragment -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.view.ViewTreeObserver +import android.view.* import android.widget.LinearLayout import android.widget.RelativeLayout import android.widget.TextView @@ -33,6 +30,8 @@ import org.joda.time.Days import kotlin.comparisons.compareBy class WeekFragment : Fragment(), WeeklyCalendar { + val CLICK_DURATION_THRESHOLD = 150 + private var mListener: WeekScrollListener? = null private var mWeekTimestamp = 0 private var mRowHeight = 0 @@ -43,6 +42,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { private var isFragmentVisible = false private var wasFragmentInit = false private var wasExtraHeightAdded = false + private var clickStartTime = 0L lateinit var mView: View lateinit var mCalendar: WeeklyCalendarImpl @@ -155,16 +155,38 @@ class WeekFragment : Fragment(), WeeklyCalendar { } } + private fun initGrid() { + (0..6).map { getColumnWithId(it) } + .forEach { + activity.runOnUiThread { it.removeAllViews() } + it.setOnTouchListener { view, motionEvent -> + checkGridClick(motionEvent) + true + } + } + } + + private fun checkGridClick(event: MotionEvent) { + when (event.action) { + MotionEvent.ACTION_DOWN -> clickStartTime = System.currentTimeMillis() + MotionEvent.ACTION_UP -> { + if (System.currentTimeMillis() - clickStartTime < CLICK_DURATION_THRESHOLD) { + + } + } + else -> { + } + } + } + override fun updateWeeklyCalendar(events: List) { if (mWasDestroyed) return + initGrid() val fullHeight = mRes.getDimension(R.dimen.weekly_view_events_height) val minuteHeight = fullHeight / (24 * 60) val minimalHeight = mRes.getDimension(R.dimen.weekly_view_minimal_event_height).toInt() - (0..6).map { getColumnWithId(it) } - .forEach { activity.runOnUiThread { it.removeAllViews() } } - activity.runOnUiThread { mView.week_all_day_holder.removeAllViews() } var hadAllDayEvent = false @@ -204,17 +226,21 @@ class WeekFragment : Fragment(), WeeklyCalendar { } if (!hadAllDayEvent) { - mView.week_top_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { - override fun onGlobalLayout() { - mView.week_top_holder.viewTreeObserver.removeOnGlobalLayoutListener(this) - if (isFragmentVisible) { - (activity as MainActivity).updateHoursTopMargin(mView.week_top_holder.height) - } - } - }) + checkTopHolderHeight() } } + private fun checkTopHolderHeight() { + mView.week_top_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + mView.week_top_holder.viewTreeObserver.removeOnGlobalLayoutListener(this) + if (isFragmentVisible) { + (activity as MainActivity).updateHoursTopMargin(mView.week_top_holder.height) + } + } + }) + } + private fun addAllDayEvent(event: Event) { (LayoutInflater.from(context).inflate(R.layout.week_all_day_event_marker, null, false) as TextView).apply { background = ColorDrawable(primaryColor)