コード例 #1
0
ファイル: FaveViewModel.cs プロジェクト: spsole/MyFeed
        public FaveViewModel(
            Func <IGrouping <string, Article>, FaveGroupViewModel> factory,
            INavigationService navigationService,
            IFavoriteManager favoriteManager,
            ISettingManager settingManager)
        {
            _navigationService = navigationService;
            _favoriteManager   = favoriteManager;
            _settingManager    = settingManager;
            _factory           = factory;

            ReadFeeds = ReactiveCommand.CreateFromTask(_navigationService.Navigate <FeedViewModel>);
            Items     = new ReactiveList <FaveGroupViewModel> {
                ChangeTrackingEnabled = true
            };

            var month = CultureInfo.CurrentCulture.DateTimeFormat.YearMonthPattern;
            var date  = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;

            OrderByDate  = CreateFilter(x => x.PublishedDate, x => x.ToString(date));
            OrderByMonth = CreateFilter(x => x.PublishedDate, x => x.ToString(month));
            OrderByFeed  = CreateFilter(x => x.FeedTitle, x => x);

            Activator = new ViewModelActivator();
            this.WhenActivated((CompositeDisposable disposables) =>
                               OrderByDate.Execute().Subscribe());
        }
コード例 #2
0
        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;
            });
        }
コード例 #3
0
        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;
            });
        }
コード例 #4
0
 /// <summary>
 /// 构造函数
 ///</summary>
 public FavoriteAppService(
     IRepository <Favorite, Guid> favoriteRepository
     , IFavoriteManager favoriteManager
     , IRepository <WeChatUser, Guid> wechatuserRepository
     , IRepository <Shop, Guid> shopRepository
     )
 {
     _favoriteRepository   = favoriteRepository;
     _favoriteManager      = favoriteManager;
     _wechatuserRepository = wechatuserRepository;
     _shopRepository       = shopRepository;
 }
コード例 #5
0
        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; });
        }
コード例 #6
0
        public FaveViewModel(
            Func <IGrouping <string, Article>, FaveGroupViewModel> factory,
            IFavoriteManager favoriteManager,
            ISettingManager settingManager)
        {
            _favoriteManager = favoriteManager;
            _settingManager  = settingManager;
            _factory         = factory;

            Items = new ReactiveList <FaveGroupViewModel> {
                ChangeTrackingEnabled = true
            };
            var month = CultureInfo.CurrentCulture.DateTimeFormat.YearMonthPattern;
            var date  = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;

            Load         = Filter(x => x.PublishedDate, x => x.ToString(date));
            OrderByDate  = Filter(x => x.PublishedDate, x => x.ToString(date));
            OrderByMonth = Filter(x => x.PublishedDate, x => x.ToString(month));
            OrderByFeed  = Filter(x => x.FeedTitle, x => x);
        }
コード例 #7
0
        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;

            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 <FeedItemFullViewModel>(_factory(this))
                );

            Fave = _article.Fave;
            Read = _article.Read;
            Open.Subscribe(x => Read = true);
            this.WhenAnyValue(x => x.Read).Skip(1)
            .Do(read => _article.Read = read)
            .Select(read => _article)
            .SelectMany(_categoryManager.Update)
            .Subscribe();

            CopyConfirm = new Interaction <Unit, bool>();
            Copy        = ReactiveCommand.CreateFromTask(DoCopy);
            MarkFave    = ReactiveCommand.CreateFromTask(DoMarkFave);
            MarkRead    = ReactiveCommand.Create(() => { Read = !Read; });
        }
コード例 #8
0
ファイル: FaveViewModel.cs プロジェクト: dimabugrov/myFeed
        public FaveViewModel(
            Func <IGrouping <string, Article>, FaveGroupViewModel> factory,
            IFavoriteManager favoriteManager,
            ISettingManager settingManager)
        {
            Items = new ReactiveList <FaveGroupViewModel>();
            var month = CultureInfo.CurrentCulture.DateTimeFormat.YearMonthPattern;
            var date  = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern;

            Load         = LoadAs(x => x.PublishedDate, x => x.ToString(date));
            OrderByMonth = LoadAs(x => x.PublishedDate, x => x.ToString(month));
            OrderByDate  = LoadAs(x => x.PublishedDate, x => x.ToString(date));
            OrderByFeed  = LoadAs(x => x.FeedTitle, x => x);

            ReactiveCommand <Unit, Unit> LoadAs <T>(Func <Article, T> order, Func <T, string> display)
            {
                return(ReactiveCommand.CreateFromTask(async() =>
                {
                    IsLoading = true;
                    var settings = await settingManager.Read();
                    var articles = await favoriteManager.GetAllAsync();
                    var groupings = articles
                                    .OrderByDescending(order)
                                    .GroupBy(x => display(order(x)))
                                    .Select(factory)
                                    .ToList();
                    await Task.Delay(300);
                    Items.Clear();
                    Items.AddRange(groupings);
                    Images = settings.Images;
                    IsEmpty = Items.Count == 0;
                    IsLoading = false;
                },
                                                      this.WhenAnyValue(x => x.IsLoading).Select(x => !x)));
            }
        }
コード例 #9
0
 public FavoritesController(IFavoriteManager favoriteManager, ApplicationDbContext Data)
 {
     this.favoriteManager = favoriteManager;
     this.Data            = Data;
 }