示例#1
0
        public override Dialog OnCreateDialog(Bundle savedInstanceState)
        {
            base.OnCreateDialog(savedInstanceState);

            AlertDialog.Builder builder = new AlertDialog.Builder(Activity)
                                          .SetView(Resource.Layout.Dialog)
                                          .SetPositiveButton(Resource.String.Join, (sender, e) => {
                var roomName = Dialog.FindViewById <EditText>(Resource.Id.Userinput).Text;

                ChatRoomContext context = Globals.CampfireChatClient.ChatRoomTable.GetOrCreate(IdentityHash.GetFlyweight(CryptoUtil.GetHash(CryptoUtil.GetHash(Encoding.UTF8.GetBytes(roomName)))));
                context.FriendlyName    = roomName;

                Globals.CampfireNetClient.IdentityManager.AddMulticastKey(
                    IdentityHash.GetFlyweight(CryptoUtil.GetHash(CryptoUtil.GetHash(Encoding.UTF8.GetBytes(roomName)))),
                    CryptoUtil.GetHash(Encoding.UTF8.GetBytes(roomName)));

                byte[] roomKey = CryptoUtil.GetHash(CryptoUtil.GetHash(Encoding.UTF8.GetBytes(roomName)));
                Globals.JoinedRooms.Add(roomKey);

                uiHandler.ObtainMessage(0, new ChatEntry(roomKey, context)).SendToTarget();

                Dismiss();
            })
                                          .SetNegativeButton(Resource.String.Cancel, (sender, e) => {
                Dismiss();
            });

            return(builder.Create());
        }
示例#2
0
        private List <ChatEntry> GetKnownRooms()
        {
            var entries = new List <ChatEntry>();

            foreach (var roomKey in Globals.JoinedRooms)
            {
                ChatRoomContext context = Globals.CampfireChatClient.ChatRoomTable.GetOrCreate(IdentityHash.GetFlyweight(roomKey));
                entries.Add(new ChatEntry(roomKey, context));
            }

            return(entries);
        }
示例#3
0
 public bool TryLookup(IdentityHash destination, out ChatRoomContext context)
 {
     return(descriptorsByRoomIdHash.TryGetValue(destination, out context));
 }
 public ChatEntry(byte[] id, ChatRoomContext context)
 {
     Id      = id;
     Context = context;
 }
示例#5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            //         testMessages = new List<MessageEntry> {
            //            new MessageEntry("Name 1", "This is a test message 1"),
            //            new MessageEntry("Name 2", "This is a test message 2"),
            //            new MessageEntry("Name 3", "This is a test message 3"),
            //            new MessageEntry("Name 2", "This is a test message 4 really long message here one that is sure to overflow. How about some more text here and see if we can get it to three lines - or even more! How far can we go?"),
            //            new MessageEntry("Name 3", "This is a test message 5"),
            //            new MessageEntry("Name 1", "These are yet more messages designed to be long and take up space."),
            //            new MessageEntry("Name 2", "These are yet more messages designed to be long and take up space."),
            //            new MessageEntry("Name 3", "These are yet more messages designed to be long and take up space."),
            //            new MessageEntry("Name 1", "These are yet more messages designed to be long and take up space."),
            //            new MessageEntry("Name 2", "These are yet more messages designed to be long and take up space.")
            //         };

            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Chat);

            var toolbar = FindViewById <Android.Widget.Toolbar>(Resource.Id.Toolbar);

            SetActionBar(toolbar);
            ActionBar.SetDisplayHomeAsUpEnabled(true);

            chatRecyclerView = (RecyclerView)FindViewById(Resource.Id.Messages);
            chatRecyclerView.HasFixedSize = true;

            chatLayoutManager = new LinearLayoutManager(this);
            chatRecyclerView.SetLayoutManager(chatLayoutManager);

            chatAdapter            = new ChatAdapter();
            chatAdapter.ItemClick += OnItemClick;
            chatRecyclerView.SetAdapter(chatAdapter);

            var chatId = Intent.GetByteArrayExtra("chatId");

            chatRoomContext = Globals.CampfireChatClient.ChatRoomTable.GetOrCreate(IdentityHash.GetFlyweight(chatId));
            Title           = chatRoomContext.FriendlyName;

            viewModel = chatRoomContext.CreateViewModelAndSubscribe((sender, e) => {
                Console.WriteLine("        ######## hitting add entry time");
                var message = e.Message;
                if (message.ContentType != ChatMessageContentType.Text)
                {
                    throw new NotImplementedException();
                }

                chatAdapter.AddEntry(new MessageEntry(message, message.FriendlySenderName, Encoding.UTF8.GetString(message.ContentRaw)));
                uiHandler.ObtainMessage(UPDATE_VIEW, -1, 0).SendToTarget();
            });
            foreach (var message in viewModel.InitialMessages)
            {
                chatAdapter.AddEntry(new MessageEntry(message, message.FriendlySenderName, Encoding.UTF8.GetString(message.ContentRaw)));
            }

            var sendButton = FindViewById <Button>(Resource.Id.SendMessage);

            sendButton.Click += HandleSendButtonClicked;

            uiHandler = new LambdaHandler(msg => {
                if (msg.What == UPDATE_VIEW)
                {
                    var index = msg.Arg1 == -1 ? chatAdapter.Entries.Count - 1 : msg.Arg1;
                    Console.WriteLine($"Updating item view at {index}");
                    //               chatAdapter.NotifyItemChanged(index);
                    chatAdapter.NotifyDataSetChanged();
                    chatRecyclerView.GetLayoutManager().ScrollToPosition(chatAdapter.Entries.Count - 1);
                }
            });
        }
示例#6
0
 public ChatRoomViewModel(ChatRoomContext context, List <ChatMessageDto> initialMessages, ChatMessageReceivedCallback messageReceivedCallback)
 {
     Context                 = context;
     InitialMessages         = initialMessages;
     MessageReceivedCallback = messageReceivedCallback;
 }