Esempio n. 1
0
        private ImageButtonStringElement CreateImageButtonStringElement(Secret secret)
        {
            var secretElement = new ImageButtonStringElement(secret.Phrase, secret, "Images/remove.png",
                                                             delegate {
                DisplaySecretDetail(secret);
            },
                                                             delegate {
                AppDelegate.HistoryData.Secrets.Remove(secret);
                Element found = null;
                foreach (var element in secretsSection.Elements)
                {
                    if (element.Caption == secret.Phrase)
                    {
                        found = element;
                        break;
                    }
                }

                if (found != null)
                {
                    secretsSection.Remove(found);
                    if (secretsSection.Count == 0)
                    {
                        (secretsSection.Parent as RootElement).RemoveAt(1);
                    }
                }
            }
                                                             );

            secretElement.Value = " ";
            secret.WatchEvent  += (s) => {
                InvokeOnMainThread(() => {
                    int peers           = s.ListenersCount;
                    secretElement.Value = peers > 0 ? peers + " device" + (peers > 1 ? "s" : "") : " ";
                    rootDVC.ReloadData();
                }
                                   );
            };

            return(secretElement);
        }
Esempio n. 2
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();
            }
        }