Пример #1
0
        private void SetupComponents(ViewModel.LobbyViewModel viewModel)
        {
            model = viewModel.Model;
            memberList.ItemsSource = viewModel.MemberIDs;

            memberList.ItemTapped += (object sender, ItemTappedEventArgs e) =>
            {
                if (e.Item == null)
                {
                    return;
                }
                var sessionId = (e.Item as ViewModel.ChatSessionID).SessionID;
                if (sessionId != null && sessionId.Length > 0)
                {
                    StartSession(sessionId, null);
                }
                memberList.SelectedItem = null;
            };

            viewModel.MemberIDs.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs e) =>
            {
                for (int i = e.NewStartingIndex; i < e.NewItems.Count; ++i)
                {
                    (e.NewItems[i] as ViewModel.ChatSessionID).PropertyChanged += (object s, PropertyChangedEventArgs ev) =>
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            // Trigger an update
                            memberList.ItemsSource = null;
                            memberList.ItemsSource = viewModel.MemberIDs;
                        });
                    };
                }
            };
        }
Пример #2
0
        private void StartSessionHandler(object sender, EventArgs e)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                chatButton.Text      = "Searching";
                chatButton.IsEnabled = false;
                spinner.IsRunning    = true;
            });

            Task.Run(async() =>
            {
                lobbyViewModel = new ViewModel.LobbyViewModel();
                bool success   = await lobbyViewModel.Model.Join();

                Device.BeginInvokeOnMainThread(async() =>
                {
                    if (success)
                    {
                        await Navigation.PushAsync(lobbyViewModel.View, true);
                    }
                    else
                    {
                        messageHandler?.ShowToast("Unable to join a chat lobby");
                    }

                    chatButton.Text      = "Start chatting";
                    chatButton.IsEnabled = true;
                    spinner.IsRunning    = false;
                });
                if (success)
                {
                    lobbyViewModel.Model.StartRequestInterval();
                }
            });
        }
Пример #3
0
        public LobbyPage(ViewModel.LobbyViewModel viewModel)
        {
            InitializeComponent();
            SetupComponents(viewModel);

            App.Instance.Connector.StateChanged += OnBackendStateChanged;
        }