コード例 #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);
            _view          = this.BindingInflate(Resource.Layout.fragment_favorite_news, container, false);
            _mRecyclerView = _view.FindViewById <MvxAdvancedNonExpandableRecyclerView>(Resource.Id.favorite_RecyclerView);

            _mLayoutManager = new LinearLayoutManager(_view.Context, LinearLayoutManager.Vertical, reverseLayout: true)
            {
                ReverseLayout = true,
            };
            _mRecyclerView.SetLayoutManager(_mLayoutManager);
            var dividerItemDecoration = new DividerItemDecoration(_view.Context, _mLayoutManager.Orientation);

            dividerItemDecoration.SetDrawable(ContextCompat.GetDrawable(_view.Context, Resource.Drawable.recycler_view_divider));
            _mRecyclerView.AddItemDecoration(dividerItemDecoration);

            _mAdapter = _mRecyclerView.AdvancedRecyclerViewAdapter as MvxNonExpandableAdapter;
            _mAdapter.SwipeItemPinnedStateController.ForLeftSwipe().Pinned += RemoveItem;

            _mAdapter.MvxViewHolderBound += (args) =>
            {
                var swipeHolder = args.Holder as MvxAdvancedRecyclerViewHolder;
                var swipeState  = swipeHolder.SwipeStateFlags;

                swipeHolder.ProportionalSwipeAmountModeEnabled = true;

                swipeHolder.MaxLeftSwipeAmount = -0.5f;

                _mAdapter.SwipeItemPinnedStateController.SetPinnedForAllStates(args.DataContext, false);

                swipeHolder.SwipeItemHorizontalSlideAmount = _mAdapter.SwipeItemPinnedStateController.ForRightSwipe().IsPinned(args.DataContext) ? -0.5f : 0;
            };

            _mAdapter.SwipeBackgroundSet += (args) =>
            {
                int bgRes = 0;
                switch (args.Type)
                {
                case SwipeableItemConstants.DrawableSwipeNeutralBackground:
                    bgRes = Resource.Drawable.bg_swipe_item_neutral;
                    break;

                case SwipeableItemConstants.DrawableSwipeLeftBackground:
                    bgRes = Resource.Drawable.bg_item_swiping_right_state;
                    break;
                }

                if (bgRes != 0)
                {
                    args.ViewHolder.ItemView.SetBackgroundResource(bgRes);
                }
            };

            return(_view);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.swipe_example);

            mRecyclerView = FindViewById <MvxAdvancedNonExpandableRecyclerView>(Resource.Id.RecyclerView);

            var mAdapter = mRecyclerView.AdvancedRecyclerViewAdapter as MvxNonExpandableAdapter;

            mAdapter.SwipeResultActionFactory = new SwipeResultActionFactory();

            mAdapter.MvxViewHolderBound += (args) =>
            {
                var swipeHolder = args.Holder as MvxAdvancedRecyclerViewHolder;
                var swipeState  = swipeHolder.SwipeStateFlags;

                if ((swipeState & SwipeableItemConstants.StateFlagIsUpdated & 0) == 0)
                {
                    int backgroundResourceId;
                    if ((swipeState & SwipeableItemConstants.StateFlagIsActive) != 0)
                    {
                        backgroundResourceId = Resource.Drawable.bg_item_swiping_active_state;
                    }
                    else if ((swipeState & SwipeableItemConstants.StateFlagSwiping) != 0)
                    {
                        backgroundResourceId = Resource.Drawable.bg_item_swiping_state;
                    }
                    else
                    {
                        backgroundResourceId = Resource.Drawable.bg_item_normal_state;
                    }
                    swipeHolder.UnderSwipeableContainerView.SetBackgroundResource(backgroundResourceId);
                }

                swipeHolder.MaxLeftSwipeAmount  = -0.5f;
                swipeHolder.MaxRightSwipeAmount = 0;

                swipeHolder.SwipeItemHorizontalSlideAmount =
                    mAdapter.SwipeItemPinnedStateController.ForRightSwipe().IsPinned(args.DataContext) ? -0.5f : 0;
            };

            mAdapter.SwipeBackgroundSet += (args) =>
            {
                int bgRes = 0;
                switch (args.Type)
                {
                case SwipeableItemConstants.DrawableSwipeNeutralBackground:
                    bgRes = Resource.Drawable.bg_swipe_item_neutral;
                    break;

                case SwipeableItemConstants.DrawableSwipeLeftBackground:
                    bgRes = Resource.Drawable.bg_item_swiping_state;
                    break;
                }

                if (bgRes != 0)
                {
                    args.ViewHolder.ItemView.SetBackgroundResource(bgRes);
                }
            };
        }