Commit f2e8ba00 authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix NPE

parent 3f049ecb
...@@ -13,21 +13,21 @@ public enum MessageType { ...@@ -13,21 +13,21 @@ public enum MessageType {
@Override @Override
public String getString(Context context, Message message) { public String getString(Context context, Message message) {
return context.getString(R.string.message_room_name_changed, return context.getString(R.string.message_room_name_changed,
message.getMessage(), message.getUser().getUsername()); message.getMessage(), getUsername(message));
} }
}, },
USER_ADDED("au") { USER_ADDED("au") {
@Override @Override
public String getString(Context context, Message message) { public String getString(Context context, Message message) {
return context.getString(R.string.message_user_added_by, return context.getString(R.string.message_user_added_by,
message.getMessage(), message.getUser().getUsername()); message.getMessage(), getUsername(message));
} }
}, },
USER_REMOVED("ru") { USER_REMOVED("ru") {
@Override @Override
public String getString(Context context, Message message) { public String getString(Context context, Message message) {
return context.getString(R.string.message_user_removed_by, return context.getString(R.string.message_user_removed_by,
message.getMessage(), message.getUser().getUsername()); message.getMessage(), getUsername(message));
} }
}, },
USER_JOINED("uj") { USER_JOINED("uj") {
...@@ -45,7 +45,7 @@ public enum MessageType { ...@@ -45,7 +45,7 @@ public enum MessageType {
WELCOME("wm") { WELCOME("wm") {
@Override @Override
public String getString(Context context, Message message) { public String getString(Context context, Message message) {
return context.getString(R.string.message_welcome, message.getUser().getUsername()); return context.getString(R.string.message_welcome, getUsername(message));
} }
}, },
MESSAGE_REMOVED("rm") { MESSAGE_REMOVED("rm") {
...@@ -77,4 +77,12 @@ public enum MessageType { ...@@ -77,4 +77,12 @@ public enum MessageType {
public String getString(Context context, Message message) { public String getString(Context context, Message message) {
return ""; return "";
} }
private static String getUsername(Message message) {
if (message != null && message.getUser() != null) {
return message.getUser().getUsername();
} else {
return "";
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment