private async Task UpdateItems() { if (IsLoading) { return; } IsLoading = true; var items = await _query.GetItemsAsync(); if (items.SequenceEqual(StorageItems, new GenericComparer <IStorageItem>(item => item.Name))) { IsLoading = false; return; } await DispatcherHelper.ExecuteOnUIThreadAsync(() => { StorageItems.Clear(); foreach (var item in items) { StorageItems.Add(item); } }); IsLoading = false; }
public override async Task GetFiles() { try { await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => { StorageItems.Clear(); IsFolderEmpty = false; IsLoadingFiles = true; }); var currentMedia = BackStack.Last().Media; if (currentMedia == null) { return; } var mediaList = await Locator.MediaLibrary.DiscoverMediaList(currentMedia); for (int i = 0; i < mediaList.count(); i++) { var media = mediaList.itemAtIndex(i); IVLCStorageItem storageItem = null; if (media.type() == MediaType.Directory) { storageItem = new VLCStorageFolder(media); } else if (media.type() == MediaType.File) { storageItem = new VLCStorageFile(media); } if (storageItem == null) { return; } await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => StorageItems.Add(storageItem)); } await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Low, () => { OnPropertyChanged(nameof(StorageItems)); IsFolderEmpty = !StorageItems.Any(); IsLoadingFiles = false; }); } catch (Exception e) { Debug.WriteLine($"Exception when getting network files {e.ToString()}"); } }
public override async Task GetFiles() { try { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { StorageItems.Clear(); IsFolderEmpty = false; IsLoadingFiles = true; }); IReadOnlyList <IStorageItem> items = null; var queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, VLCFileExtensions.Supported); var fileQuery = (BackStack.Last().StorageItem as StorageFolder).CreateItemQueryWithOptions(queryOptions); items = await fileQuery.GetItemsAsync(); var vlcItems = new ObservableCollection <IVLCStorageItem>(); foreach (var storageItem in items) { if (storageItem.IsOfType(StorageItemTypes.File)) { var file = new VLCStorageFile(storageItem as StorageFile); vlcItems.Add(file); } else if (storageItem.IsOfType(StorageItemTypes.Folder)) { var folder = new VLCStorageFolder(storageItem as StorageFolder); vlcItems.Add(folder); } } await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Low, () => { StorageItems = new ObservableCollection <IVLCStorageItem>(vlcItems); OnPropertyChanged(nameof(StorageItems)); IsFolderEmpty = !StorageItems.Any(); IsLoadingFiles = false; }); } catch (Exception exception) { LogHelper.Log("Failed to index folders and files in " + BackStack.Last().Name + "\n" + exception.ToString()); await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Low, () => { IsFolderEmpty = !StorageItems.Any(); IsLoadingFiles = false; }); } }