Horizontal-Calendar icon indicating copy to clipboard operation
Horizontal-Calendar copied to clipboard

selectDate() sometimes is off by one day, if immediate is false

Open srseibs opened this issue 6 years ago • 7 comments

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

srseibs avatar Apr 29 '18 00:04 srseibs

Dis you get it's fix ?

shivamyadavappinventiv avatar May 03 '18 20:05 shivamyadavappinventiv

No, it is not fixed.

srseibs avatar May 04 '18 19:05 srseibs

I'm Unable to fix the problem by setting immediate to true or setting date twice programmatically. Any other fixes ?

varunkumarj avatar May 17 '18 06:05 varunkumarj

I am also observing this behavior.

alliejc avatar May 18 '18 18:05 alliejc

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 *

shivamyadavappinventiv avatar May 18 '18 19:05 shivamyadavappinventiv

Any news on this? This lib is awesome, please find a fix! ;-)

yannickgagne avatar May 31 '18 01:05 yannickgagne

@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);

srseibs avatar Jun 03 '18 17:06 srseibs