Esempio n. 1
0
        public ContactPage(MessageNode node, long friendAccountId, short keyIndex = -1, Chat chat = null) : base("ContactPage")
        {
            Subscribe <ProfileDataResultEvent>(ProfileData);
            Subscribe <UnfriendEvent>(Unfriend);

            _node            = node;
            _chat            = chat;
            _friendAccountId = friendAccountId;
            _friendKeyIndex  = keyIndex;

            AddTitleRow("Title");

            if (!_self)
            {
                if (_chat == null)
                {
                    var friend     = node.GetFriend(friendAccountId);
                    var invitation = node.GetInvitation(friendAccountId);

                    if (invitation != null)
                    {
                        AddHeaderRow("PendingInvitation");

                        if (invitation.HasFriendAccountApproval)
                        {
                            var row = AddButtonRow("ApproveButton", Approve);
                            row.SetDetailViewIcon(Icons.UserPlus);
                            row.Tag = invitation;
                        }

                        if (invitation.HasAccountApproval)
                        {
                            var row = AddButtonRow("AwaitingApprovalButton", Awaiting);
                            row.SetDetailViewIcon(Icons.UserClock);
                            row.Tag = invitation;
                        }

                        AddInfoRow("PendingInvitationInfo");
                        AddFooterRow();
                    }

                    if (friend == null && invitation == null)
                    {
                        AddHeaderRow("Invitation");

                        var b = AddButtonRow("InviteButton", Invite);
                        b.SetDetailViewIcon(Icons.UserPlus);
                        AddInfoRow("InvitationInfo");

                        AddFooterRow();
                    }

                    var chats = _node.GetChats(_friendAccountId);
                    if (chats.Count > 0)
                    {
                        AddHeaderRow("Chats");

                        foreach (var c in chats)
                        {
                            var b = AddButtonRow(Time.DateTimeString(c.LastTimestamp), OpenChat);
                            b.SetDetailViewIcon(Icons.Comments);
                            b.Tag = c;
                        }

                        AddFooterRow();
                    }

                    if (friend != null)
                    {
                        AddHeaderRow("Misc");

                        var button = AddButtonRow("Unfriend", Unfriend);
                        button.RowStyle = Theme.CancelButton;
                        button.SetDetailViewIcon(Icons.UserSlash);

                        AddFooterRow();
                    }
                }
                else
                {
                    AddHeaderRow("NofificationHeader");

                    var _notification = AddSwitchRow("Notification");
                    _notification.Switch.IsToggled    = UIApp.Current.IsPushChannelSubscribed(_chat.Index);
                    _notification.Switch.ToggledAsync = Notification_Toggled;
                    _notification.SetDetailViewIcon(Icons.Bell);

                    AddFooterRow();


                    AddHeaderRow("Misc");

                    var button = AddButtonRow("ViewInboxes", ViewInboxes);
                    button.SetDetailViewIcon(Icons.Inbox);

                    button = AddButtonRow("ManageSecretKeys", ManageSecretKeys);
                    button.SetDetailViewIcon(Icons.Key);

                    button = AddButtonRow("RemoveChat", RemoveChat);
                    button.SetDetailViewIcon(Icons.CommentSlash);

                    button          = AddButtonRow("Unfriend", Unfriend);
                    button.RowStyle = Theme.CancelButton;
                    button.SetDetailViewIcon(Icons.UserSlash);

                    AddFooterRow();
                }
            }
            else
            {
                AddHeaderRow("Misc");

                AddButtonRow("InboxesPage.Inboxes", Inboxes).SetDetailViewIcon(Icons.Inbox);

                if (UIApp.CanShare)
                {
                    var b = AddButtonRow("Share", Share);
                    b.SetDetailViewIcon(Icons.Share);
                }
                var button = AddButtonRow("Copy", Copy);
                button.SetDetailViewIcon(Icons.Copy);

                AddFooterRow();
            }

            IsBusy = true;
            UIApp.Run(Update);
        }
Esempio n. 2
0
        async Task Update()
        {
            await ProfileManager.Current.GetProfileData(_friendAccountId, ProfileDownloadType.DownloadIfNotAvailable, true);

            if (_chat == null)
            {
                AddIndex       = GetRow("Misc");
                AddIndexBefore = true;
                AddIndex       = AddHeaderRow("SelectInbox");
                AddIndexBefore = false;

                var result = await _node.DownloadInboxRecords(_friendAccountId);

                if (result.Result == MessageNodeEventResultTypes.Ok)
                {
                    SelectionItem <InboxNameRecordInfo> keyIndexItem = null;
                    var list = new SelectionItemList <InboxNameRecordInfo>();

                    foreach (var item in result.InboxRecords)
                    {
                        var selectionItem = new SelectionItem <InboxNameRecordInfo>(item, null);
                        list.Add(selectionItem);
                        if (item.KeyIndex == _friendKeyIndex)
                        {
                            keyIndexItem = selectionItem;
                        }
                    }

                    if (keyIndexItem != null)
                    {
                        list.Clear();
                        list.Add(keyIndexItem);
                    }

                    var row = AddSelectionRows(list, list[0].Key);
                    row.SelectionChanged = InboxChanged;

                    foreach (var button in row.Buttons)
                    {
                        var item = button.Tag as SelectionItem <InboxNameRecordInfo>;

                        var inboxName = item.Key.InboxRecord?.Title;
                        if (inboxName == null)
                        {
                            inboxName = Tr.Get("Common.Inbox");
                        }

                        button.SetMultilineText(inboxName, Tr.Get("Common.InboxName", _friendAccountId, item.Key.KeyIndex));
                        button.SetDetailViewIcon(Icons.Inbox);
                    }

                    AddIndex = row.Buttons[row.Buttons.Count - 1];
                    AddIndex = AddInfoRow("SelectInboxInfo");
                    var f = AddFooterRow();
                    f.Identifier = "SelectInboxFooter";

                    var friend = _node.GetFriend(_friendAccountId);
                    if (friend != null)
                    {
                        await InboxChanged(list[0].Key);
                    }
                }
                else
                {
                    if (result.Result == MessageNodeEventResultTypes.InvalidAccount)
                    {
                        AddIndex = AddInfoRow("InvalidAccount");
                    }
                    else
                    {
                        AddIndex = AddInfoRow("DownloadFailed");
                    }

                    var f = AddFooterRow();
                    f.Identifier = "SelectInboxFooter";
                }
            }

            IsBusy = false;
        }