private async Task saveChangesAsync() { if (nameEntry.Text == null || nameEntry.Text == "") { await parentPage.DisplayAlert("Warning", "Contact must have name", "Ok"); return; } string filePath; if (this.contactMedia == null) { filePath = Path.Combine(FilePaths.allContactsPath, $@"{Guid.NewGuid()}" + ".contact"); IFile file = await FileSystem.Current.LocalStorage.CreateFileAsync(filePath, CreationCollisionOption.FailIfExists); } else { filePath = contactMedia.filePath; } ContactMediaContent newContactMedia = contactMedia; // update fields on contact media if (newContactMedia == null) { newContactMedia = new ContactMediaContent(filePath); } newContactMedia.initialize(nameEntry.Text, phoneEntry.Text, imageFilePath); // If null add to card if (this.contactMedia == null) { parentCard?.addMedia(newContactMedia); MediaManager.addNewMedia(newContactMedia); } this.capturedMedia = newContactMedia; this.contactMedia = this.capturedMedia as ContactMediaContent; JSONSerialManager.serialize(filePath, newContactMedia); //await Navigation.PopAsync(); }
//Open existing contact public ContactView(bool isEditable, AbMediaContent media) { InitializeComponent(); this.contactMedia = media as ContactMediaContent; this.contactImage.Source = contactMedia.image; this.imageFilePath = contactMedia.imageFilePath; this.nameEntry.Text = contactMedia.name; this.phoneEntry.Text = contactMedia.phoneNumber; /* * if(imageFilePath == null || imageFilePath == "") * { * this.changeImageLabel.Text = "Set Image"; * } * else * this.changeImageLabel.Text = "Change Image"; */ this.parentPage = Navigation.NavigationStack.LastOrDefault(); }