Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion App/Controls/DealPreview.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
Text="{Binding Deal.Title,
Source={x:Reference preview}}"
Source={x:Reference preview}, Converter={StaticResource MaxLengthConverter}, ConverterParameter={Binding TitleLimit,Source={x:Reference preview}}}"
TextColor="{StaticResource FontColor}"
FontFamily="P-Bold"
x:Name="label"
Expand Down
14 changes: 14 additions & 0 deletions App/Controls/DealPreview.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ public Deal Deal
set => SetValue(DealProperty, value);
}

/// <summary>
/// Limit of character to display for the Title
/// </summary>
public static readonly BindableProperty TitleLimitProperty = BindableProperty.Create(propertyName: nameof(Deal),
returnType: typeof(int),
declaringType: typeof(DealPreview),
defaultBindingMode: BindingMode.OneWay,
defaultValue: int.MaxValue);
public int TitleLimit
{
get => (int)GetValue(TitleLimitProperty);
set => SetValue(TitleLimitProperty, value);
}

public DealPreview()
{
InitializeComponent();
Expand Down
45 changes: 27 additions & 18 deletions App/Helpers/Converters/MaxLengthConverter.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
using System;
using System.Collections.Generic;

using System.Globalization;
using System.Text;
using Microsoft.Maui.Controls;
using Microsoft.Maui;

namespace GamHubApp.Helpers
namespace GamHubApp.Helpers;

public class MaxLengthConverter : IValueConverter
{
public class MaxLengthConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
if (parameter is Binding binding)
{
int maxLength = int.Parse((string)parameter);
string text = (string)value;
if (string.IsNullOrEmpty(text))
return 0;
if (text.Length > maxLength)
var src = binding.Source;
var propName = binding.Path;

if (propName.Contains('.'))
{
return text.Substring(0, maxLength) + "...";
var lastName = propName.Split('.').Last();
propName = src?.GetType().GetProperty(lastName)?.GetValue(src, null).ToString();
// NOTE: for any maintenance read https://benetskyybogdan.medium.com/converter-parameter-binding-how-to-bind-complex-values-at-xamarin-maui-a23b6c45ab31

}
return text;
parameter = src?.GetType().GetProperty(propName)?.GetValue(src, null).ToString();
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
int maxLength = int.Parse((string)parameter);
string text = (string)value;
if (string.IsNullOrEmpty(text))
return 0;
if (text.Length > maxLength)
{
throw new NotImplementedException();
return text.Substring(0, maxLength) + "...";
}
return text;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
16 changes: 16 additions & 0 deletions App/ViewModels/DealsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using GamHubApp.Views;
using MvvmHelpers;
using System.Collections.ObjectModel;
#if DEBUG
using System.Diagnostics;
#endif

namespace GamHubApp.ViewModels;

Expand Down Expand Up @@ -170,6 +173,8 @@ public void ResetSearch()
/// <param name="textSearch">input of the search</param>
public void DealsSearch(string textSearch)
{
try
{
if (string.IsNullOrEmpty(textSearch))
{
ResetSearch();
Expand All @@ -185,6 +190,17 @@ public void DealsSearch(string textSearch)
}

Deals = new(filteredDeals);

}
catch (Exception ex)
{
#if DEBUG
Debug.WriteLine(ex);
throw new Exception(ex.Message);
#else
SentrySdk.CaptureException(ex);
#endif
}
}

public async Task UpdateDeals()
Expand Down
5 changes: 3 additions & 2 deletions App/Views/DealsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@
>
<CollectionView.Header>
<Grid RowDefinitions="auto,*">
<Grid RowDefinitions="50,280,40"
<Grid RowDefinitions="50,310,40"
Grid.Row="0"
>
<Grid.Triggers>
<DataTrigger TargetType="Grid"
Binding="{Binding PopularDeals.Count}"
Value="0">
<Setter Property="IsVisible" Value="True" />
<Setter Property="IsVisible" Value="False" />

</DataTrigger>
</Grid.Triggers>
Expand All @@ -93,6 +93,7 @@
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="models:Deal">
<ctrl:DealPreview Deal="{Binding .}"
TitleLimit="65"
WidthRequest="350"
Margin="20,5,0,15"/>
</DataTemplate>
Expand Down
Loading