Beispiel #1
0
        public override async Task OnNavigatedToAsync(INavigationParameters parameters)
        {
            await RefreshCacheSaveFolderStatus();

            if (IsRequireUpdateCacheSaveFolder.Value)
            {
                NotificationService.ShowInAppNotification(
                    InAppNotificationPayload.CreateReadOnlyNotification("ChoiceCacheSavingFolder".Translate(),
                                                                        showDuration: TimeSpan.FromSeconds(30)
                                                                        ));

                if (await CacheSaveFolder.ChangeUserDataFolder())
                {
                    await Task.Delay(1000);

                    await RefreshCacheSaveFolderStatus();
                    await ResetList();

                    NotificationService.ShowInAppNotification(
                        InAppNotificationPayload.CreateReadOnlyNotification("ReadyForVideoCache".Translate())
                        );
                }
            }

            await base.OnNavigatedToAsync(parameters);
        }
Beispiel #2
0
        protected override async Task NavigatedToAsync(CancellationToken cancelToken, NavigatedToEventArgs e, Dictionary <string, object> viewModelState)
        {
            await RefreshCacheSaveFolderStatus();

            if (IsRequireUpdateCacheSaveFolder.Value)
            {
                NotificationService.ShowInAppNotification(
                    InAppNotificationPayload.CreateReadOnlyNotification("キャッシュの保存先フォルダを選択してください。\n保存先が選択されると利用準備が完了します。",
                                                                        showDuration: TimeSpan.FromSeconds(30)
                                                                        ));

                if (await CacheSaveFolder.ChangeUserDataFolder())
                {
                    await Task.Delay(1000);

                    await RefreshCacheSaveFolderStatus();
                    await ResetList();

                    NotificationService.ShowInAppNotification(
                        InAppNotificationPayload.CreateReadOnlyNotification("キャッシュの利用準備が出来ました")
                        );
                }
            }

            await base.NavigatedToAsync(cancelToken, e, viewModelState);
        }
        public override async Task OnNavigatedToAsync(INavigationParameters parameters)
        {
            await RefreshCacheSaveFolderStatus();

            if (IsRequireUpdateCacheSaveFolder.Value)
            {
                NotificationService.ShowInAppNotification(
                    InAppNotificationPayload.CreateReadOnlyNotification("キャッシュの保存先フォルダを選択してください。\n保存先が選択されると利用準備が完了します。",
                                                                        showDuration: TimeSpan.FromSeconds(30)
                                                                        ));

                if (await CacheSaveFolder.ChangeUserDataFolder())
                {
                    await Task.Delay(1000);

                    await RefreshCacheSaveFolderStatus();
                    await ResetList();

                    NotificationService.ShowInAppNotification(
                        InAppNotificationPayload.CreateReadOnlyNotification("キャッシュの利用準備が出来ました")
                        );
                }
            }

            await base.OnNavigatedToAsync(parameters);
        }
Beispiel #4
0
        private async Task SubmitLiveContentSuggestion(string liveId)
        {
            var hohoemaApp = App.Current.Container.Resolve <HohoemaApp>();

            var liveDesc = await hohoemaApp.NiconicoContext.Live.GetPlayerStatusAsync(liveId);

            if (liveDesc == null)
            {
                return;
            }

            var payload = new InAppNotificationPayload()
            {
                Content             = $"{liveDesc.Program.Title} をお探しですか?",
                ShowDuration        = DefaultNotificationShowDuration,
                SymbolIcon          = Symbol.Video,
                IsShowDismissButton = true,
                Commands            =
                {
                    new InAppNotificationCommand()
                    {
                        Label   = "視聴開始",
                        Command = new DelegateCommand(() =>
                        {
                            hohoemaApp.Playlist.PlayLiveVideo(liveId, liveDesc.Program.Title);

                            DismissInAppNotification();
                        })
                    },
                }
            };

            if (liveDesc.Program.IsCommunity)
            {
                payload.Commands.Add(new InAppNotificationCommand()
                {
                    Label   = "コミュニティを開く",
                    Command = new DelegateCommand(() =>
                    {
                        var pageManager = App.Current.Container.Resolve <PageManager>();
                        pageManager.OpenPage(HohoemaPageType.Community, liveDesc.Program.CommunityId);

                        DismissInAppNotification();
                    })
                });
            }

            PublishInAppNotification(payload);
        }
