Example #1
0
        public DetailViewModel(DetailModel _model)
        {
            Model = _model.AddTo(DisposeCollection);

            InputTitle   = Model.ShownTask.Select(t => t?.TitleString ?? "").ToReactiveProperty("", ReactivePropertyMode.DistinctUntilChanged).AddTo(DisposeCollection);
            InputExplain = Model.ShownTask.Select(t => t?.ExplainString ?? "").ToReactiveProperty("", ReactivePropertyMode.DistinctUntilChanged).AddTo(DisposeCollection);
            InputStatus  = Model.ShownTask.Select(t => t?.Status ?? Status.Ready).ToReactiveProperty(Status.Ready, ReactivePropertyMode.DistinctUntilChanged).AddTo(DisposeCollection);

            InputTitle.Where(s => (Model.ShownTask.Value?.Title ?? null) != Domain.Title.Create(s)).Subscribe(s => Model.Save(Domain.Title.Create(s))).AddTo(DisposeCollection);
            InputExplain.Where(s => (Model.ShownTask.Value?.Explain ?? null) != Domain.Explain.Create(s)).Subscribe(s => Model.Save(Domain.Explain.Create(s))).AddTo(DisposeCollection);
            InputStatus.Where(s => (Model.ShownTask.Value?.Status ?? null) != s).Subscribe(s => Model.Save(s)).AddTo(DisposeCollection);
        }
        public PlanningDetailPageViewModel(INavigationService navigationService, IShowPlanningDetail showDetail, IOpenWebPageService openWeb, IAnalyticsService analyticsService)
        {
            _showDetail        = showDetail;
            _navigationService = navigationService;
            _webPageService    = openWeb;

            IsFavorited = showDetail.IsFavorited;

            ToggleFavorited = new AsyncReactiveCommand();
            ToggleFavorited.Subscribe(async(_) =>
            {
                var next = !IsFavorited.Value;
                await _showDetail.TogglePlanningFavoritedState(!IsFavorited.Value);
                if (next)
                {
                    switch (DetailModel.Value.PlanningType)
                    {
                    case PlanningTypeEnum.EXHIBITION:
                        await analyticsService.SendFavoritedExhibition(DetailModel.Value.Id, DetailModel.Value.Title);
                        break;

                    case PlanningTypeEnum.STAGE:
                        await analyticsService.SendFavoritedStage(DetailModel.Value.Id, DetailModel.Value.Title);
                        break;

                    case PlanningTypeEnum.STALL:
                        await analyticsService.SendFavoritedStall(DetailModel.Value.Id, DetailModel.Value.Title);
                        break;
                    }
                }
            }).AddTo(this.Disposable);

            IconSource = IsFavorited
                         .Select((isFav) => $@"ion_ios_heart{(isFav ? "" : "_outline")}")
                         .ToReadOnlyReactiveProperty($@"ion_ios_heart{(IsFavorited.Value ? "" : "_outline")}")
                         .AddTo(this.Disposable);

            OpenMapCommand = new AsyncReactiveCommand();
            OpenMapCommand.Subscribe(async(_) =>
            {
                await _navigationService.NavigateAsync("NavigationPage/FestaMapRootPage",
                                                       FestaMapRootPageViewModel.GetNavigationParameter(DetailModel.Value.Id, DetailModel.Value.PlanningType), true);
            }).AddTo(this.Disposable);

            OpenUriCommand = new DelegateCommand <string>((uri) =>
            {
                _webPageService.OpenUri(uri);
            });

            DetailModel.AddTo(this.Disposable);
        }