Пример #1
0
        public MvxRecyclerView(Context context, IAttributeSet attrs, int defStyle, IMvxRecyclerAdapter adapter) : base(context, attrs, defStyle)
        {
            // Note: Any calling derived class passing a null adapter is responsible for setting
            // it's own ItemTemplateSelector
            if (adapter == null)
            {
                return;
            }

            if (base.GetLayoutManager() == null)
            {
                SetLayoutManager(new LinearLayoutManager(context));
            }

            var itemTemplateId       = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);
            var itemTemplateSelector = MvxRecyclerViewAttributeExtensions.BuildItemTemplateSelector(context, attrs);

            adapter.ItemTemplateSelector = itemTemplateSelector;
            Adapter = adapter;

            if (itemTemplateSelector.GetType() == typeof(MvxDefaultTemplateSelector))
            {
                ItemTemplateId = itemTemplateId;
            }

            HidesHeaderIfEmpty = MvxRecyclerViewAttributeExtensions.IsHidesHeaderIfEmptyEnabled(context, attrs);
            HidesFooterIfEmpty = MvxRecyclerViewAttributeExtensions.IsHidesFooterIfEmptyEnabled(context, attrs);

            if (MvxRecyclerViewAttributeExtensions.IsGroupingSupported(context, attrs))
            {
                GroupedDataConverter = MvxRecyclerViewAttributeExtensions.BuildMvxGroupedDataConverter(context, attrs);
            }
        }
Пример #2
0
        public MvxRecyclerView(Context context, IAttributeSet attrs, int defStyle, IMvxRecyclerAdapter adapter) : base(context, attrs, defStyle)
        {
            // Note: Any calling derived class passing a null adapter is responsible for setting
            // it's own ItemTemplateSelector
            if (adapter == null)
            {
                return;
            }

            var currentLayoutManager = base.GetLayoutManager();

            // Love you Android
            // https://code.google.com/p/android/issues/detail?id=77846#c10
            // Don't believe those bastards, it's not fixed - workaround hack hack hack
            if (currentLayoutManager == null)
            {
                SetLayoutManager(new MvxGuardedLinearLayoutManager(context));
            }

            if (currentLayoutManager is LinearLayoutManager)
            {
                var currentLinearLayoutManager = currentLayoutManager as LinearLayoutManager;
                SetLayoutManager(new MvxGuardedLinearLayoutManager(context)
                {
                    Orientation = currentLinearLayoutManager.Orientation
                });
            }

            var itemTemplateId       = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);
            var itemTemplateSelector = MvxRecyclerViewAttributeExtensions.BuildItemTemplateSelector(context, attrs);

            adapter.ItemTemplateSelector = itemTemplateSelector;
            Adapter = adapter;

            if (itemTemplateSelector.GetType() == typeof(MvxDefaultTemplateSelector))
            {
                ItemTemplateId = itemTemplateId;
            }

            HidesHeaderIfEmpty = MvxRecyclerViewAttributeExtensions.IsHidesHeaderIfEmptyEnabled(context, attrs);
            HidesFooterIfEmpty = MvxRecyclerViewAttributeExtensions.IsHidesFooterIfEmptyEnabled(context, attrs);

            if (MvxRecyclerViewAttributeExtensions.IsGroupingSupported(context, attrs))
            {
                GroupedDataConverter = MvxRecyclerViewAttributeExtensions.BuildMvxGroupedDataConverter(context, attrs);
            }
        }