public ItemsSourceAdapter([NotNull] object container, Context context, bool listenCollectionChanges, string dropDownItemTemplateSelectorName = null,
                                  string itemTemplateSelectorName = null, string dropDownItemTemplateName = null, string itemTemplateName = null)
        {
            Should.NotBeNull(container, nameof(container));
            _container = container;
            container.TryGetBindingMemberValue(AttachedMembers.Object.StableIdProvider, out _stableIdProvider);
            _itemTemplateProvider = new DataTemplateProvider(container, itemTemplateName ?? AttachedMemberConstants.ItemTemplate,
                                                             itemTemplateSelectorName ?? AttachedMemberConstants.ItemTemplateSelector);
            _dropDownTemplateProvider = new DataTemplateProvider(container,
                                                                 dropDownItemTemplateName ?? AttachedMembers.AdapterView.DropDownItemTemplate,
                                                                 dropDownItemTemplateSelectorName ?? AttachedMembers.AdapterView.DropDownItemTemplateSelector);
            _layoutInflater = context.GetBindableLayoutInflater();
            if (listenCollectionChanges)
            {
                _weakHandler = ReflectionExtensions.MakeWeakCollectionChangedHandler(this, (adapter, o, arg3) => adapter.OnCollectionChanged(o, arg3));
            }
            var activityView = context.GetActivity() as IActivityView;

            if (activityView != null)
            {
                _listener = ReflectionExtensions.CreateWeakEventHandler <ItemsSourceAdapter, EventArgs>(this, (adapter, o, arg3) => adapter.ActivityViewOnDestroyed((Activity)o));
                activityView.Mediator.Destroyed += _listener.Handle;
            }
            _defaultDropDownTemplate = IsSpinner()
                ? global::Android.Resource.Layout.SimpleDropDownItem1Line
                : global::Android.Resource.Layout.SimpleSpinnerDropDownItem;
            (container as AdapterView)?.SetDisableHierarchyListener(true);
        }
 public ItemsSourcePagerAdapter([NotNull] ViewPager viewPager)
 {
     Should.NotBeNull(viewPager, nameof(viewPager));
     _viewPager = viewPager;
     _fragmentManager = viewPager.GetFragmentManager();
     _itemTemplateProvider = new DataTemplateProvider(viewPager, AttachedMemberConstants.ItemTemplate, AttachedMemberConstants.ItemTemplateSelector);
     _weakHandler = ReflectionExtensions.MakeWeakCollectionChangedHandler(this, (adapter, o, arg3) => adapter.OnCollectionChanged(o, arg3));
     var activityView = _viewPager.Context.GetActivity() as IActivityView;
     if (activityView != null)
     {
         _listener = ReflectionExtensions.CreateWeakEventHandler<ItemsSourcePagerAdapter, EventArgs>(this, (adapter, o, arg3) => adapter.ActivityViewOnDestroyed((Activity)o));
         activityView.Mediator.Destroyed += _listener.Handle;
     }
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ItemsSourceAdapter" /> class.
 /// </summary>
 public ItemsSourceRecyclerAdapter([NotNull] global::Android.Support.V7.Widget.RecyclerView recyclerView)
 {
     Should.NotBeNull(recyclerView, "recyclerView");
     _recyclerView = recyclerView;
     _itemTemplateProvider = new DataTemplateProvider(_recyclerView, AttachedMemberConstants.ItemTemplate,
         AttachedMemberConstants.ItemTemplateSelector);
     _layoutInflater = _recyclerView.Context.GetBindableLayoutInflater();
     _weakHandler = ReflectionExtensions.MakeWeakCollectionChangedHandler(this,
         (adapter, o, arg3) => adapter.OnCollectionChanged(o, arg3));
     var activityView = _recyclerView.Context.GetActivity() as IActivityView;
     if (activityView != null)
     {
         _listener = ReflectionExtensions.CreateWeakEventHandler<ItemsSourceRecyclerAdapter, EventArgs>(this, (adapter, o, arg3) => adapter.ActivityViewOnDestroyed((Activity)o));
         activityView.Mediator.Destroyed += _listener.Handle;
     }
 }
 internal TabHostItemsSourceGenerator([NotNull] TabHost tabHost)
 {
     Should.NotBeNull(tabHost, "tabHost");
     TabHost = tabHost;
     TabHost.Setup();
     _tabToContent         = new Dictionary <string, TabInfo>();
     _tabFactory           = new TabFactory(this);
     _itemTemplateProvider = new DataTemplateProvider(tabHost, AttachedMemberConstants.ItemTemplate,
                                                      AttachedMemberConstants.ItemTemplateSelector);
     _contentTemplateProvider = new DataTemplateProvider(tabHost, AttachedMemberConstants.ContentTemplate,
                                                         AttachedMemberConstants.ContentTemplateSelector);
     _selectedItemMember = BindingServiceProvider
                           .MemberProvider
                           .GetBindingMember(tabHost.GetType(), AttachedMemberConstants.SelectedItem, false, false);
     _collectionViewManagerMember = BindingServiceProvider
                                    .MemberProvider
                                    .GetBindingMember(tabHost.GetType(), AttachedMembers.ViewGroup.CollectionViewManager, false, false);
     TryListenActivity(tabHost.Context);
     TabHost.TabChanged += TabHostOnTabChanged;
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ItemsSourceAdapter" /> class.
 /// </summary>
 public ItemsSourceAdapter([NotNull] object container, Context context, bool listenCollectionChanges, string dropDownItemTemplateSelectorName = null,
     string itemTemplateSelectorName = AttachedMemberConstants.ItemTemplateSelector, string dropDownItemTemplateIdName = null,
     string itemTemplateIdName = AttachedMemberConstants.ItemTemplate)
 {
     Should.NotBeNull(container, "container");
     _container = container;
     _itemTemplateProvider = new DataTemplateProvider(container, itemTemplateIdName, itemTemplateSelectorName);
     _dropDownTemplateProvider = new DataTemplateProvider(container,
         dropDownItemTemplateIdName ?? AttachedMembers.AdapterView.DropDownItemTemplate,
         dropDownItemTemplateSelectorName ?? AttachedMembers.AdapterView.DropDownItemTemplateSelector);
     _layoutInflater = context.GetBindableLayoutInflater();
     if (listenCollectionChanges)
         _weakHandler = ReflectionExtensions.MakeWeakCollectionChangedHandler(this, (adapter, o, arg3) => adapter.OnCollectionChanged(o, arg3));
     var activityView = context.GetActivity() as IActivityView;
     if (activityView != null)
     {
         _listener = ReflectionExtensions.CreateWeakEventHandler<ItemsSourceAdapter, EventArgs>(this, (adapter, o, arg3) => adapter.ActivityViewOnDestroyed((Activity)o));
         activityView.Mediator.Destroyed += _listener.Handle;
     }
 }
 private View GetViewInternal(int position, View convertView, ViewGroup parent, DataTemplateProvider provider, int defaultTemplate)
 {
     if (ItemsSource == null)
         return null;
     var view = CreateView(GetRawItem(position), convertView, parent, provider, defaultTemplate);
     if (view != null && !ReferenceEquals(view, convertView))
     {
         view.SetBindingMemberValue(AttachedMembers.Object.Parent, Container);
         view.ListenParentChange();
     }
     return view;
 }
        protected virtual View CreateView(object value, View convertView, ViewGroup parent, DataTemplateProvider templateProvider, int defaultTemplate)
        {
            var valueView = value as View;
            if (valueView != null)
                return valueView;

            int? templateId = null;
            int id;
            if (templateProvider.TrySelectResourceTemplate(value, out id))
                templateId = id;
            else
            {
                object template;
                if (templateProvider.TrySelectTemplate(value, out template))
                {
                    if (template != null)
                    {
                        valueView = template as View;
                        if (valueView != null)
                        {
                            valueView.SetDataContext(value);
                            return valueView;
                        }
                        if (template is int)
                            templateId = (int)template;
                        else
                            value = template;
                    }
                }
                else
                    templateId = templateProvider.GetTemplateId();
            }

            if (templateId == null)
            {
                if (!(convertView is TextView))
                    convertView = LayoutInflater.Inflate(defaultTemplate, null);
                var textView = convertView as TextView;
                if (textView != null)
                    textView.Text = value.ToStringSafe("(null)");
                return textView;
            }
            var oldId = GetViewTemplateId(convertView);
            if (oldId == null || oldId.Value != templateId.Value)
                convertView = CreateView(value, parent, templateId.Value);
            convertView.SetDataContext(value);
            return convertView;
        }
 public ItemsSourceAdapter([NotNull] object container, Context context, bool listenCollectionChanges, string dropDownItemTemplateSelectorName = null,
     string itemTemplateSelectorName = null, string dropDownItemTemplateName = null, string itemTemplateName = null)
 {
     Should.NotBeNull(container, "container");
     _container = container;
     container.TryGetBindingMemberValue(AttachedMembers.Object.StableIdProvider, out _stableIdProvider);
     _itemTemplateProvider = new DataTemplateProvider(container, itemTemplateName ?? AttachedMemberConstants.ItemTemplate,
         itemTemplateSelectorName ?? AttachedMemberConstants.ItemTemplateSelector);
     _dropDownTemplateProvider = new DataTemplateProvider(container,
         dropDownItemTemplateName ?? AttachedMembers.AdapterView.DropDownItemTemplate,
         dropDownItemTemplateSelectorName ?? AttachedMembers.AdapterView.DropDownItemTemplateSelector);
     _layoutInflater = context.GetBindableLayoutInflater();
     if (listenCollectionChanges)
         _weakHandler = ReflectionExtensions.MakeWeakCollectionChangedHandler(this, (adapter, o, arg3) => adapter.OnCollectionChanged(o, arg3));
     var activityView = context.GetActivity() as IActivityView;
     if (activityView != null)
     {
         _listener = ReflectionExtensions.CreateWeakEventHandler<ItemsSourceAdapter, EventArgs>(this, (adapter, o, arg3) => adapter.ActivityViewOnDestroyed((Activity)o));
         activityView.Mediator.Destroyed += _listener.Handle;
     }
     _defaultDropDownTemplate = IsSpinner()
         ? global::Android.Resource.Layout.SimpleDropDownItem1Line
         : global::Android.Resource.Layout.SimpleSpinnerDropDownItem;
     var absListView = container as AdapterView;
     if (absListView != null)
     {
         var member = BindingServiceProvider.MemberProvider.GetBindingMember(absListView.GetType(), AttachedMembers.ViewGroup.DisableHierarchyListener, false, false);
         if (member.CanWrite)
             member.SetSingleValue(absListView, Empty.TrueObject);
     }
 }
 internal TabHostItemsSourceGenerator([NotNull] TabHost tabHost)
 {
     Should.NotBeNull(tabHost, "tabHost");
     TabHost = tabHost;
     TabHost.Setup();
     _tabToContent = new Dictionary<string, TabInfo>();
     _tabFactory = new TabFactory(this);
     _itemTemplateProvider = new DataTemplateProvider(tabHost, AttachedMemberConstants.ItemTemplate,
         AttachedMemberConstants.ItemTemplateSelector);
     _contentTemplateProvider = new DataTemplateProvider(tabHost, AttachedMemberConstants.ContentTemplate,
         AttachedMemberConstants.ContentTemplateSelector);
     _selectedItemMember = BindingServiceProvider
                                          .MemberProvider
                                          .GetBindingMember(tabHost.GetType(), AttachedMemberConstants.SelectedItem, false, false);
     TryListenActivity(tabHost.Context);
     TabHost.TabChanged += TabHostOnTabChanged;
 }
 public TabListener(DataTemplateProvider contentTemplateProvider)
 {
     _contentTemplateProvider = contentTemplateProvider;
 }
        private View GetViewInternal(int position, View convertView, ViewGroup parent, DataTemplateProvider provider, int defaultTemplate)
        {
            if (ItemsSource == null)
            {
                return(null);
            }
            var view = CreateView(GetRawItem(position), convertView, parent, provider, defaultTemplate);

            if (view != null && !ReferenceEquals(view, convertView))
            {
                view.SetBindingMemberValue(AttachedMembers.Object.Parent, Container);
                view.ListenParentChange();
            }
            return(view);
        }
        protected virtual View CreateView(object value, View convertView, ViewGroup parent, DataTemplateProvider templateProvider, int defaultTemplate)
        {
            var valueView = value as View;

            if (valueView != null)
            {
                return(valueView);
            }

            int?templateId = null;
            int id;

            if (templateProvider.TrySelectResourceTemplate(value, out id))
            {
                templateId = id;
            }
            else
            {
                object template;
                if (templateProvider.TrySelectTemplate(value, out template))
                {
                    if (template != null)
                    {
                        valueView = template as View;
                        if (valueView != null)
                        {
                            valueView.SetDataContext(value);
                            return(valueView);
                        }
                        if (template is int)
                        {
                            templateId = (int)template;
                        }
                        else
                        {
                            value = template;
                        }
                    }
                }
                else
                {
                    templateId = templateProvider.GetTemplateId();
                }
            }

            if (templateId == null)
            {
                if (!(convertView is TextView))
                {
                    convertView = LayoutInflater.Inflate(defaultTemplate, null);
                }
                var textView = convertView as TextView;
                if (textView != null)
                {
                    textView.Text = value.ToStringSafe("(null)");
                }
                return(textView);
            }
            var oldId = GetViewTemplateId(convertView);

            if (oldId == null || oldId.Value != templateId.Value)
            {
                convertView = CreateView(value, parent, templateId.Value);
            }
            convertView.SetDataContext(value);
            return(convertView);
        }
 public override void OnDetachedFromRecyclerView(global::Android.Support.V7.Widget.RecyclerView recyclerView)
 {
     var activityView = recyclerView.Context.GetActivity() as IActivityView;
     if (activityView != null)
         activityView.Mediator.Destroyed -= _listener.Handle;
     _layoutInflater = null;
     _itemTemplateProvider = null;
     _recyclerView = null;
     _createViewHolderDelegate = null;
     base.OnDetachedFromRecyclerView(recyclerView);
 }
 public override void OnAttachedToRecyclerView(global::Android.Support.V7.Widget.RecyclerView recyclerView)
 {
     _recyclerView = recyclerView;
     _itemTemplateProvider = new DataTemplateProvider(_recyclerView, AttachedMemberConstants.ItemTemplate, AttachedMemberConstants.ItemTemplateSelector);
     _layoutInflater = _recyclerView.Context.GetBindableLayoutInflater();
     _createViewHolderDelegate = _recyclerView.GetBindingMemberValue(AttachedMembersRecyclerView.RecyclerView.CreateViewHolderDelegate);
     HasStableIds = recyclerView.TryGetBindingMemberValue(AttachedMembers.Object.StableIdProvider, out _stableIdProvider) && _stableIdProvider != null;
     var activityView = _recyclerView.Context.GetActivity() as IActivityView;
     if (activityView != null)
     {
         if (_listener == null)
             _listener = ReflectionExtensions.CreateWeakEventHandler<ItemsSourceRecyclerAdapter, EventArgs>(this, (adapter, o, arg3) => adapter.ActivityViewOnDestroyed((Activity)o));
         activityView.Mediator.Destroyed += _listener.Handle;
     }
     //To prevent HasStableIds error.
     if (_observers != null)
     {
         foreach (var observer in _observers)
             base.RegisterAdapterDataObserver(observer);
         _observers = null;
     }
     var member = BindingServiceProvider.MemberProvider.GetBindingMember(_recyclerView.GetType(), AttachedMembers.ViewGroup.DisableHierarchyListener, false, false);
     if (member.CanWrite)
         member.SetSingleValue(_recyclerView, Empty.TrueObject);
     base.OnAttachedToRecyclerView(recyclerView);
 }
        private View GetViewInternal(int position, View convertView, ViewGroup parent, DataTemplateProvider provider, int defaultTemplate)
        {
            if (ItemsSource == null)
            {
                return(null);
            }
            LayoutInflaterResult result;
            var view = CreateView(GetRawItem(position), convertView, parent, provider, defaultTemplate, out result);

            if (view != null && !ReferenceEquals(view, convertView))
            {
                view.SetBindingMemberValue(AttachedMembersBase.Object.Parent, Container);
            }
            result?.ApplyBindings();
            return(view);
        }