Beispiel #1
0
        private void SetItem(RecyclingContainerView aRoot, ItemType aItem)
        {
            ViewCache cache = aRoot.Tag as ViewCache;

            Assert.Check(cache != null);
            if (cache.ChildType == EChildViewType.Item)
            {
                RecycleItemView(iContext, aItem, cache);
            }
            else
            {
                DisconnectContainer(aRoot);
                if (iDisconnectedItemViews.Count > 0)
                {
                    View recycledView = iDisconnectedItemViews[0];
                    iDisconnectedItemViews.RemoveAt(0);
                    aRoot.Content = recycledView;
                    RecycleItemView(iContext, aItem, cache);
                }
                else
                {
                    int  childCount = aRoot.ChildCount;
                    View view       = CreateItemView(iContext, aItem, aRoot);
                    Assert.Check(aRoot.ChildCount == childCount);
                    Assert.Check(view != null);
                    aRoot.Content = view;
                    RecycleItemView(iContext, aItem, cache);
                }
                cache.ChildType = EChildViewType.Item;
            }
        }
Beispiel #2
0
        public virtual void Clear()
        {
            foreach (RecyclingContainerView view in iViews)
            {
                DisconnectContainer(view);
                ViewCache cache = view.Tag as ViewCache;
                view.Tag = null;
                view.EventRequestDeleteClick -= EventRequestDeleteHandler;
                view.EventConfirmDeleteClick -= EventConfirmDeleteHandler;
                view.EventMoveUpClick        -= EventMoveUpHandler;
                view.EventMoveDownClick      -= EventMoveDownHandler;
                view.Dispose();
                cache.Close();
                cache.Dispose();
            }
            foreach (View v in iDisconnectedSectionHeaderViews)
            {
                v.Dispose();
            }
            iDisconnectedSectionHeaderViews.Clear();
            foreach (View v in iDisconnectedItemViews)
            {
                v.Dispose();
            }
            iDisconnectedItemViews.Clear();

            iViews.Clear();
        }
Beispiel #3
0
        private void SetHeader(RecyclingContainerView aRoot, SectionHeader <SectionHeaderType> aHeader)
        {
            ViewCache cache = aRoot.Tag as ViewCache;

            Assert.Check(cache != null);
            if (cache.ChildType == EChildViewType.Header)
            {
                RecycleSectionHeaderView(iContext, aHeader.Header, cache);
            }
            else
            {
                DisconnectContainer(aRoot);
                if (iDisconnectedSectionHeaderViews.Count > 0)
                {
                    View recycledView = iDisconnectedSectionHeaderViews[0];
                    iDisconnectedSectionHeaderViews.RemoveAt(0);
                    aRoot.Content = recycledView;
                    RecycleSectionHeaderView(iContext, aHeader.Header, cache);
                }
                else
                {
                    int  childCount = aRoot.ChildCount;
                    View view       = CreateSectionHeaderView(iContext, aHeader.Header, aRoot);
                    Assert.Check(aRoot.ChildCount == childCount);
                    Assert.Check(view != null);
                    aRoot.Content = view;
                    RecycleSectionHeaderView(iContext, aHeader.Header, cache);
                }
                cache.ChildType = EChildViewType.Header;
            }
        }
Beispiel #4
0
        private void DisconnectContainer(RecyclingContainerView aRoot)
        {
            ViewCache cache = aRoot.Tag as ViewCache;

            Assert.Check(cache != null);
            View disconnectedChild = aRoot.Content;

            switch (cache.ChildType)
            {
            case EChildViewType.Header:
            {
                if (iDisconnectedSectionHeaderViews.Count < kMaxDisconnectedViews)
                {
                    iDisconnectedSectionHeaderViews.Add(disconnectedChild);
                }
                else
                {
                    DestroySectionHeaderView(iContext, cache);
                    disconnectedChild.Dispose();
                    disconnectedChild = null;
                }
                break;
            }

            case EChildViewType.Item:
            {
                if (iDisconnectedItemViews.Count < kMaxDisconnectedViews)
                {
                    iDisconnectedItemViews.Add(disconnectedChild);
                }
                else
                {
                    DestroyItemView(iContext, cache);
                    disconnectedChild.Dispose();
                    disconnectedChild = null;
                }
                break;
            }

            default:
            {
                Assert.Check(false);
                break;
            }
            }
            aRoot.Content = null;
            cache.Clear();
        }
Beispiel #5
0
        private void EventRequestDeleteHandler(object sender, EventArgs args)
        {
            RecyclingContainerView senderView = sender as RecyclingContainerView;
            ViewCache cache = senderView.Tag as ViewCache;

            Assert.Check(cache != null);
            if (cache.Position == iDeleteIndex)
            {
                iDeleteIndex = -1;
            }
            else
            {
                iDeleteIndex = cache.Position;
            }
            NotifyDataSetChanged();
        }
