59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using CommunityToolkit.Maui.Views;
|
|
using NotesDataAnalyst.NoteContent;
|
|
|
|
|
|
namespace NotesDataAnalyst
|
|
{
|
|
public partial class NoteSelectionPopup : Popup
|
|
{
|
|
public event Action<Note> NoteSelected;
|
|
|
|
public NoteSelectionPopup()
|
|
{
|
|
InitializeComponent();
|
|
notesCollectionView.ItemsSource = App.Database.GetAllNotes(); // Çàãðóçêà çàìåòîê èç ÁÄ
|
|
}
|
|
|
|
private void OnSearchTextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
string searchText = e.NewTextValue.ToLower();
|
|
notesCollectionView.ItemsSource = App.Database.GetAllNotes()
|
|
.Where(note => note.Title.ToLower().Contains(searchText));
|
|
}
|
|
|
|
private async void OnNoteSelected(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
|
|
|
|
if (e.CurrentSelection.FirstOrDefault() is Note selectedNote)
|
|
{
|
|
|
|
NoteSelected?.Invoke(selectedNote);
|
|
Close(); // Çàêðûâàåì îêíî ïîñëå âûáîðà çàìåòêè
|
|
}
|
|
}
|
|
|
|
private async void OnNoteTapped(object sender, EventArgs e)
|
|
{
|
|
// Ïîëó÷àåì ýëåìåíò, íà êîòîðûé êëèêíóëè
|
|
var tappedFrame = (Frame)sender;
|
|
var selectedNote = (Note)tappedFrame.BindingContext;
|
|
|
|
if (selectedNote != null)
|
|
{
|
|
NoteSelected?.Invoke(selectedNote);
|
|
Close(); // Çàêðûâàåì îêíî ïîñëå âûáîðà çàìåòêè
|
|
}
|
|
}
|
|
|
|
|
|
private void OnCancelButtonClicked(object sender, EventArgs e)
|
|
{
|
|
Close(); // Çàêðûòèå îêíà ïî íàæàòèþ íà êíîïêó Îòìåíà
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|