diff --git a/app/src/main/java/com/example/nemophila/FriendActivity.java b/app/src/main/java/com/example/nemophila/FriendActivity.java index ffd1b1c..5852875 100644 --- a/app/src/main/java/com/example/nemophila/FriendActivity.java +++ b/app/src/main/java/com/example/nemophila/FriendActivity.java @@ -42,6 +42,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -69,16 +70,6 @@ RecyclerView friendRecyclerView = findViewById(R.id.friendsList); LinearLayout requestingConstraintLayout = findViewById(R.id.requestingLayout); - // フレンド一覧と申請先一覧の画面切り替え - showFriend.setOnClickListener(v2 -> { - friendRecyclerView.setVisibility(View.VISIBLE); - requestingConstraintLayout.setVisibility(View.INVISIBLE); - }); - showRequesting.setOnClickListener(v3 -> { - friendRecyclerView.setVisibility(View.INVISIBLE); - requestingConstraintLayout.setVisibility(View.VISIBLE); - }); - // 初期化 List friendsDataset = new ArrayList<>(); // 1行分の情報を持つDataModelを格納するリスト RecyclerView rv = findViewById(R.id.friendsList); // recyclerViewを取得 @@ -250,10 +241,6 @@ rv_r.setHasFixedSize(true); rv_r.setLayoutManager(llm_r); - //FriendViewModelを初期化し、申請先のデータをロードしておく - friendViewModel = new ViewModelProvider(this).get(FriendViewModel.class); - friendViewModel.getRequesting(uid); - //申請先の一覧のLiveDataへの購読 friendViewModel.getRequestingLiveData().observe(this, new Observer>() { //データに変更があった時実行 @@ -301,7 +288,19 @@ } }); - // ダイアログを閉じる + // フレンド一覧と申請先一覧の画面切り替え + showFriend.setOnClickListener(v2 -> { + friendRecyclerView.setVisibility(View.VISIBLE); + requestingConstraintLayout.setVisibility(View.INVISIBLE); + friendViewModel.getFriends(uid); + }); + showRequesting.setOnClickListener(v3 -> { + friendRecyclerView.setVisibility(View.INVISIBLE); + requestingConstraintLayout.setVisibility(View.VISIBLE); + friendViewModel.getRequesting(uid); + }); + + // MyPageActivityに戻る Button closeBtn = findViewById(R.id.close); closeBtn.setOnClickListener(d -> finish()); }