Skip to content

Commit

Permalink
Merge pull request #176 from edgiardina/support-leagues
Browse files Browse the repository at this point in the history
Support Leagues
  • Loading branch information
edgiardina authored Oct 6, 2024
2 parents 6a4b2b5 + e5a7083 commit 44ecebe
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 14 deletions.
21 changes: 21 additions & 0 deletions Converters/NotEqualMultiValueConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Globalization;

namespace Ifpa.Converters
{
public class NotEqualMultiValueConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length == 2 && values[0] != null && values[1] != null)
{
return !values[0].Equals(values[1]);
}
return false;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
6 changes: 3 additions & 3 deletions IfpaMaui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
<PackageReference Include="LiveChartsCore.SkiaSharpView.Maui" Version="2.0.0-beta.911" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="PinballApi" Version="3.0.9" />
<PackageReference Include="PinballApi" Version="3.0.10" />
<PackageReference Include="Plugin.Maui.Calendar" Version="1.2.2" />
<PackageReference Include="Scrutor" Version="4.2.2" />
<PackageReference Include="Scrutor" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Xamarin" Version="1.0.0" />
<PackageReference Include="Shiny.Core" Version="3.3.3" />
<PackageReference Include="Shiny.Hosting.Maui" Version="3.3.3" />
Expand All @@ -73,7 +73,7 @@
<PackageReference Include="Syncfusion.Maui.Core" Version="24.1.45" />
<PackageReference Include="Syncfusion.Maui.TabView" Version="24.1.45" />
<PackageReference Include="System.ServiceModel.Syndication" Version="8.0.0" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog" Version="4.0.2" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
Expand Down
6 changes: 6 additions & 0 deletions Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public static string CalendarRankingSystem
set => Preferences.Set("CalendarRankingSystem", value);
}

public static bool CalendarShowLeagues
{
get => Preferences.Get("CalendarShowLeagues", false);
set => Preferences.Set("CalendarShowLeagues", value);
}

