public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.Clear;
            vwBackground.AddGestureRecognizer(new UITapGestureRecognizer(() => DismissViewController(true, null)));

            btnTakePhoto.TouchUpInside += async(sender, e) =>
            {
                await CrossMedia.Current.Initialize();

                var mediaFile = await AppMedia.TakePhotoAsync();

                HandleFile(mediaFile);
                DismissViewController(true, null);
            };

            btnPickPhoto.TouchUpInside += async(sender, e) =>
            {
                await CrossMedia.Current.Initialize();

                var mediaFile = await AppMedia.PickPhotoAsync();

                HandleFile(mediaFile);
                DismissViewController(true, null);
            };

            btnTakeVideo.TouchUpInside += async(sender, e) =>
            {
                await CrossMedia.Current.Initialize();

                var mediaFile = await AppMedia.TakeVideoAsync();

                HandleVideo(mediaFile);
                DismissViewController(true, null);
            };

            btnPickVideo.TouchUpInside += async(sender, e) =>
            {
                await CrossMedia.Current.Initialize();

                var mediaFile = await AppMedia.PickVideoAsync();

                HandleVideo(mediaFile);
                DismissViewController(true, null);
            };
        }
Example #2
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();
        }