public ExecutePageViewModel(INavigationService navigationService)
            : base(navigationService)
        {
            Title = "Execute Page";

            GetImageCommand.Subscribe(async() =>
            {
                DetectedData.Value = null;

                FaceImageSource.Value = await Media.GetImageToImageSource();
                if (FaceImageSource.Value != null)
                {
                    DetectedData.Value = await Common.ExecuteFaceAPIAsync(APIKey.Value, FaceUriEndPoint, FaceAttributes, FaceImageSource.Value);
                }
            }).AddTo(this.Disposable);

            TakePhotoCommand.Subscribe(async() =>
            {
                DetectedData.Value = null;

                FaceImageSource.Value = await Media.TakePhotoToImageSource();
                if (FaceImageSource.Value != null)
                {
                    DetectedData.Value = await Common.ExecuteFaceAPIAsync(APIKey.Value, FaceUriEndPoint, FaceAttributes, FaceImageSource.Value);
                }
            }).AddTo(this.Disposable);
        }
        public ChildrenViewModel(IUserDialogs userDialogs, IMvxMessenger mvxMessenger,
                                 IParentService parentsService, AppHelper appHelper) : base(userDialogs, mvxMessenger, appHelper)
        {
            _parentsService = parentsService;


            LoadChildrenCommand = ReactiveCommand.CreateFromObservable <Unit, IList <SonEntity> >((param) => _parentsService.GetChildren());

            LoadChildrenCommand.Subscribe((children) =>
            {
                Debug.WriteLine("Children Count " + children?.Count);
                Children  = children;
                DataFound = children?.Count > 0;
            });

            LoadChildrenCommand.IsExecuting.Subscribe((IsLoading) => IsBusy = IsLoading);

            LoadChildrenCommand.ThrownExceptions.Subscribe(HandleExceptions);


            TakePhotoCommand = ReactiveCommand.CreateFromObservable <string, ImageEntity>((SonIdentity) =>
            {
                return(_appHelper.PickPhotoStream()
                       .Select(MediaFile => MediaFile.GetStream())
                       .Do((_) => _userDialogs.ShowLoading(AppResources.Profile_Updating_Profile_Image))
                       .SelectMany((FileStream) => _parentsService.UploadSonProfileImage(SonIdentity, FileStream))
                       .Do((Image) =>
                {
                    var SonEntity = Children.FirstOrDefault((Son) => Son.Identity.Equals(SonIdentity));
                    if (SonEntity != null)
                    {
                        SonEntity.Identity = Image.Identity;
                    }
                })
                       .Do((_) => _userDialogs.HideLoading()));
            });

            TakePhotoCommand.Subscribe((image) =>
            {
                _userDialogs.ShowSuccess(AppResources.Profile_Updating_Profile_Image_Success);
            });

            TakePhotoCommand.ThrownExceptions.Subscribe(HandleExceptions);
        }
        public ProfileViewModel(IParentService parentService, IUserDialogs userDialogs,
                                IMvxMessenger mvxMessenger, AppHelper appHelper) : base(userDialogs, mvxMessenger, appHelper)
        {
            _parentService = parentService;

            SaveChangesCommand = ReactiveCommand.CreateFromObservable <Unit, ParentEntity>((param) =>
            {
                return(NewProfileImage != null ?
                       _parentService.UploadProfileImage(NewProfileImage.GetStream())
                       .SelectMany((_) => _parentService.Update(SelfParent.FirstName, SelfParent.LastName, SelfParent.Birthdate, SelfParent.Email, string.Concat(SelfParent.PhonePrefix, SelfParent.PhoneNumber))) :

                       _parentService.Update(SelfParent.FirstName, SelfParent.LastName, SelfParent.Birthdate, SelfParent.Email, string.Concat(SelfParent.PhonePrefix, SelfParent.PhoneNumber)));
            });


            SaveChangesCommand.Subscribe(AccountUpdatedHandler);

            SaveChangesCommand.IsExecuting.Subscribe((IsLoading) => HandleIsExecuting(IsLoading, AppResources.Profile_Save_Changes));

            SaveChangesCommand.ThrownExceptions.Subscribe(HandleExceptions);

            RefreshCommand = ReactiveCommand.CreateFromObservable <Unit, ParentEntity>((param) => _parentService.GetProfileInformation());

            RefreshCommand.Subscribe((ParentEntity) => {
                SelfParent.HydrateWith(ParentEntity);
                ResetCommonProps();
                IsDirtyMonitoring = true;
            });

            RefreshCommand.IsExecuting.Subscribe((IsLoading) => HandleIsExecuting(IsLoading, AppResources.Profile_Loading_Data));

            RefreshCommand.ThrownExceptions.Subscribe(HandleExceptions);

            DeleteAccountCommand = ReactiveCommand
                                   .CreateFromObservable <Unit, string>((param) =>
            {
                return(Observable.FromAsync <bool>((_) => _userDialogs.ConfirmAsync(new ConfirmConfig()
                {
                    Title = AppResources.Profile_Confirm_Account_Deleting
                })).Where((confirmed) => confirmed).Do((_) => HandleIsExecuting(true, AppResources.Profile_Account_Deleting))
                       .SelectMany((_) => _parentService.DeleteAccount())
                       .Do((_) => HandleIsExecuting(false, AppResources.Profile_Account_Deleting)));
            });


            DeleteAccountCommand.Subscribe((_) =>
            {
                Bullytect.Core.Config.Settings.AccessToken = null;
                ShowViewModel <AuthenticationViewModel>(new AuthenticationViewModel.AuthenticationParameter()
                {
                    ReasonForAuthentication = AuthenticationViewModel.ACCOUNT_DELETED
                });
            });


            DeleteAccountCommand.ThrownExceptions.Subscribe(HandleExceptions);


            TakePhotoCommand = ReactiveCommand.CreateFromObservable <Unit, MediaFile>((_) => appHelper.PickPhotoStream());


            TakePhotoCommand.Subscribe((ImageStream) => {
                _userDialogs.HideLoading();
                NewProfileImage = ImageStream;
                OnNewSelectedImage(ImageStream);
            });

            TakePhotoCommand.ThrownExceptions.Subscribe(HandleExceptions);
        }
