Skip to content

Commit

Permalink
Implemented max drag and date in drag textView on day selection
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill committed Jan 17, 2019
1 parent 2a4a594 commit ba0f9c7
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,36 @@ class MoveManagerImpl(private val viewProvider: ViewProvider) : MoveManager {
private fun calculateOffsets(touchY: Float) {
val newHeight = (totalHeight * (touchY / totalHeight)) + dragHeight

if (touchY > topLimit) {
when {
touchY > topLimit && touchY < bottomLimit -> {
performMovement(newHeight, touchY)
}
touchY > bottomLimit -> {
performMovement(bottomLimit.toFloat() + dragHeight, bottomLimit.toFloat())
}
touchY <= topLimit -> {
viewProvider.moveWeek(selectedWeek, topLimit.toFloat())
viewProvider.setViewHeight(minHeight + dragHeight)
viewProvider.setDragTop(minHeight.toFloat())
controlAboveSelected(touchY, overScroll = true)
controlBelowSelected(touchY, overScroll = true)
}
}
}

viewProvider.setViewHeight(newHeight.toInt())
viewProvider.setDragTop(touchY)
private fun performMovement(newHeight: Float, touchY: Float) {
viewProvider.setViewHeight(newHeight.toInt())
viewProvider.setDragTop(touchY)

for (week in 0 until weekCount) {
if (week < selectedWeek) {
moveWeek(week, viewProvider.getWeekBottom(week), touchY - weekHeight, defaultPositions[week])
} else {
moveWeek(week, viewProvider.getWeekBottom(week), touchY, defaultPositions[week])
}
for (week in 0 until weekCount) {
if (week < selectedWeek) {
moveWeek(week, viewProvider.getWeekBottom(week), touchY - weekHeight, defaultPositions[week])
} else {
moveWeek(week, viewProvider.getWeekBottom(week), touchY, defaultPositions[week])
}
controlAboveSelected(touchY)
controlBelowSelected(touchY)
} else {
viewProvider.moveWeek(selectedWeek, topLimit.toFloat())
viewProvider.setViewHeight(minHeight + dragHeight)
viewProvider.setDragTop(minHeight.toFloat())
controlAboveSelected(touchY, overScroll = true)
controlBelowSelected(touchY, overScroll = true)
}
controlAboveSelected(touchY)
controlBelowSelected(touchY)
}

/**
Expand Down
58 changes: 44 additions & 14 deletions vishnu/src/main/java/com/yalantis/vishnu/view/MonthPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.yalantis.vishnu.implementation.DateManagerImpl
import com.yalantis.vishnu.implementation.MoveManagerImpl
import com.yalantis.vishnu.interfaces.*
import com.yalantis.vishnu.model.*
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList

Expand Down Expand Up @@ -129,20 +130,20 @@ class MonthPage(context: Context, stylable: VishnuStylable) : LinearLayout(conte
}

private fun obtainStylable(stylable: VishnuStylable) {
dragText = stylable.dragText
dragColor = stylable.dragColor
dragHeight = stylable.dragHeight
dayTypeface = stylable.dayTypeface
dragTextSize = stylable.dragTextSize
dragTextColor = stylable.dragTextColor
monthTypeface = stylable.monthTypeface
weekDayTypeface = stylable.weekDayTypeface
kalendarBackground = stylable.pageBackground
selectedDayDrawable = stylable.selectedDayDrawable
monthSwitchBackground = stylable.monthSwitchBackground
weekDayNamesBackground = stylable.weekDayNamesBackground
selectedWeekBackground = stylable.selectedWeekBackground
unselectedWeekBackground = stylable.unselectedWeekBackground
dragText = stylable.dragText
dragColor = stylable.dragColor
dragHeight = stylable.dragHeight
dayTypeface = stylable.dayTypeface
dragTextSize = stylable.dragTextSize
dragTextColor = stylable.dragTextColor
monthTypeface = stylable.monthTypeface
weekDayTypeface = stylable.weekDayTypeface
kalendarBackground = stylable.pageBackground
selectedDayDrawable = stylable.selectedDayDrawable
monthSwitchBackground = stylable.monthSwitchBackground
weekDayNamesBackground = stylable.weekDayNamesBackground
selectedWeekBackground = stylable.selectedWeekBackground
unselectedWeekBackground = stylable.unselectedWeekBackground

}

Expand Down Expand Up @@ -246,6 +247,7 @@ class MonthPage(context: Context, stylable: VishnuStylable) : LinearLayout(conte
if (moveManager.isInAction.not() && moveManager.isCollapsed.not()) {
changeDayColors(day)
selectWeek(day)
applyDragText(dragTextFor(day))
} else {
actionQueue.add(KAction(ACTION_SELECT_DAY))
moveManager.expand()
Expand All @@ -254,6 +256,33 @@ class MonthPage(context: Context, stylable: VishnuStylable) : LinearLayout(conte
}
}

private fun applyDragText(dragText: String) {
(getChildAt(childCount - 1) as TextView).text = dragText
}

private fun dragTextFor(day: Day): String {
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_YEAR, -1)
val yesterday = formatDate(calendar.time)
calendar.add(Calendar.DAY_OF_YEAR, 1)
val today = formatDate(calendar.time)
calendar.add(Calendar.DAY_OF_YEAR, 1)
val tomorrow = formatDate(calendar.time)

calendar.time = day.date

val selectedDay = formatDate(calendar.time)

return when (selectedDay) {
today -> resources.getString(R.string.today)
yesterday -> resources.getString(R.string.yesterday)
tomorrow -> resources.getString(R.string.tomorrow)
else -> selectedDay
}
}

private fun formatDate(date: Date) = SimpleDateFormat("dd MMM yyyy", Locale.getDefault()).format(date)

/**
* Method creates day view which will be later displayed
*/
Expand Down Expand Up @@ -431,6 +460,7 @@ class MonthPage(context: Context, stylable: VishnuStylable) : LinearLayout(conte
val weekHeight = getWeekHeight()
collapsedHeight = switchHeight + weekHeight * 2 + dragHeight
totalHeight = switchHeight + (weekHeight * (childCount - 2)) + dragHeight

var weekBottom = switchHeight + weekHeight
for (i in 0 until childCount - 1) {
weekBottom += weekHeight
Expand Down
8 changes: 8 additions & 0 deletions vishnu/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="yesterday">Yesterday</string>
<string name="today">Today</string>
<string name="tomorrow">Tomorrow</string>

</resources>

0 comments on commit ba0f9c7

Please sign in to comment.