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 3f0ca2c..0c5a721 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 @@ -1,5 +1,7 @@ package com.example.tampopo_client.viewmodels; +import android.os.Handler; +import android.os.Looper; import android.util.Log; import java.util.ArrayList; @@ -8,17 +10,35 @@ public class ChatViewModel extends RealTimeViewModel { private final List notificationListeners = new ArrayList<>(); - private static final double NOTIFICATION_RECEIVE_PROBABILITY = 0.01; + //private static final double NOTIFICATION_RECEIVE_PROBABILITY = 0.5; + //natty + private boolean notificationSent = false; // 一度だけ送信するためのフラグ + + +// @Override +// public Runnable onUpdate() { +// return () -> { +// // 1% の確率で onNotificationReceived() が呼び出される +// double borderValue = Math.floor(Math.random() * 100); +// double currentValue = NOTIFICATION_RECEIVE_PROBABILITY * 100; +// if (currentValue >= borderValue) { +// Log.d("ChatViewModel", "Received test notification."); +// notificationListeners.forEach(listener -> listener.onNotificationReceived()); +// } +// }; +// } + //natty @Override public Runnable onUpdate() { return () -> { - // 1% の確率で onNotificationReceived() が呼び出される - double borderValue = Math.floor(Math.random() * 100); - double currentValue = NOTIFICATION_RECEIVE_PROBABILITY * 100; - if (currentValue >= borderValue) { - Log.d("ChatViewModel", "Received test notification."); - notificationListeners.forEach(listener -> listener.onNotificationReceived()); + if (!notificationSent) { + // 10秒後に一回だけ通知を送る + notificationSent = true; // もう送らない + new Handler(Looper.getMainLooper()).postDelayed(() -> { + Log.d("ChatViewModel", "Received test notification (after 10s)."); + notificationListeners.forEach(NotificationListener::onNotificationReceived); + }, 10_000); // 10秒(10000ms) } }; }