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 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 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 async Task ShouldTryToAddFeedWhenInputIsCompletelyValid() { var handled = false; var item = new FeedlyItem { FeedId = "feed/http://google.com" }; var categories = new List <Category> { new Category { Title = "Foo" } }; var response = new FeedlyRoot { Results = new List <FeedlyItem> { item } }; _categoryManager.GetAll().Returns(categories); _searchService.Search("q").Returns(response); _searchViewModel.SearchQuery = "q"; _searchViewModel.Added.RegisterHandler(handle => handle.SetOutput(handled = true)); _searchViewModel.RefreshCategories.Execute().Subscribe(); _searchViewModel.Search.Execute().Subscribe(); await Task.Delay(100); _searchViewModel.IsLoading.Should().BeFalse(); _searchViewModel.Feeds.Should().NotBeEmpty(); _searchViewModel.SelectedCategory = _searchViewModel.Categories.First(); _searchViewModel.SelectedFeed = _searchViewModel.Feeds.First(); _searchViewModel.Add.Execute().Subscribe(); await _categoryManager.Received(1).Update(Arg.Any <Category>()); handled.Should().BeTrue(); }