public void AddMatchItem(MatchItem item)
        {
            matchList.Insert(0, item);
            adapter.NotifyDataSetChanged();

            NoMatch.Visibility = ViewStates.Gone;
            NoofMatches.Text   = (matchList.Count == 1) ? "1 " + res.GetString(Resource.String.ChatListMatch) : matchList.Count + " " + res.GetString(Resource.String.ChatListMatches);
        }
        public void AddMatchItem(MatchItem item)
        {
            matchList.Insert(0, item);
            ChatUserListAdapter adapter = new ChatUserListAdapter(matchList);

            ChatUserList.Source = adapter;
            ChatUserList.ReloadData();
            ChatUserList.RowHeight = 101;
            ChatUserList.Delegate  = this;

            NoMatch.Hidden   = true;
            NoofMatches.Text = (matchList.Count == 1) ? "1 " + LangEnglish.ChatListMatch : matchList.Count + " " + LangEnglish.ChatListMatches;
        }
Пример #3
0
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            ChatUserListCell cell = (ChatUserListCell)tableView.DequeueReusableCell("ChatUserListCell");
            MatchItem        item = items[indexPath.Row];

            cell.SeparatorInset = new UIEdgeInsets(0, 0, 0, 0);

            if ((bool)item.Active)
            {
                cell.ContentView.BackgroundColor = UIColor.FromName("ChatTarget");
                cell.activeCell = true;
            }
            else
            {
                cell.ContentView.BackgroundColor = UIColor.FromName("ChatPassive");
                cell.activeCell = false;
            }

            UIImageView imageView = cell.ChatUserListImage;

            ImageCache im = new ImageCache(this);

            im.LoadImage(imageView, item.TargetID.ToString(), item.TargetPicture);

            cell.ChatUserListName.Text = item.TargetName;

            foreach (UILabel label in cell.ChatUserListItems.Subviews)
            {
                label.Text = "";
            }

            int j = 0;

            for (int i = item.Chat.Length - 1; i >= 0; i--)
            {
                string messageItem = item.Chat[i];
                int    sep1Pos     = messageItem.IndexOf('|');
                int    sep2Pos     = messageItem.IndexOf('|', sep1Pos + 1);
                int    sep3Pos     = messageItem.IndexOf('|', sep2Pos + 1);
                int    sep4Pos     = messageItem.IndexOf('|', sep3Pos + 1);
                int    sep5Pos     = messageItem.IndexOf('|', sep4Pos + 1);
                int    senderID    = int.Parse(messageItem.Substring(sep1Pos + 1, sep2Pos - sep1Pos - 1));
                long   readTime    = long.Parse(messageItem.Substring(sep4Pos + 1, sep5Pos - sep4Pos - 1));
                string message     = messageItem.Substring(sep5Pos + 1);

                UILabel label = (UILabel)cell.ChatUserListItems.Subviews[j];
                label.Text = message.Replace(Environment.NewLine, " ");
                j++;
                label.TextColor = UIColor.FromName("PrimaryDark");
                if (senderID != Session.ID)
                {
                    label.Font = UIFont.BoldSystemFontOfSize(14);
                    if (readTime == 0)
                    {
                        label.BackgroundColor = UIColor.FromName("ChatHighlight");
                    }
                    else
                    {
                        label.BackgroundColor = UIColor.FromRGBA(0, 0, 0, 0); //label may remain blue after list reload
                    }
                }
                else
                {
                    label.Font            = UIFont.SystemFontOfSize(14);
                    label.BackgroundColor = UIColor.FromRGBA(0, 0, 0, 0);
                }
            }

            return(cell);
        }
        public override async void ViewWillAppear(bool animated)
        {
            try
            {
                base.ViewWillAppear(animated);

                if (currentMatch is null && Session.CurrentMatch != null)
                {
                    currentMatch = (MatchItem)c.Clone(Session.CurrentMatch);
                }

                SetMenu();

                var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
                UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => {
                    CommonMethods.LogStatic("ChatOne notification authorization granted: " + granted);
                    if (granted)
                    {
                        InvokeOnMainThread(() => {
                            UIApplication.SharedApplication.RegisterForRemoteNotifications();
                        });
                    }
                    else if (bool.Parse(File.ReadAllText(notificationRequestFile)) == true)
                    {
                        InvokeOnMainThread(() => {
                            c.ActionAlert("", LangEnglish.ChatOneEnableNotifications, LangEnglish.DialogYes, LangEnglish.DialogNo, LangEnglish.DialogDontAsk, LangEnglish.DialogGoToSettings, (alert) => {
                                UIApplication.SharedApplication.OpenUrl(new NSUrl("app-settings:"));
                            }, (alert) => {
                            }, (alert) => {
                                File.WriteAllText(notificationRequestFile, "False");
                            }, (alert) => {
                                CommonMethods.OpenPage("SettingsActivity", 1);
                            }, ChatViewProfile);
                        });
                    }
                });

                string responseString;
                if (!(IntentData.senderID is null))
                {
                    responseString = await c.MakeRequest("action=loadmessages&ID=" + Session.ID + "&SessionID=" + Session.SessionID + "&TargetID=" + (int)IntentData.senderID);

                    IntentData.senderID = null;

                    if (responseString.Substring(0, 2) == "OK")
                    {
                        LoadMessages(responseString, false);
                    }
                    else if (responseString == "ERROR_MatchNotFound")                     //user deleted itself while the other was on its standalone page, and now loading chat. Chat remains, but userid does not exist anymore.
                    {
                        Session.SnackMessage = LangEnglish.MatchNotFound;
                        CommonMethods.OpenPage(null, 0);
                    }
                    else
                    {
                        c.ReportError(responseString);
                    }
                }
                else
                {
                    LoadHeader();

                    responseString = await c.MakeRequest("action=loadmessages&ID=" + Session.ID + "&SessionID=" + Session.SessionID + "&MatchID=" + currentMatch.MatchID);

                    if (responseString.Substring(0, 2) == "OK")
                    {
                        LoadMessages(responseString, true);
                    }
                    else
                    {
                        c.ReportError(responseString);
                    }
                }
            }