public ItemDetailViewModel(PictureService _picService, PicItem item = null) { Item = item; picService = _picService; StItems = new List <ST>(); FolioItems = new List <Folio>(); St_names = new ObservableRangeCollection <string>(); result_insert = PostResult; //stDataService = _stDataService; LoadItemsCommand = new Command(async() => await ExecuteLoadItems()); }
public async Task <Image> TakePicture() { if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsPickPhotoSupported) { //DisplayAlert("No Camera", ":( No camera avaialble.", "OK"); } UserDialogs.Instance.ShowLoading("Obteniendo posicion", MaskType.Black); var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 25; var position = new Plugin.Geolocator.Abstractions.Position(); try { position = await locator.GetPositionAsync(timeoutMilliseconds : 10000); if (position == null) { } UserDialogs.Instance.HideLoading(); } catch (Exception ex) { UserDialogs.Instance.HideLoading(); } var fileName = System.DateTime.Now.Ticks.ToString(); var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { Directory = "Sample", Name = fileName, PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium, CompressionQuality = 80 }); if (file == null) { return(new Image()); } //DisplayAlert("File Location", file.Path, "OK"); Console.WriteLine(file.Path); var image = new Image { Aspect = Aspect.AspectFit }; image.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return(stream); }); var stream_ = file.GetStream(); byte[] bytes = new byte[stream_.Length]; await stream_.ReadAsync(bytes, 0, (int)stream_.Length); var base64 = Convert.ToBase64String(bytes); Item = new PicItem { FileName = base64, Sent = false, CreatedOn = DateTime.UtcNow.ToLocalTime().ToString("s") + "Z", Latitude = position.Latitude, Longitude = position.Longitude, Color = "#FFFFFF" }; Item.ST_string = ""; Item.Folio_string = ""; await picService.AddItemAsync(Item); Items.Add(Item); //ESTO LO COMENTE RECIÉN MessagingCenter.Send(this, "AddItem", Item); //await Navigation.PopToRootAsync(); return(image); }
public async Task RemoveItemCommand(PicItem item) { await picService.DeleteItemAsync(item); return; }
/* Unmerged change from project 'test2' * Before: * public bool SaveItem(string st, string folio, string note, PicItem item) * After: * public bool SaveItemAsync(string st, string folio, string note, PicItem item) */ public async Task <bool> SaveItemAsync(string st, string folio, string note, PicItem item) { await picService.UpdateItemAsync(st, folio, note, item); return(true); }