コード例 #1
0
ファイル: ChatActivity.cs プロジェクト: Rickedb/Presence
        public void setUpDelegates()
        {
            Action <int, string, string> receiveMessage = (int chatId, string user, string msg) =>
            {
                this.mAdapter.chatMessages.Add(new ChatMessages()
                {
                    Username = user,
                    Message  = msg
                });

                this.mAdapter.NotifyItemRangeChanged(this.chatMessages.Count - 1, 1);
            };

            Action <int, string> kickedUser = (int chatId, string user) =>
            {
                if (user == this.currentUser.Username)
                {
                    var mainActivity = new Intent(this, typeof(MainActivity));
                    mainActivity.PutExtra("user", new string[] {
                        currentUser.Username,
                        currentUser.Admin.ToString()
                    });
                    mainActivity.PutExtra("signalr", this.signalRURL);
                    this.StartActivity(mainActivity);
                    this.Finish();
                }
            };

            this.chatHub = new ChatClientHub(this.signalRURL);
            this.chatHub.ConfigureCallBacks(receiveMessage, kickedUser);
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.OnlineUsersList);
            drawerLayout = FindViewById <DrawerLayout>(Resource.Id.onlineUsersDrawer);

            this.chatId = Intent.GetIntExtra("chatId", -1);
            string[] userData = Intent.GetStringArrayExtra("user");
            this.signalRURL = Intent.GetStringExtra("signalr");
            this.user       = new Users()
            {
                Username = userData[0], Admin = Convert.ToBoolean(userData[1])
            };
            this.hub       = new ChatClientHub(this.signalRURL);
            this.usersList = new List <Users>();
            this.mAdapter  = new OnlineUsersAdapter(this.usersList.ToArray(), this);

            this.hub.refreshUsers((object retVal) =>
            {
                var jContainer = ((JContainer)retVal);
                var usersList  = new List <Users>();
                foreach (JToken token in jContainer)
                {
                    usersList.Add(new Users()
                    {
                        Username = token.Values().ElementAt(1).ToString(),
                        Admin    = false
                    });
                }
                this.mAdapter.users = usersList.ToArray();
                this.mAdapter.NotifyDataSetChanged();
            }, this.chatId);

            this.setUpLayout();
        }
コード例 #3
0
        public void setUpDelegates()
        {
            Action <object> receiveMessage = (object response) =>
            {
                var jContainer = ((JContainer)response);
                this.chats.Clear();
                foreach (JToken token in jContainer)
                {
                    var chat = new Chat()
                    {
                        ID   = (int)token.Values().ElementAt(0),
                        Name = token.Values().ElementAt(2).ToString()
                    };
                    this.chats.Add(chat);
                }
                this.mAdapter.chats = this.chats.ToArray();
                this.mAdapter.NotifyDataSetChanged();
            };

            this.chatHub = new ChatClientHub(this.signalRURL);
            this.chatHub.ConfigureCallBacks(receiveMessage);
        }
コード例 #4
0
        protected void onCreateClick(object sender, EventArgs e)
        {
            ChatClientHub chatHub = new ChatClientHub(this.signalRURL);

            chatHub.CreateChat((bool ok) => {
                if (ok)
                {
                    this.Finish();
                }
                else
                {
                    RunOnUiThread(() =>
                    {
                        Android.Support.V7.App.AlertDialog.Builder builder;
                        builder = new Android.Support.V7.App.AlertDialog.Builder(this);
                        builder.SetTitle("Erro");
                        builder.SetMessage("Nome de Chat já existente!");
                        builder.SetCancelable(false);
                        builder.SetPositiveButton("OK", delegate { });
                        builder.Show();
                    });
                }
            }, this.currentUser.Username, this._txtChatName.Text, Convert.ToInt32(this._txtCapacity.Text));
        }