Changing folder names
This commit is contained in:
@ -0,0 +1,41 @@
|
||||
#Header {
|
||||
background-color: transparent;
|
||||
margin-top: 10;
|
||||
}
|
||||
|
||||
#Header > Entry {
|
||||
margin-left: 155;
|
||||
margin-top: 2;
|
||||
margin-bottom: 2;
|
||||
}
|
||||
|
||||
#TitleContainer {
|
||||
margin-top: 10;
|
||||
margin-left: 10;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#TitleContainer Label {
|
||||
color: white;
|
||||
margin-left: 155;
|
||||
font-size: 22;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
#Player {
|
||||
background-color: #303030;
|
||||
height: 60;
|
||||
}
|
||||
|
||||
#Content {
|
||||
margin-right: 10;
|
||||
}
|
||||
|
||||
#Modal {
|
||||
height: 500;
|
||||
width: 400;
|
||||
margin-top: 20;
|
||||
margin-bottom: 20;
|
||||
border-radius: 15;
|
||||
background-color: #626363;
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
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"
|
||||
StyleClass="primaryColor">
|
||||
<ContentPage.Resources>
|
||||
<StyleSheet
|
||||
Source="MainView.css"/>
|
||||
</ContentPage.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="35"/>
|
||||
<RowDefinition Height="35"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="60"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="150"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!--Header-->
|
||||
<StackLayout
|
||||
x:Name="Header"
|
||||
Grid.Row="0"
|
||||
Grid.ColumnSpan="2"
|
||||
Orientation="Horizontal">
|
||||
<Entry Text="Search"/>
|
||||
</StackLayout>
|
||||
|
||||
<!--Title-->
|
||||
<StackLayout
|
||||
Grid.Row="1"
|
||||
Grid.ColumnSpan="2"
|
||||
x:Name="TitleContainer">
|
||||
<Label Text="{Binding Title}" TextColor="White"/>
|
||||
</StackLayout>
|
||||
|
||||
<!--Sidebar-->
|
||||
<navigation:NavigationMenu
|
||||
Grid.Column="0"
|
||||
Grid.RowSpan="3"
|
||||
x:Name="MasterPage"
|
||||
Items="{Binding Pages}"
|
||||
SelectedItem="{Binding SelectedItem}"/>
|
||||
|
||||
<!--Page Container-->
|
||||
<views:PageContainer
|
||||
Grid.Column="1"
|
||||
Grid.Row="2"
|
||||
x:Name="Content"/>
|
||||
|
||||
<!--Modal Dialog-->
|
||||
<dialog:Modal x:Name="Modal"
|
||||
Grid.Column="1"
|
||||
Grid.Row="2"
|
||||
StyleClass="secondAccentColor"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="End"/>
|
||||
|
||||
<!--Music Player-->
|
||||
<mp:Player
|
||||
StyleClass="secondAccentColor"
|
||||
x:Name="Player"
|
||||
Grid.Row="3"
|
||||
Grid.ColumnSpan="2"/>
|
||||
</Grid>
|
||||
|
||||
</ContentPage>
|
@ -0,0 +1,263 @@
|
||||
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;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Aurora.Models.Media;
|
||||
using Aurora.Design.Components.MediaPlayer;
|
||||
using Aurora.Services.Player;
|
||||
using Autofac;
|
||||
|
||||
namespace Aurora.Design.Views.Main
|
||||
{
|
||||
public enum PlayAction
|
||||
{
|
||||
Play,
|
||||
Pause,
|
||||
Resume,
|
||||
Stop
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for updating player metadata
|
||||
/// </summary>
|
||||
/// <param name="media"></param>
|
||||
public delegate Task SetPlayerDelegate(BaseMedia media, PlayAction action);
|
||||
public delegate bool GetIsPlayingDelegate();
|
||||
public delegate void ShowModalDelegate(Type view, BaseDialogViewModel viewModel);
|
||||
public delegate void HideModalDelegate();
|
||||
public delegate void FinishDialogDelegate();
|
||||
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class MainView : ContentPage//, IDisposable
|
||||
{
|
||||
private Dictionary<int, BaseViewModel> _viewModels;
|
||||
private BaseViewModel _lastViewModel;
|
||||
private Player _playerComponent;
|
||||
private IPlayer _playerService;
|
||||
private ContentPresenter _viewContent;
|
||||
|
||||
public MainView(IPlayer player)
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = new MainViewModel();
|
||||
_viewModels = new Dictionary<int, BaseViewModel>();
|
||||
|
||||
_playerComponent = Player;
|
||||
|
||||
_viewContent = (ContentPresenter)Content.FindByName("ViewContent");
|
||||
_playerService = player;
|
||||
|
||||
MasterPage.ListView.ItemSelected += OnNavItemSelected;
|
||||
|
||||
Appearing += OnAppearing;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Appearing -= OnAppearing;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event handler for side bar items being selected
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnNavItemSelected(object sender, SelectedItemChangedEventArgs e)
|
||||
{
|
||||
var item = e.SelectedItem as NavigationItem;
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
var view = (View)Activator.CreateInstance(item.TargetType);
|
||||
|
||||
//Check if we have an instantiated viewModel
|
||||
BaseViewModel vm = new BaseViewModel();
|
||||
if (_viewModels.ContainsKey(item.Id))
|
||||
{
|
||||
_viewModels.TryGetValue(item.Id, out vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.TargetViewModelType.BaseType != typeof(BaseViewModel))
|
||||
{
|
||||
throw new InvalidOperationException("TargetViewModel field must be of type BaseViewModel");
|
||||
}
|
||||
|
||||
//Instantiate new view model
|
||||
vm = (BaseViewModel)App.Container.Resolve(item.TargetViewModelType); //Activator.CreateInstance(item.TargetViewModelType);
|
||||
_viewModels.Add(item.Id, vm);
|
||||
|
||||
}
|
||||
|
||||
//Assign player controls to viewmodel
|
||||
AssignPlayerControls(vm);
|
||||
ChangeModalVisiblity(false);
|
||||
|
||||
//Activate viewmodel
|
||||
vm.OnActive();
|
||||
|
||||
//Deactivate last viewModel
|
||||
_lastViewModel.OnInactive();
|
||||
//Unasign deactivating vm
|
||||
UnassignPlayerControls(_lastViewModel);
|
||||
|
||||
//Assign viewModel
|
||||
_lastViewModel = vm;
|
||||
view.BindingContext = vm;
|
||||
|
||||
_viewContent.Content = view;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event handler for page appearing.
|
||||
/// </summary>
|
||||
/// <param name="sender">The object that fired the event.</param>
|
||||
/// <param name="args">The event arguments</param>
|
||||
private void OnAppearing(object sender, EventArgs args)
|
||||
{
|
||||
//Set initial view from first item in list
|
||||
ObservableCollection<NavigationGroupItem> screenList = (ObservableCollection<NavigationGroupItem>)MasterPage.ListView.ItemsSource;
|
||||
|
||||
//Assign viewModel
|
||||
NavigationItem firstNavItem = screenList.FirstOrDefault().FirstOrDefault();
|
||||
var view = (View)Activator.CreateInstance(firstNavItem.TargetType);
|
||||
|
||||
BaseViewModel vm = new BaseViewModel();
|
||||
if (_viewModels.ContainsKey(firstNavItem.Id))
|
||||
{
|
||||
_viewModels.TryGetValue(firstNavItem.Id, out vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Instantiate new view model
|
||||
vm = (BaseViewModel)App.Container.Resolve(firstNavItem.TargetViewModelType); //(BaseViewModel)Activator.CreateInstance(firstNavItem.TargetViewModelType);
|
||||
_viewModels.Add(firstNavItem.Id, vm);
|
||||
}
|
||||
|
||||
view.BindingContext = vm;
|
||||
_lastViewModel = vm;
|
||||
AssignPlayerControls(vm);
|
||||
ChangeModalVisiblity(false);
|
||||
vm.OnActive();
|
||||
|
||||
_viewContent.Content = view;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unassign setplayer delegate to prevent vms from changing player info when inactive
|
||||
/// </summary>
|
||||
/// <param name="vm"></param>
|
||||
private void UnassignPlayerControls(BaseViewModel vm)
|
||||
{
|
||||
vm.ChangePlayerState = null;
|
||||
vm.IsPlaying = null;
|
||||
vm.ShowModal = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assign main views music player controls to a view model
|
||||
/// </summary>
|
||||
/// <param name="vm">BaseViewModel to assign controls to</param>
|
||||
private void AssignPlayerControls(BaseViewModel vm)
|
||||
{
|
||||
_playerComponent.PlayButtonCommand = new Command(vm.OnPlayButtonCommandExecute, vm.CanPlayButtonCommandExecute);
|
||||
_playerComponent.NextButtonCommand = new Command(vm.OnNextButtonExecute, vm.CanNextButtonCommandExecute);
|
||||
_playerComponent.PreviousButtonCommand = new Command(vm.OnPreviousButtonExecute, vm.CanPreviousButtonCommandExecute);
|
||||
|
||||
vm.ChangePlayerState = ChangePlayerState;
|
||||
vm.IsPlaying = () =>
|
||||
{
|
||||
return _playerService.PlaybackState == PlaybackState.Playing;
|
||||
};
|
||||
vm.ShowModal = this.ShowModal;
|
||||
vm.HideModal = this.HideModal;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delegate handler for a view model controling music playback
|
||||
/// </summary>
|
||||
/// <param name="media"></param>
|
||||
/// <param name="action"></param>
|
||||
/// <returns></returns>
|
||||
private async Task ChangePlayerState(BaseMedia media, PlayAction action)
|
||||
{
|
||||
if (media != null && media.Metadata is AudioMetadata)
|
||||
{
|
||||
AudioMetadata meta = (AudioMetadata)media.Metadata;
|
||||
_playerComponent.ArtistName = meta.Artist;
|
||||
_playerComponent.SongTitle = meta.Title;
|
||||
}
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case PlayAction.Pause:
|
||||
{
|
||||
_playerService.Pause();
|
||||
_playerComponent.IsPlaying = false;
|
||||
break;
|
||||
}
|
||||
case PlayAction.Play:
|
||||
{
|
||||
if (media == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!_playerService.IsMediaLoaded(media))
|
||||
{
|
||||
await _playerService.LoadMedia(media).ConfigureAwait(true);
|
||||
}
|
||||
|
||||
_playerService.Play();
|
||||
_playerComponent.IsPlaying = true;
|
||||
break;
|
||||
}
|
||||
case PlayAction.Resume:
|
||||
{
|
||||
_playerService.Play();
|
||||
_playerComponent.IsPlaying = true;
|
||||
break;
|
||||
}
|
||||
case PlayAction.Stop:
|
||||
{
|
||||
_playerService.Stop();
|
||||
_playerComponent.IsPlaying = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ShowModal(Type view, BaseDialogViewModel viewModel)
|
||||
{
|
||||
ContentPresenter modalContainer = (ContentPresenter)Modal.FindByName("ViewContent");
|
||||
var vw = (View)Activator.CreateInstance(view);
|
||||
|
||||
vw.BindingContext = viewModel;
|
||||
|
||||
//Set modal container content
|
||||
modalContainer.Content = vw;
|
||||
|
||||
//Set visibility
|
||||
ChangeModalVisiblity(true);
|
||||
}
|
||||
|
||||
private void HideModal()
|
||||
{
|
||||
ChangeModalVisiblity(false);
|
||||
}
|
||||
|
||||
private void ChangeModalVisiblity(bool isVisible)
|
||||
{
|
||||
Modal.IsVisible = isVisible;
|
||||
Content.IsVisible = !isVisible;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Aurora.Design.Components.NavigationMenu;
|
||||
using Aurora.Design.Views.Albums;
|
||||
using Aurora.Design.Views.Artists;
|
||||
using Aurora.Design.Views.Songs;
|
||||
using Aurora.Design.Views.Stations;
|
||||
using Aurora.Design.Views.Party;
|
||||
using Aurora.Design.Views.Profile;
|
||||
|
||||
namespace Aurora.Design.Views.MainView
|
||||
{
|
||||
public class MainViewModel : BaseViewModel
|
||||
{
|
||||
private ObservableCollection<NavigationItem> _pages;
|
||||
public ObservableCollection<NavigationItem> Pages
|
||||
{
|
||||
get { return _pages; }
|
||||
set
|
||||
{
|
||||
if (value != _pages)
|
||||
{
|
||||
_pages = value;
|
||||
OnPropertyChanged("Pages");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private NavigationItem _selectedItem;
|
||||
public NavigationItem SelectedItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedItem;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedItem, value);
|
||||
OnPropertyChanged("Title");
|
||||
}
|
||||
}
|
||||
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return (_selectedItem != null && !string.IsNullOrWhiteSpace(_selectedItem.Title)) ?
|
||||
_selectedItem.Title : "";
|
||||
}
|
||||
}
|
||||
|
||||
public MainViewModel()
|
||||
{
|
||||
_pages = new ObservableCollection<NavigationItem>(new[]
|
||||
{
|
||||
new NavigationItem { Id = 0, Title = "Songs", Group="Your Music", TargetType = typeof(SongsView), TargetViewModelType = typeof(SongsViewModel) },
|
||||
new NavigationItem { Id = 1, Title = "Artists", Group="Your Music", TargetType = typeof(ArtistsView), TargetViewModelType = typeof(ArtistsViewModel)},
|
||||
new NavigationItem { Id = 2, Title = "Albums", Group="Your Music", TargetType = typeof(AlbumsView), TargetViewModelType = typeof(AlbumsViewModel)},
|
||||
new NavigationItem { Id = 3, Title = "Stations", Group="Your Music", TargetType = typeof(StationsView), TargetViewModelType = typeof(StationsViewModel)},
|
||||
new NavigationItem { Id = 4, Title = "Party", Group="Social", TargetType = typeof(PartyView), TargetViewModelType = typeof(PartyViewModel)},
|
||||
new NavigationItem { Id = 5, Title = "Profile", Group="Social", TargetType = typeof(ProfileView), TargetViewModelType = typeof(ProfileViewModel)},
|
||||
new NavigationItem { Id = 6, Title = "A + B", Group="Playlists", TargetType = typeof(StationsView), TargetViewModelType = typeof(StationsViewModel)}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Aurora.Design.Views.MainView.PageContainer">
|
||||
<ContentView.Content>
|
||||
<Grid
|
||||
x:Name="Grid">
|
||||
<ContentPresenter
|
||||
x:Name="ViewContent"/>
|
||||
|
||||
</Grid>
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Design.Views.MainView
|
||||
{
|
||||
public partial class PageContainer : ContentView
|
||||
{
|
||||
public PageContainer()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user