Exemplo n.º 1
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (requestCode == PickImageId && resultCode == Result.Ok && data != null)
            {
                Toast.MakeText(this, "Sending image...", ToastLength.Long);

                Bitmap img = MediaStore.Images.Media.GetBitmap(ContentResolver, data.Data);
                new Thread(async() => {
                    while (!await network.SendImage(db, user, chat, img))
                    {
                        await network.Authenticate(db, user);
                    }
                }).Start();
            }
        }
Exemplo n.º 2
0
        private void ShowChats(User user)
        {
            TextView placeholder = FindViewById <TextView> (Resource.Id.placeholder);
            var      x           = db.Table <Chat> ();

            if (x.Count() > 0)
            {
                placeholder.Visibility = ViewStates.Gone;
            }
            else
            {
                placeholder.Visibility = ViewStates.Visible;
                placeholder.Text       = "No chats found.";
            }
            LinearLayout chatList = FindViewById <LinearLayout> (Resource.Id.chatList);

            chatList.RemoveAllViews();
            foreach (var elem in x.OrderByDescending(e => e.time))
            {
                View v;
                if (setting.FontSize == Setting.Size.large)
                {
                    v = LayoutInflater.Inflate(Resource.Layout.ChatLarge, null);
                }
                else
                {
                    v = LayoutInflater.Inflate(Resource.Layout.Chat, null);
                }
                TextView  name    = v.FindViewById <TextView>(Resource.Id.chatName);
                TextView  message = v.FindViewById <TextView>(Resource.Id.chatMessage);
                TextView  time    = v.FindViewById <TextView>(Resource.Id.chatTime);
                ImageView image   = v.FindViewById <ImageView> (Resource.Id.chatImage);

                new Thread(async() => {
                    try {
                        string conv = elem.conversation;
                        if (conv.Split(',').Length == 2)
                        {
                            if (conv.Split(',')[0] == user.user)
                            {
                                conv = conv.Split(',')[1];
                            }
                            else
                            {
                                conv = conv.Split(',')[0];
                            }
                        }
                        var imageBitmap = await network.GetImageBitmapFromUrl(Resources.GetString(Resource.String.profileUrl) + conv + ".png", AsyncNetwork.MINI_PROFILE_SIZE, AsyncNetwork.MINI_PROFILE_SIZE);
                        RunOnUiThread(() => image.SetImageBitmap(imageBitmap));
                    } catch (Exception e) {
                        Log.Error("BlaChat", e.StackTrace);
                    }
                }).Start();

                name.Text = elem.name;
                var tmp     = db.Table <Message> ().Where(q => q.conversation == elem.conversation).OrderByDescending(q => q.time);
                var lastMsg = tmp.FirstOrDefault();
                if (lastMsg != null)
                {
                    var escape = lastMsg.text.Replace("&quot;", "\"");
                    escape = escape.Replace("&lt;", "<");
                    escape = escape.Replace("&gt;", ">");
                    escape = escape.Replace("&amp;", "&");
                    if (lastMsg.nick == user.user)
                    {
                        message.Text = "Du: " + escape;
                    }
                    else
                    {
                        if (elem.conversation.Split(',').Length == 2 && lastMsg.nick != "watchdog")
                        {
                            message.Text = escape;
                        }
                        else
                        {
                            message.Text = lastMsg.author + ": " + escape;
                        }
                    }
                    time.Text = TimeConverter.AutoConvert(lastMsg.time);
                }
                else
                {
                    time.Text    = "";
                    message.Text = "No message";
                }

                v.Clickable = true;
                v.Click    += delegate {
                    Finish();
                    var intent = new Intent(this, typeof(ChatActivity));
                    intent.PutExtra("conversation", elem.conversation);
                    StartActivity(intent);
                    var chat = db.Get <Chat> (elem.conversation);
                    new Thread(async() => {
                        if (textShare != null)
                        {
                            while (!await network.SendMessage(db, user, chat, "(Shared Text) " + textShare))
                            {
                                await network.Authenticate(db, user);
                            }
                        }
                        foreach (var file in fileset)
                        {
                            Bitmap img = MediaStore.Images.Media.GetBitmap(ContentResolver, file);
                            while (!await network.SendImage(db, user, chat, img))
                            {
                                await network.Authenticate(db, user);
                            }
                        }
                    }).Start();
                };
                chatList.AddView(v);
            }
            chatList.Post(() => chatList.RequestLayout());
        }