Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix preview in android studio #124

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions library/src/main/java/com/alamkanak/weekview/WeekView.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
}

init();

if (isInEditMode()) {
goToHour(Math.max(Calendar.getInstance().get(Calendar.HOUR_OF_DAY) - 2, 0));
}
}

private void init() {
Expand Down Expand Up @@ -717,7 +721,7 @@ private void drawTimeColumnAndAxes(Canvas canvas) {
canvas.save();
canvas.clipRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight());
canvas.restore();

for (int i = 0; i < getNumberOfPeriods(); i++) {
// If we are showing half hours (eg. 5:30am), space the times out by half the hour height
// and need to provide 30 minutes on each odd period, otherwise, minutes is always 0.
Expand Down Expand Up @@ -868,9 +872,9 @@ else if (mNewHourHeight > mMaxHourHeight)

// Get more events if necessary. We want to store the events 3 months beforehand. Get
// events only when it is the first iteration of the loop.
if (mEventRects == null || mRefreshEvents ||
if (!isInEditMode() && (mEventRects == null || mRefreshEvents ||
(dayNumber == leftDaysWithGaps + 1 && mFetchedPeriod != (int) mWeekViewLoader.toWeekViewPeriodIndex(day) &&
Math.abs(mFetchedPeriod - mWeekViewLoader.toWeekViewPeriodIndex(day)) > 0.5)) {
Math.abs(mFetchedPeriod - mWeekViewLoader.toWeekViewPeriodIndex(day)) > 0.5))) {
getMoreEvents(day);
mRefreshEvents = false;
}
Expand Down Expand Up @@ -937,7 +941,7 @@ else if (mNewHourHeight > mMaxHourHeight)
canvas.clipRect(0, 0, mTimeTextWidth + mHeaderColumnPadding * 2, mHeaderHeight + mHeaderRowPadding * 2);
canvas.drawRect(0, 0, mTimeTextWidth + mHeaderColumnPadding * 2, mHeaderHeight + mHeaderRowPadding * 2, mHeaderBackgroundPaint);
canvas.restore();

// Clip to paint header row only.
canvas.save();
canvas.clipRect(mHeaderColumnWidth, 0, getWidth(), mHeaderHeight + mHeaderRowPadding * 2);
Expand Down Expand Up @@ -1280,9 +1284,9 @@ private void getMoreEvents(Calendar day) {
mFetchedPeriod = -1;
}

if (mWeekViewLoader != null) {
if (mWeekViewLoader != null && !isInEditMode()) {
int periodToFetch = (int) mWeekViewLoader.toWeekViewPeriodIndex(day);
if (!isInEditMode() && (mFetchedPeriod < 0 || mFetchedPeriod != periodToFetch || mRefreshEvents)) {
if (mFetchedPeriod < 0 || mFetchedPeriod != periodToFetch || mRefreshEvents) {
List<? extends WeekViewEvent> newEvents = mWeekViewLoader.onLoad(periodToFetch);

// Clear events.
Expand Down