Пример #1
0
        public SearchResultKeywordPageViewModel(
            HohoemaApp hohoemaApp,
            PageManager pageManager,
            MylistRegistrationDialogService mylistDialogService
            )
            : base(hohoemaApp, pageManager, mylistDialogService, useDefaultPageTitle: false)
        {
            _ContentFinder = HohoemaApp.ContentFinder;

            FailLoading = new ReactiveProperty <bool>(false)
                          .AddTo(_CompositeDisposable);

            LoadedPage = new ReactiveProperty <int>(1)
                         .AddTo(_CompositeDisposable);
        }
Пример #2
0
        public HohoemaVideoListingPageViewModelBase(HohoemaApp app, PageManager pageManager, MylistRegistrationDialogService mylistDialogService, bool isRequireSignIn = true, bool useDefaultPageTitle = true)
            : base(app, pageManager, useDefaultPageTitle: useDefaultPageTitle)
        {
            MylistDialogService = mylistDialogService;


            var SelectionItemsChanged = SelectedItems.ToCollectionChanged().ToUnit();

#if DEBUG
            SelectedItems.CollectionChangedAsObservable()
            .Subscribe(x =>
            {
                Debug.WriteLine("Selected Count: " + SelectedItems.Count);
            });
#endif


            PlayAllCommand = SelectionItemsChanged
                             .Select(_ => SelectedItems.Count > 0)
                             .ToReactiveCommand(false)
                             .AddTo(_CompositeDisposable);

            PlayAllCommand
            .SubscribeOnUIDispatcher()
            .Subscribe(_ =>
            {
                // TODO: プレイリストに登録
                // プレイリストを空にしてから選択動画を登録

                //				SelectedVideoInfoItems.First()?.PlayCommand.Execute();
            })
            .AddTo(_CompositeDisposable);

            CancelCacheDownloadRequest = SelectionItemsChanged
                                         .Select(_ => SelectedItems.Count > 0)
                                         .ToReactiveCommand(false)
                                         .AddTo(_CompositeDisposable);

            CancelCacheDownloadRequest
            .SubscribeOnUIDispatcher()
            .Subscribe(async _ =>
            {
                var items  = EnumerateCacheRequestedVideoItems().ToList();
                var action = AsyncInfo.Run <uint>(async(cancelToken, progress) =>
                {
                    uint count = 0;
                    foreach (var item in items)
                    {
                        await item.NicoVideo.CancelCacheRequest();

                        ++count;
                        progress.Report(count);
                    }

                    ClearSelection();
                });

                await PageManager.StartNoUIWork("キャッシュリクエストをキャンセル中", items.Count, () => action);
            }
                       )
            .AddTo(_CompositeDisposable);


            // クオリティ指定無しのキャッシュDLリクエスト
            RequestCacheDownload = SelectionItemsChanged
                                   .Select(_ => SelectedItems.Count > 0 && CanDownload)
                                   .ToReactiveCommand(false)
                                   .AddTo(_CompositeDisposable);

            RequestCacheDownload
            .SubscribeOnUIDispatcher()
            .Subscribe(async _ =>
            {
                foreach (var item in EnumerateCanDownloadVideoItem())
                {
                    await item.NicoVideo.RequestCache(HohoemaApp.UserSettings.PlayerSettings.DefaultQuality);
                }

                ClearSelection();
                await UpdateList();
            })
            .AddTo(_CompositeDisposable);



            RegistratioMylistCommand = SelectionItemsChanged
                                       .Select(x => SelectedItems.Count > 0)
                                       .ToReactiveCommand(false)
                                       .AddTo(_CompositeDisposable);
            RegistratioMylistCommand
            .SubscribeOnUIDispatcher()
            .Subscribe(async _ =>
            {
                var mylists             = HohoemaApp.UserMylistManager.UserMylists;
                var localMylists        = HohoemaApp.Playlist.Playlists;
                var selectDialogService = App.Current.Container.Resolve <ContentSelectDialogService>();
                var result = await selectDialogService.ShowDialog(
                    "追加先マイリストを選択",
                    new List <ISelectableContainer>()
                {
                    new ChoiceFromListSelectableContainer("マイリスト",
                                                          mylists.Select(x => new SelectDialogPayload()
                    {
                        Label = x.Name, Id = x.Id, Context = x
                    })
                                                          ),
                    new ChoiceFromListSelectableContainer("ローカルマイリスト",
                                                          localMylists.Select(x => new SelectDialogPayload()
                    {
                        Label = x.Name, Id = x.Id, Context = x
                    })
                                                          )
                }
                    );

                if (result == null)
                {
                    return;
                }

                var targetMylist = result.Context as IPlayableList;

                var items  = SelectedItems.ToList();
                var action = AsyncInfo.Run <uint>(async(cancelToken, progress) =>
                {
                    uint progressCount = 0;


                    Debug.WriteLine($"一括マイリストに追加を開始...");
                    int successCount = 0;
                    int existCount   = 0;
                    int failedCount  = 0;
                    foreach (var video in SelectedItems)
                    {
                        if (targetMylist.Origin == PlaylistOrigin.LoginUser)
                        {
                            var mylistGroup        = targetMylist as MylistGroupInfo;
                            var registrationResult = await mylistGroup.Registration(
                                video.RawVideoId
                                , ""
                                , withRefresh: false /* あとで一括でリフレッシュ */
                                );

                            switch (registrationResult)
                            {
                            case Mntone.Nico2.ContentManageResult.Success: successCount++; break;

                            case Mntone.Nico2.ContentManageResult.Exist: existCount++; break;

                            case Mntone.Nico2.ContentManageResult.Failed: failedCount++; break;

                            default:
                                break;
                            }

                            Debug.WriteLine($"{video.Title}[{video.RawVideoId}]:{registrationResult.ToString()}");
                        }
                        else if (targetMylist.Origin == PlaylistOrigin.Local)
                        {
                            var localMylist = targetMylist as LocalMylist;
                            if (localMylist.PlaylistItems.FirstOrDefault(x => x.ContentId == video.RawVideoId) != null)
                            {
                                existCount++;
                            }
                            else
                            {
                                var resultItem = localMylist.AddVideo(video.RawVideoId, video.Title);
                                if (resultItem != null)
                                {
                                    successCount++;
                                }
                                else
                                {
                                    failedCount++;
                                }
                            }
                        }

                        progressCount++;
                        progress.Report(progressCount);
                    }


                    if (targetMylist.Origin == PlaylistOrigin.LoginUser)
                    {
                        var mylistGroup = targetMylist as MylistGroupInfo;
                        await mylistGroup.Refresh();

                        // マイリストに追加に失敗したものを残すように
                        // 登録済みのアイテムを選択アイテムリストから削除
                        foreach (var item in SelectedItems.ToArray())
                        {
                            if (mylistGroup.CheckRegistratedVideoId(item.RawVideoId))
                            {
                                SelectedItems.Remove(item);
                            }
                        }
                    }

                    // リフレッシュ



                    // ユーザーに結果を通知

                    var titleText    = $"「{targetMylist.Name}」に {successCount}件 の動画を登録しました";
                    var toastService = App.Current.Container.Resolve <ToastNotificationService>();
                    var resultText   = $"";
                    if (existCount > 0)
                    {
                        resultText += $"重複:{existCount} 件";
                    }
                    if (failedCount > 0)
                    {
                        resultText += $"\n登録に失敗した {failedCount}件 は選択されたままです";
                    }

                    toastService.ShowText(titleText, resultText);

                    //					ResetList();

                    Debug.WriteLine($"一括マイリストに追加を完了---------------");
                    ClearSelection();
                });

                await PageManager.StartNoUIWork("マイリストに追加", items.Count, () => action);
            }
                       );


            Playlists = HohoemaApp.Playlist.Playlists.ToReadOnlyReactiveCollection();
        }
