Quivr / Android-Week-View

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.
Apache License 2.0
257 stars 64 forks source link

Bug with goToHour method when time range is set #104

Open anisias opened 6 years ago

anisias commented 6 years ago

If a time range is set and goToHour(currentTime) method is called the view will not scroll to currentTime hour because of a bug in goToHour method

https://github.com/Quivr/Android-Week-View/blob/2a5f09a6c6ccad3158491acb8c3b05eaf8150b1b/library/src/main/java/com/alamkanak/weekview/WeekView.java#L2677

it should be verticalOffset = (int) (mHourHeight * (hour - mMinTime)); otherwise it works only with the default range of 0-24

NaturallyAsh commented 5 years ago

I am having this problem as well after setting max and min time attr. I tried your change but unfortunately it doesn't help with the problem.

anisias commented 5 years ago

I modified also other parts of this method, do you have problems when current hour > maxTime, when current hour > minTime or in both cases? This is my current method:

public void goToHour(double hour) {
    if (mAreDimensionsInvalid) {
        mScrollToHour = hour;
        return;
    }

   int verticalOffset = 0;
   if (hour > mMinTime && hour < mMaxTime) {
        verticalOffset = (int) (mHourHeight * (hour - mMinTime));
    }
    if (verticalOffset > mHourHeight * (mMaxTime - mMinTime) - getHeight() + mHeaderHeight + mHeaderMarginBottom) {
        verticalOffset = (int) (mHourHeight * (mMaxTime - mMinTime) - getHeight() + mHeaderHeight + mHeaderMarginBottom);
    }
    mCurrentOrigin.y = -verticalOffset;
    invalidate();
    mScroller.forceFinished(true);
}

Hope it helps

NaturallyAsh commented 5 years ago

Yes it works now! Thanx soo much!