diff --git a/app/src/main/java/com/example/tampopo_client/views/ChatActivity.java b/app/src/main/java/com/example/tampopo_client/views/ChatActivity.java index 494c624..00f42a4 100644 --- a/app/src/main/java/com/example/tampopo_client/views/ChatActivity.java +++ b/app/src/main/java/com/example/tampopo_client/views/ChatActivity.java @@ -20,10 +20,12 @@ import com.example.tampopo_client.Tampopo; import com.example.tampopo_client.viewmodels.ChatViewModel; import com.example.tampopo_client.viewmodels.ChatViewModelFactory; +import com.example.tampopo_client.viewmodels.UserViewModel; public class ChatActivity extends AppCompatActivity { private ChatViewModel chatViewModel; + private UserViewModel userViewModel; //メンバー変数 private EditText senderMessage; @@ -47,6 +49,7 @@ ChatViewModelFactory factory1 = new ChatViewModelFactory(tampopo.getUserId(), tampopo.getToken()); chatViewModel = new ViewModelProvider(this, factory1).get(ChatViewModel.class); chatViewModel.setChatRoomId(tampopo.getChatroomId()); + userViewModel = new ViewModelProvider(this).get(UserViewModel.class); senderMessage = findViewById(R.id.sender_message); receiverMessage = findViewById(R.id.receiver_message); @@ -54,7 +57,19 @@ backButton = findViewById(R.id.back_Button); roomId = findViewById(R.id.chat_room_id); TextView friendIdTextView = findViewById(R.id.friend_id); - friendIdTextView.setText(tampopo.getChatFriendId()); + // ひとまずIDを暫定表示 + String chatFriendId = tampopo.getChatFriendId(); + friendIdTextView.setText(chatFriendId); + // 相手のニックネームを取得して表示(最小変更のため同期APIを別スレッドで呼び出し) + new Thread(() -> { + try { + String nickname = userViewModel.getNickname(chatFriendId); + String display = (nickname != null && !nickname.isEmpty()) ? nickname : chatFriendId; + runOnUiThread(() -> friendIdTextView.setText(display)); + } catch (Exception e) { + // 失敗時はIDのまま + } + }).start(); receiverMessage.setKeyListener(null);//受信メッセージ編集不可 // buttonSend.setOnClickListener(new OnClickListener() {