Player controls now get dynamically assigned to view model base classes.
This gives view models more freedom in how play events from the player are handled
This commit is contained in:
@ -6,6 +6,8 @@ using Aurora.Design.Components.NavigationMenu;
|
||||
using Aurora.Design.Views.MainView;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Aurora.Models.Media;
|
||||
using Aurora.Design.Components.MediaPlayer;
|
||||
|
||||
namespace Aurora.Design.Views.Main
|
||||
{
|
||||
@ -20,7 +22,7 @@ namespace Aurora.Design.Views.Main
|
||||
InitializeComponent();
|
||||
BindingContext = new MainViewModel();
|
||||
_viewModels = new Dictionary<int, BaseViewModel>();
|
||||
MasterPage.ListView.ItemSelected += ListView_ItemSelected;
|
||||
MasterPage.ListView.ItemSelected += OnNavItemSelected;
|
||||
|
||||
Appearing += OnAppearing;
|
||||
}
|
||||
@ -29,7 +31,12 @@ namespace Aurora.Design.Views.Main
|
||||
Appearing -= OnAppearing;
|
||||
}
|
||||
|
||||
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
|
||||
public Command PlayCommand { get; set; }
|
||||
public Command PreviousCommand { get; set; }
|
||||
public Command NextCommand { get; set; }
|
||||
public BaseMedia Media { get; set; }
|
||||
|
||||
private void OnNavItemSelected(object sender, SelectedItemChangedEventArgs e)
|
||||
{
|
||||
var item = e.SelectedItem as NavigationItem;
|
||||
if (item == null)
|
||||
@ -54,6 +61,14 @@ namespace Aurora.Design.Views.Main
|
||||
vm = (BaseViewModel)Activator.CreateInstance(item.TargetViewModelType);
|
||||
_viewModels.Add(item.Id, vm);
|
||||
}
|
||||
|
||||
//Assign player controls to viewmodel
|
||||
Player player = (Player)ContentPage.FindByName("Player");
|
||||
player.PlayButtonCommand = new Command(vm.PlayExecute, vm.PlayCanExecute);
|
||||
player.NextButtonCommand = new Command(vm.NextExecute, vm.NextCanExecute);
|
||||
player.PreviousButtonCommand = new Command(vm.PreviousExecute, vm.PreviousCanExecute);
|
||||
vm.Media = this.Media;
|
||||
|
||||
//Activate viewmodel
|
||||
vm.OnActive();
|
||||
|
||||
@ -98,6 +113,11 @@ namespace Aurora.Design.Views.Main
|
||||
|
||||
view.BindingContext = vm;
|
||||
_lastViewModel = vm;
|
||||
Player player = (Player)ContentPage.FindByName("Player");
|
||||
player.PlayButtonCommand = new Command(vm.PlayExecute, vm.PlayCanExecute);
|
||||
player.NextButtonCommand = new Command(vm.NextExecute, vm.NextCanExecute);
|
||||
player.PreviousButtonCommand = new Command(vm.PreviousExecute, vm.PreviousCanExecute);
|
||||
vm.Media = this.Media;
|
||||
vm.OnActive();
|
||||
|
||||
ContentPresenter viewContent = (ContentPresenter)ContentPage.Content.FindByName("ViewContent");
|
||||
@ -105,6 +125,7 @@ namespace Aurora.Design.Views.Main
|
||||
|
||||
MasterPage.ListView.SelectedItem = screenList.FirstOrDefault();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
Grid.Row="0"
|
||||
x:Name="ViewContent"/>
|
||||
<mp:Player
|
||||
x:Name="Player"
|
||||
Grid.Row="1"
|
||||
HorizontalOptions="CenterAndExpand"
|
||||
VerticalOptions="End"
|
||||
|
Reference in New Issue
Block a user