protected override RecyclerView.Adapter BuildWrappedAdapter(IMvxTemplateSelector templateSelector)
        {
            var advancedRecyclerViewAdapter = new MvxNonExpandableAdapter(BindingContext);

            RecyclerView.Adapter adapter = advancedRecyclerViewAdapter;

            var itemUniqueIdProvider =
                MvxAdvancedRecyclerViewAttributeExtensions.BuildUniqueItemIdProvider(Context, Attrs);

            advancedRecyclerViewAdapter.UniqueIdProvider     = itemUniqueIdProvider;
            advancedRecyclerViewAdapter.ItemTemplateSelector = templateSelector;

            AdvancedRecyclerViewAdapter = advancedRecyclerViewAdapter;

            bool isSwipeEnabled = MvxAdvancedRecyclerViewAttributeExtensions.IsSwipeSupported(Context, Attrs);

            if (isSwipeEnabled)
            {
                var swipeableTemplate =
                    MvxAdvancedRecyclerViewAttributeExtensions.BuildSwipeableTemplate(Context, Attrs);
                advancedRecyclerViewAdapter.SwipeableTemplate = swipeableTemplate;

                _mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
                _mRecyclerViewTouchActionGuardManager.SetInterceptVerticalScrollingWhileAnimationRunning(true);
                _mRecyclerViewTouchActionGuardManager.Enabled = true;

                _mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();
                return(_mRecyclerViewSwipeManager.CreateWrappedAdapter(advancedRecyclerViewAdapter));
            }

            return(advancedRecyclerViewAdapter);
        }
        protected override RecyclerView.Adapter BuildWrappedAdapter(IMvxTemplateSelector templateSelector)
        {
            bool isGroupingSupported = MvxAdvancedRecyclerViewAttributeExtensions.IsGroupingSupported(Context, Attrs);

            if (!isGroupingSupported)
            {
                throw new InvalidOperationException($"You are using {nameof(MvxAdvancedExpandableRecyclerView)} without using grouping attributes. Check documentation.");
            }

            expandableItemManager = new RecyclerViewExpandableItemManager(expandCollapseSavedState);
            var expandableAdapter = new MvxExpandableItemAdapter(BindingContext as IMvxAndroidBindingContext);

            expandableAdapter.TemplateSelector               = templateSelector;
            expandableAdapter.GroupExpandController          = MvxAdvancedRecyclerViewAttributeExtensions.BuildGroupExpandController(Context, Attrs);
            expandableItemManager.DefaultGroupsExpandedState = expandableAdapter.GroupExpandController.AreGroupsExpandedByDefault;
            expandableAdapter.GroupExpandController.ExpandableItemManager = expandableItemManager;

            AdvancedRecyclerViewAdapter = expandableAdapter;
            var groupedDataConverter = MvxAdvancedRecyclerViewAttributeExtensions.BuildMvxGroupedDataConverter(Context, Attrs);

            expandableAdapter.ExpandableDataConverter = groupedDataConverter;
            wrappedAdapter = expandableItemManager.CreateWrappedAdapter(expandableAdapter);

            return(wrappedAdapter);
        }
        public static IMvxTemplateSelector BuildItemTemplateSelector(Context context, IAttributeSet attrs)
        {
            var templateSelectorAttributes = ReadRecyclerViewItemTemplateSelectorAttributes(context, attrs);
            var type = Type.GetType(templateSelectorAttributes.TemplateSelectorClassName);

            if (type == null && templateSelectorAttributes.ItemTemplateLayoutId == 0)
            {
                var message = $"Cant create template selector." +
                              $"Sorry but type with class name: {templateSelectorAttributes.TemplateSelectorClassName} does not exist." +
                              $"Make sure you have provided full Type name: namespace + class name, AssemblyName." +
                              $"Example (check Example.Droid sample!): Example.Droid.Common.TemplateSelectors.MultiItemTemplateModelTemplateSelector, Example.Droid";
                Mvx.Resolve <IMvxLog>().Log(MvxLogLevel.Error, () => message);
                throw new InvalidOperationException(message);
            }

            if (type != null && !typeof(IMvxTemplateSelector).IsAssignableFrom(type))
            {
                string message = $"Sorry but type: {type} does not implement {nameof(IMvxTemplateSelector)} interface.";
                Mvx.Resolve <IMvxLog>().Log(MvxLogLevel.Error, () => message);
                throw new InvalidOperationException(message);
            }

            if (type?.IsAbstract ?? false)
            {
                string message = $"Sorry can not instatiate {nameof(IMvxTemplateSelector)} as provided type: {type} is abstract/interface.";
                Mvx.Resolve <IMvxLog>().Log(MvxLogLevel.Error, () => message);
                throw new InvalidOperationException(message);
            }

            IMvxTemplateSelector templateSelector = null;

            if (type != null)
            {
                templateSelector = Activator.CreateInstance(type) as IMvxTemplateSelector;
            }
            else
            {
                templateSelector = new MvxDefaultHeaderFooterTemplateSelector(templateSelectorAttributes.ItemTemplateLayoutId);
            }

            var headerTemplate = templateSelector as IMvxHeaderTemplate;
            var footerTemplate = templateSelector as IMvxFooterTemplate;

            if (headerTemplate != null)
            {
                headerTemplate.HeaderLayoutId = templateSelectorAttributes.HeaderLayoutId;
            }

            if (footerTemplate != null)
            {
                footerTemplate.FooterLayoutId = templateSelectorAttributes.FooterLayoutId;
            }

            return(templateSelector);
        }
        protected override RecyclerView.Adapter BuildWrappedAdapter(IMvxTemplateSelector templateSelector)
        {
            bool isGroupingSupported = MvxAdvancedRecyclerViewAttributeExtensions.IsGroupingSupported(Context, Attrs);

            if (!isGroupingSupported)
            {
                throw new InvalidOperationException($"You are using {nameof(MvxAdvancedExpandableRecyclerView)} without using grouping attributes. Check documentation.");
            }

            expandableItemManager = new RecyclerViewExpandableItemManager(expandCollapseSavedState);
            var expandableAdapter = new MvxExpandableItemAdapter(BindingContext as IMvxAndroidBindingContext);

            expandableAdapter.TemplateSelector               = templateSelector;
            expandableAdapter.GroupExpandController          = MvxAdvancedRecyclerViewAttributeExtensions.BuildGroupExpandController(Context, Attrs);
            expandableItemManager.DefaultGroupsExpandedState = expandableAdapter.GroupExpandController.AreGroupsExpandedByDefault;
            expandableAdapter.GroupExpandController.ExpandableItemManager = expandableItemManager;

            AdvancedRecyclerViewAdapter = expandableAdapter;
            var groupedDataConverter = MvxAdvancedRecyclerViewAttributeExtensions.BuildMvxGroupedDataConverter(Context, Attrs);

            expandableAdapter.ExpandableDataConverter = groupedDataConverter;
            wrappedAdapter = expandableItemManager.CreateWrappedAdapter(expandableAdapter);

            bool isSwipeForExpandableSupported = MvxAdvancedRecyclerViewAttributeExtensions.IsSwipeForExpandableSupported(Context, Attrs);

            if (isSwipeForExpandableSupported)
            {
                if (MvxAdvancedRecyclerViewAttributeExtensions.IsGroupedSwipeSupported(Context, Attrs))
                {
                    var groupedSwipeableTemplate =
                        MvxAdvancedRecyclerViewAttributeExtensions.BuildGroupSwipeableTemplate(Context, Attrs);
                    expandableAdapter.GroupSwipeableTemplate = groupedSwipeableTemplate;
                }

                if (MvxAdvancedRecyclerViewAttributeExtensions.IsGroupedChildSwipeSupported(Context, Attrs))
                {
                    var childSwipeableTemplate =
                        MvxAdvancedRecyclerViewAttributeExtensions.BuildGroupChildSwipeableTemplate(Context, Attrs);
                    expandableAdapter.ChildSwipeableTemplate = childSwipeableTemplate;
                }

                _mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
                _mRecyclerViewTouchActionGuardManager.SetInterceptVerticalScrollingWhileAnimationRunning(true);
                _mRecyclerViewTouchActionGuardManager.Enabled = true;

                _mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();
                return(_mRecyclerViewSwipeManager.CreateWrappedAdapter(wrappedAdapter));
            }

            return(wrappedAdapter);
        }
        private Data.MvxHeaderFooterDetails BuildHeaderFooterDetails(IMvxTemplateSelector templateSelector)
        {
            var headerFooterDetails = new Data.MvxHeaderFooterDetails();
            var headerTemplate      = templateSelector as IMvxHeaderTemplate;
            var footerTemplate      = templateSelector as IMvxFooterTemplate;

            if (headerTemplate != null)
            {
                headerFooterDetails.HeaderLayoutId = headerTemplate.HeaderLayoutId;
            }
            if (footerTemplate != null)
            {
                headerFooterDetails.FooterLayoutId = footerTemplate.FooterLayoutId;
            }

            return(headerFooterDetails);
        }
 protected abstract RecyclerView.Adapter BuildWrappedAdapter(IMvxTemplateSelector templateSelector);
Ejemplo n.º 7
0
 public ShimmerItemTemplateSelector(IMvxTemplateSelector templateSelector, int shimmerTemplateId)
     : this(shimmerTemplateId)
 {
     this.templateSelector    = templateSelector;
     this.hasTemplateSelector = true;
 }
 public DraggableRecyclerAdapter(IMvxAndroidBindingContext bindingContext, IItemDragStartListener mDragListener, IMvxTemplateSelector itemTemplateSelector) : base(bindingContext)
 {
     ItemTemplateSelector = itemTemplateSelector;
     this.mDragListener   = mDragListener;
     this.bindingContext  = bindingContext;
 }