/// <summary> /// Takes a IHistoryEntry and binds it to a created HistoryEntryComponent to be used in the history list. /// </summary> /// <param name="entry">History entry to bind</param> /// <param name="expanded">Whether or not to show its list of changed entries.</param> /// <returns>Inflated and bound component.</returns> HistoryEntryComponent CreateHistoryEntry([NotNull] IHistoryEntry entry, bool expanded) { Assert.IsNotNull(m_Presenter, "Invalid state when creating history entry"); var comp = new HistoryEntryComponent(); // Handle expanded vs compact layout if (expanded) { // Hide fields used for compact view comp.showFilesButton.AddToClassList(UiConstants.ussHidden); comp.cloudStatusText.AddToClassList(UiConstants.ussHidden); comp.changedFilesCount.text = $"Changes ( {entry.Changes.Count} )"; var listAdapter = new HistoryEntryChangeListAdapter(m_Presenter, entry.RevisionId, entry.Changes.ToList()); comp.changedFiles.SetAdapter(listAdapter); listAdapter.NotifyDataSetChanged(); // Configure button comp.gotoButton.text = entry.GetGotoText(); comp.gotoButton.clickable.clicked += () => m_Presenter.RequestGoto(entry.RevisionId, entry.Status); } else { // Hide fields used for expanded view comp.changedFilesCount.AddToClassList(UiConstants.ussHidden); comp.changedFiles.AddToClassList(UiConstants.ussHidden); comp.gotoButton.text = string.Empty; comp.gotoButton.AddToClassList(UiConstants.ussHidden); // Setup show button comp.showFilesButton.text = entry.Changes.Count == 1 ? StringAssets.showChange : string.Format(StringAssets.showChanges, entry.Changes.Count); comp.showFilesButton.clickable.clicked += () => m_Presenter.SelectedRevisionId = entry.RevisionId; // TODO: cloud status text } // Trim whitespace on either side and grab initial for profile circle var trimmedAuthorName = entry.AuthorName.Trim(); comp.profileInitial.text = trimmedAuthorName.Substring(0, 1).ToUpper(); comp.authorName.text = trimmedAuthorName; // Display relative or absolute timestamp. If relative, show absolute as a tooltip. comp.timestamp.text = TimeStamp.GetTimeStamp(entry.Time); if (TimeStamp.UseRelativeTimeStamps) { comp.timestamp.tooltip = TimeStamp.GetLocalisedTimeStamp(entry.Time); } // Display revision id and show full length id as a tooltip comp.revisionId.text = $"ID: {entry.RevisionId.Substring(0, 10)}"; comp.revisionId.tooltip = entry.RevisionId; comp.commitMessage.text = entry.Message; return(comp); }