Changing folder names

This commit is contained in:
Brandon Watson
2021-04-10 10:20:50 -04:00
parent f1a3771912
commit dd4632cdb6
62 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<?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.Albums.AlbumsView">
<ContentPage.Content>
<Grid></Grid>
</ContentPage.Content>
</ContentView>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Aurora.Design.Views.Albums
{
public partial class AlbumsView : ContentView
{
public AlbumsView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,10 @@
using System;
namespace Aurora.Design.Views.Albums
{
public class AlbumsViewModel : BaseViewModel
{
public AlbumsViewModel()
{
}
}
}

View File

@ -0,0 +1,9 @@
<?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.Artists.ArtistsView">
<ContentView.Content>
</ContentView.Content>
</ContentView>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Aurora.Design.Views.Artists
{
public partial class ArtistsView : ContentView
{
public ArtistsView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
namespace Aurora.Design.Views.Artists
{
public class TestObj
{
public string Test1 { get; set; }
public string Test2 { get; set; }
}
public class ArtistsViewModel : BaseViewModel
{
public ArtistsViewModel()
{
}
}
}

View File

@ -0,0 +1,15 @@
using System;
using Aurora.Design.Views.Main;
namespace Aurora.Design.Views
{
public class BaseDialogViewModel : BaseViewModel
{
public BaseDialogViewModel()
{
}
public FinishDialogDelegate Finish { get; set; }
public object ReturnObject { get; protected set; }
}
}

View File

@ -0,0 +1,104 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Aurora.Models.Media;
using Xamarin.Forms;
using Aurora.Design.Views.Main;
namespace Aurora.Design.Views
{
public class BaseViewModel : INotifyPropertyChanged
{
public BaseViewModel()
{
}
#region Player
/// <summary>
/// Command event handler for player play button
/// </summary>
public virtual void OnPlayButtonCommandExecute() { }
public virtual bool CanPlayButtonCommandExecute()
{
return true;
}
/// <summary>
/// Command event handler for player next button
/// </summary>
public virtual void OnNextButtonExecute() { }
public virtual bool CanNextButtonCommandExecute()
{
return true;
}
/// <summary>
/// Command event handler for player previous button
/// </summary>
public virtual void OnPreviousButtonExecute() { }
public virtual bool CanPreviousButtonCommandExecute()
{
return true;
}
/// <summary>
/// Delegate for interacting with main screen player control
/// </summary>
/// <value></value>
public SetPlayerDelegate ChangePlayerState { get; set; }
/// <summary>
/// Delegate for checking if main screen player control is currently playing
/// </summary>
/// <value></value>
public GetIsPlayingDelegate IsPlaying { get; set; }
public ShowModalDelegate ShowModal { get; set; }
public HideModalDelegate HideModal { get; set; }
#endregion Player
#region Lifecycle
/// <summary>
/// Called by main screen on view appearing
/// </summary>
/// <typeparam name="object"></typeparam>
/// <returns></returns>
public virtual Task OnActive() { return Task.FromResult<object>(null); }
/// <summary>
/// Called by main screen on view disappearing
/// </summary>
/// <typeparam name="object"></typeparam>
/// <returns></returns>
public virtual Task OnInactive() { return Task.FromResult<object>(null); }
#endregion
#region INotifyPropertyChanged Implementation
public bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (Object.Equals(storage, value))
return false;
storage = value;
OnPropertyChanged(propertyName);
return true;
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged == null)
return;
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}

View File

@ -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;
}

View File

@ -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>

View File

@ -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;
}
}
}

View File

@ -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)}
});
}
}
}

View File

@ -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>

View File

@ -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();
}
}
}

View File

@ -0,0 +1,20 @@
using System;
namespace Aurora.Design.Views.Party.NewPartyDialog
{
public enum ConnectionType
{
Host,
Join
}
public class ConnectionDetails
{
public ConnectionDetails()
{
}
public string HostName { get; set; }
public ConnectionType ConnectionType { get; set; }
}
}

View File

