public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == Header) { View itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.GridHeader, parent, false); GridHeaderViewHolder vh = new GridHeaderViewHolder(itemView); return(vh); } else { View itemView = LayoutInflater.From(parent.Context).Inflate((viewType == Collection)? Resource.Layout.GridItemCollection : Resource.Layout.GridItem, parent, false); LearningActivityViewHolder vh = new LearningActivityViewHolder(itemView, OnClick); return(vh); } }
public override void OnBindViewHolder(Object holder, int sectionInd, int relativePos, int absPos) { LearningActivityViewHolder vh = holder as LearningActivityViewHolder; TaskParameter imTask; FeedItem thisItem; if (Data[sectionInd].Collections?.Count > relativePos) { thisItem = Data[sectionInd].Collections.ElementAt(relativePos); } else if (Data[sectionInd].Activities?.Count > (relativePos - Data[sectionInd].Collections?.Count ?? 0)) { thisItem = Data[sectionInd].Activities.ElementAt(relativePos - (Data[sectionInd].Collections?.Count ?? 0)); } else { return; } if (string.IsNullOrWhiteSpace(thisItem.ImageUrl)) { imTask = ImageService.Instance.LoadCompiledResource("logoRect"); } else if (thisItem.ImageUrl.StartsWith("/data", StringComparison.Ordinal)) { imTask = ImageService.Instance.LoadFile(thisItem.ImageUrl); } else { imTask = ImageService.Instance.LoadUrl(ServerUtils.GetUploadUrl(thisItem.ImageUrl)); } imTask.DownSampleInDip(width: 150); if (vh == null) { return; } imTask.Into(vh.Image); vh.Name.Text = thisItem.Name; string truncatedDesc = Helpers.Truncate(thisItem.Description, 100); vh.Description.Text = truncatedDesc; bool thisAuthor = thisItem.Author?.Id == dbManager.CurrentUser.Id; if (thisAuthor && (thisItem.Approved || thisItem.IsPublic == false)) { vh.StatusText.Visibility = ViewStates.Gone; vh.TickIcon.Visibility = ViewStates.Visible; } else if (thisAuthor) { vh.StatusText.Visibility = ViewStates.Visible; vh.StatusText.SetText(Resource.String.activityPending); vh.TickIcon.Visibility = ViewStates.Gone; } else { vh.StatusText.Visibility = ViewStates.Gone; vh.TickIcon.Visibility = ViewStates.Gone; } }