Skip to content

Commit

Permalink
First week overlap fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill committed Jan 18, 2019
1 parent b166efa commit 01fba8b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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) {
Expand All @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface ViewProvider {
* Change drag area top side
*/

fun setDragTop(newDragTop: Float)
fun moveDragView(newDragTop: Float)

/**
* Return week bottom position
Expand Down Expand Up @@ -80,12 +80,6 @@ interface ViewProvider {

fun getViewTop(): Int

/**
* Change week height
*/

fun setWeekHeight(i: Int, weekHeight: Int)

/**
* Return drag area height
*/
Expand All @@ -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
Expand Down
18 changes: 10 additions & 8 deletions vishnu/src/main/java/com/yalantis/vishnu/view/MonthPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit 01fba8b

Please sign in to comment.