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..58caea2 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..427a9db 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,9 +161,6 @@
});
}
-
-
-
// ===============================
// 2. メッセージ送信
// ===============================
@@ -196,9 +169,9 @@
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
- if (response.isSuccessful() && response.body() != null) {
- Chatroom newMessage = response.body();
-
+ if (response.isSuccessful()) {
+ // メッセージ送信成功後、すぐに最新メッセージを読み込む
+ loadLatestMessage(chatroomId, userId, token);
}
}
@@ -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..216f4e4 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.startUpdating(1); // 1秒ごとに更新
+
// buttonSend.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View view) {