//clear the current list of items and load the new items through GetItemsAsync //this is executed when the user refreshes the list async Task ExecuteLoadItemsCommand() { //the code will run only when IsBusy is false if (IsBusy) { return; } //make is busy ture so that the user can't run this twice while it is runnig IsBusy = true; Debug.WriteLine("[ExecuteLoadItemsCommand]Start loading items..."); try { //clear all the items in the list Items.Clear(); ItemGrouped.Clear(); Debug.WriteLine("[ExecuteLoadItemsCommand]Cleared items list"); //update the list only if it is connected to the internet if (CrossConnectivity.Current.IsConnected) { //get new events online, and add them to the database if there is a new one await SyncEvents.UpdateAcaEventsAsync(); } else { Debug.WriteLine("No internet connection"); } var itemsInDb = await App.Database.SortListByDate(); //add all the items to the list foreach (var item in itemsInDb) { //add items to the list Items.Add(item); } //refresh the grouped item list SetupGroup(Items); } catch (Exception ex) { await SyncEvents.SendErrorEmail(ex.Message); } finally { //set the IsBusy to false after the program finishes IsBusy = false; ScrollToEvent = true; Debug.WriteLine("[ExecuteLoadItemsCommand]There are " + Items.Count + " items in the database"); } }
/// <summary> /// Per item callback once grouping is achieved /// </summary> /// <param name="_particle"></param> public void OneItemGroupingCompleted(ItemParticlesAnimation _particle) { if (_particle.itemAnimationData.compt > 0) { SetUnused(_particle); ItemGrouped?.Invoke(_particle); } _particle.itemAnimationData.compt--; if (_particle.itemAnimationData.compt <= 0) { _particle.itemAnimationData.compt = _particle.itemAnimationData.quantity; OnGroupedCompleted?.Invoke(_particle); } }
//setup and group the given list into a grouped list void SetupGroup(ObservableCollection <Item> items) { var allListItemGroups = new ObservableCollection <ItemGroup>(); foreach (var item in items) { //find any existing groups where the group thitle marches the first char of the Item list name var listItemGroup = allListItemGroups.FirstOrDefault(g => g.Heading == item.GroupDate); //if the group does not exist, create one if (listItemGroup == null) { //create a new small list (group) listItemGroup = new ItemGroup(item.GroupDate) { item }; //add the list of items to the group allListItemGroups.Add(listItemGroup); } else { //add the item to the small list listItemGroup.Add(item); } } Debug.WriteLine("[SetupGroup]Finished grouping items"); var finalGroupedList = allListItemGroups.Except(ItemGrouped); foreach (var i in finalGroupedList) { ItemGrouped.Add(i); } Debug.WriteLine("[SetupGroup]Finished adding all the groups to the list"); }