Пример #1
0
        public async Task <Tuple <MylistGroupInfo, string> > GetResult()
        {
            MylistGroupInfo mylistGroupInfo;

            if (IsCreateMylistMode.Value)
            {
                if (HasMylistName.Value == false)
                {
                    throw new Exception();
                }
                var prevMylistGroups = UserMylistManager.UserMylists.ToArray();

                var result = await UserMylistManager.AddMylist(NewMylistName.Value, "", false, Mntone.Nico2.Mylist.MylistDefaultSort.Latest, Mntone.Nico2.Mylist.IconType.Default);

                if (result == Mntone.Nico2.ContentManageResult.Success)
                {
                    var added = UserMylistManager.UserMylists.Single(x => !prevMylistGroups.Any(y => x.GroupId == y.GroupId));
                    mylistGroupInfo = added;
                }
                else
                {
                    throw new Exception();
                }
            }
            else
            {
                mylistGroupInfo = SelectedItem.Value;
            }
            return(new Tuple <MylistGroupInfo, string>(mylistGroupInfo, MylistComment.Value));
        }
Пример #2
0
        protected override async void Execute(object parameter)
        {
            var data = new Dialogs.MylistGroupEditData()
            {
            };
            var result = await DialogService.ShowCreateMylistGroupDialogAsync(data);

            if (result)
            {
                var mylistCreateResult = await UserMylistManager.AddMylist(data.Name, data.Description, data.IsPublic, data.MylistDefaultSort, data.IconType);

                Debug.WriteLine("マイリスト作成:" + mylistCreateResult);
            }

            var mylist = UserMylistManager.Mylists.FirstOrDefault(x => x.Label == data.Name);

            if (mylist == null)
            {
                return;
            }

            if (parameter is Interfaces.IVideoContent content)
            {
                await mylist.AddItem(content.Id);
            }
            else if (parameter is string videoId)
            {
                await mylist.AddItem(videoId);
            }
        }
Пример #3
0
        protected override async void Execute(object parameter)
        {
            var currentMethod = System.Reflection.MethodBase.GetCurrentMethod();
            //Microsoft.AppCenter.Analytics.Analytics.TrackEvent($"{currentMethod.DeclaringType.Name}#{currentMethod.Name}");

            var data = new Dialogs.MylistGroupEditData()
            {
            };
            var result = await DialogService.ShowCreateMylistGroupDialogAsync(data);

            if (result)
            {
                var mylist = await UserMylistManager.AddMylist(data.Name, data.Description, data.IsPublic, data.DefaultSortKey, data.DefaultSortOrder);

                if (mylist == null)
                {
                    return;
                }

                if (parameter is IVideoContent content)
                {
                    await mylist.AddItem(content);
                }
                else if (parameter is IEnumerable <IVideoContent> items)
                {
                    await mylist.AddItem(items);
                }
            }
        }
Пример #4
0
        public async Task <Interfaces.IUserOwnedMylist> ChoiceMylist(
            params string[] ignoreMylistId
            )
        {
            const string CreateNewContextLabel = @"@create_new";
            var          mylists      = UserMylistManager.Mylists;
            var          localMylists = LocalMylistManager.Mylists;

            List <ISelectableContainer> selectDialogContent;

            if (false)
            {
                selectDialogContent = new List <ISelectableContainer>()
                {
                    new ChoiceFromListSelectableContainer("マイリスト",
                                                          mylists.Where(x => ignoreMylistId.All(y => x.Id != y))
                                                          .Select(x => new SelectDialogPayload()
                    {
                        Label = x.Label, Id = x.Id, Context = x
                    })
                                                          ),
                    new ChoiceFromListSelectableContainer("ローカルマイリスト",
                                                          localMylists.Where(x => ignoreMylistId.All(y => x.Id != y))
                                                          .Select(x => new SelectDialogPayload()
                    {
                        Label = x.Label, Id = x.Id, Context = x
                    })
                                                          ),
                    new ChoiceFromListSelectableContainer("新規作成",
                                                          new [] {
                        new SelectDialogPayload()
                        {
                            Label = "マイリストを作成", Id = "mylist", Context = CreateNewContextLabel
                        },
                        new SelectDialogPayload()
                        {
                            Label = "ローカルマイリストを作成", Id = "local", Context = CreateNewContextLabel
                        },
                    }
                                                          )
                };
            }
            else
            {
                selectDialogContent = new List <ISelectableContainer>()
                {
                    new ChoiceFromListSelectableContainer("ローカルマイリスト",
                                                          localMylists.Where(x => ignoreMylistId.All(y => x.Id != y))
                                                          .Select(x => new SelectDialogPayload()
                    {
                        Label = x.Label, Id = x.Id, Context = x
                    })
                                                          ),
                    new ChoiceFromListSelectableContainer("新規作成",
                                                          new [] {
                        new SelectDialogPayload()
                        {
                            Label = "ローカルマイリストを作成", Id = "local", Context = CreateNewContextLabel
                        },
                    }
                                                          )
                };
            }

            Interfaces.IUserOwnedMylist resultList = null;
            while (resultList == null)
            {
                var result = await ShowContentSelectDialogAsync(
                    "追加先マイリストを選択",
                    selectDialogContent
                    );

                if (result == null)
                {
                    break;
                }

                if (result?.Context as string == CreateNewContextLabel)
                {
                    var mylistTypeLabel = result.Id == "mylist" ? "マイリスト" : "ローカルマイリスト";
                    var title           = await GetTextAsync(
                        $"{mylistTypeLabel}を作成",
                        $"{mylistTypeLabel}名",
                        validater : (str) => !string.IsNullOrWhiteSpace(str)
                        );

                    if (title == null)
                    {
                        continue;
                    }

                    if (result.Id == "mylist")
                    {
                        await UserMylistManager.AddMylist(title, "", false, Mntone.Nico2.Mylist.MylistDefaultSort.FirstRetrieve_Descending, Mntone.Nico2.Mylist.IconType.Default);

                        resultList = UserMylistManager.Mylists.FirstOrDefault(x => x.Label == title);
                    }
                    else //if (result.Id == "local")
                    {
                        var localMylist = new LocalMylistGroup(Guid.NewGuid().ToString(), title);
                        LocalMylistManager.Mylists.Add(localMylist);
                        resultList = localMylist;
                    }
                }
                else
                {
                    resultList = result?.Context as Interfaces.IUserOwnedMylist;
                }
            }

            return(resultList);
        }
