protected override async Task NavigatedToAsync(CancellationToken cancelToken, NavigatedToEventArgs e, Dictionary <string, object> viewModelState)
        {
            if (e.Parameter is string)
            {
                var payload      = MylistPagePayload.FromParameterString <MylistPagePayload>(e.Parameter as string);
                var playableList = await MylistHelper.FindMylist(payload.Id, payload.Origin);

                Mylist.Value       = playableList;
                MylistOrigin.Value = playableList.ToMylistOrigin().Value;
            }

            if (Mylist.Value != null)
            {
                MylistBookmark = Database.BookmarkDb.Get(Database.BookmarkType.Mylist, Mylist.Value.Id)
                                 ?? new Database.Bookmark()
                {
                    Label        = Mylist.Value.Label,
                    Content      = Mylist.Value.Id,
                    BookmarkType = Database.BookmarkType.Mylist,
                };

                FollowToggleButtonService.SetFollowTarget(Mylist.Value as Interfaces.IFollowable);

                RaisePropertyChanged(nameof(MylistBookmark));
            }

            await Reset();

            await base.NavigatedToAsync(cancelToken, e, viewModelState);
        }
Example #2
0
        private void NewVideosAddToDestinations(IEnumerable <SubscriptionDestination> destinations, IEnumerable <Database.NicoVideo> newItems)
        {
            // あとで見るに追加
            foreach (var dest in destinations)
            {
                var origin = default(PlaylistOrigin?);
                if (dest.Target == SubscriptionDestinationTarget.LocalPlaylist)
                {
                    origin = PlaylistOrigin.Local;
                }
                else if (dest.Target == SubscriptionDestinationTarget.LoginUserMylist)
                {
                    origin = PlaylistOrigin.LoginUser;
                }

                var mylist = MylistHelper.FindMylistInCached(dest.PlaylistId, origin);
                if (mylist is Interfaces.IUserOwnedMylist ownedMylist)
                {
                    foreach (var video in newItems)
                    {
                        _ = ownedMylist.AddMylistItem(video.RawVideoId);
                    }
                }
            }
        }
        /*
         *
         * private async Task<bool> FavoriteMylist()
         *      {
         *              if (PlayableList.Value == null) { return false; }
         *  if (PlayableList.Value.Origin != PlaylistOrigin.OtherUser) { return false; }
         *
         *              var favManager = HohoemaApp.FollowManager;
         *              var result = await favManager.AddFollow(FollowItemType.Mylist, PlayableList.Value.Id, PlayableList.Value.Label);
         *
         *              return result == ContentManageResult.Success || result == ContentManageResult.Exist;
         *      }
         *
         *      private async Task<bool> UnfavoriteMylist()
         *      {
         *              if (PlayableList.Value == null) { return false; }
         *  if (PlayableList.Value.Origin != PlaylistOrigin.OtherUser) { return false; }
         *
         *  var favManager = HohoemaApp.FollowManager;
         *              var result = await favManager.RemoveFollow(FollowItemType.Mylist, PlayableList.Value.Id);
         *
         *              return result == ContentManageResult.Success;
         *
         *      }
         *
         */

        public async Task OnNavigatedToAsync(INavigationParameters parameters)
        {
            string         mylistId = null;
            PlaylistOrigin?origin   = null;

            if (parameters.TryGetValue <string>("id", out var idString))
            {
                mylistId = idString;
            }
            else if (parameters.TryGetValue <int>("id", out var idInt))
            {
                mylistId = idInt.ToString();
            }

            if (parameters.TryGetValue <PlaylistOrigin>("origin", out var mylistOrigin))
            {
                origin = mylistOrigin;
            }
            else if (parameters.TryGetValue("origin", out string mylistOriginString))
            {
                if (Enum.TryParse(mylistOriginString, out mylistOrigin))
                {
                    origin = mylistOrigin;
                }
            }

            var playableList = await MylistHelper.FindMylist(mylistId, origin);

            if (playableList == null)
            {
                return;
            }


            Mylist.Value       = playableList;
            MylistOrigin.Value = playableList.ToMylistOrigin().Value;

            if (Mylist.Value != null)
            {
                MylistBookmark = Database.BookmarkDb.Get(Database.BookmarkType.Mylist, Mylist.Value.Id)
                                 ?? new Database.Bookmark()
                {
                    Label        = Mylist.Value.Label,
                    Content      = Mylist.Value.Id,
                    BookmarkType = Database.BookmarkType.Mylist,
                };

                FollowToggleButtonService.SetFollowTarget(Mylist.Value as Interfaces.IFollowable);

                RaisePropertyChanged(nameof(MylistBookmark));
            }


            PageManager.PageTitle = playableList.Label;

            await Reset();
        }
Example #4
0
 public MultiSelectSubscriptionDestinationCommand(
     DialogService dialogService,
     LocalMylistManager localMylistManager,
     UserMylistManager userMylistManager,
     Services.HohoemaPlaylist hohoemaPlaylist,
     MylistHelper mylistHelper
     )
 {
     DialogService      = dialogService;
     LocalMylistManager = localMylistManager;
     UserMylistManager  = userMylistManager;
     HohoemaPlaylist    = hohoemaPlaylist;
     MylistHelper       = mylistHelper;
 }
Example #5
0
        private void ShowNewVideosToastNotification(Subscription subscription, SubscriptionSource source, IEnumerable <Database.NicoVideo> newItems)
        {
            var mylistMan = (App.Current as App).Container.Resolve <UserMylistManager>();

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

            foreach (var dest in subscription.Destinations)
            {
                Interfaces.IMylist list = null;
                if (dest.Target == SubscriptionDestinationTarget.LocalPlaylist)
                {
                    list = MylistHelper.FindMylistInCached(dest.PlaylistId, PlaylistOrigin.Local);
                }
                else if (dest.Target == SubscriptionDestinationTarget.LoginUserMylist)
                {
                    list = MylistHelper.FindMylistInCached(dest.PlaylistId, PlaylistOrigin.LoginUser);
                }

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

                    if (!cacheVideoList.Item2.Contains(subscription))
                    {
                        cacheVideoList.Item2.Add(subscription);
                    }
                }
                else
                {
                    videoList = new List <Database.NicoVideo>();
                    NewItemsPerPlayableList.Add(list, new Tuple <IList <Database.NicoVideo>, 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      = $"『{playableList.Label}』に新着動画を追加",
                        HintStyle = AdaptiveTextStyle.Base
                    });

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



                    ToastActionsCustom action = new ToastActionsCustom()
                    {
                        Buttons =
                        {
                            new ToastButton("視聴する",  new LoginRedirectPayload()
                            {
                                RedirectPageType = HohoemaPageType.VideoPlayer,RedirectParamter                             = newItemsPerList.First().RawVideoId
                            }.ToParameterString())
                            {
                                ActivationType = ToastActivationType.Foreground,
                            },
                            new ToastButton("購読を管理", 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());
            }
        }