Esempio n. 1
0
        private async void ShowNewVideosToastNotification(Subscription subscription, SubscriptionSource source, IEnumerable <IVideoContent> newItems)
        {
            var mylistMan = App.Current.Container.Resolve <UserMylistManager>();

            // TODO: プレイリスト毎にまとめたほうがいい?

            foreach (var dest in subscription.Destinations)
            {
                Interfaces.IPlaylist list = null;
                list = await _playlistAggregate.FindPlaylistAsync(dest.PlaylistId);

                if (list == null)
                {
                    // TODO: 購読で利用できない追加先プレイリストを通知する
                    continue;
                }

                IList <IVideoContent> videoList;
                if (NewItemsPerPlayableList.TryGetValue(list, out var cacheVideoList))
                {
                    videoList = cacheVideoList.Item1;

                    if (!cacheVideoList.Item2.Contains(subscription))
                    {
                        cacheVideoList.Item2.Add(subscription);
                    }
                }
                else
                {
                    videoList = new List <IVideoContent>();
                    NewItemsPerPlayableList.Add(list, new Tuple <IList <IVideoContent>, IList <Subscription> >(videoList, new List <Subscription>()
                    {
                        subscription
                    }));
                }

                foreach (var video in newItems)
                {
                    videoList.Add(video);
                }
            }


            try
            {
                foreach (var pair in NewItemsPerPlayableList)
                {
                    var playableList    = pair.Key;
                    var newItemsPerList = pair.Value.Item1;
                    var subscriptions   = pair.Value.Item2;

                    ToastVisual visual = new ToastVisual()
                    {
                        BindingGeneric = new ToastBindingGeneric()
                        {
                            Children = { }
                        }
                    };

                    visual.BindingGeneric.Children.Insert(0, new AdaptiveText()
                    {
                        Text      = "InAppNotification_AddItemToSubscription".Translate(playableList.Label),
                        HintStyle = AdaptiveTextStyle.Base
                    });

                    foreach (var item in newItemsPerList)
                    {
                        visual.BindingGeneric.Children.Add(new AdaptiveText()
                        {
                            Text      = item.Label,
                            HintStyle = AdaptiveTextStyle.BaseSubtle
                        });
                    }



                    ToastActionsCustom action = new ToastActionsCustom()
                    {
                        Buttons =
                        {
                            new ToastButton("WatchVideo".Translate(),           new LoginRedirectPayload()
                            {
                                RedirectPageType = HohoemaPageType.VideoPlayer, RedirectParamter           = $"id={newItemsPerList.First().Id}&playlist_id=@view"
                            }.ToParameterString())
                            {
                                ActivationType = ToastActivationType.Foreground,
                            },
                            new ToastButton("SubscriptionSettings".Translate(), new LoginRedirectPayload()
                            {
                                RedirectPageType = HohoemaPageType.Subscription
                            }.ToParameterString())
                            {
                                ActivationType = ToastActivationType.Foreground,
                            },
                        }
                    };

                    ToastContent toastContent = new ToastContent()
                    {
                        Visual  = visual,
                        Actions = action,
                    };

                    var toast = new ToastNotification(toastContent.GetXml());

                    var notifier = ToastNotificationManager.CreateToastNotifier();

                    toast.Tag   = playableList.Id;
                    toast.Group = TOAST_GROUP;
                    notifier.Show(toast);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
Esempio n. 2
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);
        }