Skip to content

Commit cea4d02

Browse files
committed
Add commit SHA-1 and message to push event details area
1 parent b787877 commit cea4d02

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

app/src/main/java/com/github/mobile/ui/user/NewsListAdapter.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@
6262
import com.github.mobile.util.TimeUtils;
6363
import com.viewpagerindicator.R.layout;
6464

65+
import java.text.NumberFormat;
66+
import java.util.List;
67+
6568
import org.eclipse.egit.github.core.Comment;
69+
import org.eclipse.egit.github.core.Commit;
6670
import org.eclipse.egit.github.core.CommitComment;
6771
import org.eclipse.egit.github.core.Download;
6872
import org.eclipse.egit.github.core.Issue;
@@ -90,6 +94,9 @@
9094
*/
9195
public class NewsListAdapter extends ItemListAdapter<Event, NewsItemView> {
9296

97+
private static final NumberFormat NUMBER_FORMAT = NumberFormat
98+
.getIntegerInstance();
99+
93100
/**
94101
* Can the given event be rendered by this view holder?
95102
*
@@ -396,6 +403,47 @@ private static void formatPush(Event event, StyledText main,
396403
main.append(" at ");
397404

398405
boldRepo(main, event);
406+
407+
final List<Commit> commits = payload.getCommits();
408+
int size = commits != null ? commits.size() : -1;
409+
if (size > 0) {
410+
if (size != 1)
411+
details.append(NUMBER_FORMAT.format(size)).append(
412+
" new commits");
413+
else
414+
details.append("1 new commit");
415+
416+
int max = 3;
417+
int appended = 0;
418+
for (Commit commit : commits) {
419+
if (commit == null)
420+
continue;
421+
422+
details.append('\n');
423+
424+
String sha = commit.getSha();
425+
if (TextUtils.isEmpty(sha))
426+
continue;
427+
if (sha.length() > 7)
428+
details.monospace(sha.substring(0, 7));
429+
else
430+
details.monospace(sha);
431+
432+
String message = commit.getMessage();
433+
if (!TextUtils.isEmpty(message)) {
434+
details.append(' ');
435+
int newline = message.indexOf('\n');
436+
if (newline > 0)
437+
details.append(message.subSequence(0, newline));
438+
else
439+
details.append(message);
440+
}
441+
442+
appended++;
443+
if (appended == max)
444+
break;
445+
}
446+
}
399447
}
400448

401449
private static void formatTeamAdd(Event event, StyledText main,

0 commit comments

Comments
 (0)