public LobbyViewModel() : base()
        {
            var thd = new Thread(() =>
            {
                try
                {
                    var games = CardsAgainstHumility.ListAsync().Result;
                    dispatcher.BeginInvoke(() =>
                    {
                        Games  = games;
                        Status = $"{(games.Count == 0 ? "No" : games.Count.ToString())} Games Found";
                    });
                }
                catch (Exception ex)
                {
                    dispatcher.BeginInvoke(() =>
                    {
                        Status = "Connection Error";
                    });
                }
                CardsAgainstHumility.Lobby_GameAdded += Lobby_GameAdded;
                CardsAgainstHumility.ConnectToLobby();
            });

            Status = "Refreshing";
            thd.Start();
        }
Exemplo n.º 2
0
        private void RefreshGamesList()
        {
            RunOnUiThread(() =>
            {
                TextView txtStatus = FindViewById <TextView>(Resource.Id.gb_Status);
                if (txtStatus != null)
                {
                    txtStatus.Text = "Refreshing";
                }
                if (txtStatus != null)
                {
                    txtStatus.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal);
                }
                ListView gameList = FindViewById <ListView>(Resource.Id.gb_List);
                if (gameList != null)
                {
                    gameList.Adapter = new GameInstanceArrayAdapter(this, null, new GameInstance[] { });
                }
            });
            try
            {
                var games = CardsAgainstHumility.ListAsync().Result;

                RunOnUiThread(() =>
                {
                    ListView gameList  = FindViewById <ListView>(Resource.Id.gb_List);
                    TextView txtStatus = FindViewById <TextView>(Resource.Id.gb_Status);

                    if (gameList != null)
                    {
                        gameList.Adapter = new GameInstanceArrayAdapter(this, JoinGame, games);
                    }
                    if (txtStatus != null)
                    {
                        txtStatus.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal);
                    }
                    if (txtStatus != null)
                    {
                        txtStatus.Text = $"{((games.Count > 0) ? games.Count.ToString() : "No")} Game{(games.Count == 1 ? "" : "s")} Found";
                    }

                    CardsAgainstHumility.Lobby_SocketConnected      += OnSocketConnected;
                    CardsAgainstHumility.Lobby_SocketConnectError   += OnSocketConnectError;
                    CardsAgainstHumility.Lobby_SocketConnectTimeout += OnSocketConnectTimeout;
                    CardsAgainstHumility.Lobby_Join      += OnLobbyJoin;
                    CardsAgainstHumility.Lobby_GameAdded += OnGameAdded;
                    CardsAgainstHumility.ConnectToLobby();
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                RunOnUiThread(() =>
                {
                    TextView txtStatus = FindViewById <TextView>(Resource.Id.gb_Status);
                    if (txtStatus != null)
                    {
                        txtStatus.Text = ("Connection Error");
                    }
                });
            }
        }