Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reactive.Linq;
- using System.Reactive.Threading.Tasks;
- using Akavache;
- using EventProApp;
- using EventProApp.Helpers;
- using EventProApp.Page.Dashboard;
- using EventProApp.Page.Login;
- using EventProClientApi;
- using Microsoft.Azure.Mobile;
- using Microsoft.Azure.Mobile.Analytics;
- using Microsoft.Azure.Mobile.Crashes;
- using ReactiveUI;
- using Splat;
- using Xamarin.Forms;
- namespace EventProMobile
- {
- public partial class App : Application
- {
- public static MasterDetailPage MasterDetailPage = new MasterDetailPage();
- public static string AppName
- {
- get { return Constants.ApplicationName; }
- }
- public App()
- {
- LogHelper.LogDebug("At the start of the constructor");
- InitializeComponent();
- MainPage = new NavigationPage(new Xamarin.Forms.Page());
- }
- protected override void OnStart()
- {
- // Handle when your app starts
- MobileCenter.Start(typeof(Analytics), typeof(Crashes));
- BlobCache.ApplicationName = "EventPro";
- MainPage = RunCredentialCheck();
- }
- protected override void OnSleep()
- {
- // Handle when your app sleeps
- }
- protected override void OnResume()
- {
- // Handle when your app resumes
- }
- public static NavigationPage RunCredentialCheck()
- {
- NavigationPage result = null;
- var seq = SecurityHelper.HasUserCredentials()
- .ToObservable<bool>()
- .ObserveOn(RxApp.MainThreadScheduler)
- .Timeout(TimeSpan.FromSeconds(6))
- .Select((hasCreds) =>
- {
- return (hasCreds) ? new NavigationPage(new RootPage(true)) : new NavigationPage(new StartPage());
- }).FirstAsync();
- seq.Subscribe((NavigationPage nav) =>
- {
- result = nav;
- }, ex =>
- {
- Logger.Write($"Error:{ex.Message}", Splat.LogLevel.Error);
- throw ex;
- });
- return result;
- }
- public static ILogger Logger
- {
- get
- {
- return Splat.Locator.Current.GetService<ILogger>();
- }
- }
- private static ViewModelLocator _locator;
- public static ViewModelLocator Locator
- {
- get
- {
- return _locator ?? (_locator = new ViewModelLocator());
- }
- }
- public static Xamarin.Forms.Page GetMainPage()
- {
- return new RootPage(true);
- }
- public static Xamarin.Forms.Page GetLoginPage()
- {
- return new Login();
- }
- public static Xamarin.Forms.Page GetSignupPage()
- {
- return new Signup();
- }
- public static Xamarin.Forms.Page GetStartPage()
- {
- return new StartPage();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement