Example #1
0
 public async Task <MylistPlaylist> GetMylist(string mylistId)
 {
     if (_userMylistManager.HasMylistGroup(mylistId))
     {
         return(_userMylistManager.GetMylistGroup(mylistId));
     }
     else
     {
         return(await _otherOwneredMylistManager.GetMylist(mylistId));
     }
 }
Example #2
0
        public Interfaces.IMylist FindMylistInCached(string id, Services.PlaylistOrigin?origin = null)
        {
            if (!origin.HasValue)
            {
                if (UserMylistManager.HasMylistGroup(id))
                {
                    origin = Services.PlaylistOrigin.LoginUser;
                }
                else if (Services.HohoemaPlaylist.WatchAfterPlaylistId == id)
                {
                    origin = Services.PlaylistOrigin.Local;
                }
                else if (LocalMylistManager.Mylists.FirstOrDefault(x => x.Id == id) != null)
                {
                    origin = Services.PlaylistOrigin.Local;
                }
                else
                {
                    origin = Services.PlaylistOrigin.OtherUser;
                }
            }

            switch (origin.Value)
            {
            case Services.PlaylistOrigin.LoginUser:
                // ログインユーザーのマイリスト
                return(UserMylistManager.GetMylistGroup(id));

            case Services.PlaylistOrigin.Local:
                // ローカルマイリスト
                if (Services.HohoemaPlaylist.WatchAfterPlaylistId == id)
                {
                    return(HohoemaPlaylist.DefaultPlaylist);
                }
                else
                {
                    return(LocalMylistManager.Mylists.FirstOrDefault(x => x.Id == id));
                }

            case Services.PlaylistOrigin.OtherUser:
                // 他ユーザーのマイリスト
                return(OtherOwneredMylistManager.GetMylistIfCached(id));

            default:
                throw new Exception("not found mylist:" + id);
            }
        }
        private async Task Reset()
        {
            if (Mylist.Value == null)
            {
                return;
            }

            CanEditMylist = false;

            var mylistOrigin = Mylist.Value?.ToMylistOrigin();

            IsLoginUserDeflist      = false;
            IsWatchAfterLocalMylist = Mylist.Value is Interfaces.ILocalMylist &&
                                      Mylist.Value?.Id == HohoemaPlaylist.WatchAfterPlaylistId;
            IsUserOwnerdMylist = Mylist.Value is Interfaces.IUserOwnedMylist;
            IsLocalMylist      = Mylist.Value is Interfaces.ILocalMylist;

            IsLoginUserMylistWithoutDeflist = false;

            MaxItemsCount = Mylist.Value.ItemCount;
            RaisePropertyChanged(nameof(MaxItemsCount));

            switch (mylistOrigin)
            {
            case PlaylistOrigin.LoginUser:
            {
                var mylistGroup = UserMylistManager.GetMylistGroup(Mylist.Value.Id);
                MylistItems = mylistGroup.ToReadOnlyReactiveCollection(x => new MylistVideItemViewModel(x, mylistGroup))
                              .AddTo(_NavigatingCompositeDisposable);

                MylistTitle        = mylistGroup.Label;
                MylistDescription  = mylistGroup.Description;
                ThemeColor         = mylistGroup.IconType.ToColor();
                IsPublic           = mylistGroup.IsPublic;
                IsLoginUserDeflist = mylistGroup.IsDeflist;

                OwnerUserId = mylistGroup.UserId;
                UserName    = NiconicoSession.UserName;

                CanEditMylist = !IsLoginUserDeflist;

                if (IsLoginUserDeflist)
                {
                    MylistState = "とりあえずマイリスト";
                    DeflistRegistrationCapacity = UserMylistManager.DeflistRegistrationCapacity;
                    DeflistRegistrationCount    = UserMylistManager.DeflistRegistrationCount;
                }
                else
                {
                    IsLoginUserMylistWithoutDeflist = true;
                    MylistState = IsPublic ? "公開マイリスト" : "非公開マイリスト";
                    MylistRegistrationCapacity = UserMylistManager.MylistRegistrationCapacity;
                    MylistRegistrationCount    = UserMylistManager.MylistRegistrationCount;
                }
            }
            break;


            case PlaylistOrigin.OtherUser:
                var otherOwnedMylist = Mylist.Value as OtherOwneredMylist;

                MylistItems = new IncrementalLoadingCollection <OtherOwnedMylistIncrementalSource, MylistVideItemViewModel>(new OtherOwnedMylistIncrementalSource(otherOwnedMylist, MylistProvider, NgSettings));

                var response = await MylistProvider.GetMylistGroupDetail(Mylist.Value.Id);

                var mylistGroupDetail = response.MylistGroup;
                MylistTitle       = otherOwnedMylist.Label;
                MylistDescription = otherOwnedMylist.Description;
                IsPublic          = true;
                //ThemeColor = mylistGroupDetail.GetIconType().ToColor();

                OwnerUserId = mylistGroupDetail.UserId;

                MylistState = IsPublic ? "公開マイリスト" : "非公開マイリスト";
                var user = Database.NicoVideoOwnerDb.Get(OwnerUserId);
                if (user != null)
                {
                    UserName = user.ScreenName;
                }
                else
                {
                    var userDetail = await UserProvider.GetUser(OwnerUserId);

                    UserName = userDetail.ScreenName;
                }

                CanEditMylist = false;

                break;



            case PlaylistOrigin.Local:
            {
                var localMylist = Mylist.Value as LocalMylistGroup;
                MylistItems = localMylist.ToReadOnlyReactiveCollection(x => new MylistVideItemViewModel(x, localMylist))
                              .AddTo(_NavigatingCompositeDisposable);

                MylistTitle = Mylist.Value.Label;
                OwnerUserId = NiconicoSession.UserId.ToString();
                UserName    = NiconicoSession.UserName;

                MylistState = "ローカル";

                CanEditMylist = !IsWatchAfterLocalMylist;
            }

            break;

            default:
                break;
            }

            RaisePropertyChanged(nameof(MylistItems));

            EditMylistGroupCommand.RaiseCanExecuteChanged();
            DeleteMylistCommand.RaiseCanExecuteChanged();
        }
Example #4
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));
                }
            });
        }