diff --git a/App/Controls/DealPreview.xaml b/App/Controls/DealPreview.xaml
new file mode 100644
index 00000000..11d29acf
--- /dev/null
+++ b/App/Controls/DealPreview.xaml
@@ -0,0 +1,206 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/App/Controls/DealPreview.xaml.cs b/App/Controls/DealPreview.xaml.cs
new file mode 100644
index 00000000..d928ba6f
--- /dev/null
+++ b/App/Controls/DealPreview.xaml.cs
@@ -0,0 +1,22 @@
+using GamHubApp.Models;
+
+namespace GamHubApp.Controls;
+
+public partial class DealPreview : ContentView
+{
+ public static readonly BindableProperty DealProperty = BindableProperty.Create(propertyName: nameof(Deal),
+ returnType: typeof(Deal),
+ declaringType: typeof(DealPreview),
+ defaultBindingMode: BindingMode.OneWay);
+ public Deal Deal
+ {
+ get => (Deal)GetValue(DealProperty);
+ set => SetValue(DealProperty, value);
+ }
+
+ public DealPreview()
+ {
+ InitializeComponent();
+ BindingContext = this;
+ }
+}
\ No newline at end of file
diff --git a/App/GamHubApp.csproj b/App/GamHubApp.csproj
index 1347e113..bbdcfc43 100644
--- a/App/GamHubApp.csproj
+++ b/App/GamHubApp.csproj
@@ -140,6 +140,9 @@
+
+ MSBuild:Compile
+
MSBuild:Compile
diff --git a/App/Models/Deal.cs b/App/Models/Deal.cs
index 9683b911..0459d305 100644
--- a/App/Models/Deal.cs
+++ b/App/Models/Deal.cs
@@ -68,5 +68,5 @@ public Command ShareDeal
}
}
[JsonIgnore, Ignore]
- public bool EpirationDisplayed { get => (Expires - DateTime.Now).TotalDays < 30; }
+ public bool ExpirationDisplayed { get => (Expires - DateTime.Now).TotalDays < 30; }
}
diff --git a/App/Services/Fetcher.cs b/App/Services/Fetcher.cs
index 97d02a8a..0a8af0c2 100644
--- a/App/Services/Fetcher.cs
+++ b/App/Services/Fetcher.cs
@@ -536,14 +536,14 @@ public async Task> GetPartners()
/// Get all the deals
///
/// all the deals
- public async Task> GetDeals()
+ public async Task> GetDeals(string filterCode = null)
{
if (!Fetcher.CheckFeasability())
return [];
ResetHandler();
try
{
- string filterCode = Preferences.Get(PreferencesKeys.DealFilterCode, null);
+ filterCode ??= Preferences.Get(PreferencesKeys.DealFilterCode, null);
using var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(5));
diff --git a/App/ViewModels/DealsViewModel.cs b/App/ViewModels/DealsViewModel.cs
index 510d88d7..06eb0dde 100644
--- a/App/ViewModels/DealsViewModel.cs
+++ b/App/ViewModels/DealsViewModel.cs
@@ -10,6 +10,7 @@ public class DealsViewModel : BaseViewModel
{
public App CurrentApp { get; }
private ObservableRangeCollection _deals = new ();
+ private ObservableRangeCollection _presearchDeals;
public ObservableRangeCollection Deals
{
@@ -39,6 +40,21 @@ public bool IsLoading
}
}
+ private ObservableRangeCollection _popularDeals = new();
+
+ public ObservableRangeCollection PopularDeals
+ {
+ get
+ {
+ return _popularDeals;
+ }
+ set
+ {
+ _popularDeals = value;
+ OnPropertyChanged(nameof(PopularDeals));
+ }
+ }
+
private bool _filtersApplied = false;
public bool FiltersApplied
{
@@ -97,7 +113,7 @@ public DealsViewModel()
CurrentApp.DataFetcher.AllDeals.Where(deal =>
deal?.DRM != null && allowedDrms.Contains(deal.DRM)
).OrderBy(d => d.Expires);
- Deals = new ObservableRangeCollection(
+ _presearchDeals = Deals = new ObservableRangeCollection(
filtersList);
FiltersApplied = true;
@@ -140,62 +156,66 @@ public ObservableCollection Platforms
}
+ ///
+ /// Reset the search to what it was initially
+ ///
+ public void ResetSearch()
+ {
+ Deals = _presearchDeals;
+ }
+
+ ///
+ /// Process a search
+ ///
+ /// input of the search
+ public void DealsSearch(string textSearch)
+ {
+ if (string.IsNullOrEmpty(textSearch))
+ {
+ ResetSearch();
+ return;
+ }
+
+ var filteredDeals = _presearchDeals.Where(deal => deal?.Title?.ToLower().Contains(textSearch.ToLower()) ?? false)?.ToList();
+
+ if (filteredDeals is null)
+ {
+ Deals = _presearchDeals;
+ return;
+ }
+
+ Deals = new(filteredDeals);
+ }
+
public async Task UpdateDeals()
{
if (!(Deals?.Count > 0))
{
- if (Preferences.Get(PreferencesKeys.DealFilterCode, null) != null)
+ string filterCode = Preferences.Get(PreferencesKeys.DealFilterCode, null);
+
+ var getTendingTask = CurrentApp.DataFetcher.GetTrendingDeals();
+ var getDealTask = CurrentApp.DataFetcher.GetDeals(filterCode);
+ await Task.WhenAll(getTendingTask, getDealTask);
+ if (filterCode != null)
{
- Deals.AddRange(new ObservableRangeCollection(
- (await CurrentApp.DataFetcher.GetDeals())
- .OrderBy(d => d.Expires)));
+
+ Deals = new(getDealTask?.Result?.OrderBy(d => d.Expires));
IsLoading = false;
FiltersApplied = true;
_setup = true;
+ PopularDeals = new((getTendingTask?.Result?.Where(dt => filterCode.Contains(dt.DRM))));
+ _presearchDeals = _deals;
return;
}
- var getTendingTask = CurrentApp.DataFetcher.GetTrendingDeals();
- var getDealTask = CurrentApp.DataFetcher.GetDeals();
-
- await foreach (var task in Task.WhenEach(getTendingTask,
- getDealTask))
- {
- await MainThread.InvokeOnMainThreadAsync(() =>
- {
- if (task == getTendingTask )
- {
- var res = getTendingTask.Result
- .Where(d => d != null)
- .OrderBy(d => d?.Expires).ToList();
- if (Deals.Count > 0)
- {
- var tendingDeals = new ObservableRangeCollection(res);
- for (int i = 0; i < tendingDeals.Count; i++)
- {
-
- Deals.Insert(i, tendingDeals[i]);
- }
-
- }
- else
- {
- Deals.AddRange(new ObservableRangeCollection(res));
- }
- }
- if (task == getDealTask)
- {
- var res = getDealTask.Result;
- if (res != null)
- Deals.AddRange(new ObservableRangeCollection(getDealTask.Result.OrderBy(d => d.Expires)));
- }
-
- });
- }
+ Deals = new (getDealTask?.Result?.OrderBy(d=> d.Expires));
+ PopularDeals = new (getTendingTask?.Result);
IsLoading = false;
_setup = true;
+
+ _presearchDeals = _deals;
return;
}
IsLoading = false;
@@ -220,5 +240,6 @@ await MainThread.InvokeOnMainThreadAsync(() =>
Deals.RemoveAt(i);
}
+ _presearchDeals = _deals;
}
}
diff --git a/App/Views/DealsPage.xaml b/App/Views/DealsPage.xaml
index c729bba5..92015a00 100644
--- a/App/Views/DealsPage.xaml
+++ b/App/Views/DealsPage.xaml
@@ -6,8 +6,8 @@
xmlns:models="clr-namespace:GamHubApp.Models"
xmlns:local="clr-namespace:GamHubApp.Models.Animations"
xmlns:viewmodels="clr-namespace:GamHubApp.ViewModels"
+ xmlns:ctrl="clr-namespace:GamHubApp.Controls"
x:DataType="viewmodels:DealsViewModel"
- xmlns:stroked="https://vapolia.eu/Vapolia.StrokedLabel"
Shell.ForegroundColor="{DynamicResource PrimaryAccent}"
Shell.BackgroundColor="{DynamicResource LightDark}"
x:Name="page">
@@ -60,6 +60,65 @@
ItemsSource="{Binding Deals}"
Margin="1,0"
>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -123,186 +182,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/App/Views/DealsPage.xaml.cs b/App/Views/DealsPage.xaml.cs
index 4b29df28..4e7aa63f 100644
--- a/App/Views/DealsPage.xaml.cs
+++ b/App/Views/DealsPage.xaml.cs
@@ -40,4 +40,21 @@ public void Resume()
{
_vm.UpdateDeals().GetAwaiter();
}
+
+ private void search_SearchButtonPressed(object sender, EventArgs e)
+ {
+ _vm.DealsSearch(search.Text);
+ search.Unfocus();
+ Dispatcher.Dispatch(async () =>
+ await search.HideSoftInputAsync(System.Threading.CancellationToken.None));
+
+ }
+
+ private void search_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ if (string.IsNullOrEmpty(search.Text))
+ {
+ _vm.ResetSearch();
+ }
+ }
}
\ No newline at end of file