Ejemplo n.º 1
0
        public HomeViewModel(IAnilibriaApiService anilibriaApiService)
        {
            m_AnilibriaApiService = anilibriaApiService ?? throw new ArgumentNullException(nameof(anilibriaApiService));

            var version = Package.Current.Id.Version;

            Version = $"{version.Major}.{version.Minor}.{version.Build}";

            m_MenuItems = new List <SplitViewItem> {
                new SplitViewItem {
                    Name          = "Каталог релизов",
                    Page          = ReleasesPage,
                    IconUri       = new Uri("ms-appx:///Assets/Icons/hambergermenu.svg"),
                    IsVisible     = StubMenuIsVisible,
                    IsReleasePage = true
                },
                new SplitViewItem {
                    Name           = "Видеоплеер",
                    Page           = PlayerPage,
                    IconUri        = new Uri("ms-appx:///Assets/Icons/videoplayer.svg"),
                    IsVisible      = StubMenuIsVisible,
                    IsOnlinePlayer = true
                },
                new SplitViewItem {
                    Name          = "Youtube",
                    Page          = YoutubePage,
                    IconUri       = new Uri("ms-appx:///Assets/Icons/youtube.svg"),
                    IsVisible     = StubMenuIsVisible,
                    IsYoutubePage = true
                },
                new SplitViewItem {
                    Name         = "Поддержать проект",
                    Page         = DonatePage,
                    IconUri      = new Uri("ms-appx:///Assets/Icons/donate.svg"),
                    IsVisible    = StubMenuIsVisible,
                    IsDonatePage = true
                },
                new SplitViewItem {
                    Name         = "Войти",
                    Page         = AuthorizePage,
                    IconUri      = new Uri("ms-appx:///Assets/Icons/user.svg"),
                    IsVisible    = AuthorizeOptionIsVisible,
                    IsSigninPage = true
                }

                /*,
                 * new SplitViewItem {
                 *      Name = "Менеджер загрузок",
                 *      Page = "Torrents",
                 *      Icon = "\xE896"
                 * }*/
            };
            RefreshOptions();

            CreateCommands();

            ObserverEvents.SubscribeOnEvent("showMessage", ShowMessage);

            LaunchParameters.AddSubscriber(ChangeLaunchParameter);
        }
Ejemplo n.º 2
0
        private async void Signin()
        {
            ErrorMessage = "";
            try {
                var(result, message) = await m_AnilibriaApiService.Authentification(Email, Password, TwoFACode);

                if (result)
                {
                    ChangePage("Releases", null);
                    RefreshOptions?.Invoke();
                    await ChangeUserSession();

                    if (m_AnilibriaApiService.IsAuthorized())
                    {
                        ObserverEvents.FireEvent(
                            "showMessage",
                            new MessageModel {
                            Header  = "Авторизация",
                            Message = "Вы успешно вошли в аккаунт"
                        }
                            );
                    }
                }
                else
                {
                    ErrorMessage = message;
                }
            } catch {
                ErrorMessage = "Ошибка авторизации";
            }
        }
        private async void SaveVideo(string identifier)
        {
            var id          = GetIdentifierFromString(identifier);
            var quality     = identifier.Replace(id, "");
            var enumQuality = quality == "HD" ? VideoQuality.HD : VideoQuality.SD;
            var videoId     = Convert.ToInt32(id);
            var release     = m_DownloadService.GetDownloadRelease(SelectedDownload.ReleaseId);
            var video       = release.Videos.FirstOrDefault(a => a.Id == videoId && a.Quality == enumQuality);

            var savePicker = new FileSavePicker();

            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            savePicker.FileTypeChoices.Add("Video file", new List <string> ()
            {
                ".mp4"
            });
            savePicker.SuggestedFileName = "Video";

            var file = await savePicker.PickSaveFileAsync();

            var failed = false;

            if (file != null)
            {
                CachedFileManager.DeferUpdates(file);

                try {
                    var storageFile = await StorageFile.GetFileFromPathAsync(video.DownloadedPath);

                    using (var inputStream = await storageFile.OpenStreamForReadAsync())
                        using (var outputStream = await file.OpenStreamForWriteAsync()) {
                            await inputStream.CopyToAsync(outputStream);
                        }
                } catch {
                    failed = true;
                }

                var status = await CachedFileManager.CompleteUpdatesAsync(file);

                if (status != FileUpdateStatus.Complete)
                {
                    failed = true;
                }

                if (failed)
                {
                    ObserverEvents.FireEvent(
                        "showMessage",
                        new MessageModel {
                        Header  = $"Копирование серии",
                        Message = $"Не удалось скопировать серию"
                    }
                        );
                }
            }
        }
