diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index b589d56..b86273d 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml
index b268ef3..764e884 100644
--- a/.idea/deploymentTargetSelector.xml
+++ b/.idea/deploymentTargetSelector.xml
@@ -4,6 +4,14 @@
+
+
+
+
+
+
+
+
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 0897082..639c779 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -4,6 +4,7 @@
-
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 8978d23..74dd639 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,7 @@
+
-
+
diff --git a/app/src/main/java/com/example/tampopo_client/viewmodels/ChatViewModel.java b/app/src/main/java/com/example/tampopo_client/viewmodels/ChatViewModel.java
index 80b1fce..dd58bf9 100644
--- a/app/src/main/java/com/example/tampopo_client/viewmodels/ChatViewModel.java
+++ b/app/src/main/java/com/example/tampopo_client/viewmodels/ChatViewModel.java
@@ -8,7 +8,6 @@
import com.example.tampopo_client.models.ChatMessage;
import com.example.tampopo_client.models.Chatroom;
-import com.example.tampopo_client.models.Chatroom;
import com.example.tampopo_client.resources.ChatroomResource;
import java.io.IOException;
@@ -28,7 +27,7 @@
// --- LiveData ---
private final MutableLiveData chatroomIdLiveData = new MutableLiveData<>();
- private final MutableLiveData> chatMessages = new MutableLiveData<>(new ArrayList<>());
+ private final MutableLiveData> chatMessages = new MutableLiveData<>(new ArrayList<>());
private final MutableLiveData latestMessage = new MutableLiveData<>();
private final MutableLiveData chatroomClosed = new MutableLiveData<>();
@@ -81,20 +80,11 @@
@Override
public Runnable onUpdate() {
return () -> {
- if (!notificationSent) {
- notificationSent = true;
- new Handler(Looper.getMainLooper()).postDelayed(() -> {
- Log.d("ChatViewModel", "Received test notification (after 10s).");
- notificationListeners.forEach(NotificationListener::onNotificationReceived);
- }, 10_000); // 10秒後に通知
+ foundChatroom(userId, token);
+ String currentChatroomId = chatroomIdLiveData.getValue();
+ if (currentChatroomId != null) {
+ loadLatestMessage(currentChatroomId, userId, token);
}
- foundChatroom(userId,token);
- System.out.println(chatroomIdLiveData.getValue());
- if (chatroomId != null){
- loadLatestMessage(chatroomId, userId, token);
- };
-
- //chatroomIdがnullの時は呼び出さないようにしました
};
}
@@ -104,7 +94,7 @@
return chatroomIdLiveData;
}
- public MutableLiveData> getChatMessages() {
+ public MutableLiveData> getChatMessages() {
return chatMessages;
}
@@ -139,20 +129,6 @@
} catch (IOException e) {
throw new RuntimeException(e);
}
-// call.enqueue(new Callback() {
-// @Override
-// public void onResponse(Call call, Response response) {
-// if (response.isSuccessful() && response.body() != null) {
-// chatroomIdLiveData.setValue(response.body().getChatroomId());
-// Log.d("ChatVM", "enterChatroom success → chatroomId: " + response.body().getChatroomId());
-// }
-// }
-//
-// @Override
-// public void onFailure(Call call, Throwable t) {
-// Log.e("ChatVM", "enterChatroom error: " + t.getMessage());
-// }
-// });
}
// 1.5 自分がchatroomに入っているのか確認する
@@ -185,26 +161,23 @@
});
}
-
-
-
// ===============================
// 2. メッセージ送信
// ===============================
public void sendMessage(String chatroomId, String senderId, String message, String token) {
- Call call = chatroomResource.sendMessage(chatroomId, senderId, message, token);
- call.enqueue(new Callback() {
+ Call call = chatroomResource.sendMessage(chatroomId, senderId, message, token);
+ call.enqueue(new Callback() {
@Override
- public void onResponse(Call call, Response response) {
- if (response.isSuccessful() && response.body() != null) {
- Chatroom newMessage = response.body();
-
+ public void onResponse(Call call, Response response) {
+ if (response.isSuccessful()) {
+ // メッセージ送信成功後、すぐに最新メッセージを読み込む
+ loadLatestMessage(chatroomId, userId, token);
}
}
@Override
- public void onFailure(Call call, Throwable t) {
+ public void onFailure(Call call, Throwable t) {
Log.e("ChatVM", "sendMessage error: " + t.getMessage());
}
});
@@ -286,4 +259,3 @@
isChecking = false;
}
}
-//
\ No newline at end of file
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 73b36f7..9545d3f 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
@@ -55,6 +55,8 @@
roomId = findViewById(R.id.chat_room_id);
receiverMessage.setKeyListener(null);//受信メッセージ編集不可
+ chatViewModel.start(1000); // 1秒ごとに更新
+
// buttonSend.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View view) {
@@ -109,7 +111,7 @@
String token = tampopo.getToken();
String chatroomId = tampopo.getChatroomId();
//String chatroomId = "0";
- chatViewModel.sendMessage(chatroomId, senderId, senderText, token);
+ chatViewModel.sendMessage(chatroomId, senderId, senderText, token, false);
senderMessage.setText("");//自分のメッセージを消す
}
}