question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Re: Question about setting weekview event

See original GitHub issue

Hello,

This is with reference to the issue I opened earlier, with the same title. I cannot reopen the issue, because it was not closed by me. Hence opening a new issue:

Question : Is there a way to set the list of events in WeekView other than returning List of WeekViewEvents in onMonthChange() ?

Your solution:

Currently the week view does not provide a ready-made solution for async event loading. But there is a simple hack. Use the following code to achieve what you want.

@Override public List onMonthChange(int newYear, int newMonth) { // Populate the week view with some events. List events = new ArrayList();

// Fetch events for the date user selected.
fetchEventsinBackground();

}

// Callback when fetchEvents finishes. public void setEventList(Activity activity, final List eventModels) {

// Hide the progress dialog.
if(mProgressDialog != null && mProgressDialog.isShowing()) {
    mProgressDialog.dismiss();
}

// Refresh the week view.
activity.runOnUiThread(new Runnable() {
    @Override
    public void run() {
        // Store the returned events in a global variable for later use.
        mEventModels = eventModels;

        // This line will trigger the method 'onMonthChange()' again.
        mWeekView.notifyDatasetChanged();
    }
});

}

@Override public List<WeekViewEvent> onMonthChange(int year, int month) { // TODO Be sure to check if the variables year and month equals the year and month of the events of mEventModels. return getWeekViewEventsFromEventModels(mEventModels); }

Thank you for the response, however it did not work for me.

Java doesn’t support 2 methods with same signature, so I can’t have something like this in the same class:

@Override public List<WeekViewEvent> onMonthChange(int year, int month) { // TODO Be sure to check if the variables year and month equals the year and month of the events of mEventModels. return getWeekViewEventsFromEventModels(mEventModels); } @Override public List onMonthChange(int newYear, int newMonth) { // Populate the week view with some events. List events = new ArrayList();

// Fetch events for the date user selected.
fetchEventsinBackground();

} If mWeekView.notifyDatasetChanged(); triggers onMonthChange() again, then it results in an infinite loop with fetchEventsinBackground() being called again & again!

Is there a better way out ? Thanks for all the help!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:23 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
alamkanakcommented, Jan 13, 2015

Sorry. I should have been more precise about the code. Here, check out the new code.

private List<EventModel> mEventModels = new ArrayList<EventModel>();

@Override
public List onMonthChange(int newYear, int newMonth) {
    // Check if you've already fetched the events for this month on the previous call.
    if (mEventModels.size() == 0 || !containsEvents(mEventModels, newYear, newMonth)) {
        // Fetch events for the date user selected.
        fetchEventsInBackground();
        return new ArrayList<WeekViewEvent>();
    }

    // If we've reached up to this point then it means we've already fetched the data in the previous call.
    return getWeekViewEventsFromEventModels(mEventModels, year, month);
}

// Callback when fetchEvents finishes.
public void setEventList(Activity activity, final List<EventModel> eventModels) {

    // Hide the progress dialog.
    if(mProgressDialog != null && mProgressDialog.isShowing()) {
        mProgressDialog.dismiss();
    }

    // Refresh the week view.
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // Store the returned events in a global variable for later use.
            mEventModels.addAll(eventModels);

            // This line will trigger the method 'onMonthChange()' again.
            mWeekView.notifyDatasetChanged();
        }
    });
}

private boolean containsEvents(List eventModels, year, month) {
    // TODO Do a search in the 'eventModels' list to see if it contains the events of the given 'year' and 'month'. If not then return false.
}


private boolean getWeekViewEventsFromEventModels(List eventModels, year, month) {
    // TODO Filter the events from the eventModels by year and month. It would be good idea if you remove the events that are not in the desired range (i.e. where the month is not month+-1). This will release some memory.
}
1reaction
entropitorcommented, May 9, 2016

@waynem81 You’ll probably have to convert your bean to an instance of WeekViewEvent

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add event in alamkanak week view - Stack Overflow
Please provide if there is anything. This is how Alam-Kanak is adding an event: Calendar startTime = Calendar.getInstance(); startTime.set ...
Read more >
Using Week View - - The Events Calendar
We want to show a weekly session timetable at our venue, for regular opening times etc – that we can edit / update...
Read more >
macos - Suppress event times in week view? - Ask Different
Yes. It is possible from the Preferences > General menu of Calendar to activate the display of event times within the week view...
Read more >
Event calendar Month or week view Example - Mobiscroll
JQuery event calendar for one, two and three weeks. ... Use the type and size properties of the view option to set the...
Read more >
Week View - VueMinder Pro and Ultimate Help
The preferred layout can be selected from the Week View Settings menu, ... Non all-day events and tasks that overlap with each other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found