async void CheckForSavedInfo() { if (await FileHelper.ExistsAsync(App.TransientFilename)) { // Read the file. string str = await FileHelper.ReadTextAsync(App.TransientFilename); // Delete the file. await FileHelper.DeleteFileAsync(App.TransientFilename); // Break down the file contents. string[] contents = str.Split('\x1F'); string filename = contents[0]; bool isNoteEdit = Boolean.Parse(contents[1]); string entryText = contents[2]; string editorText = contents[3]; // Create the Note object and initialize it with saved data. Note note = new Note(filename); note.Title = entryText; note.Text = editorText; // Navigate to NotePage. NotePage notePage = new NotePage(note, isNoteEdit); await this.Navigation.PushAsync(notePage); } }
public HomePage() { this.Title = "Note Taker"; // Create and initialize ListView. ListView listView = new ListView { ItemsSource = App.NoteFolder.Notes, ItemTemplate = new DataTemplate(typeof(TextCell)), VerticalOptions = LayoutOptions.FillAndExpand }; listView.ItemTemplate.SetBinding(TextCell.TextProperty, "Identifier"); // Handle item selection for editing and deleting. listView.ItemSelected += (sender, args) => { if (args.SelectedItem != null) { // Deselect the item. listView.SelectedItem = null; // Navigate to NotePage. Note note = (Note)args.SelectedItem; this.Navigation.PushAsync(new NotePage(note, true)); } }; // Create and initialize ToolbarItem. ToolbarItem addNewItem = new ToolbarItem { Name = "Add Note", Icon = Device.OnPlatform("new.png", "ic_action_new.png", "Images/add.png"), Order = ToolbarItemOrder.Primary }; addNewItem.Activated += (sender, args) => { // Create unique filename. DateTime datetime = DateTime.UtcNow; string filename = datetime.ToString("yyyyMMddHHmmssfff") + ".note"; // Navigate to new NotePage. Note note = new Note(filename); this.Navigation.PushAsync(new NotePage(note)); }; this.ToolbarItems.Add(addNewItem); // Assemble page. this.Content = listView; CheckForSavedInfo(); }
public void Restore(string prefix) { Application app = Application.Current; // Create a new Note object. Note note = new Note((string)app.Properties["fileName"]) { Title = (string)app.Properties["title"], Text = (string)app.Properties["text"] }; // Set the properties of this class. Note = note; IsNoteEdit = (bool)app.Properties["isNoteEdit"]; }
async void GetFilesAsync() { // Sort the filenames. IEnumerable<string> filenames = from filename in await FileHelper.GetFilesAsync() where filename.EndsWith(".note") orderby (filename) select filename; // Store them in the Notes collection. foreach (string filename in filenames) { Note note = new Note(filename); await note.LoadAsync(); this.Notes.Add(note); } }
public NotePage(Note note, bool isNoteEdit = false) { // Initialize Note object this.note = note; this.isNoteEdit = isNoteEdit; Title = isNoteEdit ? "Edit Note" : "New Note"; // Create Entry and Editor views. Entry entry = new Entry { Placeholder = "Title (optional)" }; Editor editor = new Editor { Keyboard = Keyboard.Create(KeyboardFlags.All), BackgroundColor = Device.OnPlatform(Color.Default, Color.Default, Color.White), VerticalOptions = LayoutOptions.FillAndExpand }; // Set data bindings. this.BindingContext = note; entry.SetBinding(Entry.TextProperty, "Title"); editor.SetBinding(Editor.TextProperty, "Text"); // Assemble page. StackLayout stackLayout = new StackLayout { Children = { new Label { Text = "Title:" }, entry, new Label { Text = "Note:" }, editor, } }; if (isNoteEdit) { // Cancel toolbar item. ToolbarItem cancelItem = new ToolbarItem { Name = "Cancel", Icon = Device.OnPlatform("cancel.png", "ic_action_cancel.png", "Images/cancel.png"), Order = ToolbarItemOrder.Primary }; cancelItem.Activated += async (sender, args) => { bool confirm = await this.DisplayAlert("Note Taker", "Cancel note edit?", "Yes", "No"); if (confirm) { // Reload note. await note.LoadAsync(); // Return to home page. await this.Navigation.PopAsync(); } }; this.ToolbarItems.Add(cancelItem); // Delete toolbar item. ToolbarItem deleteItem = new ToolbarItem { Name = "Delete", Icon = Device.OnPlatform("discard.png", "ic_action_discard.png", "Images/delete.png"), Order = ToolbarItemOrder.Primary }; deleteItem.Activated += async (sender, args) => { bool confirm = await this.DisplayAlert("Note Taker", "Delete this note?", "Yes", "No"); if (confirm) { // Delete Note file and remove from collection. await note.DeleteAsync(); App.NoteFolder.Notes.Remove(note); // Return to home page. await this.Navigation.PopAsync(); } }; this.ToolbarItems.Add(deleteItem); } this.Content = stackLayout; }