示例#1
0
        private void Render(Maybe <IList <NewsFeedModel.Item> > newsItems)
        {
            _loadingPlaceholder.SetActive(false);

            if (newsItems.IsJust)
            {
                for (var i = 0; i < newsItems.Value.Count; i++)
                {
                    if (i >= _maxNewsItems)
                    {
                        break;
                    }
                    var newsItem = newsItems.Value[i];
                    newsItem = new NewsFeedModel.Item(
                        title: newsItem.Title,
                        description: newsItem.Description.Limit(_maxItemLength, trailingChars: "..."),
                        link: newsItem.Link,
                        publicationDate: newsItem.PublicationDate);
                    var itemView = Instantiate(_newsItemPrefab).GetComponent <NewsFeedItemView>();
                    itemView.Render(newsItem);
                    itemView.transform.SetParent(_newsItemsParent);
                    itemView.transform.localPosition = Vector3.zero;
                    itemView.transform.localRotation = Quaternion.identity;
                    itemView.transform.localScale    = Vector3.one;
                }
            }
            else
            {
                Debug.LogError("Failed to fetch news");
            }
        }
        public void Render(NewsFeedModel.Item item)
        {
            _title.text = item.Title;
            if (item.PublicationDate.HasValue)
            {
                _date.enabled = true;
                _date.text    = item.PublicationDate.Value.ToString("dddd, d MMMM", enUsCulture);
            }
            else
            {
                _date.enabled = false;
            }

            _description.text = item.Description;
            _link.SetUrl("Read more...", item.Link);
        }