Skip to content

Commit

Permalink
Merge pull request #358 from brunck/implement-shell-navigation
Browse files Browse the repository at this point in the history
Implement Shell Navigation
  • Loading branch information
rockfordlhotka authored Feb 3, 2020
2 parents 1f3f55a + 8371f55 commit ff2b2d9
Show file tree
Hide file tree
Showing 19 changed files with 310 additions and 197 deletions.
20 changes: 11 additions & 9 deletions src/MobileKidsIdApp.DataAccess/LocalStorage/FamilyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using MobileKidsIdApp.DataAccess.DataModels;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.IO.IsolatedStorage;
using System.IO;
using System.Diagnostics;

namespace MobileKidsIdApp.DataAccess.LocalStorage
{
Expand Down Expand Up @@ -42,8 +42,9 @@ private async Task<bool> TestGetAsync(string password, string fileName)
result = true;

}
catch
catch(Exception e)
{
Debug.WriteLine($"Exception caught in FamilyProvider.TestGetAsync(): {e}");
if (BackupPath != PrimaryPath)
{
// see if pw works on backup file
Expand Down Expand Up @@ -72,8 +73,9 @@ public async Task<Family> GetAsync()
result = JsonConvert.DeserializeObject<Family>(dataBlob);

}
catch
catch(Exception e)
{
Debug.WriteLine($"Exception caught in FamilyProvider.GetAsync(): {e}");
// if we can't read primary file, restore last backup
// and try again
if (File.Exists(BackupPath))
Expand All @@ -95,7 +97,7 @@ public async Task<Family> GetAsync()
return result;
}

public async Task SaveAsync(Family data)
public Task SaveAsync(Family data)
{
if (File.Exists(PrimaryPath))
{
Expand All @@ -104,18 +106,18 @@ public async Task SaveAsync(Family data)
var json = JsonConvert.SerializeObject(data);
var dataBlob = Encryption.Encrypt(Csla.ApplicationContext.User.Identity.Name, json);
File.WriteAllText(PrimaryPath, dataBlob);
await Task.Delay(0); // prevent warning about no await in an async method

return Task.CompletedTask;
}

public async Task ResetData()
public Task ResetData()
{
await Task.Delay(0); // prevent warning about no await in an async method

if (File.Exists(BackupPath))
File.Delete(BackupPath);
if (File.Exists(PrimaryPath))
File.Delete(PrimaryPath);

return Task.CompletedTask;
}
}
}
40 changes: 27 additions & 13 deletions src/MobileKidsIdApp.Models/Family.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading.Tasks;
using Csla;

