Пример #1
0
        private void CheckForDateHeader(FizzUIMessage action)
        {
            bool shouldAddHeaderModel = false;

            if (_lastAction == null)
            {
                shouldAddHeaderModel = true;
                _lastAction          = action;
            }
            else
            {
                DateTime last = Utils.GetDateTimeToUnixTime(_lastAction.Created);
                last = last.Date;
                DateTime current = Utils.GetDateTimeToUnixTime(action.Created);
                TimeSpan ts      = current.Subtract(last);
                if (ts.Days > 0)
                {
                    shouldAddHeaderModel = true;
                }
                _lastAction = action;
            }

            if (shouldAddHeaderModel)
            {
                UIChatCellModel model = new UIChatCellModel();
                model.Action = action;
                model.Type   = UIChatCellModel.UIChatCellModelType.DateHeader;

                _chatCellModelList.Add(model);
            }
        }
Пример #2
0
        public int GetItemType(int index)
        {
            UIChatActionType actionType;
            UIChatCellModel  model = _chatCellModelList[index];

            if (model.Type == UIChatCellModel.UIChatCellModelType.ChatAction)
            {
                FizzUIMessage lastAction = null;
                FizzUIMessage nextAction = null;
                FizzUIMessage chatAction = _chatCellModelList[index].Action;

                int lastIndex = index - 1;
                while (lastIndex > -1)
                {
                    if (_chatCellModelList[lastIndex].Type == UIChatCellModel.UIChatCellModelType.ChatAction)
                    {
                        lastAction = _chatCellModelList[lastIndex].Action;
                        break;
                    }
                    lastIndex--;
                }

                int nextIndex = index + 1;
                while (nextIndex < _chatCellModelList.Count)
                {
                    if (_chatCellModelList[nextIndex].Type == UIChatCellModel.UIChatCellModelType.ChatAction)
                    {
                        nextAction = _chatCellModelList[nextIndex].Action;
                        break;
                    }
                    nextIndex++;
                }

                string senderId = chatAction.From;

                bool             ownMessage = _userId.Equals(senderId);
                UIChatActionType cellType   = UIChatActionType.TheirsMessageAction;

                cellType = ownMessage ? UIChatActionType.YoursMessageAction : UIChatActionType.TheirsMessageAction;

                if (!ownMessage && lastAction != null && chatAction.From.Equals(lastAction.From))
                {
                    cellType = UIChatActionType.TheirsRepeatMessageAction;
                }
                // else if (ownMessage && nextAction != null && chatAction.From.Equals (nextAction.From)) {
                //     cellType = UIChatActionType.YoursRepeatMessageAction;
                // }

                actionType = cellType;
            }
            else
            {
                actionType = UIChatActionType.DateHeader;
            }

            return((int)actionType);
        }
Пример #3
0
        /// <summary>
        /// Set the data to populate ChatCellView.
        /// </summary>
        /// <param name="model">FIZZChatMessageAction. Please see <see cref="FIZZ.Actions.IFIZZChatMessageAction"/></param>
        public override void SetData(FizzUIMessage model, bool appTranslationEnabled)
        {
            base.SetData(model, appTranslationEnabled);

            nickLabel.text  = _model.Nick;
            nickLabel.color = Utils.GetUserNickColor(_model.From);

            LoadChatMessageAction();
        }
Пример #4
0
        private UIChatCellModel GetActionFromLookup(FizzUIMessage action)
        {
            UIChatCellModel model = null;

            if (!string.IsNullOrEmpty(action.AlternateId.ToString()) && _actionsLookUpDict.ContainsKey(action.AlternateId.ToString()))
            {
                _actionsLookUpDict.TryGetValue(action.AlternateId.ToString(), out model);
            }
            else if (!string.IsNullOrEmpty(action.Id.ToString()) && _actionsLookUpDict.ContainsKey(action.Id.ToString()))
            {
                _actionsLookUpDict.TryGetValue(action.Id.ToString(), out model);
            }
            return(model);
        }
