Skip to content

Commit

Permalink
Modernize code
Browse files Browse the repository at this point in the history
- Don't use unsupported api's on newer versions
- Use keyboard notifications to find keyboard size
- Add API set for specifying Window since we can now be multiwindow apps - by default we do our best guess to get the first window
  • Loading branch information
Redth committed Jan 23, 2023
1 parent bb017e3 commit 9a3b340
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 118 deletions.
91 changes: 76 additions & 15 deletions BTProgressHUD/BTProgressHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ public static class BTProgressHUD
{
public static void Show(string? status = null, float progress = -1, MaskType maskType = MaskType.None)
{
ProgressHUD.Shared.Show(status, progress, maskType);
ProgressHUD.ForDefaultWindow().Show(status, progress, maskType);
}

public static void Show(string cancelCaption, Action cancelCallback, string? status = null, float progress = -1, MaskType maskType = MaskType.None)
{
ProgressHUD.Shared.Show(cancelCaption, cancelCallback, status, progress, maskType);
ProgressHUD.ForDefaultWindow().Show(cancelCaption, cancelCallback, status, progress, maskType);
}

public static void ShowContinuousProgress(string? status = null, MaskType maskType = MaskType.None)
{
ProgressHUD.Shared.ShowContinuousProgress(status, maskType);
ProgressHUD.ForDefaultWindow().ShowContinuousProgress(status, maskType);
}

public static void ShowToast(string status, bool showToastCentered = false, double timeoutMs = 1000)
Expand All @@ -28,51 +28,112 @@ public static void ShowToast(string status, bool showToastCentered = false, doub

public static void ShowToast(string status, ToastPosition toastPosition = ToastPosition.Center, double timeoutMs = 1000)
{
ProgressHUD.Shared.ShowToast(status, MaskType.None, toastPosition, timeoutMs);
ProgressHUD.ForDefaultWindow().ShowToast(status, MaskType.None, toastPosition, timeoutMs);
}

public static void ShowToast(string status, MaskType maskType = MaskType.None, bool showToastCentered = true, double timeoutMs = 1000)
{
ProgressHUD.Shared.ShowToast(status, maskType, showToastCentered ? ToastPosition.Center : ToastPosition.Bottom, timeoutMs);
ProgressHUD.ForDefaultWindow().ShowToast(status, maskType, showToastCentered ? ToastPosition.Center : ToastPosition.Bottom, timeoutMs);
}

public static void SetStatus(string status)
{
ProgressHUD.Shared.SetStatus(status);
ProgressHUD.ForDefaultWindow().SetStatus(status);
}

public static void ShowSuccessWithStatus(string status, MaskType maskType = MaskType.None, double timeoutMs = 1000, ImageStyle imageStyle = ImageStyle.Default)
{
ProgressHUD.Shared.ShowSuccessWithStatus(status, maskType, timeoutMs, imageStyle);
ProgressHUD.ForDefaultWindow().ShowSuccessWithStatus(status, maskType, timeoutMs, imageStyle);
}

public static void ShowErrorWithStatus(string status, MaskType maskType = MaskType.None, double timeoutMs = 1000, ImageStyle imageStyle = ImageStyle.Default)
{
ProgressHUD.Shared.ShowErrorWithStatus(status, maskType, timeoutMs, imageStyle);
ProgressHUD.ForDefaultWindow().ShowErrorWithStatus(status, maskType, timeoutMs, imageStyle);
}

public static void ShowInfoWithStatus(string status, MaskType maskType = MaskType.None, double timeoutMs = 1000, ImageStyle imageStyle = ImageStyle.Default)
{
ProgressHUD.Shared.ShowInfoWithStatus(status, maskType, timeoutMs, imageStyle);
ProgressHUD.ForDefaultWindow().ShowInfoWithStatus(status, maskType, timeoutMs, imageStyle);
}

public static void ShowImage(UIImage image, string? status, MaskType maskType = MaskType.None, double timeoutMs = 1000)
{
ProgressHUD.Shared.ShowImage(image, status, maskType, timeoutMs);
ProgressHUD.ForDefaultWindow().ShowImage(image, status, maskType, timeoutMs);
}

public static void Dismiss()
{
ProgressHUD.Shared.Dismiss();
ProgressHUD.ForDefaultWindow().Dismiss();
}

public static bool IsVisible
=> ProgressHUD.ForDefaultWindow().IsVisible;




public static void Show(UIWindow forWindow, string? status = null, float progress = -1, MaskType maskType = MaskType.None)
{
ProgressHUD.For(forWindow).Show(status, progress, maskType);
}

public static void Show(UIWindow forWindow, string cancelCaption, Action cancelCallback, string? status = null, float progress = -1, MaskType maskType = MaskType.None)
{
ProgressHUD.For(forWindow).Show(cancelCaption, cancelCallback, status, progress, maskType);
}

public static void ShowContinuousProgress(UIWindow forWindow, string? status = null, MaskType maskType = MaskType.None)
{
ProgressHUD.For(forWindow).ShowContinuousProgress(status, maskType);
}

public static void ShowToast(UIWindow forWindow, string status, bool showToastCentered = false, double timeoutMs = 1000)
{
ShowToast(forWindow, status, showToastCentered ? ToastPosition.Center : ToastPosition.Bottom, timeoutMs);
}

public static void ShowToast(UIWindow forWindow, string status, ToastPosition toastPosition = ToastPosition.Center, double timeoutMs = 1000)
{
ProgressHUD.For(forWindow).ShowToast(status, MaskType.None, toastPosition, timeoutMs);
}

public static void ShowToast(UIWindow forWindow, string status, MaskType maskType = MaskType.None, bool showToastCentered = true, double timeoutMs = 1000)
{
get
{
return ProgressHUD.Shared.IsVisible;
}
ProgressHUD.For(forWindow).ShowToast(status, maskType, showToastCentered ? ToastPosition.Center : ToastPosition.Bottom, timeoutMs);
}

public static void SetStatus(UIWindow forWindow, string status)
{
ProgressHUD.For(forWindow).SetStatus(status);
}

public static void ShowSuccessWithStatus(UIWindow forWindow, string status, MaskType maskType = MaskType.None, double timeoutMs = 1000, ImageStyle imageStyle = ImageStyle.Default)
{
ProgressHUD.For(forWindow).ShowSuccessWithStatus(status, maskType, timeoutMs, imageStyle);
}

public static void ShowErrorWithStatus(UIWindow forWindow, string status, MaskType maskType = MaskType.None, double timeoutMs = 1000, ImageStyle imageStyle = ImageStyle.Default)
{
ProgressHUD.For(forWindow).ShowErrorWithStatus(status, maskType, timeoutMs, imageStyle);
}

public static void ShowInfoWithStatus(UIWindow forWindow, string status, MaskType maskType = MaskType.None, double timeoutMs = 1000, ImageStyle imageStyle = ImageStyle.Default)
{
ProgressHUD.For(forWindow).ShowInfoWithStatus(status, maskType, timeoutMs, imageStyle);
}

public static void ShowImage(UIWindow forWindow, UIImage image, string? status, MaskType maskType = MaskType.None, double timeoutMs = 1000)
{
ProgressHUD.For(forWindow).ShowImage(image, status, maskType, timeoutMs);
}

public static void Dismiss(UIWindow forWindow)
{
ProgressHUD.For(forWindow).Dismiss();
}

public static bool GetIsVisible(UIWindow forWindow)
=> ProgressHUD.For(forWindow).IsVisible;
}
}

Loading

0 comments on commit 9a3b340

Please sign in to comment.