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
36 changes: 1 addition & 35 deletions App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public partial class App : Application
public User SaveInfo { get; private set; }
public Collection<Partner> Partners { get; private set; }
public Collection<Deal> Deals { get; private set; }
public string InstanceID { get; set; }

/// <summary>
/// Date first registered to determin when is the best time to ask for user review
/// </summary>
Expand Down Expand Up @@ -141,7 +141,6 @@ private async Task RecoverFromOffline()

protected override void OnStart()
{
SetupInstance().GetAwaiter();

Task.Run(RecoverFromOffline);

Expand Down Expand Up @@ -316,39 +315,6 @@ await Snackbar.Make(message,
actionButtonText: "contact support").Show();
}

/// <summary>
/// Setup the instance for a device
/// </summary>
/// <returns>a task returning the id of the instance</returns>
public async Task<string> SetupInstance()
{

#if IOS
string instanceID = await SecureStorage.Default.GetAsync(AppConstant.InstanceIdKey);
if (string.IsNullOrEmpty(instanceID))
{
await SecureStorage.Default.SetAsync(AppConstant.InstanceIdKey, instanceID = UIKit.UIDevice.CurrentDevice.IdentifierForVendor.ToString().ToLower().Replace("-", string.Empty).Substring(0,30));

}

#if DEBUG
Debug.WriteLine($"Instance: {instanceID}");
#endif
return
#endif
InstanceID =
#if ANDROID
Secure.GetString(Android.App.Application.Context.ContentResolver, Secure.AndroidId);
#if DEBUG
Debug.WriteLine($"Instance: {InstanceID}");
#endif
await SecureStorage.Default.SetAsync(AppConstant.InstanceIdKey, InstanceID);
return InstanceID;
#elif IOS
instanceID;
#endif

}
/// <summary>
/// Load all the partners
/// </summary>
Expand Down
52 changes: 49 additions & 3 deletions App/Services/Fetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
using Plugin.FirebasePushNotifications;
using System.Net.Sockets;

#if ANDROID
using static Android.Provider.Settings;
#endif

#if IOS
using Maui.RevenueCat.InAppBilling.Services;
Expand All @@ -23,6 +26,8 @@
public static string ProdHost { get; } = "api.gamhub.io";
private static string _dateFormat = "dd-MM-yyy_HH:mm:ss";
private Session CurrentSession { get; set; }

public string InstanceID { get; set; }
public Service WebService { get; private set; }
public static Collection<Source> Sources { get; set; }

Expand Down Expand Up @@ -52,7 +57,7 @@
public string PlatformsStr { get; private set; }

#if IOS
private readonly IRevenueCatBilling _revenueCatBilling;

Check warning on line 60 in App/Services/Fetcher.cs

View workflow job for this annotation

GitHub Actions / build-ios / iOS Publish

The field 'Fetcher._revenueCatBilling' is never used
#endif
public Fetcher(GeneralDataBase generalDataBase,
BackUpDataBase backUpDataBase,
Expand All @@ -70,12 +75,19 @@
_generalDB = generalDataBase;
_backupDB = backUpDataBase;
_firebasePushPermissions = notificationPermissions;
}

Task.WhenAll([
/// <summary>
/// Initialised all the data needed to move forward
/// </summary>
/// <returns></returns>
public async Task DataInit()
{
await Task.WhenAll([
GetSources(),
SetCultureInfo(),
GetDRMs()
]).GetAwaiter();
]);
}

/// <summary>
Expand Down Expand Up @@ -330,7 +342,7 @@
cancellationToken: cts.Token,
unSuccessCallback: e => _ = HandleHttpException(e)))?? [];
}
catch (Exception ex)

Check warning on line 345 in App/Services/Fetcher.cs

View workflow job for this annotation

GitHub Actions / build-android / Android Publish

The variable 'ex' is declared but never used

Check warning on line 345 in App/Services/Fetcher.cs

View workflow job for this annotation

GitHub Actions / build-ios / iOS Publish

The variable 'ex' is declared but never used
{
#if DEBUG
Debug.WriteLine(ex);
Expand Down Expand Up @@ -405,7 +417,7 @@
parameters: parameters,jsonBody: null,
unSuccessCallback: e => _ = HandleHttpException(e))));
}
catch (Exception ex)

Check warning on line 420 in App/Services/Fetcher.cs

View workflow job for this annotation

GitHub Actions / build-android / Android Publish

The variable 'ex' is declared but never used

Check warning on line 420 in App/Services/Fetcher.cs

View workflow job for this annotation

GitHub Actions / build-ios / iOS Publish

The variable 'ex' is declared but never used
{
#if DEBUG
Debug.WriteLine(ex);
Expand Down Expand Up @@ -448,7 +460,7 @@
return [];
return new ([.. articleTrends]);
}
catch (Exception ex)

Check warning on line 463 in App/Services/Fetcher.cs

View workflow job for this annotation

GitHub Actions / build-android / Android Publish

