Пример #1
0
        private static string GetDisplayDateTime(Context context, long milli)
        {
            var date = new Date(milli);

            if (SendBirdUtils.GetCurrentTimeMills() - milli < 60 * 60 * 24 * 1000L)
            {
                return(DateFormat.GetTimeFormat(context).Format(date));
            }

            return(DateFormat.GetDateFormat(context).Format(date) + " " + DateFormat.GetTimeFormat(context).Format(date));
        }
Пример #2
0
 public bool CheckTypeStatus()
 {
     foreach (var key in mTypeStatus.Keys)
     {
         long ts = mTypeStatus [key];
         if (SendBirdUtils.GetCurrentTimeMills() - ts > 10 * 1000L)
         {
             mTypeStatus.Remove(key);
             return(true);
         }
     }
     return(false);
 }
        private static string GetDisplayTimeOrDate(Context context, long milli)
        {
            Date date = new Date(milli);

            if (SendBirdUtils.GetCurrentTimeMills() - milli > 60 * 60 * 24 * 1000L)
            {
                return(DateFormat.GetDateFormat(context).Format(date));
            }
            else
            {
                return(DateFormat.GetTimeFormat(context).Format(date));
            }
        }
Пример #4
0
        private void InitSendBird(Bundle extras)
        {
            mSendBirdInfo = extras;

            String appId    = extras.GetString("appId");
            String uuid     = extras.GetString("uuid");
            String userName = extras.GetString("userName");

            mSyncContext = SynchronizationContext.Current;             // required for api queries

            #region SendBirdEventHandler

            SendBirdEventHandler seh = new SendBirdEventHandler();
            seh.OnConnect         += (sender, e) => {
            };
            seh.OnError           += (sender, e) => {
            };
            seh.OnChannelLeft     += (sender, e) => {
            };
            seh.OnMessageReceived += (sender, e) => {
                SendBirdSDK.MarkAsRead();
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.AddMessageModel(e.Message);
                }, null);
            };
            seh.OnBroadcastMessageReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.AddMessageModel(e.Message);
                }, null);
            };
            seh.OnSystemMessageReceived += (sender, e) => {
                var systemMessage = (SystemMessage)e.Message;
                mSyncContext.Post(delegate {
                    switch (systemMessage.category)
                    {
                    case SystemMessage.CATEGORY_TOO_MANY_MESSAGES:
                        systemMessage.SetMessage("Too many messages. Please try later.");
                        break;

                    case SystemMessage.CATEGORY_MESSAGING_USER_BLOCKED:
                        systemMessage.SetMessage("Blocked.");
                        break;

                    case SystemMessage.CATEGORY_MESSAGING_USER_DEACTIVATED:
                        systemMessage.SetMessage("Deactivated.");
                        break;
                    }

                    mSendBirdMessagingAdapter.AddMessageModel(systemMessage);
                }, null);
            };
            seh.OnFileReceived += (sender, e) => {
            };
            seh.OnReadReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.SetReadStatus(e.ReadStatus.GetUserId(), e.ReadStatus.timestamp);
                }, null);
            };
            seh.OnTypeStartReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.SetTypeStatus(e.TypeStatus.GetUserId(), SendBirdUtils.GetCurrentTimeMills());
                }, null);
            };
            seh.OnTypeEndReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.SetTypeStatus(e.TypeStatus.GetUserId(), 0);
                }, null);
            };
            seh.OnAllDataReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.NotifyDataSetChanged();
                    mSendBirdMessagingFragment.mListView.SetSelection(mSendBirdMessagingAdapter.Count - 1);
                }, null);
            };
            seh.OnMessageDelivery += (sender, e) => {
                if (!e.Sent)
                {
                    mSyncContext.Post(delegate {
                        mSendBirdMessagingFragment.mEtxtMessage.Text = e.Message;
                    }, null);
                }
            };
            seh.OnMessagingStarted += (sender, e) => {
                mSendBirdMessagingAdapter.Clear();
                mSyncContext.Post(delegate {
                    UpdateMessagingChannel(e.MessagingChannel);

                    var channelUrl = e.MessagingChannel.GetUrl();

                    MessageListQuery messageListQuery = SendBirdSDK.QueryMessageList(channelUrl);
                    messageListQuery.OnResult        += (sender_child, e_child) => {
                        // mSyncContext.Post for RunOnUIThread
                        mSyncContext.Post(delegate {
                            foreach (var messageModel in e_child.Messages)
                            {
                                mSendBirdMessagingAdapter.AddMessageModel(messageModel);
                            }

                            mSendBirdMessagingAdapter.NotifyDataSetChanged();
                            mSendBirdMessagingFragment.mListView.SetSelection(30);

                            SendBirdSDK.MarkAsRead(channelUrl);
                            SendBirdSDK.Join(channelUrl);
                            SendBirdSDK.Connect(mSendBirdMessagingAdapter.GetMaxMessageTimestamp());
                        }, null);
                    };
                    messageListQuery.Prev(long.MaxValue, 50);                      // Excute Query
                }, null);
            };
            seh.OnMessagingUpdated += (sender, e) => {
                mSyncContext.Post(delegate {
                    UpdateMessagingChannel(e.MessagingChannel);
                }, null);
            };
            seh.OnMessagingChannelUpdated += (sender, e) => {
                if (mMessagingChannel != null && mMessagingChannel.GetId() == e.MessagingChannel.GetId())
                {
                    mSyncContext.Post(delegate {
                        UpdateMessagingChannel(e.MessagingChannel);
                    }, null);
                }
            };
            seh.OnMentionUpdated += (sender, e) => {
            };

            #endregion

            SendBirdSDK.Init(appId);
            SendBirdSDK.Login(uuid, userName);
            SendBirdSDK.SetEventHandler(seh);
        }