protected virtual void LoadView(IShellContext shellContext)
        {
            var context = shellContext.AndroidContext;

            // Android designer can't load fragments or resources from layouts
            if (context.IsDesignerContext())
            {
                _rootView = new FrameLayout(context);
                return;
            }

            var coordinator = LayoutInflater.FromContext(context).Inflate(Resource.Layout.FlyoutContent, null);
            var recycler    = coordinator.FindViewById <RecyclerView>(Resource.Id.flyoutcontent_recycler);
            var appBar      = coordinator.FindViewById <AppBarLayout>(Resource.Id.flyoutcontent_appbar);

            _rootView = coordinator;

            appBar.AddOnOffsetChangedListener(this);

            int actionBarHeight = (int)context.ToPixels(56);

            _headerView = new HeaderContainer(context, ((IShellController)shellContext.Shell).FlyoutHeader)
            {
                MatchWidth = true
            };
            _headerView.SetMinimumHeight(actionBarHeight);
            _headerView.LayoutParameters = new AppBarLayout.LayoutParams(LP.MatchParent, LP.WrapContent)
            {
                ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll
            };
            appBar.AddView(_headerView);

            var adapter = new ShellFlyoutRecyclerAdapter(shellContext, OnElementSelected);

            recycler.SetPadding(0, (int)context.ToPixels(20), 0, 0);
            recycler.SetClipToPadding(false);
            recycler.SetLayoutManager(new LinearLayoutManager(context, (int)Orientation.Vertical, false));
            recycler.SetAdapter(adapter);

            var metrics = context.Resources.DisplayMetrics;
            var width   = Math.Min(metrics.WidthPixels, metrics.HeightPixels);

            using (TypedValue tv = new TypedValue())
            {
                if (context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ActionBarSize, tv, true))
                {
                    actionBarHeight = TypedValue.ComplexToDimensionPixelSize(tv.Data, metrics);
                }
            }

            width -= actionBarHeight;

            coordinator.LayoutParameters = new LP(width, LP.MatchParent);

            UpdateFlyoutHeaderBehavior();
            _shellContext.Shell.PropertyChanged += OnShellPropertyChanged;

            UpdateFlyoutBackgroundColor();
        }
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                _shellContext.Shell.PropertyChanged -= OnShellPropertyChanged;

                if (_flyoutHeader != null)
                {
                    _flyoutHeader.MeasureInvalidated -= OnFlyoutHeaderMeasureInvalidated;
                }

                if (_appBar != null)
                {
                    _appBar.RemoveOnOffsetChangedListener(this);
                    _appBar.RemoveView(_headerView);
                }

                if (_rootView != null && _footerView?.NativeView != null)
                {
                    _rootView.RemoveView(_footerView.NativeView);
                }

                if (_recycler != null)
                {
                    _recycler.SetLayoutManager(null);
                    _recycler.SetAdapter(null);
                    _recycler.Dispose();
                }

                _adapter?.Dispose();
                _headerView.Dispose();
                _footerView?.TearDown();
                _rootView.Dispose();
                _layoutManager?.Dispose();
                _defaultBackgroundColor?.Dispose();
                _bgImage?.Dispose();

                _flyoutHeader           = null;
                _rootView               = null;
                _headerView             = null;
                _shellContext           = null;
                _appBar                 = null;
                _recycler               = null;
                _adapter                = null;
                _defaultBackgroundColor = null;
                _layoutManager          = null;
                _bgImage                = null;
                _footerView             = null;
            }

            base.Dispose(disposing);
        }
示例#3
0
 public RecyclerViewContainer(Context context, ShellFlyoutRecyclerAdapter shellFlyoutRecyclerAdapter) : base(context)
 {
     _shellFlyoutRecyclerAdapter = shellFlyoutRecyclerAdapter;
     SetClipToPadding(false);
     SetLayoutManager(_layoutManager = new ScrollLayoutManager(context, (int)Orientation.Vertical, false));
     SetLayoutManager(new LinearLayoutManager(context, (int)Orientation.Vertical, false));
     SetAdapter(_shellFlyoutRecyclerAdapter);
 }
示例#4
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;
            if (disposing)
            {
                SetLayoutManager(null);
                SetAdapter(null);
                _shellFlyoutRecyclerAdapter?.Dispose();
                _layoutManager?.Dispose();
                _shellFlyoutRecyclerAdapter = null;
                _layoutManager = null;
            }

            base.Dispose(disposing);
        }
示例#5
0
        protected virtual void LoadView(IShellContext shellContext)
        {
            Profile.FrameBegin();

            var context = shellContext.AndroidContext;

            // Android designer can't load fragments or resources from layouts
            if (context.IsDesignerContext())
            {
                _rootView = new FrameLayout(context);
                return;
            }

            var coordinator = LayoutInflater.FromContext(context).Inflate(Resource.Layout.FlyoutContent, null);

            Profile.FramePartition("Find Recycler");
            var recycler = coordinator.FindViewById <RecyclerView>(Resource.Id.flyoutcontent_recycler);

            Profile.FramePartition("Find AppBar");
            var appBar = coordinator.FindViewById <AppBarLayout>(Resource.Id.flyoutcontent_appbar);

            _rootView = coordinator as ViewGroup;

            Profile.FramePartition("Add Listener");
            appBar.AddOnOffsetChangedListener(this);

            Profile.FramePartition("Add HeaderView");
            _actionBarHeight = (int)context.ToPixels(56);

            _flyoutHeader = ((IShellController)shellContext.Shell).FlyoutHeader;
            if (_flyoutHeader != null)
            {
                _flyoutHeader.MeasureInvalidated += OnFlyoutHeaderMeasureInvalidated;
            }

            _headerView = new HeaderContainer(context, _flyoutHeader)
            {
                MatchWidth = true
            };
            _headerView.SetMinimumHeight(_actionBarHeight);
            _headerView.LayoutParameters = new AppBarLayout.LayoutParams(LP.MatchParent, LP.WrapContent)
            {
                ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll
            };
            appBar.AddView(_headerView);

            Profile.FramePartition("Recycler.SetAdapter");
            var adapter = new ShellFlyoutRecyclerAdapter(shellContext, OnElementSelected);

            recycler.SetClipToPadding(false);
            recycler.SetLayoutManager(_layoutManager = new ScrollLayoutManager(context, (int)Orientation.Vertical, false));
            recycler.SetAdapter(adapter);

            Profile.FramePartition("Initialize BgImage");
            var metrics = context.Resources.DisplayMetrics;
            var width   = Math.Min(metrics.WidthPixels, metrics.HeightPixels);

            using (TypedValue tv = new TypedValue())
            {
                if (context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ActionBarSize, tv, true))
                {
                    _actionBarHeight = TypedValue.ComplexToDimensionPixelSize(tv.Data, metrics);
                }
            }

            width -= _actionBarHeight;

            coordinator.LayoutParameters = new LP(width, LP.MatchParent);

            _bgImage = new ImageView(context)
            {
                LayoutParameters = new LP(coordinator.LayoutParameters)
            };

            Profile.FramePartition("UpdateFlyoutHeaderBehavior");
            UpdateFlyoutHeaderBehavior();
            _shellContext.Shell.PropertyChanged += OnShellPropertyChanged;

            Profile.FramePartition("UpdateFlyoutBackground");
            UpdateFlyoutBackground();

            Profile.FrameEnd();

            Profile.FramePartition(nameof(UpdateVerticalScrollMode));
            UpdateVerticalScrollMode();
            Profile.FrameEnd();
        }