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

Commit

Permalink
Fixed IPad layout issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thedillonb committed Feb 7, 2016
1 parent e2b1c2a commit 6464940
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 149 deletions.
1 change: 0 additions & 1 deletion CodeHub.Core/CodeHub.Core.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<Compile Include="Filters\SourceFilterModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\ApplicationService.cs" />
<Compile Include="Services\GitHubAccountsService.cs" />
<Compile Include="Services\IApplicationService.cs" />
<Compile Include="ViewModels\Accounts\AccountsViewModel.cs" />
<Compile Include="ViewModels\Accounts\AddAccountViewModel.cs" />
Expand Down
2 changes: 1 addition & 1 deletion CodeHub.Core/Factories/ILoginFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CodeHub.Core.Factories
{
public interface ILoginFactory
{
Task<LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain, GitHubAccount existingAccount);
Task<LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain);

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

Expand Down
9 changes: 6 additions & 3 deletions CodeHub.Core/Factories/LoginFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CodeHub.Core.Data;
using GitHubSharp;
using System.Threading.Tasks;
using System.Linq;

namespace CodeHub.Core.Factories
{
Expand All @@ -16,17 +17,19 @@ public LoginFactory(IAccountsService accounts)
_accounts = accounts;
}

public async Task<LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain, GitHubAccount account)
public async Task<LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain)
{
var token = await Client.RequestAccessToken(clientId, clientSecret, code, redirect, requestDomain);
var client = Client.BasicOAuth(token.AccessToken, apiDomain);
var info = await client.ExecuteAsync(client.AuthenticatedUser.GetInfo());
var username = info.Data.Login;

//Does this user exist?

var account = _accounts.FirstOrDefault(x => string.Equals(x.Username, username) && string.Equals(x.Domain, apiDomain));
var exists = account != null;
if (!exists)
account = new GitHubAccount { Username = username };
account = account ?? new GitHubAccount { Username = username };

account.OAuth = token.AccessToken;
account.AvatarUrl = info.Data.AvatarUrl;
account.Domain = apiDomain;
Expand Down
33 changes: 17 additions & 16 deletions CodeHub.Core/Services/AccountsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

namespace CodeHub.Core.Services
{
public abstract class AccountsService<TAccount> : IAccountsService where TAccount : class, IAccount, new()
public class AccountsService : IAccountsService
{
private readonly SQLiteConnection _userDatabase;
private readonly IDefaultValueService _defaults;
private readonly string _accountsPath;

public IAccount ActiveAccount { get; private set; }
public GitHubAccount ActiveAccount { get; private set; }

protected AccountsService(IDefaultValueService defaults, IAccountPreferencesService accountPreferences)
public AccountsService(IDefaultValueService defaults, IAccountPreferencesService accountPreferences)
{
_defaults = defaults;
_accountsPath = accountPreferences.AccountsDir;
Expand All @@ -25,24 +25,24 @@ protected AccountsService(IDefaultValueService defaults, IAccountPreferencesServ
Directory.CreateDirectory(_accountsPath);

_userDatabase = new SQLiteConnection(Path.Combine(_accountsPath, "accounts.db"));
_userDatabase.CreateTable<TAccount>();
_userDatabase.CreateTable<GitHubAccount>();
}

public IAccount GetDefault()
public GitHubAccount GetDefault()
{
int id;
return !_defaults.TryGet("DEFAULT_ACCOUNT", out id) ? null : Find(id);
}

public void SetDefault(IAccount account)
public void SetDefault(GitHubAccount account)
{
if (account == null)
_defaults.Set("DEFAULT_ACCOUNT", null);
else
_defaults.Set("DEFAULT_ACCOUNT", account.Id);
}

public void SetActiveAccount(IAccount account)
public void SetActiveAccount(GitHubAccount account)
{
if (account != null)
{
Expand All @@ -54,20 +54,20 @@ public void SetActiveAccount(IAccount account)
ActiveAccount = account;
}

protected string CreateAccountDirectory(IAccount account)
protected string CreateAccountDirectory(GitHubAccount account)
{
return Path.Combine(_accountsPath, account.Id.ToString(CultureInfo.InvariantCulture));
}

public void Insert(IAccount account)
public void Insert(GitHubAccount account)
{
lock (_userDatabase)
{
_userDatabase.Insert(account);
}
}

public void Remove(IAccount account)
public void Remove(GitHubAccount account)
{
lock (_userDatabase)
{
Expand All @@ -80,31 +80,32 @@ public void Remove(IAccount account)
Directory.Delete(accountDir, true);
}

public void Update(IAccount account)
public void Update(GitHubAccount account)
{
lock (_userDatabase)
{
_userDatabase.Update(account);
}
}

public bool Exists(IAccount account)
public bool Exists(GitHubAccount account)
{
return Find(account.Id) != null;
}

public IAccount Find(int id)
public GitHubAccount Find(int id)
{
lock (_userDatabase)
{
var query = _userDatabase.Find<TAccount>(x => x.Id == id);
var query = _userDatabase.Find<GitHubAccount>(x => x.Id == id);
return query;
}
}

public IEnumerator<IAccount> GetEnumerator()
public IEnumerator<GitHubAccount> GetEnumerator()
{
return _userDatabase.Table<TAccount>().GetEnumerator();
foreach (var account in _userDatabase.Table<GitHubAccount>())
yield return account;
}

IEnumerator IEnumerable.GetEnumerator()
Expand Down
14 changes: 0 additions & 14 deletions CodeHub.Core/Services/GitHubAccountsService.cs

This file was deleted.

20 changes: 10 additions & 10 deletions CodeHub.Core/Services/IAccountsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,52 @@

namespace CodeHub.Core.Services
{
public interface IAccountsService : IEnumerable<IAccount>
public interface IAccountsService : IEnumerable<GitHubAccount>
{
/// <summary>
/// Gets the active account
/// </summary>
IAccount ActiveAccount { get; }
GitHubAccount ActiveAccount { get; }

/// <summary>
/// Sets the active account
/// </summary>
/// <param name="account"></param>
void SetActiveAccount(IAccount account);
void SetActiveAccount(GitHubAccount account);

/// <summary>
/// Gets the default account
/// </summary>
IAccount GetDefault();
GitHubAccount GetDefault();

/// <summary>
/// Sets the default account
/// </summary>
void SetDefault(IAccount account);
void SetDefault(GitHubAccount account);

/// <summary>
/// Insert the specified account.
/// </summary>
void Insert(IAccount account);
void Insert(GitHubAccount account);

/// <summary>
/// Remove the specified account.
/// </summary>
void Remove(IAccount account);
void Remove(GitHubAccount account);

/// <summary>
/// Update this instance in the database
/// </summary>
void Update(IAccount account);
void Update(GitHubAccount account);

/// <summary>
/// Checks to see whether a specific account exists (Username comparison)
/// </summary>
bool Exists(IAccount account);
bool Exists(GitHubAccount account);

/// <summary>
/// Find the specified account via it's username
/// </summary>
IAccount Find(int id);
GitHubAccount Find(int id);
}
}
50 changes: 4 additions & 46 deletions CodeHub.Core/ViewModels/Accounts/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public string LoginUrl
}
}

public bool IsEnterprise { get; private set; }

public GitHubAccount AttemptedAccount { get; private set; }

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

public void Init(NavObject navObject)
{
IsEnterprise = navObject.IsEnterprise;
WebDomain = navObject.WebDomain;

if (WebDomain == null && !IsEnterprise)
{
WebDomain = GitHubSharp.Client.AccessTokenUri;
}
WebDomain = navObject.WebDomain ?? GitHubSharp.Client.AccessTokenUri;

if (navObject.AttemptedAccountId >= 0)
{
AttemptedAccount = this.GetApplication().Accounts.Find(navObject.AttemptedAccountId) as GitHubAccount;

//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
if (WebDomain == null && IsEnterprise)
{
try
{
WebDomain = AttemptedAccount.Domain.Substring(0, AttemptedAccount.Domain.IndexOf("/api"));
}
catch
{
//Doh!
}
}
AttemptedAccount = this.GetApplication().Accounts.Find(navObject.AttemptedAccountId);
}
}

public async Task Login(string code)
{
string apiUrl;
if (IsEnterprise)
{
apiUrl = WebDomain;
if (!apiUrl.StartsWith("http://") && !apiUrl.StartsWith("https://"))
apiUrl = "https://" + apiUrl;
if (!apiUrl.EndsWith("/"))
apiUrl += "/";
if (!apiUrl.Contains("/api/"))
apiUrl += "api/v3/";

apiUrl = apiUrl.TrimEnd('/');
}
else
{
apiUrl = GitHubSharp.Client.DefaultApi;
}

LoginData loginData = null;
bool shouldPromptPush = false;

try
{
IsLoggingIn = true;
var account = AttemptedAccount;
loginData = await _loginFactory.LoginWithToken(ClientId, ClientSecret, code, RedirectUri, WebDomain, apiUrl, account);
loginData = await _loginFactory.LoginWithToken(ClientId, ClientSecret, code, RedirectUri, WebDomain, GitHubSharp.Client.DefaultApi);

if (!_featuresService.IsPushNotificationsActivated && !IsEnterprise)
if (!_featuresService.IsPushNotificationsActivated)
{
try
{
Expand Down Expand Up @@ -157,7 +117,6 @@ public async Task Login(string code)
public class NavObject
{
public string Username { get; set; }
public bool IsEnterprise { get; set; }
public string WebDomain { get; set; }
public int AttemptedAccountId { get; set; }

Expand All @@ -171,7 +130,6 @@ public static NavObject CreateDontRemember(GitHubAccount account)
return new NavObject
{
WebDomain = account.WebDomain,
IsEnterprise = !string.Equals(account.Domain, GitHubSharp.Client.DefaultApi),
Username = account.Username,
AttemptedAccountId = account.Id
};
Expand Down
11 changes: 11 additions & 0 deletions CodeHub.Core/ViewModels/App/StartupViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ protected async override void Startup()
if (account.DontRemember)
{
ShowViewModel<Accounts.AccountsViewModel>();

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

return;
}

Expand Down
2 changes: 1 addition & 1 deletion CodeHub.iOS/Elements/IssueElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected override NSString CellKey {
public override UITableViewCell GetCell (UITableView tv)
{
var cell = tv.DequeueReusableCell(CellKey) as IssueCellView ?? IssueCellView.Create();
cell.Bind(Title, Status, Priority, Assigned, LastUpdated, Id, Kind);
cell.Bind(Title, Status, Priority, Assigned, LastUpdated, Id, Kind);
return cell;
}

Expand Down
10 changes: 8 additions & 2 deletions CodeHub.iOS/Elements/SplitViewElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,22 @@ public SplitButton(UIImage image, string text = null)
_text.MinimumScaleFactor = 0.7f;
this.Add(_text);
}

private static bool IsPad = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad;

public override void LayoutSubviews()
{
base.LayoutSubviews();

var offset = IsPad ? 24f : 18f;
var rightOffset = IsPad ? 16f : 14f;

var height = (this.Bounds.Height - 24f);
_image.Frame = new CGRect(15, 12, height, height);
_image.Frame = new CGRect(offset, 12, height, height);

var textHeight = (int)Math.Ceiling(TextFont.LineHeight) + 1;
var textY = (this.Bounds.Height / 2) - (textHeight / 2);
_text.Frame = new CGRect(_image.Frame.Right + 10f, textY, (int)Math.Floor(this.Bounds.Width) - (_image.Frame.Right + 10f + _image.Frame.Left), textHeight);
_text.Frame = new CGRect(_image.Frame.Right + rightOffset, textY, (int)Math.Floor(this.Bounds.Width) - (_image.Frame.Right + rightOffset + _image.Frame.Left), textHeight);
}
}
}
Expand Down
Loading

0 comments on commit 6464940

Please sign in to comment.