diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7bee9cc..09ad5d2 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,8 +1,9 @@
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
diff --git a/app/src/main/java/com/example/tampopo_client/Tampopo.java b/app/src/main/java/com/example/tampopo_client/Tampopo.java
index 3cff24c..735dada 100644
--- a/app/src/main/java/com/example/tampopo_client/Tampopo.java
+++ b/app/src/main/java/com/example/tampopo_client/Tampopo.java
@@ -6,10 +6,12 @@
private String token;
private String userId;
private String password;
+ private String chatroomId;
+ private String mailaddress;
+ private String nickname;
+ private String icon;
- public String getToken() {
- return token;
- }
+ public String getToken() {return token;}
public void setToken(String token) {
this.token = token;
@@ -30,4 +32,24 @@
public void setPassword(String password) {
this.password = password;
}
+
+ public String getChatroomId() {
+ return chatroomId;
+ }
+
+ public void setChatroomId(String ChatroomId) {
+ this.chatroomId = ChatroomId;
+ }
+
+ public String getMailaddress() { return mailaddress; }
+
+ public void setMailaddress(String mailaddress) {this.mailaddress = mailaddress; }
+
+ public String getNickname() { return nickname; }
+
+ public void setNickname(String nickname) {this.nickname = nickname; }
+
+ public String getIcon() { return icon; }
+
+ public void setIcon(String icon) {this.icon = icon; }
}
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)
}
};
}
diff --git a/app/src/main/java/com/example/tampopo_client/views/AccountActivity.java b/app/src/main/java/com/example/tampopo_client/views/AccountActivity.java
new file mode 100644
index 0000000..90ed189
--- /dev/null
+++ b/app/src/main/java/com/example/tampopo_client/views/AccountActivity.java
@@ -0,0 +1,106 @@
+package com.example.tampopo_client.views;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageButton;
+
+import androidx.activity.EdgeToEdge;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.graphics.Insets;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowInsetsCompat;
+
+import com.example.tampopo_client.R;
+import com.example.tampopo_client.Tampopo;
+
+public class AccountActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ EdgeToEdge.enable(this);
+ setContentView(R.layout.activity_account);
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
+ Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
+ v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
+ return insets;
+ });
+
+
+ //アカウント編集画面から設定画面への遷移
+ ImageButton buttonReturn = (ImageButton)findViewById(R.id.buttonReturn);
+ buttonReturn.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ Intent intent = new Intent(AccountActivity.this, SettingActivity.class);
+ startActivity(intent);
+ }
+ });
+
+ //もともとのメールアドレスを表示
+ EditText mailbuttonInput = (EditText) findViewById(R.id.mailbutton);
+ mailbuttonInput.setText(((Tampopo) AccountActivity.this.getApplication()).getMailaddress());
+
+ //決定ボタンを押したときにパスワードとメールアドレスを保存
+ Button dicisionbutton = (Button) findViewById(R.id.dicisionbutton);
+ dicisionbutton.setOnClickListener(new View.OnClickListener() {
+
+ private Object getApplication;
+
+ public void onClick(View v) {
+ //現在のパスワード
+ EditText beforepasswordbuttonInput = (EditText) findViewById(R.id.beforepasswordbutton);
+ String beforepasswordbutton = beforepasswordbuttonInput.getText().toString();
+
+ //パスワード変更
+ EditText afterpasswordbutton1Input = (EditText) findViewById(R.id.afterpasswordbutton1);
+ String afterpasswordbutton1 = afterpasswordbutton1Input.getText().toString();
+
+ EditText afterpasswordbutton2Input = (EditText) findViewById(R.id.afterpasswordbutton2);
+ String afterpasswordbutton2 = afterpasswordbutton1Input.getText().toString();
+ ((Tampopo) AccountActivity.this.getApplication()).setPassword(afterpasswordbutton2);
+
+ //メールアドレス登録
+ EditText mailbuttonInput = (EditText) findViewById(R.id.mailbutton);
+ String mailbutton = mailbuttonInput.getText().toString();
+ ((Tampopo) AccountActivity.this.getApplication()).setMailaddress(mailbutton);
+
+ //もし前のパスワードが合っていなかったはじくようにする
+
+
+ //決定を押したら設定画面に遷移
+ Intent intent = new Intent(AccountActivity.this, SettingActivity.class);
+ startActivity(intent);
+ }
+ });
+
+// //もし前のパスワードが合っていなかったはじくようにする
+//
+//
+// //決定を押したら設定画面に遷移
+// dicisionbutton.setOnClickListener(new View.OnClickListener() {
+//
+// private Object getApplication;
+//
+// public void onClick(View v) {
+//
+// Intent intent = new Intent(AccountActivity.this, SettingActivity.class);
+// startActivity(intent);
+//
+//
+// }
+// });
+
+ }
+ @Override
+ protected void onStart() {
+ super.onStart();
+
+ //もともとのメールアドレスを表示
+ EditText mailbuttonInput = (EditText) findViewById(R.id.mailbutton);
+ mailbuttonInput.setText(((Tampopo) AccountActivity.this.getApplication()).getMailaddress());
+
+ }
+}
\ 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
new file mode 100644
index 0000000..10cc5ed
--- /dev/null
+++ b/app/src/main/java/com/example/tampopo_client/views/ChatActivity.java
@@ -0,0 +1,98 @@
+package com.example.tampopo_client.views;
+
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import androidx.activity.EdgeToEdge;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.graphics.Insets;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowInsetsCompat;
+import androidx.core.view.WindowInsetsCompat.Type;
+import androidx.lifecycle.ViewModelProvider;
+import com.example.tampopo_client.R;
+import com.example.tampopo_client.Tampopo;
+import com.example.tampopo_client.viewmodels.ChatroomViewModel;
+import com.example.tampopo_client.viewmodels.NotificationListener;
+import com.example.tampopo_client.viewmodels.UserViewModel;
+
+public class ChatActivity extends AppCompatActivity {
+
+ private ChatroomViewModel chatViewModel;
+
+ //メンバー変数
+ private EditText senderMessage;
+ private EditText receiverMessage;
+ private Button buttonSend;
+
+ Tampopo tampopo;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ tampopo = (Tampopo)getApplication();
+
+ super.onCreate(savedInstanceState);//Activityの基本的な初期化処理
+ EdgeToEdge.enable(this);//画面の端っこまで使う(Edge-to-Edge)表示
+ setContentView(R.layout.activity_chat);//表示する画面のレイアウトXMLファイル(activity_chat.xml)を指定
+
+ chatViewModel = new ViewModelProvider(this).get(ChatroomViewModel.class);
+
+ senderMessage = findViewById(R.id.sender_message);
+ receiverMessage = findViewById(R.id.receiver_message);
+ buttonSend = findViewById(R.id.buttonSend);
+
+ receiverMessage.setKeyListener(null);//受信メッセージ編集不可
+
+// buttonSend.setOnClickListener(new OnClickListener() {
+// @Override
+// public void onClick(View view) {
+// String receiverText = receiverMessage.getText().toString();//receiverMessageにユーザーが入力した文字を取り出して、String型の 変数receiverText に入れる
+// if (!receiverText.isEmpty()) {
+// String senderId = tampopo.getUserId();
+// String token = tampopo.getToken();
+// ChatroomViewModel.loadLatestMessage(null, senderId, token);
+// receiverMessage.setText(receiverText);//受信欄に表示
+// senderMessage.setText("");//送信欄をクリア
+// }
+// }
+// });
+
+// String receiverText = senderMessage.getText().toString();//senderMessageにユーザーが入力した文字を取り出して、String型の 変数receiverText に入れる
+// if (!receiverText.isEmpty()) {
+// receiverMessage.setText(ChatroomViewModel.latestMessage);
+// }
+
+ buttonSend.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ String senderText = senderMessage.getText().toString();//senderMessageにユーザーが入力した文字を取り出して、String型の 変数receiverText に入れる
+ if (!senderText.isEmpty()) {
+ String senderId = tampopo.getUserId();
+ String token = tampopo.getToken();
+ String chatroomId = tampopo.getChatroomId();
+ ChatroomViewModel.senderMessage(chatroomId, senderId, senderText, token);
+ senderMessage.setText(senderText);//送信欄に表示
+ }
+ }
+ });
+
+ chatViewModel.getLatestMessageLiveData().observe(this, receiverText -> {
+ if (receiverText != null) {
+ receiverMessage.setText(receiverText.getContent());
+ }
+ });
+
+
+
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
+ Insets systemBars = insets.getInsets(Type.systemBars());
+ v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
+ return insets;
+ });
+
+
+ }
+
+}
diff --git a/app/src/main/java/com/example/tampopo_client/views/LoginActivity.java b/app/src/main/java/com/example/tampopo_client/views/LoginActivity.java
index 4e598b5..52837ad 100644
--- a/app/src/main/java/com/example/tampopo_client/views/LoginActivity.java
+++ b/app/src/main/java/com/example/tampopo_client/views/LoginActivity.java
@@ -53,13 +53,13 @@
}
});
- Button button_login = (Button) findViewById(R.id.loginbutton);
+ Button button_login = (Button) findViewById(R.id.dicisionbutton);
button_login.setOnClickListener(new OnClickListener() {
private Object getApplication;
public void onClick(View v) {
- EditText useridInput = (EditText) findViewById(R.id.userIDText);
+ EditText useridInput = (EditText) findViewById(R.id.idbutton);
String userid = useridInput.getText().toString();
((Tampopo) LoginActivity.this.getApplication()).setUserId(userid);
EditText passwordInput = (EditText) findViewById(R.id.PasswordText);
diff --git a/app/src/main/java/com/example/tampopo_client/views/LogoutActivity.java b/app/src/main/java/com/example/tampopo_client/views/LogoutActivity.java
new file mode 100644
index 0000000..35b0561
--- /dev/null
+++ b/app/src/main/java/com/example/tampopo_client/views/LogoutActivity.java
@@ -0,0 +1,49 @@
+package com.example.tampopo_client.views;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ImageButton;
+
+import androidx.activity.EdgeToEdge;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.graphics.Insets;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowInsetsCompat;
+
+import com.example.tampopo_client.R;
+
+public class LogoutActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ EdgeToEdge.enable(this);
+ setContentView(R.layout.activity_logout);
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
+ Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
+ v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
+ return insets;
+ });
+
+ //ログアウト画面から設定画面への遷移
+ Button cancelbutton = (Button) findViewById(R.id.cancelbutton);
+ cancelbutton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ Intent intent = new Intent(LogoutActivity.this, SettingActivity.class);
+ startActivity(intent);
+ }
+ });
+
+ //ログアウト画面から新規登録画面への遷移
+ Button logoutbutton = (Button) findViewById(R.id.logoutbutton);
+ logoutbutton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ Intent intent = new Intent(LogoutActivity.this, SettingActivity.class);
+ startActivity(intent);
+ }
+ });
+
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/tampopo_client/views/MainActivity.java b/app/src/main/java/com/example/tampopo_client/views/MainActivity.java
index c21e92b..d5021fd 100644
--- a/app/src/main/java/com/example/tampopo_client/views/MainActivity.java
+++ b/app/src/main/java/com/example/tampopo_client/views/MainActivity.java
@@ -1,7 +1,14 @@
package com.example.tampopo_client.views;
+import android.app.Dialog;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Build;
import android.os.Bundle;
+import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
@@ -9,12 +16,18 @@
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
+import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+import androidx.core.app.NotificationCompat;
+import androidx.core.app.NotificationManagerCompat;
+import androidx.core.content.ContextCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
@@ -26,10 +39,14 @@
import com.example.tampopo_client.Tampopo;
import com.example.tampopo_client.models.Activity;
import com.example.tampopo_client.viewmodels.ActivityViewModel;
+import com.google.android.material.imageview.ShapeableImageView;
import com.example.tampopo_client.viewmodels.ActivityViewModelFactory;
import com.example.tampopo_client.viewmodels.ChatViewModel;
import com.example.tampopo_client.viewmodels.NotificationListener;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public class MainActivity extends AppCompatActivity implements NotificationListener {
@@ -42,12 +59,14 @@
//アクティビティの選択肢
private String[] words = {"ひまnow", "あそぼ!", "そろそろ会いたない〜?", "勉強なう", "電話しよ~", "お風呂入ってくる~", "今暇だよー!", "いそがしい~!!"};
private Button openDialogButton;
+ private Map userViews = new HashMap<>();
ActivityViewModel activityViewModel;
Tampopo tampopo;
private ChatViewModel chatViewModel;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -59,6 +78,21 @@
return insets;
});
+ //疑似的な通知のためにchatViewModelを定義する
+ chatViewModel = new ViewModelProvider(this).get(ChatViewModel.class);
+ chatViewModel.addNotificationListener(this);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS)
+ != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(
+ this,
+ new String[]{android.Manifest.permission.POST_NOTIFICATIONS},
+ 1001
+ );
+ }
+ }
+
+// handleIncomingIntent(getIntent());
//メイン画面からフレンド一覧画面への遷移
ImageButton friendButton = (ImageButton) findViewById(R.id.friend);
friendButton.setOnClickListener(new View.OnClickListener() {
@@ -90,10 +124,10 @@
// }
// });
- MutableLiveData