Beispiel #5
0
        private void PushNextNotication(InAppNotificationPayload payload)
        {
            NoticationRequestQueue.Enqueue(payload);

            _dispatcherQueue.TryEnqueue(() =>
            {
                // 前に表示した通知が時間設定されていない場合には強制非表示
                if (_CurrentNotication != null && _CurrentNotication.ShowDuration == null)
                {
                    LiteNotification.Dismiss();
                }
                else
                {
                    TryNextDisplayNotication();
                }
            });
        }
Beispiel #6
0
        private void TryNextDisplayNotication()
        {
            // only show Active Window
            if (_CurrentActiveWindowUIContextService.UIContext != UIContext)
            {
                NoticationRequestQueue.Clear();
                return;
            }

            if (NoticationRequestQueue.TryDequeue(out var payload))
            {
                if (payload == null)
                {
                    return;
                }

                _CurrentNotication = payload;

                LiteNotification.DataContext       = payload;
                LiteNotification.ShowDismissButton = payload.IsShowDismissButton;
                LiteNotification.Show((int)(payload.ShowDuration ?? DefaultShowDuration).TotalMilliseconds);
            }
        }
Beispiel #7
0
 private void LiteNotification_Dismissed(object sender, EventArgs e)
 {
     _CurrentNotication = null;
     (sender as Microsoft.Toolkit.Uwp.UI.Controls.InAppNotification).DataContext = null;
     TryNextDisplayNotication();
 }
        public CacheManagementPageViewModel(
            HohoemaApp app,
            PageManager pageManager,
            HohoemaDialogService dialogService
            )
            : base(app, pageManager)
        {
            _MediaManager         = app.CacheManager;
            _HohoemaDialogService = dialogService;

            IsRequireUpdateCacheSaveFolder = new ReactiveProperty <bool>(false);

            IsCacheUserAccepted = HohoemaApp.UserSettings.CacheSettings.ObserveProperty(x => x.IsUserAcceptedCache)
                                  .ToReadOnlyReactiveProperty();

            RequireEnablingCacheCommand = new DelegateCommand(async() =>
            {
                var result = await _HohoemaDialogService.ShowAcceptCacheUsaseDialogAsync();
                if (result)
                {
                    HohoemaApp.UserSettings.CacheSettings.IsEnableCache       = true;
                    HohoemaApp.UserSettings.CacheSettings.IsUserAcceptedCache = true;
                    (App.Current).Resources["IsCacheEnabled"] = true;

                    await RefreshCacheSaveFolderStatus();

                    (App.Current as App).PublishInAppNotification(
                        InAppNotificationPayload.CreateReadOnlyNotification("キャッシュの保存先フォルダを選択してください。\n保存先が選択されると利用準備が完了します。",
                                                                            showDuration: TimeSpan.FromSeconds(30)
                                                                            ));

                    if (await HohoemaApp.ChangeUserDataFolder())
                    {
                        await RefreshCacheSaveFolderStatus();
                        await ResetList();

                        (App.Current as App).PublishInAppNotification(
                            InAppNotificationPayload.CreateReadOnlyNotification("キャッシュの利用準備が出来ました")
                            );
                    }
                }
            });

            ReadCacheAcceptTextCommand = new DelegateCommand(async() =>
            {
                var result = await _HohoemaDialogService.ShowAcceptCacheUsaseDialogAsync(showWithoutConfirmButton: true);
            });



            CacheFolderStateDescription = new ReactiveProperty <string>("");
            CacheSaveFolderPath         = new ReactiveProperty <string>("");

            OpenCurrentCacheFolderCommand = new DelegateCommand(async() =>
            {
                await RefreshCacheSaveFolderStatus();

                var folder = await HohoemaApp.GetVideoCacheFolder();
                if (folder != null)
                {
                    await Launcher.LaunchFolderAsync(folder);
                }
            });


            ChangeCacheFolderCommand = new DelegateCommand(async() =>
            {
                var prevPath = CacheSaveFolderPath.Value;

                if (await HohoemaApp.ChangeUserDataFolder())
                {
                    (App.Current as App).PublishInAppNotification(
                        InAppNotificationPayload.CreateReadOnlyNotification($"キャッシュの保存先を {CacheSaveFolderPath.Value} に変更しました")
                        );

                    await RefreshCacheSaveFolderStatus();
                    await ResetList();
                }
            });
        }
