public static UserDB ConvertFromUser(User item) { UserDB toReturn = new UserDB (); toReturn.AccountActive = item.AccountActive; toReturn.AccountID = item.AccountID; toReturn.DateOfBirth = item.DateOfBirth; toReturn.EmailAddress = item.EmailAddress; toReturn.Errors = item.Errors == null ? null : item.Errors; toReturn.FirstName = item.FirstName; toReturn.LastName = item.LastName; toReturn.Password = item.Password; toReturn.Picture = item.Picture; toReturn.PictureURL = item.PictureURL; toReturn.AllowLocationSearch = item.AllowLocationSearch; toReturn.AllowSearch = item.AllowSearch; toReturn.Description = item.Description; toReturn.DateCreated = item.DateCreated; toReturn.Latitude = item.Latitude; toReturn.Longitude = item.Longitude; toReturn.ShowLocation = item.ShowLocation; toReturn.UserGender = item.UserGender; toReturn.UserName = item.UserName; return toReturn; }
private void CreateUI() { if (MessageConversations.clearView) { RunOnUiThread (() => listWrapper.RemoveAllViewsInLayout ()); MessageConversations.clearView = false; } int c = 0; List<int> unreadMessages = new List<int> (); int numberInConversation = 0; foreach (LOLMessageConversation conversation in MessageConversations.conversationsList) { unreadMessages.Add (conversation.MessageIDs.Count - conversation.ReadMessageIDs.Count); int t = 0; } if (unknownUsers == null) unknownUsers = new List<Guid> (); else unknownUsers.Clear (); List<Guid> unknownMessages = new List<Guid> (); foreach (MessageDB latestMessage in MessageConversations.initialMessages) { UserDB whoFrom = new UserDB (); whoFrom = dbm.GetUserWithAccountID (MessageConversations.conversationsList [c].Recipients [0].ToString ()); if (latestMessage.MessageRecipientDBList.Count != 0) { if (whoFrom == null && latestMessage.MessageRecipientDBList [0].AccountGuid == AndroidData.CurrentUser.AccountID.ToString ()) whoFrom = UserDB.ConvertFromUser (AndroidData.CurrentUser); if (whoFrom != null) { #if DEBUG System.Diagnostics.Debug.WriteLine ("c = {0}, Recipient[0] Guid = {1}, whoFrom name = {2} {3}", c, MessageConversations.conversationsList [c].Recipients [0], whoFrom.FirstName, whoFrom.LastName); #endif List<UserDB> users = new List<UserDB> (); numberInConversation = latestMessage.MessageRecipientDBList.Count; for (int i = 0; i < (numberInConversation > 3 ? 3 : numberInConversation); ++i) { if (latestMessage.MessageRecipientDBList [i] != null) { UserDB current = dbm.GetUserWithAccountID (latestMessage.MessageRecipientDBList [i].AccountGuid.ToString ()); if (current == null && latestMessage.MessageRecipientDBList [i].AccountGuid != AndroidData.CurrentUser.AccountID.ToString ()) unknownUsers.Add (new Guid (latestMessage.MessageRecipientDBList [i].AccountGuid)); else users.Add (current); } } int leftOver = (int)wowZapp.LaffOutOut.Singleton.ScreenXWidth - (int)ImageHelper.convertDpToPixel (imageSize [0] + 30f, context); LinearLayout shell = new LinearLayout (context); shell.Orientation = Orientation.Horizontal; shell.SetGravity (GravityFlags.CenterVertical); shell.LayoutParameters = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.FillParent, (int)ImageHelper.convertDpToPixel (imageSize [1] + 40f, context)); shell.SetPadding (0, 0, 0, (int)ImageHelper.convertDpToPixel (5f, context)); ImageView imageLayout = new ImageView (context); using (LinearLayout.LayoutParams layParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent)) { layParams.SetMargins (3, 3, 3, 3); imageLayout.LayoutParameters = layParams; } imageLayout.SetPadding ((int)ImageHelper.convertDpToPixel (5f, context), 0, (int)ImageHelper.convertDpToPixel (10f, context), (int)ImageHelper.convertDpToPixel (10f, context)); imageLayout = generateUserImage (users); RunOnUiThread (() => shell.AddView (imageLayout)); LinearLayout information = new LinearLayout (context); information.LayoutParameters = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.FillParent); information.Orientation = Orientation.Vertical; LinearLayout topLayout = new LinearLayout (context); topLayout.Orientation = Orientation.Vertical; using (LinearLayout.LayoutParams layParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, (int)ImageHelper.convertDpToPixel(28f, context))) { layParams.Weight = 10f; layParams.SetMargins (0, 0, 0, (int)ImageHelper.convertDpToPixel (3f, context)); topLayout.LayoutParameters = layParams; } TextView whoAmI = new TextView (context); using (LinearLayout.LayoutParams layParams= new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent)) { layParams.SetMargins (10, 0, 10, 5); whoAmI.LayoutParameters = layParams; } string myName = whoFrom.FirstName + " " + whoFrom.LastName; if (numberInConversation != 1) { myName += string.Format (" and {0} other{1}", numberInConversation == 2 ? "1" : (numberInConversation - 1).ToString (), numberInConversation == 2 ? "." : "s."); } whoAmI.SetTextColor (Android.Graphics.Color.Black); whoAmI.Text = myName; whoAmI.SetTextSize (Android.Util.ComplexUnitType.Dip, 12f); RunOnUiThread (() => topLayout.AddView (whoAmI)); LinearLayout messageLayout = new LinearLayout (context); using (LinearLayout.LayoutParams linParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.FillParent)) { linParams.Weight = 80f; messageLayout.LayoutParameters = linParams; } messageLayout.Orientation = Orientation.Horizontal; TextView txtMessage = new TextView (context); using (LinearLayout.LayoutParams linParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, (int)ImageHelper.convertDpToPixel(70f, context))) { linParams.SetMargins (0, 0, (int)ImageHelper.convertDpToPixel (8f, context), 0); txtMessage.LayoutParameters = linParams; } txtMessage.SetPadding ((int)ImageHelper.convertDpToPixel (10f, context), (int)ImageHelper.convertDpToPixel (5f, context), (int)ImageHelper.convertDpToPixel (10f, context), (int)ImageHelper.convertDpToPixel (5f, context)); if (latestMessage.MessageStepDBList.Count == 1 && latestMessage.MessageStepDBList [0].StepType == MessageStep.StepTypes.Text) { txtMessage = messageTextBox (latestMessage, 0, leftOver); } else { for (int n = 0; n < latestMessage.MessageStepDBList.Count; ++n) { if (latestMessage.MessageStepDBList [n].StepType == MessageStep.StepTypes.Text) { txtMessage = messageTextBox (latestMessage, n, leftOver); break; } } } txtMessage.ContentDescription = latestMessage.MessageID.ToString (); #if DEBUG System.Diagnostics.Debug.WriteLine ("ContentDesctription = {0}, ID = {1}", txtMessage.ContentDescription, latestMessage.ID); #endif txtMessage.Click += textMessage_Click; RunOnUiThread (() => messageLayout.AddView (txtMessage)); LinearLayout bottomLayout = new LinearLayout (context); using (LinearLayout.LayoutParams linParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent)) { linParams.SetMargins (0, (int)ImageHelper.convertDpToPixel (3f, context), 0, 0); bottomLayout.LayoutParameters = linParams; } bottomLayout.SetGravity (GravityFlags.Right); TextView txtMessageUnread = new TextView (context); using (LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, (int)ImageHelper.convertDpToPixel(12f, context))) { layoutParams.SetMargins (10, 0, 10, 0); txtMessageUnread.LayoutParameters = layoutParams; } txtMessageUnread.LayoutParameters = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent); txtMessageUnread.SetTextColor (Color.Black); txtMessageUnread.SetTextSize (Android.Util.ComplexUnitType.Dip, 10f); if (unreadMessages [c] == 0) txtMessageUnread.Text = "0 unread messages."; else txtMessageUnread.Text = string.Format ("({0}) unread message{1}", unreadMessages [c], unreadMessages [c] == 1 ? "." : "s."); txtMessageUnread.Gravity = GravityFlags.Right; RunOnUiThread (() => bottomLayout.AddView (txtMessageUnread)); LinearLayout messageItems = new LinearLayout (context); if (latestMessage.MessageStepDBList.Count > 0) { messageItems.Orientation = Orientation.Horizontal; float messageBarSize = wowZapp.LaffOutOut.Singleton.resizeFonts == true ? ImageHelper.convertPixelToDp (((55f * imageSize [0]) / 100), context) : ImageHelper.convertDpToPixel (40f, context); using (LinearLayout.LayoutParams layParams = new LinearLayout.LayoutParams (leftOver, (int)messageBarSize)) { layParams.SetMargins ((int)ImageHelper.convertDpToPixel (14f, context), (int)ImageHelper.convertDpToPixel (3.3f, context), (int)ImageHelper.convertDpToPixel (12.7f, context), (int)ImageHelper.convertDpToPixel (4f, context)); messageItems.LayoutParameters = layParams; } messageItems.SetPadding ((int)ImageHelper.convertDpToPixel (10f, context), (int)ImageHelper.convertDpToPixel (3.3f, context), (int)ImageHelper.convertDpToPixel (10f, context), 0); messageItems.SetGravity (GravityFlags.Left); messageItems.SetBackgroundResource (Resource.Drawable.attachmentspreviewbkgr); messageItems = createMessageBar (messageItems, latestMessage, leftOver); messageItems.ContentDescription = latestMessage.MessageGuid; messageItems.Click += messageBar_Click; } else { messageItems.Orientation = Orientation.Horizontal; float messageBarSize = wowZapp.LaffOutOut.Singleton.resizeFonts == true ? ImageHelper.convertPixelToDp (((55f * imageSize [0]) / 100), context) : ImageHelper.convertDpToPixel (40f, context); using (LinearLayout.LayoutParams layParams = new LinearLayout.LayoutParams (leftOver, (int)messageBarSize)) { layParams.SetMargins ((int)ImageHelper.convertDpToPixel (14f, context), (int)ImageHelper.convertDpToPixel (3.3f, context), (int)ImageHelper.convertDpToPixel (12.7f, context), (int)ImageHelper.convertDpToPixel (4f, context)); messageItems.LayoutParameters = layParams; messageItems.SetBackgroundResource (Resource.Drawable.attachmentspreviewbkgr); } } RunOnUiThread (delegate { information.AddView (topLayout); if (!string.IsNullOrEmpty (txtMessage.Text)) information.AddView (messageLayout); if (latestMessage.MessageStepDBList.Count > 1) information.AddView (messageItems); information.AddView (bottomLayout); shell.AddView (information); listWrapper.AddView (shell); }); #if DEBUG System.Diagnostics.Debug.WriteLine ("done a loop"); #endif } } if (c < MessageConversations.initialMessages.Count - 2) c++; } //}); if (unknownUsers.Count != 0) { Contacts.AddUnknownUser auu = new Contacts.AddUnknownUser (unknownUsers, context); } if (progress != null) RunOnUiThread (() => progress.Dismiss ()); }
private LinearLayout contactUserInterface(MessageDB message, UserDB contact, bool direction) { LinearLayout layout = new LinearLayout (context); layout.Orientation = Android.Widget.Orientation.Horizontal; layout.SetGravity (GravityFlags.CenterVertical); string messager = ""; layout.SetPadding ((int)ImageHelper.convertDpToPixel (5f, context), 0, (int)ImageHelper.convertDpToPixel (5f, context), (int)ImageHelper.convertDpToPixel (10f, context)); ImageView profilepic = new ImageView (context); if (!direction) { profilepic.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (55f, context), (int)ImageHelper.convertDpToPixel (100f, context)); if (contact == null) profilepic.SetImageDrawable (Application.Context.Resources.GetDrawable (Resource.Drawable.defaultuserimage)); else { profilepic.Tag = new Java.Lang.String ("profilepic_" + contact.AccountID); profilepic.SetImageResource (Resource.Drawable.defaultuserimage); layout.AddView (profilepic); if (contact.Picture.Length == 0 && contact.HasProfileImage) getGuid.Add (contact.AccountID); else { if (contact.Picture.Length > 0) LoadUserImage (contact, profilepic); else profilepic.SetImageDrawable (Application.Context.Resources.GetDrawable (Resource.Drawable.defaultuserimage)); } LinearLayout layout2 = new LinearLayout (context); layout2.Orientation = Orientation.Vertical; layout2.SetGravity (GravityFlags.Center); if (message.MessageStepDBList.Count == 1 && message.MessageStepDBList [0].StepType == MessageStep.StepTypes.Text) { TextView text = new TextView (context); text.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (220f, context), (int)ImageHelper.convertDpToPixel (60f, context)); text.SetPadding ((int)ImageHelper.convertDpToPixel (20f, context), 0, (int)ImageHelper.convertDpToPixel (10f, context), 0); text.Gravity = GravityFlags.CenterVertical; text.SetBackgroundResource (Resource.Drawable.bubblesolidright); text.TextSize = 16f; for (int e = 0; e < message.MessageStepDBList.Count; ++e) { if (!string.IsNullOrEmpty (message.MessageStepDBList [e].MessageText)) { messager = message.MessageStepDBList [e].MessageText; break; } } if (string.IsNullOrEmpty (messager)) messager = "No text message found"; int nolines = (int)(ImageHelper.convertDpToPixel ((messager.Length / 27f) * 12f, context)); text.SetHeight (nolines); text.SetTextColor (Android.Graphics.Color.Black); text.Text = messager; layout2.Clickable = true; layout2.AddView (text); } layout.AddView (layout2); } } else { LinearLayout layout2 = new LinearLayout (context); layout2.Orientation = Orientation.Vertical; layout2.SetGravity (GravityFlags.Center); if (message.MessageStepDBList.Count == 1 && message.MessageStepDBList [0].StepType == MessageStep.StepTypes.Text) { TextView text = new TextView (context); text.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (220f, context), (int)ImageHelper.convertDpToPixel (60f, context)); text.SetPadding ((int)ImageHelper.convertDpToPixel (20f, context), 0, (int)ImageHelper.convertDpToPixel (10f, context), 0); text.Gravity = GravityFlags.CenterVertical; text.SetBackgroundResource (Resource.Drawable.bubblesolidleft); text.TextSize = 16f; for (int e = 0; e < message.MessageStepDBList.Count; ++e) { if (!string.IsNullOrEmpty (message.MessageStepDBList [e].MessageText)) { messager = message.MessageStepDBList [e].MessageText; break; } } if (string.IsNullOrEmpty (messager)) messager = "No text message found"; int nolines = (int)(ImageHelper.convertDpToPixel ((messager.Length / 27f) * 12f, context)); text.SetHeight (nolines); text.SetTextColor (Android.Graphics.Color.Black); text.Text = messager; layout2.Clickable = true; layout2.AddView (text); } profilepic.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (55f, context), (int)ImageHelper.convertDpToPixel (100f, context)); layout.AddView (layout2); if (contact == null) profilepic.SetImageDrawable (Application.Context.Resources.GetDrawable (Resource.Drawable.defaultuserimage)); else { profilepic.Tag = new Java.Lang.String ("profilepic_" + contact.AccountID); profilepic.SetImageResource (Resource.Drawable.defaultuserimage); layout.AddView (profilepic); if (contact.Picture.Length == 0 && contact.HasProfileImage) getGuid.Add (contact.AccountID); else { if (contact.Picture.Length > 0) LoadUserImage (contact, profilepic); else profilepic.SetImageDrawable (Application.Context.Resources.GetDrawable (Resource.Drawable.defaultuserimage)); } } } return layout; }
public Conversations(UserDB userFrom, Context context) { ConversationsUtil.userFrom = userFrom; ConversationsUtil.conversation = null; startActivity (context); }
private void createUI(MessageDB message, UserDB contact) { #if DEBUG System.Diagnostics.Debug.WriteLine ("AccoundID (MC) = {0}", AndroidData.CurrentUser.AccountID.ToString ()); #endif int m = 0; string messager = ""; if (message != null && contact != null) { RunOnUiThread (delegate { ImageView random = null; LinearLayout layout = new LinearLayout (context); layout.Orientation = Android.Widget.Orientation.Horizontal; layout.SetGravity (GravityFlags.CenterVertical); layout.SetPadding ((int)ImageHelper.convertDpToPixel (10f, context), 0, (int)ImageHelper.convertDpToPixel (10f, context), (int)ImageHelper.convertDpToPixel (10f, context)); ImageView profilepic = new ImageView (context); profilepic.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (60f, context), (int)ImageHelper.convertDpToPixel (100f, context)); profilepic.Tag = new Java.Lang.String ("profilepic_" + m.ToString ()); if (contact == null) profilepic.SetImageDrawable (Application.Context.Resources.GetDrawable (Resource.Drawable.defaultuserimage)); else { if (contact.Picture.Length > 0) { //profilepic.SetImageDrawable(Android.Graphics.Drawables.Drawable.CreateFromStream(new MemoryStream(eachContact.ContactUser.Picture), "Profile")); loadProfilePicture (contact.AccountID); } else { profilepic.SetImageDrawable (Application.Context.Resources.GetDrawable (Resource.Drawable.defaultuserimage)); } //layout.AddView(profilepic); LinearLayout layout2 = new LinearLayout (context); layout2.Orientation = Orientation.Vertical; layout2.SetGravity (GravityFlags.Center); TextView name = new TextView (context); name.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (260f, context), (int)ImageHelper.convertDpToPixel (40f, context)); name.Gravity = GravityFlags.Center; name.SetTextColor (Color.White); name.TextSize = 16f; name.Text = contact.FirstName + " " + contact.LastName; layout2.AddView (name); TextView text = new TextView (context); text.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (240f, context), (int)ImageHelper.convertDpToPixel (60f, context)); text.SetPadding ((int)ImageHelper.convertDpToPixel (10f, context), 0, (int)ImageHelper.convertDpToPixel (10f, context), 0); text.Gravity = GravityFlags.CenterVertical; if (name.Text == isMe) text.SetBackgroundResource (Resource.Drawable.bubblesolidright); else text.SetBackgroundResource (Resource.Drawable.bubblesolidleft); text.TextSize = 16f; for (int e = 0; e < message.MessageStepDBList.Count; ++e) { if (!string.IsNullOrEmpty (message.MessageStepDBList [e].MessageText)) { messager = message.MessageStepDBList [e].MessageText; break; } } if (string.IsNullOrEmpty (messager)) messager = "No text message found"; int nolines = messager.Length / 27; text.SetHeight ((nolines + 1) * 20); text.SetTextColor (Android.Graphics.Color.Black); text.Text = messager; layout2.Clickable = true; layout2.AddView (text); if (message.MessageStepDBList.Count > 1) { LinearLayout layout3 = new LinearLayout (context); layout3.Orientation = Orientation.Horizontal; if (name.Text == isMe) layout3.SetGravity (GravityFlags.Right); else layout3.SetGravity (GravityFlags.Left); layout3.SetBackgroundResource (Resource.Drawable.attachmentspreviewbkgr); layout3.SetVerticalGravity (GravityFlags.CenterVertical); layout3.SetMinimumHeight (30); layout3.SetPadding ((int)ImageHelper.convertDpToPixel (10f, context), 0, (int)ImageHelper.convertDpToPixel (10f, context), 0); if (name.Text != isMe) { random = new ImageView (context); random.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (30f, context), (int)ImageHelper.convertDpToPixel (30f, context)); random.SetBackgroundResource (Resource.Drawable.playblack); //random.Click += delegate { PlayMessage(message); }; layout3.AddView (random); } for (int i = 1; i < message.MessageStepDBList.Count; ++i) { switch (message.MessageStepDBList [i].StepType) { case LOLMessageDelivery.MessageStep.StepTypes.Animation: random = new ImageView (context); random.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (30f, context), (int)ImageHelper.convertDpToPixel (30f, context)); random.SetBackgroundResource (Resource.Drawable.drawicon); layout3.AddView (random); break; case LOLMessageDelivery.MessageStep.StepTypes.Comicon: random = new ImageView (context); random.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (30f, context), (int)ImageHelper.convertDpToPixel (30f, context)); random.SetBackgroundResource (Resource.Drawable.comicon); layout3.AddView (random); break; case LOLMessageDelivery.MessageStep.StepTypes.Comix: random = new ImageView (context); random.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (30f, context), (int)ImageHelper.convertDpToPixel (30f, context)); random.SetBackgroundResource (Resource.Drawable.comicmsgs); layout3.AddView (random); break; case LOLMessageDelivery.MessageStep.StepTypes.Emoticon: random = new ImageView (context); random.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (30f, context), (int)ImageHelper.convertDpToPixel (30f, context)); random.SetBackgroundResource (Resource.Drawable.emoticonmsg); layout3.AddView (random); break; case LOLMessageDelivery.MessageStep.StepTypes.Polling: random = new ImageView (context); random.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (30f, context), (int)ImageHelper.convertDpToPixel (30f, context)); random.SetBackgroundResource (Resource.Drawable.pollmsg); layout3.AddView (random); break; case LOLMessageDelivery.MessageStep.StepTypes.SoundFX: random = new ImageView (context); random.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (30f, context), (int)ImageHelper.convertDpToPixel (30f, context)); random.SetBackgroundResource (Resource.Drawable.soundfxmsg); layout3.AddView (random); break; case LOLMessageDelivery.MessageStep.StepTypes.Video: random = new ImageView (context); random.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (30f, context), (int)ImageHelper.convertDpToPixel (30f, context)); random.SetBackgroundResource (Resource.Drawable.videomsg); layout3.AddView (random); break; case LOLMessageDelivery.MessageStep.StepTypes.Voice: random = new ImageView (context); random.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (30f, context), (int)ImageHelper.convertDpToPixel (30f, context)); random.SetBackgroundResource (Resource.Drawable.voicemsg); layout3.AddView (random); break; } } if (name.Text == isMe) { random = new ImageView (context); random.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (30f, context), (int)ImageHelper.convertDpToPixel (30f, context)); random.SetBackgroundResource (Resource.Drawable.playblack); //random.Click += delegate { PlayMessage(message); }; layout3.AddView (random); } layout2.AddView (layout3); } if (name.Text != isMe) { layout.AddView (profilepic); layout.AddView (layout2); } else { layout.AddView (layout2); layout.AddView (profilepic); } converse.AddView (layout); m++; } }); } }
private void LoadUserImage(UserDB user, ImageView profilePic) { RunOnUiThread (delegate { if (user.Picture.Length == 0) profilePic.SetImageResource (Resource.Drawable.defaultuserimage); else using (Bitmap img = ImageHelper.CreateUserProfileImageForDisplay(user.Picture, this.thumbImageWidth, this.thumbImageHeight, this.Resources)) { profilePic.SetImageBitmap (img); }//end using }); }
private void LoadUserImage(UserDB user, ImageView profilePic) { if (user.Picture.Length == 0) RunOnUiThread (() => profilePic.SetImageResource (Resource.Drawable.defaultuserimage)); else using (Bitmap img = ImageHelper.CreateUserProfileImageForDisplay(user.Picture, (int)imageSize[0], (int)imageSize[0], this.Resources)) { RunOnUiThread (() => profilePic.SetImageBitmap (img)); }//end using }
private void CreateMessagesUI() { List<UserDB> participants = new List<UserDB> (); bool moreThanOne = false, isCurrentMe = false; if (MessageConversations.clearView) { listWrapper.RemoveAllViews (); MessageConversations.clearView = false; } if (Contacts.SelectContactsUtil.selectedContacts.Count != 0) Contacts.SelectContactsUtil.selectedContacts.Clear (); if (MessageConversations.currentConversationMessages [0].MessageRecipientDBList.Count > 1) { moreThanOne = true; for (int m = 0; m < MessageConversations.currentConversationMessages[0].MessageRecipientDBList.Count; ++m) { if (MessageConversations.currentConversationMessages [0].MessageRecipientDBList [m].AccountGuid != AndroidData.CurrentUser.AccountID.ToString ()) { UserDB userDetails = dbm.GetUserWithAccountID (MessageConversations.currentConversationMessages [0].MessageRecipientDBList [m].AccountGuid); participants.Add (userDetails); ContactDB contact = new ContactDB (); contact.ContactUser = new LOLAccountManagement.User (); contact.ContactUser.AccountID = userDetails.AccountID; Contacts.SelectContactsUtil.selectedContacts.Add (contact); } else { UserDB userDetails = UserDB.ConvertFromUser (AndroidData.CurrentUser); participants.Add (userDetails); } } } else { UserDB userDetails = dbm.GetUserWithAccountID (MessageConversations.currentConversationMessages [0].MessageRecipientDBList [0].AccountGuid); ContactDB contact = new ContactDB (); contact.ContactUser = new LOLAccountManagement.User (); contact.ContactUser.AccountID = userDetails.AccountID; Contacts.SelectContactsUtil.selectedContacts.Add (contact); } if (moreThanOne) { string toReturn = ""; List<UserDB> sortedList = new List<UserDB> (); sortedList = participants.OrderBy (s => s.LastName).OrderBy (s => s.FirstName).ToList (); foreach (UserDB eachItem in sortedList) toReturn += string.Format ("{0} {1}, ", eachItem.FirstName, eachItem.LastName); int last = toReturn.LastIndexOf (", "); toReturn = toReturn.Remove (last); using (LinearLayout btnlayout = new LinearLayout (context)) { btnlayout.Orientation = Android.Widget.Orientation.Vertical; btnlayout.SetGravity (GravityFlags.Center); btnlayout.LayoutParameters = new ViewGroup.LayoutParams (LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent); btnlayout.SetPadding ((int)ImageHelper.convertDpToPixel (5f, context), 0, (int)ImageHelper.convertDpToPixel (5f, context), (int)ImageHelper.convertDpToPixel (10f, context)); using (TextView name = new TextView(context)) { name.Text = toReturn; name.SetTextSize (Android.Util.ComplexUnitType.Dip, 18f); name.SetTextColor (Color.Black); RunOnUiThread (() => btnlayout.AddView (name)); } using (Button showAll = new Button (context)) { showAll.Gravity = GravityFlags.CenterVertical; showAll.Text = Application.Context.Resources.GetString (Resource.String.messageShowAllInConversation); showAll.Click += (object sender, EventArgs e) => { showParticipants (sender, e, participants); }; showAll.SetWidth ((int)ImageHelper.convertDpToPixel (180f, context)); showAll.SetHeight ((int)ImageHelper.convertDpToPixel (30f, context)); showAll.SetBackgroundResource (Resource.Drawable.button); RunOnUiThread (() => btnlayout.AddView (showAll)); } RunOnUiThread (() => listWrapper.AddView (btnlayout)); } } foreach (MessageDB message in MessageConversations.currentConversationMessages) { isCurrentMe = message.FromAccountID != AndroidData.CurrentUser.AccountID ? false : true; LinearLayout shell = new LinearLayout (context); shell.LayoutParameters = new ViewGroup.LayoutParams (LinearLayout.LayoutParams.FillParent, (int)ImageHelper.convertDpToPixel (imageSize [0] + 50f, context)); shell.Orientation = Orientation.Horizontal; shell.SetPadding (0, 0, 0, (int)ImageHelper.convertDpToPixel (5f, context)); UserDB whoAmI = new UserDB (); whoAmI = message.FromAccountID != AndroidData.CurrentUser.AccountID ? dbm.GetUserWithAccountID (message.FromAccountGuid) : UserDB.ConvertFromUser (AndroidData.CurrentUser); LinearLayout imageViewLayout = new LinearLayout (context); imageViewLayout.LayoutParameters = new ViewGroup.LayoutParams (LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent); imageViewLayout.SetGravity (GravityFlags.CenterVertical); ImageView userImage = new ImageView (context); if (Contacts.ContactsUtil.contactFilenames.Contains (message.FromAccountGuid)) { using (Bitmap bm = BitmapFactory.DecodeFile (System.IO.Path.Combine (wowZapp.LaffOutOut.Singleton.ImageDirectory, message.FromAccountGuid))) { using (MemoryStream ms = new MemoryStream ()) { bm.Compress (Bitmap.CompressFormat.Jpeg, 80, ms); byte[] image = ms.ToArray (); using (Bitmap myBitmap = ImageHelper.CreateUserProfileImageForDisplay(image, (int)imageSize[0], (int)imageSize[1], this.Resources)) { RunOnUiThread (delegate { userImage.SetImageBitmap (myBitmap); }); } } } } else { userImage.LayoutParameters = new ViewGroup.LayoutParams ((int)ImageHelper.convertDpToPixel (imageSize [0], context), (int)ImageHelper.convertDpToPixel (imageSize [1], context)); userImage.SetScaleType (ImageView.ScaleType.FitXy); userImage.SetImageResource (Resource.Drawable.defaultuserimage); } RunOnUiThread (() => imageViewLayout.AddView (userImage)); LinearLayout messageShell = new LinearLayout (context); int left = (int)wowZapp.LaffOutOut.Singleton.ScreenXWidth - (int)ImageHelper.convertDpToPixel (imageSize [0] + 20f, context); int leftOver = (int)wowZapp.LaffOutOut.Singleton.ScreenXWidth - (int)ImageHelper.convertDpToPixel (imageSize [0] + 40f, context); messageShell.LayoutParameters = new ViewGroup.LayoutParams (!isCurrentMe ? LinearLayout.LayoutParams.FillParent : left, LinearLayout.LayoutParams.FillParent); messageShell.Orientation = Orientation.Vertical; LinearLayout from = new LinearLayout (context); using (LinearLayout.LayoutParams layParms = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, (int)ImageHelper.convertDpToPixel(24f, context))) { layParms.SetMargins (isCurrentMe ? 0 : (int)ImageHelper.convertDpToPixel (30f, context), 0, isCurrentMe ? (int)ImageHelper.convertDpToPixel (30f, context) : 0, 0); layParms.Weight = 10f; from.LayoutParameters = layParms; } TextView whoIsIt = new TextView (context); whoIsIt.SetTextColor (Color.Black); whoIsIt.SetTextSize (Android.Util.ComplexUnitType.Dip, 12f); whoIsIt.Gravity = !isCurrentMe ? GravityFlags.Left : GravityFlags.Right; whoIsIt.Text = whoAmI.FirstName + " " + whoAmI.LastName; RunOnUiThread (() => from.AddView (whoIsIt)); LinearLayout messageBox = new LinearLayout (context); using (LinearLayout.LayoutParams linParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.FillParent)) { messageBox.LayoutParameters = linParams; linParams.Weight = 60f; } for (int m = 0; m < message.MessageStepDBList.Count; ++m) { if (message.MessageStepDBList [m].StepType == LOLMessageDelivery.MessageStep.StepTypes.Text) { TextView messageText = new TextView (context); using (LinearLayout.LayoutParams layParam = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.FillParent)) { messageText.LayoutParameters = layParam; } messageText.SetBackgroundResource (message.FromAccountID != AndroidData.CurrentUser.AccountID ? Resource.Drawable.bubblesolidleft : Resource.Drawable.bubblesolidright); int lr = (int)ImageHelper.convertDpToPixel (20f, context); int tb = lr / 2; messageText.SetPadding (lr, tb, lr, tb); messageText.SetTextColor (Color.White); messageText.SetTextSize (Android.Util.ComplexUnitType.Dip, 14f); string messager = message.MessageStepDBList [m].MessageText; if (messager.Length > 40) messager = messager.Substring (0, 40) + "..."; messageText.Text = messager; messageText.ContentDescription = message.MessageGuid; RunOnUiThread (() => messageBox.AddView (messageText)); break; } } LinearLayout messageLay = new LinearLayout (context); using (LinearLayout.LayoutParams messParam = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, (int)ImageHelper.convertDpToPixel(24f, context))) { messParam.SetMargins (isCurrentMe ? 0 : (int)ImageHelper.convertDpToPixel (30f, context), 0, isCurrentMe ? (int)ImageHelper.convertDpToPixel (30f, context) : 0, 0); messParam.Weight = 10f; messageLay.LayoutParameters = messParam; } TextView messageDate = new TextView (context); messageDate.LayoutParameters = new ViewGroup.LayoutParams (LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent); messageDate.SetTextColor (Color.Black); messageDate.SetTextSize (Android.Util.ComplexUnitType.Dip, 10f); messageDate.Gravity = message.FromAccountID != AndroidData.CurrentUser.AccountID ? GravityFlags.Left : GravityFlags.Right; messageDate.Text = message.MessageSent.ToShortTimeString () + ", " + message.MessageSent.ToShortDateString (); RunOnUiThread (() => messageLay.AddView (messageDate)); LinearLayout messageItems = new LinearLayout (context); messageItems.Orientation = Orientation.Horizontal; float messageBarSize = wowZapp.LaffOutOut.Singleton.resizeFonts == true ? ImageHelper.convertPixelToDp (((50f * imageSize [0]) / 100), context) : ImageHelper.convertDpToPixel (40f, context); using (LinearLayout.LayoutParams layParams = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.FillParent, (int)messageBarSize)) { layParams.SetMargins ((int)ImageHelper.convertDpToPixel (14f, context), (int)ImageHelper.convertDpToPixel (3.3f, context), (int)ImageHelper.convertDpToPixel (12.7f, context), (int)ImageHelper.convertDpToPixel (4f, context)); messageItems.LayoutParameters = layParams; } messageItems.SetPadding ((int)ImageHelper.convertDpToPixel (10f, context), (int)ImageHelper.convertDpToPixel (3.3f, context), (int)ImageHelper.convertDpToPixel (10f, context), 0); messageItems.SetGravity (GravityFlags.Left); messageItems = createMessageBar (messageItems, message, leftOver); RunOnUiThread (delegate { messageShell.AddView (from); messageShell.AddView (messageBox); messageShell.AddView (messageLay); messageShell.AddView (messageItems); if (whoAmI.AccountID == AndroidData.CurrentUser.AccountID) { shell.AddView (messageShell); shell.AddView (imageViewLayout); } else { shell.AddView (imageViewLayout); shell.AddView (messageShell); } listWrapper.AddView (shell); }); } if (progress != null) RunOnUiThread (() => progress.Dismiss ()); }