|
@@ -16,6 +16,7 @@ using SkiaSharp;
|
|
|
using System.Threading;
|
|
|
using System.Linq;
|
|
|
using System.Collections.Generic;
|
|
|
+using static Android.Icu.Text.AlphabeticIndex;
|
|
|
|
|
|
//[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
|
|
|
namespace comal.timesheets
|
|
@@ -46,6 +47,7 @@ namespace comal.timesheets
|
|
|
|
|
|
public App()
|
|
|
{
|
|
|
+ InitializeComponent();
|
|
|
LoadAll();
|
|
|
}
|
|
|
|
|
@@ -53,67 +55,140 @@ namespace comal.timesheets
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- Material.Init(this);
|
|
|
- InitializeComponent();
|
|
|
- Material.Use("Material.Configuration");
|
|
|
+ InitAndRegister();
|
|
|
|
|
|
- MobileUtils.Init();
|
|
|
- CoreUtils.RegisterClasses();
|
|
|
- ComalUtils.RegisterClasses();
|
|
|
+ LoadSettings();
|
|
|
|
|
|
- FindDeviceInfo();
|
|
|
+ ApplyComalSettings();
|
|
|
|
|
|
- Settings = new LocalConfiguration<ConnectionSettings>().Load();
|
|
|
+ SaveSettings();
|
|
|
|
|
|
- DBSettings = new LocalConfiguration<DatabaseSettings>().Load();
|
|
|
+ SetupClient();
|
|
|
|
|
|
- if (!string.IsNullOrWhiteSpace(Settings.UserID) && string.IsNullOrWhiteSpace(DBSettings.UserID))
|
|
|
- DBSettings.UserID = Settings.UserID;
|
|
|
- if (!string.IsNullOrWhiteSpace(Settings.Password) && string.IsNullOrWhiteSpace(DBSettings.Password))
|
|
|
- DBSettings.Password = Settings.Password;
|
|
|
+ FinishSetup();
|
|
|
|
|
|
- List<string> list = new List<string>();
|
|
|
- list.Add("remote.com-al.com.au:8000");
|
|
|
- list.Add("remote2.com-al.com.au:8000");
|
|
|
- list.Add("remote3.com-al.com.au:8000");
|
|
|
+ LaunchLoginPage();
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ LaunchLoginPage();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- DBSettings.URLs = list.ToArray();
|
|
|
+ private void LaunchLoginPage()
|
|
|
+ {
|
|
|
+ MainPage = new MaterialNavigationPage(new PINLoginPage());
|
|
|
+ }
|
|
|
|
|
|
- new LocalConfiguration<DatabaseSettings>().Save(DBSettings);
|
|
|
- MobileUtils.SaveToSecureStorage();
|
|
|
+ private void FinishSetup()
|
|
|
+ {
|
|
|
+ GlobalVariables.InternalOnAppearing = true;
|
|
|
+ GlobalVariables.ChangeUser = false;
|
|
|
|
|
|
- if (!string.IsNullOrWhiteSpace(GlobalVariables.LoadFromLinkString))
|
|
|
- {
|
|
|
- MobileUtils.LoadFromLink();
|
|
|
- }
|
|
|
+ RunTimers();
|
|
|
+ }
|
|
|
|
|
|
- var result = JsonClient<User>.Ping(DBSettings.URLs, out DatabaseInfo info);
|
|
|
+ private void SetupClient()
|
|
|
+ {
|
|
|
+ if (CheckLoadFromLink())
|
|
|
+ return;
|
|
|
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var result = JsonClient<User>.Ping(DBSettings.URLs, out DatabaseInfo info);
|
|
|
ClientFactory.SetClientType(typeof(JsonClient<>), "TimeBench", MobileUtils.AppVersion.InstalledVersionNumber + DeviceString, result, true);
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ }
|
|
|
|
|
|
- GlobalVariables.InternalOnAppearing = true;
|
|
|
- GlobalVariables.ChangeUser = false;
|
|
|
+ private bool CheckLoadFromLink()
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(GlobalVariables.LoadFromLinkString))
|
|
|
+ {
|
|
|
+ MobileUtils.LoadFromLink();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- if (!reload)
|
|
|
- RunTimers();
|
|
|
+ private void SaveSettings()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ new LocalConfiguration<DatabaseSettings>().Save(DBSettings);
|
|
|
+ MobileUtils.SaveToSecureStorage();
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ }
|
|
|
|
|
|
- MainPage = new MaterialNavigationPage(new PINLoginPage());
|
|
|
+ private void ApplyComalSettings() //temporary fix
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ List<string> list = new List<string>
|
|
|
+ {
|
|
|
+ "remote.com-al.com.au:8000",
|
|
|
+ "remote2.com-al.com.au:8000",
|
|
|
+ "remote3.com-al.com.au:8000"
|
|
|
+ };
|
|
|
+
|
|
|
+ DBSettings.URLs = list.ToArray();
|
|
|
}
|
|
|
- catch
|
|
|
+ catch { }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadSettings()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Settings = new LocalConfiguration<ConnectionSettings>().Load();
|
|
|
+
|
|
|
+ DBSettings = new LocalConfiguration<DatabaseSettings>().Load();
|
|
|
+
|
|
|
+ if (!string.IsNullOrWhiteSpace(Settings.UserID) && string.IsNullOrWhiteSpace(DBSettings.UserID))
|
|
|
+ DBSettings.UserID = Settings.UserID;
|
|
|
+ if (!string.IsNullOrWhiteSpace(Settings.Password) && string.IsNullOrWhiteSpace(DBSettings.Password))
|
|
|
+ DBSettings.Password = Settings.Password;
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void InitAndRegister()
|
|
|
+ {
|
|
|
+ try
|
|
|
{
|
|
|
- Thread.Sleep(1000);
|
|
|
- LoadAll(true);
|
|
|
+ Material.Init(this);
|
|
|
+
|
|
|
+ Material.Use("Material.Configuration");
|
|
|
+
|
|
|
+ MobileUtils.Init();
|
|
|
+ CoreUtils.RegisterClasses();
|
|
|
+ ComalUtils.RegisterClasses();
|
|
|
+
|
|
|
+ FindDeviceInfo();
|
|
|
}
|
|
|
+ catch { }
|
|
|
}
|
|
|
|
|
|
private void RunTimers()
|
|
|
{
|
|
|
- Task.Run(() =>
|
|
|
+ try
|
|
|
{
|
|
|
GPS.GetLocation();
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ try
|
|
|
+ {
|
|
|
Bluetooth.ScanForDevices();
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
|
|
|
+ try
|
|
|
+ {
|
|
|
Device.StartTimer(new TimeSpan(0, 0, 30), () =>
|
|
|
{
|
|
|
if (App.IsInForeground)
|
|
@@ -131,7 +206,8 @@ namespace comal.timesheets
|
|
|
}
|
|
|
return true;
|
|
|
});
|
|
|
- });
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
}
|
|
|
|
|
|
private async void TryLoadFromSecureCache()
|