public static long LastCalendarIdSeen
{
get => Preferences.Get("LastCalendarIdSeen", 0L);
Expand Down
2 changes: 1 addition & 1 deletion Platforms/Android/Resources/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>
<color name="colorPrimary">#4579FB</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
<color name="colorAccent">#4579FB</color>
<color name="ifpaBackground">#062C53</color>
<color name="ifpaAltText">#d3d3d3</color>
</resources>
18 changes: 18 additions & 0 deletions Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,10 @@
<data name="CalendarFilterModalPage_RankingType" xml:space="preserve">
<value>Ranking Type</value>
</data>
<data name="CalendarFilterModalPage_ShowLeagues" xml:space="preserve">
<value>Show Leagues?</value>
</data>
<data name="Hyphen" xml:space="preserve">
<value>- </value>
</data>
</root>
6 changes: 4 additions & 2 deletions ViewModels/CalendarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using TournamentSearch = PinballApi.Models.WPPR.Universal.Tournaments.Search.Tournament;
using System.Windows.Input;
using PinballApi.Models.WPPR.Universal;
using PinballApi.Models.WPPR.Universal.Tournaments.Search;

namespace Ifpa.ViewModels
{
Expand Down Expand Up @@ -78,13 +79,15 @@ public async Task ExecuteLoadItemsCommand(Location geoLocation, int distance)
}

var tournamentType = (TournamentType?)(Settings.CalendarRankingSystem == "All" ? null : Enum.Parse(typeof(TournamentType), Settings.CalendarRankingSystem));
TournamentEventType? eventType = Settings.CalendarShowLeagues ? null : TournamentEventType.Tournament;

var items = await pinballRankingApi.TournamentSearch(latitude,
longitude,
distance, DistanceType.Miles,
startDate: DateTime.Now,
endDate: DateTime.Now.AddYears(1),
tournamentType: tournamentType,
tournamentType: tournamentType,
tournamentEventType: eventType,
totalReturn: 500);

logger.LogDebug("Api call completed at {0}", sw.ElapsedMilliseconds);
Expand All @@ -102,7 +105,6 @@ public async Task ExecuteLoadItemsCommand(Location geoLocation, int distance)
TournamentCalendarItems = new EventCollection();

items.Tournaments
.Where(item => item.EventEndDate - item.EventStartDate <= 5.Days())
.Select(n => new TournamentWithDistance(n, (long)Location.CalculateDistance(latitude.Value, longitude.Value, n.Latitude, n.Longitude, DistanceUnits.Miles)))
.GroupBy(item => item.EventStartDate.Date)
.ToList()
Expand Down
2 changes: 1 addition & 1 deletion ViewModels/PlayerSearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Command SearchCommand
{
var items = await PinballRankingApiV2.GetPlayersBySearch(new PlayerSearchFilter() { Name = text.Trim() });

Players = items.Results.ToObservableCollection();
Players = items.Results?.ToObservableCollection();
OnPropertyChanged("Players");
}
IsLoaded = true;
Expand Down
30 changes: 25 additions & 5 deletions Views/CalendarDetailPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<toolkit:InvertedBoolConverter x:Key="invertedBoolConverter" />
<toolkit:IsNotNullConverter x:Key="isNotNullConverter" />
<toolkit:IsNotEqualConverter x:Key="IsNotEqualConverter" />
<converters:NotEqualMultiValueConverter x:Key="NotEqualMultiValueConverter" />
<Style x:Key="calendarHeader"
TargetType="Label">
<Setter Property="TextColor"
Expand Down Expand Up @@ -114,11 +115,30 @@
<Label Text="{x:Static local:Strings.CalendarDetailPage_Date}"
Style="{DynamicResource labelStyle}"
Grid.Column="0" />

<Label Text="{Binding Tournament.EventStartDate, StringFormat='{0:d}', Mode=OneWay}"
Style="{DynamicResource valueStyle}"
Grid.Column="1" />

<HorizontalStackLayout Grid.Column="1">
<Label Text="{Binding Tournament.EventStartDate, StringFormat='{0:d}', Mode=OneWay}"
Style="{DynamicResource valueStyle}" />
<Label Text="{x:Static local:Strings.Hyphen}"
HorizontalTextAlignment="Center"
Padding="10,0,0,0"
Margin="5,0,0,0">
<Label.IsVisible>
<MultiBinding Converter="{StaticResource NotEqualMultiValueConverter}">
<Binding Path="Tournament.EventStartDate" />
<Binding Path="Tournament.EventEndDate" />
</MultiBinding>
</Label.IsVisible>
</Label>
<Label Text="{Binding Tournament.EventEndDate, StringFormat='{0:d}', Mode=OneWay}"
Style="{DynamicResource valueStyle}">
<Label.IsVisible>
<MultiBinding Converter="{StaticResource NotEqualMultiValueConverter}">
<Binding Path="Tournament.EventStartDate" />
<Binding Path="Tournament.EventEndDate" />
</MultiBinding>
</Label.IsVisible>
</Label>
</HorizontalStackLayout>

<Label Text="{x:Static local:Strings.CalendarDetailPage_Director}"
Style="{DynamicResource labelStyle}"
Expand Down
13 changes: 12 additions & 1 deletion Views/CalendarFilterModalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Location -->
<Label Text="{x:Static local:Strings.CalendarFilterModalPage_Location}"
Expand Down Expand Up @@ -93,10 +94,20 @@
<!--<x:String>Youth</x:String>-->
</Picker.Items>
</Picker>

<!-- Event Type -->
<Label Text="{x:Static local:Strings.CalendarFilterModalPage_ShowLeagues}"
Grid.Row="3"
Grid.Column="0"
VerticalTextAlignment="Center" />
<CheckBox Grid.Row="3"
Grid.Column="1"
Margin="20,0,5,0"
x:Name="ShowLeaguesCheckBox" />

<!-- Buttons -->
<StackLayout Orientation="Horizontal"
Grid.Row="3"
Grid.Row="4"
Grid.ColumnSpan="4"
Margin="0, 20">
<Button WidthRequest="160"
Expand Down
2 changes: 2 additions & 0 deletions Views/CalendarFilterModalPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public CalendarFilterModalPage()
LocationEntry.Text = lastCalendarLocation;
DistanceText.Text = ((int)DistanceSlider.Value).ToString();
RankingTypePicker.SelectedItem = lastCalendarRankingSystem;
ShowLeaguesCheckBox.IsChecked = Settings.CalendarShowLeagues;
}

private void Slider_ValueChanged(object sender, ValueChangedEventArgs e)
Expand Down Expand Up @@ -84,6 +85,7 @@ private async void FindButton_Clicked(object sender, EventArgs e)
Settings.LastCalendarLocation = LocationEntry.Text;
Settings.LastCalendarDistance = (int)DistanceSlider.Value;
Settings.CalendarRankingSystem = (string)RankingTypePicker.SelectedItem;
Settings.CalendarShowLeagues = ShowLeaguesCheckBox.IsChecked;

await Navigation.PopModalAsync();
FilterSaved?.Invoke();
Expand Down
3 changes: 2 additions & 1 deletion Views/PlayerDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ private async void ShareButton_Clicked(object sender, EventArgs e)
await Share.RequestAsync(new ShareTextRequest
{
Uri = $"https://www.ifpapinball.com/player.php?p={ViewModel.PlayerId}",
Title = Strings.PlayerDetailPage_SharePlayer
Title = Strings.PlayerDetailPage_SharePlayer,

});
}

Expand Down

0 comments on commit 44ecebe

Please sign in to comment.