Пример #5
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;
                        }
                    }
                }
            });
        }
Пример #6
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));
                }
            });
        }
Пример #7
0
        public async Task <Interfaces.IPlaylist> ChoiceMylist(
            params string[] ignoreMylistId
            )
        {
            const string CreateNewContextLabel = @"@create_new";
            var          mylists      = _userMylistManager.Mylists;
            var          localMylists = _localMylistManager.LocalPlaylists;

            List <ISelectableContainer> selectDialogContent;

            if (false)
            {
                selectDialogContent = new List <ISelectableContainer>()
                {
                    new ChoiceFromListSelectableContainer("マイリスト",
                                                          mylists.Where(x => ignoreMylistId.All(y => x.Id != y))
                                                          .Select(x => new SelectDialogPayload()
                    {
                        Label = x.Label, Id = x.Id, Context = x
                    })
                                                          ),
                    new ChoiceFromListSelectableContainer("ローカルマイリスト",
                                                          localMylists.Where(x => ignoreMylistId.All(y => x.Id != y))
                                                          .Select(x => new SelectDialogPayload()
                    {
                        Label = x.Label, Id = x.Id, Context = x
                    })
                                                          ),
                    new ChoiceFromListSelectableContainer("新規作成",
                                                          new [] {
                        new SelectDialogPayload()
                        {
                            Label = "マイリストを作成", Id = "mylist", Context = CreateNewContextLabel
                        },
                        new SelectDialogPayload()
                        {
                            Label = "ローカルマイリストを作成", Id = "local", Context = CreateNewContextLabel
                        },
                    }
                                                          )
                };
            }
            else
            {
                selectDialogContent = new List <ISelectableContainer>()
                {
                    new ChoiceFromListSelectableContainer("LocalPlaylist".Translate(),
                                                          localMylists.Where(x => ignoreMylistId.All(y => x.Id != y))
                                                          .Select(x => new SelectDialogPayload()
                    {
                        Label = x.Label, Id = x.Id, Context = x
                    })
                                                          ),
                    new ChoiceFromListSelectableContainer("CreateNew".Translate(),
                                                          new [] {
                        new SelectDialogPayload()
                        {
                            Label = "LocalPlaylistCreate".Translate(), Id = "local", Context = CreateNewContextLabel
                        },
                    }
                                                          )
                };
            }

            Interfaces.IPlaylist resultList = null;
            while (resultList == null)
            {
                var result = await _dialogService.ShowContentSelectDialogAsync(
                    "SelectMylist".Translate(),
                    selectDialogContent
                    );

                if (result == null)
                {
                    break;
                }

                if (result?.Context as string == CreateNewContextLabel)
                {
                    if (result.Id == "mylist")
                    {
                        var title = await _dialogService.GetTextAsync(
                            $"MylistCreate".Translate(),
                            $"MylistNameTextBoxPlacefolder".Translate(),
                            validater : (str) => !string.IsNullOrWhiteSpace(str)
                            );

                        await _userMylistManager.AddMylist(title, "", false, Mntone.Nico2.Mylist.MylistDefaultSort.FirstRetrieve_Descending, Mntone.Nico2.Mylist.IconType.Default);

                        resultList = _userMylistManager.Mylists.LastOrDefault(x => x.Label == title);
                    }
                    else //if (result.Id == "local")
                    {
                        var title = await _dialogService.GetTextAsync(
                            $"LocalPlaylistCreate".Translate(),
                            $"LocalPlaylistNameTextBoxPlacefolder".Translate(),
                            validater : (str) => !string.IsNullOrWhiteSpace(str)
                            );

                        resultList = _localMylistManager.CreatePlaylist(title);;
                    }
                }
                else
                {
                    resultList = result?.Context as Interfaces.IPlaylist;
                }
            }

            return(resultList);
        }