Android UI updates.

This commit is contained in:
Kyle Spearrin 2016-08-22 22:59:42 -04:00
parent 610789fd6d
commit 34cb04cbde
9 changed files with 173 additions and 43 deletions

View file

@ -7,6 +7,7 @@ using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using AView = Android.Views.View;
using Android.Widget;
using Android.Text;
[assembly: ExportRenderer(typeof(ExtendedTextCell), typeof(ExtendedTextCellRenderer))]
namespace Bit.Android.Controls
@ -42,12 +43,24 @@ namespace Bit.Android.Controls
if(View.ChildCount > 1)
{
var layout = View.GetChildAt(1) as LinearLayout;
if(layout != null && layout.ChildCount > 0)
if(layout != null)
{
var textView = layout.GetChildAt(0) as TextView;
if(textView != null)
if(layout.ChildCount > 0)
{
textView.TextSize = (float)Device.GetNamedSize(NamedSize.Medium, typeof(Label));
var textView = layout.GetChildAt(0) as TextView;
if(textView != null)
{
textView.TextSize = (float)Device.GetNamedSize(NamedSize.Medium, typeof(Label));
}
}
if(layout.ChildCount > 1)
{
var detailView = layout.GetChildAt(1) as TextView;
if(detailView != null)
{
UpdateLineBreakMode(detailView, extendedCell.DetailLineBreakMode);
}
}
}
}
@ -70,6 +83,44 @@ namespace Bit.Android.Controls
// TODO: other properties
}
private void UpdateLineBreakMode(TextView view, LineBreakMode lineBreakMode)
{
if(view == null)
{
return;
}
switch(lineBreakMode)
{
case LineBreakMode.NoWrap:
view.SetSingleLine(true);
view.Ellipsize = null;
break;
case LineBreakMode.WordWrap:
view.SetSingleLine(false);
view.Ellipsize = null;
view.SetMaxLines(100);
break;
case LineBreakMode.CharacterWrap:
view.SetSingleLine(false);
view.Ellipsize = null;
view.SetMaxLines(100);
break;
case LineBreakMode.HeadTruncation:
view.SetSingleLine(true);
view.Ellipsize = TextUtils.TruncateAt.Start;
break;
case LineBreakMode.TailTruncation:
view.SetSingleLine(true);
view.Ellipsize = TextUtils.TruncateAt.End;
break;
case LineBreakMode.MiddleTruncation:
view.SetSingleLine(true);
view.Ellipsize = TextUtils.TruncateAt.Middle;
break;
}
}
private class DisclosureImage : ImageView
{
private ExtendedTextCell _cell;

View file

@ -42,6 +42,8 @@ namespace Bit.App.Controls
set { SetValue(DisclousureImageProperty, value); }
}
public LineBreakMode DetailLineBreakMode { get; set; } = LineBreakMode.TailTruncation;
public event EventHandler DisclousureTapped;
public void OnDisclousureTapped()

View file

@ -81,7 +81,7 @@ namespace Bit.App.Controls
{
if(!useLabelAsPlaceholder)
{
Entry.Margin = new Thickness(-11, 0, -11, -5);
Entry.Margin = new Thickness(-4, -7, -4, -11);
}
}

View file

@ -24,7 +24,10 @@ namespace Bit.App.Controls
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
Children = { Label, Detail },
Padding = new Thickness(15, 5, 5, 5),
Padding = Device.OnPlatform(
iOS: new Thickness(15, 5, 5, 5),
Android: new Thickness(15, 0, 5, 5),
WinPhone: new Thickness(15, 5, 5, 5)),
Spacing = 0
};

View file

@ -41,9 +41,17 @@ namespace Bit.App.Controls
Orientation = StackOrientation.Horizontal,
Children = { Label, StepperValueLabel, Stepper },
Spacing = 15,
Padding = new Thickness(15, 8)
Padding = Device.OnPlatform(
iOS: new Thickness(15, 8),
Android: new Thickness(15, 2),
WinPhone: new Thickness(15, 8))
};
if(Device.OS == TargetPlatform.Android)
{
Label.TextColor = Color.Black;
}
View = stackLayout;
}

View file

@ -53,9 +53,18 @@ Fingerprint by masterpage.com from the Noun Project")
var layout = new StackLayout
{
Children = { label },
Padding = new Thickness(15, 20)
Padding = Device.OnPlatform(
iOS: new Thickness(15, 20),
Android: new Thickness(16, 20),
WinPhone: new Thickness(15, 20)),
BackgroundColor = Color.White
};
if(Device.OS == TargetPlatform.Android)
{
label.TextColor = Color.Black;
}
View = layout;
}
}

View file

