diff --git a/MyFirstMauiApp/NotesNet8/AppShell.xaml b/MyFirstMauiApp/NotesNet8/AppShell.xaml index ec92af7..b7b81b8 100644 --- a/MyFirstMauiApp/NotesNet8/AppShell.xaml +++ b/MyFirstMauiApp/NotesNet8/AppShell.xaml @@ -3,17 +3,17 @@ xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:NotesNet8" - xmlns:page="clr-namespace:NotesNet8.Pages" + xmlns:views="clr-namespace:NotesNet8.Views" Title="NotesNet8" Shell.FlyoutBehavior="Disabled"> diff --git a/MyFirstMauiApp/NotesNet8/AppShell.xaml.cs b/MyFirstMauiApp/NotesNet8/AppShell.xaml.cs index 4d4d359..334b8cf 100644 --- a/MyFirstMauiApp/NotesNet8/AppShell.xaml.cs +++ b/MyFirstMauiApp/NotesNet8/AppShell.xaml.cs @@ -5,6 +5,12 @@ public AppShell() { InitializeComponent(); + RegisterRoutes(); + } + + private void RegisterRoutes() + { + Routing.RegisterRoute(nameof(Views.NotePage), typeof(Views.NotePage)); } } } diff --git a/MyFirstMauiApp/NotesNet8/Models/About.cs b/MyFirstMauiApp/NotesNet8/Models/About.cs new file mode 100644 index 0000000..79e65a8 --- /dev/null +++ b/MyFirstMauiApp/NotesNet8/Models/About.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NotesNet8.Models +{ + internal class About + { + public string Title => AppInfo.Name; + public string Version => AppInfo.VersionString; + public string MoreInfoUrl => "https://aka.ms/maui"; + public string Message => "This app is written in XAML and C# with .NET MAUI"; + } +} diff --git a/MyFirstMauiApp/NotesNet8/Models/AllNotes.cs b/MyFirstMauiApp/NotesNet8/Models/AllNotes.cs new file mode 100644 index 0000000..0ef9559 --- /dev/null +++ b/MyFirstMauiApp/NotesNet8/Models/AllNotes.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NotesNet8.Models +{ + internal class AllNotes + { + public ObservableCollection Notes { get; set; } = new ObservableCollection(); + + public AllNotes() + { + LoadNotes(); + } + public void LoadNotes() + { + Notes.Clear(); + + string appDataPath = FileSystem.AppDataDirectory; + IEnumerable notes = Directory + .EnumerateFiles(appDataPath, "*.notes.txt") + .Select(filename => new Note() + { + Filename = filename, + Text = File.ReadAllText(filename), + Date = File.GetCreationTime(filename) + }) + .OrderBy(note => note.Date); + + foreach (Note note in notes) + { + Notes.Add(note); + } + } + } +} diff --git a/MyFirstMauiApp/NotesNet8/Models/Note.cs b/MyFirstMauiApp/NotesNet8/Models/Note.cs new file mode 100644 index 0000000..1e059c6 --- /dev/null +++ b/MyFirstMauiApp/NotesNet8/Models/Note.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NotesNet8.Models +{ + internal class Note + { + public string Filename { get; set; } + public string Text { get; set; } + public DateTime Date { get; set; } + } +} diff --git a/MyFirstMauiApp/NotesNet8/NotesNet8.csproj b/MyFirstMauiApp/NotesNet8/NotesNet8.csproj index f055842..84f530b 100644 --- a/MyFirstMauiApp/NotesNet8/NotesNet8.csproj +++ b/MyFirstMauiApp/NotesNet8/NotesNet8.csproj @@ -68,10 +68,13 @@ - + MSBuild:Compile - + + MSBuild:Compile + + MSBuild:Compile diff --git a/MyFirstMauiApp/NotesNet8/Pages/NotePage.xaml.cs b/MyFirstMauiApp/NotesNet8/Pages/NotePage.xaml.cs deleted file mode 100644 index ad25342..0000000 --- a/MyFirstMauiApp/NotesNet8/Pages/NotePage.xaml.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace NotesNet8.Pages; - -public partial class NotePage : ContentPage -{ - string _fileName = Path.Combine(FileSystem.AppDataDirectory, "notes.txt"); - - public NotePage() - { - InitializeComponent(); - - if (File.Exists(_fileName)) - TextEditor.Text = File.ReadAllText(_fileName); - } - - private void SaveButton_Clicked(object sender, EventArgs e) - { - File.WriteAllText(_fileName, TextEditor.Text); - } - - private void DeleteButton_Clicked(object sender, EventArgs e) - { - if (File.Exists(_fileName)) - File.Delete(_fileName); - - TextEditor.Text = string.Empty; - } -} \ No newline at end of file diff --git a/MyFirstMauiApp/NotesNet8/Pages/AboutPage.xaml b/MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml similarity index 51% rename from MyFirstMauiApp/NotesNet8/Pages/AboutPage.xaml rename to MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml index b3fd847..78a7114 100644 --- a/MyFirstMauiApp/NotesNet8/Pages/AboutPage.xaml +++ b/MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml @@ -1,16 +1,25 @@ - + + + + - -