コード例 #1
0
ファイル: ArticleViewModel.cs プロジェクト: wondial/myFeed
        public ArticleViewModel(
            ICategoriesRepository categoriesRepository,
            ITranslationsService translationsService,
            INavigationService navigationService,
            IFavoritesService favoritesService,
            ISettingsService settingsService,
            IPlatformService platformService,
            IDialogService dialogService,
            Article article)
        {
            Title         = article.Title;
            Feed          = article.FeedTitle;
            Content       = article.Content;
            PublishedDate = article.PublishedDate;
            IsFavorite    = article.Fave;
            IsRead        = article.Read;

            Open  = new ObservableCommand(() => navigationService.Navigate <ArticleViewModel>(this));
            Image = new ObservableProperty <string>(async() =>
            {
                var shouldLoadImages = await settingsService.GetAsync <bool>("LoadImages");
                return(shouldLoadImages ? article.ImageUri : null);
            });
            Share = new ObservableCommand(() =>
            {
                var shareMessage = string.Concat(
                    article.Title, Environment.NewLine,
                    article.Uri, Environment.NewLine,
                    "via myFeed for Windows Universal");
                return(platformService.Share(shareMessage));
            });
            CopyLink = new ObservableCommand(async() =>
            {
                await platformService.CopyTextToClipboard(article.Uri);
                await dialogService.ShowDialog(
                    translationsService.Resolve("CopyLinkSuccess"),
                    translationsService.Resolve("SettingsNotification"));
            });
            LaunchUri = new ObservableCommand(async() =>
            {
                if (Uri.IsWellFormedUriString(article.Uri, UriKind.Absolute))
                {
                    await platformService.LaunchUri(new Uri(article.Uri));
                }
            });
            MarkRead = new ObservableCommand(async() =>
            {
                IsRead.Value = article.Read = !IsRead.Value;
                await categoriesRepository.UpdateArticleAsync(article);
            });
            MarkFavorite = new ObservableCommand(async() =>
            {
                IsFavorite.Value = !IsFavorite.Value;
                if (IsFavorite.Value)
                {
                    await favoritesService.Insert(article);
                }
                else
                {
                    await favoritesService.Remove(article);
                }
            });
        }