diff --git a/Sources/Linaris/AlbumPage.xaml b/Sources/Linaris/AlbumPage.xaml index 89b1f95..9623718 100644 --- a/Sources/Linaris/AlbumPage.xaml +++ b/Sources/Linaris/AlbumPage.xaml @@ -12,7 +12,9 @@ - + + + diff --git a/Sources/Linaris/InfoTitlePage.xaml b/Sources/Linaris/InfoTitlePage.xaml index 16c0d60..91ce209 100644 --- a/Sources/Linaris/InfoTitlePage.xaml +++ b/Sources/Linaris/InfoTitlePage.xaml @@ -14,7 +14,9 @@ - + + + diff --git a/Sources/Linaris/Linaris.csproj b/Sources/Linaris/Linaris.csproj index d90e6e9..f954d66 100644 --- a/Sources/Linaris/Linaris.csproj +++ b/Sources/Linaris/Linaris.csproj @@ -69,6 +69,9 @@ FooterPage.xaml + + SearchBarView.xaml + @@ -99,6 +102,9 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile diff --git a/Sources/Linaris/LocalFilesPage.xaml b/Sources/Linaris/LocalFilesPage.xaml index 339621f..ca1ffb2 100644 --- a/Sources/Linaris/LocalFilesPage.xaml +++ b/Sources/Linaris/LocalFilesPage.xaml @@ -16,7 +16,9 @@ - + + + diff --git a/Sources/Linaris/MainPage.xaml b/Sources/Linaris/MainPage.xaml index 70b7a4c..2c77abc 100644 --- a/Sources/Linaris/MainPage.xaml +++ b/Sources/Linaris/MainPage.xaml @@ -16,7 +16,7 @@ - + diff --git a/Sources/Linaris/PlaylistPage.xaml b/Sources/Linaris/PlaylistPage.xaml index 63c61fd..e4384af 100644 --- a/Sources/Linaris/PlaylistPage.xaml +++ b/Sources/Linaris/PlaylistPage.xaml @@ -12,7 +12,9 @@ - + + + diff --git a/Sources/Linaris/PlaylistsPage.xaml b/Sources/Linaris/PlaylistsPage.xaml index e0b2c77..442ccc2 100644 --- a/Sources/Linaris/PlaylistsPage.xaml +++ b/Sources/Linaris/PlaylistsPage.xaml @@ -16,7 +16,9 @@ - + + + diff --git a/Sources/Linaris/SearchBarView.xaml b/Sources/Linaris/SearchBarView.xaml new file mode 100644 index 0000000..9ff20a8 --- /dev/null +++ b/Sources/Linaris/SearchBarView.xaml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Linaris/SearchBarView.xaml.cs b/Sources/Linaris/SearchBarView.xaml.cs new file mode 100644 index 0000000..593840d --- /dev/null +++ b/Sources/Linaris/SearchBarView.xaml.cs @@ -0,0 +1,127 @@ +using Microsoft.Maui.Controls; +using Model; +using Model.Stub; +using System.Collections.ObjectModel; +using System.Linq; +using System.Runtime.CompilerServices; + +namespace Linaris; + +public partial class SearchBarView : ContentView +{ + Manager Manager { get; set; } = (Application.Current as App).Manager; + + private ObservableCollection albums = new ObservableCollection(); + + public ObservableCollection Albums + { + get => albums; + set + { + albums = value; + } + } + + private ObservableCollection infoTitles = new ObservableCollection(); + + public ObservableCollection InfoTitles + { + get => infoTitles; + set + { + infoTitles = value; + } + } + + private ObservableCollection playlists = new ObservableCollection(); + + public ObservableCollection Playlists + { + get => playlists; + set + { + playlists = value; + } + } + + public SearchBarView() + { + InitializeComponent(); + BindingContext = this; + } + + public void SearchBar_TextChanged(object sender, EventArgs e) + { + string filterText = ((SearchBar)sender).Text; + if (filterText.Length == 0) + { + ResetCollections(); + return; + } + SearchAll(filterText); + } + + public void ResetCollections() + { + Albums.Clear(); + InfoTitles.Clear(); + Playlists.Clear(); + } + + public void SearchAll(string filterText) + { + Albums.Clear(); + foreach (var album in SearchAlbums(filterText)) + { + Albums.Add(album); + } + + InfoTitles.Clear(); + foreach (var infoTitle in SearchInfoTitles(filterText)) + { + InfoTitles.Add(infoTitle); + } + + Playlists.Clear(); + foreach (var playlist in SearchPlaylists(filterText)) + { + Playlists.Add(playlist); + } + } + + public ObservableCollection SearchAlbums(string filterText) + { + return new ObservableCollection(Manager.GetAlbums().Where(x => x.Name.Contains(filterText, StringComparison.OrdinalIgnoreCase))); + } + + public ObservableCollection SearchInfoTitles(string filterText) + { + return new ObservableCollection(Manager.GetInfoTitles().Where(x => x.Name.Contains(filterText, StringComparison.OrdinalIgnoreCase))); + } + + public ObservableCollection SearchPlaylists(string filterText) + { + return new ObservableCollection(Manager.GetPlaylists().Where(x => x.Name.Contains(filterText, StringComparison.OrdinalIgnoreCase))); + } + + private async void SearchResult_Tapped(object sender, TappedEventArgs e) + { + if (((Frame)sender).BindingContext is Album album) + { + Manager.CurrentAlbum = album; + await Navigation.PushAsync(new AlbumPage()); + } + + if (((Frame)sender).BindingContext is InfoTitle infoTitle) + { + Manager.CurrentInfoTitle = infoTitle; + await Navigation.PushAsync(new InfoTitlePage()); + } + + if (((Frame)sender).BindingContext is Playlist playlist) + { + Manager.CurrentPlaylist = playlist; + await Navigation.PushAsync(new PlaylistPage()); + } + } +}