예제 #1
0
        public void UpdateViews(ChildAdapterModel model)
        {
            titleText.text    = model.title;
            introImage.sprite = model.introImage;

            //float curPos = childGrid.GetNormalizedPosition();
            //if (curPos != model.normalizedScrollPos)
            //	childGrid.SetNormalizedPosition(model.normalizedScrollPos);
        }
예제 #2
0
        /// <inheritdoc/>
        protected override void UpdateViewsHolder(ChildAdapterViewsHolder newOrRecycled)
        {
            // Initialize the views from the associated model
            ChildAdapterModel childAdapterModel = Data[newOrRecycled.ItemIndex];

            newOrRecycled.UpdateViews(childAdapterModel);

            if (childAdapterModel.items == null)             // first time updating the child scroll view => download initial items
            {
                TryDownloadingSomeItemsForChildScrollView(newOrRecycled, childAdapterModel, UnityEngine.Random.Range(1, 100), false);
            }
            else
            {
                newOrRecycled.childGrid.SetItemsAndUpdate(childAdapterModel.items);                 // already having the items => update directly
            }
        }
예제 #3
0
        void TryDownloadingSomeItemsForChildScrollView(ChildAdapterViewsHolder viewsHolder, ChildAdapterModel childScrollViewModel, int count, bool append)
        {
            viewsHolder.childGrid.SetWaitingForData(true);
            //int itemsCountAtRequest = _Params.Data.Count;
            //int vhIndexAtRequest = newOrRecycled.ItemIndex;
            Coroutine coroutine  = null;
            int       nextFreeId = viewsHolder.childGrid.GetItemsCount();       // the "id" (used only to show it in TitleText) for the first downloaded item is the current items count;

            viewsHolder.modelsDownloadingCoroutine = coroutine = StartCoroutine(SimulateDownloadChildItemsCoroutine(
                                                                                    count,
                                                                                    nextFreeId,
                                                                                    downloadedItems =>
            {
                // Use the results only if the ViewsHolder wasn't recycled meanwhile
                //if (itemsCountAtRequest == _Params.Data.Count
                //	&& newOrRecycled.ItemIndex == vhIndexAtRequest)
                if (viewsHolder.modelsDownloadingCoroutine == null || viewsHolder.modelsDownloadingCoroutine != coroutine)
                {
                    return;
                }

                viewsHolder.modelsDownloadingCoroutine = null;                 // done

                // The childScrollViewModel keeps track of items, because the
                // child script is not a "persistent storage" - it's being constantly recycled
                if (append)                 // append is faster
                {
                    childScrollViewModel.items.AddRange(downloadedItems);
                    viewsHolder.childGrid.AddItemsAndUpdate(downloadedItems);
                }
                else
                {
                    childScrollViewModel.items = new List <MyCellModel>(downloadedItems);
                    viewsHolder.childGrid.SetItemsAndUpdate(downloadedItems);
                }
            }));
        }