Exemplo 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 = 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;
            }
        }
Exemplo 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;
            }

            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);
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 public HeaderListView(Context context, IAttributeSet attrs, HeaderAdapter adapter)
     : base(context, attrs, adapter)
 {
     if (attrs != null)
     {
         HeaderTemplateId = MvxAttributeHelpers.ReadAttributeValue(context, attrs, Resource.Styleable.HeaderListView, Resource.Styleable.HeaderListView_HeaderTemplate);
     }
 }
Exemplo n.º 6
0
        public BindableViewPager(Context context, IAttributeSet attrs, MvxBindablePagerAdapter adapter)
            : base(context, attrs)
        {
            var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);

            adapter.ItemTemplateId = itemTemplateId;
            Adapter = adapter;
        }
Exemplo n.º 7
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 MvxSectionedRecyclerView(Context context, IAttributeSet attrs) : base(context, attrs)
        {
            //create the adapter with parameters from attributes
            var headerTemplateId = MvxAttributeHelpers.ReadAttributeValue(context, attrs,
                                                                          MvxAndroidBindingResource.Instance.ExpandableListViewStylableGroupId,
                                                                          MvxAndroidBindingResource.Instance.GroupItemTemplateId);
            IMvxRecyclerAdapter adapter = new MvxSectionedRecyclerAdapter(false, headerTemplateId);

            Adapter = adapter;
        }
Exemplo 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();
    }
Exemplo n.º 10
0
        public BindableGroupListView(Context context, IAttributeSet attrs, BindableGroupListAdapter adapter)
            : base(context, attrs, adapter)
        {
            var groupTemplateId = MvxAttributeHelpers.ReadAttributeValue(context, attrs,
                                                                         MvxAndroidBindingResource.Instance
                                                                         .ListViewStylableGroupId,
                                                                         AndroidBindingResource.Instance
                                                                         .BindableListGroupItemTemplateId);

            adapter.GroupTemplateId = groupTemplateId;
        }
        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;
        }
Exemplo n.º 12
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;
        }
Exemplo n.º 13
0
        public RecurringListView(Context context, IAttributeSet attrs, RecurringAdapter adapter)
            : base(context, attrs)
        {
            var itemTemplateId = MvxAttributeHelpers.ReadAttributeValue(context, attrs,
                                                                        MvxAndroidBindingResource.Instance.ListViewStylableGroupId,
                                                                        MvxAndroidBindingResource.Instance.ListItemTemplateId);

            adapter.ItemTemplateId = itemTemplateId;
            Adapter = adapter;
            Adapter.CustomItemClick = this;
            SetupItemClickListeners();
        }
Exemplo n.º 14
0
        void InitFooters(Context context, IAttributeSet attrs)
        {
            var footerId = MvxAttributeHelpers.ReadAttributeValue(context, attrs, MvxAndroidBindingResource.Instance.ListViewStylableGroupId,
                                                                  AndroidBindingResource.Instance.MvxListViewWithHeader_FooterLayout);

            if (footerId != 0)
            {
                var bindingContext = MvxAndroidBindingContextHelpers.Current();
                var view           = bindingContext.BindingInflate(footerId, null);

                AddFooterView(view, null, false);
            }
        }
Exemplo n.º 15
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;
        }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
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;
        }
Exemplo n.º 18
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;
        }
Exemplo n.º 19
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;
        }
Exemplo n.º 20
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;
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
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;
            }
        }
Exemplo n.º 23
0
 public ARViewPager(Context context, IAttributeSet attrs)
     : base(context, attrs)
 {
     ItemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);
 }
Exemplo n.º 24
0
 private void ApplyAttributes(Context c, IAttributeSet attrs)
 {
     _headerId = MvxAttributeHelpers.ReadAttributeValue(c, attrs, Resource.Styleable.ARListView, Resource.Styleable.ARListView_MvxHeaderTemplate);
     _footerId = MvxAttributeHelpers.ReadAttributeValue(c, attrs, Resource.Styleable.ARListView, Resource.Styleable.ARListView_MvxFooterTemplate);
 }
        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
            });
        }
Exemplo n.º 26
0
 public static int ReadTemplateId(Context context, IAttributeSet attrs)
 {
     return(MvxAttributeHelpers.ReadAttributeValue(context, attrs, Resource.Styleable.ARLinearLayout, Resource.Styleable.ARLinearLayout_MvxItemTemplate));
 }