Skip to content

Commit

Permalink
1. Fix the that android toast objects are always created. 2. Add Hide…
Browse files Browse the repository at this point in the history
…Loading() API
  • Loading branch information
jxnkwlp committed May 22, 2020
1 parent 86a1079 commit c5cf0b6
Show file tree
Hide file tree
Showing 16 changed files with 5,716 additions and 5,620 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = crlf
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.{cs,vb}]
indent_style = tab
indent_size = 4
tab_width = 4
5 changes: 3 additions & 2 deletions Passingwind.UserDialogs.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2003
# Visual Studio Version 16
VisualStudioVersion = 16.0.30104.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Passingwind.UserDialogs", "Passingwind.UserDialogs\Passingwind.UserDialogs.csproj", "{DBA6284B-C0C8-436A-B012-0FE2ADCED0AA}"
EndProject
Expand All @@ -13,6 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample", "Sample\Sample\Sam
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9390F5A0-2729-4FBD-A475-75FD2C80D2BA}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
readme.md = readme.md
EndProjectSection
EndProject
Expand Down
227 changes: 115 additions & 112 deletions Passingwind.UserDialogs/Android/Builders/ProgressBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,119 +3,122 @@
using Java.Lang;
using KProgressHUDLib;
using System;
using System.Collections.Generic;
using System.Text;

namespace Passingwind.UserDialogs.Platforms
{
public class ProgressBuilder
{
private KProgressHUD _progress;

private void DelayDismiss(int interval)
{
if (_progress == null)
return;

Handler handler = new Handler();
handler.PostDelayed(new Runnable(() =>
{
_progress.Dismiss();
}), interval);
}

public IDisposable Loading(Activity activity, LoadingConfig config)
{
if (_progress != null && _progress.IsShowing)
{
_progress.Dismiss();
}

_progress = KProgressHUD.Create(activity, KProgressHUD.Style.SpinIndeterminate).SetLabel(config.Text);

_progress.SetCancellable(config.Cancellable);

if (config.Cancellable)
{
_progress.SetCancelAction(() =>
{
_progress.Dismiss();

config.CancelAction?.Invoke();
});
}

if (config.MarkType == MarkType.Black)
{
_progress.SetDimAmount(0.5f);
}

_progress.Show();

if (config.Duration != null)
{
DelayDismiss((int)config.Duration.Value.TotalMilliseconds);
}

return new DisposableAction(() => _progress.Dismiss());
}

public IProgressDialog Progress(Activity activity, ProgressConfig config)
{
if (_progress != null && _progress.IsShowing)
{
_progress.Dismiss();
}

_progress = KProgressHUD.Create(activity, KProgressHUD.Style.PieDeterminate).SetLabel(config.Text);

_progress.SetMaxProgress(100);

_progress.SetCancellable(config.Cancellable);

if (config.Cancellable)
{
_progress.SetCancelAction(() =>
{
_progress.Dismiss();

config.CancelAction?.Invoke();
});
}

if (config.MarkType == MarkType.Black)
{
_progress.SetDimAmount(0.5f);
}

_progress.Show();

return new LoadingDialog(_progress);
}

public class LoadingDialog : IProgressDialog, IDisposable
{
readonly KProgressHUD _progress;

public LoadingDialog(KProgressHUD progress)
{
_progress = progress;
}

public void Dispose()
{
Hide();
}

public void Hide()
{
_progress.Dismiss();
}

public void SetProgress(uint value)
{
_progress.SetProgress((int)value);
}
}
}
public class ProgressBuilder
{
private KProgressHUD _progress;

private void DelayDismiss(int interval)
{
if (_progress == null)
return;

Handler handler = new Handler();
handler.PostDelayed(new Runnable(() =>
{
_progress.Dismiss();
}), interval);
}

public IDisposable Loading(Activity activity, LoadingConfig config)
{
if (_progress != null && _progress.IsShowing)
{
_progress.Dismiss();
}

_progress = KProgressHUD.Create(activity, KProgressHUD.Style.SpinIndeterminate).SetLabel(config.Text);

_progress.SetCancellable(config.Cancellable);

if (config.Cancellable)
{
_progress.SetCancelAction(() =>
{
_progress.Dismiss();

config.CancelAction?.Invoke();
});
}

if (config.MarkType == MarkType.Black)
{
_progress.SetDimAmount(0.5f);
}

_progress.Show();

if (config.Duration != null)
{
DelayDismiss((int)config.Duration.Value.TotalMilliseconds);
}

return new DisposableAction(() => _progress.Dismiss());
}

public IProgressDialog Progress(Activity activity, ProgressConfig config)
{
if (_progress != null && _progress.IsShowing)
{
_progress.Dismiss();
}

_progress = KProgressHUD.Create(activity, KProgressHUD.Style.PieDeterminate).SetLabel(config.Text);

_progress.SetMaxProgress(100);

_progress.SetCancellable(config.Cancellable);

if (config.Cancellable)
{
_progress.SetCancelAction(() =>
{
_progress.Dismiss();

config.CancelAction?.Invoke();
});
}

if (config.MarkType == MarkType.Black)
{
_progress.SetDimAmount(0.5f);
}

_progress.Show();

return new LoadingDialog(_progress);
}

public void Hide()
{
_progress?.Dismiss();
}

public class LoadingDialog : IProgressDialog, IDisposable
{
private readonly KProgressHUD _progress;

public LoadingDialog(KProgressHUD progress)
{
_progress = progress;
}

public void Dispose()
{
Hide();
}

public void Hide()
{
_progress.Dismiss();
}

public void SetProgress(uint value)
{
_progress.SetProgress((int)value);
}
}
}
}
Loading

0 comments on commit c5cf0b6

Please sign in to comment.