The variable 'ex' is declared but never used

Check warning on line 463 in App/Services/Fetcher.cs

View workflow job for this annotation

GitHub Actions / build-ios / iOS Publish

The variable 'ex' is declared but never used
{
#if DEBUG
Debug.WriteLine(ex);
Expand Down Expand Up @@ -496,7 +508,7 @@
return new ([.. dealTrends]);

}
catch (Exception ex)

Check warning on line 511 in App/Services/Fetcher.cs

View workflow job for this annotation

GitHub Actions / build-android / Android Publish

The variable 'ex' is declared but never used

Check warning on line 511 in App/Services/Fetcher.cs

View workflow job for this annotation

GitHub Actions / build-ios / iOS Publish

The variable 'ex' is declared but never used
{
#if DEBUG
Debug.WriteLine(ex);
Expand Down Expand Up @@ -1062,7 +1074,7 @@
if (string.IsNullOrEmpty(instanceID))
{
// Reissue an instanceID
instanceID = await (App.Current as App).SetupInstance();
instanceID = await SetupInstance();
}
#if DEBUG
Debug.WriteLine($"ApiKey: {apiKey}");
Expand All @@ -1087,6 +1099,40 @@
}

/// <summary>
/// Setup the instance for a device
/// </summary>
/// <returns>a task returning the id of the instance</returns>
public async Task<string> SetupInstance()
{

#if IOS
string instanceID = await SecureStorage.Default.GetAsync(AppConstant.InstanceIdKey);
if (string.IsNullOrEmpty(instanceID))
{
await SecureStorage.Default.SetAsync(AppConstant.InstanceIdKey, instanceID = UIKit.UIDevice.CurrentDevice.IdentifierForVendor.ToString().ToLower().Replace("-", string.Empty).Substring(0,30));

}

#if DEBUG
Debug.WriteLine($"Instance: {instanceID}");
#endif
return
#endif
InstanceID =
#if ANDROID
Secure.GetString(Android.App.Application.Context.ContentResolver, Secure.AndroidId);
#if DEBUG
Debug.WriteLine($"Instance: {InstanceID}");
#endif
await SecureStorage.Default.SetAsync(AppConstant.InstanceIdKey, InstanceID);
return InstanceID;
#elif IOS
instanceID;
#endif
}


/// <summary>
/// Adding a hook to an article
/// </summary>
/// <param name="article">article hooked</param>
Expand Down
1 change: 1 addition & 0 deletions App/ViewModels/AppShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public AppShellViewModel(Fetcher fetc,
Task.Run(async () =>
{
await Task.WhenAll(
dataFetcher.DataInit(),
Task.Run(async () =>
{
DonationEnabled = (await fetc.GetGlobalSettings())?.DonationEnabled ?? false;
Expand Down
36 changes: 31 additions & 5 deletions App/ViewModels/NewsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ public ObservableRangeCollection<Article> Articles
{
get
{
ObservableRangeCollection<Article> upArticles = new();
ObservableRangeCollection<Article> upArticles = [];

try
{
for (int i = 0; i < _articles?.Count; i++)
{
var article = _articles[i];
Expand All @@ -199,6 +201,18 @@ public ObservableRangeCollection<Article> Articles
if (article.Source?.IsSelected ?? true)
upArticles.Add(article);
}

}

catch (Exception ex)
{
#if DEBUG
Debug.WriteLine(ex);

#else
SentrySdk.CaptureException(ex);
#endif
}
return upArticles;
}
set
Expand All @@ -212,13 +226,15 @@ public ObservableRangeCollection<Article> Articles
SetProperty(ref _articles, value);
}
}
private ObservableCollection<Article> _trendingArticles = new();
private ObservableCollection<Article> _trendingArticles = [];

public ObservableCollection<Article> TrendingArticles
{
get
{
ObservableRangeCollection<Article> upArticles = new();
ObservableRangeCollection<Article> upArticles = [];
try
{
for (int i = 0; i < _trendingArticles?.Count; i++)
{
var article = _trendingArticles[i];
Expand All @@ -230,6 +246,16 @@ public ObservableCollection<Article> TrendingArticles
if (article.Source?.IsSelected ?? true)
upArticles.Add(article);
}
}
catch (Exception ex)
{
#if DEBUG
Debug.WriteLine(ex);

#else
SentrySdk.CaptureException(ex);
#endif
}
return upArticles;
}
set
Expand Down Expand Up @@ -335,7 +361,7 @@ public bool IsSearchLoading
}
public bool IsLoadingChunks { get; private set; }

private List<Source> _sources;
private List<Source> _sources = [];

public List<Source> Sources
{
Expand Down Expand Up @@ -797,8 +823,8 @@ public async Task Resume()
else
RefreshFeed.Execute(_isSearching);
#endif
Sources = await _generalDB.GetSources();
}
Sources = await _generalDB.GetSources();

await FetchTrendingArticles();

Expand Down
Loading