Example #1
0
        void SetupViewBindings()
        {
            btnBack.Click    += (sender, e) => Finish();
            lblTitle.Typeface = CustomTypefaces.RobotoBold;

            ShowHelpIfNecessary(TutorialHelper.CreateContent);

            var user = CrossSettings.Current.GetValueOrDefaultJson <User>("User");

            hideTagProfiles = string.IsNullOrEmpty(user.AthleteTeamId) || !user.AthleteVerified;
            if (!string.IsNullOrEmpty(user.ProfileUrl))
            {
                ImageService.Instance.LoadUrl(user.ProfileUrl).Retry(3, 300).DownSample(200).Transform(new CircleTransformation()).Into(imgProfile);
            }
            lblName.Text = user.FirstName + " " + user.LastName;

            //rlMedia.Visibility = ViewStates.Invisible;
            var parameters = rlMedia.LayoutParameters as LinearLayout.LayoutParams;
            var height     = Resources.DisplayMetrics.WidthPixels * 9 / 16f;

            parameters.Height        = (int)height;
            rlMedia.LayoutParameters = parameters;

            if (!string.IsNullOrEmpty(PostId))
            {
                ShowProgressDialog();
                var apiTask = new ServiceApi().GetPost(PostId);
                apiTask.HandleError(this);
                apiTask.OnSucess(this, response =>
                {
                    post            = response.Result;
                    txtContent.Text = post.Content;
                    if (!string.IsNullOrEmpty(post.ContentSourceId))
                    {
                        lblName.Text = user.ContentSourceName;
                        ImageService.Instance.LoadUrl(user.ContentSourceUrl).Retry(3, 300).DownSample(200).Transform(new CircleTransformation()).Into(imgProfile);
                        hideTagProfiles = false;
                    }
                    if (!string.IsNullOrEmpty(post.TeamId))
                    {
                        var team = user.AdminTeams.FirstOrDefault(m => m.Id == post.TeamId);
                        if (team == null)
                        {
                            return;
                        }
                        lblName.Text = team.SchoolName;
                        ImageService.Instance.LoadUrl(team.ProfileUrl).Retry(3, 300).DownSample(200).Transform(new CircleTransformation()).Into(imgProfile);
                        hideTagProfiles = true;
                    }
                    if (!string.IsNullOrEmpty(post.SchoolId))
                    {
                        var school = user.AdminSchools.FirstOrDefault(m => m.Id == post.SchoolId);
                        if (school == null)
                        {
                            return;
                        }
                        lblName.Text = school.Name;
                        ImageService.Instance.LoadUrl(school.ProfileUrl).Retry(3, 300).DownSample(200).Transform(new CircleTransformation()).Into(imgProfile);
                        hideTagProfiles = false;
                    }
                    HideProgressDialog();
                    SetImageUI();
                });
            }
            else
            {
                post         = new Post();
                post.Schools = new List <string>();
                post.Sports  = new List <string>();
                post.Teams   = new List <string>();
                post.Links   = new List <PostLink>();
                post.Images  = new List <PostImage>();
                post.Videos  = new List <PostVideo>();
                post.Events  = new List <string>();
                SetImageUI();
            }

            //btnNext.Text = "Post";

            btnNext.Click += (sender, e) =>
            {
                post.Content = txtContent.Text;

                if (!post.Images.Any() && !post.Videos.Any() && !post.Links.Any() && string.IsNullOrEmpty(post.Content))
                {
                    new AlertDialog.Builder(this)
                    .SetTitle("Error")
                    .SetMessage("You must choose some content to post")
                    .SetPositiveButton("Ok", (s, e2) => { })
                    .Show();
                    return;
                }

                if (hideTagProfiles)
                {
                    Intent i = new Intent(this, typeof(TagEventsActivity));
                    i.PutExtra("Post", JsonConvert.SerializeObject(post));
                    StartActivity(i);
                }
                else
                {
                    Intent i = new Intent(this, typeof(TagProfileActivity));
                    i.PutExtra("Post", JsonConvert.SerializeObject(post));
                    StartActivity(i);
                }
            };

            llAddMedia.Click += (sender, args) =>
            {
                var view   = LayoutInflater.Inflate(Resource.Layout.AddMediaOptionsLayout, null);
                var dialog = new AlertDialog.Builder(this).SetView(view).Create();
                view.FindViewById <Button>(Resource.Id.btnTakePhoto).Click += async(sender2, args2) =>
                {
                    dialog.Dismiss();
                    var file = await AppMedia.TakePhotoAsync();

                    ImagePicked(file);
                };
                view.FindViewById <Button>(Resource.Id.btnPickPhoto).Click += async(sender2, args2) =>
                {
                    dialog.Dismiss();
                    var file = await AppMedia.PickPhotoAsync();

                    ImagePicked(file);
                };
                view.FindViewById <Button>(Resource.Id.btnTakeVideo).Click += async(sender2, args2) =>
                {
                    dialog.Dismiss();
                    var file = await AppMedia.TakeVideoAsync();

                    HandleVideo(file);
                };
                view.FindViewById <Button>(Resource.Id.btnPickVideo).Click += async(sender2, args2) =>
                {
                    dialog.Dismiss();
                    var file = await AppMedia.PickVideoAsync();

                    HandleVideo(file);
                };

                dialog.Show();
            };

            llAddLink.Click += (sender, args) =>
            {
                var view    = LayoutInflater.Inflate(Resource.Layout.AddLinkLayout, null);
                var txtLink = view.FindViewById <EditText>(Resource.Id.txtLink);
                var dialog  = new AlertDialog.Builder(this).SetView(view).SetPositiveButton("Ok", async(s, e) =>
                {
                    SetNoImage();
                    SetNoLink();
                    post.Videos.Clear();
                    post.Images.Clear();
                    post.Links.Clear();
                    ShowProgressDialog();
                    var link = await AppMedia.GetLinkData(txtLink.Text);
                    if (link != null)
                    {
                        link.ImageAspectRatio = await GetImageAspectRatio(link.ImageUrl);
                    }

                    HideProgressDialog();
                    if (link != null)
                    {
                        post.Links.Add(link);
                        lblLink.Text = txtLink.Text;
                    }

                    SetImageUI();
                }).SetNegativeButton("Cancel", (s, e) => { }).Create();

                dialog.Show();
            };

            btnCancel.Click += (sender, e) =>
            {
                post.Images.Clear();
                post.Videos.Clear();
                post.Links.Clear();;

                rlMedia.Visibility = ViewStates.Invisible;
                SetNoImage();
                SetNoLink();
            };

            btnPostAs.Click += (sender, e) => PostAsClicked();
        }
