Ejemplo n.º 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;
            }

            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));
            }

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

            adapter.ItemTemplateSelector = itemTemplateSelector;
            Adapter = adapter;

            if (itemTemplateSelector.GetType() == typeof(MvxDefaultTemplateSelector))
            {
                ItemTemplateId = itemTemplateId;
            }
        }
Ejemplo n.º 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 = GetLayoutManager();

            if (currentLayoutManager == null)
#pragma warning disable CA2000 // Dispose objects before losing scope
            {
                SetLayoutManager(new MvxGuardedLinearLayoutManager(context));
            }
#pragma warning restore CA2000 // Dispose objects before losing scope

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

            adapter.ItemTemplateSelector = itemTemplateSelector;
            Adapter = adapter;

            if (itemTemplateId == 0)
            {
                itemTemplateId = global::Android.Resource.Layout.SimpleListItem1;
            }

            if (itemTemplateSelector.GetType() == typeof(MvxDefaultTemplateSelector))
            {
                ItemTemplateId = itemTemplateId;
            }
        }
Ejemplo n.º 3
0
        public MvxHorizontalGridView(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 itemTemplateId
            if (adapter == null)
            {
                return;
            }

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

            adapter.ItemTemplateId = itemTemplateId;
            Adapter = adapter;

            var typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.MvxHorizontalGridView);

            try
            {
                FocusFirstChildOnLaidOut = typedArray.GetBoolean(Resource.Styleable.MvxHorizontalGridView_FocusFirstChildOnLaidOut, false);
                if (FocusFirstChildOnLaidOut)
                {
                    SetOnChildLaidOutListener(new MvxFocusFirstChildOnChildLaidOutListener());
                }
            }
            finally
            {
                typedArray.Recycle();
            }

            // We need this listener to get information about the currently _selected_ item
            // Overriding setter of base.SelectedPosition is not enough!
            OnChildViewHolderSelectedListener = new MvxOnChildViewHolderSelectedListener();
            SetOnChildViewHolderSelectedListener(OnChildViewHolderSelectedListener);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public BindableViewPager(Context context, IAttributeSet attrs, MvxBindablePagerAdapter adapter)
            : base(context, attrs)
        {
            var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);

            adapter.ItemTemplateId = itemTemplateId;
            Adapter = adapter;
        }
Ejemplo n.º 6
0
        public MvxAppCompatAutoCompleteTextView(Context context, IAttributeSet attrs,
                                                MvxFilteringAdapter adapter) : base(context, attrs)
        {
            var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);

            adapter.ItemTemplateId = itemTemplateId;
            Adapter    = adapter;
            ItemClick += OnItemClick;
        }
        public BindableViewPager(Context context, IAttributeSet attrs, MvxBindablePagerAdapter adapter)
            : base(context, attrs)
        {
            this._initialIndex      = attrs.GetAttributeIntValue("http://schemas.android.com/apk/res-auto", "selectedIndex", -1);
            this.OffscreenPageLimit = attrs.GetAttributeIntValue("http://schemas.android.com/apk/res-auto", "offscreenPageLimit", 1);

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

            adapter.ItemTemplateId = itemTemplateId;
            Adapter = adapter;
        }
Ejemplo n.º 8
0
        public MvxAppCompatSpinner(Context context, IAttributeSet attrs, IMvxAdapter adapter)
            : base(context, attrs)
        {
            var itemTemplateId         = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);
            var dropDownItemTemplateId = MvxAttributeHelpers.ReadDropDownListItemTemplateId(context, attrs);

            adapter.ItemTemplateId         = itemTemplateId;
            adapter.DropDownItemTemplateId = dropDownItemTemplateId;
            Adapter       = adapter;
            ItemSelected += OnItemSelected;
        }
Ejemplo n.º 9
0
    public MvxSpinnerIndexer(Context context, IAttributeSet attrs, IMvxAdapter adapter)
        : base(context, attrs)
    {
        var itemTemplateId         = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);
        var dropDownItemTemplateId = MvxAttributeHelpers.ReadDropDownListItemTemplateId(context, attrs);

        adapter.ItemTemplateId         = itemTemplateId;
        adapter.DropDownItemTemplateId = dropDownItemTemplateId;
        Adapter = adapter;
        SetupHandleItemSelected();
    }
