Exemplo n.º 1
0
        private async Task <bool> AddReservation(string liveId, string liveTitle)
        {
            var result = await NiconicoSession.Context.Live.ReservationAsync(liveId);

            bool isAdded = false;

            if (result.IsCanOverwrite)
            {
                // 予約数が上限到達、他のタイムシフトを削除すれば予約可能
                // いずれかの予約を削除するよう選択してもらう
                if (await HohoemaDialogService.ShowMessageDialog(
                        "Dialog_ConfirmTimeshiftReservationiOverwrite".Translate(result.Data.Overwrite.Title, liveTitle),
                        "DialogTitle_ConfirmTimeshiftReservationiOverwrite".Translate(),
                        "Overwrite".Translate(),
                        "Cancel".Translate()
                        ))
                {
                    result = await NiconicoSession.Context.Live.ReservationAsync(liveId, isOverwrite : true);
                }
            }

            if (result.IsOK)
            {
                // 予約できてるはず
                // LiveInfoのタイムシフト周りの情報と共に通知
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = "InAppNotification_AddedTimeshiftWithTitle".Translate(liveTitle),
                });

                isAdded = true;
            }
            else if (result.IsCanOverwrite)
            {
                // 一つ前のダイアログで明示的的にキャンセルしてるはずなので特に通知を表示しない
            }
            else if (result.IsReservationDeuplicated)
            {
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = "InAppNotification_ExistTimeshift".Translate(),
                });
            }
            else if (result.IsReservationExpired)
            {
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = "InAppNotification_TimeshiftExpired".Translate(),
                });
            }

            return(isAdded);
        }
        private async Task <bool> AddReservation(string liveId, string liveTitle)
        {
            var result = await NiconicoSession.Context.Live.ReservationAsync(liveId);

            bool isAdded = false;

            if (result.IsCanOverwrite)
            {
                // 予約数が上限到達、他のタイムシフトを削除すれば予約可能
                // いずれかの予約を削除するよう選択してもらう
                if (await HohoemaDialogService.ShowMessageDialog(
                        $"『{result.Data.Overwrite.Title}』を『{liveTitle}』のタイムシフト予約で上書きすると予約できます。\r(他のタイムシフトを削除したい場合はキャンセルしてタイムシフト一覧ページから操作してください。)",
                        "予約枠に空きがありません。古いタイムシフト予約を上書きしますか?"
                        , "予約を上書きする"
                        , "キャンセル"
                        ))
                {
                    result = await NiconicoSession.Context.Live.ReservationAsync(liveId, isOverwrite : true);
                }
            }

            if (result.IsOK)
            {
                // 予約できてるはず
                // LiveInfoのタイムシフト周りの情報と共に通知
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = $"『{liveTitle}』のタイムシフトを予約しました。",
                });

                isAdded = true;
            }
            else if (result.IsCanOverwrite)
            {
                // 一つ前のダイアログで明示的的にキャンセルしてるはずなので特に通知を表示しない
            }
            else if (result.IsReservationDeuplicated)
            {
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = $"指定された放送は既にタイムシフト予約しています。",
                });
            }
            else if (result.IsReservationExpired)
            {
                var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                notificationService.ShowInAppNotification(new InAppNotificationPayload()
                {
                    Content = $"指定された放送はタイムシフト予約の期限を過ぎているため予約できませんでした。",
                });
            }

            return(isAdded);
        }
        private async Task <bool> DeleteReservation(string liveId, string liveTitle)
        {
            if (string.IsNullOrEmpty(liveId))
            {
                throw new ArgumentException(nameof(liveId));
            }

            bool isDeleted = false;

            var token = await NiconicoSession.Context.Live.GetReservationTokenAsync();

            if (token == null)
            {
                return(isDeleted);
            }

            if (await HohoemaDialogService.ShowMessageDialog(
                    $"{liveTitle}",
                    "タイムシフト予約を削除しますか?"
                    , "予約を削除"
                    , "キャンセル"
                    )
                )
            {
                await NiconicoSession.Context.Live.DeleteReservationAsync(liveId, token);

                var deleteAfterReservations = await NiconicoSession.Context.Live.GetReservationsAsync();

                isDeleted = !deleteAfterReservations.Any(x => liveId.EndsWith(x));
                if (isDeleted)
                {
                    // 削除成功
                    var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                    notificationService.ShowInAppNotification(new InAppNotificationPayload()
                    {
                        Content             = $"タイムシフト予約を削除しました。\r削除後の予約数は {deleteAfterReservations.Count}件 です。",
                        IsShowDismissButton = true,
                    });
                }
                else
                {
                    // まだ存在するゾイ
                    var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                    notificationService.ShowInAppNotification(new InAppNotificationPayload()
                    {
                        Content             = $"【失敗】タイムシフト予約を削除できませんでした。",
                        IsShowDismissButton = true,
                    });

                    Debug.Fail("タイムシフト削除に失敗しました: " + liveId);
                }
            }

            return(isDeleted);
        }
