Exemplo n.º 1
0
        protected override void OrderByChanged()
        {
            string nonGroupFileName   = ResourceLoader.GetForCurrentView().GetString("List/File/Text");
            string nonGroupFolderName = ResourceLoader.GetForCurrentView().GetString("List/Folder/Text");

            var isOrderByName = _Sort == SortType.Name || _Sort == SortType.NameDescending;
            List <StorageItemInfo> folderItems = null;
            List <StorageItemInfo> fileItems   = null;

            switch (_Sort)
            {
            case SortType.Name:
                folderItems = StorageItemGroupSource.Where(x => x.Type == StorageItemTypes.Folder).SelectMany(x => x.Items).OrderBy(x => x.DisplayName).ToList();
                fileItems   = StorageItemGroupSource.Where(x => x.Type == StorageItemTypes.File).SelectMany(x => x.Items).OrderBy(x => x.DisplayName).ToList();
                break;

            case SortType.NameDescending:
                folderItems = StorageItemGroupSource.Where(x => x.Type == StorageItemTypes.Folder).SelectMany(x => x.Items).OrderByDescending(x => x.DisplayName).ToList();
                fileItems   = StorageItemGroupSource.Where(x => x.Type == StorageItemTypes.File).SelectMany(x => x.Items).OrderByDescending(x => x.DisplayName).ToList();
                break;

            case SortType.CreatedDate:
                folderItems = StorageItemGroupSource.Where(x => x.Type == StorageItemTypes.Folder).SelectMany(x => x.Items).OrderBy(x => x.DateCreated).ToList();
                fileItems   = StorageItemGroupSource.Where(x => x.Type == StorageItemTypes.File).SelectMany(x => x.Items).OrderBy(x => x.DateCreated).ToList();
                break;

            case SortType.CreatedDateDescending:
                folderItems = StorageItemGroupSource.Where(x => x.Type == StorageItemTypes.Folder).SelectMany(x => x.Items).OrderByDescending(x => x.DateCreated).ToList();
                fileItems   = StorageItemGroupSource.Where(x => x.Type == StorageItemTypes.File).SelectMany(x => x.Items).OrderByDescending(x => x.DateCreated).ToList();
                break;
            }

            //리스트 전체 초기화
            StorageItemGroupSource.Clear();
            //폴더 재추가
            if (folderItems != null && folderItems.Count > 0)
            {
                StorageItemGroup folderGroup = new StorageItemGroup(StorageItemTypes.Folder, nonGroupFolderName);
                StorageItemGroupSource.Add(folderGroup);

                foreach (var item in folderItems)
                {
                    item.IsOrderByName = isOrderByName;
                    folderGroup.Items.Add(item);
                }
            }
            //파일 재추가
            if (fileItems != null && fileItems.Count > 0)
            {
                StorageItemGroup fileGroup = null;
                var fileStartIndex         = StorageItemGroupSource.Any(x => x.Type == StorageItemTypes.Folder) ? 1 : 0;

                if (isOrderByName && fileItems.Count > GROUP_MAX_ITME_COUNT)
                {
                    foreach (var item in fileItems)
                    {
                        var groupName = _CharacterGroupings.Lookup(item.DisplayName);
                        fileGroup = StorageItemGroupSource.FirstOrDefault(x => x.Name == groupName);

                        if (fileGroup == null)
                        {
                            fileGroup = new StorageItemGroup(StorageItemTypes.File, groupName);
                            StorageItemGroupSource.Add(fileGroup);
                        }

                        item.IsOrderByName = isOrderByName;
                        fileGroup.Items.Add(item);
                    }
                }
                else
                {
                    fileGroup = new StorageItemGroup(StorageItemTypes.File, nonGroupFileName);
                    StorageItemGroupSource.Add(fileGroup);

                    foreach (var item in fileItems)
                    {
                        item.IsOrderByName = isOrderByName;
                        fileGroup.Items.Add(item);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private async Task LoadItemsAsync(IEnumerable <StorageItemInfo> storageItemList, int itemCount, string defaultGroupName, bool isFile, int patchSize)
        {
            var isOrderByName = _Sort == SortType.Name || _Sort == SortType.NameDescending;
            var isMultiGroup  = isFile && isOrderByName && itemCount > GROUP_MAX_ITME_COUNT;
            List <StorageItemInfo> addedList = new List <StorageItemInfo>();
            int offset = 0;

            switch (_Sort)
            {
            case SortType.CreatedDateDescending:
                storageItemList = storageItemList.OrderByDescending(x => x.DateCreated);
                break;

            case SortType.CreatedDate:
                storageItemList = storageItemList.OrderBy(x => x.DateCreated);
                break;

            case SortType.NameDescending:
                storageItemList = storageItemList.OrderByDescending(x => x.DisplayName);
                break;

            default:
                storageItemList = storageItemList.OrderBy(x => x.DisplayName);
                break;
            }

            if (isFile && itemCount > 0 && _CurrentSubtitleFileList == null)
            {
                //자막 검색
                var currentFolder = await CurrentFolderInfo.GetStorageFolderAsync();

                var queryResult = currentFolder.CreateFileQueryWithOptions(_SubtitleFileQueryOptions);
                var list        = await queryResult.GetFilesAsync();

                _CurrentSubtitleFileList = list.Select(x => x.Path.ToUpper()).ToList();
                System.Diagnostics.Debug.WriteLine($"DLNA Server : {currentFolder.Path} 폴더내 자막파일 {_CurrentSubtitleFileList.Count}개 검색 됨...");
            }

            StorageItemGroup group     = null;
            string           groupName = isMultiGroup ? null : defaultGroupName;

            foreach (var storageItem in storageItemList)
            {
                if (isMultiGroup)
                {
                    groupName = _CharacterGroupings.Lookup(storageItem.DisplayName);
                }
                //그룹이 변경되는 경우
                if (group == null || group.Name != groupName)
                {
                    group = new StorageItemGroup(isFile ? StorageItemTypes.File : StorageItemTypes.Folder, groupName);
                    //신규 그룹 생성
                    await DispatcherHelper.RunAsync(() => StorageItemGroupSource.Add(group));
                }

                //일괄 작업을 위해 리스트에 추가
                addedList.Add(storageItem);
                storageItem.Group = group;

                //리스트가 일정수량에 도달하거나, 마지막까지 도달한 경우
                if (++offset % patchSize == 0 || offset >= itemCount)
                {
                    bool isCanceled = false;
                    await DispatcherHelper.RunAsync(() =>
                    {
                        foreach (var added in addedList)
                        {
                            added.Group.Items.Add(added);
                            added.Group = null;
                        }
                        addedList.Clear();
                    });

                    if (isCanceled)
                    {
                        break;
                    }
                }
            }
        }