diff --git a/BookAStar/BookAStar/App.xaml.cs b/BookAStar/BookAStar/App.xaml.cs index add3d1df..b0bbba9d 100644 --- a/BookAStar/BookAStar/App.xaml.cs +++ b/BookAStar/BookAStar/App.xaml.cs @@ -33,13 +33,14 @@ namespace BookAStar public static IPlatform PlatformSpecificInstance { get; set; } public static string AppName { get; set; } - + // Exists in order to dispose of a static instance strongly typed // TODO : replace all references to this field // by Views resolution, and then, drop it public static App CurrentApp { get { return Current as App; } } - public static bool MasterPresented { + public static bool MasterPresented + { get { return CurrentApp.masterDetail.IsPresented; } internal set @@ -49,7 +50,7 @@ namespace BookAStar public void Init() { var app = Resolver.Resolve(); - + if (app == null) { return; @@ -74,11 +75,11 @@ namespace BookAStar ViewFactory.Register(); ViewFactory.Register(); ViewFactory.Register(); - ConfigManager = new XLabs.Settings.GenericConfigSettingsMgr(s => - Settings.AppSettings.GetValueOrDefault(s, Settings.SettingsDefault), null); + MainSettings.AppSettings.GetValueOrDefault(s, MainSettings.SettingsDefault), null); + } - + ExtendedMasterDetailPage masterDetail; public App(IPlatform instance) @@ -110,14 +111,17 @@ namespace BookAStar home = new HomePage() { Title = "Accueil", Icon = "icon.png" }; // var mainPage = new NavigationPage(bQueriesPage); - - masterDetail = new ExtendedMasterDetailPage() { - Title="MainPage" + + masterDetail = new ExtendedMasterDetailPage() + { + Title = "MainPage" }; - masterDetail.Master = new DashboardPage { + masterDetail.Master = new DashboardPage + { Title = "Bookingstar", - BindingContext = new DashboardViewModel() }; + BindingContext = new DashboardViewModel() + }; // masterDetail.Detail = home; @@ -133,7 +137,7 @@ namespace BookAStar Text = "Accueil", Icon = "icon.png" }; - + /* var navPage = new NavigationPage(masterDetail) { Title = "Navigation", @@ -145,10 +149,10 @@ namespace BookAStar navPage.ToolbarItems.Add(tiSetts); */ this.MainPage = masterDetail; - + Resolver.Resolve() .Register(t => new NavigationService(masterDetail.Detail.Navigation)) - ; + ; } @@ -158,12 +162,12 @@ namespace BookAStar "gcm/register", PlatformSpecificInstance.GetDeviceInfo()); } - + public static void ShowBookQuery (BookQueryData query) { - var page = ViewFactory.CreatePage((b,p)=> p.BindingContext = new BookQueryViewModel(query)); - App.Current.MainPage.Navigation.PushAsync(page as Page); + var page = ViewFactory.CreatePage((b, p) => p.BindingContext = new BookQueryViewModel(query)); + App.Current.MainPage.Navigation.PushAsync(page as Page); } // TODO système de persistance de l'état de l'appli diff --git a/BookAStar/BookAStar/Helpers/MainSettings.cs b/BookAStar/BookAStar/Helpers/MainSettings.cs index 63151925..71e871d0 100644 --- a/BookAStar/BookAStar/Helpers/MainSettings.cs +++ b/BookAStar/BookAStar/Helpers/MainSettings.cs @@ -4,6 +4,7 @@ using BookAStar.Model.Auth.Account; using Newtonsoft.Json; using Plugin.Settings; using Plugin.Settings.Abstractions; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -12,63 +13,68 @@ using Xamarin.Forms; namespace BookAStar { - - /// - /// This is the Settings static class that can be used in your Core solution or in any - /// of your client applications. All settings are laid out the same exact way with getters - /// and setters. - /// - public static class MainSettings - { - - private static ISettings AppSettings { - get { - return CrossSettings.Current; - } - } - - #region Setting Constants - - private const string userNameKey = "user_id"; - private const string PushNotificationsKey = "pushNotifs"; + + /// + /// This is the Settings static class that can be used in your Core solution or in any + /// of your client applications. All settings are laid out the same exact way with getters + /// and setters. + /// + public static class MainSettings + { + + public static ISettings AppSettings + { + get + { + return CrossSettings.Current; + } + } + + #region Setting Constants + public static readonly string SettingsDefault = string.Empty; + public static readonly string EntityDataSettingsPrefix = "Ed"; + public static readonly string EntityCursorSettingsPrefix = "Ec"; + private const string userNameKey = "user_id"; + private const string PushNotificationsKey = "pushNotifs"; private const string AllowGPSUsageKey = "allowGPSUsage"; private const string UserListsKey = "userList"; private const string GoogleRegIdKey = "googleRedId"; private const string AllowProBookingOnlyKey = "allowProBookingOnly"; - - private static readonly string UserIdDefault = - string.Empty; - private static readonly bool PushNotificationsDefault = false; - public static readonly string GoogleSenderId = "325408689282"; + private static readonly string UserIdDefault = + string.Empty; + private static readonly bool PushNotificationsDefault = false; + + public static readonly string GoogleSenderId = "325408689282"; - private const string MusicalKey = "musical_prefs"; - private const string EnvironKey = "environ_prefs"; - private static readonly Dictionary MusicalDefault = - new Dictionary { - { "Pop", 0.5 }, { "Hip Hop" , 0.5 }, { "Rock" , 0.5 }, { "Funk", 0.5 }, - { "R&B", 0.5 }, { "Jazz", 0.5 } - }; + private const string MusicalKey = "musical_prefs"; + private const string EnvironKey = "environ_prefs"; + private static readonly Dictionary MusicalDefault = + new Dictionary { + { "Pop", 0.5 }, { "Hip Hop" , 0.5 }, { "Rock" , 0.5 }, { "Funk", 0.5 }, + { "R&B", 0.5 }, { "Jazz", 0.5 } + }; private static readonly Dictionary musical = new Dictionary(); - private static readonly Dictionary EnvironDefault = - new Dictionary { - { "Discothèque", 0.5 }, { "Salles de concert", 0.5 }, - { "Piano bar", 0.5 }, { "Bar", 0.5 }, { "Cinema", 0.5 }, - { "Théatre", 0.5 }, { "Salles des fêtes", 0.5 }, - { "Espace publique", 0.5 } - }; + private static readonly Dictionary EnvironDefault = + new Dictionary { + { "Discothèque", 0.5 }, { "Salles de concert", 0.5 }, + { "Piano bar", 0.5 }, { "Bar", 0.5 }, { "Cinema", 0.5 }, + { "Théatre", 0.5 }, { "Salles des fêtes", 0.5 }, + { "Espace publique", 0.5 } + }; private static readonly Dictionary environ = new Dictionary(); - #endregion + #endregion - public static string UserName + public static string UserName { - get { - return AppSettings.GetValueOrDefault(userNameKey, null); - } - } + get + { + return AppSettings.GetValueOrDefault(userNameKey, null); + } + } public const string bookQueryNotificationsKey = "BookQueryNotifications"; public static BookQueryData[] GetBookQueryNotifications() { @@ -76,7 +82,7 @@ namespace BookAStar var json = AppSettings.GetValueOrDefault(bookQueryNotificationsKey); if (!string.IsNullOrWhiteSpace(json)) return JsonConvert.DeserializeObject(json); - return new BookQueryData[] {}; + return new BookQueryData[] { }; } public static BookQueryData[] AddBookQueryNotification(BookQueryData query) @@ -89,9 +95,10 @@ namespace BookAStar return result; } - public static string GoogleRegId + public static string GoogleRegId { - set { + set + { var oldregid = GoogleRegId; AppSettings.AddOrUpdateValue(GoogleRegIdKey, value); // TODO If it changed, and there's an identified user, @@ -101,10 +108,10 @@ namespace BookAStar App.CurrentApp.PostDeviceInfo(); } } - get { return AppSettings.GetValueOrDefault(GoogleRegIdKey); } + get { return AppSettings.GetValueOrDefault(GoogleRegIdKey); } } - private static ObservableCollection accountList=null; + private static ObservableCollection accountList = null; public static ObservableCollection AccountList { get @@ -118,17 +125,19 @@ namespace BookAStar { var users = JsonConvert.DeserializeObject(json); if (users != null) - foreach (User user in users) - { - accountList.Add(user); - } + foreach (User user in users) + { + accountList.Add(user); + } } } return accountList; } } - - public static User CurrentUser { get + + public static User CurrentUser + { + get { var uname = UserName; if (uname == null) return null; @@ -166,22 +175,25 @@ namespace BookAStar public static User GetUser(string username) { - return AccountList.FirstOrDefault(a=>a.UserName == username); + return AccountList.FirstOrDefault(a => a.UserName == username); } - public static bool PushNotifications { - get { - return AppSettings.GetValueOrDefault( - PushNotificationsKey, - PushNotificationsDefault); - } - set { + public static bool PushNotifications + { + get + { + return AppSettings.GetValueOrDefault( + PushNotificationsKey, + PushNotificationsDefault); + } + set + { // TODO Stop Broadcast receiver - AppSettings.AddOrUpdateValue ( - PushNotificationsKey, - value); + AppSettings.AddOrUpdateValue( + PushNotificationsKey, + value); } - } + } public static bool AllowGPSUsage { @@ -214,28 +226,61 @@ namespace BookAStar value); } } - public static void SetMusical (string key, double value) - { - AppSettings.AddOrUpdateValue (MusicalKey + key, value); - } + public static void SetMusical(string key, double value) + { + AppSettings.AddOrUpdateValue(MusicalKey + key, value); + } - public static double GetMusical (string key) - { - return AppSettings.GetValueOrDefault (MusicalKey + key, MusicalDefault [key]); - } + public static double GetMusical(string key) + { + return AppSettings.GetValueOrDefault(MusicalKey + key, MusicalDefault[key]); + } - public static Dictionary Musical { - get { - return musical; - } - } + public static Dictionary Musical + { + get + { + return musical; + } + } - public static Dictionary Environ + public static Dictionary Environ { get { return environ; } } + /// + /// Use a sub-key to make persist different tables with the same definition. + /// + /// + /// + /// + public static void Populate(this IList collection, string subKey = null) + { + var key = $"{EntityDataSettingsPrefix}/{subKey}/{typeof(V).FullName}"; + var data = AppSettings.GetValueOrDefault(key, null); + if (data != null) + { + var items = JsonConvert.DeserializeObject>(data); + if (items != null) + foreach (var item in items) + collection.Add(item); + } + } + + /// + /// Saves a list + /// + /// + /// + /// + public static void SaveCollection(this IList collection, string subKey=null) + { + if (collection == null) return; + var key = $"{EntityDataSettingsPrefix}/{subKey}/{typeof(V).FullName}"; + AppSettings.AddOrUpdateValue(key, JsonConvert.SerializeObject(collection)); + } } } diff --git a/BookAStar/BookAStar/Helpers/Settings.cs b/BookAStar/BookAStar/Helpers/Settings.cs index 5d03245f..248312af 100644 --- a/BookAStar/BookAStar/Helpers/Settings.cs +++ b/BookAStar/BookAStar/Helpers/Settings.cs @@ -1,6 +1,5 @@ // Helpers/Settings.cs -using Plugin.Settings; -using Plugin.Settings.Abstractions; +#if USELESS_but_makes_the_component_removable // this file must exist ^^ namespace BookAStar.Helpers { @@ -23,7 +22,6 @@ namespace BookAStar.Helpers private const string SettingsKey = "settings_key"; public static readonly string SettingsDefault = string.Empty; - public static readonly string XLabsSettingsPrefix = "_XLABS_"; #endregion @@ -39,6 +37,7 @@ namespace BookAStar.Helpers AppSettings.AddOrUpdateValue(SettingsKey, value); } } - } -} \ No newline at end of file +} + +#endif \ No newline at end of file