yavsc/BookAStar/BookAStar/App.xaml.cs

243 lines
7.6 KiB
C#
Raw Normal View History

2016-10-05 01:20:06 +02:00
using BookAStar.Interfaces;
2016-09-21 04:02:40 +02:00
using BookAStar.Model;
2016-09-18 00:11:35 +02:00
using BookAStar.Pages;
2016-09-27 02:35:45 +02:00
using BookAStar.ViewModels;
using System;
using Xamarin.Forms;
2016-09-27 02:35:45 +02:00
using XLabs.Forms.Mvvm;
2016-09-29 04:54:14 +02:00
using XLabs.Forms.Pages;
2016-09-27 02:35:45 +02:00
using XLabs.Forms.Services;
using XLabs.Ioc;
using XLabs.Platform.Mvvm;
using XLabs.Platform.Services;
2016-10-03 18:32:37 +02:00
using XLabs.Settings;
2016-10-05 01:20:06 +02:00
using XLabs;
using XLabs.Enums;
2016-10-02 19:27:32 +02:00
/*
Glyphish icons from
2016-07-21 22:02:53 +02:00
http://www.glyphish.com/
under
2016-07-21 22:02:53 +02:00
http://creativecommons.org/licenses/by/3.0/us/
support them by buying the full set / Retina versions
*/
namespace BookAStar
{
public partial class App : Application // superclass new in 1.3
{
2016-09-21 04:02:40 +02:00
public static IPlatform PlatformSpecificInstance { get; set; }
public static string AppName { get; set; }
2016-09-29 04:54:14 +02:00
2016-10-04 02:46:24 +02:00
2016-09-29 04:54:14 +02:00
// Exists in order to dispose of a static instance strongly typed
// TODO : replace all references to this field
// by Views resolution, and then, drop it
public static App CurrentApp { get { return Current as App; } }
2016-09-29 04:54:14 +02:00
2016-10-04 02:46:24 +02:00
public static bool MasterPresented
{
2016-10-02 19:27:32 +02:00
get
{ return CurrentApp.masterDetail.IsPresented; }
internal set
{ CurrentApp.masterDetail.IsPresented = value; }
}
public void Init()
2016-09-25 00:44:30 +02:00
{
2016-09-27 02:35:45 +02:00
var app = Resolver.Resolve<IXFormsApp>();
2016-10-04 02:46:24 +02:00
2016-09-27 02:35:45 +02:00
if (app == null)
2016-09-25 00:44:30 +02:00
{
2016-09-27 02:35:45 +02:00
return;
}
Configure(app);
2016-10-05 01:20:06 +02:00
app.Closing += OnClosing;
app.Error += OnError;
app.Initialize += OnInitialize;
app.Resumed += OnAppResumed;
app.Rotation += OnRotation;
app.Startup += OnStartup;
app.Suspended += OnSuspended;
2016-09-25 00:44:30 +02:00
}
2016-10-05 01:20:06 +02:00
// omg
private void OnError(object sender, EventArgs e)
{
}
// Called on rotation after OnSuspended
private void OnClosing(object sender, EventArgs e)
{
}
// FIXME Not called
private void OnInitialize(object sender, EventArgs e)
{
}
// called on app startup, not on rotation
private void OnStartup(object sender, EventArgs e)
{
// TODO special starup pages as
// notification details or wizard setup page
}
// Called on rotation
private void OnSuspended(object sender, EventArgs e)
{
// TODO the navigation stack persistence (save)
}
// called on app startup, after OnStartup, not on rotation
private void OnAppResumed(object sender, EventArgs e)
{
// TODO the navigation stack persistence (restore)
base.OnResume();
}
// FIXME Not called ... see OnSuspended
private void OnRotation(object sender, EventArgs<Orientation> e)
{
// TODO the navigation stack persistence (restore?)
}
2016-10-03 18:32:37 +02:00
public static GenericConfigSettingsMgr ConfigManager { protected set; get; }
private void Configure(IXFormsApp app)
2016-09-29 04:54:14 +02:00
{
ViewFactory.EnableCache = true;
ViewFactory.Register<DashboardPage, DashboardViewModel>(
resolver => new DashboardViewModel());
ViewFactory.Register<BookQueryPage, BookQueryViewModel>();
2016-10-02 19:27:32 +02:00
ViewFactory.Register<BookQueriesPage, BookQueriesViewModel>();
2016-09-29 04:54:14 +02:00
ViewFactory.Register<EditBillingLinePage, BillingLineViewModel>();
ViewFactory.Register<EditEstimatePage, EstimateViewModel>();
2016-10-03 18:32:37 +02:00
ConfigManager = new XLabs.Settings.GenericConfigSettingsMgr(s =>
2016-10-04 02:46:24 +02:00
MainSettings.AppSettings.GetValueOrDefault<string>(s, MainSettings.SettingsDefault), null);
2016-10-03 18:32:37 +02:00
}
2016-10-04 02:46:24 +02:00
2016-09-29 04:54:14 +02:00
ExtendedMasterDetailPage masterDetail;
2016-09-25 00:44:30 +02:00
2016-09-18 00:11:35 +02:00
public App(IPlatform instance)
{
2016-10-05 01:20:06 +02:00
// This declaration became obsolete by introduction
// of the XLabs App that
// refers this instance with
// its application context property
// and is obtained using the `Resolver`
2016-09-27 02:35:45 +02:00
PlatformSpecificInstance = instance;
2016-10-05 01:20:06 +02:00
// Xaml
2016-09-25 00:44:30 +02:00
InitializeComponent();
2016-10-05 01:20:06 +02:00
// Static properties construction
2016-09-27 02:35:45 +02:00
Init();
2016-10-05 01:20:06 +02:00
// Builds the Main page
2016-09-29 04:54:14 +02:00
BuildMainPage();
2016-10-05 01:20:06 +02:00
2016-09-27 02:35:45 +02:00
}
2016-10-03 18:32:37 +02:00
2016-09-29 04:54:14 +02:00
BookQueriesPage bQueriesPage;
AccountChooserPage accChooserPage;
HomePage home;
2016-09-25 00:44:30 +02:00
2016-09-29 04:54:14 +02:00
private void BuildMainPage()
2016-09-27 02:35:45 +02:00
{
2016-09-29 04:54:14 +02:00
accChooserPage = new AccountChooserPage();
bQueriesPage = new BookQueriesPage
2016-09-25 00:44:30 +02:00
{
Title = "Demandes",
2016-10-02 19:27:32 +02:00
Icon = "icon.png",
BindingContext = new BookQueriesViewModel()
2016-09-25 00:44:30 +02:00
};
2016-09-27 02:35:45 +02:00
home = new HomePage() { Title = "Accueil", Icon = "icon.png" };
2016-09-27 02:35:45 +02:00
2016-09-29 04:54:14 +02:00
// var mainPage = new NavigationPage(bQueriesPage);
2016-10-04 02:46:24 +02:00
masterDetail = new ExtendedMasterDetailPage()
{
Title = "MainPage"
2016-09-27 02:35:45 +02:00
};
2016-10-04 02:46:24 +02:00
masterDetail.Master = new DashboardPage
{
2016-09-29 04:54:14 +02:00
Title = "Bookingstar",
2016-10-04 02:46:24 +02:00
BindingContext = new DashboardViewModel()
};
2016-09-27 02:35:45 +02:00
2016-10-02 19:27:32 +02:00
// masterDetail.Detail = home;
2016-10-02 19:27:32 +02:00
masterDetail.Detail = new NavigationPage(home);
2016-09-18 00:11:35 +02:00
ToolbarItem tiSetts = new ToolbarItem()
{
2016-09-27 02:35:45 +02:00
Text = "Paramètres",
2016-09-18 00:11:35 +02:00
Icon = "ic_corp_icon.png"
};
2016-09-18 00:11:35 +02:00
2016-09-27 02:35:45 +02:00
ToolbarItem tiHome = new ToolbarItem()
2016-09-18 00:11:35 +02:00
{
2016-09-27 02:35:45 +02:00
Text = "Accueil",
Icon = "icon.png"
2016-09-18 00:11:35 +02:00
};
2016-10-04 02:46:24 +02:00
2016-10-02 19:27:32 +02:00
/*
var navPage = new NavigationPage(masterDetail) {
Title = "Navigation",
Icon = "icon.png"
} ;
2016-09-29 04:54:14 +02:00
//var navPage = new NavigationPage(mainTab);
navPage.ToolbarItems.Add(tiHome);
navPage.ToolbarItems.Add(tiSetts);
2016-10-02 19:27:32 +02:00
*/
this.MainPage = masterDetail;
2016-10-05 18:45:45 +02:00
masterDetail.ToolbarItems.Add(tiHome);
masterDetail.ToolbarItems.Add(tiSetts);
NavigationService = new NavigationService(masterDetail.Detail.Navigation);
2016-09-27 02:35:45 +02:00
}
2016-10-05 18:45:45 +02:00
public INavigationService NavigationService { protected set; get; }
public void PostDeviceInfo()
{
2016-09-21 04:02:40 +02:00
var res = PlatformSpecificInstance.InvokeApi(
2016-09-18 00:11:35 +02:00
"gcm/register",
2016-09-21 04:02:40 +02:00
PlatformSpecificInstance.GetDeviceInfo());
}
2016-10-04 02:46:24 +02:00
2016-09-29 04:54:14 +02:00
public static void ShowBookQuery (BookQueryData query)
2016-09-21 04:02:40 +02:00
{
2016-10-04 02:46:24 +02:00
var page = ViewFactory.CreatePage<BookQueryViewModel
, BookQueryPage>((b, p) => p.BindingContext = new BookQueryViewModel(query));
App.Current.MainPage.Navigation.PushAsync(page as Page);
2016-09-21 04:02:40 +02:00
}
2016-09-25 00:44:30 +02:00
// TODO système de persistance de l'état de l'appli
2016-10-05 01:20:06 +02:00
/*
2016-09-27 02:35:45 +02:00
/// <summary>
/// Shows a page asynchronously by locating the default constructor, creating the page,
/// the pushing it onto the navigation stack.
/// </summary>
/// <param name="parentPage">Parent Page</param>
/// <param name="pageType">Type of page to show</param>
/// <returns></returns>
2016-09-29 04:54:14 +02:00
public static async Task ShowPage(VisualElement parentPage, Type pageType)
2016-09-10 00:53:08 +02:00
{
2016-09-27 02:35:45 +02:00
// Get all the constructors of the page type.
var constructors = pageType.GetTypeInfo().DeclaredConstructors;
2016-09-29 04:54:14 +02:00
foreach (var page in
2016-09-27 02:35:45 +02:00
from constructor in constructors
where constructor.GetParameters().Length == 0
select (Page)constructor.Invoke(null))
2016-09-25 00:44:30 +02:00
{
2016-09-27 02:35:45 +02:00
await parentPage.Navigation.PushAsync(page);
break;
2016-09-25 00:44:30 +02:00
}
2016-10-05 01:20:06 +02:00
}*/
}
}