private async Task <IEnumerable <TItem> > GetDataAsync(string?key = null) { if (DataProvider is null) { return(new TItem[0]); } try { BlockOverlayService.Show(); var request = new DataRequest <TItem> { Skip = 0, ForceUpdate = false, // if load on demand and item key is given then only fetch immediate child items SearchText = LoadOnDemand ? key ?? string.Empty : null }; // perform query data var response = await DataProvider .GetDataAsync(request, CancellationToken.None) .ConfigureAwait(true); // allow calling application to filter/add items etc var items = new List <TItem>(response.Items); await ItemsLoaded.InvokeAsync(items).ConfigureAwait(true); return(items); } finally { BlockOverlayService.Hide(); } }
public async void LoadItems() { ItemsLoading?.Invoke(); await _apiClient.GetCategories().Process( categories => _items = categories, error => Toast.MakeText(_context, error as string, ToastLength.Long).Show() ); NotifyDataSetChanged(); ItemsLoaded?.Invoke(); }
private void AddItems() { Add(new ItemModel { Name = 1, Description = "First" }); Add(new ItemModel { Name = 2, Description = "Second" }); Add(new ItemModel { Name = 3, Description = "Third" }); ItemsLoaded?.Invoke(this, new EventArgs()); }
/// <summary> /// Requests data from the data provider using the current settings. /// </summary> /// <param name="searchText">Optional override for the search text.</param> protected async Task GetDataAsync(string?searchText = null) { try { BlockOverlayService.Show(); //var sortColumn = Columns.SingleOrDefault(c => c.SortColumn); var sortColumn = Columns.Find(x => x.Id == SortCriteria?.Key || x.Title == SortCriteria?.Key); var request = new DataRequest <TItem> { Skip = 0, ForceUpdate = false, SortFieldExpression = sortColumn?.Field, SortDirection = sortColumn?.SortDirection, SearchText = searchText ?? SearchText }; // paging if (PageCriteria != null) { request.Take = (int)PageCriteria.PageSize; request.Skip = (int)PageCriteria.PreviousItems; } // perform query data var response = await DataProvider .GetDataAsync(request, CancellationToken.None) .ConfigureAwait(true); // allow calling application to filter/add items etc var items = new List <TItem>(response.Items); ItemsLoaded?.Invoke(items); // must use an action here and not an EventCallaback as that leads to infinite loop and 100% CPU ItemsToDisplay = items; // update pager state if (PageCriteria != null) { PageCriteria.TotalCount = (uint)(response.TotalCount ?? 0); } // clear selection await ClearSelectionAsync().ConfigureAwait(true); } finally { BlockOverlayService.Hide(); } }
public async void LoadItems(long cityId, int?page = null) { ItemsLoading?.Invoke(); await _apiClient.GetCityPlaces(1, page : page).Process( places => { _images = new string[places.Length]; Parallel.ForEach(places, async(place, _, index) => _images[index] = await ImageStorage.StoreImage("places", place.Id, place.PhotoUrl) ); _items = places; }, error => Toast.MakeText(_context, error as string, ToastLength.Long).Show() ); NotifyDataSetChanged(); ItemsLoaded?.Invoke(); }
/// <summary> /// This should only really be called directly if the control was created with DeferLoading set to true. /// </summary> /// <returns></returns> public async Task LoadItems() { if (_READY) { SearchTimer.Stop(); SearchTimer.Dispose(); ClearSelection(); } if (LockUiFunction != null) { await LockUiFunction(UIStrings.Loading_Items, null, this); } // Pump us into another thread so the UI stays nice and fresh. await Task.Run(async() => { CategoryElements = new ObservableCollection <ItemTreeElement>(); SetElements = new ObservableCollection <ItemTreeElement>(); DependencyRootNodes = new Dictionary <string, ItemTreeElement>(); try { // Gotta build set tree first, so the items from the item list can latch onto the nodes there. BuildSetTree(); await BuildCategoryTree(); } catch (Exception ex) { FlexibleMessageBox.Show("An error occurred while loading the item list.\n" + ex.Message, "Item List Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); return; } var toAdd = new List <(ItemTreeElement parent, ItemTreeElement child)>(); foreach (var kv in DependencyRootNodes) { // This dependency root had no EXD-Items associated with it. // Gotta make a generic item for it. if (kv.Value.Children.Count == 0) { // See if we can actually turn this root into a fully fledged item. try { var root = await XivCache.GetFirstRoot(kv.Key); if (root != null) { // If we can, add it into the list. var item = root.ToRawItem(); var e = new ItemTreeElement(null, kv.Value, item); toAdd.Add((kv.Value, e)); } else { var e = new ItemTreeElement(null, kv.Value, "[Unsupported]"); toAdd.Add((kv.Value, e)); } } catch (Exception ex) { throw; } } } // Loop back through to add the new items, so we're not affecting the previous iteration. foreach (var tup in toAdd) { tup.parent.Children.Add(tup.child); } }); var view = (CollectionView)CollectionViewSource.GetDefaultView(CategoryElements); view.Filter = SearchFilter; view = (CollectionView)CollectionViewSource.GetDefaultView(SetElements); view.Filter = SearchFilter; SearchTimer = new Timer(300); SearchTimer.Elapsed += Search; CategoryTree.ItemsSource = CategoryElements; SetTree.ItemsSource = SetElements; _READY = true; Search(this, null); if (UnlockUiFunction != null) { await UnlockUiFunction(this); } if (ItemsLoaded != null) { ItemsLoaded.Invoke(this, null); } }
protected virtual void OnItemsLoaded(ItemsLoadedEventArgs e) { ItemsLoaded?.Invoke(this, e); }
private void OnItemsLoaded() { ItemsLoaded?.Invoke(this, EventArgs.Empty); }
public void OnItemsLoaded() { Loaded = true; ItemsLoaded?.Invoke(); }