Ejemplo n.º 10
0
        public MvxAppCompatRadioGroup(Context context, IAttributeSet attrs, IMvxAdapterWithChangedEvent adapter)
            : base(context, attrs)
        {
            var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);

            if (adapter != null)
            {
                this.Adapter = adapter;
                this.Adapter.ItemTemplateId = itemTemplateId;
            }

            this.ChildViewAdded   += this.OnChildViewAdded;
            this.ChildViewRemoved += this.OnChildViewRemoved;
        }
        public BindableExpandableListView(Context context, IAttributeSet attrs, BindableExpandableListAdapter adapter)
            : base(context, attrs)
        {
            var groupTemplateId = MvxAttributeHelpers.ReadAttributeValue(context, attrs,
                                                                         MvxAndroidBindingResource.Instance
                                                                         .ListViewStylableGroupId,
                                                                         AndroidBindingResource.Instance
                                                                         .BindableListGroupItemTemplateId);

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

            SetAdapter(adapter);
            adapter.GroupTemplateId = groupTemplateId;
            adapter.ItemTemplateId  = itemTemplateId;
        }
Ejemplo n.º 12
0
        public MvxAppCompatListView(Context context, IAttributeSet attrs, IMvxAdapter adapter)
            : base(context, attrs)
        {
            // Note: Any calling derived class passing a null adapter is responsible for setting
            // it's own itemTemplateId
            if (adapter == null)
            {
                return;
            }

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

            adapter.ItemTemplateId = itemTemplateId;
            this.Adapter           = adapter;
        }
Ejemplo n.º 13
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 itemTemplateId
            if (adapter == null)
            {
                return;
            }

            SetLayoutManager(new LinearLayoutManager(context));

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

            adapter.ItemTemplateId = itemTemplateId;
            Adapter = adapter;
        }
Ejemplo n.º 14
0
        public MvxAppCompatAutoCompleteTextView(Context context, IAttributeSet attrs,
                                                MvxFilteringAdapter adapter)
            : base(context, attrs)
        {
            var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);

            if (itemTemplateId > 0)
            {
                adapter.ItemTemplateId = itemTemplateId;
            }

            Adapter = adapter;

            // note - we shouldn't realy need both of these... but we do
            ItemClick    += OnItemClick;
            ItemSelected += OnItemSelected;
        }
Ejemplo n.º 15
0
        public MvxListViewWithHeader(Context context, IAttributeSet attrs)
            : base(context, attrs, null)
        {
            IMvxAdapter adapter = new MvxAdapter(context);

            ApplyAttributes(context, attrs);

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

            adapter.ItemTemplateId = itemTemplateId;

            var headers = GetHeaders();
            var footers = GetFooters();

            IMvxAdapter headerAdapter = new HeaderMvxAdapter(headers, footers, adapter);

            Adapter = headerAdapter;
        }
Ejemplo n.º 16
0
        public MvxListViewWithHeader(Context context, IAttributeSet attrs) : base(context, attrs, null)
        {
            var headerId = MvxAttributeHelpers.ReadAttributeValue(context, attrs, MvxAndroidBindingResource.Instance.ListViewStylableGroupId,
                                                                  AndroidBindingResource.Instance.MvxListViewWithHeader_HeaderLayout);
            var footerId = MvxAttributeHelpers.ReadAttributeValue(context, attrs, MvxAndroidBindingResource.Instance.ListViewStylableGroupId,
                                                                  AndroidBindingResource.Instance.MvxListViewWithHeader_FooterLayout);

            var headers = GetFixedViewInfos(headerId);
            var footers = GetFixedViewInfos(footerId);

            var adapter = new MvxAdapter(context);

            adapter.ItemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);

            var headerAdapter = new HeaderMvxAdapter(headers, footers, adapter);

            Adapter = headerAdapter;
        }
