First pass at modal dialog
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
#Header {
|
||||
background-color: transparent;
|
||||
margin-top: 10;
|
||||
}
|
||||
|
||||
#Header > Entry {
|
||||
@ -27,3 +28,11 @@
|
||||
#Player {
|
||||
background-color: #626363;
|
||||
}
|
||||
|
||||
#Modal {
|
||||
height: 500;
|
||||
width: 400;
|
||||
margin-top: 20;
|
||||
margin-bottom: 20;
|
||||
border-radius: 15;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
xmlns:views="clr-namespace:Aurora.Design.Views.MainView"
|
||||
xmlns:navigation="clr-namespace:Aurora.Design.Components.NavigationMenu"
|
||||
xmlns:mp="clr-namespace:Aurora.Design.Components.MediaPlayer"
|
||||
xmlns:dialog="clr-namespace:Aurora.Design.Components.Dialogs"
|
||||
x:Class="Aurora.Design.Views.Main.MainView">
|
||||
<ContentPage.Resources>
|
||||
<StyleSheet
|
||||
@ -12,8 +13,8 @@
|
||||
</ContentPage.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="28"/>
|
||||
<RowDefinition Height="28"/>
|
||||
<RowDefinition Height="35"/>
|
||||
<RowDefinition Height="35"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="60"/>
|
||||
</Grid.RowDefinitions>
|
||||
@ -52,12 +53,20 @@
|
||||
Grid.Row="2"
|
||||
x:Name="ContentPage"/>
|
||||
|
||||
<!--Modal Dialog-->
|
||||
<dialog:Modal x:Name="Modal"
|
||||
BackgroundColor="Blue"
|
||||
Grid.Column="1"
|
||||
Grid.Row="2"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="End"/>
|
||||
|
||||
<!--Music Player-->
|
||||
<mp:Player
|
||||
x:Name="Player"
|
||||
Grid.Row="3"
|
||||
Grid.ColumnSpan="2"
|
||||
HeightRequest="50"/>
|
||||
HeightRequest="60"/>
|
||||
</Grid>
|
||||
|
||||
</ContentPage>
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using Aurora.Design.Components.NavigationMenu;
|
||||
using Aurora.Design.Views.MainView;
|
||||
@ -9,6 +10,7 @@ using Xamarin.Forms.Xaml;
|
||||
using Aurora.Models.Media;
|
||||
using Aurora.Design.Components.MediaPlayer;
|
||||
using Aurora.Services.PlayerService;
|
||||
using System.Threading;
|
||||
|
||||
namespace Aurora.Design.Views.Main
|
||||
{
|
||||
@ -24,8 +26,10 @@ namespace Aurora.Design.Views.Main
|
||||
/// Delegate for updating player metadata
|
||||
/// </summary>
|
||||
/// <param name="media"></param>
|
||||
public delegate void SetPlayerDelegate(BaseMedia media, PlayAction action);
|
||||
public delegate Task SetPlayerDelegate(BaseMedia media, PlayAction action);
|
||||
public delegate bool GetIsPlayingDelegate();
|
||||
public delegate Task<object> ShowModalDelegate<T>(Type view, Type viewModel);
|
||||
public delegate void FinishDialogDelegate();
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class MainView : ContentPage//, IDisposable
|
||||
@ -43,6 +47,7 @@ namespace Aurora.Design.Views.Main
|
||||
_viewModels = new Dictionary<int, BaseViewModel>();
|
||||
|
||||
_playerComponent = Player;
|
||||
|
||||
_viewContent = (ContentPresenter)ContentPage.Content.FindByName("ViewContent");
|
||||
_playerService = PlayerService.Instance;
|
||||
|
||||
@ -88,6 +93,10 @@ namespace Aurora.Design.Views.Main
|
||||
|
||||
}
|
||||
|
||||
//Assign player controls to viewmodel
|
||||
AssignPlayerControls(vm);
|
||||
ChangeModalVisiblity(false);
|
||||
|
||||
//Activate viewmodel
|
||||
vm.OnActive();
|
||||
|
||||
@ -99,8 +108,6 @@ namespace Aurora.Design.Views.Main
|
||||
//Assign viewModel
|
||||
_lastViewModel = vm;
|
||||
view.BindingContext = vm;
|
||||
//Assign player controls to viewmodel
|
||||
AssignPlayerControls(vm);
|
||||
|
||||
_viewContent.Content = view;
|
||||
}
|
||||
@ -134,6 +141,7 @@ namespace Aurora.Design.Views.Main
|
||||
view.BindingContext = vm;
|
||||
_lastViewModel = vm;
|
||||
AssignPlayerControls(vm);
|
||||
ChangeModalVisiblity(false);
|
||||
vm.OnActive();
|
||||
|
||||
_viewContent.Content = view;
|
||||
@ -149,6 +157,7 @@ namespace Aurora.Design.Views.Main
|
||||
{
|
||||
vm.ChangePlayerState = null;
|
||||
vm.IsPlaying = null;
|
||||
vm.ShowModal = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -161,13 +170,13 @@ namespace Aurora.Design.Views.Main
|
||||
_playerComponent.NextButtonCommand = new Command(vm.OnNextButtonExecute, vm.CanNextButtonExecute);
|
||||
_playerComponent.PreviousButtonCommand = new Command(vm.OnPreviousButtonExecute, vm.CanPreviousButtonExecute);
|
||||
|
||||
//Assign SetPlayer delegate
|
||||
|
||||
vm.ChangePlayerState = ChangePlayerState;
|
||||
vm.IsPlaying = () =>
|
||||
{
|
||||
return _playerService.PlaybackState == PlaybackState.Playing;
|
||||
};
|
||||
vm.ShowModal = this.ShowModal<object>;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -176,7 +185,7 @@ namespace Aurora.Design.Views.Main
|
||||
/// <param name="media"></param>
|
||||
/// <param name="action"></param>
|
||||
/// <returns></returns>
|
||||
private async void ChangePlayerState(BaseMedia media, PlayAction action)
|
||||
private async Task ChangePlayerState(BaseMedia media, PlayAction action)
|
||||
{
|
||||
if (media != null && media.Metadata is AudioMetadata)
|
||||
{
|
||||
@ -224,5 +233,42 @@ namespace Aurora.Design.Views.Main
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Task<object> ShowModal<T>(Type view, Type viewModel)
|
||||
{
|
||||
return Task<object>.Run(() =>
|
||||
{
|
||||
object returnObj = null;
|
||||
|
||||
ContentPresenter modalContainer = (ContentPresenter)Modal.FindByName("ViewContent");
|
||||
var vw = (View)Activator.CreateInstance(view);
|
||||
BaseDialogViewModel vm = (BaseDialogViewModel)Activator.CreateInstance(viewModel);
|
||||
|
||||
vw.BindingContext = vm;
|
||||
|
||||
//Set modal container content
|
||||
modalContainer.Content = vw;
|
||||
|
||||
//Set visibility
|
||||
ChangeModalVisiblity(true);
|
||||
|
||||
AutoResetEvent autoResetEvent = new AutoResetEvent(false);
|
||||
//Finish is executed by modal
|
||||
vm.Finish = () =>
|
||||
{
|
||||
ChangeModalVisiblity(false);
|
||||
returnObj = vm.ReturnObject;
|
||||
autoResetEvent.Set();
|
||||
};
|
||||
autoResetEvent.WaitOne();
|
||||
return returnObj;
|
||||
});
|
||||
}
|
||||
|
||||
private void ChangeModalVisiblity(bool isVisible)
|
||||
{
|
||||
ContentPage.IsVisible = !isVisible;
|
||||
Modal.IsVisible = isVisible;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user