Skip to content

Commit 7abb7ef

Browse files
authored
Merge pull request #49 from aminography/auto_select_end_day
Add feature of selecting end day automatically.
2 parents f7ba94f + af01a53 commit 7abb7ef

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ repositories {
7878
}
7979
8080
dependencies {
81-
implementation 'com.aminography:primedatepicker:3.3.2'
81+
implementation 'com.aminography:primedatepicker:3.4.0'
8282
implementation 'com.aminography:primecalendar:1.3.2'
8383
}
8484
```
@@ -232,11 +232,11 @@ There are several builder functions applying relevant configurations on the date
232232
</tr>
233233

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

242242
<tr>

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
buildscript {
44
def versionMajor = 3 // X
5-
def versionMinor = 3 // Y
6-
def versionPatch = 2 // Z
5+
def versionMinor = 4 // Y
6+
def versionPatch = 0 // Z
77

88
ext.version_code = versionMajor * 10000 + versionMinor * 100 + versionPatch
99
ext.version_name = "${versionMajor}.${versionMinor}.${versionPatch}"

library/src/main/java/com/aminography/primedatepicker/picker/PrimeDatePickerImpl.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ internal class PrimeDatePickerImpl(
7474
private var gotoView: BaseLazyView? = null
7575
private var direction: Direction = Direction.LTR
7676
private var typeface: Typeface? = null
77+
private var autoSelectPickEndDay: Boolean = true
7778
private lateinit var themeFactory: ThemeFactory
7879

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

98+
arguments?.getBoolean("autoSelectPickEndDay", true)?.let {
99+
autoSelectPickEndDay = it
100+
}
101+
97102
arguments?.getString("pickType")?.let { internalPickType = PickType.valueOf(it) }
98103
arguments?.getBoolean("initiallyPickEndDay")?.takeIf { it }?.let {
99104
internalPickType = PickType.RANGE_END
@@ -330,9 +335,14 @@ internal class PrimeDatePickerImpl(
330335
(selectionBarView as SingleDaySelectionBarView).pickedDay = singleDay
331336
}
332337
PickType.RANGE_START, PickType.RANGE_END -> {
333-
(selectionBarView as RangeDaysSelectionBarView).run {
334-
pickedRangeStartDay = startDay
335-
pickedRangeEndDay = endDay
338+
(selectionBarView as RangeDaysSelectionBarView).let {
339+
it.pickedRangeStartDay = startDay
340+
it.pickedRangeEndDay = endDay
341+
342+
if (autoSelectPickEndDay && pickType == PickType.RANGE_START && endDay == null) {
343+
it.animateBackground(false)
344+
it.onRangeEndClickListener?.invoke()
345+
}
336346
}
337347
}
338348
PickType.MULTIPLE -> {

library/src/main/java/com/aminography/primedatepicker/picker/builder/RangeDaysRequestBuilder.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ class RangeDaysRequestBuilder<T : PrimeDatePicker> internal constructor(
4646
return this
4747
}
4848

49+
/**
50+
* Specifies automatic selection of picking end day when the start day gets picked.
51+
*
52+
* @param autoSelect enables automatic selection if `true`, disables otherwise.
53+
*
54+
* @return current instance of [RangeDaysRequestBuilder].
55+
*/
56+
fun autoSelectPickEndDay(autoSelect: Boolean): RangeDaysRequestBuilder<T> {
57+
bundle.putBoolean("autoSelectPickEndDay", autoSelect)
58+
return this
59+
}
60+
4961
// /**
5062
// * Specifies minimum length of range that can be picked.
5163
// *

library/src/main/java/com/aminography/primedatepicker/picker/selection/range/RangeDaysSelectionBarView.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ internal class RangeDaysSelectionBarView(
106106
}
107107
}
108108

109-
private fun animateBackground(isStart: Boolean, duration: Long = 300) {
109+
internal fun animateBackground(isStart: Boolean, duration: Long = 300) {
110110
rootView.backImageView.post {
111111
ObjectAnimator.ofFloat(
112112
rootView.backImageView,
@@ -122,5 +122,4 @@ internal class RangeDaysSelectionBarView(
122122
}
123123
}
124124
}
125-
126125
}

0 commit comments

Comments
 (0)