Skip to content

Commit 56f810b

Browse files
committed
Added support for calling first & last visible day
1 parent 1ed908b commit 56f810b

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ Android Week View
55

66
![](images/screen-shot.png)
77

8-
> Please note that this project is still under development. I will be happy if you collaborate in this project and help it become even more polished.
9-
108
Features
119
------------
1210

@@ -21,6 +19,7 @@ Who uses it
2119
---------------
2220

2321
* [Series Addict](https://play.google.com/store/apps/details?id=com.alamkanak.seriesaddict)
22+
* Using the library? Just [tweet me](https://twitter.com/alamkanak) or [send me an email](mailto:[email protected]).
2423

2524
Usage
2625
---------
@@ -32,14 +31,14 @@ Usage
3231
<dependency>
3332
<groupId>com.github.alamkanak</groupId>
3433
<artifactId>android-week-view</artifactId>
35-
<version>1.1.4</version>
34+
<version>1.1.5</version>
3635
<type>aar</type>
3736
</dependency>
3837
```
3938
* Grab via gradle
4039

4140
```groovy
42-
compile 'com.github.alamkanak:android-week-view:1.1.4'
41+
compile 'com.github.alamkanak:android-week-view:1.1.5'
4342
```
4443
2. Add WeekView in your xml layout.
4544

@@ -133,6 +132,11 @@ To do
133132
Changelog
134133
---------
135134

135+
**Version 1.1.5**
136+
137+
* A bug related to overlapping events fixed
138+
* You can now programmatically get first and last visible day in the week view
139+
136140
**Version 1.1.4**
137141

138142
* Small bug fixed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION_NAME=1.1.4
1+
VERSION_NAME=1.1.5
22
GROUP=com.github.alamkanak
33

44
POM_DESCRIPTION=Dissect layout traversals on Android.

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public class WeekView extends View {
9494
private int mDayNameLength = LENGTH_LONG;
9595
private int mOverlappingEventGap = 0;
9696
private int mEventMarginVertical = 0;
97+
private Calendar mFirstVisibleDay;
98+
private Calendar mLastVisibleDay;
9799

98100
// Listeners.
99101
private EventClickListener mEventClickListener;
@@ -357,7 +359,7 @@ private void drawHeaderRowAndEvents(Canvas canvas) {
357359
// Consider scroll offset.
358360
if (mCurrentScrollDirection == Direction.HORIZONTAL) mCurrentOrigin.x -= mDistanceX;
359361
int leftDaysWithGaps = (int) -(Math.ceil(mCurrentOrigin.x / (mWidthPerDay + mColumnGap)));
360-
float startFromPixel = mCurrentOrigin.x + (mWidthPerDay+mColumnGap) * leftDaysWithGaps +
362+
float startFromPixel = mCurrentOrigin.x + (mWidthPerDay + mColumnGap) * leftDaysWithGaps +
361363
mHeaderColumnWidth;
362364
float startPixel = startFromPixel;
363365

@@ -379,13 +381,17 @@ private void drawHeaderRowAndEvents(Canvas canvas) {
379381
}
380382

381383
// Iterate through each day.
384+
mFirstVisibleDay = (Calendar) mToday.clone();
385+
mFirstVisibleDay.add(Calendar.DATE, leftDaysWithGaps);
382386
for (int dayNumber = leftDaysWithGaps + 1;
383387
dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1;
384388
dayNumber++) {
385389

386390
// Check if the day is today.
387391
day = (Calendar) mToday.clone();
392+
mLastVisibleDay = (Calendar) day.clone();
388393
day.add(Calendar.DATE, dayNumber - 1);
394+
mLastVisibleDay.add(Calendar.DATE, dayNumber - 2);
389395
boolean sameDay = isSameDay(day, mToday);
390396

391397
// Get more events if necessary. We want to store the events 3 months beforehand. Get
@@ -749,7 +755,7 @@ private boolean isEventsCollide(WeekViewEvent event1, WeekViewEvent event2) {
749755
long end1 = event1.getEndTime().getTimeInMillis();
750756
long start2 = event2.getStartTime().getTimeInMillis();
751757
long end2 = event2.getEndTime().getTimeInMillis();
752-
return (start1 >= start2 && start1 <= end2) || (end1 >= start2 && end1 <= end2);
758+
return !((start1 >= end2) || (end1 <= start2));
753759
}
754760

755761

@@ -1066,6 +1072,22 @@ public void setEventMarginVertical(int eventMarginVertical) {
10661072
invalidate();
10671073
}
10681074

1075+
/**
1076+
* Returns the first visible day in the week view.
1077+
* @return The first visible day in the week view.
1078+
*/
1079+
public Calendar getFirstVisibleDay() {
1080+
return mFirstVisibleDay;
1081+
}
1082+
1083+
/**
1084+
* Returns the last visible day in the week view.
1085+
* @return The last visible day in the week view.
1086+
*/
1087+
public Calendar getLastVisibleDay() {
1088+
return mLastVisibleDay;
1089+
}
1090+
10691091
/////////////////////////////////////////////////////////////////
10701092
//
10711093
// Functions related to scrolling.

0 commit comments

Comments
 (0)