Skip to content

Commit

Permalink
show Cancel button only if OnCancel action is set
Browse files Browse the repository at this point in the history
  • Loading branch information
shutdown256 committed Feb 20, 2024
1 parent 68ba030 commit 5380ae1
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/Acr.UserDialogs/Platforms/Android/ProgressDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected virtual void Refresh()
p,
this.config.MaskType.ToNative(),
null,
this.OnCancelClick,
this.config.OnCancel is not null ? this.OnCancelClick : null,
true,
null,
this.BeforeShow,
Expand All @@ -136,19 +136,22 @@ private void BeforeShow(Dialog dialog)
var layout = (RelativeLayout)textViewId.Parent;
layout.SetMinimumWidth((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 150, dialog.Context.Resources.DisplayMetrics));

var _params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
_params.AddRule(LayoutRules.Below, AndroidHUD.Resource.Id.textViewStatus);
_params.AddRule(LayoutRules.CenterHorizontal);
if (config.OnCancel is not null)
{
var _params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
_params.AddRule(LayoutRules.Below, AndroidHUD.Resource.Id.textViewStatus);
_params.AddRule(LayoutRules.CenterHorizontal);

Button button;
if (config.CancelButtonAndroidStyleId is int styleId)
button = new Button(new ContextThemeWrapper(dialog.Context, styleId));
else
button = new Button(dialog.Context);
Button button;
if (config.CancelButtonAndroidStyleId is int styleId)
button = new Button(new ContextThemeWrapper(dialog.Context, styleId));
else
button = new Button(dialog.Context);

button.Text = config.CancelText;
button.Click += (s, e) => OnCancelClick();
layout.AddView(button, _params);
button.Text = config.CancelText;
button.Click += (s, e) => OnCancelClick();
layout.AddView(button, _params);
}
}

private void AfterShow(Dialog dialog)
Expand Down

0 comments on commit 5380ae1

Please sign in to comment.