コード例 #1
0
ファイル: HomeViewModel.cs プロジェクト: y105109/NNReader
        public BookmarkInfoViewModel(IOrderBuilder orderBuilder, IBookmarkInfo bookmarkInfo)
        {
            this.LoadedCommand = new AsyncReactiveCommand()
                                 .WithSubscribe(async() =>
            {
                await orderBuilder.From("LoadingBookmarkSummary")
                .With("Id", bookmarkInfo.Id)
                .DispatchAsync();
            })
                                 .AddTo(this.CompositeDisposable);

            this.Title = bookmarkInfo.ObserveProperty(x => x.Title)
                         .ObserveOnUIDispatcher()
                         .ToReadOnlyReactivePropertySlim()
                         .AddTo(this.CompositeDisposable);

            this.Writer = bookmarkInfo.ObserveProperty(x => x.Writer)
                          .ObserveOnUIDispatcher()
                          .ToReadOnlyReactivePropertySlim()
                          .AddTo(this.CompositeDisposable);

            this.ChapterCount = bookmarkInfo.Chapters.ObserveProperty(x => x.Count)
                                .ObserveOnUIDispatcher()
                                .ToReadOnlyReactivePropertySlim()
                                .AddTo(this.CompositeDisposable);

            this.BookmarkedDate = bookmarkInfo.ObserveProperty(x => x.BookmarkedDate)
                                  .Select(x => $"{x}")
                                  .ObserveOnUIDispatcher()
                                  .ToReadOnlyReactivePropertySlim()
                                  .AddTo(this.CompositeDisposable);

            this.Updating = bookmarkInfo.ObserveProperty(x => x.Status)
                            .Select(x => x == BookmarkInfoStatus.SummaryDownloading || x == BookmarkInfoStatus.ChapterDownloading || x == BookmarkInfoStatus.SummaryLoading || x == BookmarkInfoStatus.ChapterLoading)
                            .ObserveOnUIDispatcher()
                            .ToReadOnlyReactivePropertySlim()
                            .AddTo(this.CompositeDisposable);

            this.UpdateCommand = new AsyncReactiveCommand()
                                 .WithSubscribe(async() =>
            {
                await orderBuilder.From("UpdatingBookmarkChapter")
                .With("Id", bookmarkInfo.Id)
                .DispatchAsync();
            })
                                 .AddTo(this.CompositeDisposable);

            this.ReadCommand = new AsyncReactiveCommand()
                               .WithSubscribe(async() =>
            {
                Transitioner.MoveNextCommand.Execute(null, null);
                await orderBuilder.From("RequestingBookmark")
                .With("Id", bookmarkInfo.Id)
                .DispatchAsync();
            })
                               .AddTo(this.CompositeDisposable);
        }
コード例 #2
0
        public ReadingRoomViewModel(IOrderBuilder orderBuilder, ILoadableBookmarkService loadableBookmarkService, IBookmarkInfo bookmarkInfo)
        {
            this.Loading = bookmarkInfo.ObserveProperty(x => x.Status)
                           .Select(x => x == BookmarkInfoStatus.SummaryLoading || x == BookmarkInfoStatus.SummaryDownloading || x == BookmarkInfoStatus.ChapterLoading || x == BookmarkInfoStatus.ChapterDownloading)
                           .ObserveOnUIDispatcher()
                           .ToReadOnlyReactivePropertySlim()
                           .AddTo(this.CompositeDisposable);

            this.BackCommand = new AsyncReactiveCommand()
                               .WithSubscribe(async() =>
            {
                Transitioner.MovePreviousCommand.Execute(null, null);
                await orderBuilder.From("RequestingChapter")
                .With("Id", Guid.Empty)
                .Next("RequestingBookmark")
                .With("Id", Guid.Empty)
                .DispatchAsync();
            })
                               .AddTo(this.CompositeDisposable);

            this.Chapters = bookmarkInfo.Chapters.ToReadOnlyReactiveCollection(x => new ChapterViewModel(orderBuilder, loadableBookmarkService, x), UIDispatcherScheduler.Default)
                            .AddTo(this.CompositeDisposable);

            this.SelectionChangedCommand = new AsyncReactiveCommand <SelectionChangedEventArgs>()
                                           .WithSubscribe(async e =>
            {
                var selectred = e.AddedItems.Cast <ChapterViewModel>().FirstOrDefault();
                await orderBuilder.From("RequestingChapter")
                .With("Id", selectred?.Id ?? Guid.Empty)
                .DispatchAsync();
            })
                                           .AddTo(this.CompositeDisposable);

            this.IsSelected = Observable.FromEventPattern <BookmarkRequestEventArgs>(h => loadableBookmarkService.BookmarkRequested += h, h => loadableBookmarkService.BookmarkRequested -= h)
                              .Select(x => x.EventArgs.Bookmark != null && x.EventArgs.Bookmark.Id == bookmarkInfo.Id)
                              .ObserveOnUIDispatcher()
                              .ToReadOnlyReactivePropertySlim()
                              .AddTo(this.CompositeDisposable);

            this.ChapterTitle = Observable.FromEventPattern <ChapterRequestEventArgs>(h => loadableBookmarkService.ChapterRequested += h, h => loadableBookmarkService.ChapterRequested -= h)
                                .Select(x => x.EventArgs.Chapter?.Title ?? "")
                                .ObserveOnUIDispatcher()
                                .ToReadOnlyReactivePropertySlim()
                                .AddTo(this.CompositeDisposable);

            //this.ChapterContent = new ReactivePropertySlim<string>("").AddTo(this.CompositeDisposable);

            this.ChapterContent = Observable.FromEventPattern <ChapterRequestEventArgs>(h => loadableBookmarkService.ChapterRequested += h, h => loadableBookmarkService.ChapterRequested -= h)
                                  .SelectMany(x =>
            {
                var chapter = x.EventArgs.Chapter;
                if (chapter == null || bookmarkInfo.Chapters.All(c => c.Id != chapter.Id))
                {
                    return(Observable.Return(""));
                }
                return(chapter.ObserveProperty(c => c.Content));
            })
                                  .ObserveOnUIDispatcher()
                                  //.Subscribe(x => this.ChapterContent.Value = x)
                                  .ToReadOnlyReactivePropertySlim()
                                  .AddTo(this.CompositeDisposable);

            this.IsSelected.Where(x => x).Take(1).SelectMany(x =>
            {
                return(orderBuilder.From("LoadingBookmarkChapter")
                       .With("Id", bookmarkInfo.Id)
                       .DispatchAsync()
                       .ToObservable());
            })
            .Subscribe()
            .AddTo(this.CompositeDisposable);
        }
コード例 #3
0
 public BookmarkRequestEventArgs(IBookmarkInfo bookmarkInfo)
 => this.Bookmark = bookmarkInfo;