Horizontal-Calendar
Horizontal-Calendar copied to clipboard
selectDate() sometimes is off by one day, if immediate is false
Expected Behavior / Goal
Calling: selectDate(Calendar.getInstance(), false)
should scroll to today's date using normal scrolling speeds.
Actual Behavior
The calendar scrolls quickly and slows down as it approaches today, overshoots by one, and most of the time it will come back to the correct day. But about 1 out of 5 times it stays on one day after today.
Repeating the selectDate() command works fine.
Also setting 'immediate' to 'true' works fine.
Steps to Reproduce the Problem (sample code if possible)
In Activity:
Calendar startDate = Calendar.getInstance();
startDate.add(Calendar.MONTH, -1);
Calendar endDate = Calendar.getInstance();
endDate.add(Calendar.MONTH, 1);
mCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
.range(startDate, endDate)
.datesNumberOnScreen(5)
.addEvents(new CalendarEventsPredicate() {
Random rnd = new Random();
@Override
public List<CalendarEvent> events(Calendar date) {
List<CalendarEvent> events = new ArrayList<>();
int count = rnd.nextInt(4);
for (int i = 0; i <= count; i++){
events.add(new CalendarEvent(getResources().getColor(R.color.md_green_600)));
}
return events;
}
})
.build();
mCalendar.setCalendarListener(new HorizontalCalendarListener() {
@Override
public void onDateSelected(Calendar date, int position) {
}
});
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.mn_cal_today:
mCalendar.selectDate(Calendar.getInstance(), true);
return true;
}
return false;
}
layout:
<devs.mulham.horizontalcalendar.HorizontalCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryLight"
app:textColorNormal="@color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/include"
/>
Specifications
- Android Version: 7.0 on Samsung S7 Edge
- Horizontal-Calendar Version: 1.3.4
Dis you get it's fix ?
No, it is not fixed.
I'm Unable to fix the problem by setting immediate to true or setting date twice programmatically. Any other fixes ?
I am also observing this behavior.
This issue can be resolved by setting the start time as one month prior to current date and end time one month after after current.
Thanks
On Sat, May 19, 2018 at 12:21 AM Alison Caldwell [email protected] wrote:
I am also observing this behavior.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Mulham-Raee/Horizontal-Calendar/issues/83#issuecomment-390299659, or mute the thread https://github.com/notifications/unsubscribe-auth/AjMH2F83R1xMdl4lMz_9ggCaWKN2GFaYks5tzxhCgaJpZM4TrnQS .
-- *Shivam Yadav *
- Android Developer *
Any news on this? This lib is awesome, please find a fix! ;-)
@shivamyadavappinventiv suggests:
This issue can be resolved by setting the start time as one month prior to current date and end time one month after after current.
I don't believe that worked for me. You can see in the original problem statement that I did set the start and end dates like that
Steps to Reproduce the Problem (sample code if possible)
In Activity:
Calendar startDate = Calendar.getInstance();
startDate.add(Calendar.MONTH, -1);
Calendar endDate = Calendar.getInstance();
endDate.add(Calendar.MONTH, 1);