Пример #1
0
        internal void UpdateSubview(object view, DataTemplate viewTemplate, nint viewTag, ref UIView uiView, ref VisualElement formsElement)
        {
            uiView?.RemoveFromSuperview();

            if (formsElement != null)
            {
                ItemsView.RemoveLogicalChild(formsElement);
                formsElement.MeasureInvalidated -= OnFormsElementMeasureInvalidated;
            }

            UpdateView(view, viewTemplate, ref uiView, ref formsElement);

            if (uiView != null)
            {
                uiView.Tag = viewTag;
                CollectionView.AddSubview(uiView);
            }

            if (formsElement != null)
            {
                ItemsView.AddLogicalChild(formsElement);
            }

            if (formsElement != null)
            {
                RemeasureLayout(formsElement);
                formsElement.MeasureInvalidated += OnFormsElementMeasureInvalidated;
            }
            else if (uiView != null)
            {
                uiView.SizeToFit();
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            CollectionView.ScrollsToTop                   = false;
            CollectionView.Bounces                        = false;
            CollectionView.AlwaysBounceHorizontal         = false;
            CollectionView.ShowsHorizontalScrollIndicator = false;
            CollectionView.ClipsToBounds                  = false;

            _bar = new UIView(new CGRect(0, 0, 20, 20));
            _bar.BackgroundColor = UIColor.White;
            _bar.Layer.ZPosition = 9001;             //its over 9000!
            CollectionView.AddSubview(_bar);

            _bottomShadow = new UIView(new CGRect(0, 0, 10, 1));
            _bottomShadow.BackgroundColor = Color.Black.MultiplyAlpha(0.3).ToUIColor();
            _bottomShadow.Layer.ZPosition = 9002;
            CollectionView.AddSubview(_bottomShadow);

            var flowLayout = Layout as UICollectionViewFlowLayout;

            flowLayout.ScrollDirection         = UICollectionViewScrollDirection.Horizontal;
            flowLayout.MinimumInteritemSpacing = 0;
            flowLayout.MinimumLineSpacing      = 0;
            flowLayout.EstimatedItemSize       = new CGSize(70, 35);

            CollectionView.RegisterClassForCell(GetCellType(), CellId);

            ((IShellController)_shellContext.Shell).AddAppearanceObserver(this, ShellSection);
            ShellSectionController.ItemsCollectionChanged += OnShellSectionItemsChanged;

            UpdateSelectedIndex();
            ShellSection.PropertyChanged += OnShellSectionPropertyChanged;
        }
        void AddRefreshControl()
        {
            refreshControl = new UIRefreshControl()
            {
                TintColor = UIColor.FromRGB(214, 93, 98)
                            //AttributedTitle = new NSAttributedString("Fetching new prompt")
            };

            if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
            {
                CollectionView.RefreshControl = refreshControl;
            }
            else
            {
                CollectionView.AddSubview(refreshControl);
            }

            refreshControl.ValueChanged += (sender, e) =>
            {
                CollectionView.Bounces = false;
                CollectionView.AlwaysBounceVertical = false;

                GenerateNewPrompt();
                ReloadPromptsCollection();
                refreshControl.EndRefreshing();

                CollectionView.Bounces = true;
                CollectionView.AlwaysBounceVertical = true;
            };
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            RefreshControl.ValueChanged += (sender, e) => Task.Run(async() => await Refresh());
            CollectionView.AddSubview(RefreshControl);
            var deletate = new CustomFlowLayoutDelegate();

            deletate.ItemClick += async(sender, e) =>
            {
                var item = await Detail.GetVideo(ID, List[e.Index].Set, LanguageHelper.PrefLang);

                var picker = new UIPickerView();
                var model  = new QualityPickerViewModel(item);
                model.ItemClick += (s2, e2) =>
                {
                    View.WillRemoveSubview(picker);
                    if (moviePlayer == null)
                    {
                        moviePlayer = new MPMoviePlayerController();
                        View.AddSubview(moviePlayer.View);
                        moviePlayer.ShouldAutoplay = true;
                    }
                    moviePlayer.ContentUrl = NSUrl.FromString(item.ToDictionary().Values.ToArray()[e2.Index]);
                    moviePlayer.SetFullscreen(true, false);
                    moviePlayer.PrepareToPlay();
                    moviePlayer.Play();
                };
                View.AddSubview(picker);
                picker.Hidden = false;
            };
            CollectionView.Delegate = deletate;
            CollectionView.RegisterClassForCell(typeof(DetailCell), _detailCellId);
            CollectionView.ContentInset = new UIEdgeInsets(4, 4, 4, 4);
            Task.Run(async() => await Refresh());
        }
Пример #5
0
        protected void UpdateSubview(object view, DataTemplate viewTemplate, ref UIView uiView, ref VisualElement formsElement)
        {
            if (uiView != null)
            {
                CollectionView.Subviews.Remove(uiView);
            }

            if (formsElement != null)
            {
                ItemsView.RemoveLogicalChild(formsElement);
                formsElement.MeasureInvalidated -= OnFormsElementMeasureInvalidated;
            }

            UpdateView(view, viewTemplate, ref uiView, ref formsElement);

            if (uiView != null)
            {
                CollectionView.AddSubview(uiView);
            }

            if (formsElement != null)
            {
                ItemsView.AddLogicalChild(formsElement);
            }

            if (formsElement != null)
            {
                RemeasureLayout(formsElement);
                formsElement.MeasureInvalidated += OnFormsElementMeasureInvalidated;
            }
            else if (uiView != null)
            {
                uiView.SizeToFit();
            }
        }
Пример #6
0
        void AddPullToRefresh()
        {
            var refreshControl = new UIRefreshControl();

            refreshControl.ValueChanged += HandleValueChanged;
            refreshControl.AddTarget(Self, new Selector("startRefresh"), UIControlEvent.ValueChanged);
            refreshControl.TintColor = UIColor.Clear;


            var loadingView = new UIView(refreshControl.Bounds);

            loadingView.BackgroundColor = UIColor.Clear;
            var backgroundImage = new UIImageView(UIImage.FromBundle("loading.png"));

            loadingView.AddSubview(backgroundImage);
            loadingView.ClipsToBounds = true;

            var refreshColorView = new UIView(refreshControl.Bounds);

            refreshColorView.BackgroundColor = UIColor.Clear;
            refreshColorView.Alpha           = 0.3f;

            refreshControl.AddSubview(loadingView);
            refreshControl.AddSubview(refreshColorView);

            CollectionView.AddSubview(refreshControl);
        }
Пример #7
0
        void SetUpPullToRefresh()
        {
            refresher = new UIRefreshControl();
            refresher.ValueChanged += OnControllValueChanged;

            CollectionView.AlwaysBounceVertical = true;
            CollectionView.AddSubview(refresher);
        }
Пример #8
0
        public override void ViewDidLoad()
        {
            LoggingClass.LogInfo("Entered into favorite", screen);
            try
            {
                this.CollectionView.Add(refreshControl);
                refreshControl.ValueChanged += (rcSender, e) =>
                {
                    //Refresh this view
                    myData = svc.GetItemFavsUID(CurrentUser.RetreiveUserId()).Result;
                    if (myData.ItemList.Count == 0)
                    {
                        UIImageView ImgIns = new UIImageView();
                        ImgIns.Image = UIImage.FromFile("FavIns.png");
                        UILabel NoFav = new UILabel();
                        NoFav.Text          = myData.ErrorDescription;
                        NoFav.LineBreakMode = UILineBreakMode.WordWrap;
                        NoFav.Lines         = 0;
                        CGSize sTemp = new CGSize(View.Frame.Width, 100);
                        sTemp               = NoFav.SizeThatFits(sTemp);
                        NoFav.Frame         = new CGRect(0, 50, View.Frame.Width - 20, sTemp.Height);
                        NoFav.TextAlignment = UITextAlignment.Center;
                        ImgIns.Frame        = new CGRect((View.Frame.Width / 2) - 100, 50 + sTemp.Height + 20, 202, 381);
                        CollectionView.AddSubview(NoFav);
                        CollectionView.AddSubview(ImgIns);
                    }
                    CollectionView.ReloadData();
                    refreshControl.EndRefreshing();
                };

                myData = svc.GetItemFavsUID(CurrentUser.RetreiveUserId()).Result;
                if (myData.ItemList.Count == 0)
                {
                    UIImageView ImgIns = new UIImageView();
                    ImgIns.Image = UIImage.FromFile("FavIns.png");
                    UILabel NoFav = new UILabel();
                    NoFav.Text          = myData.ErrorDescription;
                    NoFav.LineBreakMode = UILineBreakMode.WordWrap;
                    NoFav.Lines         = 0;
                    CGSize sTemp = new CGSize(View.Frame.Width, 100);
                    sTemp               = NoFav.SizeThatFits(sTemp);
                    NoFav.Frame         = new CGRect(0, 50, View.Frame.Width - 20, sTemp.Height);
                    NoFav.TextAlignment = UITextAlignment.Center;
                    ImgIns.Frame        = new CGRect((View.Frame.Width / 2) - 100, 50 + sTemp.Height + 20, 202, 381);
                    CollectionView.AddSubview(NoFav);
                    CollectionView.AddSubview(ImgIns);
                }
                BTProgressHUD.Dismiss();
                this.View.BackgroundColor           = new UIColor(256, 256, 256, 0.8f);
                this.CollectionView.BackgroundColor = UIColor.White;
                CollectionView.RegisterClassForCell(typeof(MyFavViewCell), MyFavViewCell.Key);
            }
            catch (Exception ex)
            {
                LoggingClass.LogError(ex.Message, screen, ex.StackTrace);
            }
        }
Пример #9
0
        public void AddSubView(IView subView)
        {
            var mvxViewController = subView as MvxViewController;

            if (mvxViewController != null)
            {
                mvxViewController.View.ClipsToBounds = true;
                mvxViewController.View.Hidden        = false;
                mvxViewController.View.Frame         = new RectangleF(0, 0, 320, 200);
                CollectionView.AddSubview(mvxViewController.View);
                //BringSubviewToFront(mvxViewController.MyView);
            }
        }
Пример #10
0
        // Do NOT remove this handler even if ReSharper cannot find it's usage. It is referred in BarCell.designer.cs file by its name. That's how Xamarin is linking the event on the button.
        partial void HandleButtonRightTouchUpInside(NSObject sender)
        {
            var subViewModelTwo = App.SGFactory.Create <ISubViewModelTwo, ISubViewTwo>();

            if (subViewModelTwo != null)
            {
                var subViewTwo = subViewModelTwo.MyView as MvxViewController;
                if (subViewTwo != null)
                {
                    subViewTwo.View.Hidden = false;
                    subViewTwo.View.Frame  = new RectangleF(0, 0, 320, 200);
                    CollectionView.AddSubview(subViewTwo.View);
                    //BringSubviewToFront(subViewTwo.MyView);
                }
            }
        }
Пример #11
0
        void UpdateEmptyViewVisibility(bool isEmpty)
        {
            if (isEmpty && _emptyUIView != null)
            {
                var emptyView = CollectionView.ViewWithTag(EmptyTag);

                if (emptyView != null)
                {
                    emptyView.RemoveFromSuperview();
                    ItemsView.RemoveLogicalChild(_emptyViewFormsElement);
                }

                _emptyUIView.Tag = EmptyTag;
                CollectionView.AddSubview(_emptyUIView);
                LayoutEmptyView();

                if (_emptyViewFormsElement != null)
                {
                    if (ItemsView.EmptyViewTemplate == null)
                    {
                        ItemsView.AddLogicalChild(_emptyViewFormsElement);
                    }

                    // Now that the native empty view's frame is sized to the UICollectionView, we need to handle
                    // the Forms layout for its content
                    _emptyViewFormsElement.Layout(_emptyUIView.Frame.ToRectangle());
                }

                _emptyViewDisplayed = true;
            }
            else
            {
                // Is the empty view currently in the background? Swap back to the default.
                if (_emptyViewDisplayed)
                {
                    _emptyUIView.RemoveFromSuperview();
                    _emptyUIView.Dispose();
                    _emptyUIView = null;

                    ItemsView.RemoveLogicalChild(_emptyViewFormsElement);
                }

                _emptyViewDisplayed = false;
            }
        }
Пример #12
0
        void ShowEmptyView()
        {
            if (_emptyViewDisplayed || _emptyUIView == null)
            {
                return;
            }

            _emptyUIView.Tag = EmptyTag;
            CollectionView.AddSubview(_emptyUIView);

            if (!ItemsView.LogicalChildren.Contains(_emptyViewFormsElement))
            {
                ItemsView.AddLogicalChild(_emptyViewFormsElement);
            }

            LayoutEmptyView();

            AlignEmptyView();
            _emptyViewDisplayed = true;
        }
Пример #13
0
		void ShowEmptyView()
		{
			if (_emptyViewDisplayed || _emptyUIView == null)
			{
				return;
			}

			_emptyUIView.Tag = EmptyTag;
			CollectionView.AddSubview(_emptyUIView);

			if (((IElementController)ItemsView).LogicalChildren.IndexOf(_emptyViewFormsElement) == -1)
			{
				ItemsView.AddLogicalChild(_emptyViewFormsElement);
			}

			LayoutEmptyView();

			AlignEmptyView();
			_emptyViewDisplayed = true;
		}
Пример #14
0
        internal void UpdateSubview(object view, DataTemplate viewTemplate, ref UIView uiView, ref VisualElement formsElement)
        {
            if (uiView != null)
            {
                CollectionView.Subviews.Remove(uiView);
            }

            if (formsElement != null)
            {
                ItemsView.RemoveLogicalChild(formsElement);
                formsElement.MeasureInvalidated -= OnFormsElementMeasureInvalidated;
            }

            UpdateView(view, viewTemplate, ref uiView, ref formsElement);

            if (uiView != null)
            {
                CollectionView.AddSubview(uiView);
            }

            if (formsElement != null)
            {
                ItemsView.AddLogicalChild(formsElement);
            }

            if (formsElement != null)
            {
                var request = formsElement.Measure(CollectionView.Frame.Width, double.PositiveInfinity, MeasureFlags.IncludeMargins);
                Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(formsElement, new Rectangle(0, -request.Request.Height, CollectionView.Frame.Width, request.Request.Height));

                formsElement.MeasureInvalidated += OnFormsElementMeasureInvalidated;
            }
            else if (uiView != null)
            {
                uiView.SizeToFit();
            }
        }
Пример #15
0
        protected override void HandleLongPressGesture()
        {
            switch (LongPressGestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
            {
                // we get the current item and draw a floating copy on it on the Collection View, so that it cannot be taken outside the bounds of the collection view
                // we get the copy usign RasterizedImage
                var currentIndexPath = CollectionView.IndexPathForItemAtPoint(LongPressGestureRecognizer.LocationInView(CollectionView));
                SelectedItemIndexPath = currentIndexPath;
                if (SelectedItemIndexPath == null)
                {
                    return;
                }

                if (!DataSource.CanMoveItemAtIndexPath(SelectedItemIndexPath))
                {
                    return;
                }

                var collectionViewCell = CollectionView.CellForItem(SelectedItemIndexPath);
                CurrentView = new UIView(collectionViewCell.Frame);

                collectionViewCell.Highlighted = true;
                var highlightedImageView = new UIImageView(RastertizedImage(collectionViewCell));
                highlightedImageView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                highlightedImageView.Alpha            = 1.0f;

                collectionViewCell.Highlighted = false;
                var imageView = new UIImageView(RastertizedImage(collectionViewCell));
                imageView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                imageView.Alpha            = 0.0f;

                CurrentView.AddSubview(imageView);
                CurrentView.AddSubview(highlightedImageView);
                CollectionView.AddSubview(CurrentView);
                CurrentViewCenter = CurrentView.Center;

                OnWillBeginDraggingItem(SelectedItemIndexPath);

                // animate the floating copy into existence
                UIView.Animate(0.3, 0.0, UIViewAnimationOptions.BeginFromCurrentState,
                               () =>
                    {
                        CurrentView.Transform      = CGAffineTransform.MakeScale(1.1f, 1.1f);
                        highlightedImageView.Alpha = 0.0f;
                        imageView.Alpha            = 1.0f;
                    },
                               () =>
                    {
                        highlightedImageView.RemoveFromSuperview();
                        OnDidBegingDraggingItem(SelectedItemIndexPath);
                    });
                InvalidateLayout();
            }
            break;

            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Ended:
            {
                var currentIndexPath = SelectedItemIndexPath;
                if (currentIndexPath == null)
                {
                    return;
                }
                SelectedItemIndexPath = null;
                CurrentViewCenter     = PointF.Empty;

                OnWillEndDraggingItem(currentIndexPath);

                UIView.Animate(0.3, 0.0, UIViewAnimationOptions.BeginFromCurrentState,
                               () =>
                    {
                        var layoutAttributes  = LayoutAttributesForItem(currentIndexPath);
                        CurrentView.Transform = CGAffineTransform.MakeScale(1.0f, 1.0f);
                        CurrentView.Center    = layoutAttributes.Center;
                    },
                               () =>
                    {
                        CurrentView.RemoveFromSuperview();
                        CurrentView = null;
                        InvalidateLayout();

                        OnDidEndDraggingItem(currentIndexPath);
                    });
            }
            break;
            }
        }