Giter Site home page Giter Site logo

Comments (13)

SundeepK avatar SundeepK commented on May 4, 2024

Are you on the latest version? I have tried to reproduce this, but I'm finding it difficult to do so. Are you using the sample or have you modified any thing?

from compactcalendarview.

carlastabile avatar carlastabile commented on May 4, 2024

@SundeepK I'm using version 1.7.9. I know its hard to reproduce it and it doesn't happen all the time. It is really really weird you need to scroll like 12 months away to start seeing it.

from compactcalendarview.

SundeepK avatar SundeepK commented on May 4, 2024

I have scrolled years and haven't spotted it, you are using the sample project correct?

from compactcalendarview.

carlastabile avatar carlastabile commented on May 4, 2024

@SundeepK this is my code:

 calendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() {
        @Override
        public void onDayClick(Date dateClicked) {
            currentSelectedDate = dateClicked;
            dateSelected.setText(DateUtil.getCalendarShowableDate(dateClicked));
        }

        @Override
        public void onMonthScroll(Date firstDayOfNewMonth) {
            setMonthName(dateFormatForMonth.format(firstDayOfNewMonth)); //here I'm showing month and year in the Toolbar

            Calendar scrolledCalendar = Calendar.getInstance();
            scrolledCalendar.setTime(firstDayOfNewMonth);

            todayCal = Calendar.getInstance(Locale.getDefault());

            //If I scrolled to the current month, set the day to the current day
            if (todayCal.get(Calendar.MONTH) == scrolledCalendar.get(Calendar.MONTH) &&
                    todayCal.get(Calendar.YEAR) == scrolledCalendar.get(Calendar.YEAR)) {
                scrolledCalendar.set(Calendar.DAY_OF_MONTH, CalendarContainer.this.todayCal.get(Calendar.DAY_OF_MONTH));
                calendarView.setCurrentDate(scrolledCalendar.getTime());
            }
            dateSelected.setText(DateUtil.getCalendarShowableDate(scrolledCalendar.getTime()));
            presenter.getEventsByStartDate(scrolledCalendar.getTime());
        }
    });

from compactcalendarview.

SundeepK avatar SundeepK commented on May 4, 2024

I suspect a bug on setting the current date using setCurrentDate() whilst in the callback.

from compactcalendarview.

carlastabile avatar carlastabile commented on May 4, 2024

@SundeepK Do you mean I can't call setcurrentDate inside the onMonthScroll? Sorry, I didn't understand that last comment.

from compactcalendarview.

SundeepK avatar SundeepK commented on May 4, 2024

Well it might be a bug in the library when setting the current day whilst in the callback. Under the hood, it uses java Calendar object, which is not the nicest class you work with and is mutable. Might be some inconsistency while setting the date which could be causing the problem, but I will investigate.

I have copied your code directly and I can see the bug as you describe.

from compactcalendarview.

SundeepK avatar SundeepK commented on May 4, 2024

Ok I think I found the problem, under the hood, the library uses OverScroller to keep track of how far the user has scrolled in x direction. When setting the date, the current date was being initialized correctly with the one passed in but the OverScroller current x direction was not being reset to 0.

This causes a problem since internally it uses OverScroller is used to keep track how many months user has scrolled in +/- and sets the date accordingly.

I think solution is simple as calling scroller.startScroll(0,0,0,0); when setting the date. Also would be a good place to reset any internal values to 0 just to be sure.

from compactcalendarview.

SundeepK avatar SundeepK commented on May 4, 2024

This also leads to anther method to be exposed by the library which is scrollBackToCurrentDate(). This will allow user to easily scroll back to the currently set date in the calendar through scroller.startScroll((int) accumulatedScrollOffset.x,0, (int) - accumulatedScrollOffset.x,0); and will play an animation. But this is totally out of scope of this issue.

from compactcalendarview.

SundeepK avatar SundeepK commented on May 4, 2024

After a bit of playing around, I've taken the pragmatic approach by simply calling scroller.startScroll(0,0,0,0); to fix the bug. However, this doesn't have the nicest effect since it makes the calender reset its X position to 0 with a really quick scrolling animation . Unfortunately, the ``OverScroller` class provided in the Android SDK doesn't allow you to simply set an X value without scroll, which is annoying.

I will have another look at refining this, but I much rather fix the problem than have it perfect.

from compactcalendarview.

SundeepK avatar SundeepK commented on May 4, 2024

Changes are in master, will be released in the next day.

from compactcalendarview.

SundeepK avatar SundeepK commented on May 4, 2024

Re-opening until I actually release a new version so other people can see the issue.

from compactcalendarview.

SundeepK avatar SundeepK commented on May 4, 2024

Available in version:

dependencies {
    compile 'com.github.sundeepk:compact-calendar-view:1.8.0'
}

from compactcalendarview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.