Skip to content

Commit

Permalink
Merge pull request #49 from aminography/auto_select_end_day
Browse files Browse the repository at this point in the history
Add feature of selecting end day automatically.
  • Loading branch information
aminography authored Feb 25, 2021
2 parents f7ba94f + af01a53 commit 7abb7ef
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ repositories {
}
dependencies {
implementation 'com.aminography:primedatepicker:3.3.2'
implementation 'com.aminography:primedatepicker:3.4.0'
implementation 'com.aminography:primecalendar:1.3.2'
}
```
Expand Down Expand Up @@ -232,11 +232,11 @@ There are several builder functions applying relevant configurations on the date
</tr>

<tr>
<td><b>• initiallyPickedStartDay(startDay: PrimeCalendar, pickEndDay: Boolean)</b></td>
<td><b>• autoSelectPickEndDay(autoSelect: Boolean)</b></td>
<td>RangeDays</td>
</tr>
<tr>
<td colspan="2"><i>Specifies initially picked start day when the date picker has just shown.</i></td>
<td colspan="2"><i>Specifies automatic selection of picking end day when the start day gets picked.</i></td>
</tr>

<tr>
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

buildscript {
def versionMajor = 3 // X
def versionMinor = 3 // Y
def versionPatch = 2 // Z
def versionMinor = 4 // Y
def versionPatch = 0 // Z

ext.version_code = versionMajor * 10000 + versionMinor * 100 + versionPatch
ext.version_name = "${versionMajor}.${versionMinor}.${versionPatch}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ internal class PrimeDatePickerImpl(
private var gotoView: BaseLazyView? = null
private var direction: Direction = Direction.LTR
private var typeface: Typeface? = null
private var autoSelectPickEndDay: Boolean = true
private lateinit var themeFactory: ThemeFactory

internal fun onCreate(context: Context, coroutineScope: CoroutineScope) {
Expand All @@ -94,6 +95,10 @@ internal class PrimeDatePickerImpl(
initialDateCalendar.firstDayOfWeek = it
}

arguments?.getBoolean("autoSelectPickEndDay", true)?.let {
autoSelectPickEndDay = it
}

arguments?.getString("pickType")?.let { internalPickType = PickType.valueOf(it) }
arguments?.getBoolean("initiallyPickEndDay")?.takeIf { it }?.let {
internalPickType = PickType.RANGE_END
Expand Down Expand Up @@ -330,9 +335,14 @@ internal class PrimeDatePickerImpl(
(selectionBarView as SingleDaySelectionBarView).pickedDay = singleDay
}
PickType.RANGE_START, PickType.RANGE_END -> {
(selectionBarView as RangeDaysSelectionBarView).run {
pickedRangeStartDay = startDay
pickedRangeEndDay = endDay
(selectionBarView as RangeDaysSelectionBarView).let {
it.pickedRangeStartDay = startDay
it.pickedRangeEndDay = endDay

if (autoSelectPickEndDay && pickType == PickType.RANGE_START && endDay == null) {
it.animateBackground(false)
it.onRangeEndClickListener?.invoke()
}
}
}
PickType.MULTIPLE -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ class RangeDaysRequestBuilder<T : PrimeDatePicker> internal constructor(
return this
}

/**
* Specifies automatic selection of picking end day when the start day gets picked.
*
* @param autoSelect enables automatic selection if `true`, disables otherwise.
*
* @return current instance of [RangeDaysRequestBuilder].
*/
fun autoSelectPickEndDay(autoSelect: Boolean): RangeDaysRequestBuilder<T> {
bundle.putBoolean("autoSelectPickEndDay", autoSelect)
return this
}

// /**
// * Specifies minimum length of range that can be picked.
// *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal class RangeDaysSelectionBarView(
}
}

private fun animateBackground(isStart: Boolean, duration: Long = 300) {
internal fun animateBackground(isStart: Boolean, duration: Long = 300) {
rootView.backImageView.post {
ObjectAnimator.ofFloat(
rootView.backImageView,
Expand All @@ -122,5 +122,4 @@ internal class RangeDaysSelectionBarView(
}
}
}

}

1 comment on commit 7abb7ef

@AminFeizi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How May I Show Holidays In My Calender For My Clinets ?

Please sign in to comment.