Skip to content

Commit

Permalink
added search handler
Browse files Browse the repository at this point in the history
  • Loading branch information
davidortinau committed Nov 7, 2019
1 parent 6009b0e commit 2ca79bd
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 110 deletions.
2 changes: 1 addition & 1 deletion FlyMe.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlyMe.Android", "FlyMe\FlyM
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlyMe.iOS", "FlyMe\FlyMe.iOS\FlyMe.iOS.csproj", "{CD453E99-9D74-4CC3-B661-EDC2D86F0439}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlyMe", "FlyMe\FlyMe\FlyMe.csproj", "{3ED26151-0828-4F80-8B66-74869817A097}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlyMe", "FlyMe\FlyMe\FlyMe.csproj", "{3ED26151-0828-4F80-8B66-74869817A097}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
1 change: 0 additions & 1 deletion FlyMe/FlyMe.Android/FlyMe.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<None Include="Renderers\ShellRenderer.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
96 changes: 0 additions & 96 deletions FlyMe/FlyMe.Android/Renderers/ShellRenderer.cs

This file was deleted.

3 changes: 3 additions & 0 deletions FlyMe/FlyMe.UWP/FlyMe.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@
<PackageReference Include="Xamarin.Forms" Version="4.4.0.936621-pre1" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.9" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
<PackageReference Include="Xamarin.Forms.Visual.Material">
<Version>4.4.0.936621-pre1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FlyMe\FlyMe.csproj">
Expand Down
17 changes: 8 additions & 9 deletions FlyMe/FlyMe/FlightResultsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,36 @@
x:Class="FlyMe.FlightResultsPage">

<ContentPage.BindingContext>
<vm:FlightResultsViewModel />
<vm:FlightResultsViewModel x:Name="vm" />
</ContentPage.BindingContext>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<CollectionView
ItemsSource="{Binding FlightsToDisplay}"
RemainingItemsThreshold="0"
RemainingItemsThresholdReachedCommand="{Binding LoadMoreFlightsCommand}"
Margin="15">
<CollectionView.ItemsLayout>
<GridItemsLayout
HorizontalItemSpacing="8"
VerticalItemSpacing="8"
Span="2"
<LinearItemsLayout
ItemSpacing="8"
Orientation="Vertical" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<local:ResultViewB>
<local:ResultViewB.GestureRecognizers>
<local:ResultViewA>
<local:ResultViewA.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding
Source={RelativeSource
AncestorType={x:Type vm:FlightResultsViewModel}},
Path=GoToDetailsCommand}"
CommandParameter="{Binding .}"/>
</local:ResultViewB.GestureRecognizers>
</local:ResultViewB>
</local:ResultViewA.GestureRecognizers>
</local:ResultViewA>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Expand Down
38 changes: 36 additions & 2 deletions FlyMe/FlyMe/FlightResultsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using FlyMe.ViewModels;
using System;
using System.Collections.Generic;

using System.Linq;
using Xamarin.Forms;

namespace FlyMe
Expand All @@ -10,6 +11,39 @@ public partial class FlightResultsPage : ContentPage
public FlightResultsPage()
{
InitializeComponent();

Shell.SetSearchHandler(this, new FeedSearchHandler(vm));
}
}

public class FeedSearchHandler : SearchHandler
{
FlightResultsViewModel _vm;
public FeedSearchHandler(ViewModels.FlightResultsViewModel vm)
{
SearchBoxVisibility = SearchBoxVisibility.Expanded;
IsSearchEnabled = true;
ShowsResults = false;
Placeholder = "Find a Flight";
CancelButtonColor = Color.DarkBlue;
TextColor = Color.DarkBlue;

_vm = vm;
}

protected override void OnQueryChanged(string oldValue, string newValue)
{
base.OnQueryChanged(oldValue, newValue);
if (string.IsNullOrEmpty(newValue))
{
ItemsSource = null;
}
else
{
var results = new List<string>();
results = _vm.Flights.Where(x => x.Price.IndexOf(newValue, StringComparison.InvariantCultureIgnoreCase) > -1).Select(x => $"{x.From} to {x.To} - {x.Price}").ToList<string>();
ItemsSource = results;
}
}
}
}
2 changes: 1 addition & 1 deletion FlyMe/FlyMe/ResultViewB.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
HorizontalTextAlignment="Center"
VerticalOptions="End"
VerticalTextAlignment="Center"
BackgroundColor="Orange"
BackgroundColor="OrangeRed"
Padding="8"
TextColor="White">
<Label.FormattedText>
Expand Down

0 comments on commit 2ca79bd

Please sign in to comment.