| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 | 
							- using System;
 
- using System.Linq;
 
- using System.Threading;
 
- using System.Threading.Tasks;
 
- using Comal.Classes;
 
- using InABox.Clients;
 
- using InABox.Core;
 
- using InABox.Mobile;
 
- using InABox.Rpc;
 
- using Xamarin.Essentials;
 
- using Xamarin.Forms;
 
- using Xamarin.Forms.Xaml;
 
- using XF.Material.Forms;
 
- using XF.Material.Forms.UI;
 
- [assembly: XamlCompilation(XamlCompilationOptions.Compile)]
 
- namespace PRS.Mobile
 
- {
 
-     
 
-     public enum TransportStatus
 
-     {
 
-         BadConfiguration,
 
-         NoConnection,
 
-         OK,
 
-         None
 
-     }
 
-     
 
-     public partial class App : Application
 
-     {
 
-         
 
-         public static string LaunchParameters { get; set; }
 
-         public static IRpcClientTransport Transport { get; set; }
 
-         
 
-         public static TransportStatus ConnectTransport(string[] urls)
 
-         {
 
-             if (Transport?.IsConnected() == true)
 
-                 Transport.Disconnect();
 
-             
 
-             Transport = null;
 
-             
 
-             if (!urls.Any())
 
-                 return TransportStatus.BadConfiguration;
 
-             
 
-             var transport = new RpcClientSocketTransport(urls);
 
-             transport.Connect();
 
-             if (!transport.IsConnected())
 
-                 return TransportStatus.NoConnection;
 
-             Transport = transport;
 
-             ClientFactory.SetClientType(typeof(RpcClient<>), InABox.Core.Platform.TimeBench, MobileUtils.AppVersion.InstalledVersionNumber + App.DeviceString, Transport);
 
-             return TransportStatus.OK;
 
-         }
 
-         public static LocationServices GPS { get; } = new LocationServices() { ScanDelay = new TimeSpan(0, 1, 0) };
 
-         public static Bluetooth Bluetooth { get; } = new Bluetooth() { ScanDelay = new TimeSpan(0, 1, 0) };
 
-         public static DataModel Data { get; } = new DataModel();
 
-         
 
-         public static string DeviceString
 
-         {
 
-             get
 
-             {
 
-                 var result = Device.RuntimePlatform.Substring(0, 1).ToUpper();
 
-                 if (Device.Idiom == TargetIdiom.Phone)
 
-                     result = result.ToLower();
 
-                 return result;
 
-             }
 
-         }
 
-         
 
-         public static double GetXamarinWidth()
 
-         {
 
-             var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
 
-             var width = mainDisplayInfo.Width;
 
-             return width / mainDisplayInfo.Density;
 
-         }
 
-         public static bool IsInForeground { get; set; } = false;
 
-         
 
-         
 
-         // this is set by PINLoginPage if DatabaseSettings.UserID is blank
 
-         // Effective, this will enable the "back" (-> logout) button on the Main page
 
-         // if the userid is not set.
 
-         public static bool IsSharedDevice { get; set; }
 
-         public const string MessageOnStart = "OnStart";
 
-         public const string MessageOnSleep = "OnSleep";
 
-         public const string MessageOnResume = "OnResume";
 
-         
 
-         public App()
 
-         {
 
-             InitializeComponent();
 
-             
 
-             // https://github.com/Baseflow/XF-Material-Library
 
-             XF.Material.Forms.Material.Init(this);
 
-             XF.Material.Forms.Material.Use("Material.Configuration");
 
-             MobileUtils.Init();
 
-             CoreUtils.RegisterClasses();
 
-             ComalUtils.RegisterClasses();
 
-             
 
-             StartMonitoringGPS();
 
-             
 
-             StartMonitoringBlueTooth();
 
-             
 
-             // PINLoginPage is going to be the root navigation page.
 
-             // If shown, it will rerun the validation process
 
-             // So we should be able to get to this page from
 
-             // 1. App Startup => Autologin
 
-             // 2. SettingsPage.Save() => AutoLogin
 
-             // 3. Main Window => Always manual login?
 
-             var login = new PinLoginPage();
 
-             var navigation = new NavigationPage(login); 
 
-             MainPage = navigation;
 
-         }
 
-         protected override void OnStart()
 
-         {
 
-             // Handle when your app starts
 
-         }
 
-         protected override void OnSleep()
 
-         {
 
-             // Handle when your app sleeps
 
-         }
 
-         protected override void OnResume()
 
-         {
 
-             // Handle when your app resumes
 
-         }
 
-         
 
-         private void StartMonitoringGPS()
 
-         {
 
-             Task.Run(() =>
 
-             {
 
-                 while (true)
 
-                 {
 
-                     if (App.IsInForeground)
 
-                     {
 
-                         try
 
-                         {
 
-                             GPS.GetLocation();
 
-                         }
 
-                         catch (Exception e)
 
-                         {
 
-                             // Need to Log this
 
-                         }
 
-                     }
 
-                     Thread.Sleep(TimeSpan.FromSeconds(30));
 
-                 }
 
-             });
 
-         }
 
-         
 
-         private void StartMonitoringBlueTooth()
 
-         {
 
-             Task.Run(() =>
 
-             {
 
-                 while (true)
 
-                 {
 
-                     if (App.IsInForeground)
 
-                     {
 
-                         try
 
-                         {
 
-                             Bluetooth.ScanForDevices();
 
-                         }
 
-                         catch (Exception e)
 
-                         {
 
-                             // Need to Log this
 
-                         }
 
-                     }
 
-                     Thread.Sleep(TimeSpan.FromSeconds(30));
 
-                 }
 
-             });
 
-         }
 
-     }
 
- }
 
 
  |