public ChannelItemViewModel( ChannelGroupViewModel channelGroup, ICategoryManager categoryManager, IPlatformService platformService, Category category, Channel channel) { _categoryManager = categoryManager; _platformService = platformService; _channelGroup = channelGroup; _category = category; _channel = channel; Copy = ReactiveCommand.CreateFromTask(() => _platformService.CopyTextToClipboard(Url)); Open = ReactiveCommand.CreateFromTask(DoOpen, this.WhenAnyValue(x => x.Url, url => Uri .IsWellFormedUriString(url, UriKind.Absolute))); Notify = _channel.Notify; this.ObservableForProperty(x => x.Notify) .Select(property => property.Value) .Do(notify => _channel.Notify = notify) .Select(notify => channel) .SelectMany(_categoryManager.Update) .Subscribe(); Delete = ReactiveCommand.CreateFromTask(DoDelete); Delete.ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => _channelGroup.Channels.Remove(this)); }
public ChannelViewModel( IPlatformService platformService, ICategoriesRepository categoriesRepository, ChannelCategoryViewModel parentViewModel, Channel channel) { Url = channel.Uri; Notify = channel.Notify; Name = new Uri(channel.Uri).Host; CopyLink = new ObservableCommand(() => platformService.CopyTextToClipboard(channel.Uri)); OpenInBrowser = new ObservableCommand(async() => { if (!Uri.IsWellFormedUriString(channel.Uri, UriKind.Absolute)) { return; } var uri = new Uri(channel.Uri); var plainUri = new Uri(string.Format("{0}://{1}", uri.Scheme, uri.Host)); await platformService.LaunchUri(plainUri); }); DeleteSource = new ObservableCommand(async() => { parentViewModel.Items.Remove(this); await categoriesRepository.RemoveChannelAsync( parentViewModel.Category.Value, channel); }); Notify.PropertyChanged += async(sender, args) => { channel.Notify = Notify.Value; await categoriesRepository.UpdateAsync( parentViewModel.Category.Value); }; }
public SearchItemViewModel( ICategoryManager categoryManager, IPlatformService platformService, FeedlyItem feedlyItem) { _categoryManager = categoryManager; _platformService = platformService; _feedlyItem = feedlyItem; Select = new Interaction <IList <string>, int>(); Add = ReactiveCommand.CreateFromTask(DoAdd, Observable .Return(feedlyItem.FeedId?.Substring(5)) .Select(x => Uri.IsWellFormedUriString(x, UriKind.Absolute))); Error = new Interaction <Exception, bool>(); Add.ThrownExceptions .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(error => Error.Handle(error)); Open = ReactiveCommand.CreateFromTask( () => _platformService.LaunchUri(new Uri(Url)), Observable.Return(Uri.IsWellFormedUriString(Url, UriKind.Absolute)) ); Copy = ReactiveCommand.CreateFromTask( () => _platformService.CopyTextToClipboard(Url), Observable.Return(!string.IsNullOrWhiteSpace(Url)) ); }
public ChannelItemViewModel( ICategoryManager categoryManager, IPlatformService platformService, IMessageBus messageBus, Channel channel) { _categoryManager = categoryManager; _platformService = platformService; _messageBus = messageBus; _channel = channel; Notify = _channel.Notify; this.WhenAnyValue(x => x.Notify).Skip(1) .Do(notify => _channel.Notify = notify) .Select(notify => channel) .SelectMany(_categoryManager.Update) .Subscribe(); DeleteRequest = new Interaction <Unit, bool>(); Delete = ReactiveCommand.CreateFromTask(DoDelete); Copy = ReactiveCommand.CreateFromTask( () => _platformService.CopyTextToClipboard(Url) ); Open = ReactiveCommand.CreateFromTask(DoOpen, this.WhenAnyValue(x => x.Url).Select(x => Uri .IsWellFormedUriString(x, UriKind.Absolute))); }
private Inline GenerateImage(HtmlNode node) { if (!_loadImages) { return(new Span()); } var reference = node.Attributes["src"]?.Value; if (!Uri.IsWellFormedUriString(reference, UriKind.Absolute)) { return(new Span()); } var sourceUri = new Uri(reference, UriKind.Absolute); var image = new Image { Source = new BitmapImage(sourceUri) { CreateOptions = BitmapCreateOptions.IgnoreImageCache }, Stretch = Stretch.Uniform, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Center, MaxHeight = 500, Margin = new Thickness(-12, 12, -12, 12), Opacity = 0 }; image.ImageOpened += (sender, e) => { var bmp = (BitmapImage)image.Source; if (bmp.PixelHeight >= bmp.PixelWidth) { image.Margin = new Thickness(0, 12, 0, 12); } image.Fade(1, 300, 100).Start(); }; image.RightTapped += (sender, e) => { var launcher = new MenuFlyoutItem { Text = _translationsService.Resolve("ImageOpenFullSize") }; var copier = new MenuFlyoutItem { Text = _translationsService.Resolve("ImageCopyLink") }; copier.Click += (s, o) => _platformService.CopyTextToClipboard(sourceUri.AbsoluteUri); launcher.Click += (s, o) => _platformService.LaunchUri(sourceUri); new MenuFlyout { Items = { launcher, copier } }.ShowAt(image); }; var inlineUiContainer = new InlineUIContainer { Child = image }; var span = new Span(); span.Inlines.Add(inlineUiContainer); span.Inlines.Add(new LineBreak()); return(span); }
public FeedItemViewModel( Func <FeedItemViewModel, ArticleViewModel> factory, INavigationService navigationService, ICategoryManager categoryManager, IFavoriteManager favoriteManager, IPlatformService platformService, Article article) { Published = article.PublishedDate; Content = article.Content; Image = article.ImageUri; Feed = article.FeedTitle; Title = article.Title; Fave = article.Fave; Read = article.Read; Launch = ReactiveCommand.CreateFromTask( () => platformService.LaunchUri(new Uri(article.Uri)), Observable.Return(Uri.IsWellFormedUriString(article.Uri, UriKind.Absolute)) ); Share = ReactiveCommand.CreateFromTask( () => platformService.Share($"{article.Title} {article.Uri}") ); Open = ReactiveCommand.CreateFromTask( () => navigationService.Navigate <ArticleViewModel>(factory(this)) ); MarkRead = ReactiveCommand.Create(() => { Read = !Read; }); Open.Subscribe(x => Read = true); this.WhenAnyValue(x => x.Read) .Skip(1).Do(x => article.Read = x) .SelectMany(x => categoryManager .UpdateArticleAsync(article) .ToObservable()) .Subscribe(); CopyConfirm = new Interaction <Unit, bool>(); Copy = ReactiveCommand.CreateFromTask(async() => { await platformService.CopyTextToClipboard(article.Uri); await CopyConfirm.Handle(Unit.Default); }); MarkFave = ReactiveCommand.CreateFromTask(async() => { if (Fave) { await favoriteManager.RemoveAsync(article); } else { await favoriteManager.InsertAsync(article); } Fave = article.Fave; }); }
public FeedItemViewModel( INavigationService navigationService, ICategoryManager categoryManager, IFavoriteManager favoriteManager, IPlatformService platformService, ISettingManager settingManager, Article article) { _navigationService = navigationService; _categoryManager = categoryManager; _favoriteManager = favoriteManager; _platformService = platformService; _settingManager = settingManager; _article = article; Share = ReactiveCommand.CreateFromTask( () => _platformService.Share($"{_article.Title} {_article.Uri}")); Open = ReactiveCommand.CreateFromTask( () => _navigationService.NavigateTo(this)); Fave = _article.Fave; Read = _article.Read; Open.Subscribe(x => Read = true); this.ObservableForProperty(x => x.Read) .Select(property => property.Value) .Do(read => _article.Read = read) .Select(read => _article) .Select(_categoryManager.Update) .SelectMany(task => task.ToObservable()) .Subscribe(); Launch = ReactiveCommand.CreateFromTask( () => _platformService.LaunchUri(new Uri(_article.Uri)), Observable.Return(Uri.IsWellFormedUriString(_article.Uri, UriKind.Absolute))); Copy = ReactiveCommand.CreateFromTask( () => _platformService.CopyTextToClipboard(_article.Uri), Observable.Return(!string.IsNullOrWhiteSpace(_article.Uri))); MarkFave = ReactiveCommand.CreateFromTask(DoMarkFave); MarkRead = ReactiveCommand.Create(() => { Read = !Read; }); Copied = new Interaction <Unit, bool>(); Copy.ObserveOn(RxApp.MainThreadScheduler) .SelectMany(Copied.Handle) .Subscribe(); Activator = new ViewModelActivator(); this.WhenActivated(async(CompositeDisposable disposables) => { var settings = await _settingManager.Read(); Images = settings.Images; Font = settings.Font; }); }
public FeedItemViewModel( Func <FeedItemViewModel, FeedItemFullViewModel> factory, INavigationService navigationService, ICategoryManager categoryManager, IFavoriteManager favoriteManager, IPlatformService platformService, Article article) { _navigationService = navigationService; _categoryManager = categoryManager; _favoriteManager = favoriteManager; _platformService = platformService; _article = article; _factory = factory; Share = ReactiveCommand.CreateFromTask( () => _platformService.Share($"{_article.Title} {_article.Uri}")); Open = ReactiveCommand.CreateFromTask( () => _navigationService.NavigateWith <FeedItemFullViewModel>(_factory(this))); Fave = _article.Fave; Read = _article.Read; Open.Subscribe(x => Read = true); this.ObservableForProperty(x => x.Read) .Select(property => property.Value) .Do(read => _article.Read = read) .Select(read => _article) .SelectMany(_categoryManager.Update) .Subscribe(); Launch = ReactiveCommand.CreateFromTask( () => _platformService.LaunchUri(new Uri(_article.Uri)), Observable.Return(Uri.IsWellFormedUriString(_article.Uri, UriKind.Absolute))); Copy = ReactiveCommand.CreateFromTask( () => _platformService.CopyTextToClipboard(_article.Uri), Observable.Return(!string.IsNullOrWhiteSpace(_article.Uri))); CopyConfirm = new Interaction <Unit, bool>(); Copy.ObserveOn(RxApp.MainThreadScheduler) .SelectMany(CopyConfirm.Handle) .Subscribe(); MarkFave = ReactiveCommand.CreateFromTask(DoMarkFave); MarkRead = ReactiveCommand.Create(() => { Read = !Read; }); }
public SearchItemViewModel( IPlatformService platformService, FeedlyItem feedlyItem) { _feedlyItem = feedlyItem; _platformService = platformService; Open = ReactiveCommand.CreateFromTask( () => _platformService.LaunchUri(new Uri(Url)), Observable.Return(Uri.IsWellFormedUriString(Url, UriKind.Absolute))); Copy = ReactiveCommand.CreateFromTask( () => _platformService.CopyTextToClipboard(Url), Observable.Return(!string.IsNullOrWhiteSpace(Url))); Copied = new Interaction <Unit, bool>(); Copy.ObserveOn(RxApp.MainThreadScheduler) .SelectMany(Copied.Handle) .Subscribe(); }
public SearchItemViewModel( ICategoryManager categoryManager, IPlatformService platformService, FeedlyItem feedlyItem) { Description = feedlyItem.Description; Image = feedlyItem.IconUrl; Title = feedlyItem.Title; Url = feedlyItem.Website; Open = ReactiveCommand.CreateFromTask( () => platformService.LaunchUri(new Uri(Url)), Observable.Return(Uri.IsWellFormedUriString(Url, UriKind.Absolute)) ); Copy = ReactiveCommand.CreateFromTask( () => platformService.CopyTextToClipboard(Url), Observable.Return(!string.IsNullOrWhiteSpace(Url)) ); AddSelect = new Interaction <IList <string>, int>(); Add = ReactiveCommand.CreateFromTask(async() => { var response = await categoryManager.GetAllAsync(); var categories = new List <Category>(response); var titles = categories.Select(i => i.Title).ToList(); var index = await AddSelect.Handle(titles); if (index < 0) { return; } var feed = feedlyItem.FeedId?.Substring(5); var source = new Channel { Notify = true, Uri = feed }; var category = categories[index]; category.Channels.Add(source); await categoryManager.UpdateAsync(category); }, Observable.Return(feedlyItem.FeedId?.Substring(5)).Select(x => Uri.IsWellFormedUriString(x, UriKind.Absolute))); }
public ChannelItemViewModel( ICategoryManager categoryManager, IPlatformService platformService, IMessageBus messageBus, Channel channel) { Url = channel.Uri; Notify = channel.Notify; Name = new Uri(channel.Uri).Host; this.WhenAnyValue(x => x.Notify) .Skip(1).Do(x => channel.Notify = x) .SelectMany(x => categoryManager .UpdateChannelAsync(channel) .ToObservable()) .Subscribe(); DeleteRequest = new Interaction <Unit, bool>(); Delete = ReactiveCommand.CreateFromTask(async() => { if (!await DeleteRequest.Handle(Unit.Default)) { return; } messageBus.SendMessage(new ChannelDeleteEvent(channel, this)); }); Copy = ReactiveCommand.CreateFromTask(() => platformService.CopyTextToClipboard(Url)); Open = ReactiveCommand.CreateFromTask(async() => { var url = new Uri(Url); var builder = new UriBuilder(url) { Fragment = string.Empty }; await platformService.LaunchUri(builder.Uri); }, this.WhenAnyValue(x => x.Url).Select(x => Uri .IsWellFormedUriString(x, UriKind.Absolute))); }
public SearchItemViewModel( ICategoriesRepository categoriesRepository, IPlatformService platformService, IDialogService dialogService, FeedlyItem feedlyItem) { Url = feedlyItem.Website; Title = feedlyItem.Title; ImageUri = feedlyItem.IconUrl; Description = feedlyItem.Description; FeedUrl = feedlyItem.FeedId?.Substring(5); CopyLink = new ObservableCommand(() => platformService.CopyTextToClipboard(feedlyItem.Website)); OpenInEdge = new ObservableCommand(async() => { if (Uri.IsWellFormedUriString(feedlyItem.Website, UriKind.Absolute)) { await platformService.LaunchUri(new Uri(feedlyItem.Website)); } }); AddToSources = new ObservableCommand(async() => { if (!Uri.IsWellFormedUriString(FeedUrl.Value, UriKind.Absolute)) { return; } var categories = await categoriesRepository.GetAllAsync(); var response = await dialogService.ShowDialogForSelection(categories); if (response is Category category) { var source = new Channel { Notify = true, Uri = FeedUrl.Value }; await categoriesRepository.InsertChannelAsync(category, source); } }); }
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); } }); }
private async Task DoCopy() { await _platformService.CopyTextToClipboard(_article.Uri); await CopyConfirm.Handle(Unit.Default); }