Adding dependency injection
This commit is contained in:
@ -9,8 +9,8 @@ using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Aurora.Models.Media;
|
||||
using Aurora.Design.Components.MediaPlayer;
|
||||
using Aurora.Services.PlayerService;
|
||||
using System.Threading;
|
||||
using Aurora.Services.Player;
|
||||
using Autofac;
|
||||
|
||||
namespace Aurora.Design.Views.Main
|
||||
{
|
||||
@ -38,10 +38,10 @@ namespace Aurora.Design.Views.Main
|
||||
private Dictionary<int, BaseViewModel> _viewModels;
|
||||
private BaseViewModel _lastViewModel;
|
||||
private Player _playerComponent;
|
||||
private PlayerService _playerService;
|
||||
private IPlayer _playerService;
|
||||
private ContentPresenter _viewContent;
|
||||
|
||||
public MainView()
|
||||
public MainView(IPlayer player)
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = new MainViewModel();
|
||||
@ -50,7 +50,7 @@ namespace Aurora.Design.Views.Main
|
||||
_playerComponent = Player;
|
||||
|
||||
_viewContent = (ContentPresenter)Content.FindByName("ViewContent");
|
||||
_playerService = PlayerService.Instance;
|
||||
_playerService = player;
|
||||
|
||||
MasterPage.ListView.ItemSelected += OnNavItemSelected;
|
||||
|
||||
@ -89,7 +89,7 @@ namespace Aurora.Design.Views.Main
|
||||
}
|
||||
|
||||
//Instantiate new view model
|
||||
vm = (BaseViewModel)Activator.CreateInstance(item.TargetViewModelType);
|
||||
vm = (BaseViewModel)App.Container.Resolve(item.TargetViewModelType); //Activator.CreateInstance(item.TargetViewModelType);
|
||||
_viewModels.Add(item.Id, vm);
|
||||
|
||||
}
|
||||
@ -135,7 +135,7 @@ namespace Aurora.Design.Views.Main
|
||||
else
|
||||
{
|
||||
//Instantiate new view model
|
||||
vm = (BaseViewModel)Activator.CreateInstance(firstNavItem.TargetViewModelType);
|
||||
vm = (BaseViewModel)App.Container.Resolve(firstNavItem.TargetViewModelType); //(BaseViewModel)Activator.CreateInstance(firstNavItem.TargetViewModelType);
|
||||
_viewModels.Add(firstNavItem.Id, vm);
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,11 @@ using Aurora.Proto.Party;
|
||||
using Aurora.Proto.Events;
|
||||
using Aurora.Services.ClientService;
|
||||
using Aurora.Services.ClientService.Events;
|
||||
using Aurora.Services.PlayerService;
|
||||
using Aurora.Services.Player;
|
||||
using Aurora.Services.EventManager;
|
||||
using Aurora.Models.Media;
|
||||
using Aurora.Design.Views.Party.NewPartyDialog;
|
||||
using Aurora.Services.Settings;
|
||||
|
||||
namespace Aurora.Design.Views.Party
|
||||
{
|
||||
@ -32,22 +33,25 @@ namespace Aurora.Design.Views.Party
|
||||
private ObservableCollection<PartyMember> _members;
|
||||
private ObservableCollection<BaseMedia> _queue;
|
||||
private BaseMedia _selectedMedia;
|
||||
private ClientService _client;
|
||||
private IClientService _client;
|
||||
private ISettingsService _settingsService;
|
||||
|
||||
private int _selectedTabIndex;
|
||||
|
||||
public PartyViewModel()
|
||||
public PartyViewModel(ISettingsService settingsService, IClientService clientService)
|
||||
{
|
||||
_members = new ObservableCollection<PartyMember>();
|
||||
_queue = new ObservableCollection<BaseMedia>();
|
||||
|
||||
this._settingsService = settingsService;
|
||||
|
||||
SetState(PartyState.SelectingHost);
|
||||
|
||||
PlayCommand = new Command(OnDoubleClickCommandExecute, CanDoubleClickCommandExecute);
|
||||
|
||||
LeavePartyCommand = new Command(OnLeavePartyCommandExecute, CanLeavePartyCommandExecute);
|
||||
|
||||
_client = ClientService.Instance;
|
||||
_client = clientService;
|
||||
|
||||
_client.OnMediaPaused += this.OnRemoteMediaPaused;
|
||||
_client.OnMediaResumed += this.OnRemoteMediaResumed;
|
||||
@ -245,7 +249,7 @@ namespace Aurora.Design.Views.Party
|
||||
private async void OnJoinCommandExecute()
|
||||
{
|
||||
SetState(PartyState.Connecting);
|
||||
_client.Start(_hostname, SettingsService.Instance.DefaultPort.ToString());
|
||||
_client.Start(_hostname, this._settingsService.DefaultPort.ToString());
|
||||
await JoinParty(false);
|
||||
|
||||
//TODO add cancellation token
|
||||
@ -272,7 +276,7 @@ namespace Aurora.Design.Views.Party
|
||||
ServerService.Instance.Start();
|
||||
string localHost = ServerService.GetLocalIPAddress();
|
||||
_client.IsHost = true;
|
||||
_client.Start(localHost, SettingsService.Instance.DefaultPort.ToString());
|
||||
_client.Start(localHost, this._settingsService.DefaultPort.ToString());
|
||||
await JoinParty(true);
|
||||
|
||||
|
||||
@ -387,10 +391,10 @@ namespace Aurora.Design.Views.Party
|
||||
{
|
||||
JoinPartyResponse resp = await _client.RemotePartyClient.JoinPartyAsync(new JoinPartyRequest
|
||||
{
|
||||
UserName = SettingsService.Instance.Username,
|
||||
UserName = this._settingsService.Username,
|
||||
});
|
||||
|
||||
SettingsService.Instance.ClientId = resp.ClientId;
|
||||
this._settingsService.ClientId = resp.ClientId;
|
||||
|
||||
RefreshMembers();
|
||||
|
||||
@ -447,13 +451,13 @@ namespace Aurora.Design.Views.Party
|
||||
req.EventTypes.Add(EventType.PartyMemberLeft);
|
||||
req.EventTypes.Add(EventType.MediaPlaying);
|
||||
req.EventTypes.Add(EventType.MediaStopped);
|
||||
if (!string.IsNullOrWhiteSpace(SettingsService.Instance.ClientId))
|
||||
if (!string.IsNullOrWhiteSpace(this._settingsService.ClientId))
|
||||
{
|
||||
req.ClientId = SettingsService.Instance.ClientId;
|
||||
req.ClientId = this._settingsService.ClientId;
|
||||
}
|
||||
|
||||
|
||||
Console.WriteLine(string.Format("CLIENT {0} - SubscribeToEvents called from client with id", SettingsService.Instance.ClientId));
|
||||
Console.WriteLine(string.Format("CLIENT {0} - SubscribeToEvents called from client with id", this._settingsService.ClientId));
|
||||
await _client.RemoteEventClient.SubscribeToEventsAsync(req);
|
||||
}
|
||||
private async Task UnsubscribeFromEvents()
|
||||
|
@ -1,32 +1,34 @@
|
||||
using System;
|
||||
using Aurora.Services;
|
||||
using Aurora.Services.Settings;
|
||||
|
||||
namespace Aurora.Design.Views.Profile
|
||||
{
|
||||
public class ProfileViewModel : BaseViewModel
|
||||
{
|
||||
private ISettingsService _settingsService;
|
||||
|
||||
public ProfileViewModel()
|
||||
public ProfileViewModel(ISettingsService settingsService)
|
||||
{
|
||||
this._settingsService = settingsService;
|
||||
}
|
||||
|
||||
public string Username
|
||||
{
|
||||
get { return SettingsService.Instance.Username; }
|
||||
get { return this._settingsService.Username; }
|
||||
set
|
||||
{
|
||||
SettingsService.Instance.Username = value;
|
||||
this._settingsService.Username = value;
|
||||
OnPropertyChanged("Username");
|
||||
}
|
||||
}
|
||||
|
||||
public string Port
|
||||
{
|
||||
get { return SettingsService.Instance.DefaultPort.ToString(); }
|
||||
get { return this._settingsService.DefaultPort.ToString(); }
|
||||
set
|
||||
{
|
||||
Int32.TryParse(value, out int portNum);
|
||||
SettingsService.Instance.DefaultPort = portNum;
|
||||
this._settingsService.DefaultPort = portNum;
|
||||
OnPropertyChanged("Port");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user