Beispiel #6
0
        private void EventMoveDownHandler(object sender, EventArgs args)
        {
            RecyclingContainerView senderView = sender as RecyclingContainerView;
            ViewCache cache = senderView.Tag as ViewCache;

            Assert.Check(cache != null);
            int position = cache.Position;
            SectionHeader <SectionHeaderType> header = GetSectionHeader(position);

            if (header != null)
            {
                OnEventSectionMovedDown(header.Header, position);
            }
            else
            {
                int      loaderPosition = GetLoaderPosition(position);
                ItemType item           = iLoader.Item(loaderPosition);
                Assert.Check(item != null);
                OnEventItemMovedDown(item, position);
            }
        }
Beispiel #7
0
        private RecyclingContainerView CreateContainerView(Context aContext)
        {
            RecyclingContainerView result = new RecyclingContainerView(aContext, RequestDeleteButtonResourceId, ConfirmDeleteButtonResourceId, MoveDownButtonResourceId, MoveUpButtonResourceId);

            using (ListView.LayoutParams layoutParams = new ListView.LayoutParams(ListView.LayoutParams.FillParent, ListView.LayoutParams.WrapContent))
            {
                result.LayoutParameters = layoutParams;
            }
            ViewCache cache = new ViewCache(result);

            result.Tag = cache;
            View view = CreateItemView(aContext, default(ItemType), result);

            result.EditMode = EItemEditMode.None;
            Assert.Check(view != null);
            result.Content = view;
            result.EventRequestDeleteClick += EventRequestDeleteHandler;
            result.EventConfirmDeleteClick += EventConfirmDeleteHandler;
            result.EventMoveUpClick        += EventMoveUpHandler;
            result.EventMoveDownClick      += EventMoveDownHandler;
            iViews.Add(result);
            return(result);
        }
Beispiel #8
0
 protected virtual void RecycleSectionHeaderView(Context aContext, SectionHeaderType aSectionHeader, ViewCache aViewCache)
 {
 }
Beispiel #9
0
        public override View GetView(int aPosition, View aConvertView, ViewGroup aParent)
        {
            RecyclingContainerView root = aConvertView as RecyclingContainerView;

            if (root == null)
            {
                root = CreateContainerView(iContext);
            }
            else if (root.HasResurfacedWithoutJNIHandle)
            {
                UserLog.WriteLine("Ticket #1194: Item has resurfaced after dispose! - " + iId);
                Assert.Check(false);
            }
            ViewCache cache = root.Tag as ViewCache;

            Assert.Check(cache != null);
            cache.Position = aPosition;
            SectionHeader <SectionHeaderType> header = GetSectionHeader(aPosition);
            ItemType item          = default(ItemType);
            bool     isPlaceholder = false;

            if (header != null)
            {
                SetHeader(root, header);
            }
            else
            {
                int loaderPosition = GetLoaderPosition(aPosition);
                item = iLoader.Item(loaderPosition);

                if (item != null)
                {
                    SetItem(root, item);
                }
                else
                {
                    SetItem(root, default(ItemType));
                    isPlaceholder = true;
                }
            }
            if (iEditMode && !isPlaceholder)
            {
                root.EditMode = aPosition == iDeleteIndex ? EItemEditMode.ConfirmDelete : EItemEditMode.Editing;
                if (header != null)
                {
                    root.CanDelete   = CanDeleteSection(header.Header, aPosition);
                    root.CanMoveUp   = CanMoveSectionUp(header.Header, aPosition);
                    root.CanMoveDown = CanMoveSectionDown(header.Header, aPosition);
                }
                else
                {
                    root.CanDelete   = CanDeleteItem(item, aPosition);
                    root.CanMoveUp   = CanMoveItemUp(item, aPosition);
                    root.CanMoveDown = CanMoveItemDown(item, aPosition);
                }
            }
            else
            {
                root.EditMode = EItemEditMode.None;
            }
            root.IsFirst = aPosition == 0;
            root.IsLast  = aPosition == Count - 1;
            return(root);
        }
Beispiel #10
0
 protected virtual void DestroyItemView(Context aContext, ViewCache aViewCache)
 {
 }
Beispiel #11
0
 protected virtual void DestroySectionHeaderView(Context aContext, ViewCache aViewCache)
 {
 }
Beispiel #12
0
 protected virtual void RecycleItemView(Context aContext, ItemType aItem, ViewCache aViewCache)
 {
 }