private void MultiLevelRecyclerView_ItemClick(View view, RecyclerViewItem item, int position)
 {
     if (ToggleItemOnClick)
     {
         ToggleItemsGroup(position);
     }
 }
        private void AddItems(RecyclerViewItem clickedItem, IList <RecyclerViewItem> tempList, int position)
        {
            if (clickedItem.HasChildren)
            {
                prevClickedPosition = position;

                for (int i = 0; i < clickedItem.Children.Count; i++)
                {
                    tempList.Insert(position + 1 + i, clickedItem.Children[i]);
                }
                //tempList.AddAll(position + 1, clickedItem.Children);

                clickedItem.Expanded = true;

                numberOfItemsAdded = clickedItem.Children.Count;

                mMultiLevelAdapter.RecyclerViewItemList = tempList;

                mMultiLevelAdapter.NotifyItemRangeInserted(position + 1, clickedItem.Children.Count);

                SmoothScrollToPosition(position);
                RefreshPosition();
            }
        }
        public void ToggleItemsGroup(int position)
        {
            if (position == -1)
            {
                return;
            }

            IList <RecyclerViewItem> adapterList = mMultiLevelAdapter.RecyclerViewItemList;

            RecyclerViewItem clickedItem = adapterList[position];

            if (Accordion)
            {
                if (clickedItem.Expanded)
                {
                    clickedItem.Expanded = false;
                    RemoveAllChildren(clickedItem.Children);
                    RemovePrevItems(adapterList, position, clickedItem.Children.Count);
                    prevClickedPosition = -1;
                    numberOfItemsAdded  = 0;
                }
                else
                {
                    int i             = GetExpandedPosition(clickedItem.Level);
                    int itemsToRemove = GetItemsToBeRemoved(clickedItem.Level);

                    if (i != -1)
                    {
                        RemovePrevItems(adapterList, i, itemsToRemove);

                        adapterList[i].Expanded = false;

                        if (clickedItem.Position > adapterList[i].Position)
                        {
                            AddItems(clickedItem, adapterList, position - itemsToRemove);
                        }
                        else
                        {
                            AddItems(clickedItem, adapterList, position);
                        }
                    }
                    else
                    {
                        AddItems(clickedItem, adapterList, position);
                    }
                }
            }
            else
            {
                if (clickedItem.Expanded)
                {
                    clickedItem.Expanded = false;
                    RemoveAllChildren(clickedItem.Children);
                    RemovePrevItems(adapterList, position, clickedItem.Children.Count);
                    prevClickedPosition = -1;
                    numberOfItemsAdded  = 0;
                }
                else
                {
                    if (clickedItem.Expanded)
                    {
                        RemovePrevItems(adapterList, prevClickedPosition, numberOfItemsAdded);
                        AddItems(clickedItem, adapterList, clickedItem.Position);
                    }
                    else
                    {
                        AddItems(clickedItem, adapterList, position);
                    }
                }
            }
        }