Add SearchBar feature
continuous-integration/drone/push Build is passing Details

pull/36/head
Corentin LEMAIRE 2 years ago
parent e447943261
commit 4321756733

@ -12,7 +12,9 @@
<ScrollView Grid.Column="1" BackgroundColor="#404040">
<VerticalStackLayout>
<SearchBar Style="{StaticResource SearchBar}"/>
<local:SearchBarView/>
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Style="{StaticResource InfosComplementairesGridTrigger}">
<VerticalStackLayout Grid.Column="0">
<Frame IsClippedToBounds="True" CornerRadius="75" HeightRequest="150" WidthRequest="150" HorizontalOptions="Center" VerticalOptions="Center" BackgroundColor="Transparent">

@ -14,7 +14,9 @@
<ScrollView Grid.Column="1" BackgroundColor="#404040">
<VerticalStackLayout BindingContext="{Binding InfoTitle}">
<SearchBar Style="{StaticResource SearchBar}"/>
<local:SearchBarView/>
<Frame IsClippedToBounds="True" CornerRadius="75" HeightRequest="150" WidthRequest="150" HorizontalOptions="Center" VerticalOptions="Center" BackgroundColor="Transparent">
<Image Source="{Binding ImageURL}" Aspect="AspectFill" WidthRequest="150" HeightRequest="150" Margin="-20" IsAnimationPlaying="True"/>
</Frame>

@ -69,6 +69,9 @@
<Compile Update="FooterPage.xaml.cs">
<DependentUpon>FooterPage.xaml</DependentUpon>
</Compile>
<Compile Update="SearchBarView.xaml.cs">
<DependentUpon>SearchBarView.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
@ -99,6 +102,9 @@
<MauiXaml Update="PlaylistsPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="SearchBarView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="test.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>

@ -16,7 +16,9 @@
<local:Layout Grid.Column="0"/>
<ScrollView Grid.Column="1" Grid.Row="0" BackgroundColor="#404040">
<VerticalStackLayout>
<SearchBar Style="{StaticResource SearchBar}"/>
<local:SearchBarView/>
<FlexLayout Direction="Row" AlignItems="Start" BindableLayout.ItemsSource="{Binding CustomTitles}" JustifyContent="SpaceAround" Wrap="Wrap">
<BindableLayout.ItemTemplate>
<DataTemplate>

@ -16,7 +16,7 @@
<VerticalStackLayout>
<SearchBar Style="{StaticResource SearchBar}"/>
<local:SearchBarView/>
<FlexLayout Direction="Row" AlignItems="Start" BindableLayout.ItemsSource="{Binding Albums}" JustifyContent="SpaceAround" Wrap="Wrap">
<BindableLayout.ItemTemplate>

@ -12,7 +12,9 @@
<ScrollView Grid.Column="1" BackgroundColor="#404040">
<VerticalStackLayout>
<SearchBar Style="{StaticResource SearchBar}"/>
<local:SearchBarView/>
<Frame IsClippedToBounds="True" CornerRadius="75" HeightRequest="150" WidthRequest="150" HorizontalOptions="Center" VerticalOptions="Center" BackgroundColor="Transparent">
<Image Source="{Binding ImageURL}" Aspect="AspectFill" WidthRequest="150" HeightRequest="150" Margin="-20" IsAnimationPlaying="True"/>
</Frame>

@ -16,7 +16,9 @@
<local:Layout Grid.Column="0"/>
<ScrollView Grid.Column="1" Grid.Row="0" BackgroundColor="#404040">
<VerticalStackLayout>
<SearchBar Style="{StaticResource SearchBar}"/>
<local:SearchBarView/>
<FlexLayout Direction="Row" AlignItems="Start" BindableLayout.ItemsSource="{Binding Playlists}" JustifyContent="SpaceAround" Wrap="Wrap">
<BindableLayout.ItemTemplate>
<DataTemplate>

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Linaris"
xmlns:model="clr-namespace:Model;assembly=Model"
x:Class="Linaris.SearchBarView">
<VerticalStackLayout>
<SearchBar Style="{StaticResource SearchBar}" TextChanged="SearchBar_TextChanged" Text=""/>
<VerticalStackLayout Margin="40,-10,40,10">
<FlexLayout Direction="Column" BindableLayout.ItemsSource="{Binding Albums}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame Padding="10" BackgroundColor="white" BorderColor="black" HeightRequest="40">
<Label Text="{Binding Name}" TextColor="black"/>
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="SearchResult_Tapped" />
</Frame.GestureRecognizers>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
<FlexLayout Direction="Column" BindableLayout.ItemsSource="{Binding Artists}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame Padding="10" BackgroundColor="white" BorderColor="black" HeightRequest="40">
<Label Text="{Binding Name}" TextColor="black"/>
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="SearchResult_Tapped" />
</Frame.GestureRecognizers>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
<FlexLayout Direction="Column" BindableLayout.ItemsSource="{Binding InfoTitles}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame Padding="10" BackgroundColor="white" BorderColor="black" HeightRequest="40">
<Label Text="{Binding Name}" TextColor="black"/>
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="SearchResult_Tapped" />
</Frame.GestureRecognizers>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
<FlexLayout Direction="Column" BindableLayout.ItemsSource="{Binding CustomTitles}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame Padding="10" BackgroundColor="white" BorderColor="black" HeightRequest="40">
<Label Text="{Binding Name}" TextColor="black"/>
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="SearchResult_Tapped" />
</Frame.GestureRecognizers>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
<FlexLayout Direction="Column" BindableLayout.ItemsSource="{Binding Playlists}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame Padding="10" BackgroundColor="white" BorderColor="black" HeightRequest="40">
<Label Text="{Binding Name}" TextColor="black"/>
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="SearchResult_Tapped" />
</Frame.GestureRecognizers>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
</VerticalStackLayout>
</VerticalStackLayout>
</ContentView>

@ -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<Album> albums = new ObservableCollection<Album>();
public ObservableCollection<Album> Albums
{
get => albums;
set
{
albums = value;
}
}
private ObservableCollection<InfoTitle> infoTitles = new ObservableCollection<InfoTitle>();
public ObservableCollection<InfoTitle> InfoTitles
{
get => infoTitles;
set
{
infoTitles = value;
}
}
private ObservableCollection<Playlist> playlists = new ObservableCollection<Playlist>();
public ObservableCollection<Playlist> 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<Album> SearchAlbums(string filterText)
{
return new ObservableCollection<Album>(Manager.GetAlbums().Where(x => x.Name.Contains(filterText, StringComparison.OrdinalIgnoreCase)));
}
public ObservableCollection<InfoTitle> SearchInfoTitles(string filterText)
{
return new ObservableCollection<InfoTitle>(Manager.GetInfoTitles().Where(x => x.Name.Contains(filterText, StringComparison.OrdinalIgnoreCase)));
}
public ObservableCollection<Playlist> SearchPlaylists(string filterText)
{
return new ObservableCollection<Playlist>(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());
}
}
}
Loading…
Cancel
Save