Exemple #1
0
        private void SendProcess()
        {
            try
            {
                if (!string.IsNullOrEmpty(txtMsg.Text))
                {
                    var msgTime = StaticMethods.TimeAgo(DateTime.Now);
                    if (items != null)
                    {
                        //var time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt");

                        items.Items.Add(new ChatModel.Datum
                        {
                            name        = _productModel.name,
                            message     = txtMsg.Text,
                            Incoming    = false,
                            Outgoing    = true,
                            MessageTime = msgTime
                        });
                    }
                    else
                    {
                        _chatModel = new ChatModel();
                        var list = new List <ChatModel.Datum>();
                        list.Add(new ChatModel.Datum
                        {
                            name        = _productModel.name,
                            message     = txtMsg.Text,
                            Incoming    = false,
                            Outgoing    = true,
                            MessageTime = msgTime
                        });
                        _chatModel.data = list;
                        items           = new ChatItemList(_chatModel.data);
                        flowlistview.FlowItemsSource = items.Items;
                    }
                    var lastItem = flowlistview.FlowItemsSource.OfType <object>().Last();
                    flowlistview.ScrollTo(lastItem, ScrollToPosition.End, false);

                    SendMessage(txtMsg.Text, Convert.ToDouble(_productModel.price)).Wait();
                    txtMsg.Text = string.Empty;
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #2
0
        private async Task GetAllChatMessages()
        {
            string ret = string.Empty;

            Task.Factory.StartNew(
                // tasks allow you to use the lambda syntax to pass wor
                () =>
            {
                _chatModel = WebService.GetAllChatMessage(Convert.ToInt32(_productModel.user_id), Convert.ToInt32(_productModel.product_id));
            }).ContinueWith(async
                            t =>
            {
                try
                {
                    if (_chatModel.data != null)
                    {
                        for (int i = 0; i < _chatModel.data.Count; i++)
                        {
                            if (!string.IsNullOrEmpty(_chatModel.data[i].profile_pic))
                            {
                                _chatModel.data[i].profile_pic = Constants.ProfilePicUrl + _chatModel.data[i].profile_pic;
                            }
                            else
                            {
                                _chatModel.data[i].profile_pic = "dummyprofile.png";
                            }
                            if (_chatModel.data[i].sender_id == StaticDataModel.userId.ToString())
                            {
                                _chatModel.data[i].Outgoing = true;
                                _chatModel.data[i].Incoming = false;
                            }
                            else
                            {
                                _chatModel.data[i].Outgoing = false;
                                _chatModel.data[i].Incoming = true;
                            }
                            if (!string.IsNullOrEmpty(_chatModel.data[i].created_at))
                            {
                                var t1 = Convert.ToDateTime(_chatModel.data[i].created_at);

                                if (!isFromLocal)
                                {
                                    t1 = DateTime.SpecifyKind(t1, DateTimeKind.Utc);
                                    t1 = t1.ToLocalTime();
                                }
                                _chatModel.data[i].MessageTime = StaticMethods.TimeAgo(Convert.ToDateTime(t1));
                            }
                        }

                        items = new ChatItemList(_chatModel.data);
                        flowlistview.FlowItemsSource = items.Items;
                        var lastItem = flowlistview.FlowItemsSource.OfType <object>().Last();
                        flowlistview.ScrollTo(lastItem, ScrollToPosition.End, false);
                    }
                }
                catch (Exception ex)
                {
                }
            }, TaskScheduler.FromCurrentSynchronizationContext()
                            );
        }
Exemple #3
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            txtMsg.Focused       += TxtMsg_Focused;
            txtMsg.Unfocused     += TxtMsg_Unfocused;
            txtMsg.Completed     += TxtMsg_Completed;
            btnYes.Clicked       += BtnYes_Clicked;
            btnNo.Clicked        += BtnNo_Clicked;
            btnAccept.Clicked    += BtnAccept_Clicked;
            btnRefuse.Clicked    += BtnRefuse_Clicked;
            btnOk.Clicked        += BtnOk_Clicked;
            btnCash.Clicked      += BtnCash_Clicked;
            btnOnline.Clicked    += BtnOnline_Clicked;
            btnMakeOffer.Clicked += BtnMakeOffer_Clicked;

            txtMsg.Focused += (sender, e) =>
            {
                //flowlistviewOverlay.IsVisible = true;
            };
            txtMsg.Unfocused += (sender, e) =>
            {
                //flowlistviewOverlay.IsVisible = false;
            };

            TapGestureRecognizer flowlistviewTapGesture = new TapGestureRecognizer();

            flowlistviewTapGesture.Command = new Command(() =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    txtMsg.Unfocus();
                    ChatEntry.keepOpen = false;
                });
            });
            flowlistview.GestureRecognizers.Add(flowlistviewTapGesture);
            stackContent.GestureRecognizers.Add(flowlistviewTapGesture);
            //stackScrollContent.GestureRecognizers.Add(flowlistviewTapGesture);
            //flowlistviewOverlay.GestureRecognizers.Add(flowlistviewTapGesture);

            flowlistview.FlowItemTapped += (sender, e) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    txtMsg.Unfocus();
                    ChatEntry.keepOpen = false;
                });
            };

            if (fromPage == "make_offer")
            {
                if (isFirstLoad)
                {
                    await SaveChatUser();
                }
            }
            else if (fromPage == "user_list")
            {
                if (isFirstLoad)
                {
                    GetAllChatMessages().Wait();
                }
            }
            else if (fromPage == "private_chat")
            {
                if (isFirstLoad)
                {
                    GetAllChatMessages().Wait();
                }
            }

            MessagingCenter.Subscribe <object, ChatModel.Datum>(this, "NotificationRecieved", (sender, model) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    if (!ReferenceEquals(model, null))
                    {
                        if (string.Equals(model.type, "chat"))
                        {
                            model.Incoming = true;
                            if (!string.IsNullOrEmpty(model.profile_pic))
                            {
                                model.profile_pic = Constants.ProfilePicUrl + model.profile_pic;
                            }
                            var t1 = Convert.ToDateTime(model.created_at);
                            if (!isFromLocal)
                            {
                                t1 = DateTime.SpecifyKind(t1, DateTimeKind.Utc);
                                t1 = t1.ToLocalTime();
                            }
                            model.MessageTime = StaticMethods.TimeAgo(Convert.ToDateTime(t1));
                            if (items != null)
                            {
                                //var time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt");

                                items.Items.Add(model);
                            }
                            else
                            {
                                _chatModel = new ChatModel();
                                var list   = new List <ChatModel.Datum>();
                                list.Add(model);
                                _chatModel.data = list;
                                items           = new ChatItemList(_chatModel.data);
                                flowlistview.FlowItemsSource = items.Items;
                            }
                            var lastItem = flowlistview.FlowItemsSource.OfType <object>().Last();
                            flowlistview.ScrollTo(lastItem, ScrollToPosition.End, false);
                        }
                        else
                        {
                            offer_status = model.status;
                            UpdateOfferStatus().Wait();
                        }
                        lblPrice.Text = model.offer_price;
                    }
                });
            });
        }