@ -41,15 +41,6 @@ namespace Bit.App.Pages
private void Init()
{
var fingerprintName = Device.OnPlatform(iOS: "Touch ID", Android: "Fingerprint", WinPhone: "Fingerprint");
FingerprintCell = new ExtendedSwitchCell
{
Text = "Unlock with " + fingerprintName + (!_fingerprint.IsAvailable ? " (Unavilable)" : null),
On = _settings.GetValueOrDefault<bool>(Constants.SettingFingerprintUnlockOn),
IsEnabled = _fingerprint.IsAvailable
};
FingerprintCell.OnChanged += FingerprintCell_Changed;
PinCell = new ExtendedSwitchCell
{
Text = "Unlock with PIN Code",
@ -72,6 +63,26 @@ namespace Bit.App.Pages
};
twoStepCell.Tapped += TwoStepCell_Tapped; ;
var securitySecion = new TableSection("Security")
{
LockOptionsCell,
PinCell,
twoStepCell
};
if(_fingerprint.IsAvailable)
{
var fingerprintName = Device.OnPlatform(iOS: "Touch ID", Android: "Fingerprint", WinPhone: "Fingerprint");
FingerprintCell = new ExtendedSwitchCell
{
Text = "Unlock with " + fingerprintName,
On = _settings.GetValueOrDefault<bool>(Constants.SettingFingerprintUnlockOn),
IsEnabled = _fingerprint.IsAvailable
};
FingerprintCell.OnChanged += FingerprintCell_Changed;
securitySecion.Insert(1, FingerprintCell);
}
var changeMasterPasswordCell = new ExtendedTextCell
{
Text = "Change Master Password",
@ -126,30 +137,38 @@ namespace Bit.App.Pages
};
helpCell.Tapped += HelpCell_Tapped;
var rateCell = new LongDetailViewCell("Rate the App", null);
rateCell.Tapped += RateCell_Tapped;
var otherSection = new TableSection("Other")
{
aboutCell,
helpCell
};
if(Device.OS == TargetPlatform.iOS)
{
rateCell.Detail.Text = "App Store ratings are reset with every new version of bitwarden."
+ " Please consider helping us out with a good review!";
var rateCell = new LongDetailViewCell("Rate the App",
"App Store ratings are reset with every new version of bitwarden."
+ " Please consider helping us out with a good review!");
rateCell.Tapped += RateCell_Tapped;
otherSection.Add(rateCell);
}
else
{
rateCell.Detail.Text = "Please consider helping us out with a good review!";
var rateCell = new ExtendedTextCell
{
Text = "Rate the App",
Detail = "Please consider helping us out with a good review!",
ShowDisclousure = true,
DetailLineBreakMode = LineBreakMode.WordWrap
};
rateCell.Tapped += RateCell_Tapped;
otherSection.Add(rateCell);
}
Table = new CustomTable
{
Root = new TableRoot
{
new TableSection("Security")
{
LockOptionsCell,
FingerprintCell,
PinCell,
twoStepCell
},
securitySecion,
new TableSection("Account")
{
changeMasterPasswordCell,
@ -165,12 +184,7 @@ namespace Bit.App.Pages
lockCell,
logOutCell
},
new TableSection("Other")
{
aboutCell,
helpCell,
rateCell
}
otherSection
}
};
@ -349,7 +363,11 @@ namespace Bit.App.Pages
_settings.AddOrUpdateValue(Constants.SettingPinUnlockOn, true);
_settings.AddOrUpdateValue(Constants.SettingFingerprintUnlockOn, false);
PinCell.On = true;
FingerprintCell.On = false;
if(FingerprintCell != null)
{
FingerprintCell.On = false;
}
}
private void FoldersCell_Tapped(object sender, EventArgs e)
@ -430,12 +448,6 @@ namespace Bit.App.Pages
Padding = new Thickness(15)
};
if(Device.OS == TargetPlatform.Android)
{
labelDetailStackLayout.Spacing = 5;
Label.TextColor = Color.Black;
}
ShowDisclousure = true;
View = labelDetailStackLayout;
}

View file

@ -209,9 +209,17 @@ namespace Bit.App.Pages
Orientation = StackOrientation.Horizontal,
Spacing = 15,
Children = { label, LengthSlider, Value },
Padding = new Thickness(15, 8)
Padding = Device.OnPlatform(
iOS: new Thickness(15, 8),
Android: new Thickness(16, 10),
WinPhone: new Thickness(15, 8))
};
if(Device.OS == TargetPlatform.Android)
{
label.TextColor = Color.Black;
}
View = stackLayout;
}

View file

@ -45,9 +45,46 @@ namespace Bit.iOS.Controls
}
WireUpForceUpdateSizeRequested(item, cell, tv);
UpdateLineBreakMode(cell.DetailTextLabel, extendedCell.DetailLineBreakMode);
}
return cell;
}
private void UpdateLineBreakMode(UILabel label, LineBreakMode lineBreakMode)
{
if(label == null)
{
return;
}
switch(lineBreakMode)
{
case LineBreakMode.NoWrap:
label.LineBreakMode = UILineBreakMode.Clip;
label.Lines = 1;
break;
case LineBreakMode.WordWrap:
label.LineBreakMode = UILineBreakMode.WordWrap;
label.Lines = 0;
break;
case LineBreakMode.CharacterWrap:
label.LineBreakMode = UILineBreakMode.CharacterWrap;
label.Lines = 0;
break;
case LineBreakMode.HeadTruncation:
label.LineBreakMode = UILineBreakMode.HeadTruncation;
label.Lines = 1;
break;
case LineBreakMode.MiddleTruncation:
label.LineBreakMode = UILineBreakMode.MiddleTruncation;
label.Lines = 1;
break;
case LineBreakMode.TailTruncation:
label.LineBreakMode = UILineBreakMode.TailTruncation;
label.Lines = 1;
break;
}
}
}
}