/// ------------------------------------------------------------------------------------------------ /// Name OnSaveClicked /// /// <summary> Save image and Dismisses the popup on clicking Save button. /// </summary> /// <param name="sender"> </param> /// <param name="e"> event arguments</param> /// ------------------------------------------------------------------------------------------------ private async void OnSaveClicked(object sender, EventArgs e) { try { if (_isExecute) { _isExecute = false; if (Txt_ImageDescription.Text != null && (Txt_ImageName.Text != null)) { Btn_Save.TextColor = Styles.MainAccent; Btn_Save.IsEnabled = true; IsSaveEnabled = true; } if (IsSaveEnabled) { OnSiteDocument doc; FileSystemArgs write; doc = new OnSiteDocument() { Description = Txt_ImageDescription.Text, Extension = ".png", Id = Guid.NewGuid().ToString(), MimeType = "application/png", Name = Txt_ImageName.Text, Status = SyncStatus.Changed, }; write = await FileSystem.WriteAsync(ImageBytes, doc.FileName); if (write.Error == null) { AppData.PropertyModel.AddDocument(doc); //saving doc to file for preserving it when loggedout PropertySummary.RefreshCount(); DocumentAdded?.Invoke(doc); AppContext.AppContext.InspectionCell.RefreshList(); } else { await SplitView.DisplayAlert("Saving Failed", write.Error.Message, "OK", null); } SplitView.CenterPopupContent?.DismisPopup(); } await Task.Run(() => { Task.Delay(2000).Wait(); _isExecute = true; }); } } catch (Exception ex) { LogTracking.LogTrace(ex.ToString()); } }
/// ------------------------------------------------------------------------------------------------ /// Name OnSaveClicked /// /// <summary> Save audio and Dismisses the popup on clicking Save button. /// </summary> /// <param name="sender"> </param> /// <param name="e"> event arguments</param> /// ------------------------------------------------------------------------------------------------ private async void OnSaveClicked(object sender, EventArgs e) { try { if (!_isRecording) { if (_isExecute) { _isExecute = false; if (Txt_AudioDescription.Text != null && (Txt_AudioName.Text != null)) { Btn_Save.TextColor = Styles.MainAccent; Btn_Save.IsEnabled = true; IsSaveEnabled = true; } if (IsSaveEnabled) { var audio = await DependencyService.Get <IRecorder>().AudioByte(); if (audio != null) { var doc = new OnSiteDocument() { Description = Txt_AudioDescription.Text, Extension = (Device.OS == TargetPlatform.iOS) ? ".wav" : ".mp3", Id = Guid.NewGuid().ToString(), MimeType = (Device.OS == TargetPlatform.iOS) ? "application/wav" : "application/mp3", Name = Txt_AudioName.Text, Status = SyncStatus.Changed, }; var write = await FileSystem.WriteAsync(audio, doc.FileName); if (write.Error == null) { AppData.PropertyModel.AddDocument(doc); //saving doc to file for preserving it when loggedout PropertySummary.RefreshCount(); AddNewImageView.DocumentAdded?.Invoke(doc); AppContext.AppContext.InspectionCell.RefreshList(); } else { await SplitView.DisplayAlert("Saving Failed", write.Error.Message, "OK", null); } DependencyService.Get <IRecorder>().ClearAudioFiles(); Cancel(); } else { if (Device.OS == TargetPlatform.iOS) { DependencyService.Get <IDisplayAlertPopup>().NoAudioAlert(); } else { await SplitView.DisplayAlert("No Audio Recorded", "Please give the audio input", "OK", null); } } } await Task.Run(() => { Task.Delay(2000).Wait(); _isExecute = true; }); } } else { if (Device.OS == TargetPlatform.iOS) { DependencyService.Get <IDisplayAlertPopup>().AudioIsRecording(); } else { await SplitView.DisplayAlert("Warning", "You can not save the Audio while recording", "OK", null); } } } catch (Exception ex) { LogTracking.LogTrace(ex.ToString()); // ignored } }