Skip to content
This repository has been archived by the owner on Jul 2, 2022. It is now read-only.

Commit

Permalink
Beter Startup View
Browse files Browse the repository at this point in the history
  • Loading branch information
thedillonb committed Apr 16, 2014
1 parent 394b6c1 commit 120496c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 61 deletions.
125 changes: 65 additions & 60 deletions CodeHub.Core/ViewModels/App/StartupViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,88 @@
using CodeHub.Core.Services;
using System.Linq;
using CodeHub.Core.Factories;
using System.Threading.Tasks;

namespace CodeHub.Core.ViewModels.App
{
public class StartupViewModel : BaseStartupViewModel
public class StartupViewModel : BaseStartupViewModel
{
private readonly ILoginFactory _loginFactory;
private readonly IApplicationService _applicationService;
private readonly IApplicationService _applicationService;

public StartupViewModel(ILoginFactory loginFactory, IApplicationService applicationService)
{
_loginFactory = loginFactory;
_applicationService = applicationService;
}
{
_loginFactory = loginFactory;
_applicationService = applicationService;
}

protected async override void Startup()
{
if (!_applicationService.Accounts.Any())
{
ShowViewModel<Accounts.AccountsViewModel>();
ShowViewModel<Accounts.NewAccountViewModel>();
return;
}
protected async override void Startup()
{
if (!_applicationService.Accounts.Any())
{
ShowViewModel<Accounts.AccountsViewModel>();
ShowViewModel<Accounts.NewAccountViewModel>();
return;
}

var account = GetDefaultAccount() as GitHubAccount;
if (account == null)
{
ShowViewModel<Accounts.AccountsViewModel>();
return;
}
var account = GetDefaultAccount() as GitHubAccount;
if (account == null)
{
ShowViewModel<Accounts.AccountsViewModel>();
return;
}

var isEnterprise = account.IsEnterprise || !string.IsNullOrEmpty(account.Password);
if (account.DontRemember)
{
ShowViewModel<Accounts.AccountsViewModel>();
var isEnterprise = account.IsEnterprise || !string.IsNullOrEmpty(account.Password);
if (account.DontRemember)
{
ShowViewModel<Accounts.AccountsViewModel>();

//Hack for now
if (isEnterprise)
{
ShowViewModel<Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id });
}
else
{
ShowViewModel<Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account));
}
//Hack for now
if (isEnterprise)
{
ShowViewModel<Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id });
}
else
{
ShowViewModel<Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account));
}

return;
}
return;
}

//Lets login!
try
{
IsLoggingIn = true;
var client = await _loginFactory.LoginAccount(account);
_applicationService.ActivateUser(account, client);
}
catch (GitHubSharp.UnauthorizedException e)
{
//Lets login!
try
{
IsLoggingIn = true;

Uri accountAvatarUri = null;
Uri.TryCreate(account.AvatarUrl, UriKind.Absolute, out accountAvatarUri);
ImageUrl = accountAvatarUri;
Status = "Logging in as " + account.Username;

var client = await _loginFactory.LoginAccount(account);
_applicationService.ActivateUser(account, client);
}
catch (GitHubSharp.UnauthorizedException e)
{
DisplayAlert("The credentials for the selected account are incorrect. " + e.Message);

ShowViewModel<Accounts.AccountsViewModel>();
if (isEnterprise)
ShowViewModel<Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id });
else
ShowViewModel<Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account));
}
catch (Exception e)
{
ShowViewModel<Accounts.AccountsViewModel>();
if (isEnterprise)
ShowViewModel<Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id });
else
ShowViewModel<Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account));
}
catch (Exception e)
{
DisplayAlert(e.Message);
ShowViewModel<Accounts.AccountsViewModel>();
}
finally
{
IsLoggingIn = false;
}
ShowViewModel<Accounts.AccountsViewModel>();
}
finally
{
IsLoggingIn = false;
}

}
}
}
}

2 changes: 2 additions & 0 deletions CodeHub.iOS/CodeHub.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@
<BundleResource Include="Images\MarkdownComposer\photo.png" />
<BundleResource Include="Images\MarkdownComposer\picture%402x.png" />
<BundleResource Include="Images\MarkdownComposer\picture.png" />
<BundleResource Include="Images\login_user_unknown%402x.png" />
<BundleResource Include="Images\login_user_unknown.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions CodeHub.iOS/Images/Images.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static class Images
public static UIImage Language { get { return UIImageHelper.FromFileAuto("Images/language"); } }
public static UIImage Unlocked { get { return UIImageHelper.FromFileAuto("Images/unlocked"); } }
public static UIImage Locked { get { return UIImageHelper.FromFileAuto("Images/locked"); } }

public static UIImage LoginUserUnknown { get { return UIImageHelper.FromFileAuto("Images/login_user_unknown"); } }


public static Uri GitHubRepoUrl
{
Expand Down
Binary file added CodeHub.iOS/Images/login_user_unknown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CodeHub.iOS/Images/login_user_unknown@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions CodeHub.iOS/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,7 @@ public UIColor ApplicationNavigationBarTint
}

public float FontSizeRatio { get; set; }

public UIImage LoginUserUnknown { get { return Images.LoginUserUnknown; } }
}
}

0 comments on commit 120496c

Please sign in to comment.