parent
7ef194a4cb
commit
f92f5f2a79
@ -1,50 +1,9 @@ |
|||||||
namespace NotesNet8.Views; |
namespace NotesNet8.Views; |
||||||
|
|
||||||
[QueryProperty(nameof(ItemId), nameof(ItemId))] |
|
||||||
public partial class NotePage : ContentPage |
public partial class NotePage : ContentPage |
||||||
{ |
{ |
||||||
public string ItemId { set { LoadNote(value); } } |
|
||||||
|
|
||||||
public NotePage() |
public NotePage() |
||||||
{ |
{ |
||||||
InitializeComponent(); |
InitializeComponent(); |
||||||
|
|
||||||
string appDataPath = FileSystem.AppDataDirectory; |
|
||||||
string randomFileName = $"{Path.GetRandomFileName()}.notes.txt"; |
|
||||||
|
|
||||||
LoadNote(Path.Combine(appDataPath, randomFileName)); |
|
||||||
} |
|
||||||
|
|
||||||
private void LoadNote(string fileName) |
|
||||||
{ |
|
||||||
Models.Note noteModel = new Models.Note(); |
|
||||||
noteModel.Filename = fileName; |
|
||||||
|
|
||||||
if (File.Exists(fileName)) |
|
||||||
{ |
|
||||||
noteModel.Date = File.GetCreationTime(fileName); |
|
||||||
noteModel.Text = File.ReadAllText(fileName); |
|
||||||
} |
|
||||||
|
|
||||||
BindingContext = noteModel; |
|
||||||
} |
|
||||||
|
|
||||||
private async void SaveButton_Clicked(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
if (BindingContext is Models.Note note) |
|
||||||
File.WriteAllText(note.Filename, TextEditor.Text); |
|
||||||
|
|
||||||
await Shell.Current.GoToAsync(".."); |
|
||||||
} |
|
||||||
|
|
||||||
private async void DeleteButton_Clicked(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
if (BindingContext is Models.Note note) |
|
||||||
{ |
|
||||||
if (File.Exists(note.Filename)) |
|
||||||
File.Delete(note.Filename); |
|
||||||
} |
|
||||||
|
|
||||||
await Shell.Current.GoToAsync(".."); |
|
||||||
} |
} |
||||||
} |
} |
Loading…
Reference in new issue