Esempio n. 1
0
        public UserMylistPageViewModel(
            ApplicationLayoutManager applicationLayoutManager,
            Services.PageManager pageManager,
            Services.DialogService dialogService,
            NiconicoSession niconicoSession,
            UserProvider userProvider,
            MylistRepository mylistRepository,
            UserMylistManager userMylistManager,
            LocalMylistManager localMylistManager,
            HohoemaPlaylist hohoemaPlaylist,
            CreateLocalMylistCommand createLocalMylistCommand
            )
        {
            ApplicationLayoutManager = applicationLayoutManager;
            PageManager              = pageManager;
            DialogService            = dialogService;
            NiconicoSession          = niconicoSession;
            UserProvider             = userProvider;
            _mylistRepository        = mylistRepository;
            _userMylistManager       = userMylistManager;
            _localMylistManager      = localMylistManager;
            CreateLocalMylistCommand = createLocalMylistCommand;
            HohoemaPlaylist          = hohoemaPlaylist;
            IsLoginUserMylist        = new ReactiveProperty <bool>(false);

            OpenMylistCommand = new ReactiveCommand <IPlaylist>();

            OpenMylistCommand.Subscribe(listItem =>
            {
                PageManager.OpenPage(HohoemaPageType.Mylist, $"id={listItem.Id}");
            });

            AddMylistGroupCommand = new DelegateCommand(async() =>
            {
                MylistGroupEditData data = new MylistGroupEditData()
                {
                    Name              = "",
                    Description       = "",
                    IsPublic          = false,
                    MylistDefaultSort = MylistDefaultSort.Latest,
                    IconType          = IconType.Default,
                };

                // 成功するかキャンセルが押されるまで繰り返す
                while (true)
                {
                    if (true == await DialogService.ShowCreateMylistGroupDialogAsync(data))
                    {
                        var result = await _userMylistManager.AddMylist(
                            data.Name,
                            data.Description,
                            data.IsPublic,
                            data.MylistDefaultSort,
                            data.IconType
                            );

                        if (result == Mntone.Nico2.ContentManageResult.Success)
                        {
                            await ResetList();
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
                                                        , () => _userMylistManager.Mylists.Count < _userMylistManager.MaxMylistGroupCountCurrentUser
                                                        );

            RemoveMylistGroupCommand = new DelegateCommand <Interfaces.IPlaylist>(async(item) =>
            {
                {
                    if (item is LocalPlaylist localPlaylist)
                    {
                        if (localPlaylist.IsWatchAfterPlaylist())
                        {
                            return;
                        }
                    }
                    else if (item is LoginUserMylistPlaylist loginUserMylist)
                    {
                        if (loginUserMylist.IsDefaultMylist())
                        {
                            return;
                        }
                    }
                }

                // 確認ダイアログ
                var contentMessage = "ConfirmDeleteX_ImpossibleReDo".Translate(item.Label);

                var dialog = new MessageDialog(contentMessage, "ConfirmDeleteX".Translate(item.GetOrigin().Translate()));
                dialog.Commands.Add(new UICommand("Delete".Translate(), async(i) =>
                {
                    if (item is LocalPlaylist localPlaylist)
                    {
                        _localMylistManager.RemovePlaylist(localPlaylist);
                    }
                    else if (item is LoginUserMylistPlaylist loginUserMylist)
                    {
                        await _userMylistManager.RemoveMylist(item.Id);
                    }
                }));

                dialog.Commands.Add(new UICommand("Cancel".Translate()));
                dialog.CancelCommandIndex  = 1;
                dialog.DefaultCommandIndex = 1;

                await dialog.ShowAsync();
            });


            EditMylistGroupCommand = new DelegateCommand <Interfaces.IPlaylist>(async item =>
            {
                if (item is LocalPlaylist localPlaylist)
                {
                    if (item.Id == HohoemaPlaylist.WatchAfterPlaylistId)
                    {
                        return;
                    }

                    var resultText = await DialogService.GetTextAsync("RenameLocalPlaylist".Translate(),
                                                                      localPlaylist.Label,
                                                                      localPlaylist.Label,
                                                                      (tempName) => !string.IsNullOrWhiteSpace(tempName)
                                                                      );

                    if (!string.IsNullOrWhiteSpace(resultText))
                    {
                        localPlaylist.Label = resultText;
                    }
                }
                else if (item is LoginUserMylistPlaylist loginUserMylist)
                {
                    if (loginUserMylist.IsDefaultMylist())
                    {
                        return;
                    }

                    MylistGroupEditData data = new MylistGroupEditData()
                    {
                        Name              = loginUserMylist.Label,
                        Description       = loginUserMylist.Description,
                        IsPublic          = loginUserMylist.IsPublic,
                        MylistDefaultSort = loginUserMylist.DefaultSort,
                        IconType          = loginUserMylist.IconType,
                    };

                    // 成功するかキャンセルが押されるまで繰り返す
                    while (true)
                    {
                        if (true == await DialogService.ShowCreateMylistGroupDialogAsync(data))
                        {
                            var result = await loginUserMylist.UpdateMylist(data);

                            if (result == Mntone.Nico2.ContentManageResult.Success)
                            {
                                loginUserMylist.Label       = data.Name;
                                loginUserMylist.Description = data.Description;
                                loginUserMylist.IsPublic    = data.IsPublic;
                                loginUserMylist.DefaultSort = data.MylistDefaultSort;
                                loginUserMylist.IconType    = data.IconType;

                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            });
        }
Esempio n. 2
0
        public UserMylistPageViewModel(
            Services.PageManager pageMaanger,
            Services.DialogService dialogService,
            NiconicoSession niconicoSession,
            UserProvider userProvider,
            LoginUserMylistProvider loginUserMylistProvider,
            OtherOwneredMylistManager otherOwneredMylistManager,
            UserMylistManager userMylistManager,
            LocalMylistManager localMylistManager,
            HohoemaPlaylist hohoemaPlaylist
            )
            : base(pageMaanger, useDefaultPageTitle: false)
        {
            DialogService             = dialogService;
            NiconicoSession           = niconicoSession;
            UserProvider              = userProvider;
            LoginUserMylistProvider   = loginUserMylistProvider;
            OtherOwneredMylistManager = otherOwneredMylistManager;
            UserMylistManager         = userMylistManager;
            LocalMylistManager        = localMylistManager;
            HohoemaPlaylist           = hohoemaPlaylist;
            IsLoginUserMylist         = new ReactiveProperty <bool>(false);

            OpenMylistCommand = new ReactiveCommand <Interfaces.IMylist>();

            OpenMylistCommand.Subscribe(listItem =>
            {
                PageManager.OpenPage(HohoemaPageType.Mylist,
                                     new MylistPagePayload()
                {
                    Id = listItem.Id, Origin = listItem.ToMylistOrigin()
                }
                                     .ToParameterString()
                                     );
            });

            AddMylistGroupCommand = new DelegateCommand(async() =>
            {
                MylistGroupEditData data = new MylistGroupEditData()
                {
                    Name              = "新しいマイリスト",
                    Description       = "",
                    IsPublic          = false,
                    MylistDefaultSort = MylistDefaultSort.Latest,
                    IconType          = IconType.Default,
                };

                // 成功するかキャンセルが押されるまで繰り返す
                while (true)
                {
                    if (true == await DialogService.ShowCreateMylistGroupDialogAsync(data))
                    {
                        var result = await UserMylistManager.AddMylist(
                            data.Name,
                            data.Description,
                            data.IsPublic,
                            data.MylistDefaultSort,
                            data.IconType
                            );

                        if (result == Mntone.Nico2.ContentManageResult.Success)
                        {
                            await ResetList();
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
                                                        , () => UserMylistManager.Mylists.Count < UserMylistManager.MaxMylistGroupCountCurrentUser
                                                        );

            RemoveMylistGroupCommand = new DelegateCommand <Interfaces.IMylist>(async(item) =>
            {
                var mylistOrigin = item.ToMylistOrigin();
                if (mylistOrigin == PlaylistOrigin.Local)
                {
                    if (item.Id == HohoemaPlaylist.WatchAfterPlaylistId)
                    {
                        return;
                    }
                }
                else if (mylistOrigin == PlaylistOrigin.LoginUser)
                {
                    if (item.Id == "0")
                    {
                        return;
                    }
                }

                // 確認ダイアログ
                var originText     = mylistOrigin == PlaylistOrigin.Local ? "ローカルマイリスト" : "マイリスト";
                var contentMessage = $"{item.Label} を削除してもよろしいですか?(変更は元に戻せません)";

                var dialog = new MessageDialog(contentMessage, $"{originText}削除の確認");
                dialog.Commands.Add(new UICommand("削除", async(i) =>
                {
                    if (mylistOrigin == PlaylistOrigin.Local)
                    {
                        LocalMylistManager.RemoveCommand.Execute(item as LocalMylistGroup);
                    }
                    else if (mylistOrigin == PlaylistOrigin.LoginUser)
                    {
                        await UserMylistManager.RemoveMylist(item.Id);
                        //                        await UpdateUserMylist();
                    }
                }));

                dialog.Commands.Add(new UICommand("キャンセル"));
                dialog.CancelCommandIndex  = 1;
                dialog.DefaultCommandIndex = 1;

                await dialog.ShowAsync();
            });


            EditMylistGroupCommand = new DelegateCommand <Interfaces.IMylist>(async item =>
            {
                var mylistOrigin = item.ToMylistOrigin();
                if (mylistOrigin == PlaylistOrigin.Local)
                {
                    if (item.Id == HohoemaPlaylist.WatchAfterPlaylistId)
                    {
                        return;
                    }
                }
                else if (mylistOrigin == PlaylistOrigin.LoginUser)
                {
                    if (item.Id == "0")
                    {
                        return;
                    }
                }

                if (mylistOrigin == PlaylistOrigin.Local)
                {
                    var localMylist = item as LocalMylistGroup;
                    var resultText  = await DialogService.GetTextAsync("プレイリスト名を変更",
                                                                       localMylist.Label,
                                                                       localMylist.Label,
                                                                       (tempName) => !string.IsNullOrWhiteSpace(tempName)
                                                                       );

                    if (!string.IsNullOrWhiteSpace(resultText))
                    {
                        localMylist.Label = resultText;
                    }
                }


                if (mylistOrigin == PlaylistOrigin.LoginUser)
                {
                    var mylistGroupListItem   = item as UserOwnedMylist;
                    var selectedMylistGroupId = mylistGroupListItem.Id;

                    if (selectedMylistGroupId == null)
                    {
                        return;
                    }

                    var mylistGroup          = UserMylistManager.GetMylistGroup(selectedMylistGroupId);
                    MylistGroupEditData data = new MylistGroupEditData()
                    {
                        Name              = mylistGroup.Label,
                        Description       = mylistGroup.Description,
                        IsPublic          = mylistGroup.IsPublic,
                        MylistDefaultSort = mylistGroup.Sort,
                        IconType          = mylistGroup.IconType,
                    };

                    // 成功するかキャンセルが押されるまで繰り返す
                    while (true)
                    {
                        if (true == await DialogService.ShowCreateMylistGroupDialogAsync(data))
                        {
                            mylistGroup.Label       = data.Name;
                            mylistGroup.Description = data.Description;
                            mylistGroup.IsPublic    = data.IsPublic;
                            mylistGroup.Sort        = data.MylistDefaultSort;
                            mylistGroup.IconType    = data.IconType;
                            var result = await LoginUserMylistProvider.UpdateMylist(mylistGroup);

                            if (result == Mntone.Nico2.ContentManageResult.Success)
                            {
                                // TODO: UI上のマイリスト表示を更新する
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            });

            PlayAllCommand = new DelegateCommand <Interfaces.IMylist>((mylist) =>
            {
                if (mylist.ItemCount == 0)
                {
                    return;
                }

                HohoemaPlaylist.Play(mylist);
            });



            AddLocalMylistCommand = new DelegateCommand(async() =>
            {
                var name = await DialogService.GetTextAsync("新しいローカルマイリスト名を入力", "ローカルマイリスト名", "",
                                                            (s) =>
                {
                    if (string.IsNullOrWhiteSpace(s))
                    {
                        return(false);
                    }

                    if (LocalMylistManager.Mylists.Any(x => x.Label == s))
                    {
                        return(false);
                    }

                    return(true);
                });

                if (name != null)
                {
                    LocalMylistManager.Mylists.Add(new LocalMylistGroup(Guid.NewGuid().ToString(), name));
                }
            });
        }