Beispiel #9
0
        public CacheManagementPageViewModel(
            ApplicationLayoutManager applicationLayoutManager,
            CacheSettings cacheSettings,
            VideoCacheManager videoCacheManager,
            CacheSaveFolder cacheSaveFolder,
            NicoVideoProvider nicoVideoProvider,
            PageManager pageManager,
            DialogService dialogService,
            NotificationService notificationService,
            HohoemaPlaylist hohoemaPlaylist
            )
        {
            ApplicationLayoutManager       = applicationLayoutManager;
            CacheSettings                  = cacheSettings;
            VideoCacheManager              = videoCacheManager;
            CacheSaveFolder                = cacheSaveFolder;
            NicoVideoProvider              = nicoVideoProvider;
            HohoemaDialogService           = dialogService;
            NotificationService            = notificationService;
            HohoemaPlaylist                = hohoemaPlaylist;
            IsRequireUpdateCacheSaveFolder = new ReactiveProperty <bool>(false);

            IsCacheUserAccepted = CacheSettings.ObserveProperty(x => x.IsUserAcceptedCache)
                                  .ToReadOnlyReactiveProperty();

            RequireEnablingCacheCommand = new DelegateCommand(async() =>
            {
                var result = await HohoemaDialogService.ShowAcceptCacheUsaseDialogAsync();
                if (result)
                {
                    CacheSettings.IsEnableCache               = true;
                    CacheSettings.IsUserAcceptedCache         = true;
                    (App.Current).Resources["IsCacheEnabled"] = true;

                    await RefreshCacheSaveFolderStatus();

                    NotificationService.ShowInAppNotification(
                        InAppNotificationPayload.CreateReadOnlyNotification("ChoiceCacheSavingFolder".Translate(),
                                                                            showDuration: TimeSpan.FromSeconds(30)
                                                                            ));

                    if (await CacheSaveFolder.ChangeUserDataFolder())
                    {
                        await RefreshCacheSaveFolderStatus();

                        await VideoCacheManager.CacheFolderChanged();

                        await ResetList();

                        NotificationService.ShowInAppNotification(
                            InAppNotificationPayload.CreateReadOnlyNotification("ReadyForVideoCache".Translate())
                            );
                    }
                }
            });

            ReadCacheAcceptTextCommand = new DelegateCommand(async() =>
            {
                var result = await HohoemaDialogService.ShowAcceptCacheUsaseDialogAsync(showWithoutConfirmButton: true);
            });



            CacheFolderStateDescription = new ReactiveProperty <string>("");
            CacheSaveFolderPath         = new ReactiveProperty <string>("");

            OpenCurrentCacheFolderCommand = new DelegateCommand(async() =>
            {
                await RefreshCacheSaveFolderStatus();

                var folder = await CacheSaveFolder.GetVideoCacheFolder();
                if (folder != null)
                {
                    await Launcher.LaunchFolderAsync(folder);
                }
            });


            ChangeCacheFolderCommand = new DelegateCommand(async() =>
            {
                var prevPath = CacheSaveFolderPath.Value;

                if (await CacheSaveFolder.ChangeUserDataFolder())
                {
                    NotificationService.ShowInAppNotification(
                        InAppNotificationPayload.CreateReadOnlyNotification("CacheSaveFolderChangeToX".Translate(CacheSaveFolderPath.Value))
                        );

                    await RefreshCacheSaveFolderStatus();

                    await VideoCacheManager.CacheFolderChanged();

                    await ResetList();
                }
            });
        }
