Exemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            CompletedCountInitial = Challenge.CompletedCount ?? 0;
            TargetCount           = (Challenge.TargetCount ?? 0) == 0 ? MAX_IMAGES : Challenge.TargetCount.Value;
            IsSingleImage         = TargetCount == 1;
            IsUnlimitedImages     = TargetCount == MAX_IMAGES;
            AllowUserCompletion   = (Challenge.AllowUserCompletion ?? false) || IsUnlimitedImages;

            SetupFonts();

            if (CompletedCount == 0)
            {
                ShowNoImageView();
            }
            else if (CompletedCount > 0)
            {
                ShowImagesCollectionView();
            }

            CountContainer.Layer.BorderColor  = UIColor.FromRGB(238, 238, 238).CGColor;
            CountContainer.Layer.BorderWidth  = 1;
            CountContainer.Layer.CornerRadius = 2;

            CameraButtonCenter.TouchUpInside += (e, s) => TakePicture(true);

            btnSubmitPictureWithDescription.TouchUpInside += (e, s) =>
            {
                if (IsSingleImage)
                {
                    Spinner = new UIImageView(UIImage.FromBundle("loading-indicator"));
                    PreviewImage.AddSubview(Spinner);
                    Platform.AnimateRotation(Spinner);
                    PosteringOverlay = Platform.AddOverlay(View, View.Frame, UIColor.Clear, true);

                    CountContainer.AddConstraint(NSLayoutConstraint.Create(CountContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, 0));
                }
                else
                {
                    ShowImagesCollectionView();
                }
                SubmitChallenge(btnSubmitChallenge);
            };

            CameraButton.TouchUpInside       += (e, s) => TakePicture(true);
            btnSubmitChallenge.TouchUpInside += (e, s) =>
            {
                UIAlertController alertController = UIAlertController.Create(null,
                                                                             $"You have submitted {CompletedCount}/{(IsUnlimitedImages ? "∞" : TargetCount.ToString())} pieces of content - would you like to complete this challenge now, or leave it open to submit more later?", UIAlertControllerStyle.ActionSheet);

                alertController.AddAction(UIAlertAction.Create("COMPLETE NOW", UIAlertActionStyle.Destructive, (a) => SL.Manager.PostSubmitCollateral(Challenge.ID, (resp) => SubmitChallengeComplete(btnSubmitChallenge, resp))));
                alertController.AddAction(UIAlertAction.Create("LEAVE OPEN", UIAlertActionStyle.Cancel, (a) => {
                    NavigationController.PopViewController(true);
                    NavigationController.PopViewController(false);
                }));
                NavigationController.PresentViewController(alertController, true, null);
            };

            DescriptionText.ReturnKeyType     = UIReturnKeyType.Done;
            DescriptionText.ShouldChangeText += DescriptionText_ShouldChangeText;

            DescriptionText.ShouldBeginEditing += (UITextView textView) =>
            {
                if (textView.Text == placeholder)
                {
                    textView.Text      = "";
                    textView.TextColor = UIColor.Black; // Text Color
                }
                return(true);
            };

            DescriptionText.ShouldEndEditing += (UITextView textView) =>
            {
                if (textView.Text == "")
                {
                    textView.Text      = placeholder;
                    textView.TextColor = UIColor.LightGray; // Placeholder Color
                }
                return(true);
            };

            lblChallengeName.Text    = Challenge.Name;
            NeedUploadCountText.Text = "/ " + (IsUnlimitedImages ? "∞" : TargetCount.ToString());

            CollectionView.RegisterNibForCell(CollateralCollectionViewCell.Nib, CollateralCollectionViewCell.ClassName);
            CollectionViewAttach.RegisterNibForCell(CollateralCollectionViewCell.Nib, CollateralCollectionViewCell.ClassName);
        }
Exemplo n.º 2
0
        void ReleaseDesignerOutlets()
        {
            if (borderSubmit != null)
            {
                borderSubmit.Dispose();
                borderSubmit = null;
            }

            if (bottomButtonsContainer != null)
            {
                bottomButtonsContainer.Dispose();
                bottomButtonsContainer = null;
            }

            if (btnSubmitChallenge != null)
            {
                btnSubmitChallenge.Dispose();
                btnSubmitChallenge = null;
            }

            if (btnSubmitPictureWithDescription != null)
            {
                btnSubmitPictureWithDescription.Dispose();
                btnSubmitPictureWithDescription = null;
            }

            if (CameraButton != null)
            {
                CameraButton.Dispose();
                CameraButton = null;
            }

            if (CameraButtonCenter != null)
            {
                CameraButtonCenter.Dispose();
                CameraButtonCenter = null;
            }

            if (CollectionView != null)
            {
                CollectionView.Dispose();
                CollectionView = null;
            }

            if (CollectionViewAttach != null)
            {
                CollectionViewAttach.Dispose();
                CollectionViewAttach = null;
            }

            if (CountContainer != null)
            {
                CountContainer.Dispose();
                CountContainer = null;
            }

            if (DescriptionText != null)
            {
                DescriptionText.Dispose();
                DescriptionText = null;
            }

            if (lblChallengeName != null)
            {
                lblChallengeName.Dispose();
                lblChallengeName = null;
            }

            if (lblUpload != null)
            {
                lblUpload.Dispose();
                lblUpload = null;
            }

            if (NeedUploadCountText != null)
            {
                NeedUploadCountText.Dispose();
                NeedUploadCountText = null;
            }

            if (PreviewImage != null)
            {
                PreviewImage.Dispose();
                PreviewImage = null;
            }

            if (submitContainer != null)
            {
                submitContainer.Dispose();
                submitContainer = null;
            }

            if (UploadedCountText != null)
            {
                UploadedCountText.Dispose();
                UploadedCountText = null;
            }

            if (vCameraCenter != null)
            {
                vCameraCenter.Dispose();
                vCameraCenter = null;
            }

            if (vDescriptionContainer != null)
            {
                vDescriptionContainer.Dispose();
                vDescriptionContainer = null;
            }
        }