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;
        }
示例#2
0
        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()}");
            }
        }