Exemplo n.º 1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            first  = inflater.Inflate(Resource.Layout.NewPost, null);
            second = inflater.Inflate(Resource.Layout.NewPost2, null);

            userId = new UserSettings(this.Activity).getUserID();

            if (!activeSecond)
            {
                if (ContextCompat.CheckSelfPermission(this.Activity, Manifest.Permission.ReadExternalStorage) == (int)Permission.Granted)
                {
                    addViewModel = new AddViewModel();

                    ImageButton takePctrBtn  = first.FindViewById <ImageButton>(Resource.Id.takePictureBtn);
                    ImageButton chooseFewBtn = first.FindViewById <ImageButton>(Resource.Id.fewPictures);

                    takePctrBtn.Click  += (sender, e) => StartCameraActivity();
                    chooseFewBtn.Click += (sender, e) => ShowCheckCircles();

                    recView = first.FindViewById <AndroidX.RecyclerView.Widget.RecyclerView>(Resource.Id.recView);

                    var galleryPhotos = getPhotosFromGallery();

                    var imgAdapter = new ImageShortCutAdapter(this.Activity, galleryPhotos);

                    var grid = new AndroidX.RecyclerView.Widget.GridLayoutManager(this.Activity, 3);

                    recView.HasFixedSize = true;
                    recView.SetLayoutManager(grid);
                    recView.SetAdapter(imgAdapter);

                    imgAdapter.ItemClick += (sender, e) =>
                    {
                        int position = e;

                        if (imgAdapter.fewSelectActive)
                        {
                            var view = recView.GetChildAt(position);
                            var vh   = recView.FindViewHolderForLayoutPosition(position);

                            if (view == null)
                            {
                                view = vh.ItemView;
                            }

                            if (!imgAdapter.CheckedPositions.Contains(position))
                            {
                                if (imgAdapter.CheckedPositions.Count >= 10)
                                {
                                    Toast.MakeText(this.Activity, "You could clip up to 10 photos", ToastLength.Short).Show();
                                }
                                else
                                {
                                    imgAdapter.CheckedPositions.Add(position);
                                }
                            }
                            else
                            {
                                imgAdapter.CheckedPositions.Remove(position);
                            }
                            imgAdapter.BindViewHolder(vh, position);
                        }
                        else
                        {
                            SelectedImgsFromGallery(new List <string>()
                            {
                                galleryPhotos[position]
                            });
                        }
                    };
                }
                else
                {
                    ActivityCompat.RequestPermissions(this.Activity, new string[] { Manifest.Permission.ReadExternalStorage }, 200);
                    OnCreateView(inflater, container, savedInstanceState);
                }

                return(first);
            }
            else
            {
                return(second);
            }
        }