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

Commit 6464940

Browse files
committed
Fixed IPad layout issues
1 parent e2b1c2a commit 6464940

File tree

18 files changed

+98
-149
lines changed

18 files changed

+98
-149
lines changed

CodeHub.Core/CodeHub.Core.iOS.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
<Compile Include="Filters\SourceFilterModel.cs" />
4444
<Compile Include="Properties\AssemblyInfo.cs" />
4545
<Compile Include="Services\ApplicationService.cs" />
46-
<Compile Include="Services\GitHubAccountsService.cs" />
4746
<Compile Include="Services\IApplicationService.cs" />
4847
<Compile Include="ViewModels\Accounts\AccountsViewModel.cs" />
4948
<Compile Include="ViewModels\Accounts\AddAccountViewModel.cs" />

CodeHub.Core/Factories/ILoginFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace CodeHub.Core.Factories
55
{
66
public interface ILoginFactory
77
{
8-
Task<LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain, GitHubAccount existingAccount);
8+
Task<LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain);
99

1010
Task<GitHubSharp.Client> LoginAccount(GitHubAccount account);
1111

CodeHub.Core/Factories/LoginFactory.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using CodeHub.Core.Data;
44
using GitHubSharp;
55
using System.Threading.Tasks;
6+
using System.Linq;
67

78
namespace CodeHub.Core.Factories
89
{
@@ -16,17 +17,19 @@ public LoginFactory(IAccountsService accounts)
1617
_accounts = accounts;
1718
}
1819

