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);
        }
Esempio n. 2
0
        public override void OnDestroy(Action baseOnDestroy)
        {
            if (Tracer.TraceInformation)
            {
                Tracer.Info("OnDestroy activity({0})", Target);
            }
            ServiceProvider.EventAggregator.Unsubscribe(this);
            var handler = Destroyed;

            if (handler != null)
            {
                handler(Target, EventArgs.Empty);
            }
            _view.RemoveFromParent();
            if (_attachedViews == null)
            {
                _view.ClearBindingsRecursively(true, true);
            }
            else
            {
                CleanupItems();
            }
            _view = null;

            if (_metadata != null)
            {
                _metadata.Clear();
                _metadata = null;
            }

            MenuTemplate.Clear(_menu);
            _menu = null;

            if (_menuInflater != null)
            {
                _menuInflater.Dispose();
                _menuInflater = null;
            }
            if (_layoutInflater != null)
            {
                _layoutInflater.Dispose();
                _layoutInflater = null;
            }
            base.OnDestroy(baseOnDestroy);
            PlatformExtensions.SetCurrentActivity(Target, true);
            Target.ClearBindings(false, true);
            OptionsItemSelected  = null;
            ConfigurationChanged = null;
            PostCreate           = null;
            BackPressing         = null;
            Created           = null;
            Started           = null;
            Paused            = null;
            SaveInstanceState = null;
            Stoped            = null;
            Restarted         = null;
            Resume            = null;
            Destroyed         = null;
        }
Esempio n. 3
0
 public LayoutInflater GetLayoutInflater(LayoutInflater baseLayoutInflater)
 {
     if (_layoutInflater == null)
     {
         _layoutInflater = PlatformExtensions.LayoutInflaterFactory(Target, MugenMvvmToolkit.Models.DataContext.Empty, Get <IViewFactory>(), baseLayoutInflater);
         if (_layoutInflater != null)
         {
             _layoutInflater = new BindableLayoutInflaterProxy(_layoutInflater);
         }
     }
     return(_layoutInflater ?? baseLayoutInflater);
 }
        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);
        }