public UploadPhotoPage(UserFirstUpdate user, bool error = false, string message = "") { InitializeComponent(); App.Configuration.InitialAsync(this); NavigationPage.SetHasNavigationBar(this, false); _media = DependencyService.Get <IMedia>(); _devicePermissionServices = DependencyService.Get <IDevicePermissionServices>(); _model = new UploadPhotoViewModel(); _user = user; BindingContext = _model; Initialization(); _trackerPivotService = DependencyService.Get <ITrackerPivotService>(); _helper = DependencyService.Get <IHelper>(); if (error) { _model.SetActivityResource(showError: true, errorMessage: string.IsNullOrWhiteSpace(message.Trim()) ? message.Trim() : _helper.ReturnMessage(message)); } }
public UploadPhotoPage(UserFirstUpdate user, bool error = false, string message = "") { try { InitializeComponent(); _user = user; _trackerPivotService = DependencyService.Get <ITrackerPivotService>(); _media = DependencyService.Get <IMedia>(); _helper = DependencyService.Get <IHelper>(); Init(); if (error) { _model.SetActivityResource(showError: true, errorMessage: string.IsNullOrWhiteSpace(message.Trim()) ? message.Trim() : _helper.ReturnMessage(message)); } } catch (Exception ex) { ClientService.WriteLog(null, ex).GetAwaiter(); } }
private async Task UploadImageAsync(ImageSide side) { if (side == ImageSide.SIDE) { _imageSideName = string.Empty; _model.ImageSide = _model.ImageDefault; } else { _imageFrontName = string.Empty; _model.ImageFront = _model.ImageDefault; } var result = await DisplayActionSheet(TextResources.ChooseOption, TextResources.Cancel, null, new string[] { TextResources.PickFromGallery, TextResources.TakeFromCamera }); if (result != null) { if (result == "Cancel") { return; } if (!await _devicePermissionServices.RequestReadStoragePermission()) { _model.SetActivityResource(showError: true, errorMessage: TextResources.MessagePermissionReadStorageRequired); return; } _media.Refresh(); if (result == TextResources.PickFromGallery) { var mediaFile = await _media.PickPhotoAsync(); if (mediaFile == null) { _model.SetActivityResource(showError: true, errorMessage: _media.Message); return; } _model.SetActivityResource(false, true); var response = await _media.UploadPhotoAsync(mediaFile); if (!response) { _model.SetActivityResource(true, false, showError: true, errorMessage: _media.Message); return; } _model.SetActivityResource(); (side == ImageSide.SIDE ? imageSide : imageFront).Source = ImageSource.FromStream(() => { return(mediaFile.GetStream()); }); if (_media.FileName != null) { if (side == ImageSide.SIDE) { _imageSideName = _model.ImageSide = _media.FileName; } else { _imageFrontName = _model.ImageFront = _media.FileName; } (side == ImageSide.SIDE ? imageSide : imageFront).Source = ImageSource.FromStream(() => { return(mediaFile.GetStream()); }); } else { _model.SetActivityResource(showError: true, errorMessage: _media.Message); } } else if (result == TextResources.TakeFromCamera) { if (!await _devicePermissionServices.RequestCameraPermission()) { _model.SetActivityResource(showError: true, errorMessage: TextResources.MessagePermissionCameraRequired); return; } if (!await _devicePermissionServices.RequestWriteStoragePermission()) { _model.SetActivityResource(showError: true, errorMessage: TextResources.MessagePermissionCameraRequired); return; } var mediaFile = await _media.TakePhotoAsync(); if (mediaFile == null) { _model.SetActivityResource(showError: true, errorMessage: _media.Message); return; } _model.SetActivityResource(false, true); var response = await _media.UploadPhotoAsync(mediaFile); if (!response) { _model.SetActivityResource(true, false, showError: true, errorMessage: _media.Message); return; } _model.SetActivityResource(); if (_media.FileName != null && _media.FileName.Trim().Length > 0) { if (side == ImageSide.SIDE) { _imageSideName = _model.ImageSide = _media.FileName; } else { _imageFrontName = _model.ImageFront = _media.FileName; } (side == ImageSide.SIDE ? imageSide : imageFront).Source = ImageSource.FromStream(() => { return(mediaFile.GetStream()); }); } else { _model.SetActivityResource(showError: true, errorMessage: _media.Message); } } } }