Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Display issue closed reason in timeline events #1223

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 60 additions & 39 deletions app/src/main/java/com/gh4a/adapter/timeline/EventViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
import com.meisolsson.githubsdk.model.Issue;
import com.meisolsson.githubsdk.model.IssueEvent;
import com.meisolsson.githubsdk.model.IssueEventType;
import com.meisolsson.githubsdk.model.IssueStateReason;
import com.meisolsson.githubsdk.model.Label;
import com.meisolsson.githubsdk.model.Rename;
import com.meisolsson.githubsdk.model.User;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -42,32 +44,6 @@ class EventViewHolder

private static final Pattern COMMIT_URL_REPO_NAME_AND_OWNER_PATTERN =
Pattern.compile(".*github\\.com/repos/([^/]+)/([^/]+)/commits");
private static final HashMap<IssueEventType, Integer> EVENT_ICONS = new HashMap<>();

static {
EVENT_ICONS.put(IssueEventType.Closed, R.drawable.issue_event_closed);
EVENT_ICONS.put(IssueEventType.Reopened, R.drawable.issue_event_reopened);
EVENT_ICONS.put(IssueEventType.Merged, R.drawable.issue_event_merged);
EVENT_ICONS.put(IssueEventType.Referenced, R.drawable.issue_event_referenced);
EVENT_ICONS.put(IssueEventType.Assigned, R.drawable.issue_event_person);
EVENT_ICONS.put(IssueEventType.Unassigned, R.drawable.issue_event_person);
EVENT_ICONS.put(IssueEventType.Labeled, R.drawable.issue_event_label);
EVENT_ICONS.put(IssueEventType.Unlabeled, R.drawable.issue_event_label);
EVENT_ICONS.put(IssueEventType.Locked, R.drawable.issue_event_locked);
EVENT_ICONS.put(IssueEventType.Unlocked, R.drawable.issue_event_unlocked);
EVENT_ICONS.put(IssueEventType.Milestoned, R.drawable.issue_event_milestone);
EVENT_ICONS.put(IssueEventType.Demilestoned, R.drawable.issue_event_milestone);
EVENT_ICONS.put(IssueEventType.Renamed, R.drawable.issue_event_renamed);
EVENT_ICONS.put(IssueEventType.HeadRefDeleted, R.drawable.timeline_event_branch);
EVENT_ICONS.put(IssueEventType.HeadRefRestored, R.drawable.timeline_event_branch);
EVENT_ICONS.put(IssueEventType.HeadRefForcePushed, R.drawable.timeline_event_branch);
EVENT_ICONS.put(IssueEventType.CommentDeleted, R.drawable.timeline_event_comment_deleted);
EVENT_ICONS.put(IssueEventType.ReviewRequested, R.drawable.timeline_event_review);
EVENT_ICONS.put(IssueEventType.ReviewRequestRemoved, R.drawable.timeline_event_review_request_removed);
EVENT_ICONS.put(IssueEventType.ConvertToDraft, R.drawable.timeline_event_branch);
EVENT_ICONS.put(IssueEventType.ReadyForReview, R.drawable.timeline_event_review);
EVENT_ICONS.put(IssueEventType.CrossReferenced, R.drawable.timeline_event_cross_referenced);
}

private final Context mContext;
private final String mRepoOwner;
Expand Down Expand Up @@ -102,37 +78,77 @@ public void bind(TimelineItem.TimelineEvent item) {
AvatarHandler.assignAvatar(mAvatarView, user);
mAvatarContainer.setTag(user);

Integer eventIconResId = EVENT_ICONS.get(item.event.event());
Integer eventIconResId = getEventIcon(item.event);
if (eventIconResId != null) {
mEventIconView.setImageResource(eventIconResId);
mEventIconView.setVisibility(View.VISIBLE);
} else {
mEventIconView.setVisibility(View.GONE);
}

mMessageView.setText(formatEvent(item.event, user,
mMessageView.getTypefaceValue(), mIsPullRequest));
mMessageView.setText(formatEvent(item.event, user, mMessageView.getTypefaceValue()));
}

private Integer getEventIcon(IssueEvent event) {
switch (event.event()) {
case Closed:
return mIsPullRequest || event.stateReason() == IssueStateReason.NotPlanned
? R.drawable.issue_event_closed
: R.drawable.issue_event_closed_completed;
case Reopened: return R.drawable.issue_event_reopened;
case Merged: return R.drawable.issue_event_merged;
case Referenced: return R.drawable.issue_event_referenced;
case Assigned:
case Unassigned:
return R.drawable.issue_event_person;
case Labeled:
case Unlabeled:
return R.drawable.issue_event_label;
case Locked: return R.drawable.issue_event_locked;
case Unlocked: return R.drawable.issue_event_unlocked;
case Milestoned:
case Demilestoned:
return R.drawable.issue_event_milestone;
case Renamed: return R.drawable.issue_event_renamed;
case CommentDeleted: return R.drawable.timeline_event_comment_deleted;
case HeadRefDeleted:
case HeadRefRestored:
case HeadRefForcePushed:
case ConvertToDraft:
return R.drawable.timeline_event_branch;
case ReviewRequested:
case ReadyForReview:
return R.drawable.timeline_event_review;
case ReviewRequestRemoved: return R.drawable.timeline_event_review_request_removed;
case CrossReferenced: return R.drawable.timeline_event_cross_referenced;
}
return null;
}

