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;
            }
            _recyclerView.SetDisableHierarchyListener(true);
            base.OnAttachedToRecyclerView(recyclerView);
        }
        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);
        }
示例#3
0
        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;
            }
        }
 public TabListener(DataTemplateProvider contentTemplateProvider)
 {
     _contentTemplateProvider = contentTemplateProvider;
 }