Ejemplo n.º 4
0
        public DownloadManagerViewModel(IDownloadService downloadService, IDataContext dataContext)
        {
            m_DownloadService = downloadService ?? throw new ArgumentNullException(nameof(downloadService));
            m_DownloadService.SetDownloadProgress(ProgressHandler);
            m_DownloadService.SetDownloadFinished(FinishHandler);
            m_ReleaseCollection = dataContext.GetCollection <ReleaseEntity> ();
            CreateCommands();

            m_SelectedSection = m_Sections.First();
            ObserverEvents.SubscribeOnEvent("synchronizedReleases", RefreshAfterSynchronize);
        }
        public DownloadManagerViewModel(IDownloadService downloadService, IDataContext dataContext, IAnalyticsService analyticsService, IReleasesService releasesService)
        {
            m_DownloadService  = downloadService ?? throw new ArgumentNullException(nameof(downloadService));
            m_AnalyticsService = analyticsService ?? throw new ArgumentNullException(nameof(analyticsService));
            m_ReleasesService  = releasesService ?? throw new ArgumentNullException(nameof(releasesService));
            m_DownloadService.SetDownloadProgress(ProgressHandler);
            m_DownloadService.SetDownloadFinished(FinishHandler);
            CreateCommands();
            RestoreSettings();

            m_SelectedSection = m_Sections.First();
            m_PauseColor      = WhiteColor;
            m_PlayColor       = LightGrayColor;
            ObserverEvents.SubscribeOnEvent("synchronizedReleases", RefreshAfterSynchronize);
        }
        private void FinishHandler(DownloadReleaseEntity downloadRelease, int videoId, long downloaded, VideoQuality videoQuality)
        {
            var release = m_Downloads.FirstOrDefault(a => a.ReleaseId == downloadRelease.ReleaseId);

            if (release == null)
            {
                return;
            }

            release.CurrentDownloadVideo = downloadRelease.Videos.FirstOrDefault(a => a.IsProgress)?.Id ?? 0;
            release.DownloadProgress     = downloadRelease.Videos.Count(a => a.IsProgress);
            release.DownloadedHdVideos   = downloadRelease.Videos.Count(a => a.IsDownloaded && a.Quality == VideoQuality.HD);
            release.AllDownloadedSize    = downloadRelease.Videos.Any() ? FileHelper.GetFileSize((long)downloadRelease.Videos.Sum(a => (long)a.DownloadedSize)) : FileHelper.GetFileSize(0);
            release.DownloadedSdVideos   = downloadRelease.Videos.Count(a => a.IsDownloaded && a.Quality == VideoQuality.SD);
            release.DownloadSpeed        = "";
            release.NotDownloadedVideos  = downloadRelease.Videos.Count(a => !a.IsDownloaded && !a.IsProgress);
            release.Active = downloadRelease.Active && downloadRelease.Videos.Any(a => a.IsProgress);


            var displayQuality = GetDisplayQuality(videoQuality);
            var video          = release.Videos.Where(a => a.Order == videoId && a.Quality == displayQuality).FirstOrDefault();

            if (video == null)
            {
                return;
            }

            video.IsProgress     = false;
            video.DownloadedSize = FileHelper.GetFileSize(downloaded);
            video.IsDownloaded   = true;

            if (IsFullNotification)
            {
                ObserverEvents.FireEvent(
                    "showMessage",
                    new MessageModel {
                    Header  = $"Скачана {video.Name} {video.Quality}",
                    Message = $"В релизе " + release.Title
                }
                    );
            }
        }