Esempio n. 1
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();
                }
            });
        }