Version 3.0.346

This commit is contained in:
Oliver Hauff 2022-10-17 18:45:38 +02:00
parent 1ba809dd59
commit 47c03f43fb
43 changed files with 609 additions and 117 deletions

View file

@ -0,0 +1,9 @@
namespace TINK.Model.Settings
{
/// <summary> Settings determining the startup behavior of the app. </summary>
public interface IStartupSettings
{
/// <summary> Holds the page to show when apps starts. </summary>
ViewTypes StartupPage { get; set; }
}
}

View file

@ -1,6 +1,7 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Serilog.Events;
@ -39,6 +40,9 @@ namespace TINK.Model.Settings
/// <summary> Key of the center to ... entry. </summary>
public const string CENTERMAPTOCURRENTLOCATION = "CenterMapToCurrentLocation";
/// <summary> Key of the center to ... entry. </summary>
public const string STARTUPSETTINGS = "StartupSettings";
public const string LOGTOEXTERNALFOLDER = "LogToExternalFolder";
public const string THEMEKEY = "Theme";
@ -49,7 +53,7 @@ namespace TINK.Model.Settings
/// <param name="settingsJSON">Dictionary to get value from.</param>
public static T? GetNullableEntry<T>(
string keyName,
Dictionary<string, string> settingsJSON) where T : struct
IDictionary<string, string> settingsJSON) where T : struct
{
if (!settingsJSON.TryGetValue(keyName, out string boolText)
|| string.IsNullOrEmpty(boolText))
@ -65,7 +69,7 @@ namespace TINK.Model.Settings
/// <param name="settingsJSON">Dictionary to get value from.</param>
public static T GetEntry<T>(
string keyName,
Dictionary<string, string> settingsJSON,
IDictionary<string, string> settingsJSON,
Func<string, string> legacyValueConverter = null) where T : class
{
if (string.IsNullOrEmpty(keyName)
@ -465,7 +469,7 @@ namespace TINK.Model.Settings
public static bool? GetIsSiteCachingOn(Dictionary<string, string> settingsJSON) => GetNullableEntry<bool>(ISSITECACHINGON, settingsJSON);
/// <summary> Sets whether to store logging data on SD card or not.</summary>
/// <param name="settingsJSON">Dictionary to get value from.</param>
/// <param name="settingsJSON">Dictionary to write value to.</param>
public static Dictionary<string, string> SetLogToExternalFolder(this IDictionary<string, string> targetDictionary, bool useSdCard) => SetEntry(useSdCard, LOGTOEXTERNALFOLDER, targetDictionary);
/// <summary> Sets active theme.</summary>
@ -550,5 +554,28 @@ namespace TINK.Model.Settings
settings["FilterCollection"] = JsonConvert.SerializeObject(p_oFilterCollection);
return settings;
}
/// <summary>
/// Gets the startup settings from dictionary.
/// </summary>
/// <param name="settings">Settings objet to load from.</param>
public static StartupSettings GetStartupSettings(this IDictionary<string, string> settingsJSON)
=> GetEntry<StartupSettings>(STARTUPSETTINGS, settingsJSON) ?? new StartupSettings();
/// <summary> Sets the startup settings.</summary>
/// <param name="settingsJSON">Dictionary to write value to.</param>
public static IDictionary<string, string> SetStartupSettings(
this IDictionary<string, string> settingsJSON,
IStartupSettings startupSettings)
{
if (settingsJSON == null
|| startupSettings == null)
{
return settingsJSON;
}
settingsJSON[STARTUPSETTINGS] = JsonConvert.SerializeObject(startupSettings);
return settingsJSON;
}
}
}

View file

@ -1,4 +1,4 @@
using System;
using System;
using Serilog.Events;
using TINK.Services.BluetoothLock;
using TINK.Services.CopriApi.ServerUris;
@ -27,6 +27,7 @@ namespace TINK.Model.Settings
/// <summary> Constructs settings object. </summary>
/// <param name="groupFilterMapPage">filter which is applied on the map view. Either TINK or Konrad stations are displayed.</param>
/// <param name="groupFilterSettings"></param>
/// <param name="startupSettings">Settings determining the startup behavior of the app.</param>
/// <param name="activeUri"></param>
/// <param name="pollingParameters"></param>
/// <param name="minimumLogEventLevel">Minimum logging level to be applied.</param>
@ -38,6 +39,7 @@ namespace TINK.Model.Settings
public Settings(
IGroupFilterMapPage groupFilterMapPage = null,
IGroupFilterSettings groupFilterSettings = null,
IStartupSettings startupSettings = null,
Uri activeUri = null,
PollingParameters pollingParameters = null,
LogEventLevel? minimumLogEventLevel = null,
@ -54,6 +56,7 @@ namespace TINK.Model.Settings
{
GroupFilterMapPage = groupFilterMapPage ?? new GroupFilterMapPage(); // Default behaviour: No filtering.
GroupFilterSettings = groupFilterSettings ?? new GroupFilterSettings(); // Default behaviour: No filtering.
StartupSettings = startupSettings ?? new StartupSettings();
ActiveUri = GetActiveUri(activeUri);
PollingParameters = pollingParameters ?? PollingParameters.Default;
MinimumLogEventLevel = minimumLogEventLevel ?? DEFAULTLOGGINLEVEL;
@ -75,6 +78,9 @@ namespace TINK.Model.Settings
/// <summary> Holds the filters loaded from settings. </summary>
public IGroupFilterSettings GroupFilterSettings { get; }
/// <summary> Holds the stettings determining app startup behavior. </summary>
public IStartupSettings StartupSettings { get; }
/// <summary> Holds the uri to connect to. </summary>
public Uri ActiveUri { get; }

View file

@ -0,0 +1,11 @@
namespace TINK.Model.Settings
{
/// <summary> Settings determining the startup behavior of the app. </summary>
public class StartupSettings : IStartupSettings
{
public static ViewTypes DefaultStartupPage => ViewTypes.MapPage;
/// <summary> Holds the page to show when apps starts. </summary>
public ViewTypes StartupPage { get; set; } = DefaultStartupPage;
}
}