Exemplo n.º 1
0
        private void MAdapterOnItemLongClick(object sender, Holders.MesClickEventArgs e)
        {
            try
            {
                if (e.Position > -1)
                {
                    SelectedItemPositions = MAdapter.GetItem(e.Position);
                    if (SelectedItemPositions != null)
                    {
                        var arrayAdapter = new List <string>();
                        var dialogList   = new MaterialDialog.Builder(this).Theme(AppSettings.SetTabDarkTheme ? AFollestad.MaterialDialogs.Theme.Dark : AFollestad.MaterialDialogs.Theme.Light);

                        if (e.Type == Holders.TypeClick.Text)
                        {
                            arrayAdapter.Add(GetText(Resource.String.Lbl_Copy));
                        }

                        if (SelectedItemPositions.MesData.Position == "right")
                        {
                            arrayAdapter.Add(GetText(Resource.String.Lbl_MessageInfo));
                            arrayAdapter.Add(GetText(Resource.String.Lbl_DeleteMessage));
                        }

                        arrayAdapter.Add(GetText(Resource.String.Lbl_Forward));
                        arrayAdapter.Add(SelectedItemPositions.MesData.IsStarted ? GetText(Resource.String.Lbl_UnFavorite) : GetText(Resource.String.Lbl_Favorite));

                        dialogList.Items(arrayAdapter);
                        dialogList.PositiveText(GetText(Resource.String.Lbl_Close)).OnPositive(this);
                        dialogList.AlwaysCallSingleChoiceCallback();
                        dialogList.ItemsCallback(this).Build().Show();
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 2
0
        public static void UpdateLastIdMessage(SendMessageObject chatMessages)
        {
            try
            {
                foreach (var messageInfo in chatMessages.MessageData)
                {
                    MessageData m = new MessageData
                    {
                        Id             = messageInfo.Id,
                        FromId         = messageInfo.FromId,
                        GroupId        = messageInfo.GroupId,
                        ToId           = messageInfo.ToId,
                        Text           = messageInfo.Text,
                        Media          = messageInfo.Media,
                        MediaFileName  = messageInfo.MediaFileName,
                        MediaFileNames = messageInfo.MediaFileNames,
                        Time           = messageInfo.Time,
                        Seen           = messageInfo.Seen,
                        DeletedOne     = messageInfo.DeletedOne,
                        DeletedTwo     = messageInfo.DeletedTwo,
                        SentPush       = messageInfo.SentPush,
                        NotificationId = messageInfo.NotificationId,
                        TypeTwo        = messageInfo.TypeTwo,
                        Stickers       = messageInfo.Stickers,
                        TimeText       = messageInfo.TimeText,
                        Position       = messageInfo.Position,
                        ModelType      = messageInfo.ModelType,
                        FileSize       = messageInfo.FileSize,
                        MediaDuration  = messageInfo.MediaDuration,
                        MediaIsPlaying = messageInfo.MediaIsPlaying,
                        ContactNumber  = messageInfo.ContactNumber,
                        ContactName    = messageInfo.ContactName,
                        ProductId      = messageInfo.ProductId,
                        MessageUser    = messageInfo.MessageUser,
                        Product        = messageInfo.Product,
                        MessageHashId  = messageInfo.MessageHashId,
                        Lat            = messageInfo.Lat,
                        Lng            = messageInfo.Lng,
                        SendFile       = false,
                    };

                    var typeModel = Holders.GetTypeModel(m);
                    if (typeModel == MessageModelType.None)
                    {
                        continue;
                    }

                    var message = WoWonderTools.MessageFilter(messageInfo.ToId, m, typeModel, true);
                    message.ModelType = typeModel;

                    AdapterModelsClassUser checker = WindowActivity?.MAdapter?.DifferList?.FirstOrDefault(a => a.MesData.Id == messageInfo.MessageHashId);
                    if (checker != null)
                    {
                        //checker.TypeView = typeModel;
                        checker.MesData  = message;
                        checker.Id       = Java.Lang.Long.ParseLong(message.Id);
                        checker.TypeView = typeModel;

                        checker.MesData.Id             = message.Id;
                        checker.MesData.FromId         = message.FromId;
                        checker.MesData.GroupId        = message.GroupId;
                        checker.MesData.ToId           = message.ToId;
                        checker.MesData.Text           = message.Text;
                        checker.MesData.Media          = message.Media;
                        checker.MesData.MediaFileName  = message.MediaFileName;
                        checker.MesData.MediaFileNames = message.MediaFileNames;
                        checker.MesData.Time           = message.Time;
                        checker.MesData.Seen           = message.Seen;
                        checker.MesData.DeletedOne     = message.DeletedOne;
                        checker.MesData.DeletedTwo     = message.DeletedTwo;
                        checker.MesData.SentPush       = message.SentPush;
                        checker.MesData.NotificationId = message.NotificationId;
                        checker.MesData.TypeTwo        = message.TypeTwo;
                        checker.MesData.Stickers       = message.Stickers;
                        checker.MesData.TimeText       = message.TimeText;
                        checker.MesData.Position       = message.Position;
                        checker.MesData.ModelType      = message.ModelType;
                        checker.MesData.FileSize       = message.FileSize;
                        checker.MesData.MediaDuration  = message.MediaDuration;
                        checker.MesData.MediaIsPlaying = message.MediaIsPlaying;
                        checker.MesData.ContactNumber  = message.ContactNumber;
                        checker.MesData.ContactName    = message.ContactName;
                        checker.MesData.ProductId      = message.ProductId;
                        checker.MesData.MessageUser    = message.MessageUser;
                        checker.MesData.Product        = message.Product;
                        checker.MesData.MessageHashId  = message.MessageHashId;
                        checker.MesData.Lat            = message.Lat;
                        checker.MesData.Lng            = message.Lng;
                        checker.MesData.SendFile       = false;

                        if (AppSettings.LastChatSystem == SystemApiGetLastChat.New)
                        {
                            var updaterUser = GlobalContext?.LastChatTab?.MAdapter?.ChatList?.FirstOrDefault(a => a.UserId == message.ToId);
                            if (updaterUser != null)
                            {
                                var index = GlobalContext.LastChatTab.MAdapter.ChatList.IndexOf(GlobalContext.LastChatTab.MAdapter.ChatList.FirstOrDefault(x => x.UserId == message.ToId));
                                if (index > -1)
                                {
                                    updaterUser.LastMessage.LastMessageClass.Text = typeModel switch
                                    {
                                        MessageModelType.RightGif => WindowActivity?.GetText(Resource.String.Lbl_SendGifFile),
                                        MessageModelType.RightText => !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : WindowActivity?.GetText(Resource.String.Lbl_SendMessage),
                                        MessageModelType.RightSticker => WindowActivity?.GetText(Resource.String.Lbl_SendStickerFile),
                                        MessageModelType.RightContact => WindowActivity?.GetText(Resource.String.Lbl_SendContactnumber),
                                        MessageModelType.RightFile => WindowActivity?.GetText(Resource.String.Lbl_SendFile),
                                        MessageModelType.RightVideo => WindowActivity?.GetText(Resource.String.Lbl_SendVideoFile),
                                        MessageModelType.RightImage => WindowActivity?.GetText(Resource.String.Lbl_SendImageFile),
                                        MessageModelType.RightAudio => WindowActivity?.GetText(Resource.String.Lbl_SendAudioFile),
                                        MessageModelType.RightMap => WindowActivity?.GetText(Resource.String.Lbl_SendLocationFile),
                                        _ => updaterUser.LastMessage.LastMessageClass.Text
                                    };

                                    GlobalContext.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastChatTab?.MAdapter?.ChatList.Move(index, 0);
                                            GlobalContext?.LastChatTab?.MAdapter?.NotifyItemMoved(index, 0);
                                            GlobalContext?.LastChatTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });

                                    SqLiteDatabase dbSqLite = new SqLiteDatabase();
                                    //Update All data users to database
                                    dbSqLite.Insert_Or_Update_LastUsersChat(GlobalContext, new ObservableCollection <ChatObject>()
                                    {
                                        updaterUser
                                    });
                                    dbSqLite.Dispose();
                                }
                            }
                            else
                            {
                                //insert new user
                                var data = ConvertData(checker.MesData);
                                if (data != null)
                                {
                                    GlobalContext?.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastChatTab.MAdapter.ChatList.Insert(0, data);
                                            GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(0);
                                            GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(GlobalContext.LastChatTab.MAdapter.ChatList.IndexOf(data));
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });

                                    //Update All data users to database
                                    //dbDatabase.Insert_Or_Update_LastUsersChat(new ObservableCollection<GetUsersListObject.User>
                                    //{
                                    //    data
                                    //});
                                }
                            }
                        }
                        else
                        {
                            var updaterUser = GlobalContext?.LastMessagesTab?.MAdapter?.MLastMessagesUser?.FirstOrDefault(a => a.UserId == message.ToId);
                            if (updaterUser != null)
                            {
                                var index = GlobalContext.LastMessagesTab.MAdapter.MLastMessagesUser.IndexOf(GlobalContext.LastMessagesTab.MAdapter.MLastMessagesUser.FirstOrDefault(x => x.UserId == message.ToId));
                                if (index > -1)
                                {
                                    updaterUser.LastMessage.Text = typeModel switch
                                    {
                                        MessageModelType.RightGif => WindowActivity?.GetText(Resource.String.Lbl_SendGifFile),
                                        MessageModelType.RightText => !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : WindowActivity?.GetText(Resource.String.Lbl_SendMessage),
                                        MessageModelType.RightSticker => WindowActivity?.GetText(Resource.String.Lbl_SendStickerFile),
                                        MessageModelType.RightContact => WindowActivity?.GetText(Resource.String.Lbl_SendContactnumber),
                                        MessageModelType.RightFile => WindowActivity?.GetText(Resource.String.Lbl_SendFile),
                                        MessageModelType.RightVideo => WindowActivity?.GetText(Resource.String.Lbl_SendVideoFile),
                                        MessageModelType.RightImage => WindowActivity?.GetText(Resource.String.Lbl_SendImageFile),
                                        MessageModelType.RightAudio => WindowActivity?.GetText(Resource.String.Lbl_SendAudioFile),
                                        MessageModelType.RightMap => WindowActivity?.GetText(Resource.String.Lbl_SendLocationFile),
                                        _ => updaterUser.LastMessage.Text
                                    };

                                    GlobalContext.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastMessagesTab?.MAdapter?.MLastMessagesUser.Move(index, 0);
                                            GlobalContext?.LastMessagesTab?.MAdapter?.NotifyItemMoved(index, 0);
                                            GlobalContext?.LastMessagesTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });
                                    SqLiteDatabase dbSqLite = new SqLiteDatabase();
                                    //Update All data users to database
                                    dbSqLite.Insert_Or_Update_LastUsersChat(GlobalContext, new ObservableCollection <GetUsersListObject.User>()
                                    {
                                        updaterUser
                                    });
                                    dbSqLite.Dispose();
                                }
                            }
                            else
                            {
                                //insert new user
                                var data = ConvertDataChat(checker.MesData);
                                if (data != null)
                                {
                                    GlobalContext?.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastMessagesTab?.MAdapter.MLastMessagesUser.Insert(0, data);
                                            GlobalContext?.LastMessagesTab?.MAdapter.NotifyItemInserted(0);
                                            GlobalContext?.LastMessagesTab?.MRecycler.ScrollToPosition(GlobalContext.LastMessagesTab.MAdapter.MLastMessagesUser.IndexOf(data));
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });

                                    //Update All data users to database
                                    //dbDatabase.Insert_Or_Update_LastUsersChat(new ObservableCollection<GetUsersListObject.User>
                                    //{
                                    //    data
                                    //});
                                }
                            }
                        }

                        //checker.Media = media;
                        //Update All data users to database
                        SqLiteDatabase dbDatabase = new SqLiteDatabase();
                        dbDatabase.Insert_Or_Update_To_one_MessagesTable(checker.MesData);
                        dbDatabase.Dispose();

                        GlobalContext?.RunOnUiThread(() =>
                        {
                            try
                            {
                                //Update data RecyclerView Messages.
                                if (message.ModelType != MessageModelType.RightSticker || message.ModelType != MessageModelType.RightImage || message.ModelType != MessageModelType.RightMap || message.ModelType != MessageModelType.RightVideo)
                                {
                                    WindowActivity?.Update_One_Messages(checker.MesData);
                                }

                                if (SettingsPrefFragment.SSoundControl)
                                {
                                    Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Popup_SendMesseges.mp3");
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                        });
                    }
                }

                Datauser     = null;
                DataUserChat = null;
                UserData     = null;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }