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 : BasePartyViewModel { public PartyViewModel(ISettingsService settingsService): base(settingsService) { } /// /// Called by framework when view becomes active /// /// public override Task OnActive() { OnPropertyChanged("SelectedTabIndex"); switch(this.State) { case PartyStateV2.Hosting: { this.SetView.Invoke(typeof(PartyView), typeof(HostPartyViewModel)); break; } case PartyStateV2.InParty: { // TODO break; } default: { //Open host selection modal NewPartyDialogViewModel vm = new NewPartyDialogViewModel(); ConnectionDetails details = new ConnectionDetails(); vm.Finish = () => { this.HideModal(); details = vm.ReturnObject as ConnectionDetails; this._hostname = details.HostName; switch (details.ConnectionType) { case ConnectionType.Host: { this.SetView.Invoke(typeof(PartyView), typeof(HostPartyViewModel)); break; } case ConnectionType.Join: { // TODO break; } } }; this.ShowModal(typeof(NewPartyDialog.NewPartyDialog), vm); break; } } return Task.FromResult(null); } /// /// Called by framework when view becomes inactive /// /// public override Task OnInactive() { // if(this._eventCancellationTokenSource != null){ // this._eventCancellationTokenSource.Cancel(); // } return Task.FromResult(null); } } }