private CharSequence formatEvent(final IssueEvent event, final User user, int typefaceValue,
boolean isPullRequestEvent) {
private CharSequence formatEvent(final IssueEvent event, final User user, int typefaceValue) {
String textBase = null;
int textResId = 0;

switch (event.event()) {
case Closed:
if (isPullRequestEvent) {
if (mIsPullRequest) {
textResId = event.commitId() != null
? R.string.pull_request_event_closed_with_commit
: R.string.pull_request_event_closed;
} else {
textResId = event.commitId() != null
? R.string.issue_event_closed_with_commit
: R.string.issue_event_closed;
if (event.stateReason() == IssueStateReason.NotPlanned) {
textResId = event.commitId() != null
? R.string.issue_event_closed_not_planned_with_commit
: R.string.issue_event_closed_not_planned;
} else {
textResId = event.commitId() != null
? R.string.issue_event_closed_completed_with_commit
: R.string.issue_event_closed_completed;
}
}
break;
case Reopened:
textResId = isPullRequestEvent
textResId = mIsPullRequest
? R.string.pull_request_event_reopened
: R.string.issue_event_reopened;
break;
Expand All @@ -142,7 +158,7 @@ private CharSequence formatEvent(final IssueEvent event, final User user, int ty
: R.string.pull_request_event_merged;
break;
case Referenced:
if (isPullRequestEvent) {
if (mIsPullRequest) {
textResId = event.commitId() != null
? R.string.pull_request_event_referenced_with_commit
: R.string.pull_request_event_referenced;
Expand All @@ -159,7 +175,7 @@ private CharSequence formatEvent(final IssueEvent event, final User user, int ty
String assigneeLogin = event.assignee() != null ? event.assignee().login() : null;
if (assigneeLogin != null && assigneeLogin.equals(actorLogin)) {
if (isAssign) {
textResId = isPullRequestEvent
textResId = mIsPullRequest
? R.string.pull_request_event_assigned_self
: R.string.issue_event_assigned_self;
} else {
Expand All @@ -182,7 +198,12 @@ private CharSequence formatEvent(final IssueEvent event, final User user, int ty
textResId = R.string.issue_event_unlabeled;
break;
case Locked:
textResId = R.string.issue_event_locked;
if (event.lockReason() == null) {
textResId = R.string.issue_event_locked;
} else {
textBase = mContext.getString(R.string.issue_event_locked_with_reason,
getUserLoginWithBotSuffix(user), event.lockReason());
}
break;
case Unlocked:
textResId = R.string.issue_event_unlocked;
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/drawable-night/issue_event_closed_completed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillAlpha="1"
android:fillColor="#563996"
android:pathData="M12,0A12,12 0,0 1,24 12,12 12,0 0,1 12,24 12,12 0,0 1,-0 12,12 12,0 0,1 12,0"
android:strokeWidth="1.19999993" />
<path
android:fillAlpha="1"
android:fillColor="#ffffff"
android:pathData="m10.75,16.205 l7,-7 -1.41,-1.41 -5.59,5.58 -3.09,-3.08 -1.41,1.41z" />
</vector>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/issue_event_closed_completed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillAlpha="1"
android:fillColor="#8558e6"
android:pathData="M12,0A12,12 0,0 1,24 12,12 12,0 0,1 12,24 12,12 0,0 1,-0 12,12 12,0 0,1 12,0"
android:strokeWidth="1.19999993" />
<path
android:fillAlpha="1"
android:fillColor="#ffffff"
android:pathData="m10.75,16.205 l7,-7 -1.41,-1.41 -5.59,5.58 -3.09,-3.08 -1.41,1.41z" />
</vector>
7 changes: 5 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@
<string name="repo_activity">Activity</string>

<!-- Issue events -->
<string name="issue_event_closed">[b]%1$s[/b] closed this issue [time]</string>
<string name="issue_event_closed_with_commit">[b]%1$s[/b] closed this issue in [commit] [time]</string>
<string name="issue_event_closed_completed">[b]%1$s[/b] closed this issue as completed [time]</string>
<string name="issue_event_closed_completed_with_commit">[b]%1$s[/b] closed this issue as completed in [commit] [time]</string>
<string name="issue_event_closed_not_planned">[b]%1$s[/b] closed this issue as not planned [time]</string>
<string name="issue_event_closed_not_planned_with_commit">[b]%1$s[/b] closed this issue as not planned in [commit] [time]</string>
<string name="issue_event_reopened">[b]%1$s[/b] reopened this issue [time]</string>
<string name="issue_event_referenced">[b]%1$s[/b] referenced this issue [time]</string>
<string name="issue_event_referenced_with_commit">[b]%1$s[/b] referenced this issue in commit [commit] [time]</string>
Expand All @@ -301,6 +303,7 @@
<string name="issue_event_demilestoned">[b]%1$s[/b] removed this from the [b]%2$s[/b] milestone [time]</string>
<string name="issue_event_renamed">[b]%1$s[/b] changed the title from [b]%2$s[/b] to [b]%3$s[/b] [time]</string>
<string name="issue_event_locked">[b]%1$s[/b] locked and limited conversation to collaborators [time]</string>
<string name="issue_event_locked_with_reason">[b]%1$s[/b] locked as [b]%2$s[/b] and limited conversation to collaborators [time]</string>
<string name="issue_event_unlocked">[b]%1$s[/b] unlocked this conversation [time]</string>
<string name="issue_event_mentioned">[b]%1$s[/b] mentioned this issue in [b][source][/b] [time]</string>

Expand Down