Ejemplo n.º 17
0
        public BindableExpandableListView(Context context, IAttributeSet attrs)
            : base(context, attrs)
        {
            var expandableAdapter = new BindableExpandableListAdapter(context);

            var groupTemplateId = MvxAttributeHelpers.ReadAttributeValue(context, attrs,
                                                                         MvxAndroidBindingResource.Instance
                                                                         .ListViewStylableGroupId,
                                                                         AndroidBindingResource.Instance
                                                                         .BindableListGroupItemTemplateId);

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

            expandableAdapter.GroupTemplateId = groupTemplateId;
            expandableAdapter.ItemTemplateId  = itemTemplateId;

            SetAdapter(expandableAdapter);

            InitHeaders(context, attrs);
            InitFooters(context, attrs);
        }
Ejemplo n.º 18
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;
            }

            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;
            }
        }
Ejemplo n.º 19
0
 public ARViewPager(Context context, IAttributeSet attrs)
     : base(context, attrs)
 {
     ItemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);
 }
        static MvxAdvancedRecyclerViewAttributes ReadRecyclerViewItemTemplateSelectorAttributes(Context context, IAttributeSet attrs)
        {
            TryInitializeBindingResourcePaths();

            TypedArray typedArray = null;

            string templateSelectorClassName       = string.Empty;
            string groupedDataConverterClassName   = string.Empty;
            string groupExpandControllerClassName  = string.Empty;
            string swipeableTemplateClassName      = string.Empty;
            string uniqueItemIdProviderClassName   = string.Empty;
            string groupSwipeableTemplateClassName = string.Empty;
            string childSwipeableTemplateClassName = string.Empty;

            int headerLayoutId = 0;
            int footerLayoutId = 0;

            try
            {
                typedArray = context.ObtainStyledAttributes(attrs, MvxRecyclerViewGroupId);
                int numberOfStyles = typedArray.IndexCount;

                for (int i = 0; i < numberOfStyles; ++i)
                {
                    var attributeId = typedArray.GetIndex(i);

                    if (attributeId == MvxRecyclerViewGroupExpandController)
                    {
                        groupExpandControllerClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewItemTemplateSelector)
                    {
                        templateSelectorClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewHeaderLayoutId)
                    {
                        headerLayoutId = typedArray.GetResourceId(attributeId, 0);
                    }
                    if (attributeId == MvxRecyclerViewFooterLayoutId)
                    {
                        footerLayoutId = typedArray.GetResourceId(attributeId, 0);
                    }
                    if (attributeId == MvxRecyclerViewGroupedDataConverter)
                    {
                        groupedDataConverterClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewSwipeableTemplate)
                    {
                        swipeableTemplateClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewUniqueItemIdProvider)
                    {
                        uniqueItemIdProviderClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewGroupSwipeableTemplate)
                    {
                        groupSwipeableTemplateClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewChildSwipeableTemplate)
                    {
                        childSwipeableTemplateClassName = typedArray.GetString(attributeId);
                    }
                }
            }
            finally
            {
                typedArray?.Recycle();
            }

            if (string.IsNullOrEmpty(templateSelectorClassName))
            {
                templateSelectorClassName = typeof(MvxDefaultTemplateSelector).FullName;
            }
            if (string.IsNullOrEmpty(groupExpandControllerClassName))
            {
                groupExpandControllerClassName = typeof(DefaultMvxGroupExpandController).FullName;
            }

            return(new MvxAdvancedRecyclerViewAttributes()
            {
                TemplateSelectorClassName = templateSelectorClassName,
                ItemTemplateLayoutId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs),
                FooterLayoutId = footerLayoutId,
                HeaderLayoutId = headerLayoutId,
                GroupedDataConverterClassName = groupedDataConverterClassName,
                GroupExpandControllerClassName = groupExpandControllerClassName,
                SwipeableTemplateClassName = swipeableTemplateClassName,
                UniqueItemIdProviderClassName = uniqueItemIdProviderClassName,
                GroupSwipeableTemplateClassName = groupSwipeableTemplateClassName,
                ChildSwipeableTemplateClassName = childSwipeableTemplateClassName
            });
        }