Example #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ShowHelpIfNecessary(TutorialHelper.CreateContent);

            btnBack.TouchUpInside += (sender, e) =>
            {
                NavigationController.PopViewController(true);
            };
            var user = CrossSettings.Current.GetValueOrDefaultJson <User>("User");

            hideProfileTagging = string.IsNullOrEmpty(user.AthleteTeamId) || !user.AthleteVerified;

            if (!string.IsNullOrEmpty(PostId))
            {
                LoadingScreen.Show();
                var apiTask = new ServiceApi().GetPost(PostId);
                apiTask.HandleError(LoadingScreen);
                apiTask.OnSucess(response =>
                {
                    post            = response.Result;
                    txtComment.Text = post.Content;

                    if (!string.IsNullOrEmpty(post.ContentSourceId))
                    {
                        lblName.Text = user.ContentSourceName;
                        ImageService.Instance.LoadUrl(user.ContentSourceUrl).Retry(3, 300).Transform(new CircleTransformation()).Into(imgProfile);
                        hideProfileTagging = false;
                        btnNext.SetTitle("Next", UIControlState.Normal);
                    }

                    if (!string.IsNullOrEmpty(post.TeamId))
                    {
                        var team = user.AdminTeams.FirstOrDefault(m => m.Id == post.TeamId);
                        if (team == null)
                        {
                            return;
                        }
                        lblName.Text = team.SchoolName;
                        ImageService.Instance.LoadUrl(team.ProfileUrl).Retry(3, 300).Transform(new CircleTransformation()).Into(imgProfile);
                        hideProfileTagging = true;
                        btnNext.SetTitle("Next", UIControlState.Normal);
                    }
                    if (!string.IsNullOrEmpty(post.SchoolId))
                    {
                        var school = user.AdminSchools.FirstOrDefault(m => m.Id == post.SchoolId);
                        if (school == null)
                        {
                            return;
                        }
                        lblName.Text = school.Name;
                        ImageService.Instance.LoadUrl(school.ProfileUrl).Retry(3, 300).Transform(new CircleTransformation()).Into(imgProfile);
                        hideProfileTagging = false;
                        btnNext.SetTitle("Next", UIControlState.Normal);
                    }

                    LoadingScreen.Hide();
                    SetImageUI();
                });
            }
            else
            {
                post         = new Post();
                post.Schools = new List <string>();
                post.Sports  = new List <string>();
                post.Teams   = new List <string>();
                post.Links   = new List <PostLink>();
                post.Images  = new List <PostImage>();
                post.Videos  = new List <PostVideo>();
                post.Events  = new List <string>();
                SetImageUI();
            }

            lblName.Text = user.FirstName + " " + user.LastName;
            if (!string.IsNullOrEmpty(user.ProfileUrl))
            {
                ImageService.Instance.LoadUrl(user.ProfileUrl).Retry(3, 200).Transform(new CircleTransformation()).Into(imgProfile);
            }

            btnNext.TouchUpInside += (sender, e) =>
            {
                post.Content = txtComment.Text;
                if (!post.Images.Any() && !post.Videos.Any() && !post.Links.Any() && string.IsNullOrEmpty(post.Content))
                {
                    var errorController = UIAlertController.Create("Error", "You must choose some content to post", UIAlertControllerStyle.Alert);
                    errorController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (obj) => { }));
                    PresentViewController(errorController, true, null);
                    return;
                }

                if (hideProfileTagging)
                {
                    var controller = Storyboard.InstantiateViewController <TagEventsViewController>();
                    controller.Post = post;
                    NavigationController.PushViewController(controller, true);
                }
                else
                {
                    var controller = Storyboard.InstantiateViewController <TagProfileViewController>();
                    controller.Post = post;
                    NavigationController.PushViewController(controller, true);
                }
            };

            vwAddMedia.AddGestureRecognizer(new UITapGestureRecognizer(() =>
            {
                var controller = Storyboard.InstantiateViewController <AddContentOptionsViewController>();
                controller.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
                controller.ModalTransitionStyle   = UIModalTransitionStyle.CrossDissolve;
                controller.ImagePicked            = ImagePicked;
                controller.VideoPicked            = VideoPicked;
                PresentViewController(controller, true, null);
            }));

            vwAddLink.AddGestureRecognizer(new UITapGestureRecognizer(() =>
            {
                var controller = UIAlertController.Create("Enter a link", "", UIAlertControllerStyle.Alert);
                controller.AddTextField((tf) =>
                {
                    tf.Placeholder = "Link";
                });
                controller.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, async(obj) =>
                {
                    SetNoImage();
                    SetNoLink();
                    post.Videos.Clear();
                    post.Images.Clear();
                    post.Links.Clear();

                    var link = await AppMedia.GetLinkData(controller.TextFields[0].Text);
                    if (link != null)
                    {
                        link.ImageAspectRatio = await GetImageAspectRatio(link.ImageUrl);
                    }

                    if (link != null)
                    {
                        post.Links.Add(link);
                        lblLink.Text = controller.TextFields[0].Text;
                    }

                    SetImageUI();
                }));

                PresentViewController(controller, true, null);
            }));

            btnCancel.TouchUpInside += (sender, e) =>
            {
                post.Images.Clear();
                post.Videos.Clear();
                post.Links.Clear();;

                vwImageContainer.Hidden = true;
                SetNoImage();
                SetNoLink();
            };
            btnLinkCancel.Hidden = true;

            btnPostAs.TouchUpInside += (sender, e) => PostAsClicked();
            //btnNext.SetTitle("Post", UIControlState.Normal);

            txtComment.Changed += (sender, e) =>
            {
                if (string.IsNullOrEmpty(txtComment.Text))
                {
                    lblPlaceholder.Hidden = false;
                }
                else
                {
                    lblPlaceholder.Hidden = true;
                }
            };
        }