mirror of
https://github.com/bitwarden/mobile
synced 2025-12-21 02:33:36 +00:00
PS-70 Fixed grid cell width. Added red progress at 20 percent. Refactored circular progress view.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
StyleClass="list-row, list-row-platform"
|
StyleClass="list-row, list-row-platform"
|
||||||
RowSpacing="0"
|
RowSpacing="0"
|
||||||
ColumnSpacing="0"
|
ColumnSpacing="0"
|
||||||
|
HorizontalOptions="FillAndExpand"
|
||||||
x:DataType="pages:GroupingsPageTOTPListItem">
|
x:DataType="pages:GroupingsPageTOTPListItem">
|
||||||
|
|
||||||
<Grid.Resources>
|
<Grid.Resources>
|
||||||
@@ -26,8 +27,8 @@
|
|||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="40" />
|
<ColumnDefinition Width="40" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="60" />
|
<ColumnDefinition Width="40" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto"/>
|
||||||
<ColumnDefinition Width="40" />
|
<ColumnDefinition Width="40" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
@@ -59,63 +60,55 @@
|
|||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
|
HorizontalOptions="FillAndExpand"
|
||||||
Padding="0, 7">
|
Padding="0, 7">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<Grid.ColumnDefinitions>
|
|
||||||
<ColumnDefinition Width="Auto" />
|
|
||||||
<ColumnDefinition Width="Auto" />
|
|
||||||
<ColumnDefinition Width="*" />
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
|
|
||||||
<controls:MonoLabel
|
<controls:MonoLabel
|
||||||
LineBreakMode="TailTruncation"
|
LineBreakMode="TailTruncation"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.ColumnSpan="3"
|
|
||||||
StyleClass="list-title, list-title-platform"
|
StyleClass="list-title, list-title-platform"
|
||||||
Text="{Binding TotpCodeFormatted, Mode=OneWay}" />
|
Text="{Binding Cipher.Name}" />
|
||||||
<Label
|
<Label
|
||||||
LineBreakMode="TailTruncation"
|
LineBreakMode="TailTruncation"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
StyleClass="list-subtitle, list-subtitle-platform"
|
StyleClass="list-subtitle, list-subtitle-platform"
|
||||||
Text="{Binding Cipher.Name}" />
|
Text="{Binding Cipher.SubTitle}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<controls:CircularProgressbarView
|
<controls:CircularProgressbarView
|
||||||
Progress="{Binding Progress}"
|
Progress="{Binding Progress}"
|
||||||
Margin="0, 10, 0, 0"
|
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
Grid.RowSpan="2"
|
HorizontalOptions="FillAndExpand"
|
||||||
VerticalOptions="CenterAndExpand" />
|
VerticalOptions="CenterAndExpand" />
|
||||||
|
|
||||||
<Label
|
<Label
|
||||||
Text="{Binding TotpSec, Mode=OneWay}"
|
Text="{Binding TotpSec, Mode=OneWay}"
|
||||||
Style="{DynamicResource textTotp}"
|
Style="{DynamicResource textTotp}"
|
||||||
Margin="0, 0, 0, 10"
|
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
Grid.RowSpan="2"
|
|
||||||
StyleClass="text-sm"
|
StyleClass="text-sm"
|
||||||
HorizontalTextAlignment="Center"
|
XAlign="Center"
|
||||||
VerticalOptions="CenterAndExpand" />
|
YAlign="Center"
|
||||||
|
HorizontalOptions="FillAndExpand"
|
||||||
|
VerticalOptions="FillAndExpand"/>
|
||||||
|
|
||||||
<Label
|
<controls:MonoLabel
|
||||||
Text="{Binding TotpCodeFormatted, Mode=OneWay}"
|
Text="{Binding TotpCodeFormatted, Mode=OneWay}"
|
||||||
Style="{DynamicResource textTotp}"
|
Style="{DynamicResource textTotp}"
|
||||||
Margin="0, 0, 0, 0"
|
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="3"
|
Grid.Column="3"
|
||||||
Grid.RowSpan="2"
|
StyleClass="list-title, list-title-platform"
|
||||||
StyleClass="text-sm"
|
XAlign="Center"
|
||||||
HorizontalOptions="CenterAndExpand"
|
YAlign="Center"
|
||||||
HorizontalTextAlignment="Center"
|
HorizontalOptions="FillAndExpand"
|
||||||
VerticalOptions="CenterAndExpand" />
|
VerticalOptions="FillAndExpand" />
|
||||||
|
|
||||||
<controls:IconButton
|
<controls:IconButton
|
||||||
StyleClass="box-row-button, box-row-button-platform"
|
StyleClass="box-row-button, box-row-button-platform"
|
||||||
@@ -124,8 +117,9 @@
|
|||||||
CommandParameter="LoginTotp"
|
CommandParameter="LoginTotp"
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="4"
|
Grid.Column="4"
|
||||||
Grid.RowSpan="2"
|
|
||||||
Padding="0,0,1,0"
|
Padding="0,0,1,0"
|
||||||
|
HorizontalOptions="FillAndExpand"
|
||||||
|
VerticalOptions="CenterAndExpand"
|
||||||
AutomationProperties.IsInAccessibleTree="True"
|
AutomationProperties.IsInAccessibleTree="True"
|
||||||
AutomationProperties.Name="{u:I18n CopyTotp}" />
|
AutomationProperties.Name="{u:I18n CopyTotp}" />
|
||||||
</controls:ExtendedGrid>
|
</controls:ExtendedGrid>
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
using SkiaSharp.Views.Forms;
|
using SkiaSharp.Views.Forms;
|
||||||
|
using Xamarin.Essentials;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Bit.App.Controls
|
namespace Bit.App.Controls
|
||||||
@@ -13,8 +14,6 @@ namespace Bit.App.Controls
|
|||||||
public static readonly BindableProperty ProgressProperty = BindableProperty.Create(
|
public static readonly BindableProperty ProgressProperty = BindableProperty.Create(
|
||||||
"Progress", typeof(double), typeof(CircularProgressbarView), propertyChanged: OnProgressChanged);
|
"Progress", typeof(double), typeof(CircularProgressbarView), propertyChanged: OnProgressChanged);
|
||||||
|
|
||||||
public SKColor Color => Progress > 90 ? SKColors.Red : SKColors.Blue;
|
|
||||||
|
|
||||||
public double Progress
|
public double Progress
|
||||||
{
|
{
|
||||||
get { return (double)GetValue(ProgressProperty); }
|
get { return (double)GetValue(ProgressProperty); }
|
||||||
@@ -30,8 +29,9 @@ namespace Bit.App.Controls
|
|||||||
public CircularProgressbarView()
|
public CircularProgressbarView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
var circle = new Circle(25, (info) => new SKPoint((float)info.Width / 2, (float)info.Height / 2));
|
var pixels = DeviceDisplay.MainDisplayInfo.Density * 15;
|
||||||
_progressDrawer = new ProgressDrawer(SkCanvasView, circle, () => (float)Progress, 5, SKColors.White, Color);
|
var circle = new Circle((float)pixels, (info) => new SKPoint((float)info.Width / 2, (float)info.Height / 2));
|
||||||
|
_progressDrawer = new ProgressDrawer(SkCanvasView, circle, () => (float)Progress, 5, SKColors.White, SKColors.Blue, SKColors.Red);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,59 +48,22 @@ namespace Bit.App.Controls
|
|||||||
public float Redius { get; set; }
|
public float Redius { get; set; }
|
||||||
public SKRect Rect => new SKRect(Center.X - Redius, Center.Y - Redius, Center.X + Redius, Center.Y + Redius);
|
public SKRect Rect => new SKRect(Center.X - Redius, Center.Y - Redius, Center.X + Redius, Center.Y + Redius);
|
||||||
|
|
||||||
public class ProgressDrawer
|
|
||||||
{
|
|
||||||
|
|
||||||
public ProgressDrawer(SKCanvasView canvas, Circle circle, Func<float> progress, float strokeWidth, SKColor progressColor, SKColor foregroundColor)
|
|
||||||
{
|
|
||||||
canvas.PaintSurface += (sender, args) =>
|
|
||||||
{
|
|
||||||
circle.CalculateCenter(args.Info);
|
|
||||||
args.Surface.Canvas.Clear();
|
|
||||||
DrawCircle(args.Surface.Canvas, circle, strokeWidth, progressColor);
|
|
||||||
DrawArc(args.Surface.Canvas, circle, progress, strokeWidth, foregroundColor);
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawCircle(SKCanvas canvas, Circle circle, float strokewidth, SKColor color)
|
|
||||||
{
|
|
||||||
canvas.DrawCircle(circle.Center, circle.Redius,
|
|
||||||
new SKPaint()
|
|
||||||
{
|
|
||||||
StrokeWidth = strokewidth,
|
|
||||||
Color = color,
|
|
||||||
IsStroke = true,
|
|
||||||
IsAntialias = true,
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawArc(SKCanvas canvas, Circle circle, Func<float> progress, float strokewidth, SKColor color)
|
|
||||||
{
|
|
||||||
var angle = progress.Invoke() * 3.6f;
|
|
||||||
canvas.DrawArc(circle.Rect, 270, angle, false,
|
|
||||||
new SKPaint() { StrokeWidth = strokewidth, Color = color, IsStroke = true, IsAntialias = true });
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CalculateCenter(SKImageInfo argsInfo)
|
public void CalculateCenter(SKImageInfo argsInfo)
|
||||||
{
|
{
|
||||||
Center = _centerfunc.Invoke(argsInfo);
|
Center = _centerfunc.Invoke(argsInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProgressDrawer
|
public class ProgressDrawer
|
||||||
{
|
{
|
||||||
public ProgressDrawer(SKCanvasView canvas, Circle circle, Func<float> progress, float strokeWidth, SKColor progressColor, SKColor foregroundColor)
|
public ProgressDrawer(SKCanvasView canvas, Circle circle, Func<float> progress, float strokeWidth, SKColor progressColor, SKColor foregroundColor, SKColor progressEndColor)
|
||||||
{
|
{
|
||||||
canvas.PaintSurface += (sender, args) =>
|
canvas.PaintSurface += (sender, args) =>
|
||||||
{
|
{
|
||||||
circle.CalculateCenter(args.Info);
|
circle.CalculateCenter(args.Info);
|
||||||
args.Surface.Canvas.Clear();
|
args.Surface.Canvas.Clear();
|
||||||
DrawCircle(args.Surface.Canvas, circle, strokeWidth, progressColor);
|
DrawCircle(args.Surface.Canvas, circle, strokeWidth, progressColor);
|
||||||
DrawArc(args.Surface.Canvas, circle, progress, strokeWidth, foregroundColor);
|
DrawArc(args.Surface.Canvas, circle, progress, strokeWidth, foregroundColor, progressEndColor);
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,11 +79,16 @@ namespace Bit.App.Controls
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawArc(SKCanvas canvas, Circle circle, Func<float> progress, float strokewidth, SKColor color)
|
private void DrawArc(SKCanvas canvas, Circle circle, Func<float> progress, float strokewidth, SKColor color, SKColor progressEndColor)
|
||||||
{
|
{
|
||||||
var angle = progress.Invoke() * 3.6f;
|
var progressValue = progress.Invoke();
|
||||||
|
var angle = progressValue * 3.6f;
|
||||||
canvas.DrawArc(circle.Rect, 270, angle, false,
|
canvas.DrawArc(circle.Rect, 270, angle, false,
|
||||||
new SKPaint() { StrokeWidth = strokewidth, Color = color, IsStroke = true,
|
new SKPaint()
|
||||||
|
{
|
||||||
|
StrokeWidth = strokewidth,
|
||||||
|
Color = progressValue < 20f ? progressEndColor : color,
|
||||||
|
IsStroke = true,
|
||||||
IsAntialias = true
|
IsAntialias = true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user