Beispiel #10
0
        public void PublishInAppNotification(InAppNotificationPayload payload)
        {
            var notificationEvent = EventAggregator.GetEvent <InAppNotificationEvent>();

            notificationEvent.Publish(payload);
        }
        public HohoemaVideoListingPageViewModelBase(HohoemaApp app, PageManager pageManager, bool isRequireSignIn = true, bool useDefaultPageTitle = true)
            : base(app, pageManager, useDefaultPageTitle: useDefaultPageTitle)
        {
            var SelectionItemsChanged = SelectedItems.ToCollectionChanged().ToUnit();

#if DEBUG
            SelectedItems.CollectionChangedAsObservable()
            .Subscribe(x =>
            {
                Debug.WriteLine("Selected Count: " + SelectedItems.Count);
            })

            .AddTo(_CompositeDisposable);
#endif


            PlayAllCommand = SelectionItemsChanged
                             .Select(_ => SelectedItems.Count > 0)
                             .ToReactiveCommand(false)
                             .AddTo(_CompositeDisposable);

            PlayAllCommand
            .SubscribeOnUIDispatcher()
            .Subscribe(_ =>
            {
                // TODO: プレイリストに登録
                // プレイリストを空にしてから選択動画を登録

                //				SelectedVideoInfoItems.First()?.PlayCommand.Execute();
            })
            .AddTo(_CompositeDisposable);

            CancelCacheDownloadRequest = SelectionItemsChanged
                                         .Select(_ => SelectedItems.Count > 0)
                                         .ToReactiveCommand(false)
                                         .AddTo(_CompositeDisposable);

            CancelCacheDownloadRequest
            .SubscribeOnUIDispatcher()
            .Subscribe(async _ =>
            {
                var items  = EnumerateCacheRequestedVideoItems().ToList();
                var action = AsyncInfo.Run <uint>(async(cancelToken, progress) =>
                {
                    uint count = 0;
                    foreach (var item in items)
                    {
                        foreach (var quality in item.CachedQualityVideos.ToArray())
                        {
                            await HohoemaApp.CacheManager.CancelCacheRequest(item.RawVideoId, quality.Quality);
                        }

                        ++count;
                        progress.Report(count);
                    }

                    ClearSelection();
                });

                await PageManager.StartNoUIWork("キャッシュリクエストをキャンセル中", items.Count, () => action);
            }
                       )
            .AddTo(_CompositeDisposable);


            // クオリティ指定無しのキャッシュDLリクエスト
            RequestCacheDownload = SelectionItemsChanged
                                   .Select(_ => SelectedItems.Count > 0 && CanDownload)
                                   .ToReactiveCommand(false)
                                   .AddTo(_CompositeDisposable);

            RequestCacheDownload
            .SubscribeOnUIDispatcher()
            .Subscribe(async _ =>
            {
                foreach (var item in SelectedItems)
                {
                    await HohoemaApp.CacheManager.RequestCache(item.RawVideoId, NicoVideoQuality.Smile_Original);
                }

                ClearSelection();
                await UpdateList();
            })
            .AddTo(_CompositeDisposable);



            RegistratioMylistCommand = SelectionItemsChanged
                                       .Select(x => SelectedItems.Count > 0)
                                       .ToReactiveCommand(false)
                                       .AddTo(_CompositeDisposable);
            RegistratioMylistCommand
            .SubscribeOnUIDispatcher()
            .Subscribe(async _ =>
            {
                var targetMylist = await HohoemaApp.ChoiceMylist();

                if (targetMylist == null)
                {
                    return;
                }

                var items  = SelectedItems.ToList();
                var action = AsyncInfo.Run <uint>(async(cancelToken, progress) =>
                {
                    uint progressCount = 0;

                    Debug.WriteLine($"一括マイリストに追加を開始...");
                    int successCount = 0;
                    int existCount   = 0;
                    int failedCount  = 0;
                    foreach (var video in SelectedItems)
                    {
                        var registrationResult = await HohoemaApp.AddMylistItem(targetMylist, video.Label, video.RawVideoId);

                        switch (registrationResult)
                        {
                        case Mntone.Nico2.ContentManageResult.Success: successCount++; break;

                        case Mntone.Nico2.ContentManageResult.Exist: existCount++; break;

                        case Mntone.Nico2.ContentManageResult.Failed: failedCount++; break;

                        default:
                            break;
                        }

                        Debug.WriteLine($"{video.Label}[{video.RawVideoId}]:{registrationResult.ToString()}");

                        progressCount++;
                        progress.Report(progressCount);
                    }


                    if (targetMylist.Origin == PlaylistOrigin.LoginUser)
                    {
                        var mylistGroup = targetMylist as MylistGroupInfo;
                        await mylistGroup.Refresh();

                        // マイリストに追加に失敗したものを残すように
                        // 登録済みのアイテムを選択アイテムリストから削除
                        foreach (var item in SelectedItems.ToArray())
                        {
                            if (mylistGroup.CheckRegistratedVideoId(item.RawVideoId))
                            {
                                SelectedItems.Remove(item);
                            }
                        }
                    }

                    // リフレッシュ



                    // ユーザーに結果を通知

                    var titleText  = $"「{targetMylist.Label}」に {successCount}件 の動画を登録しました";
                    var resultText = $"";
                    if (existCount > 0)
                    {
                        resultText += $"重複:{existCount} 件";
                    }
                    if (failedCount > 0)
                    {
                        resultText += $"\n登録に失敗した {failedCount}件 は選択されたままです";
                    }

                    (App.Current as App).PublishInAppNotification(InAppNotificationPayload.CreateReadOnlyNotification(
                                                                      titleText,
                                                                      TimeSpan.FromSeconds(7)
                                                                      ));
                    //					ResetList();

                    Debug.WriteLine($"一括マイリストに追加を完了---------------");
                    ClearSelection();
                });

                await PageManager.StartNoUIWork("マイリストに追加", items.Count, () => action);
            }
                       )
            .AddTo(_CompositeDisposable);


            Playlists = HohoemaApp.Playlist.Playlists.ToReadOnlyReactiveCollection();
        }