public override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            if (IsInitialized)
            {
                return;
            }

            base.OnViewCreated(view, savedInstanceState);

            if (_media.Count > 1)
            {
                _photos.Visibility           = ViewStates.Visible;
                _previewContainer.Visibility = ViewStates.Gone;
                _photos.SetLayoutManager(new LinearLayoutManager(Activity, LinearLayoutManager.Horizontal, false));
                _photos.SetAdapter(GalleryAdapter);
                _photos.AddItemDecoration(new ListItemDecoration((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, Resources.DisplayMetrics)));
            }
            else
            {
                _photos.Visibility           = ViewStates.Gone;
                _previewContainer.Visibility = ViewStates.Visible;
                _preview.CornerRadius        = BitmapUtils.DpToPixel(5, Resources);

                var margin = (int)BitmapUtils.DpToPixel(15, Resources);

                if (_media[0].PreparedBitmap == null)
                {
                    var layoutParams = new RelativeLayout.LayoutParams(Resources.DisplayMetrics.WidthPixels - margin * 2, Resources.DisplayMetrics.WidthPixels - margin * 2);
                    layoutParams.SetMargins(margin, 0, margin, margin);
                    _previewContainer.LayoutParameters = layoutParams;

                    _preview.SetImagePath(_media[0].Path, _media[0].Parameters);
                    _ratioBtn.Click  += RatioBtnOnClick;
                    _rotateBtn.Click += RotateBtnOnClick;
                }
                else
                {
                    var previewSize = ViewUtils.CalculateImagePreviewSize(_media[0].PreparedBitmap.Width,
                                                                          _media[0].PreparedBitmap.Height, Resources.DisplayMetrics.WidthPixels - margin * 2,
                                                                          int.MaxValue);
                    var layoutParams = new RelativeLayout.LayoutParams(previewSize.Width, previewSize.Height);
                    layoutParams.SetMargins(margin, 0, margin, margin);
                    _previewContainer.LayoutParameters = layoutParams;

                    _ratioBtn.Visibility = _rotateBtn.Visibility = ViewStates.Gone;
                    _preview.SetImageBitmap(_media[0].PreparedBitmap);
                }

                _preview.Touch += PreviewOnTouch;
            }

            SearchTextChanged();
            CheckOnSpam();
        }
Пример #2
0
        public override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            if (IsInitialized)
            {
                return;
            }

            base.OnViewCreated(view, savedInstanceState);

            SetEditPost();

            _ratioBtn.Visibility = _rotateBtn.Visibility = ViewStates.Gone;
            if (_editPost.Media.Length > 1)
            {
                _photos.Visibility           = ViewStates.Visible;
                _previewContainer.Visibility = ViewStates.Gone;
                _photos.SetLayoutManager(new LinearLayoutManager(Activity, LinearLayoutManager.Horizontal, false));
                _photos.SetAdapter(GalleryAdapter);
                _photos.AddItemDecoration(new ListItemDecoration((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, Resources.DisplayMetrics)));
            }
            else
            {
                _photos.Visibility           = ViewStates.Gone;
                _previewContainer.Visibility = ViewStates.Visible;
                var margin      = (int)BitmapUtils.DpToPixel(15, Resources);
                var previewSize = ViewUtils.CalculateImagePreviewSize(_editPost.Media[0].Size.Width,
                                                                      _editPost.Media[0].Size.Height, Resources.DisplayMetrics.WidthPixels - margin * 2,
                                                                      int.MaxValue);
                var layoutParams = new RelativeLayout.LayoutParams(previewSize.Width, previewSize.Height);
                layoutParams.SetMargins(margin, 0, margin, margin);
                _previewContainer.LayoutParameters = layoutParams;
                _preview.CornerRadius = BitmapUtils.DpToPixel(5, Resources);

                var url = _editPost.Media[0].Thumbnails.Mini;
                Picasso.With(Activity).Load(url).CenterCrop()
                .Resize(_previewContainer.LayoutParameters.Width, _previewContainer.LayoutParameters.Height)
                .Into(_preview);

                _preview.Touch += PreviewOnTouch;
            }

            SearchTextChanged();
        }
Пример #3
0
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            var width       = (int)Math.Round(((Android.App.Activity)parent.Context).WindowManager.DefaultDisplay.Width - BitmapUtils.DpToPixel(25, parent.Resources));
            var height      = (int)Math.Round(BitmapUtils.DpToPixel(160, parent.Resources));
            var previewSize = _gallery == null?
                              ViewUtils.CalculateImagePreviewSize(_postMedia[0].Size.Width, _postMedia[0].Size.Height, width, height) :
                                  ViewUtils.CalculateImagePreviewSize(_gallery[0].PreparedBitmap.Width, _gallery[0].PreparedBitmap.Height, width, height);

            var cardView = new CardView(parent.Context)
            {
                LayoutParameters = new FrameLayout.LayoutParams(previewSize.Width, previewSize.Height),
                Radius           = BitmapUtils.DpToPixel(5, parent.Resources)
            };
            var image = new ImageView(parent.Context)
            {
                Id = Resource.Id.photo,
                LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)
            };

            image.SetScaleType(ImageView.ScaleType.FitXy);
            cardView.AddView(image);
            return(new GalleryViewHolder(cardView));
        }