Пример #5
0
 private void AddActionInLookup(UIChatCellModel model)
 {
     if (model.Type == UIChatCellModel.UIChatCellModelType.ChatAction)
     {
         FizzUIMessage action = model.Action;
         if (!string.IsNullOrEmpty(action.Id.ToString()) && !_actionsLookUpDict.ContainsKey(action.Id.ToString()))
         {
             _actionsLookUpDict.Add(action.Id.ToString(), model);
         }
         else if (!string.IsNullOrEmpty(action.AlternateId.ToString()) && !_actionsLookUpDict.ContainsKey(action.AlternateId.ToString()))
         {
             _actionsLookUpDict.Add(action.AlternateId.ToString(), model);
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Set the data to populate ChatCellView.
        /// </summary>
        /// <param name="model">FIZZChatMessageAction. Please see <see cref="FIZZ.Actions.IFIZZChatMessageAction"/></param>
        public virtual void SetData(FizzUIMessage model, bool appTranslationEnabled)
        {
            _model = model;
            _appTranslationEnabled = appTranslationEnabled;

            if (timeLabel != null)
            {
                DateTime dt         = Utils.GetDateTimeToUnixTime(_model.Created);
                string   timeFormat = string.Format("{0:h:mm tt}", dt);
                timeLabel.text = timeFormat;
            }

            if (customNode != null)
            {
                customNode.DestroyChildren();
                customNode.gameObject.SetActive(false);
            }
        }
Пример #7
0
        public GameObject GetListItem(int index, int itemType, GameObject obj)
        {
            if (obj == null)
            {
                switch (itemType)
                {
                case (int)UIChatActionType.YoursMessageAction:
                    obj = Instantiate(rightCellView.gameObject);
                    break;

                case (int)UIChatActionType.YoursRepeatMessageAction:
                    obj = Instantiate(rightRepeatCellView.gameObject);
                    break;

                case (int)UIChatActionType.TheirsMessageAction:
                    obj = Instantiate(leftCellView.gameObject);
                    break;

                case (int)UIChatActionType.TheirsRepeatMessageAction:
                    obj = Instantiate(leftRepeatCellView.gameObject);
                    break;

                case (int)UIChatActionType.DateHeader:
                    obj = Instantiate(dateHeaderCellView.gameObject);
                    break;
                }
            }

            UIChatCellModel model = _chatCellModelList[index];

            if (model.Type == UIChatCellModel.UIChatCellModelType.ChatAction)
            {
                FizzUIMessage  action       = model.Action;
                UIChatCellView chatCellView = obj.GetComponent <UIChatCellView> ();
                chatCellView.rowNumber = index;
                chatCellView.SetData(action, _isAppTranslationEnabled);

                if (itemType == (int)UIChatActionType.TheirsMessageAction)
                {
                    var leftCell = chatCellView as UILeftChatCellView;
                    leftCell.onTranslateTogglePressed = OnTranslateToggleClicked;
                }
                else if (itemType == (int)UIChatActionType.TheirsRepeatMessageAction)
                {
                    var leftRepeatCell = chatCellView as UILeftRepeatChatCellView;
                    leftRepeatCell.onTranslateTogglePressed = OnTranslateToggleClicked;
                }

                if (action.Data != null)
                {
                    RectTransform customView = null;
                    if (_chatDataSource != null)
                    {
                        customView = _chatDataSource.GetCustomMessageDrawable(action);
                        if (customView != null)
                        {
                            chatCellView.SetCustomData(customView);
                        }
                    }
                }
            }
            else if (model.Type == UIChatCellModel.UIChatCellModelType.DateHeader)
            {
                UIChatDateHeaderCellView dateHeader = obj.GetComponent <UIChatDateHeaderCellView> ();
                dateHeader.SetData(model.Action, _isAppTranslationEnabled);
            }

            return(obj);
        }
Пример #8
0
        /// <summary>
        /// Set the data to populate ChatCellView.
        /// </summary>
        /// <param name="model">FIZZChatMessageAction. Please see <see cref="FIZZ.Actions.IFIZZChatMessageAction"/></param>
        public override void SetData(FizzUIMessage model, bool appTranslationEnabled)
        {
            base.SetData(model, appTranslationEnabled);

            LoadChatMessageAction();
        }
        /// <summary>
        /// Set the data to populate ChatCellView.
        /// </summary>
        /// <param name="model">FIZZChatMessageAction. Please see <see cref="FIZZ.Actions.IFIZZChatMessageAction"/></param>
        public override void SetData(FizzUIMessage model, bool appTranslationEnabled)
        {
            base.SetData(model, appTranslationEnabled);

            messageLabel.text = Utils.GetFormattedTimeForUnixTimeStamp(_model.Created);
        }