Skip to content

Commit 74c9b80

Browse files
committed
Fix crash when commit author data is missing
Closes #829
1 parent 53a3502 commit 74c9b80

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

app/src/main/java/com/gh4a/adapter/CommitAdapter.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.content.Intent;
2020
import android.graphics.Typeface;
2121
import android.support.v7.widget.RecyclerView;
22+
import android.text.TextUtils;
2223
import android.view.LayoutInflater;
2324
import android.view.View;
2425
import android.view.ViewGroup;
@@ -51,12 +52,13 @@ public ViewHolder onCreateViewHolder(LayoutInflater inflater, ViewGroup parent,
5152
@Override
5253
public void onBindViewHolder(ViewHolder holder, Commit commit) {
5354
User author = commit.author();
54-
if (author != null) {
55+
if (author != null && !TextUtils.isEmpty(author.name())) {
5556
AvatarHandler.assignAvatar(holder.ivGravatar, author);
5657
} else {
5758
GitUser commitAuthor = commit.commit().author();
59+
String userName = commitAuthor != null ? commitAuthor.name() : null;
5860
String email = commitAuthor != null ? commitAuthor.email() : null;
59-
holder.ivGravatar.setImageDrawable(new AvatarHandler.DefaultAvatarDrawable(null, email));
61+
holder.ivGravatar.setImageDrawable(new AvatarHandler.DefaultAvatarDrawable(userName, email));
6062
}
6163
holder.ivGravatar.setTag(commit);
6264

app/src/main/java/com/gh4a/utils/ApiHelpers.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ public interface IssueState {
5151

5252
//RepositoryCommit
5353
public static String getAuthorName(Context context, Commit commit) {
54-
if (commit.author() != null) {
55-
return commit.author().login();
54+
User author = commit.author();
55+
if (author != null && !TextUtils.isEmpty(author.login())) {
56+
return author.login();
5657
}
57-
if (commit.commit().author() != null) {
58-
return commit.commit().author().name();
58+
GitUser commitAuthor = commit.commit().author();
59+
if (commitAuthor != null && !TextUtils.isEmpty(commitAuthor.name())) {
60+
return commitAuthor.name();
5961
}
6062
return context.getString(R.string.unknown);
6163
}

app/src/main/java/com/gh4a/utils/AvatarHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private void processResult(long requestId, Bitmap bitmap) {
9292
};
9393

9494
public static void assignAvatar(ImageView view, User user) {
95-
if (user == null) {
95+
if (user == null || user.id() == null) {
9696
assignAvatar(view, null, 0, null);
9797
return;
9898
}

0 commit comments

Comments
 (0)