protected TableViewSourceBase([NotNull] UITableView tableView, string itemTemplate = AttachedMemberConstants.ItemTemplate) { Should.NotBeNull(tableView, nameof(tableView)); _tableView = ServiceProvider.WeakReferenceFactory(tableView); _templateProvider = new DataTemplateProvider(tableView, itemTemplate); var controllerView = tableView.FindParent<IViewControllerView>(); if (controllerView != null && !(controllerView is IMvvmNavigationController)) { _listener = ReflectionExtensions.CreateWeakEventHandler<TableViewSourceBase, EventArgs>(this, (adapter, o, arg3) => adapter.OnDisposeController(o, arg3)); controllerView.Mediator.DisposeHandler += _listener.Handle; } UseAnimations = tableView .GetBindingMemberValue(AttachedMembers.UITableView.UseAnimations) .GetValueOrDefault(true); AddAnimation = tableView .GetBindingMemberValue(AttachedMembers.UITableView.AddAnimation) .GetValueOrDefault(UITableViewRowAnimation.Automatic); RemoveAnimation = tableView .GetBindingMemberValue(AttachedMembers.UITableView.RemoveAnimation) .GetValueOrDefault(UITableViewRowAnimation.Automatic); ReplaceAnimation = tableView .GetBindingMemberValue(AttachedMembers.UITableView.ReplaceAnimation) .GetValueOrDefault(UITableViewRowAnimation.Automatic); ScrollPosition = tableView .GetBindingMemberValue(AttachedMembers.UITableView.ScrollPosition) .GetValueOrDefault(UITableViewScrollPosition.Middle); }
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 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); }
protected TableViewSourceBase([NotNull] UITableView tableView, string itemTemplate = AttachedMemberConstants.ItemTemplate) { Should.NotBeNull(tableView, nameof(tableView)); _tableView = ToolkitServiceProvider.WeakReferenceFactory(tableView); _templateProvider = new DataTemplateProvider <ITableCellTemplateSelector>(tableView, itemTemplate); var controllerView = tableView.FindParent <IViewControllerView>(); if (controllerView != null && !(controllerView is IMvvmNavigationController)) { _listener = ReflectionExtensions.CreateWeakEventHandler <TableViewSourceBase, EventArgs>(this, (adapter, o, arg3) => adapter.OnDisposeController(o, arg3)); controllerView.Mediator.DisposeHandler += _listener.Handle; } UseAnimations = tableView .GetBindingMemberValue(AttachedMembers.UITableView.UseAnimations) .GetValueOrDefault(true); AddAnimation = tableView .GetBindingMemberValue(AttachedMembers.UITableView.AddAnimation) .GetValueOrDefault(UITableViewRowAnimation.Automatic); RemoveAnimation = tableView .GetBindingMemberValue(AttachedMembers.UITableView.RemoveAnimation) .GetValueOrDefault(UITableViewRowAnimation.Automatic); ReplaceAnimation = tableView .GetBindingMemberValue(AttachedMembers.UITableView.ReplaceAnimation) .GetValueOrDefault(UITableViewRowAnimation.Automatic); ScrollPosition = tableView .GetBindingMemberValue(AttachedMembers.UITableView.ScrollPosition) .GetValueOrDefault(UITableViewScrollPosition.Middle); }
protected virtual void OnTargetDisposed(object sender, EventArgs e) { if (_listener != null) { #if ANDROID var activityView = sender as IActivityView; if (activityView != null) { activityView.Mediator.Destroyed -= _listener.Handle; } #elif WINFORMS var component = sender as IComponent; if (component != null) { component.Disposed -= _listener.Handle; } #elif TOUCH var controllerView = sender as IViewControllerView; if (controllerView != null) { controllerView.Mediator.DisposeHandler -= _listener.Handle; } #endif } var collectionChanged = ItemsSource as INotifyCollectionChanged; if (collectionChanged != null) { collectionChanged.CollectionChanged -= _handler; } ItemsSource = null; _listener = null; }
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 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; } }
protected CollectionViewSourceBase([NotNull] UICollectionView collectionView, string itemTemplate = AttachedMemberConstants.ItemTemplate) { Should.NotBeNull(collectionView, "collectionView"); _collectionView = PlatformExtensions.CreateWeakReference(collectionView); _itemTemplateMember = BindingServiceProvider.MemberProvider.GetBindingMember(collectionView.GetType(), itemTemplate, false, false); var controllerView = collectionView.FindParent<IViewControllerView>(); if (controllerView != null && !(controllerView is IMvvmNavigationController)) { _listener = ReflectionExtensions.CreateWeakEventHandler<CollectionViewSourceBase, EventArgs>(this, (adapter, o, arg3) => adapter.OnDisposeController(o, arg3)); controllerView.Mediator.DisposeHandler += _listener.Handle; } UseAnimations = collectionView .GetBindingMemberValue(AttachedMembers.UICollectionView.UseAnimations) .GetValueOrDefault(true); ScrollPosition = collectionView .GetBindingMemberValue(AttachedMembers.UICollectionView.ScrollPosition) .GetValueOrDefault(UICollectionViewScrollPosition.Top); }
/// <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; } }
protected CollectionViewSourceBase([NotNull] UICollectionView collectionView, string itemTemplate = AttachedMemberConstants.ItemTemplate) { Should.NotBeNull(collectionView, nameof(collectionView)); _collectionView = TouchToolkitExtensions.CreateWeakReference(collectionView); _itemTemplateProvider = new DataTemplateProvider <ICollectionCellTemplateSelector>(collectionView, itemTemplate); var controllerView = collectionView.FindParent <IViewControllerView>(); if (controllerView != null && !(controllerView is IMvvmNavigationController)) { _listener = ReflectionExtensions.CreateWeakEventHandler <CollectionViewSourceBase, EventArgs>(this, (adapter, o, arg3) => adapter.OnDisposeController(o, arg3)); controllerView.Mediator.DisposeHandler += _listener.Handle; } UseAnimations = collectionView .GetBindingMemberValue(AttachedMembers.UICollectionView.UseAnimations) .GetValueOrDefault(true); ScrollPosition = collectionView .GetBindingMemberValue(AttachedMembers.UICollectionView.ScrollPosition) .GetValueOrDefault(UICollectionViewScrollPosition.Top); }
private void InitializeListener() { _listener = ReflectionExtensions.CreateWeakEventHandler <ItemsSourceGeneratorBase, EventArgs>(this, (@base, o, arg3) => @base.OnTargetDisposed(o, arg3)); }
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 void InitializeListener() { _listener = ReflectionExtensions.CreateWeakEventHandler<ItemsSourceGeneratorBase, EventArgs>(this, (@base, o, arg3) => @base.OnTargetDisposed(o, arg3)); }
protected virtual void OnTargetDisposed(object sender, EventArgs e) { if (_listener != null) { #if ANDROID var activityView = sender as IActivityView; if (activityView != null) activityView.Mediator.Destroyed -= _listener.Handle; #elif WINFORMS var component = sender as IComponent; if (component != null) component.Disposed -= _listener.Handle; #elif TOUCH var controllerView = sender as IViewControllerView; if (controllerView != null) controllerView.Mediator.DisposeHandler -= _listener.Handle; #endif } var collectionChanged = ItemsSource as INotifyCollectionChanged; if (collectionChanged != null) collectionChanged.CollectionChanged -= _handler; ItemsSource = null; _listener = null; }
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); } }
private static NotifyCollectionChangedEventHandler CreateHandler(ReflectionExtensions.IWeakEventHandler <NotifyCollectionChangedEventArgs> weakEventHandler) { return(weakEventHandler.Handle); }