Expand All @@ -12,20 +10,36 @@ public class Family : BusinessListBase<Family, Child>
{
private async Task DataPortal_Fetch()
{
var provider = new DataAccess.DataProviderFactory().GetDataProvider();
var dal = provider.GetFamilyProvider();
var data = await dal.GetAsync();
foreach (var item in data.Children)
Add(DataPortal.FetchChild<Child>(item));
try
{
var provider = new DataAccess.DataProviderFactory().GetDataProvider();
var dal = provider.GetFamilyProvider();
var data = await dal.GetAsync();
foreach (var item in data.Children)
Add(DataPortal.FetchChild<Child>(item));
}
catch (Exception e)
{
Debug.WriteLine($"Exception in Family.DataPortal_Fetch(): {e}");
throw;
}
}

private new async Task DataPortal_Update()
{
var provider = new DataAccess.DataProviderFactory().GetDataProvider();
var dal = provider.GetFamilyProvider();
var dtoRoot = new DataAccess.DataModels.Family();
Child_Update(dtoRoot.Children);
await dal.SaveAsync(dtoRoot);
try
{
var provider = new DataAccess.DataProviderFactory().GetDataProvider();
var dal = provider.GetFamilyProvider();
var dtoRoot = new DataAccess.DataModels.Family();
Child_Update(dtoRoot.Children);
await dal.SaveAsync(dtoRoot);
}
catch (Exception e)
{
Debug.WriteLine($"Exception in Family.DataPortal_Update(): {e}");
throw;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Foundation;
using MobileKidsIdApp.Services;
using UIKit;
using Xamarin.Forms;

[assembly: Xamarin.Forms.Dependency(typeof(MobileKidsIdApp.iOS.Services.PhotoPicker))]
namespace MobileKidsIdApp.iOS.Services
Expand Down Expand Up @@ -32,8 +33,11 @@ public Task<string> GetCopiedFilePath(string copyToDirectory, string fileNameWit
ImagePicker.Canceled += OnImagePickerCancelled;
TaskCompletionSource.Task.ContinueWith(t =>
{
ImagePicker.FinishedPickingMedia -= OnImagePickerFinishedPickingMedia;
ImagePicker.Canceled -= OnImagePickerCancelled;
Device.InvokeOnMainThreadAsync(() =>
{
ImagePicker.FinishedPickingMedia -= OnImagePickerFinishedPickingMedia;
ImagePicker.Canceled -= OnImagePickerCancelled;
});
});

// Present UIImagePickerController;
Expand Down
76 changes: 40 additions & 36 deletions src/MobileKidsIdApp/MobileKidsIdApp/App.xaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MobileKidsIdApp.App">
<Application
x:Class="MobileKidsIdApp.App"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<Application.Resources>
<ResourceDictionary>
<!-- Colors -->
<!--
See MCM Brand Inspriation Board for usage guidelines on color pallette.
https://github.com/HTBox/MobileKidsIdApp/blob/master/resources/inspiration-board-square-green.jpg
<!-- Colors -->
<!--
See MCM Brand Inspriation Board for usage guidelines on color palette.
https://github.com/HTBox/MobileKidsIdApp/blob/master/resources/inspiration-board-square-green.jpg
-->
<Color x:Key="MCM-White-1">#FFFFFF</Color>

Expand All @@ -20,12 +21,12 @@
<Color x:Key="MCM-LightBlue-2">#64c4ca</Color>
<Color x:Key="MCM-LightBlue-3">#7cd0d3</Color>
<Color x:Key="MCM-LightBlue-4">#94d9da</Color>

<Color x:Key="MCM-Orange-1">#df8319</Color>
<Color x:Key="MCM-Orange-2">#e59c36</Color>
<Color x:Key="MCM-Orange-3">#e9ad52</Color>
<Color x:Key="MCM-Orange-4">#f0bc70</Color>

<Color x:Key="MCM-Green-1">#31812e</Color>
<Color x:Key="MCM-Green-2">#4e9a4a</Color>
<Color x:Key="MCM-Green-3">#69ac67</Color>
Expand All @@ -41,17 +42,22 @@
<Color x:Key="MCM-Yellow-3">#f2ecb5</Color>
<Color x:Key="MCM-Yellow-4">#f6efc5</Color>

<!-- Fonts -->
<OnPlatform x:Key="BodyCustomFont" x:TypeArguments="x:String" iOS="OpenSans-Regular" Android=""/>
<OnPlatform x:Key="HeaderCustomFont" x:TypeArguments="x:String" iOS="OpenSans-Bold" Android=""/>
<!-- Fonts -->
<OnPlatform
x:Key="BodyCustomFont"
x:TypeArguments="x:String"
Android=""
iOS="OpenSans-Regular" />
<OnPlatform
x:Key="HeaderCustomFont"
x:TypeArguments="x:String"
Android=""
iOS="OpenSans-Bold" />

<!-- Navigation -->
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="{StaticResource MCM-DarkTeal-2}"/>
<Setter Property="BarTextColor" Value="{StaticResource MCM-White-1}"/>
</Style>
<!-- Navigation -->
<!-- See AppShell.xaml -->

<!-- Label -->
<!-- Label -->
<Style x:Key="HeaderLabel" TargetType="Label">
<Setter Property="TextColor" Value="{StaticResource MCM-DarkTeal-2}" />
<Setter Property="HorizontalOptions" Value="Center" />
Expand All @@ -68,37 +74,35 @@
<Setter Property="TextColor" Value="{StaticResource MCM-Orange-1}" />
<Setter Property="Margin" Value="25, 25, 25, 15" />
</Style>
<!-- Entry -->

<!-- Entry -->
<Style x:Key="EntryText" TargetType="Entry">
<Setter Property="Margin" Value="25, 0, 25, 0" />
</Style>

<!-- Grid -->
<Style TargetType="Grid">
</Style>

<!-- ListView -->
<Style TargetType="ListView">
</Style>

<!-- StackLayout -->
<!-- <Style TargetType="StackLayout">
<!-- Grid -->
<Style TargetType="Grid" />

<!-- ListView -->
<Style TargetType="ListView" />

<!-- StackLayout -->
<!-- <Style TargetType="StackLayout">
<Setter Property="BackgroundColor" Value="{StaticResource MCM-DarkTeal-1}" />
</Style>-->

<!-- ScrollView -->
<!-- ScrollView -->
<Style TargetType="ScrollView">
<Setter Property="VerticalOptions" Value="FillAndExpand" />
<Setter Property="HorizontalOptions" Value="FillAndExpand" />
</Style>

<!-- TableView -->
<!-- TableView -->
<Style TargetType="TableView">
<Setter Property="Margin" Value="15,0,15,0"/>
<Setter Property="Margin" Value="15,0,15,0" />
</Style>
<!-- Button -->

<!-- Button -->
<Style x:Key="LoginButton" TargetType="Button">
<Setter Property="TextColor" Value="{StaticResource MCM-White-1}" />
<Setter Property="FontFamily" Value="{StaticResource BodyCustomFont}" />
Expand Down Expand Up @@ -127,7 +131,7 @@
<Setter Property="BackgroundColor" Value="{StaticResource MCM-White-1}" />
<Setter Property="TextColor" Value="{StaticResource MCM-Orange-1}" />
<Setter Property="FontFamily" Value="{StaticResource BodyCustomFont}" />
<Setter Property="FontSize" Value="Micro"/>
<Setter Property="FontSize" Value="Micro" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
</Style>
Expand Down
48 changes: 29 additions & 19 deletions src/MobileKidsIdApp/MobileKidsIdApp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,56 @@
using MobileKidsIdApp.Services;
using System;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace MobileKidsIdApp
{
public partial class App : Application
{
public static NavigationPage RootPage { private set; get; }
public partial class App : Application
{
public static Page RootPage { private set; get; }
public static ViewModels.ChildProfileList CurrentFamily { get; set; }


public App ()
{
InitializeComponent();
public App()
{
InitializeComponent();

Csla.ApplicationContext.ContextManager = new Models.ApplicationContextManager();

if (Csla.ApplicationContext.User == null)
Csla.ApplicationContext.User = new Csla.Security.UnauthenticatedPrincipal();

SetRootPage();
}

private void SetRootPage()
{
if (RootPage is Views.Login page && page.BindingContext is ViewModels.Login vm)
{
vm.SetRootPage = null;
}

if (!Csla.ApplicationContext.User.Identity.IsAuthenticated)
{
RootPage = new NavigationPage(new Views.Login { BindingContext = new ViewModels.Login() });
ViewModels.Login loginViewModel = new ViewModels.Login
{
SetRootPage = () => SetRootPage()
};
RootPage = new Views.Login { BindingContext = loginViewModel };
}
else
{
RootPage = new NavigationPage(new Views.Landing { BindingContext = new ViewModels.Landing() });
RootPage = new AppShell { BindingContext = new ViewModels.Landing() };
}

MainPage = RootPage;
}


internal static async Task Logout()
public void Logout()
{
RootPage.Navigation.InsertPageBefore(new NavigationPage(new Views.Login { BindingContext = new ViewModels.Login() }),
RootPage.Navigation.NavigationStack.First());
await RootPage.Navigation.PopAsync();
ViewModels.Login loginViewModel = new ViewModels.Login
{
SetRootPage = () => SetRootPage()
};
MainPage = RootPage = new Views.Login { BindingContext = loginViewModel };
}
}
}
27 changes: 27 additions & 0 deletions src/MobileKidsIdApp/MobileKidsIdApp/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<Shell
x:Class="MobileKidsIdApp.AppShell"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:MobileKidsIdApp.Views">

<Shell.Resources>
<ResourceDictionary>
<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="{StaticResource MCM-DarkTeal-2}" />
<Setter Property="Shell.ForegroundColor" Value="{StaticResource MCM-White-1}" />
<Setter Property="Shell.TitleColor" Value="{StaticResource MCM-White-1}" />
</Style>
<Style BasedOn="{StaticResource BaseStyle}" TargetType="ShellContent" />
</ResourceDictionary>
</Shell.Resources>

<!-- This must be a FlyoutItem because there has to be at least one FlyoutItem on a flyout nav shell page. -->
<FlyoutItem Title="My Kids">
<ShellContent ContentTemplate="{DataTemplate views:ChildProfileList}" />
</FlyoutItem>

<MenuItem Command="{Binding DisplayContentMenuCommand}" Text="Content" />
<MenuItem Command="{Binding OptionsCommand}" Text="Options" />
<MenuItem Command="{Binding LogoutCommand}" Text="Logout" />
</Shell>
12 changes: 12 additions & 0 deletions src/MobileKidsIdApp/MobileKidsIdApp/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Xamarin.Forms;

namespace MobileKidsIdApp
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
Loading

0 comments on commit ff2b2d9

Please sign in to comment.