Ejemplo n.º 1
0
        public void AddPicture(string picture, int pos)
        {
            UploadedItem uploadedItem = new UploadedItem();

            AddSubview(uploadedItem);

            //uploadedItem.Layer.ZPosition = pos;

            uploadedItem.TranslatesAutoresizingMaskIntoConstraints = false;

            uploadedItem.WidthAnchor.ConstraintEqualTo(tileSize).Active  = true;
            uploadedItem.HeightAnchor.ConstraintEqualTo(tileSize).Active = true;

            uploadedItem.TopAnchor.ConstraintEqualTo(TopAnchor, GetPosY(pos)).Active   = true;
            uploadedItem.LeftAnchor.ConstraintEqualTo(LeftAnchor, GetPosX(pos)).Active = true;

            uploadedItem.LayoutIfNeeded();

            if (context is ProfileEditActivity)
            {
                uploadedItem.SetImage(context, Session.ID.ToString(), picture);
            }
            else
            {
                uploadedItem.SetImage(context, RegisterActivity.regsessionid, picture, true);
            }

            UIButton deleteUploadedImage = (UIButton)uploadedItem.Subviews[0].Subviews[1];

            deleteUploadedImage.TouchUpInside += DeleteUploadedImage_Click;

            foreach (NSLayoutConstraint constraint in Constraints)
            {
                if (constraint.FirstAttribute == NSLayoutAttribute.Height)
                {
                    constraint.Constant = (pos - pos % numColumns) / numColumns * (tileSize + tileSpacing) + tileSize;
                }
            }

            //drawOrder.Add(pos);
        }
Ejemplo n.º 2
0
        private async void DeleteUploadedImage_Click(object sender, EventArgs e)
        {
            if (rc.imagesUploading)
            {
                context.c.Snack(LangEnglish.ImagesUploading);
                return;
            }
            else if (rc.imagesDeleting)
            {
                context.c.Snack(LangEnglish.ImagesDeleting);
                return;
            }

            if (context is ProfileEditActivity)
            {
                if (rc.uploadedImages.Count == 1)
                {
                    context.c.Snack(LangEnglish.LastImageToDelete);
                    return;
                }
            }
            else if (rc.uploadedImages.Count == 1)
            {
                rc.ImagesProgressText.Text = "";
            }

            rc.imagesDeleting = true;
            rc.StartAnim();

            UploadedItem item  = (UploadedItem)((UIButton)sender).Superview.Superview;
            int          index = Array.IndexOf(Subviews, item);    //GetDrawPosFromChildIndex(Array.IndexOf(Subviews, item));

            if (context is ProfileEditActivity)
            {
                string responseString = await context.c.MakeRequest("action=deleteexisting&imageName=" + CommonMethods.UrlEncode(rc.uploadedImages[index]) + "&ID=" + Session.ID + "&SessionID=" + Session.SessionID);

                if (responseString.Substring(0, 2) == "OK")
                {
                    rc.uploadedImages.RemoveAt(index);
                    Session.Pictures = rc.uploadedImages.ToArray();

                    RemovePicture(index);
                    if (rc.uploadedImages.Count == 1)
                    {
                        rc.ImagesProgressText.Text = "";
                    }
                }
                else
                {
                    context.c.ReportError(responseString);
                    rc.imagesDeleting = false;
                }
            }
            else
            {
                context.c.Log("DeleteUploadedImage_Click index: " + index + " count " + rc.uploadedImages.Count);

                string responseString = await context.c.MakeRequest("action=deletetemp&imageName=" + CommonMethods.UrlEncode(rc.uploadedImages[index]) + "&regsessionid=" + RegisterActivity.regsessionid);

                if (responseString.Substring(0, 2) == "OK")
                {
                    rc.uploadedImages.RemoveAt(index);

                    RemovePicture(index);
                    if (rc.uploadedImages.Count == 1)
                    {
                        rc.ImagesProgressText.Text = "";
                    }
                    else if (rc.uploadedImages.Count == 0)
                    {
                        File.Delete(RegisterActivity.regSessionFile);
                    }
                }
                else
                {
                    context.c.ReportError(responseString);
                    rc.imagesDeleting = false;
                }
            }

            rc.StopAnim();
        }