private void Initialize(Fresvii.AppSteroid.Models.GroupMessage groupMessage, float scaleFactor, float width, FresviiGUIChat frameChat)
        {
            this.transform.parent = frameChat.transform;

            this.GroupMessage = groupMessage;

            this.frameChat = frameChat;

            this.scaleFactor = scaleFactor;

            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                guiStyleText.font = null;

                guiStyleTime.font = null;

                guiStyleUserName.font = null;
            }

            sideSmallMargin *= this.scaleFactor;

            sideLargeMargin *= this.scaleFactor;

            centerMargin *= this.scaleFactor;

            userIconSize *= this.scaleFactor;

            clipImageUserIconOffset *= this.scaleFactor;

            height *= this.scaleFactor;

            imageHeight = ImageHeight * this.scaleFactor;

            imageMargin *= this.scaleFactor;

            userIconOffsetY *= this.scaleFactor;

            guiStyleText.fontSize = (int)(guiStyleText.fontSize * this.scaleFactor);

            guiStyleText.padding = FresviiGUIUtility.RectOffsetScale(guiStyleText.padding, this.scaleFactor);

            guiStyleText.normal.textColor = FresviiGUIColorPalette.GetColor(FresviiGUIColorPalette.ChatBalloonText);

            guiStyleTime.fontSize = (int)(guiStyleTime.fontSize * this.scaleFactor);

            guiStyleTime.normal.textColor = FresviiGUIColorPalette.GetColor(FresviiGUIColorPalette.ChatBalloonText);

            guiStyleUserName.fontSize = (int)(guiStyleUserName.fontSize * this.scaleFactor);

            guiStyleUserName.normal.textColor = FresviiGUIColorPalette.GetColor(FresviiGUIColorPalette.ChatBalloonText);

            guiStyleUserName.padding = FresviiGUIUtility.RectOffsetScale(guiStyleUserName.padding, this.scaleFactor);

            guiContentText = new GUIContent(GroupMessage.Text);

            guiContentTime = new GUIContent(GroupMessage.CreatedAt.ToString("H:mm"));

            Vector2 timeSize = guiStyleTime.CalcSize(guiContentTime);

            texCoodsProgressBar = FresviiGUIColorPalette.GetTextureCoods(FresviiGUIColorPalette.CardProgressBar);

            timePosition.width = timeSize.x;

            timePosition.height = timeSize.y;

            if (!string.IsNullOrEmpty(groupMessage.User.ProfileImageUrl))
                LoadUserIcon(GroupMessage.User.ProfileImageUrl);

            CalcLayout(width);

            balloonAlpha = 0.0f;

            chatBalloonColor = FresviiGUIColorPalette.GetColor(FresviiGUIColorPalette.ChatBalloon);

            iTween.ValueTo(this.gameObject, iTween.Hash("from", 0.0f, "to", 1.0f, "time", 0.5f, "onupdatetarget", this.gameObject, "onupdate", "OnUpdateBalloonAlpha", "oncompletetarget", this.gameObject, "oncomplete", "OnCompleteBalloonAlpha"));
        }
        void OnVideoSelected(Fresvii.AppSteroid.Models.Video video, Texture2D thumbnail)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FASText.Get("Offline"), (del) => { });

                return;
            }

            var item = GameObject.Instantiate(prfbMyMessageCell) as RectTransform;

            contents.AddItem(item);

            AUIGroupMessageCell cell = item.GetComponent<AUIGroupMessageCell>();

            Fresvii.AppSteroid.Models.GroupMessage groupMessage = null;

            //  Create Text message
            groupMessage = new Fresvii.AppSteroid.Models.GroupMessage(FAS.CurrentUser, "", System.DateTime.Now, Fresvii.AppSteroid.Models.GroupMessage.ContentType.Video);

            groupMessage.Video = video;

            FASGroup.SendGroupMessageVideo(Group.Id, video.Id, (_groupMessage, error) =>
            {
                if (error != null)
                {
                    Fresvii.AppSteroid.Util.DialogManager.Instance.SetLabel(FresviiGUIText.Get("OK"), FresviiGUIText.Get("Cancel"), FresviiGUIText.Get("Close"));

                    Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FASText.Get("UnknownError"), (del) => { });

                    RemoveCell(cell);
                }
                else
                {
                    cell.SetGroupMessage(_groupMessage);
                }

                Sort();
            });

            cell.auiMessages = this;

            cell.SetGroupMessage(groupMessage);

            cell.clipImage.SetTexture(thumbnail);

            groupMessageCells.Add(cell);

            cell.gameObject.SetActive(false);

            scrollView.GoToBottom(newMessageTweenDuration);
        }
        void OnInputTextDone(string text)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FASText.Get("Offline"), (del) => { });

                return;
            }

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var item = GameObject.Instantiate(prfbMyMessageCell) as RectTransform;

            contents.AddItem(item);

            AUIGroupMessageCell cell = item.GetComponent<AUIGroupMessageCell>();

            Fresvii.AppSteroid.Models.GroupMessage groupMessage = null;

            //  Create Text message
            groupMessage = new Fresvii.AppSteroid.Models.GroupMessage(FAS.CurrentUser, text, System.DateTime.Now, Fresvii.AppSteroid.Models.GroupMessage.ContentType.Text);

            FASGroup.SendGroupMessage(Group.Id, text, (_groupMessage, error) =>
            {
                if (error != null)
                {
                    Fresvii.AppSteroid.Util.DialogManager.Instance.SetLabel(FresviiGUIText.Get("OK"), FresviiGUIText.Get("Cancel"), FresviiGUIText.Get("Close"));

                    Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FASText.Get("UnknownError"), ( del ) => { });

                    RemoveCell(cell);
                }
                else
                {
                    cell.SetGroupMessage(_groupMessage);
                }

                Sort();
            });

            cell.auiMessages = this;

            cell.SetGroupMessage(groupMessage);

            groupMessageCells.Add(cell);

            cell.gameObject.SetActive(false);

            scrollView.GoToBottom(newMessageTweenDuration);

            auiInputMessage.Clear();
        }
        void OnGetGroups(IList<Fresvii.AppSteroid.Models.Group> groups, Fresvii.AppSteroid.Models.ListMeta meta, Fresvii.AppSteroid.Models.Error error)
        {
            if(loadingSpinner != null && !initialized)
                loadingSpinner.Hide();

            if(loadingSpinner != null && loading)
                loadingSpinner.Hide();

            float addedHeight = 0.0f;

            if (error == null)
            {
                if (groupListMeta == null)
                {
                    groupListMeta = meta;
                }
                else if (groupListMeta.CurrentPage != 1)
                {
                    groupListMeta = meta;
                }

                foreach (Fresvii.AppSteroid.Models.Group group in groups)
                {
                   addedHeight += AddGroup(group);
                }

                if (!initialized)
                {
                    initialized = true;

                    loadingSpinner.Hide();
                }
            }
            else
            {
                if (error.Code == (int)Fresvii.AppSteroid.Models.Error.ErrorCode.CacheNotExists && FASConfig.Instance.logLevel <= FAS.LogLevels.Warning)
                {
                    Debug.LogWarning(error.Detail);
                }
                else if (FASConfig.Instance.logLevel <= FAS.LogLevels.Error)
                {
                    Debug.LogError(error.ToString());
                }
            }

            loading = false;

            if (pullRefleshing)
            {
                if (isPullUp && addedHeight > 0.0f)
                {

                }
                else
                {
                    OnCompletePullReflesh(scrollViewRect, baseRect);
                }
            }

            pullRefleshing = false;

            isPullUp = false;

            Sort();

            if (initialGroupMessage != null)
            {
                foreach (FresviiGUIGroupCard card in groupCards)
                {
                    if (initialGroupMessage.GroupId == card.Group.Id)
                    {
                        this.SetDraw(false);

                        this.Position = new Vector2(-Screen.width, 0.0f);

                        card.GoToGroupChat(false);

                        break;
                    }
                }
            }

            initialGroupMessage = null;

            uint unreadMessageCount = 0;

            foreach (FresviiGUIGroupCard card in groupCards)
            {
                if (card.Group.LatestMessage != null)
                {
                    if (card.Group.LatestMessage.Id != card.Group.LastReadMessageId && card.Group.LatestMessage.User.Id != FAS.CurrentUser.Id)
                    {
                        FresviiGUIManager.Instance.AddUnreadGroupMessageGroupId(card.Group.Id);

                        unreadMessageCount++;
                    }
                }
            }

            if (unreadMessageCount == 0)
            {
                FresviiGUIManager.Instance.ClearUnreadGroupMessageGroupId();
            }
        }
        void LateUpdate()
        {
            if (initialGroupMessage != null)
            {
                foreach (FresviiGUIGroupCard card in groupCards)
                {
                    if (initialGroupMessage.GroupId == card.Group.Id)
                    {
                        this.SetDraw(false);

                        this.Position = new Vector2(-Screen.width, 0.0f);

                        card.GoToGroupChat(false);

                        initialGroupMessage = null;

                        break;
                    }
                }
            }
        }
        IEnumerator AddCommentCoroutine(string comment, Texture2D clipImage, Fresvii.AppSteroid.Models.Video video)
        {
            while (Group == null)
            {
                yield return 1;
            }

            //  Text
            if (!string.IsNullOrEmpty(comment))
            {
                FresviiGUIChatBalloon chatBalloon = ((GameObject)Instantiate(prfbChatBalloon)).GetComponent<FresviiGUIChatBalloon>();

                Fresvii.AppSteroid.Models.GroupMessage groupMessage = new Fresvii.AppSteroid.Models.GroupMessage(FAS.CurrentUser, comment, System.DateTime.Now, Fresvii.AppSteroid.Models.GroupMessage.ContentType.Text);

                chatBalloon.InitByLocal(groupMessage, scaleFactor, Screen.width, this, null);

                chatBalloons.Add(chatBalloon);

                FASGroup.SendGroupMessage(Group.Id, comment, delegate(Fresvii.AppSteroid.Models.GroupMessage _groupMessage, Fresvii.AppSteroid.Models.Error error)
                {
                    if (error != null)
                    {
                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("UnknownError"), delegate(bool del) { });

                        chatBalloons.Remove(chatBalloon);

                        Destroy(chatBalloon);
                    }
                    else
                    {
                        chatBalloon.GroupMessage = _groupMessage;

                        if (OnAddGroupMessage != null)
                        {
                            OnAddGroupMessage(_groupMessage);
                        }
                    }

                    Sort();
                });
            }

            //  Image
            if (clipImage != null && video == null)
            {
                FresviiGUIChatBalloon chatBalloon = ((GameObject)Instantiate(prfbChatBalloon)).GetComponent<FresviiGUIChatBalloon>();

                Fresvii.AppSteroid.Models.GroupMessage groupMessage = new Fresvii.AppSteroid.Models.GroupMessage(FAS.CurrentUser, comment, System.DateTime.Now, Fresvii.AppSteroid.Models.GroupMessage.ContentType.Image);

                chatBalloon.InitByLocal(groupMessage, scaleFactor, Screen.width, this, clipImage);

                chatBalloons.Add(chatBalloon);

                addCommentBottomMenu.ClearClipImage();

                FASGroup.SendGroupMessage(Group.Id, clipImage, delegate(Fresvii.AppSteroid.Models.GroupMessage _groupMessage, Fresvii.AppSteroid.Models.Error error)
                {
                    if (error != null)
                    {
                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("UnknownError"), delegate(bool del) { });

                        chatBalloons.Remove(chatBalloon);

                        Destroy(chatBalloon);

                        if (OnAddGroupMessage != null)
                        {
                            OnAddGroupMessage(_groupMessage);
                        }
                    }
                    else
                    {
                        chatBalloon.GroupMessage = _groupMessage;
                    }
                });
            }

            //  Video
            if (video != null)
            {
                FresviiGUIChatBalloon chatBalloon = ((GameObject)Instantiate(prfbChatBalloon)).GetComponent<FresviiGUIChatBalloon>();

                Fresvii.AppSteroid.Models.GroupMessage groupMessage = new Fresvii.AppSteroid.Models.GroupMessage(FAS.CurrentUser, comment, System.DateTime.Now, Fresvii.AppSteroid.Models.GroupMessage.ContentType.Video);

                chatBalloon.InitByLocal(groupMessage, scaleFactor, Screen.width, this, clipImage);

                chatBalloons.Add(chatBalloon);

                addCommentBottomMenu.ClearClipImage();

                chatBalloon.DataUploadProgressStart();

                FASGroup.SendGroupMessage(Group.Id, video, delegate(Fresvii.AppSteroid.Models.GroupMessage _groupMessage, Fresvii.AppSteroid.Models.Error error)
                {
                    chatBalloon.DataUploadProgressEnd();

                    if (error != null)
                    {
                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("UnknownError"), delegate(bool del) { });

                        chatBalloons.Remove(chatBalloon);

                        Destroy(chatBalloon);

                        if (OnAddGroupMessage != null)
                        {
                            OnAddGroupMessage(_groupMessage);
                        }
                    }
                    else
                    {
                        chatBalloon.GroupMessage = _groupMessage;
                    }
                });
            }

            ScrollToLatestMessage();
        }