Exemplo n.º 1
0
        private void DisplaySecretDetail(Secret s)
        {
            NSError error;
            Analytics.SharedTracker.TrackPageView ("/session", out error);

            var subRoot = new RootElement (s.Phrase)
            {
                (shareSection = new Section ("Keep on server (1 min)") {
                    (pickPhoto = new StyledStringElement ("Photo", delegate { ShowImagePicker(); })),
                    (dataEntry = new AdvancedEntryElement ("Text", "your message", null))}),
                (entriesSection = new Section ("History"))
            };

            pickPhoto.Accessory = UITableViewCellAccessory.DisclosureIndicator;
            dataEntry.ShouldReturn += delegate {
                UIApplication.SharedApplication.InvokeOnMainThread (delegate {
                    dataEntry.GetContainerTableView ().EndEditing (true);
                }
                );

                server.Send (dataEntry.Value.Trim ());

                return true;
            };
            dataEntry.ReturnKeyType = UIReturnKeyType.Send;

            entriesSection.Elements.AddRange (
                from d in s.DataItems
                select ((Element)CreateDataItemElement (d))
                );

            subRoot.UnevenRows = true;

            sectionDVC = new StyledDialogViewController (
                subRoot,
                true,
                null,
                backgroundColor
                );
            sectionDVC.HidesBottomBarWhenPushed = false;
            navigation.SetNavigationBarHidden (false, true);
            navigation.PushViewController (sectionDVC, true);

            server.CurrentSecret = s;
            currentSecret = s;
            server.Listen ();

            currentSecret.WatchEvent += (secret) => {
                int count = secret.ListenersCount - 1;
                string pattern = "Keep on server (1 min)";
                if (count > 0) {
                    pattern = (count) > 1 ? "Share with {0} devices" : "Share with {0} device";
                }
                UIApplication.SharedApplication.InvokeOnMainThread (delegate {
                    shareSection.Caption = string.Format (pattern, count);
                    if (sectionDVC != null) {
                        sectionDVC.ReloadData ();
                    }
                }
                );
            };

            sectionDVC.ViewAppearing += delegate {
                if (navigation.View.ViewWithTag(SHARE_BUTTON_TAG) != null) {
                    navigation.View.ViewWithTag(SHARE_BUTTON_TAG).RemoveFromSuperview();
                }
            };

            if (ResharedItem != null) {
                ReshareData();
            }
        }