@ -0,0 +1,25 @@
#View {
width: 300;
height: 500;
}
#DialogTitle {
text-align: center;
text-align-last: center;
margin-top: 20;
margin-bottom: 40;
margin-left: 20;
margin-right: 30;
color: white;
font-size: 50;
word-wrap: break-word;
}
#Container {
background-color: transparent;
}
Button {
background-color: transparent;
}

View File

@ -0,0 +1,46 @@
<?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.Party.NewPartyDialog.NewPartyDialog"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<ContentView.Resources>
<StyleSheet
Source="NewPartyDialog.css"/>
</ContentView.Resources>
<ContentView.Content>
<StackLayout
HorizontalOptions="FillAndExpand"
Orientation="Vertical">
<Label
x:Name="DialogTitle"
LineBreakMode="WordWrap"
Text="Join or Host a Party"/>
<StackLayout
x:Name="Container"
Orientation="Horizontal"
HorizontalOptions="Center"
VerticalOptions="Start">
<Entry
Text="{Binding Hostname}"
Placeholder="Enter a hostname"
x:Name="HostnameEntry"/>
<StackLayout
Orientation="Horizontal"
HorizontalOptions="Center">
<Button
HorizontalOptions="Center"
x:Name="buttonHost"
Text="Host"
Command="{Binding HostCommand}"/>
<Button
HorizontalOptions="Center"
x:Name="buttonClient"
Text="Join"
Command="{Binding JoinCommand}"/>
</StackLayout>
</StackLayout>
</StackLayout>
</ContentView.Content>
</ContentView>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Aurora.Design.Views.Party.NewPartyDialog
{
public partial class NewPartyDialog : ContentView
{
public NewPartyDialog()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using Xamarin.Forms;
namespace Aurora.Design.Views.Party.NewPartyDialog
{
public class NewPartyDialogViewModel : BaseDialogViewModel
{
public NewPartyDialogViewModel()
{
this.ReturnObject = new ConnectionDetails();
HostCommand = new Command(OnHostExecute, OnHostCanExecute);
JoinCommand = new Command(OnJoinExecute, OnJoinCanCanExecute);
}
public string Hostname
{
get
{
if (ReturnObject is ConnectionDetails)
{
ConnectionDetails obj = ReturnObject as ConnectionDetails;
return obj.HostName;
};
return string.Empty;
}
set
{
if (ReturnObject is ConnectionDetails)
{
ConnectionDetails obj = ReturnObject as ConnectionDetails;
if (value != obj.HostName)
{
obj.HostName = value;
}
OnPropertyChanged(Hostname);
HostCommand.ChangeCanExecute();
JoinCommand.ChangeCanExecute();
}
}
}
public void OnHostExecute()
{
ConnectionDetails obj = base.ReturnObject as ConnectionDetails;
obj.ConnectionType = ConnectionType.Host;
Finish();
}
public Command HostCommand { get; private set; }
public Command JoinCommand { get; private set; }
public bool OnHostCanExecute()
{
return string.IsNullOrWhiteSpace(Hostname);
}
public void OnJoinExecute()
{
ConnectionDetails obj = base.ReturnObject as ConnectionDetails;
obj.ConnectionType = ConnectionType.Join;
Finish();
}
public bool OnJoinCanCanExecute()
{
return !string.IsNullOrWhiteSpace(Hostname);
}
}
}

View File

@ -0,0 +1,37 @@
Label {
height: 20;
}
#MembersList {
height: 100;
background-color: transparent;
}
#LeaveButton {
margin-top: 20;
margin-bottom: 20;
vertical-align: bottom;
align-self: center;
}
#MembersList {
background-color: #1e1e1e;
}
#MembersList Grid {
margin-left: 20;
margin-right: 20;
margin-top: 20;
margin-bottom: 20;
width: 150;
border-radius: 25;
background-color: #626363;
}
#MembersList Label {
text-align: center;
vertical-align: middle;
color: white;
font-size: 20;
}

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentView
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:tabView="clr-namespace:Aurora.Design.Components.TabView"
xmlns:ml="clr-namespace:Aurora.Design.Components.MemberList"
xmlns:library="clr-namespace:Aurora.Design.Components.Library"
xmlns:flv="clr-namespace:DLToolkit.Forms.Controls;assembly=DLToolkit.Forms.Controls.FlowListView"
x:Class="Aurora.Design.Views.Party.PartyView">
<ContentView.Resources>
<StyleSheet
Source="./PartyView.css"/>
</ContentView.Resources>
<ContentView.Content>
<StackLayout
x:Name="TabHeader">
<tabView:TabViewControl
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
TabSizeOption="100"
SelectedTabIndex="{Binding SelectedTabIndex}"
HeaderBackgroundColor="#181818"
x:Name="TabView">
<tabView:TabViewControl.ItemSource>
<!-- Members Tab -->
<tabView:TabItem
HeaderText="Members">
<Grid
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition
Height="*"/>
<RowDefinition
Height="30"/>
</Grid.RowDefinitions>
<ml:MemberList
x:Name="MembersList"
Grid.Row="0"
VerticalOptions="FillAndExpand"
Members="{Binding Members}"/>
<!-- Leave Party Button -->
<Button
Grid.Row="1"
Text="Leave Party"
Command="{Binding LeavePartyCommand}"/>
</Grid>
</tabView:TabItem>
<!-- Library Tab -->
<tabView:TabItem
HeaderText="Queue">
<library:Library
ItemsSource="{Binding Queue}"
SelectedItem="{Binding SelectedSong}"
ItemDoubleClicked="{Binding PlayCommand}"/>
</tabView:TabItem>
</tabView:TabViewControl.ItemSource>
</tabView:TabViewControl>
</StackLayout>
</ContentView.Content>
</ContentView>

