mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
dismiss previous toast & cleanup
This commit is contained in:
parent
c4c24ee240
commit
ece35b96db
2 changed files with 35 additions and 7 deletions
|
@ -12,7 +12,7 @@ namespace Bit.iOS.Core.Views
|
|||
private NSLayoutConstraint _rightMarginConstraint;
|
||||
private NSLayoutConstraint _bottomMarginConstraint;
|
||||
|
||||
public Toast(string text)
|
||||
public Toast(string text)
|
||||
: base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 38))
|
||||
{
|
||||
TranslatesAutoresizingMaskIntoConstraints = false;
|
||||
|
@ -47,9 +47,11 @@ namespace Bit.iOS.Core.Views
|
|||
AddConstraints(hMessageConstraints);
|
||||
AddConstraints(vMessageConstraints);
|
||||
|
||||
AddGestureRecognizer(new UITapGestureRecognizer(() => Dismiss()));
|
||||
AddGestureRecognizer(new UITapGestureRecognizer(() => Dismiss(false)));
|
||||
}
|
||||
|
||||
public bool Dismissed { get; set; }
|
||||
public Action DismissCallback { get; set; }
|
||||
public TimeSpan Duration { get; set; } = TimeSpan.FromSeconds(3);
|
||||
public UILabel MessageLabel { get; set; }
|
||||
public nfloat LeftMargin { get; set; } = 5;
|
||||
|
@ -104,17 +106,28 @@ namespace Bit.iOS.Core.Views
|
|||
|
||||
public void Dismiss(bool animated = true)
|
||||
{
|
||||
if(Dismissed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Dismissed = true;
|
||||
_dismissTimer?.Invalidate();
|
||||
_dismissTimer = null;
|
||||
|
||||
if(!animated)
|
||||
{
|
||||
RemoveFromSuperview();
|
||||
DismissCallback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
SetNeedsLayout();
|
||||
Animate(0.3f, 0, UIViewAnimationOptions.CurveEaseIn, () => { Alpha = 0; }, RemoveFromSuperview);
|
||||
Animate(0.3f, 0, UIViewAnimationOptions.CurveEaseIn, () => { Alpha = 0; }, () =>
|
||||
{
|
||||
RemoveFromSuperview();
|
||||
DismissCallback?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
private void ShowWithAnimation()
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace Bit.iOS.Services
|
|||
private readonly IAppSettingsService _appSettingsService;
|
||||
private readonly IDeviceInfoService _deviceInfoService;
|
||||
private UIAlertController _progressAlert;
|
||||
private Toast _toast;
|
||||
|
||||
public DeviceActionService(
|
||||
IAppSettingsService appSettingsService,
|
||||
|
@ -32,17 +33,27 @@ namespace Bit.iOS.Services
|
|||
|
||||
public void Toast(string text, bool longDuration = false)
|
||||
{
|
||||
var t = new Toast(text)
|
||||
if(_toast != null && !_toast.Dismissed)
|
||||
{
|
||||
_toast.Dismiss(false);
|
||||
}
|
||||
|
||||
_toast = new Toast(text)
|
||||
{
|
||||
Duration = TimeSpan.FromSeconds(longDuration ? 5 : 3)
|
||||
};
|
||||
|
||||
if(TabBarVisible())
|
||||
{
|
||||
t.BottomMargin = 55;
|
||||
_toast.BottomMargin = 55;
|
||||
}
|
||||
|
||||
t.Show();
|
||||
_toast.Show();
|
||||
_toast.DismissCallback = () =>
|
||||
{
|
||||
_toast?.Dispose();
|
||||
_toast = null;
|
||||
};
|
||||
}
|
||||
|
||||
public void CopyToClipboard(string text)
|
||||
|
@ -277,6 +288,11 @@ namespace Bit.iOS.Services
|
|||
|
||||
public void ShowLoading(string text)
|
||||
{
|
||||
if(_progressAlert != null)
|
||||
{
|
||||
HideLoading();
|
||||
}
|
||||
|
||||
var loadingIndicator = new UIActivityIndicatorView(new CGRect(10, 5, 50, 50));
|
||||
loadingIndicator.HidesWhenStopped = true;
|
||||
loadingIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray;
|
||||
|
@ -300,7 +316,6 @@ namespace Bit.iOS.Services
|
|||
_progressAlert.DismissViewController(true, () => { });
|
||||
_progressAlert.Dispose();
|
||||
_progressAlert = null;
|
||||
|
||||
}
|
||||
|
||||
public Task LaunchAppAsync(string appName, Page page)
|
||||
|
|
Loading…
Reference in a new issue