Skip to content

Commit 82771f7

Browse files
committed
fix display current time line & onEmptyViewClicked
1 parent 3ed0eb4 commit 82771f7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

library/src/main/java/com/alamkanak/weekview/WeekView.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ private void drawTimeColumnAndAxes(Canvas canvas) {
537537
// Clip to paint in left column only.
538538
canvas.clipRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), Region.Op.REPLACE);
539539

540-
for (int i = 0; i < 24; i++) {
540+
for (int i = mStartTime; i < mEndTime; i++) {
541541
float top = mHeaderHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * (i-mStartTime) + mHeaderMarginBottom;
542542

543543
// Draw the text if its y position is not outside of the visible area. The pivot point of the text is the point at the bottom-right corner.
@@ -613,7 +613,7 @@ else if (mNewHourHeight > mMaxHourHeight)
613613

614614
// Prepare to iterate for each day.
615615
Calendar day = (Calendar) today.clone();
616-
day.add(Calendar.HOUR, 6);
616+
day.add(Calendar.HOUR_OF_DAY, 6);
617617

618618
// Prepare to iterate for each hour to draw the hour lines.
619619
int lineCount = (int) ((getHeight() - mHeaderHeight - mHeaderRowPadding * 2 -
@@ -687,7 +687,7 @@ else if (day.before(today)) {
687687

688688
// Prepare the separator lines for hours.
689689
int i = 0;
690-
for (int hourNumber = 0; hourNumber < 24; hourNumber++) {
690+
for (int hourNumber = mStartTime; hourNumber < mEndTime; hourNumber++) {
691691
float top = mHeaderHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * (hourNumber-mStartTime) + mTimeTextHeight/2 + mHeaderMarginBottom;
692692
if (top > mHeaderHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom - mHourSeparatorHeight && top < getHeight() && startPixel + mWidthPerDay - start > 0){
693693
hourLines[i * 4] = start;
@@ -714,8 +714,9 @@ else if (day.before(today)) {
714714
if (mShowNowLine && sameDay){
715715
float startY = mHeaderHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom + mCurrentOrigin.y;
716716
Calendar now = Calendar.getInstance();
717-
float beforeNow = (now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE)/60.0f) * mHourHeight;
718-
canvas.drawLine(start, startY + beforeNow, startPixel + mWidthPerDay, startY + beforeNow, mNowLinePaint);
717+
float beforeNow = (now.get(Calendar.HOUR_OF_DAY) - mStartTime + now.get(Calendar.MINUTE)/60.0f) * mHourHeight;
718+
float top = startY + beforeNow;
719+
canvas.drawLine(start, top, startPixel + mWidthPerDay, top, mNowLinePaint);
719720
}
720721

721722
// In the next iteration, start from the next day.
@@ -772,7 +773,7 @@ private Calendar getTimeFromPoint(float x, float y){
772773
- mHeaderRowPadding * 2 - mTimeTextHeight/2 - mHeaderMarginBottom;
773774
int hour = (int)(pixelsFromZero / mHourHeight);
774775
int minute = (int) (60 * (pixelsFromZero - hour * mHourHeight) / mHourHeight);
775-
day.add(Calendar.HOUR, hour);
776+
day.add(Calendar.HOUR_OF_DAY, hour + mStartTime);
776777
day.set(Calendar.MINUTE, minute);
777778
return day;
778779
}
@@ -805,7 +806,7 @@ private void limitEventTime(Calendar date){
805806

806807
if(startTime!=null && endTime !=null && startTime.before(endTime)) {
807808
mStartTime = Math.max(0,startTime.get(Calendar.HOUR_OF_DAY));
808-
mEndTime = Math.min(24,endTime.get(Calendar.HOUR_OF_DAY));
809+
mEndTime = Math.min(24,endTime.get(Calendar.HOUR_OF_DAY)+1);
809810
return;
810811
}
811812
}

0 commit comments

Comments
 (0)