diff --git a/vishnu/src/main/java/com/yalantis/vishnu/implementation/MoveManagerImpl.kt b/vishnu/src/main/java/com/yalantis/vishnu/implementation/MoveManagerImpl.kt index 48b92da..022628a 100644 --- a/vishnu/src/main/java/com/yalantis/vishnu/implementation/MoveManagerImpl.kt +++ b/vishnu/src/main/java/com/yalantis/vishnu/implementation/MoveManagerImpl.kt @@ -128,7 +128,7 @@ class MoveManagerImpl(private val viewProvider: ViewProvider) : MoveManager { touchY < topLimit -> { viewProvider.moveWeek(selectedWeek, topLimit.toFloat()) viewProvider.setViewHeight(minHeight + dragHeight) - viewProvider.setDragTop(minHeight.toFloat()) + viewProvider.moveDragView(minHeight.toFloat()) controlAboveSelected(touchY, overScroll = true) controlBelowSelected(touchY, overScroll = true) } @@ -137,7 +137,7 @@ class MoveManagerImpl(private val viewProvider: ViewProvider) : MoveManager { private fun performMovement(newHeight: Float, touchY: Float) { viewProvider.setViewHeight(newHeight.toInt()) - viewProvider.setDragTop(touchY) + viewProvider.moveDragView(touchY) for (week in 0 until weekCount) { if (week < selectedWeek) { @@ -158,7 +158,7 @@ class MoveManagerImpl(private val viewProvider: ViewProvider) : MoveManager { if (week != selectedWeek) { val alpha = (1 - (Math.abs(defaultBottom - touchY) / (weekHeight / HIDE_MULTIPLIER))) if (alpha in ALPHA_RANGE) { - viewProvider.applyAlpha(week, alpha) + viewProvider.applyWeekAlpha(week, alpha) } } } @@ -176,14 +176,14 @@ class MoveManagerImpl(private val viewProvider: ViewProvider) : MoveManager { weekBottom = defaultPositions[week] when { - overScroll -> viewProvider.applyAlpha(week, ALPHA_INVISIBLE) + overScroll -> viewProvider.applyWeekAlpha(week, ALPHA_INVISIBLE) // makes sure that week hide touchY <= defaultPositions[week + 1] - halfWeek -> { - viewProvider.applyAlpha(week, ALPHA_INVISIBLE) + viewProvider.applyWeekAlpha(week, ALPHA_INVISIBLE) } touchY > weekBottom + weekHeight -> { - viewProvider.applyAlpha(week, ALPHA_VISIBLE) + viewProvider.applyWeekAlpha(week, ALPHA_VISIBLE) } } } @@ -198,15 +198,15 @@ class MoveManagerImpl(private val viewProvider: ViewProvider) : MoveManager { for (week in selectedWeek + 1 until weekCount) { when { - overScroll -> viewProvider.applyAlpha(week, ALPHA_INVISIBLE) + overScroll -> viewProvider.applyWeekAlpha(week, ALPHA_INVISIBLE) // touch below default bottom position touchY > defaultPositions[week] -> { - viewProvider.applyAlpha(week, ALPHA_VISIBLE) + viewProvider.applyWeekAlpha(week, ALPHA_VISIBLE) } // touch above default top position touchY <= defaultPositions[week] - halfWeek -> { - viewProvider.applyAlpha(week, ALPHA_INVISIBLE) + viewProvider.applyWeekAlpha(week, ALPHA_INVISIBLE) } } } diff --git a/vishnu/src/main/java/com/yalantis/vishnu/interfaces/ViewProvider.kt b/vishnu/src/main/java/com/yalantis/vishnu/interfaces/ViewProvider.kt index d9979e5..8484472 100644 --- a/vishnu/src/main/java/com/yalantis/vishnu/interfaces/ViewProvider.kt +++ b/vishnu/src/main/java/com/yalantis/vishnu/interfaces/ViewProvider.kt @@ -42,7 +42,7 @@ interface ViewProvider { * Change drag area top side */ - fun setDragTop(newDragTop: Float) + fun moveDragView(newDragTop: Float) /** * Return week bottom position @@ -80,12 +80,6 @@ interface ViewProvider { fun getViewTop(): Int - /** - * Change week height - */ - - fun setWeekHeight(i: Int, weekHeight: Int) - /** * Return drag area height */ @@ -102,7 +96,7 @@ interface ViewProvider { * Applies alpha to the week */ - fun applyAlpha(week: Int, alpha: Float) + fun applyWeekAlpha(week: Int, alpha: Float) /** * Request for weeks default positions diff --git a/vishnu/src/main/java/com/yalantis/vishnu/view/MonthPage.kt b/vishnu/src/main/java/com/yalantis/vishnu/view/MonthPage.kt index 1ae1475..90f213d 100644 --- a/vishnu/src/main/java/com/yalantis/vishnu/view/MonthPage.kt +++ b/vishnu/src/main/java/com/yalantis/vishnu/view/MonthPage.kt @@ -9,6 +9,7 @@ import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.MATCH_PARENT +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.LinearLayout import android.widget.TextView import androidx.core.content.ContextCompat @@ -423,7 +424,7 @@ class MonthPage(context: Context, stylable: VishnuStylable) : LinearLayout(conte textAlignment = View.TEXT_ALIGNMENT_CENTER setBackgroundColor(dragColor) }) - getChildAt(childCount - 1).layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, dragHeight).apply { + getChildAt(childCount - 1).layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { gravity = Gravity.BOTTOM } } @@ -458,6 +459,12 @@ class MonthPage(context: Context, stylable: VishnuStylable) : LinearLayout(conte private fun calculateMeasuredHeight() { val switchHeight = getChildAt(0).measuredHeight val weekHeight = getWeekHeight() + val dragView = getChildAt(childCount - 1) + + measureChild(dragView, measuredWidth, measuredHeight) + dragHeight = dragView.measuredHeight + dragView.layoutParams = dragView.layoutParams.apply { height = dragHeight } + collapsedHeight = switchHeight + weekHeight * 2 + dragHeight totalHeight = switchHeight + (weekHeight * (childCount - 2)) + dragHeight @@ -572,7 +579,7 @@ class MonthPage(context: Context, stylable: VishnuStylable) : LinearLayout(conte } } - override fun applyAlpha(week: Int, alpha: Float) { + override fun applyWeekAlpha(week: Int, alpha: Float) { getChildAt(week + WEEK_OFFSET).alpha = alpha } @@ -592,15 +599,10 @@ class MonthPage(context: Context, stylable: VishnuStylable) : LinearLayout(conte override fun getWeekCount() = childCount - WEEK_OFFSET - 1 // -1 cuz dragView - override fun setDragTop(newDragTop: Float) { + override fun moveDragView(newDragTop: Float) { getChildAt(childCount - 1).y = newDragTop } - override fun setWeekHeight(i: Int, weekHeight: Int) { - val week = getChildAt(i) - week.layoutParams = week.layoutParams.apply { height = weekHeight } - } - override fun getDragTop() = getChildAt(childCount - 1).y override fun getWeekHeight() = getChildAt(WEEK_OFFSET).height