Пример #3
0
        public SearchResultTagPageViewModel(
            HohoemaApp hohoemaApp,
            PageManager pageManager,
            MylistRegistrationDialogService mylistDialogService,
            ContentSelectDialogService contentSelectDialogService
            )
            : base(hohoemaApp, pageManager, mylistDialogService, useDefaultPageTitle: false)
        {
            _ContentFinder = HohoemaApp.ContentFinder;
            _ContentSelectDialogService = contentSelectDialogService;

            FailLoading = new ReactiveProperty <bool>(false)
                          .AddTo(_CompositeDisposable);

            LoadedPage = new ReactiveProperty <int>(1)
                         .AddTo(_CompositeDisposable);


            IsFavoriteTag = new ReactiveProperty <bool>(mode: ReactivePropertyMode.DistinctUntilChanged)
                            .AddTo(_CompositeDisposable);
            CanChangeFavoriteTagState = new ReactiveProperty <bool>()
                                        .AddTo(_CompositeDisposable);

            AddFavoriteTagCommand = CanChangeFavoriteTagState
                                    .ToReactiveCommand()
                                    .AddTo(_CompositeDisposable);

            RemoveFavoriteTagCommand = IsFavoriteTag
                                       .ToReactiveCommand()
                                       .AddTo(_CompositeDisposable);


            IsFavoriteTag.Subscribe(async x =>
            {
                if (_NowProcessFavorite)
                {
                    return;
                }

                _NowProcessFavorite = true;

                CanChangeFavoriteTagState.Value = false;
                if (x)
                {
                    if (await FavoriteTag())
                    {
                        Debug.WriteLine(SearchOption.Keyword + "のタグをお気に入り登録しました.");
                    }
                    else
                    {
                        // お気に入り登録に失敗した場合は状態を差し戻し
                        Debug.WriteLine(SearchOption.Keyword + "のタグをお気に入り登録に失敗");
                        IsFavoriteTag.Value = false;
                    }
                }
                else
                {
                    if (await UnfavoriteTag())
                    {
                        Debug.WriteLine(SearchOption.Keyword + "のタグをお気に入り解除しました.");
                    }
                    else
                    {
                        // お気に入り解除に失敗した場合は状態を差し戻し
                        Debug.WriteLine(SearchOption.Keyword + "のタグをお気に入り解除に失敗");
                        IsFavoriteTag.Value = true;
                    }
                }

                CanChangeFavoriteTagState.Value = IsFavoriteTag.Value == true || HohoemaApp.FollowManager.CanMoreAddFollow(FollowItemType.Tag);


                _NowProcessFavorite = false;
            })
            .AddTo(_CompositeDisposable);
        }