lilcodelab / Xamarin.Plugin.Calendar

Calendar plugin for Xamarin.Forms
MIT License
260 stars 60 forks source link

EventIndicator Refresh #129

Closed LukasBrits closed 2 years ago

LukasBrits commented 2 years ago

Hi, I'd just like to say that it has been great exploring this project and I that appreciate the work you've done.

I am using the calendar as an event-scheduler. The user adds events that are stored in a database. The ViewModel makes an API call to get a list of events based on a number of conditions. Event indicators are working and events are showing correctly in the events section. The only issue that I am having is having an event show when a user has added a new one. The only way that I can get it to show is by exiting and re-entering the page. I saw in some of the other issues that Events.Add() refreshes the UI. This does not seem to cause the indicators to refresh for me (tried with the indexer as well). The latest attempt I made was by calling my PopolateEvents method from the code-behind's OnAppearing function. The PopulateEvents function does execute and when debugging I can see that the Events collection is updated with the newly added event, but it still does not refresh in the UI.

Please advise if I am missing some functionality or if I have implemented something incorrectly? (I am still new to using Xamarin Forms).

Looking forward to hearing from you.

DateTime currDate = DateTime.MinValue;
List<EventModel> eventsList = new List<EventModel>();
Events = new EventCollection();
var companyEvents = (await _eventsClient.GetEventsByCompanyAsync(CompanyID)).ToList();
if (companyEvents.Count != 0)
{
  foreach (var item in companyEvents)
  {
    eventsList.Add(new EventModel { EventID = item.EventID, EventTitle = item.Title, Description = item.Description, StartDate = item.StartDate });
    if (currDate != item.StartDate.Date)
    {
        currDate = item.StartDate.Date;
        Events[currDate] = new List<EventModel>(GenerateEvents(eventsList));
        eventsList.Clear();
    }
  }
}
private IEnumerable<EventModel> GenerateEvents(List<EventModel> list)
{
  return Enumerable.Range(0, list.Count).Select(x => new EventModel
  {
    EventID = list[x].EventID,
    EventTitle = list[x].EventTitle,
    Description = list[x].Description,
    StartDate = list[x].StartDate
  });
}
LukasBrits commented 2 years ago

Found the issue: I wasn't using the SetProperty() function properly.