//Open existing note public NoteView(bool isEditable, AbMediaContent media) { InitializeComponent(); this.noteMedia = media as NoteMediaContent; this.titleEntry.Text = noteMedia.name; this.bodyEditor.Text = noteMedia.bodyText; this.bodyEditor.IsEnabled = isEditable; this.titleEntry.IsEnabled = isEditable; this.titleEntry.Focus(); this.parentPage = Navigation.NavigationStack.LastOrDefault(); }
private async Task saveChangesAsync() { if (titleEntry.Text == "") { await parentPage.DisplayAlert("Warning", "Note must have title", "Ok"); return; } string filePath; //If null we are creating new text file if (this.noteMedia == null) { filePath = Path.Combine(FilePaths.allNotesPath, $@"{Guid.NewGuid()}.txt"); IFile file = await FileSystem.Current.LocalStorage.CreateFileAsync(filePath, CreationCollisionOption.FailIfExists); } else { filePath = noteMedia.filePath; } // Write to text file IFile textFile = await FileSystem.Current.GetFileFromPathAsync(filePath); await textFile.WriteAllTextAsync(titleEntry.Text + System.Environment.NewLine + bodyEditor.Text); // If null add to card if (this.noteMedia == null) { this.noteMedia = new NoteMediaContent(filePath); this.noteMedia.name = titleEntry.Text; this.noteMedia.bodyText = bodyEditor.Text; parentCard?.addMedia(this.noteMedia); MediaManager.addNewMedia(this.noteMedia); } else { // Update actual note media instance in memory this.noteMedia.name = titleEntry.Text; this.noteMedia.bodyText = bodyEditor.Text; } capturedMedia = noteMedia; // End page // await Navigation.PopAsync(); }