Second pass at modal

This commit is contained in:
watsonb8 2019-12-18 22:32:08 -05:00
parent 8affc8d2af
commit 1e7e71f29d
3 changed files with 29 additions and 31 deletions

View File

@ -56,7 +56,9 @@ namespace Aurora.Design.Views
/// <value></value> /// <value></value>
public GetIsPlayingDelegate IsPlaying { get; set; } public GetIsPlayingDelegate IsPlaying { get; set; }
public ShowModalDelegate<object> ShowModal { get; set; } public ShowModalDelegate ShowModal { get; set; }
public HideModalDelegate HideModal { get; set; }
#endregion Player #endregion Player

View File

@ -28,7 +28,9 @@ namespace Aurora.Design.Views.Main
/// <param name="media"></param> /// <param name="media"></param>
public delegate Task SetPlayerDelegate(BaseMedia media, PlayAction action); public delegate Task SetPlayerDelegate(BaseMedia media, PlayAction action);
public delegate bool GetIsPlayingDelegate(); public delegate bool GetIsPlayingDelegate();
public delegate Task<object> ShowModalDelegate<T>(Type view, Type viewModel); public delegate void ShowModalDelegate(Type view, BaseDialogViewModel viewModel);
public delegate void HideModalDelegate();
public delegate void FinishDialogDelegate(); public delegate void FinishDialogDelegate();
[XamlCompilation(XamlCompilationOptions.Compile)] [XamlCompilation(XamlCompilationOptions.Compile)]
@ -175,7 +177,8 @@ namespace Aurora.Design.Views.Main
{ {
return _playerService.PlaybackState == PlaybackState.Playing; return _playerService.PlaybackState == PlaybackState.Playing;
}; };
vm.ShowModal = this.ShowModal<object>; vm.ShowModal = this.ShowModal;
vm.HideModal = this.HideModal;
} }
@ -234,40 +237,29 @@ namespace Aurora.Design.Views.Main
} }
private Task<object> ShowModal<T>(Type view, Type viewModel) private void ShowModal(Type view, BaseDialogViewModel viewModel)
{ {
return Task<object>.Run(() =>
{
object returnObj = null;
ContentPresenter modalContainer = (ContentPresenter)Modal.FindByName("ViewContent"); ContentPresenter modalContainer = (ContentPresenter)Modal.FindByName("ViewContent");
var vw = (View)Activator.CreateInstance(view); var vw = (View)Activator.CreateInstance(view);
BaseDialogViewModel vm = (BaseDialogViewModel)Activator.CreateInstance(viewModel);
vw.BindingContext = vm; vw.BindingContext = viewModel;
//Set modal container content //Set modal container content
modalContainer.Content = vw; modalContainer.Content = vw;
//Set visibility //Set visibility
ChangeModalVisiblity(true); ChangeModalVisiblity(true);
}
AutoResetEvent autoResetEvent = new AutoResetEvent(false); private void HideModal()
//Finish is executed by modal
vm.Finish = () =>
{ {
ChangeModalVisiblity(false); ChangeModalVisiblity(false);
returnObj = vm.ReturnObject;
autoResetEvent.Set();
};
autoResetEvent.WaitOne();
return returnObj;
});
} }
private void ChangeModalVisiblity(bool isVisible) private void ChangeModalVisiblity(bool isVisible)
{ {
Modal.IsVisible = isVisible; Modal.IsVisible = isVisible;
Content.IsVisible = !isVisible;
} }
} }
} }

View File

@ -127,10 +127,12 @@ namespace Aurora.Design.Views.Party
else else
{ {
//Open host selection modal //Open host selection modal
var modalResult = await this.ShowModal(typeof(NewPartyDialog.NewPartyDialog), typeof(NewPartyDialogViewModel)); NewPartyDialogViewModel vm = new NewPartyDialogViewModel();
if (modalResult is ConnectionDetails) ConnectionDetails details = new ConnectionDetails();
vm.Finish = () =>
{ {
ConnectionDetails details = modalResult as ConnectionDetails; this.HideModal();
details = vm.ReturnObject as ConnectionDetails;
_hostname = details.HostName; _hostname = details.HostName;
switch (details.ConnectionType) switch (details.ConnectionType)
{ {
@ -145,7 +147,9 @@ namespace Aurora.Design.Views.Party
break; break;
} }
} }
} };
this.ShowModal(typeof(NewPartyDialog.NewPartyDialog), vm);
} }
} }