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

Commit 120496c

Browse files
committed
Beter Startup View
1 parent 394b6c1 commit 120496c

File tree

7 files changed

+73
-61
lines changed

7 files changed

+73
-61
lines changed

CodeHub.Core/ViewModels/App/StartupViewModel.cs

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,83 +4,88 @@
44
using CodeHub.Core.Services;
55
using System.Linq;
66
using CodeHub.Core.Factories;
7-
using System.Threading.Tasks;
87

98
namespace CodeHub.Core.ViewModels.App
109
{
11-
public class StartupViewModel : BaseStartupViewModel
10+
public class StartupViewModel : BaseStartupViewModel
1211
{
1312
private readonly ILoginFactory _loginFactory;
14-
private readonly IApplicationService _applicationService;
13+
private readonly IApplicationService _applicationService;
1514

1615
public StartupViewModel(ILoginFactory loginFactory, IApplicationService applicationService)
17-
{
18-
_loginFactory = loginFactory;
19-
_applicationService = applicationService;
20-
}
16+
{
17+
_loginFactory = loginFactory;
18+
_applicationService = applicationService;
19+
}
2120

22-
protected async override void Startup()
23-
{
24-
if (!_applicationService.Accounts.Any())
25-
{
26-
ShowViewModel<Accounts.AccountsViewModel>();
27-
ShowViewModel<Accounts.NewAccountViewModel>();
28-
return;
29-
}
21+
protected async override void Startup()
22+
{
23+
if (!_applicationService.Accounts.Any())
24+
{
25+
ShowViewModel<Accounts.AccountsViewModel>();
26+
ShowViewModel<Accounts.NewAccountViewModel>();
27+
return;
28+
}
3029

31-
var account = GetDefaultAccount() as GitHubAccount;
32-
if (account == null)
33-
{
34-
ShowViewModel<Accounts.AccountsViewModel>();
35-
return;
36-
}
30+
var account = GetDefaultAccount() as GitHubAccount;
31+
if (account == null)
32+
{
33+
ShowViewModel<Accounts.AccountsViewModel>();
34+
return;
35+
}
3736

38-
var isEnterprise = account.IsEnterprise || !string.IsNullOrEmpty(account.Password);
39-
if (account.DontRemember)
40-
{
41-
ShowViewModel<Accounts.AccountsViewModel>();
37+
var isEnterprise = account.IsEnterprise || !string.IsNullOrEmpty(account.Password);
38+
if (account.DontRemember)
39+
{
40+
ShowViewModel<Accounts.AccountsViewModel>();
4241

43-
//Hack for now
44-
if (isEnterprise)
45-
{
46-
ShowViewModel<Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id });
47-
}
48-
else
49-
{
50-
ShowViewModel<Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account));
51-
}
42+
//Hack for now
43+
if (isEnterprise)
44+
{
45+
ShowViewModel<Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id });
46+
}
47+
else
48+
{
49+
ShowViewModel<Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account));
50+
}
5251

53-
return;
54-
}
52+
return;
53+
}
5554

56-
//Lets login!
57-
try
58-
{
59-
IsLoggingIn = true;
60-
var client = await _loginFactory.LoginAccount(account);
61-
_applicationService.ActivateUser(account, client);
62-
}
63-
catch (GitHubSharp.UnauthorizedException e)
64-
{
55+
//Lets login!
56+
try
57+
{
58+
IsLoggingIn = true;
59+
60+
Uri accountAvatarUri = null;
61+
Uri.TryCreate(account.AvatarUrl, UriKind.Absolute, out accountAvatarUri);
62+
ImageUrl = accountAvatarUri;
63+
Status = "Logging in as " + account.Username;
64+
65+
var client = await _loginFactory.LoginAccount(account);
66+
_applicationService.ActivateUser(account, client);
67+
}
68+
catch (GitHubSharp.UnauthorizedException e)
69+
{
6570
DisplayAlert("The credentials for the selected account are incorrect. " + e.Message);
6671

67-
ShowViewModel<Accounts.AccountsViewModel>();
68-
if (isEnterprise)
69-
ShowViewModel<Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id });
70-
else
71-
ShowViewModel<Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account));
72-
}
73-
catch (Exception e)
74-
{
72+
ShowViewModel<Accounts.AccountsViewModel>();
73+
if (isEnterprise)
74+
ShowViewModel<Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id });
75+
else
76+
ShowViewModel<Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account));
77+
}
78+
catch (Exception e)
79+
{
7580
DisplayAlert(e.Message);
76-
ShowViewModel<Accounts.AccountsViewModel>();
77-
}
78-
finally
79-
{
80-
IsLoggingIn = false;
81-
}
81+
ShowViewModel<Accounts.AccountsViewModel>();
82+
}
83+
finally
84+
{
85+
IsLoggingIn = false;
86+
}
8287

83-
}
88+
}
8489
}
8590
}
8691

CodeHub.iOS/CodeHub.iOS.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@
434434
<BundleResource Include="Images\MarkdownComposer\photo.png" />
435435
<BundleResource Include="Images\MarkdownComposer\picture%402x.png" />
436436
<BundleResource Include="Images\MarkdownComposer\picture.png" />
437+
<BundleResource Include="Images\login_user_unknown%402x.png" />
438+
<BundleResource Include="Images\login_user_unknown.png" />
437439
</ItemGroup>
438440
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
439441
<ItemGroup>

CodeHub.iOS/Images/Images.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public static class Images
4848
public static UIImage Language { get { return UIImageHelper.FromFileAuto("Images/language"); } }
4949
public static UIImage Unlocked { get { return UIImageHelper.FromFileAuto("Images/unlocked"); } }
5050
public static UIImage Locked { get { return UIImageHelper.FromFileAuto("Images/locked"); } }
51+
52+
public static UIImage LoginUserUnknown { get { return UIImageHelper.FromFileAuto("Images/login_user_unknown"); } }
53+
5154

5255
public static Uri GitHubRepoUrl
5356
{
5.98 KB
Loading

CodeHub.iOS/Images/[email protected]

8.93 KB
Loading

CodeHub.iOS/Theme.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,7 @@ public UIColor ApplicationNavigationBarTint
164164
}
165165

166166
public float FontSizeRatio { get; set; }
167+
168+
public UIImage LoginUserUnknown { get { return Images.LoginUserUnknown; } }
167169
}
168170
}

0 commit comments

Comments
 (0)