|
|
|
|
@ -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;
|
|
|
|
|
@ -21,14 +22,18 @@ namespace BookAStar
|
|
|
|
|
public static class MainSettings
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private static ISettings AppSettings {
|
|
|
|
|
get {
|
|
|
|
|
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";
|
|
|
|
|
@ -45,13 +50,13 @@ namespace BookAStar
|
|
|
|
|
|
|
|
|
|
private const string MusicalKey = "musical_prefs";
|
|
|
|
|
private const string EnvironKey = "environ_prefs";
|
|
|
|
|
private static readonly Dictionary<string,double> MusicalDefault =
|
|
|
|
|
private static readonly Dictionary<string, double> MusicalDefault =
|
|
|
|
|
new Dictionary<string, double> {
|
|
|
|
|
{ "Pop", 0.5 }, { "Hip Hop" , 0.5 }, { "Rock" , 0.5 }, { "Funk", 0.5 },
|
|
|
|
|
{ "R&B", 0.5 }, { "Jazz", 0.5 }
|
|
|
|
|
};
|
|
|
|
|
private static readonly Dictionary<string, double> musical = new Dictionary<string, double>();
|
|
|
|
|
private static readonly Dictionary<string,double> EnvironDefault =
|
|
|
|
|
private static readonly Dictionary<string, double> EnvironDefault =
|
|
|
|
|
new Dictionary<string, double> {
|
|
|
|
|
{ "Discothèque", 0.5 }, { "Salles de concert", 0.5 },
|
|
|
|
|
{ "Piano bar", 0.5 }, { "Bar", 0.5 }, { "Cinema", 0.5 },
|
|
|
|
|
@ -65,7 +70,8 @@ namespace BookAStar
|
|
|
|
|
|
|
|
|
|
public static string UserName
|
|
|
|
|
{
|
|
|
|
|
get {
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return AppSettings.GetValueOrDefault<string>(userNameKey, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -76,7 +82,7 @@ namespace BookAStar
|
|
|
|
|
var json = AppSettings.GetValueOrDefault<string>(bookQueryNotificationsKey);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(json))
|
|
|
|
|
return JsonConvert.DeserializeObject<BookQueryData[]>(json);
|
|
|
|
|
return new BookQueryData[] {};
|
|
|
|
|
return new BookQueryData[] { };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BookQueryData[] AddBookQueryNotification(BookQueryData query)
|
|
|
|
|
@ -91,7 +97,8 @@ namespace BookAStar
|
|
|
|
|
|
|
|
|
|
public static string GoogleRegId
|
|
|
|
|
{
|
|
|
|
|
set {
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
var oldregid = GoogleRegId;
|
|
|
|
|
AppSettings.AddOrUpdateValue<string>(GoogleRegIdKey, value);
|
|
|
|
|
// TODO If it changed, and there's an identified user,
|
|
|
|
|
@ -104,7 +111,7 @@ namespace BookAStar
|
|
|
|
|
get { return AppSettings.GetValueOrDefault<string>(GoogleRegIdKey); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static ObservableCollection<User> accountList=null;
|
|
|
|
|
private static ObservableCollection<User> accountList = null;
|
|
|
|
|
public static ObservableCollection<User> AccountList
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
@ -128,7 +135,9 @@ namespace BookAStar
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static User CurrentUser { get
|
|
|
|
|
public static User CurrentUser
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var uname = UserName;
|
|
|
|
|
if (uname == null) return null;
|
|
|
|
|
@ -166,18 +175,21 @@ 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 {
|
|
|
|
|
public static bool PushNotifications
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return AppSettings.GetValueOrDefault<bool>(
|
|
|
|
|
PushNotificationsKey,
|
|
|
|
|
PushNotificationsDefault);
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
// TODO Stop Broadcast receiver
|
|
|
|
|
AppSettings.AddOrUpdateValue<bool> (
|
|
|
|
|
AppSettings.AddOrUpdateValue<bool>(
|
|
|
|
|
PushNotificationsKey,
|
|
|
|
|
value);
|
|
|
|
|
}
|
|
|
|
|
@ -214,18 +226,20 @@ namespace BookAStar
|
|
|
|
|
value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static void SetMusical (string key, double value)
|
|
|
|
|
public static void SetMusical(string key, double value)
|
|
|
|
|
{
|
|
|
|
|
AppSettings.AddOrUpdateValue <double> (MusicalKey + key, value);
|
|
|
|
|
AppSettings.AddOrUpdateValue<double>(MusicalKey + key, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double GetMusical (string key)
|
|
|
|
|
public static double GetMusical(string key)
|
|
|
|
|
{
|
|
|
|
|
return AppSettings.GetValueOrDefault <double> (MusicalKey + key, MusicalDefault [key]);
|
|
|
|
|
return AppSettings.GetValueOrDefault<double>(MusicalKey + key, MusicalDefault[key]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Dictionary<string,double> Musical {
|
|
|
|
|
get {
|
|
|
|
|
public static Dictionary<string, double> Musical
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return musical;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -237,5 +251,36 @@ namespace BookAStar
|
|
|
|
|
return environ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use a sub-key to make persist different tables with the same definition.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="V"></typeparam>
|
|
|
|
|
/// <param name="collection"></param>
|
|
|
|
|
/// <param name="subKey"></param>
|
|
|
|
|
public static void Populate<V>(this IList<V> collection, string subKey = null)
|
|
|
|
|
{
|
|
|
|
|
var key = $"{EntityDataSettingsPrefix}/{subKey}/{typeof(V).FullName}";
|
|
|
|
|
var data = AppSettings.GetValueOrDefault<string>(key, null);
|
|
|
|
|
if (data != null)
|
|
|
|
|
{
|
|
|
|
|
var items = JsonConvert.DeserializeObject<IList<V>>(data);
|
|
|
|
|
if (items != null)
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
collection.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves a list
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="V"></typeparam>
|
|
|
|
|
/// <param name="collection"></param>
|
|
|
|
|
/// <param name="subKey"></param>
|
|
|
|
|
public static void SaveCollection<V>(this IList<V> collection, string subKey=null)
|
|
|
|
|
{
|
|
|
|
|
if (collection == null) return;
|
|
|
|
|
var key = $"{EntityDataSettingsPrefix}/{subKey}/{typeof(V).FullName}";
|
|
|
|
|
AppSettings.AddOrUpdateValue(key, JsonConvert.SerializeObject(collection));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|