Exemplo n.º 4
0
        private async Task <bool> DeleteReservation(string liveId, string liveTitle)
        {
            if (string.IsNullOrEmpty(liveId))
            {
                throw new ArgumentException(nameof(liveId));
            }

            bool isDeleted = false;

            var token = await NiconicoSession.Context.Live.GetReservationTokenAsync();

            if (token == null)
            {
                return(isDeleted);
            }

            if (await HohoemaDialogService.ShowMessageDialog(
                    $"{liveTitle}",
                    "ConfirmDeleteTimeshift".Translate()
                    , "DeleteTimeshift".Translate()
                    , "Cancel".Translate()
                    )
                )
            {
                await NiconicoSession.Context.Live.DeleteReservationAsync(liveId, token);

                var deleteAfterReservations = await NiconicoSession.Context.Live.GetReservationsAsync();

                isDeleted = !deleteAfterReservations.Any(x => liveId.EndsWith(x));
                if (isDeleted)
                {
                    // 削除成功
                    var notificationService = (App.Current as App).Container.Resolve <Services.NotificationService>();
                    notificationService.ShowInAppNotification(new InAppNotificationPayload()
                    {
                        Content             = "InAppNotification_DeletedTimeshift".Translate(),
                        IsShowDismissButton = true,
                    });
                }
                else
                {
                    // まだ存在するゾイ
                    var notificationService = App.Current.Container.Resolve <Services.NotificationService>();
                    notificationService.ShowInAppNotification(new InAppNotificationPayload()
                    {
                        Content             = "InAppNotification_FailedDeleteTimeshift".Translate(),
                        IsShowDismissButton = true,
                    });

                    Debug.Fail("タイムシフト削除に失敗しました: " + liveId);
                }
            }

            return(isDeleted);
        }