示例#4
0
        public EditSonViewModel(IUserDialogs userDialogs, IMvxMessenger mvxMessenger, IParentService parentService,
                                ISocialMediaService socialMediaService, AppHelper appHelper, IOAuthService oauthService, ISchoolService schoolService) : base(userDialogs, mvxMessenger, appHelper)
        {
            _parentService      = parentService;
            _socialMediaService = socialMediaService;
            _schoolService      = schoolService;
            _oauthService       = oauthService;


            RefreshCommand = ReactiveCommand.CreateFromObservable <Unit, PageModel>((param) => !PageLoaded ? LoadPageModel(): Observable.Empty <PageModel>());

            RefreshCommand.Subscribe(OnPageModelLoaded);

            RefreshCommand.IsExecuting.Subscribe((isExecuting) => HandleIsExecuting(isExecuting, AppResources.Common_Loading));

            RefreshCommand.ThrownExceptions.Subscribe(HandleExceptions);

            ForceRefreshCommand = ReactiveCommand.CreateFromObservable <Unit, PageModel>((param) => LoadPageModel());

            ForceRefreshCommand.Subscribe(OnPageModelLoaded);

            ForceRefreshCommand.IsExecuting.Subscribe((isExecuting) => HandleIsExecuting(isExecuting, AppResources.Common_Loading));

            ForceRefreshCommand.ThrownExceptions.Subscribe(HandleExceptions);

            TakePhotoCommand = ReactiveCommand.CreateFromObservable <Unit, MediaFile>((param) => _appHelper.PickPhotoStream());

            TakePhotoCommand.Subscribe((ImageFile) =>
            {
                _userDialogs.HideLoading();
                NewProfileImage = ImageFile;
                OnNewSelectedImage(ImageFile);
            });

            TakePhotoCommand.ThrownExceptions.Subscribe(HandleExceptions);


            SaveChangesCommand = ReactiveCommand
                                 .CreateFromObservable <Unit, bool>((param) =>
            {
                return((CurrentSon.Identity == null ?
                        _parentService.AddSonToSelfParent(CurrentSon.FirstName, CurrentSon.LastName, CurrentSon.Birthdate, CurrentSon.School.Identity) :
                        _parentService.UpdateSonInformation(CurrentSon.Identity, CurrentSon.FirstName, CurrentSon.LastName, CurrentSon.Birthdate, CurrentSon.School.Identity))
                       .Do((SonEntity) => CurrentSon.HydrateWith(SonEntity))
                       .SelectMany((SonEntity) => _socialMediaService
                                   .SaveAllSocialMedia(
                                       CurrentSon.Identity,
                                       CurrentSocialMedia.Select(s => { s.Son = CurrentSon.Identity; return s; }).ToList()
                                       ).Catch <IList <SocialMediaEntity>, NoSocialMediaFoundException>(ex => Observable.Return(new List <SocialMediaEntity>()))
                                   )
                       .Do((SocialMediaEntities) => CurrentSocialMedia.ReplaceRange(SocialMediaEntities))

                       .SelectMany((_) =>
                {
                    return NewProfileImage != null ?
                    _parentService.UploadSonProfileImage(CurrentSon.Identity, NewProfileImage.GetStream()) :
                    Observable.Empty <ImageEntity>();
                })
                       .Select((_) => true)
                       .DefaultIfEmpty(true));
            });

            SaveChangesCommand.Subscribe((_) =>
            {
                NewProfileImage = null;
                OnSonUpdated(CurrentSon);
                _userDialogs.ShowSuccess(AppResources.EditSon_Saved_Changes_Successfully);
                IsDirtyMonitoring = true;
            });

            SaveChangesCommand.IsExecuting.Subscribe((isLoading) => HandleIsExecuting(isLoading, AppResources.EditSon_Saving_Changes));

            SaveChangesCommand.ThrownExceptions.Subscribe(HandleExceptions);

            SaveSchoolCommand = ReactiveCommand.CreateFromObservable <Unit, SchoolEntity>((param) => _schoolService.CreateSchool(NewSchool.Name, NewSchool.Residence, NewSchool.Latitude, NewSchool.Longitude, NewSchool.Province, NewSchool.Tfno, NewSchool.Email));

            SaveSchoolCommand.Subscribe((SchoolAdded) =>
            {
                NewSchool = new SchoolEntity();
                CurrentSon.School.HydrateWith(SchoolAdded);
                _appHelper.ShowAlert(AppResources.EditSon_School_Saved);
                OnSchoolAdded(SchoolAdded);
            });


            SaveSchoolCommand.IsExecuting.Subscribe((isLoading) => HandleIsExecuting(isLoading, AppResources.EditSon_Saving_School));

            SaveSchoolCommand.ThrownExceptions.Subscribe(HandleExceptions);


            FindSchoolsCommand = ReactiveCommand.CreateFromObservable <string, IList <SchoolEntity> >(
                (name) => _schoolService.FindSchools(name));

            FindSchoolsCommand.IsExecuting.Subscribe((isLoading) => HandleIsExecuting(isLoading, AppResources.EditSon_Find_School));

            FindSchoolsCommand.ThrownExceptions.Subscribe(HandleExceptions);

            FindSchoolsCommand.Subscribe((SchoolsFounded) => {
                SearchPerformed = true;
                Schools.ReplaceRange(SchoolsFounded);
            });
        }
示例#5
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);
        }