using System;
using Serilog.Events;
using TINK.Services.BluetoothLock;
using TINK.Services.CopriApi.ServerUris;
using TINK.Services.Geolocation;
using TINK.Settings;
using TINK.ViewModel.Map;
using TINK.ViewModel.Settings;
namespace TINK.Model.Settings
{
/// Holds settings which are persisted.
public class Settings
{
public const LogEventLevel DEFAULTLOGGINLEVEL = LogEventLevel.Error;
public const bool DEFAULTREPOTLEVEL = false;
/// Gets the type of the default geolocation service.
/// Switched from GeolocationService (GeolocationAccuracyMediumService) to GeolocationAccuracyHighService in app version 3.0.290.
public static Type DefaultLocationService => typeof(GeolocationAccuracyHighService);
// Default value of the expires after entry. Controls the expiration time of the cache values.
private TimeSpan DEFAULTEXPIRESAFTER = TimeSpan.FromSeconds(1);
/// Constructs settings object.
/// filter which is applied on the map view. Either TINK or Konrad stations are displayed.
///
/// Settings determining the startup behavior of the app.
///
///
/// Minimum logging level to be applied.
/// True if logging level is verbose.
/// Holds the expires after value.
/// Gets the name of the lock service to use.
/// Timeout to apply when connecting to bluetooth lock
/// Full class name of active app theme.
public Settings(
IGroupFilterMapPage groupFilterMapPage = null,
IGroupFilterSettings groupFilterSettings = null,
IStartupSettings startupSettings = null,
Uri activeUri = null,
PollingParameters pollingParameters = null,
LogEventLevel? minimumLogEventLevel = null,
bool? isReportLevelVerbose = null,
TimeSpan? expiresAfter = null,
string activeLockService = null,
TimeSpan? connectTimeout = null,
string activeGeolocationService = null,
bool? centerMapToCurrentLocation = null,
Xamarin.Forms.GoogleMaps.MapSpan mapSpan = null,
bool? logToExternalFolder = null,
bool? isSiteCachingOn = null,
string activeTheme = null)
{
GroupFilterMapPage = groupFilterMapPage ?? new GroupFilterMapPage(); // Default behavior: No filtering.
GroupFilterSettings = groupFilterSettings ?? new GroupFilterSettings(); // Default behavior: No filtering.
StartupSettings = startupSettings ?? new StartupSettings();
ActiveUri = GetActiveUri(activeUri);
PollingParameters = pollingParameters ?? PollingParameters.Default;
MinimumLogEventLevel = minimumLogEventLevel ?? DEFAULTLOGGINLEVEL;
IsReportLevelVerbose = isReportLevelVerbose ?? DEFAULTREPOTLEVEL;
ExpiresAfter = expiresAfter ?? DEFAULTEXPIRESAFTER;
ActiveLockService = activeLockService ?? LocksServicesContainerMutable.DefaultLocksservice;
ConnectTimeout = connectTimeout ?? new TimeSpan(0, 0, TimeOutProvider.DEFAULT_BLUETOOTHCONNECT_TIMEOUTSECONDS); // Try one sec. to connect.
ActiveGeolocationService = activeGeolocationService ?? DefaultLocationService.FullName;
CenterMapToCurrentLocation = centerMapToCurrentLocation ?? GetCenterMapToCurrentLocation(activeUri);
MapSpan = mapSpan;
LogToExternalFolder = logToExternalFolder ?? false;
IsSiteCachingOn = isSiteCachingOn ?? true;
ActiveTheme = activeTheme ?? typeof(Themes.ShareeBike).Name;
}
/// Holds the filter which is applied on the map view. Either TINK or Konrad stations are displayed.
public IGroupFilterMapPage GroupFilterMapPage { get; }
/// Holds the filters loaded from settings.
public IGroupFilterSettings GroupFilterSettings { get; }
/// Holds the settings determining app startup behavior.
public IStartupSettings StartupSettings { get; }
/// Holds the uri to connect to.
public Uri ActiveUri { get; }
/// Holds the polling parameters.
public PollingParameters PollingParameters { get; }
/// Gets the minimum logging level.
public LogEventLevel MinimumLogEventLevel { get; }
/// Gets the expires after value.
public TimeSpan ExpiresAfter { get; }
/// Gets the lock service to use.
public string ActiveLockService { get; private set; }
/// Timeout to apply when connecting to bluetooth lock.
public TimeSpan ConnectTimeout { get; }
/// Gets the geolocation service to use.
public string ActiveGeolocationService { get; }
/// True if map is centered to current position, false if not to center map.
public bool CenterMapToCurrentLocation { get; }
/// Holds the map area to display.
public Xamarin.Forms.GoogleMaps.MapSpan MapSpan { get; }
public bool LogToExternalFolder { get; }
public bool IsSiteCachingOn { get; }
public string ActiveTheme { get; }
/// Gets a value indicating whether reporting level is verbose or not.
public bool IsReportLevelVerbose { get; }
public static Uri GetActiveUri(Uri activeUri) => activeUri ?? Services.CopriApi.ServerUris.CopriServerUriList.DefaultActiveUri;
public static bool GetCenterMapToCurrentLocation(Uri activeUri)
{
// TINK does not require access to current location. Deactivate center map to current location for this reason.
return !GetActiveUri(activeUri).Host.GetIsCopri();
}
}
}