Skip to content

Commit

Permalink
Show when an issue has been merged
Browse files Browse the repository at this point in the history
Fixes #81
jonan committed Oct 23, 2015
1 parent 41b7f75 commit 113be6f
Showing 3 changed files with 37 additions and 5 deletions.
40 changes: 35 additions & 5 deletions app/src/main/java/com/github/mobile/ui/issue/IssueFragment.java
Original file line number Diff line number Diff line change
@@ -347,6 +347,7 @@ private void updateHeader(final Issue issue) {
if (!isUsable())
return;

boolean isPullRequest = IssueUtils.isPullRequest(issue);
titleText.setText(issue.getTitle());

String body = issue.getBodyHtml();
@@ -360,7 +361,7 @@ private void updateHeader(final Issue issue) {
getString(R.string.prefix_opened)).append(issue.getCreatedAt()));
avatars.bind(creatorAvatar, issue.getUser());

if (IssueUtils.isPullRequest(issue) && issue.getPullRequest().getCommits() > 0) {
if (isPullRequest && issue.getPullRequest().getCommits() > 0) {
ViewUtils.setGone(commitsView, false);

TextView icon = (TextView) headerView.findViewById(R.id.tv_commit_icon);
@@ -376,7 +377,13 @@ private void updateHeader(final Issue issue) {
boolean open = STATE_OPEN.equals(issue.getState());
if (!open) {
StyledText text = new StyledText();
text.bold(getString(R.string.closed));
if (isPullRequest && issue.getPullRequest().isMerged()) {
text.bold(getString(R.string.merged));
stateText.setBackgroundResource(R.color.state_background_merged);
} else {
text.bold(getString(R.string.closed));
stateText.setBackgroundResource(R.color.state_background_closed);
}
Date closedAt = issue.getClosedAt();
if (closedAt != null)
text.append(' ').append(closedAt);
@@ -457,13 +464,12 @@ protected void onSuccess(FullIssue fullIssue) throws Exception {

List<Object> allItems = new ArrayList<>();

List<String> excludedEvents = Arrays.asList(IssueEvent.TYPE_MENTIONED, IssueEvent.TYPE_SUBSCRIBED);
int start = 0;
for (Comment comment : fullIssue) {
for (int e = start; e < numEvents; e++) {
IssueEvent event = events.get(e);
if (comment.getCreatedAt().after(event.getCreatedAt())) {
if (!excludedEvents.contains(event.getEvent()))
if (shouldAddEvent(event, allItems))
allItems.add(event);
start++;
} else {
@@ -476,7 +482,7 @@ protected void onSuccess(FullIssue fullIssue) throws Exception {
// Adding the last events or if there are no comments
for (int e = start; e < numEvents; e++) {
IssueEvent event = events.get(e);
if (!excludedEvents.contains(event.getEvent()))
if (shouldAddEvent(event, allItems))
allItems.add(event);
}

@@ -673,4 +679,28 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
}

static private boolean shouldAddEvent(IssueEvent event, List<Object> allItems) {
// Exclude some events
List<String> excludedEvents = Arrays.asList(IssueEvent.TYPE_MENTIONED, IssueEvent.TYPE_SUBSCRIBED);
if (excludedEvents.contains(event.getEvent()))
return false;

// Don't show the close event after the merged event
if (!IssueEvent.TYPE_CLOSED.equals(event.getEvent()))
return true;

int currentSize = allItems.size();
if (currentSize == 0)
return true;

Object previousItem = allItems.get(currentSize-1);
if (!(previousItem instanceof IssueEvent))
return true;

if (IssueEvent.TYPE_MERGED.equals(((IssueEvent) previousItem).getEvent()))
return false;

return true;
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@
<color name="sign_up_text">#666666</color>
<color name="sign_up_text_link">#3797C7</color>
<color name="state_background_closed">#BD2C00</color>
<color name="state_background_merged">#6E5494</color>
<color name="state_text">#FFFFFF</color>
<color name="diff_marker_bg">#EAF2F5</color>
<color name="diff_marker_text">#999999</color>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -244,6 +244,7 @@
<string name="issue_confirm_close_title">Close Issue</string>
<string name="issue_confirm_reopen_title">Reopen Issue</string>
<string name="closed">Closed</string>
<string name="merged">Merged</string>
<string name="no_description_given">No description given.</string>
<string name="close">Close</string>
<string name="reopen">Reopen</string>

0 comments on commit 113be6f

Please sign in to comment.