Пример #1
0
        public MainPageViewModel(INavigationService navigationService)
            : base(navigationService)
        {
            Title = "HOME";

            ImageMarkerInfo.Subscribe(imageInfo =>
            {
                ImageMarkerPath.Value = null;
                ImageMarkerPath.Value = imageInfo.ImagePath;
            }).AddTo(this.Disposable);

            ImageNodeInfo.Subscribe(imageInfo =>
            {
                ImageNodePath.Value = null;
                ImageNodePath.Value = imageInfo.ImagePath;
            }).AddTo(this.Disposable);

            ChangeImageCommand = IsBusy.Inverse().ToAsyncReactiveCommand <string>();
            ChangeImageCommand.Subscribe(async(param) =>
            {
                IsBusy.Value  = true;
                var imagePath = await Common.GetImagePath();
                var imageInfo = new ImageInfo();

                if (param.Equals(MarkerStr))
                {
                    imageInfo.ImagePath   = File.Exists(imagePath) ? imagePath : ImageMarkerFileName;
                    imageInfo.IsAsset     = !File.Exists(imagePath);
                    ImageMarkerInfo.Value = imageInfo;
                }
                else if (param.Equals(NodeStr))
                {
                    imageInfo.ImagePath = File.Exists(imagePath) ? imagePath : ImageNodeFileName;
                    imageInfo.IsAsset   = !File.Exists(imagePath);
                    ImageNodeInfo.Value = imageInfo;
                }
                IsBusy.Value = false;
            }).AddTo(this.Disposable);

            TakePhotoCommand = IsBusy.Inverse().ToAsyncReactiveCommand <string>();
            TakePhotoCommand.Subscribe(async(param) =>
            {
                IsBusy.Value  = true;
                var imagePath = await Common.TakePhoto();
                var imageInfo = new ImageInfo();

                if (param.Equals(MarkerStr))
                {
                    imageInfo.ImagePath   = File.Exists(imagePath) ? imagePath : ImageMarkerFileName;
                    imageInfo.IsAsset     = !File.Exists(imagePath);
                    ImageMarkerInfo.Value = imageInfo;
                }
                else if (param.Equals(NodeStr))
                {
                    imageInfo.ImagePath = File.Exists(imagePath) ? imagePath : ImageNodeFileName;
                    imageInfo.IsAsset   = !File.Exists(imagePath);
                    ImageNodeInfo.Value = imageInfo;
                }
                IsBusy.Value = false;
            }).AddTo(this.Disposable);

            ExecuteARCommand = IsBusy.Inverse().ToAsyncReactiveCommand <string>();
            ExecuteARCommand.Subscribe(async(param) =>
            {
                if (string.IsNullOrEmpty(ApiKey.KudanARApiKey))
                {
                    await UserDialogs.Instance.AlertAsync("KudanARのAPIキー取得に失敗しました", $"{AppInfo.Name}", "OK");
                    await Xamarin.Forms.DependencyService.Get <IKudanARService>().Init();
                    return;
                }

                if (param.Equals("MarkerAR"))
                {
                    IsBusy.Value = true;
                    await Xamarin.Forms.DependencyService.Get <IKudanARService>().StartMarkerARActivityAsync();
                }
                else if (param.Equals("MarkerlessAR_Floor"))
                {
                    IsBusy.Value = true;
                    await Xamarin.Forms.DependencyService.Get <IKudanARService>().StartMarkerlessARActivityAsync();
                }
                else if (param.Equals("MarkerlessAR_Wall"))
                {
                    IsBusy.Value = true;
                    await Xamarin.Forms.DependencyService.Get <IKudanARService>().StartMarkerlessWallActivityAsync();
                }
                // Activity側でビジーフラグ変更
                //IsBusy.Value = false;
            }).AddTo(this.Disposable);

            SettingCommand = IsBusy.Inverse().ToAsyncReactiveCommand();
            SettingCommand.Subscribe(async() =>
            {
                await this.NavigationService.NavigateAsync("SettingPage");
            }).AddTo(this.Disposable);
        }