Exemplo n.º 5
0
        public PageManager(HohoemaApp hohoemaApp, INavigationService ns, AppearanceSettings appearanceSettings, HohoemaPlaylist playlist, HohoemaViewManager viewMan, HohoemaDialogService dialogService)
        {
            HohoemaApp            = hohoemaApp;
            NavigationService     = ns;
            AppearanceSettings    = appearanceSettings;
            HohoemaPlaylist       = playlist;
            HohoemaViewManager    = viewMan;
            _HohoemaDialogService = dialogService;


            CurrentPageType = HohoemaPageType.RankingCategoryList;
        }
        private async Task <bool> AddReservation(string liveId, string liveTitle)
        {
            var result = await NiconicoSession.ToolkitContext.Timeshift.ReserveTimeshiftAsync(liveId, overwrite : false);

            bool isAdded = false;

            if (result.IsCanOverwrite)
            {
                // 予約数が上限到達、他のタイムシフトを削除すれば予約可能
                // いずれかの予約を削除するよう選択してもらう
                if (await HohoemaDialogService.ShowMessageDialog(
                        "DialogContent_ConfirmTimeshiftReservationiOverwrite".Translate(result.Data.Overwrite.Title, liveTitle),
                        "DialogTitle_ConfirmTimeshiftReservationiOverwrite".Translate(),
                        "Overwrite".Translate(),
                        "Cancel".Translate()
                        ))
                {
                    result = await NiconicoSession.ToolkitContext.Timeshift.ReserveTimeshiftAsync(liveId, overwrite : true);
                }
            }

            if (result.IsSuccess)
            {
                // 予約できてるはず
                // LiveInfoのタイムシフト周りの情報と共に通知
                var notificationService = Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.Default.GetService <Services.NotificationService>();
                notificationService.ShowLiteInAppNotification_Success("InAppNotification_AddedTimeshiftWithTitle".Translate(liveTitle));

                isAdded = true;
            }
            else if (result.IsCanOverwrite)
            {
                // 一つ前のダイアログで明示的的にキャンセルしてるはずなので特に通知を表示しない
            }
            else if (result.IsReservationDeuplicated)
            {
                var notificationService = Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.Default.GetService <Services.NotificationService>();
                notificationService.ShowLiteInAppNotification_Success("InAppNotification_ExistTimeshift".Translate());
            }
            else if (result.IsReservationExpired)
            {
                var notificationService = Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.Default.GetService <Services.NotificationService>();
                notificationService.ShowLiteInAppNotification_Fail("InAppNotification_TimeshiftExpired".Translate());
            }

            return(isAdded);
        }
        private async Task <bool> DeleteReservation(string liveId, string liveTitle)
        {
            if (string.IsNullOrEmpty(liveId))
            {
                throw new ArgumentException(nameof(liveId));
            }

            bool isDeleted = false;

            var token = await NiconicoSession.ToolkitContext.Timeshift.GetReservationTokenAsync();

            if (token == null)
            {
                return(isDeleted);
            }

            if (await HohoemaDialogService.ShowMessageDialog(
                    $"{liveTitle}",
                    "ConfirmDeleteTimeshift".Translate()
                    , "DeleteTimeshift".Translate()
                    , "Cancel".Translate()
                    )
                )
            {
                await NiconicoSession.ToolkitContext.Timeshift.DeleteTimeshiftReservationAsync(liveId, token);

                var deleteAfterReservations = await NiconicoSession.ToolkitContext.Timeshift.GetTimeshiftReservationsDetailAsync();

                isDeleted = !deleteAfterReservations.Data.Items.Any(x => liveId.EndsWith(x.LiveId));
                if (isDeleted)
                {
                    // 削除成功
                    var notificationService = Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.Default.GetService <Services.NotificationService>();
                    notificationService.ShowLiteInAppNotification_Success("InAppNotification_DeletedTimeshift".Translate());
                }
                else
                {
                    // まだ存在するゾイ
                    var notificationService = Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.Default.GetService <Services.NotificationService>();
                    notificationService.ShowLiteInAppNotification_Fail("InAppNotification_FailedDeleteTimeshift".Translate());

                    Debug.Fail("タイムシフト削除に失敗しました: " + liveId);
                }
            }

            return(isDeleted);
        }
        public VideoCacheIntroductionPageViewModel(HohoemaDialogService dialogService, HohoemaApp hohoemaApp)
        {
            _HohoemaDialogService = dialogService;
            _HohoemaApp           = hohoemaApp;

            var hasCacheFolder = Windows.Storage.AccessCache.StorageApplicationPermissions.
                                 FutureAccessList.Entries.Count > 0;

            IsCompleteCacheSettings = new ReactiveProperty <bool>(_HohoemaApp.UserSettings.CacheSettings.IsUserAcceptedCache && hasCacheFolder)
                                      .AddTo(_Disposables);

            CanChangeCacheSettings = new ReactiveProperty <bool>(!IsCompleteCacheSettings.Value)
                                     .AddTo(_Disposables);
            RequireEnablingCacheCommand = CanChangeCacheSettings.ToAsyncReactiveCommand()
                                          .AddTo(_Disposables);

            RequireEnablingCacheCommand.Subscribe(async() =>
            {
                bool isAcceptedCache = _HohoemaApp.UserSettings.CacheSettings.IsUserAcceptedCache;
                if (!isAcceptedCache)
                {
                    isAcceptedCache = await _HohoemaDialogService.ShowAcceptCacheUsaseDialogAsync();
                    if (isAcceptedCache)
                    {
                        _HohoemaApp.UserSettings.CacheSettings.IsEnableCache       = true;
                        _HohoemaApp.UserSettings.CacheSettings.IsUserAcceptedCache = true;

                        (App.Current).Resources["IsCacheEnabled"] = true;
                    }
                }

                if (isAcceptedCache)
                {
                    if (await _HohoemaApp.ChangeUserDataFolder())
                    {
                        IsCompleteCacheSettings.Value = true;
                    }
                }
            })
            .AddTo(_Disposables);
        }
        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();
                }
            });
        }