View File

@ -0,0 +1,13 @@
using System;
using Xamarin.Forms;
namespace Aurora.Design.Views.Party
{
public partial class PartyView : ContentView
{
public PartyView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,577 @@
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using System.Linq;
using Xamarin.Forms;
using Aurora.Proto.Party;
using Aurora.Models.Media;
using Aurora.Services.Client;
using Aurora.Design.Views.Party.NewPartyDialog;
using Aurora.Services.Settings;
using Aurora.Services.Server;
using Aurora.Services.EventManager;
using Grpc.Core;
namespace Aurora.Design.Views.Party
{
//TODO refactor
enum PartyState
{
SelectingHost,
InParty,
Hosting,
Connecting,
}
delegate void EventHandler(BaseEvent e);
public class PartyViewModel : BaseViewModel
{
private PartyState _state;
private string _hostname = "";
private ObservableCollection<Member> _members;
private ObservableCollection<BaseMedia> _queue;
private BaseMedia _selectedMedia;
private ISettingsService _settingsService;
private IClientService _clientService;
private IServerService _serverService;
private IEventManager _eventManager;
private CancellationTokenSource _eventCancellationTokenSource;
private Dictionary<BaseEvent.DerivedEventOneofCase, EventHandler> _eventHandlers;
private int _selectedTabIndex;
public PartyViewModel(
ISettingsService settingsService,
IServerService serverService,
IEventManager eventManager,
IClientService clientService)
{
_members = new ObservableCollection<Member>();
_queue = new ObservableCollection<BaseMedia>();
this._settingsService = settingsService;
this._serverService = serverService;
this._eventManager = eventManager;
this._clientService = clientService;
SetState(PartyState.SelectingHost);
PlayCommand = new Command(OnDoubleClickCommandExecute, CanDoubleClickCommandExecute);
LeavePartyCommand = new Command(OnLeavePartyCommandExecute, CanLeavePartyCommandExecute);
//Setup event handlers
_eventHandlers = new Dictionary<BaseEvent.DerivedEventOneofCase, EventHandler>()
{
{BaseEvent.DerivedEventOneofCase.MediaPausedEvent, this.OnRemoteMediaPaused},
{BaseEvent.DerivedEventOneofCase.MediaResumedEvent, this.OnRemoteMediaResumed},
{BaseEvent.DerivedEventOneofCase.NewMediaPlayingEvent, this.OnNewRemoteMediaPlaying},
{BaseEvent.DerivedEventOneofCase.MemberCreatedEvent, this.OnPartyMemberJoined},
{BaseEvent.DerivedEventOneofCase.MemberDeletedEvent, this.OnPartyMemberLeft}
};
}
#region Properties
public int SelectedTabIndex
{
get { return _selectedTabIndex; }
set { SetProperty(ref _selectedTabIndex, value); }
}
/// <summary>
/// Publc property for the members list
/// </summary>
/// <value></value>
public ObservableCollection<Member> Members
{
get
{
return _members;
}
set
{
SetProperty(ref _members, value);
}
}
/// <summary>
/// Public property for queue item source
/// </summary>
/// <value></value>
public ObservableCollection<BaseMedia> Queue
{
get
{
return _queue;
}
set
{
if (value != _queue)
{
SetProperty(ref _queue, value);
}
}
}
/// <summary>
/// Public property for the currently selected song.
/// </summary>
/// <value></value>
public BaseMedia SelectedSong
{
get { return _selectedMedia; }
set { SetProperty(ref _selectedMedia, value); }
}
/// <summary>
/// Public property for playing media
/// </summary>
/// <value></value>
public Command PlayCommand { get; private set; }
public Command LeavePartyCommand { get; private set; }
#endregion Properties
#region Events
/// <summary>
/// Called by framework when view becomes active
/// </summary>
/// <returns></returns>
public override async Task OnActive()
{
OnPropertyChanged("SelectedTabIndex");
if (this._state == PartyState.Hosting ||
this._state == PartyState.InParty)
{
await this.GetEvents().ConfigureAwait(false);
}
else
{
//Open host selection modal
NewPartyDialogViewModel vm = new NewPartyDialogViewModel();
ConnectionDetails details = new ConnectionDetails();
vm.Finish = () =>
{
this.HideModal();
details = vm.ReturnObject as ConnectionDetails;
_hostname = details.HostName;
switch (details.ConnectionType)
{
case ConnectionType.Host:
{
OnHostCommandExecute();
break;
}
case ConnectionType.Join:
{
OnJoinCommandExecute();
break;
}
}
};
this.ShowModal(typeof(NewPartyDialog.NewPartyDialog), vm);
}
}
/// <summary>
/// Called by framework when view becomes inactive
/// </summary>
/// <returns></returns>
public override Task OnInactive()
{
if(this._eventCancellationTokenSource != null){
this._eventCancellationTokenSource.Cancel();
}
return Task.FromResult<object>(null);
}
/// <summary>
/// Remote media paused event
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
public void OnRemoteMediaPaused(BaseEvent e)
{
StopPlaying();
}
/// <summary>
/// Remote playing new media event
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
public void OnNewRemoteMediaPlaying(BaseEvent e)
{
PlayFromBeginning(GetMediaFromQueue(e.NewMediaPlayingEvent.Media.Name));
}
/// <summary>
/// Remote resumed playing event
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
public void OnRemoteMediaResumed(BaseEvent e)
{
PlayResume();
}
/// <summary>
/// Member joined party event
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
public void OnPartyMemberJoined(BaseEvent e)
{
Members.Add(e.MemberCreatedEvent.Member);
}
/// <summary>
/// Member left party event
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
public void OnPartyMemberLeft(BaseEvent e)
{
var found = Members.Where(x => x.Name == e.MemberDeletedEvent.MemberName);
foreach (Member member in found)
{
_members.Remove(member);
}
}
#endregion Events
#region Commands
private async void OnJoinCommandExecute()
{
SetState(PartyState.Connecting);
_clientService.Start(_hostname, this._settingsService.DefaultPort.ToString());
await JoinParty(false);
//TODO add cancellation token
try
{
SetState(PartyState.InParty);
await GetEvents().ConfigureAwait(true);
}
catch (Exception ex)
{
Console.WriteLine("Exception occurred while receiviing events: ", ex.Message);
}
}
private bool CanJoinCommandExecute()
{
return true;
}
private async void OnHostCommandExecute()
{
//Change state
SetState(PartyState.Connecting);
_serverService.Start("test", "asdf");
string localHost = ServerService.GetLocalIPAddress();
_clientService.Start(localHost, this._settingsService.DefaultPort.ToString());
await JoinParty(true);
//TODO add cancellation token
try
{
SetState(PartyState.Hosting);
await GetEvents().ConfigureAwait(false);
}
catch (Exception ex)
{
Console.WriteLine("Exception occurred while receiviing events: ", ex.Message);
}
}
private bool CanHostCommandExecute()
{
return true;
}
private async void OnLeavePartyCommandExecute()
{
await _clientService.RemotePartyServiceClient.DeleteMemberAsync(new DeleteMemberRequest()
{
Name = _settingsService.ClientName
});
}
private bool CanLeavePartyCommandExecute()
{
return (this._state == PartyState.InParty || this._state == PartyState.Hosting) ? true : false;
}
public override void OnPlayButtonCommandExecute()
{
if (base.IsPlaying())
{
//Fire play stopped event
AudioMetadata meta = _selectedMedia.Metadata as AudioMetadata;
MediaPausedEvent mediaPaused = new MediaPausedEvent();
_eventManager.FireEvent(new BaseEvent()
{
MediaPausedEvent = mediaPaused
});
}
else
{
//Fire play resume event
AudioMetadata meta = _selectedMedia.Metadata as AudioMetadata;
MediaResumedEvent mediaResumed = new MediaResumedEvent();
_eventManager.FireEvent(new BaseEvent()
{
MediaResumedEvent = mediaResumed
});
}
}
public override bool CanPlayButtonCommandExecute()
{
return this._state == PartyState.Hosting;
}
public override bool CanNextButtonCommandExecute()
{
return this._state == PartyState.Hosting;
}
public override bool CanPreviousButtonCommandExecute()
{
return this._state == PartyState.Hosting;
}
/// <summary>
/// On double click execute, fire media playing event
/// </summary>
public void OnDoubleClickCommandExecute()
{
//Fire Playing event
AudioMetadata meta = _selectedMedia.Metadata as AudioMetadata;
NewMediaPlayingEvent mediaPlaying = new NewMediaPlayingEvent()
{
Media = new Media()
{
//TODO need full resource name
Name = _selectedMedia.Id,
Title = meta.Title,
Artist = meta.Artist,
Album = meta.Album,
}
};
_eventManager.FireEvent(new BaseEvent()
{
NewMediaPlayingEvent = mediaPlaying
});
}
public bool CanDoubleClickCommandExecute()
{
return this._state == PartyState.Hosting;
}
#endregion Commands
#region Private Methods
/// <summary>
/// Join the remote party.
/// </summary>
/// <returns></returns>
private async Task JoinParty(bool asHost)
{
try
{
Member resp = await _clientService.RemotePartyServiceClient.CreateMemberAsync(new CreateMemberRequest
{
Member = new Member()
{
UserName = this._settingsService.Username,
}
});
this._settingsService.ClientName = resp.Name;
await RefreshMembers();
//Subscribe to events
await SubscribeToEvents();
Queue.Clear();
ListMediaResponse mediaResponse = await _clientService.RemotePartyServiceClient.ListMediaAsync(new ListMediaRequest()
{
PageSize = 50,
Parent = "TODO"
});
//Convert received data to remote audio models
foreach (Media data in mediaResponse.Media)
{
//Assign received metadata (since this can't be aquired from a file)
AudioMetadata meta = new AudioMetadata();
meta.Title = data.Title;
meta.Album = data.Album;
meta.Artist = data.Artist;
meta.Duration = data.Duration;
RemoteAudio remote = new RemoteAudio(data.Name,
asHost,
meta,
_clientService.RemotePartyServiceClient);
Queue.Add(remote);
OnPropertyChanged("Queue");
}
}
catch (Exception ex)
{
Console.WriteLine("Error subscribing to events: " + ex.Message);
}
}
private async Task LeaveParty()
{
//Stop receiving events
// _client.StopEvents();
//Unsubscribe
await UnsubscribeFromEvents();
//Leave party
DeleteMemberRequest req = new DeleteMemberRequest()
{
Name = _settingsService.ClientName
};
await _clientService.RemotePartyServiceClient.DeleteMemberAsync(req);
}
private async Task SubscribeToEvents()
{
CreateEventSubscriptionListRequest req = new CreateEventSubscriptionListRequest();
req.Parent = this._settingsService.ClientName;
req.EventSubscriptions.Add(new EventSubscription() { Type = EventType.MemberCreated });
req.EventSubscriptions.Add(new EventSubscription() { Type = EventType.MemberDeleted });
req.EventSubscriptions.Add(new EventSubscription() { Type = EventType.MediaPlaying });
req.EventSubscriptions.Add(new EventSubscription() { Type = EventType.MediaStopped });
Console.WriteLine(string.Format("CLIENT {0} - SubscribeToEvents called from client with id", this._settingsService.ClientName));
await _clientService.RemotePartyServiceClient.CreateEventSubscriptionListAsync(req);
}
private async Task UnsubscribeFromEvents()
{
DeleteAllEventSubscriptionsRequest unsubscribeReq = new DeleteAllEventSubscriptionsRequest();
await _clientService.RemotePartyServiceClient.DeleteAllEventSubscriptionsAsync(unsubscribeReq);
}
/// <summary>
/// Refresh members list.
/// </summary>
private async Task RefreshMembers()
{
Members.Clear();
ListMembersResponse response = await _clientService.RemotePartyServiceClient.ListMembersAsync(
new ListMembersRequest()
{
Parent = "TODO",
PageSize = 50,
});
//Add members
foreach (Member member in response.Members)
{
Members.Add(member);
}
}
private void SetState(PartyState state)
{
_state = state;
OnPropertyChanged("IsSelectingHost");
OnPropertyChanged("IsNotSelectingHost");
}
private BaseMedia GetMediaFromQueue(string Id)
{
if (_queue.Any((BaseMedia media) => media.Id == Id))
{
BaseMedia media = _queue.First((BaseMedia med) => med.Id == Id);
return media;
}
else
{
return null;
}
}
private void PlayFromBeginning(BaseMedia args)
{
base.ChangePlayerState(args, Main.PlayAction.Play);
}
private void PlayResume()
{
base.ChangePlayerState(null, Main.PlayAction.Resume);
}
private void StopPlaying()
{
base.ChangePlayerState(null, Main.PlayAction.Pause);
}
/// <summary>
/// Asynchronous function for processing events off of the event stream.
/// </summary>
/// <returns></returns>
public async Task GetEvents()
{
_eventCancellationTokenSource = new CancellationTokenSource();
string clientName = this._settingsService.ClientName;
Console.WriteLine(string.Format("CLIENT {0} - GetEvents called from client with id", clientName));
using (AsyncServerStreamingCall<BaseEvent> eventStream = _clientService.RemotePartyServiceClient
.GetEvents(new GetEventsRequest { Parent = this._settingsService.ClientName }))
{
try
{
while (!_eventCancellationTokenSource.Token.IsCancellationRequested &&
await eventStream.ResponseStream.MoveNext(_eventCancellationTokenSource.Token))
{
try
{
BaseEvent e = new BaseEvent(eventStream.ResponseStream.Current);
_eventHandlers.TryGetValue(e.DerivedEventCase, out EventHandler handler);
if (handler != null && handler != null)
{
handler.Invoke(e);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception while parsing event ---" + ex.Message);
}
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("EXCEPTION while parsing events --- " + ex.Message));
}
}
}
#endregion Private Methods
}
}

View File

@ -0,0 +1,35 @@
<?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.Profile.ProfileView">
<ContentView.Content>
<StackLayout
Orientation="Vertical">
<StackLayout
Orientation="Horizontal">
<Label
VerticalOptions="Center"
Text="Username"/>
<Entry
Text="{Binding Username}"/>
</StackLayout>
<StackLayout
Orientation="Horizontal">
<Label
VerticalOptions="Center"
Text="Default Port"/>
<Entry
Text="{Binding Port}"/>
</StackLayout>
<StackLayout
Orientation="Horizontal">
<Label
VerticalOptions="Center"
Text="Path to Library"/>
<Entry
Text="{Binding LibraryPath}"/>
</StackLayout>
</StackLayout>
</ContentView.Content>
</ContentView>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Aurora.Design.Views.Profile
{
public partial class ProfileView : ContentView
{
public ProfileView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,46 @@
using System;
using Aurora.Services.Settings;
namespace Aurora.Design.Views.Profile
{
public class ProfileViewModel : BaseViewModel
{
private ISettingsService _settingsService;
public ProfileViewModel(ISettingsService settingsService)
{
this._settingsService = settingsService;
}
public string Username
{
get { return this._settingsService.Username; }
set
{
this._settingsService.Username = value;
OnPropertyChanged("Username");
}
}
public string Port
{
get { return this._settingsService.DefaultPort.ToString(); }
set
{
Int32.TryParse(value, out int portNum);
this._settingsService.DefaultPort = portNum;
OnPropertyChanged("Port");
}
}
public string LibraryPath
{
get { return this._settingsService.LibraryLocation; }
set
{
this._settingsService.LibraryLocation = value;
OnPropertyChanged("LibraryPath");
}
}
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentView
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:library="clr-namespace:Aurora.Design.Components.Library"
x:Class="Aurora.Design.Views.Songs.SongsView">
<ContentView.Content>
<library:Library
ItemsSource="{Binding SongsList}"
SelectedItem="{Binding SelectedSong}"
ItemDoubleClicked="{Binding DoubleClickCommand}"/>
</ContentView.Content>
</ContentView>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Aurora.Design.Views.Songs
{
public partial class SongsView : ContentView
{
public SongsView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,115 @@
using System.Collections.ObjectModel;
using Aurora.Models.Media;
using Aurora.Services.Library;
using Xamarin.Forms;
namespace Aurora.Design.Views.Songs
{
public class SongsViewModel : BaseViewModel
{
#region Fields
private ObservableCollection<BaseMedia> _songsList;
private BaseMedia _selectedSong;
private ILibraryService _libraryService;
#endregion Fields
#region Constructor
public SongsViewModel(ILibraryService libraryService)
{
_songsList = new ObservableCollection<BaseMedia>();
DoubleClickCommand = new Command(OnDoubleClickExecute, OnDoubleClickCanExecute);
this._libraryService = libraryService;
Initialize();
}
#endregion Constructor
#region Properties
public ObservableCollection<BaseMedia> SongsList
{
get { return _songsList; }
set { SetProperty(ref _songsList, value); }
}
public BaseMedia SelectedSong
{
get { return _selectedSong; }
set { SetProperty(ref _selectedSong, value); }
}
public Command DoubleClickCommand { get; private set; }
#endregion Properties
#region Methods
public void Initialize()
{
SongsList = this._libraryService.GetLibrary();
}
#endregion Methods
#region Commmands
public override bool CanPreviousButtonCommandExecute()
{
return true;
}
public override void OnPreviousButtonExecute()
{
}
public override bool CanPlayButtonCommandExecute()
{
return true;
}
public override void OnPlayButtonCommandExecute()
{
if (_selectedSong == null)
{
return;
}
if (base.IsPlaying())
{
base.ChangePlayerState(_selectedSong, Main.PlayAction.Pause);
}
else
{
base.ChangePlayerState(_selectedSong, Main.PlayAction.Play);
}
}
public override bool CanNextButtonCommandExecute()
{
return true;
}
public override void OnNextButtonExecute()
{
}
public void OnDoubleClickExecute()
{
if (_selectedSong == null)
{
return;
}
base.ChangePlayerState(_selectedSong, Main.PlayAction.Play);
}
public bool OnDoubleClickCanExecute()
{
return true;
}
#endregion Commands
}
}

View File

@ -0,0 +1,7 @@
<?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.Stations.StationsView">
<ContentPage.Content></ContentPage.Content>
</ContentView>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Aurora.Design.Views.Stations
{
public partial class StationsView : ContentView
{
public StationsView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,10 @@
using System;
namespace Aurora.Design.Views.Stations
{
public class StationsViewModel : BaseViewModel
{
public StationsViewModel()
{
}
}
}