19-
public async Task<LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain, GitHubAccount account)
20+
public async Task<LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain)
2021
{
2122
var token = await Client.RequestAccessToken(clientId, clientSecret, code, redirect, requestDomain);
2223
var client = Client.BasicOAuth(token.AccessToken, apiDomain);
2324
var info = await client.ExecuteAsync(client.AuthenticatedUser.GetInfo());
2425
var username = info.Data.Login;
2526

2627
//Does this user exist?
28+
29+
var account = _accounts.FirstOrDefault(x => string.Equals(x.Username, username) && string.Equals(x.Domain, apiDomain));
2730
var exists = account != null;
28-
if (!exists)
29-
account = new GitHubAccount { Username = username };
31+
account = account ?? new GitHubAccount { Username = username };
32+
3033
account.OAuth = token.AccessToken;
3134
account.AvatarUrl = info.Data.AvatarUrl;
3235
account.Domain = apiDomain;

CodeHub.Core/Services/AccountsService.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
namespace CodeHub.Core.Services
99
{
10-
public abstract class AccountsService<TAccount> : IAccountsService where TAccount : class, IAccount, new()
10+
public class AccountsService : IAccountsService
1111
{
1212
private readonly SQLiteConnection _userDatabase;
1313
private readonly IDefaultValueService _defaults;
1414
private readonly string _accountsPath;
1515

16-
public IAccount ActiveAccount { get; private set; }
16+
public GitHubAccount ActiveAccount { get; private set; }
1717

18-
protected AccountsService(IDefaultValueService defaults, IAccountPreferencesService accountPreferences)
18+
public AccountsService(IDefaultValueService defaults, IAccountPreferencesService accountPreferences)
1919
{
2020
_defaults = defaults;
2121
_accountsPath = accountPreferences.AccountsDir;
@@ -25,24 +25,24 @@ protected AccountsService(IDefaultValueService defaults, IAccountPreferencesServ
2525
Directory.CreateDirectory(_accountsPath);
2626

2727
_userDatabase = new SQLiteConnection(Path.Combine(_accountsPath, "accounts.db"));
28-
_userDatabase.CreateTable<TAccount>();
28+
_userDatabase.CreateTable<GitHubAccount>();
2929
}
3030

31-
public IAccount GetDefault()
31+
public GitHubAccount GetDefault()
3232
{
3333
int id;
3434
return !_defaults.TryGet("DEFAULT_ACCOUNT", out id) ? null : Find(id);
3535
}
3636

37-
public void SetDefault(IAccount account)
37+
public void SetDefault(GitHubAccount account)
3838
{
3939
if (account == null)
4040
_defaults.Set("DEFAULT_ACCOUNT", null);
4141
else
4242
_defaults.Set("DEFAULT_ACCOUNT", account.Id);
4343
}
4444

45-
public void SetActiveAccount(IAccount account)
45+
public void SetActiveAccount(GitHubAccount account)
4646
{
4747
if (account != null)
4848
{
@@ -54,20 +54,20 @@ public void SetActiveAccount(IAccount account)
5454
ActiveAccount = account;
5555
}
5656

57-
protected string CreateAccountDirectory(IAccount account)
57+
protected string CreateAccountDirectory(GitHubAccount account)
5858
{
5959
return Path.Combine(_accountsPath, account.Id.ToString(CultureInfo.InvariantCulture));
6060
}
6161

62-
public void Insert(IAccount account)
62+
public void Insert(GitHubAccount account)
6363
{
6464
lock (_userDatabase)
6565
{
6666
_userDatabase.Insert(account);
6767
}
6868
}
6969

70-
public void Remove(IAccount account)
70+
public void Remove(GitHubAccount account)
7171
{
7272
lock (_userDatabase)
7373
{
@@ -80,31 +80,32 @@ public void Remove(IAccount account)
8080
Directory.Delete(accountDir, true);
8181
}
8282

83-
public void Update(IAccount account)
83+
public void Update(GitHubAccount account)
8484
{
8585
lock (_userDatabase)
8686
{
8787
_userDatabase.Update(account);
8888
}
8989
}
9090

91-
public bool Exists(IAccount account)
91+
public bool Exists(GitHubAccount account)
9292
{
9393
return Find(account.Id) != null;
9494
}
9595

96-
public IAccount Find(int id)
96+
public GitHubAccount Find(int id)
9797
{
9898
lock (_userDatabase)
9999
{
100-
var query = _userDatabase.Find<TAccount>(x => x.Id == id);
100+
var query = _userDatabase.Find<GitHubAccount>(x => x.Id == id);
101101
return query;
102102
}
103103
}
104104

105-
public IEnumerator<IAccount> GetEnumerator()
105+
public IEnumerator<GitHubAccount> GetEnumerator()
106106
{
107-
return _userDatabase.Table<TAccount>().GetEnumerator();
107+
foreach (var account in _userDatabase.Table<GitHubAccount>())
108+
yield return account;
108109
}
109110

110111
IEnumerator IEnumerable.GetEnumerator()

CodeHub.Core/Services/GitHubAccountsService.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

CodeHub.Core/Services/IAccountsService.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,52 @@
33

44
namespace CodeHub.Core.Services
55
{
6-
public interface IAccountsService : IEnumerable<IAccount>
6+
public interface IAccountsService : IEnumerable<GitHubAccount>
77
{
88
/// <summary>
99
/// Gets the active account
1010
/// </summary>
11-
IAccount ActiveAccount { get; }
11+
GitHubAccount ActiveAccount { get; }
1212

1313
/// <summary>
1414
/// Sets the active account
1515
/// </summary>
1616
/// <param name="account"></param>
17-
void SetActiveAccount(IAccount account);
17+
void SetActiveAccount(GitHubAccount account);
1818

1919
/// <summary>
2020
/// Gets the default account
2121
/// </summary>
22-
IAccount GetDefault();
22+
GitHubAccount GetDefault();
2323

2424
/// <summary>
2525
/// Sets the default account
2626
/// </summary>
27-
void SetDefault(IAccount account);
27+
void SetDefault(GitHubAccount account);
2828

2929
/// <summary>
3030
/// Insert the specified account.
3131
/// </summary>
32-
void Insert(IAccount account);
32+
void Insert(GitHubAccount account);
3333

3434
/// <summary>
3535
/// Remove the specified account.
3636
/// </summary>
37-
void Remove(IAccount account);
37+
void Remove(GitHubAccount account);
3838

3939
/// <summary>
4040
/// Update this instance in the database
4141
/// </summary>
42-
void Update(IAccount account);
42+
void Update(GitHubAccount account);
4343

4444
/// <summary>
4545
/// Checks to see whether a specific account exists (Username comparison)
4646
/// </summary>
47-
bool Exists(IAccount account);
47+
bool Exists(GitHubAccount account);
4848

4949
/// <summary>
5050
/// Find the specified account via it's username
5151
/// </summary>
52-
IAccount Find(int id);
52+
GitHubAccount Find(int id);
5353
}
5454
}

CodeHub.Core/ViewModels/Accounts/LoginViewModel.cs

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public string LoginUrl
4343
}
4444
}
4545

46-
public bool IsEnterprise { get; private set; }
47-
4846
public GitHubAccount AttemptedAccount { get; private set; }
4947

5048
public string WebDomain { get; set; }
@@ -62,63 +60,25 @@ public LoginViewModel(ILoginFactory loginFactory, IFeaturesService featuresServi
6260

6361
public void Init(NavObject navObject)
6462
{
65-
IsEnterprise = navObject.IsEnterprise;
66-
WebDomain = navObject.WebDomain;
67-
68-
if (WebDomain == null && !IsEnterprise)
69-
{
70-
WebDomain = GitHubSharp.Client.AccessTokenUri;
71-
}
63+
WebDomain = navObject.WebDomain ?? GitHubSharp.Client.AccessTokenUri;
7264

7365
if (navObject.AttemptedAccountId >= 0)
7466
{
75-
AttemptedAccount = this.GetApplication().Accounts.Find(navObject.AttemptedAccountId) as GitHubAccount;
76-
77-
//This is a hack to get around the fact that WebDomain will be null for Enterprise users since the last version did not contain the variable
78-
if (WebDomain == null && IsEnterprise)
79-
{
80-
try
81-
{
82-
WebDomain = AttemptedAccount.Domain.Substring(0, AttemptedAccount.Domain.IndexOf("/api"));
83-
}
84-
catch
85-
{
86-
//Doh!
87-
}
88-
}
67+
AttemptedAccount = this.GetApplication().Accounts.Find(navObject.AttemptedAccountId);
8968
}
9069
}
9170

9271
public async Task Login(string code)
9372
{
94-
string apiUrl;
95-
if (IsEnterprise)
96-
{
97-
apiUrl = WebDomain;
98-
if (!apiUrl.StartsWith("http://") && !apiUrl.StartsWith("https://"))
99-
apiUrl = "https://" + apiUrl;
100-
if (!apiUrl.EndsWith("/"))
101-
apiUrl += "/";
102-
if (!apiUrl.Contains("/api/"))
103-
apiUrl += "api/v3/";
104-
105-
apiUrl = apiUrl.TrimEnd('/');
106-
}
107-
else
108-
{
109-
apiUrl = GitHubSharp.Client.DefaultApi;
110-
}
111-
11273
LoginData loginData = null;
11374
bool shouldPromptPush = false;
11475

11576
try
11677
{
11778
IsLoggingIn = true;
118-
var account = AttemptedAccount;
119-
loginData = await _loginFactory.LoginWithToken(ClientId, ClientSecret, code, RedirectUri, WebDomain, apiUrl, account);
79+
loginData = await _loginFactory.LoginWithToken(ClientId, ClientSecret, code, RedirectUri, WebDomain, GitHubSharp.Client.DefaultApi);
12080

121-
if (!_featuresService.IsPushNotificationsActivated && !IsEnterprise)
81+
if (!_featuresService.IsPushNotificationsActivated)
12282
{
12383
try
12484
{
@@ -157,7 +117,6 @@ public async Task Login(string code)
157117
public class NavObject
158118
{
159119
public string Username { get; set; }
160-
public bool IsEnterprise { get; set; }
161120
public string WebDomain { get; set; }
162121
public int AttemptedAccountId { get; set; }
163122

@@ -171,7 +130,6 @@ public static NavObject CreateDontRemember(GitHubAccount account)
171130
return new NavObject
172131
{
173132
WebDomain = account.WebDomain,
174-
IsEnterprise = !string.Equals(account.Domain, GitHubSharp.Client.DefaultApi),
175133
Username = account.Username,
176134
AttemptedAccountId = account.Id
177135
};

CodeHub.Core/ViewModels/App/StartupViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ protected async override void Startup()
3838
if (account.DontRemember)
3939
{
4040
ShowViewModel<Accounts.AccountsViewModel>();
41+
42+
//Hack for now
43+
if (isEnterprise)
44+
{
45+
ShowViewModel<Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { AttemptedAccountId = account.Id });
46+
}
47+
else
48+
{
49+
ShowViewModel<Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account));
50+
}
51+
4152
return;
4253
}
4354

CodeHub.iOS/Elements/IssueElement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected override NSString CellKey {
5353
public override UITableViewCell GetCell (UITableView tv)
5454
{
5555
var cell = tv.DequeueReusableCell(CellKey) as IssueCellView ?? IssueCellView.Create();
56-
cell.Bind(Title, Status, Priority, Assigned, LastUpdated, Id, Kind);
56+
cell.Bind(Title, Status, Priority, Assigned, LastUpdated, Id, Kind);
5757
return cell;
5858
}
5959

CodeHub.iOS/Elements/SplitViewElement.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,22 @@ public SplitButton(UIImage image, string text = null)
144144
_text.MinimumScaleFactor = 0.7f;
145145
this.Add(_text);
146146
}
147+
148+
private static bool IsPad = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad;
149+
147150
public override void LayoutSubviews()
148151
{
149152
base.LayoutSubviews();
150153

154+
var offset = IsPad ? 24f : 18f;
155+
var rightOffset = IsPad ? 16f : 14f;
156+
151157
var height = (this.Bounds.Height - 24f);
152-
_image.Frame = new CGRect(15, 12, height, height);
158+
_image.Frame = new CGRect(offset, 12, height, height);
153159

154160
var textHeight = (int)Math.Ceiling(TextFont.LineHeight) + 1;
155161
var textY = (this.Bounds.Height / 2) - (textHeight / 2);
156-
_text.Frame = new CGRect(_image.Frame.Right + 10f, textY, (int)Math.Floor(this.Bounds.Width) - (_image.Frame.Right + 10f + _image.Frame.Left), textHeight);
162+
_text.Frame = new CGRect(_image.Frame.Right + rightOffset, textY, (int)Math.Floor(this.Bounds.Width) - (_image.Frame.Right + rightOffset + _image.Frame.Left), textHeight);
157163
}
158164
}
159165
}

0 commit comments

Comments
 (0)