private async Task <StorageItemViewModel> ConvertStorageItemViewModel(StorageItemSearchEntry entry)
        {
            var token       = _PathReferenceCountManager.GetToken(entry.Path);
            var storageItem = await _sourceStorageItemsRepository.GetStorageItemFromPath(token, entry.Path);

            var storageItemImageSource = new StorageItemImageSource(storageItem, _thumbnailManager);

            return(new StorageItemViewModel(storageItemImageSource, null, _sourceStorageItemsRepository, _folderListingSettings, _bookmarkManager));
        }
Beispiel #2
0
        public override async Task OnNavigatedToAsync(INavigationParameters parameters)
        {
            _navigationDisposables = new CompositeDisposable();
            if (!_foldersInitialized)
            {
                _foldersInitialized = true;

                Folders.Add(new StorageItemViewModel(_sourceStorageItemsRepository, _folderListingSettings, _bookmarkManager)
                {
                });
                await foreach (var item in _sourceStorageItemsRepository.GetParsistantItems())
                {
                    var storageItemImageSource = new StorageItemImageSource(item.item, _thumbnailManager);
                    if (storageItemImageSource.ItemTypes == Models.Domain.StorageItemTypes.Folder)
                    {
                        Folders.Add(new StorageItemViewModel(storageItemImageSource, item.token, _sourceStorageItemsRepository, _folderListingSettings, _bookmarkManager));
                    }
                    else
                    {
                        //throw new NotSupportedException();
                    }
                }
            }
            else
            {
                Folders.ForEach(x => x.UpdateLastReadPosition());
            }

            async Task <StorageItemViewModel> ToStorageItemViewModel(RecentlyAccessManager.RecentlyAccessEntry entry)
            {
                //_currentFolderItem =
                var token       = _PathReferenceCountManager.GetToken(entry.Path);
                var storageItem = await _sourceStorageItemsRepository.GetStorageItemFromPath(token, entry.Path);

                var storageItemImageSource = new StorageItemImageSource(storageItem, _thumbnailManager);

                return(new StorageItemViewModel(storageItemImageSource, token, _sourceStorageItemsRepository, _folderListingSettings, _bookmarkManager));
            }

            var recentlyAccessItems = _recentlyAccessManager.GetItemsSortWithRecently(10);

            if (_LastUpdatedRecentlyAccessEnties != null)
            {
                var idSet = _LastUpdatedRecentlyAccessEnties.Select(x => x.Path).ToHashSet();
                {
                    var addNewItems = recentlyAccessItems.TakeWhile(x => !idSet.Contains(x.Path)).Reverse();
                    foreach (var newItem in addNewItems)
                    {
                        var alreadyAdded = RecentlyItems.FirstOrDefault(x => x.Path == newItem.Path);
                        if (alreadyAdded != null)
                        {
                            RecentlyItems.Remove(alreadyAdded);
                            RecentlyItems.Insert(0, alreadyAdded);
                        }
                        else
                        {
                            RecentlyItems.Insert(0, await ToStorageItemViewModel(newItem));
                        }
                    }
                }
                {
                    var deletedItems = recentlyAccessItems.OrderByDescending(x => x.LastAccess).TakeWhile(x => !idSet.Contains(x.Path));
                    foreach (var i in Enumerable.Range(0, deletedItems.Count()))
                    {
                        if (RecentlyItems.Count == 0)
                        {
                            break;
                        }
                        if (RecentlyItems.Count <= 10)
                        {
                            break;
                        }

                        RecentlyItems.RemoveAt(RecentlyItems.Count - 1);
                    }
                }
            }
            else
            {
                foreach (var item in recentlyAccessItems)
                {
                    try
                    {
                        RecentlyItems.Add(await ToStorageItemViewModel(item));
                    }
                    catch
                    {
                        _recentlyAccessManager.Delete(item);
                    }
                }
            }

            _LastUpdatedRecentlyAccessEnties = recentlyAccessItems;

            await base.OnNavigatedToAsync(parameters);
        }