public ChatCommandHandler(MainActivity parentActivity, MessageListViewAdapter messageAdapter, string initialChannel)
 {
     this.parentActivity = parentActivity;
     this.messageAdapter = messageAdapter;
     this.FullHistory    = new Dictionary <string, List <ChatMessage> >();
     this.CurrentChannel = initialChannel;
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            LogManager.LogFactory = new GenericLogFactory(Console.WriteLine);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            // Get our button from the layout resource,
            // and attach an event to it
            Button sendButton = FindViewById <Button>(Resource.Id.sendMessageButton);

            messageBox = FindViewById <EditText>(Resource.Id.message);
            SupportToolbar toolbar = FindViewById <SupportToolbar>(Resource.Id.toolbar);

            drawerLayout   = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);
            rightDrawer    = FindViewById <ListView>(Resource.Id.right_drawer);
            var messageHistoryList = FindViewById <ListView>(Resource.Id.messageHistory);
            var chatBackground     = FindViewById <ImageView>(Resource.Id.chat_background);

            InitDefaultBackground(chatBackground);

            navigationView.Tag = 0;
            rightDrawer.Tag    = 1;

            var messageHistoryAdapter = new MessageListViewAdapter(this, new List <ChatMessage>(), () => this.subscriberList);

            messageHistoryList.Adapter = messageHistoryAdapter;

            var channels = new[] { "home" };

            cmdReceiver = new ChatCommandHandler(this, messageHistoryAdapter, "home");
            var activity = this;

            client = new ServerEventsClient(BaseUrl, channels)
            {
                OnConnect = connectMsg =>
                {
                    client.UpdateChatHistory(cmdReceiver)
                    .ContinueWith(t =>
                                  connectMsg.UpdateUserProfile(activity));
                },
                OnCommand = command =>
                {
                    if (command is ServerEventJoin)
                    {
                        client.GetChannelSubscribersAsync()
                        .ContinueWith(t => {
                            subscriberList = t.Result;
                            Application.SynchronizationContext.Post(_ => {
                                // Refresh profile icons when users join
                                messageHistoryAdapter.NotifyDataSetChanged();
                            }, null);
                        });
                    }
                },
                OnException = error => {
                    Application.SynchronizationContext.Post(
                        _ => { Toast.MakeText(this, "Error : " + error.Message, ToastLength.Long); }, null);
                },
                //ServiceClient = new JsonHttpClient(BaseUrl),
                Resolver = new MessageResolver(cmdReceiver)
            };
            client.RegisterNamedReceiver <ChatReceiver>("cmd");
            client.RegisterNamedReceiver <TvReciever>("tv");
            client.RegisterNamedReceiver <CssReceiver>("css");

            SetSupportActionBar(toolbar);

            var rightDataSet = new List <string>(commands.Keys);
            var rightAdapter = new ActionListViewAdapter(this, rightDataSet);

            rightDrawer.Adapter    = rightAdapter;
            rightDrawer.ItemClick += (sender, args) =>
            {
                Application.SynchronizationContext.Post(_ =>
                {
                    messageBox.Text = commands[rightDataSet[args.Position]];
                    drawerLayout.CloseDrawer(rightDrawer);
                }, null);
            };

            drawerToggle = new ChatActionBarDrawerToggle(
                this,                          //Host Activity
                drawerLayout,                  //DrawerLayout
                toolbar,                       // Instance of toolbar, if you use other ctor, the hamburger icon/arrow animation won't work..
                Resource.String.openDrawer,    //Opened Message
                Resource.String.closeDrawer    //Closed Message
                );

            SupportActionBar.SetHomeButtonEnabled(true);
            SupportActionBar.SetDisplayShowTitleEnabled(true);

            drawerLayout.SetDrawerListener(drawerToggle);
            drawerToggle.SyncState();

            navigationView.NavigationItemSelected += OnChannelClick;
            sendButton.Click += async(e, args) => { await OnSendClick(e, args); };
        }