diff --git a/.gitignore b/.gitignore index 4ce6fdde..27d67480 100644 --- a/.gitignore +++ b/.gitignore @@ -337,4 +337,5 @@ ASALocalRun/ .localhistory/ # BeatPulse healthcheck temp database -healthchecksdb \ No newline at end of file +healthchecksdb +/AresNews/AresNews/Config/AppSettings.json diff --git a/AresNews/AresNews.Android/AresNews.Android.csproj b/AresNews/AresNews.Android/AresNews.Android.csproj index 0d509f0e..f887bf70 100644 --- a/AresNews/AresNews.Android/AresNews.Android.csproj +++ b/AresNews/AresNews.Android/AresNews.Android.csproj @@ -150,6 +150,7 @@ + diff --git a/AresNews/AresNews.Android/appcenter-pre-build.sh b/AresNews/AresNews.Android/appcenter-pre-build.sh new file mode 100644 index 00000000..719cf85f --- /dev/null +++ b/AresNews/AresNews.Android/appcenter-pre-build.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +echo "Launching Android pre-build script" +if [ -z "$discord_client_id" ] +then + echo "You need define the discord_client_id variable in App Center" + exit +fi +if [ -z "$api_host" ] +then + echo "You need define the api_host variable in App Center" + exit +fi + +APP_CONSTANT_FILE=$APPCENTER_SOURCE_DIRECTORY/AresNews/AresNews/Core/AppConstant.cs + +if [ -e "$APP_CONSTANT_FILE" ] +then + echo "Updating AppConstant.cs" + echo "---" + echo "DiscordClientId = "$discord_client_id + sed -i '' 's#DiscordClientId = Environment.GetEnvironmentVariable("discord_client_id")#DiscordClientId = "'$discord_client_id'"#g' $APP_CONSTANT_FILE + echo "ApiHost = "$api_host + sed -i '' 's#ApiHost = Environment.GetEnvironmentVariable("api_host")#ApiHost = "'$api_host'"#g' $APP_CONSTANT_FILE + echo "File content:" + cat $APP_CONSTANT_FILE +else + echo "Incorrect file: "$APP_CONSTANT_FILE + exit +fi \ No newline at end of file diff --git a/AresNews/AresNews.iOS/AresNews.iOS.csproj b/AresNews/AresNews.iOS/AresNews.iOS.csproj index 18ae3afb..93c874a7 100644 --- a/AresNews/AresNews.iOS/AresNews.iOS.csproj +++ b/AresNews/AresNews.iOS/AresNews.iOS.csproj @@ -103,6 +103,7 @@ + diff --git a/AresNews/AresNews.iOS/appcenter-pre-build.sh b/AresNews/AresNews.iOS/appcenter-pre-build.sh new file mode 100644 index 00000000..a2ede3b6 --- /dev/null +++ b/AresNews/AresNews.iOS/appcenter-pre-build.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# +# For Xamarin, change some constants located in some class of the app. +# In this sample, suppose we have an AppConstant.cs class in shared folder with follow content: +# +# namespace Core +# { +# public class AppConstant +# { +# public const string ApiUrl = "https://CMS_MyApp-Eur01.com/api"; +# } +# } +# +# Suppose in our project exists two branches: master and develop. +# We can release app for production API in master branch and app for test API in develop branch. +# We just need configure this behaviour with environment variable in each branch :) +# +# The same thing can be perform with any class of the app. +# +# AN IMPORTANT THING: FOR THIS SAMPLE YOU NEED DECLARE API_URL ENVIRONMENT VARIABLE IN APP CENTER BUILD CONFIGURATION. +echo "Launching ios pre-build script" +if [ -z "$discord_client_id" ] +then + echo "You need define the discord_client_id variable in App Center" + exit +fi + +if [ -z "$api_host" ] +then + echo "You need define the api_host variable in App Center" + exit +fi + +APP_CONSTANT_FILE=$APPCENTER_SOURCE_DIRECTORY/AresNews/AresNews/Core/AppConstant.cs + +if [ -e "$APP_CONSTANT_FILE" ] +then + echo "Updating AppConstant.cs" + echo "---" + echo "DiscordClientId = "$discord_client_id + sed -i '' 's#DiscordClientId = Environment.GetEnvironmentVariable("discord_client_id")#DiscordClientId = "'$discord_client_id'"#g' $APP_CONSTANT_FILE + echo "ApiHost = "$api_host + sed -i '' 's#ApiHost = Environment.GetEnvironmentVariable("api_host")#ApiHost = "'$api_host'"#g' $APP_CONSTANT_FILE + + echo "File content:" + cat $APP_CONSTANT_FILE +else + echo "Incorrect file: "$APP_CONSTANT_FILE + exit +fi \ No newline at end of file diff --git a/AresNews/AresNews/App.xaml b/AresNews/AresNews/App.xaml index e5383325..ad79e031 100644 --- a/AresNews/AresNews/App.xaml +++ b/AresNews/AresNews/App.xaml @@ -5,7 +5,7 @@ x:Class="AresNews.App"> - #84D1AC + #4AC776 #528e70 #1DB954 #666666 @@ -13,14 +13,10 @@ #191414 #4A4A4A #404348 - #9FDBBE + #8EDCA9 #ecebeb #262626 - + #5d6af2 diff --git a/AresNews/AresNews/App.xaml.cs b/AresNews/AresNews/App.xaml.cs index 14f2e78d..174c2acc 100644 --- a/AresNews/AresNews/App.xaml.cs +++ b/AresNews/AresNews/App.xaml.cs @@ -2,10 +2,9 @@ using AresNews.Services; using AresNews.ViewModels; using AresNews.Views; +using AresNews.Core; using AresNews.Views.PopUps; using CustardApi.Objects; -using FFImageLoading; -using Newtonsoft.Json; using Rg.Plugins.Popup.Exceptions; using Rg.Plugins.Popup.Extensions; using Rg.Plugins.Popup.Pages; @@ -13,24 +12,16 @@ using System; using System.Collections.ObjectModel; using System.IO; -using System.Linq; -using System.Reflection; using System.Threading.Tasks; -using Xamarin.Essentials; using Xamarin.Forms; -using Xamarin.Forms.Xaml; - -[assembly: ExportFont("FontAwesome6Free-Regular-400.otf", Alias = "FaRegular")] -[assembly: ExportFont("FontAwesome6Brands-Regular-400.otf", Alias = "FaBrand")] -[assembly: ExportFont("FontAwesome6Free-Solid-900.otf", Alias = "FaSolid")] -[assembly: ExportFont("Ubuntu-Regular.ttf", Alias = "P-Regular")] -[assembly: ExportFont("Ubuntu-Bold.ttf", Alias = "P-Bold")] -[assembly: ExportFont("Ubuntu-Medium.otf", Alias = "P-SemiBold")] +using Xamarin.Essentials; +using Newtonsoft.Json; + namespace AresNews { public partial class App : Application { - private bool _isLoading; + public bool IsLoading { get; private set; } public static Collection Sources { get; private set; } // Property SqlLite Connection @@ -42,7 +33,7 @@ public partial class App : Application public Fetcher DataFetcher { get; set; } public static string ProdHost { get; } = "api.gamhub.io"; public static string LocalHost { get; } = "gamhubdev.ddns.net"; - + public User SaveInfo { get; private set; } public enum PageType { @@ -51,21 +42,24 @@ public enum PageType bookmark, news, source - - } public App() { #if __LOCAL__ // Set webservice - WService = new Service(host: "gamhubdev.ddns.net", + WService = new Service(host: LocalHost, port: 255, sslCertificate: false); #else - // Set webservice + // Set webservice WService = new Service(host: ProdHost, sslCertificate: true); #endif + +#if DEBUG + // Run the debug setup + EnvironementSetup.DebugSetup(); +#endif DataFetcher = new Fetcher(); Sharpnado.Tabs.Initializer.Initialize(false, false); @@ -106,24 +100,22 @@ public App() // Close the db //CloseDb(); - MainPage = new AppShell(); - } /// /// Show the popup loading indicator /// - public async void ShowLoadingIndicator(bool longer = false) + public void ShowLoadingIndicator() { try { - if (_isLoading) + if (IsLoading) return; - _isLoading = true; + IsLoading = true; - await this.MainPage.Navigation.PushPopupAsync(this.LoadingIndicator); + OpenPopUp (this.LoadingIndicator); } catch (RGPageInvalidException) { @@ -134,17 +126,18 @@ public async void ShowLoadingIndicator(bool longer = false) /// /// Remove the popup loading indicator /// - public async void RemoveLoadingIndicator() + public void RemoveLoadingIndicator() { try { - if (!_isLoading) + if (!IsLoading) return; - _isLoading = false; - //if (this.MainPage.Navigation.ModalStack.Contains(this.LoadingIndicator)) - await this.MainPage.Navigation.RemovePopupPageAsync(this.LoadingIndicator); + IsLoading = false; + + // Close the popup + ClosePopUp (this.LoadingIndicator); } catch (RGPageInvalidException) { @@ -199,6 +192,11 @@ public static async void StartDb() protected override void OnStart() { + // Restore session + _ = DataFetcher.RestoreSession(); + + + MainPage = new AppShell(); } protected override void OnSleep() @@ -234,5 +232,131 @@ protected override void OnResume() StartDb(); } + /// + /// Open any popup + /// + /// pop up to open + /// parent page + public void OpenPopUp(PopupPage popUp, Page page = null) + { + try + { + + if (popUp == null) + return; + + if (page == null) + page = GetCurrentPage(); + + _ = page.Navigation.PushPopupAsync(popUp); + } + catch (Exception ex) + { +#if DEBUG + throw ex; +#endif + } + } + /// + /// Close any popup + /// + /// pop up to open + /// parent page + public void ClosePopUp(PopupPage popUp, Page page = null) + { + try + { + + if (popUp == null) + return; + + if (page == null) + page = GetCurrentPage(); + + _ = page.Navigation.RemovePopupPageAsync(popUp); + } + catch (Exception ex) + { +#if DEBUG + throw ex; +#endif + } + } + /// + /// Get the current page from the shell + /// + /// + private Page GetCurrentPage () + { + AppShell mainPage = ((AppShell)MainPage); + return mainPage.CurrentPage; + } + /// + /// Save the info relevant to the user + /// + public void SaveUserInfo(User user) + { + SaveInfo = user; + + // Save preferences + Preferences.Set(nameof(SaveInfo), JsonConvert.SerializeObject(SaveInfo)); + } + /// + /// Save the info relevant to the user + /// + public void DeleteUserInfo() + { + // Save preferences + Preferences.Remove(nameof(SaveInfo)); + } + /// + /// Recover the info relevant to the user + /// + /// true: data found | false: data not found + public bool RecoverUserInfo() + { + + // Get preferences + string userDataStr = Preferences.Get(nameof(SaveInfo), string.Empty); + + if (string.IsNullOrEmpty(userDataStr)) + return false; + + // Set Userdata object + return (SaveInfo = DataFetcher.UserData = JsonConvert.DeserializeObject(userDataStr)) != null; + } + /// + /// Log out the current active user + /// + public void LogoutCurrentAccount() + { + // Delete user data + DeleteUserInfo(); + + // Close the current session + DataFetcher.KillSession(); + } + /// + /// Show a pop up to confirm wether or not the user wants to logout + /// + /// user + /// true: confirm | false: cancel + public async Task ShowLogoutConfirmation(User user = null) + { + if (user == null) + user = SaveInfo; + + LogoutConfirmationPopUp popUp = new(user); + OpenPopUp(popUp); + + // Wait for a response + while (popUp.Result == null) + await Task.Delay(10); + + // in any case close the pop up after receiving a response + ClosePopUp(popUp); + + return popUp.Result ?? false; + } } } diff --git a/AresNews/AresNews/AppShell.xaml b/AresNews/AresNews/AppShell.xaml index 9394f61c..9577b1d0 100644 --- a/AresNews/AresNews/AppShell.xaml +++ b/AresNews/AresNews/AppShell.xaml @@ -14,6 +14,28 @@ xmlns:xct="http://xamarin.com/schemas/2020/toolkit" xmlns:viewmodels="clr-namespace:AresNews.ViewModels"> + + + + - - + + + + + + + + @@ -155,7 +195,7 @@ - @@ -168,63 +208,45 @@ - + - --> + + +