public void OnItemClick(View view, GetUserMessagesObject.Message obj, int pos) { try { if (MAdapter.GetSelectedItemCount() > 0) // Add Select New Item { EnableActionMode(pos); } else { if (Timer != null) { Timer.Enabled = true; Timer.Start(); } if (TopChatToolBar.Visibility != ViewStates.Visible) { TopChatToolBar.Visibility = ViewStates.Visible; } } } catch (Exception e) { Console.WriteLine(e); } }
public void Update(GetUserMessagesObject.Message messages) { try { var checker = MessageList.FirstOrDefault(a => a.Id == messages.Id); if (checker != null) { checker.Id = messages.Id; checker.FromId = messages.FromId; checker.ToId = messages.ToId; checker.Text = messages.Text; checker.MediaFile = messages.MediaFile; checker.MediaType = messages.MediaType; checker.DeletedFs1 = messages.DeletedFs1; checker.DeletedFs2 = messages.DeletedFs2; checker.Seen = messages.Seen; checker.Time = messages.Time; checker.Extra = messages.Extra; checker.TimeText = messages.TimeText; checker.Position = messages.Position; ActivityContext.RunOnUiThread(() => { NotifyItemChanged(MessageList.IndexOf(checker)); ActivityContext.ChatBoxRecylerView.ScrollToPosition(MessageList.IndexOf(MessageList.Last())); }); } } catch (Exception e) { Console.WriteLine(e); } }
//Send Message type => "right_text" private void OnClick_OfSendButton() { try { UnixTimestamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; var time2 = UnixTimestamp.ToString(); string timeNow = DateTime.Now.ToString("hh:mm"); if (string.IsNullOrEmpty(EmojiconEditTextView.Text)) { } else { //Here on This function will send Text Messages to the user //remove \n in a string string replacement = Regex.Replace(EmojiconEditTextView.Text, @"\t|\n|\r", ""); if (Methods.CheckConnectivity()) { GetUserMessagesObject.Message message = new GetUserMessagesObject.Message { Id = UnixTimestamp, FromId = int.Parse(UserDetails.UserId), ToId = Userid, Text = replacement, MediaFile = "", MediaType = "", DeletedFs1 = "", DeletedFs2 = "", Seen = "0", Time = time2, Extra = "", TimeText = timeNow, Position = "Right", }; MAdapter.Add(message); UserDataObject userData = ConvertData(); MessageController.SendMessageTask(Userid, EmojiconEditTextView.Text, time2, userData).ConfigureAwait(false); } else { ToastUtils.ShowToast(GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short); } EmojiconEditTextView.Text = ""; } ChatSendButton.Tag = "Text"; ChatSendButton.SetImageResource(Resource.Drawable.SendLetter); } catch (Exception e) { Console.WriteLine(e); } }
public static void UpdateOneMessage(GetUserMessagesObject.Message message) { try { MAdapter.Update(message); } catch (Exception e) { Console.WriteLine(e); } }
public void RemoveData(int position, GetUserMessagesObject.Message users) { try { Remove(users); ResetCurrentItems(); } catch (Exception e) { Console.WriteLine(e); } }
public void Initialize(TextViewHolder holder, GetUserMessagesObject.Message item) { try { if (holder.Time.Text != item.Time) { var time = Methods.Time.UnixTimeStampToDateTime(Convert.ToInt32(item.Time)); holder.Time.Text = time.ToShortTimeString(); holder.TextSanitizerAutoLink.Load(item.Text, item.Position); } } catch (Exception e) { Console.WriteLine(e); } }
public void Remove(GetUserMessagesObject.Message users) { try { var index = MessageList.IndexOf(MessageList.FirstOrDefault(a => a.Id == users.Id)); if (index != -1) { MessageList.Remove(users); NotifyItemRemoved(index); NotifyItemRangeRemoved(0, ItemCount); } } catch (Exception e) { Console.WriteLine(e); } }
// Function public void Add(GetUserMessagesObject.Message item) { try { var check = MessageList.FirstOrDefault(a => a.Id == item.Id); if (check == null) { MessageList.Add(item); NotifyItemInserted(MessageList.IndexOf(MessageList.Last())); //Scroll Down >> ActivityContext.ChatBoxRecylerView.ScrollToPosition(MessageList.IndexOf(MessageList.Last())); } } catch (Exception exception) { Console.WriteLine(exception); } }
private string LoadMoreMessagesDatabase() { try { SqLiteDatabase dbDatabase = new SqLiteDatabase(); var localList = dbDatabase.GetMessageList(UserDetails.UserId, Userid, FirstMessageId); if (localList?.Count > 0) //Database.. Get Messages Local { localList = new List <DataTables.MessageTb>(localList.OrderByDescending(a => a.Id)); foreach (var messages in localList) { GetUserMessagesObject.Message m = new GetUserMessagesObject.Message { Id = messages.Id, FromId = messages.FromId, ToId = messages.ToId, Text = messages.Text, Seen = messages.Seen, Time = messages.Time, FromDeleted = messages.FromDeleted, ToDeleted = messages.ToDeleted, TextTime = messages.TextTime, Position = messages.Position, }; MAdapter.Insert(m, FirstMessageId); } dbDatabase.Dispose(); return("1"); } else { dbDatabase.Dispose(); return("0"); } } catch (Exception e) { Console.WriteLine(e); return("0"); } }
public void Insert(GetUserMessagesObject.Message message, int firstId) { try { var check = MessageList.FirstOrDefault(a => a.Id == message.Id); if (check == null) { MessageList.Insert(0, message); NotifyItemInserted(MessageList.IndexOf(MessageList.FirstOrDefault())); var index = MessageList.FirstOrDefault(a => a.Id == firstId); if (index != null) { NotifyItemChanged(MessageList.IndexOf(index)); //Scroll Down >> ActivityContext.ChatBoxRecylerView.ScrollToPosition(MessageList.IndexOf(index)); } } } catch (Exception e) { Console.WriteLine(e); } }
private async Task <string> LoadMoreMessagesApi() { try { if (!Methods.CheckConnectivity()) { SwipeRefreshLayout.Refreshing = false; Toast.MakeText(this, Resource.String.Lbl_CheckYourInternetConnection, ToastLength.Long).Show(); } else { var(apiStatus, respond) = await RequestsAsync.Messages.GetUserMessages(Userid, "30", FirstMessageId).ConfigureAwait(false); if (apiStatus == 200) { if (respond is GetUserMessagesObject result) { if (result.data.Messages.Count > 0) { var listApi = new ObservableCollection <GetUserMessagesObject.Message>(); foreach (var messages in result.data.Messages.OrderBy(a => a.Time)) { GetUserMessagesObject.Message message = new GetUserMessagesObject.Message { Id = messages.Id, FromId = messages.FromId, ToId = messages.ToId, Text = messages.Text, Seen = messages.Seen, Time = messages.Time, FromDeleted = messages.FromDeleted, ToDeleted = messages.ToDeleted, TextTime = messages.TextTime, Position = messages.Position, }; MAdapter.Insert(message, FirstMessageId); listApi.Insert(0, message); SqLiteDatabase dbDatabase = new SqLiteDatabase(); // Insert data user in database dbDatabase.InsertOrReplaceMessages(listApi); dbDatabase.Dispose(); } return("1"); } return("0"); } } else { Methods.DisplayReportResult(this, respond); } } return("0"); } catch (Exception exception) { Console.WriteLine(exception); return("0"); } }
public void OnItemLongClick(View view, GetUserMessagesObject.Message obj, int pos) { EnableActionMode(pos); }
public static void UpdateLastIdMessage(SendMessageObject.Data messages, UserDataObject userData) { try { var checker = MessagesBoxActivity.MAdapter.MessageList.FirstOrDefault(a => a.Id == messages.HashId); if (checker != null) { checker.Id = messages.Id; checker.FromId = messages.FromId; checker.ToId = messages.ToId; checker.Text = messages.Text; checker.Seen = messages.Seen; checker.Time = messages.Time; checker.FromDeleted = messages.FromDeleted; checker.ToDeleted = messages.ToDeleted; checker.TextTime = messages.TextTime; checker.Position = "Right"; var dataUser = LastChatActivity.MAdapter?.UserList?.FirstOrDefault(a => a.User.Id == messages.ToId); if (dataUser != null) { dataUser.GetLastMessage.Text = messages.Text; var index = LastChatActivity.MAdapter.UserList?.IndexOf(LastChatActivity.MAdapter.UserList?.FirstOrDefault(x => x.User.Id == messages.ToId)); if (index > -1) { LastChatActivity.MAdapter.Move(dataUser); LastChatActivity.MAdapter.Update(dataUser); } } else { if (userData != null) { LastChatActivity.MAdapter?.Insert(new GetChatsObject.Data() { Id = userData.Id, UserOne = "0", UserTwo = "0", Time = messages.Time, TextTime = messages.TextTime, User = userData, GetCountSeen = "0", GetLastMessage = new GetChatsObject.GetLastMessage() { Id = messages.Id, FromId = messages.FromId, ToId = messages.ToId, Text = messages.Text, Seen = messages.Seen, Time = messages.Time, FromDeleted = messages.FromDeleted, ToDeleted = messages.ToDeleted, TextTime = messages.TextTime, }, }); } } SqLiteDatabase dbDatabase = new SqLiteDatabase(); GetUserMessagesObject.Message message = new GetUserMessagesObject.Message { Id = messages.Id, FromId = messages.FromId, ToId = messages.ToId, Text = messages.Text, Seen = messages.Seen, Time = messages.Time, FromDeleted = messages.FromDeleted, ToDeleted = messages.ToDeleted, TextTime = messages.TextTime, Position = "Right", }; //Update All data users to database dbDatabase.InsertOrUpdateToOneMessages(message); dbDatabase.Dispose(); MessagesBoxActivity.UpdateOneMessage(message); if (AppSettings.RunSoundControl) { Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Popup_SendMesseges.mp3"); } } } catch (Exception e) { Console.WriteLine(e); } }
public static void UpdateLastIdMessage(SendMessageObject.Data messages, UserDataObject userData) { try { var checker = MessagesBoxActivity.MAdapter.MessageList.FirstOrDefault(a => a.Id == Convert.ToInt32(messages.HashId)); if (checker != null) { checker.Id = messages.Id; checker.FromId = messages.FromId; checker.ToId = messages.ToId; checker.Text = messages.Text; checker.MediaFile = messages.MediaFile; checker.MediaType = messages.MediaType; checker.DeletedFs1 = messages.DeletedFs1; checker.DeletedFs2 = messages.DeletedFs2; checker.Seen = messages.Seen; checker.Time = messages.Time; checker.Extra = messages.Extra; checker.TimeText = messages.TimeText; checker.Position = "Right"; var dataUser = LastChatActivity.MAdapter.UserList?.FirstOrDefault(a => a.UserId == messages.ToId); if (dataUser != null) { dataUser.LastMessage = messages.Text; var index = LastChatActivity.MAdapter.UserList?.IndexOf(LastChatActivity.MAdapter.UserList?.FirstOrDefault(x => x.UserId == messages.ToId)); if (index > -1) { LastChatActivity.MAdapter.Move(dataUser); LastChatActivity.MAdapter.Update(dataUser); } } else { if (userData != null) { LastChatActivity.MAdapter.Insert(new GetChatsObject.Data() { UserId = checker.ToId, Username = userData.Username, Avatar = userData.Avatar, Time = userData.LastSeen, LastMessage = messages.Text, NewMessage = 0, TimeText = checker.TimeText, UserData = userData, }); } } SqLiteDatabase dbDatabase = new SqLiteDatabase(); GetUserMessagesObject.Message message = new GetUserMessagesObject.Message { Id = messages.Id, FromId = messages.FromId, ToId = messages.ToId, Text = messages.Text, MediaFile = messages.MediaFile, MediaType = messages.MediaType, DeletedFs1 = messages.DeletedFs1, DeletedFs2 = messages.DeletedFs2, Seen = messages.Seen, Time = messages.Time, Extra = messages.Extra, TimeText = messages.TimeText, Position = "Right", }; //Update All data users to database dbDatabase.InsertOrUpdateToOneMessages(message); dbDatabase.Dispose(); MessagesBoxActivity.UpdateOneMessage(message); if (AppSettings.RunSoundControl) { Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Popup_SendMesseges.mp3"); } } } catch (Exception e) { Console.WriteLine(e); } }