diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageFragment.java b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageFragment.java index 88e72f5..5531868 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageFragment.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageFragment.java @@ -13,6 +13,8 @@ import org.ntlab.acanthus_client.Acanthus; import org.ntlab.acanthus_client.R; import org.ntlab.acanthus_client.databinding.FragmentMypageBinding; +import org.ntlab.acanthus_client.entities.FollowJson; +import org.ntlab.acanthus_client.entities.FollowerJson; import org.ntlab.acanthus_client.views.animation.AnimationActivity; import org.ntlab.acanthus_client.views.main_menu_ui.mypage.help.HowToUseActivity; import org.ntlab.acanthus_client.views.main_menu_ui.mypage.help.InquiryActivity; @@ -20,6 +22,7 @@ import org.ntlab.acanthus_client.views.main_menu_ui.mypage.logout.LogoutActivity; import org.ntlab.acanthus_client.views.main_menu_ui.mypage.others.PrivacyPolicyActivity; import org.ntlab.acanthus_client.views.main_menu_ui.mypage.others.TermsOfServiceActivity; +import org.ntlab.acanthus_client.views.userpage.UserPageViewModel; import org.ntlab.acanthus_client.views.userpage.followList.FollowListActivity; import org.ntlab.acanthus_client.views.userpage.followerList.FollowerListActivity; @@ -34,6 +37,7 @@ public class MyPageFragment extends Fragment { private MyPageViewModel mypageViewModel; + private UserPageViewModel userPageViewModel; private FragmentMypageBinding binding; //----------------------------------------------------------------- @@ -179,7 +183,10 @@ loginNameText.setText(acanthus.getPreferenceName()); mypageViewModel = new ViewModelProvider(this).get(MyPageViewModel.class); mypageViewModel.init(acanthus); + userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); startObserve(); + observeFollowsSize(acanthus.getPreferenceUid()); + observeFollowersSize(acanthus.getPreferenceUid()); mypageViewModel.checkInvitedRequest(); mypageViewModel.getAccountInfoRequest(); @@ -220,6 +227,36 @@ //----------------------------------------------------------------- // + public void observeFollowsSize(Integer loginUid) { + TextView followsSize = binding.followsSizeText; + + userPageViewModel.getFollows(loginUid); + userPageViewModel.getFollowJson().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(FollowJson followJson) { + Integer size = followJson.getFollowUids().size(); + followsSize.setText(size.toString()); + } + }); + } + + //----------------------------------------------------------------- + // + public void observeFollowersSize(Integer loginUid) { + TextView followersSize = binding.followersSizeText; + + userPageViewModel.getFollowers(loginUid); + userPageViewModel.getFollowerJson().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(FollowerJson followerJson) { + Integer size = followerJson.getFollowerUids().size(); + followersSize.setText(size.toString()); + } + }); + } + + //----------------------------------------------------------------- + // public void transitionFollowListActivity() { Acanthus acanthus = (Acanthus) getActivity().getApplication(); Intent intent = new Intent(acanthus, FollowListActivity.class); diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserPageActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserPageActivity.java index 8bc5636..f667570 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserPageActivity.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserPageActivity.java @@ -10,6 +10,7 @@ import org.ntlab.acanthus_client.Acanthus; import org.ntlab.acanthus_client.R; import org.ntlab.acanthus_client.entities.FollowJson; +import org.ntlab.acanthus_client.entities.FollowerJson; import org.ntlab.acanthus_client.views.userpage.followList.FollowListActivity; import org.ntlab.acanthus_client.views.userpage.followerList.FollowerListActivity; import org.ntlab.acanthus_client.views.userpage.workList.WorkListActivity; @@ -32,6 +33,7 @@ protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_userpage); + setTitle("ユーザーページ"); userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); acanthus = (Acanthus) getApplication(); @@ -48,16 +50,18 @@ userNameText.setText(uname); TextView profileText = findViewById(R.id.profileText); + TextView followsSize = findViewById(R.id.followsSizeText); + TextView followersSize = findViewById(R.id.followersSizeText); - Button returnButton = findViewById(R.id.returnButton); +// Button returnButton = findViewById(R.id.returnButton); //前の画面に戻る処理 - returnButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); +// returnButton.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// finish(); +// } +// }); Button followUserButton = findViewById(R.id.followUserButton); @@ -98,6 +102,24 @@ } }); + //フォロー及びフォロワーの数を表示 + userPageViewModel.getUserFollows(uid); + userPageViewModel.getUserFollowJson().observe(this, new Observer() { + @Override + public void onChanged(FollowJson followJson) { + Integer size = followJson.getFollowUids().size(); + followsSize.setText(size.toString()); + } + }); + userPageViewModel.getFollowers(uid); + userPageViewModel.getFollowerJson().observe(this, new Observer() { + @Override + public void onChanged(FollowerJson followerJson) { + Integer size = followerJson.getFollowerUids().size(); + followersSize.setText(size.toString()); + } + }); + //ユーザーのフォロー一覧への画面遷移の処理 Button followListButton = findViewById(R.id.followListButton); followListButton.setOnClickListener(new View.OnClickListener() { diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserPageViewModel.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserPageViewModel.java index 6f787a6..eb378c6 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserPageViewModel.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserPageViewModel.java @@ -22,11 +22,13 @@ public class UserPageViewModel extends ViewModel { private MutableLiveData followJsonMutableLiveData; + private MutableLiveData followJsonMutableLiveData2; private MutableLiveData followerJsonMutableLiveData; private MutableLiveData> animationJsonMutableLiveData; public UserPageViewModel(){ this.followJsonMutableLiveData = new MutableLiveData<>(); + this.followJsonMutableLiveData2 = new MutableLiveData<>(); this.followerJsonMutableLiveData = new MutableLiveData<>(); this.animationJsonMutableLiveData = new MutableLiveData<>(); } @@ -35,6 +37,10 @@ return this.followJsonMutableLiveData; } + public LiveData getUserFollowJson() { + return this.followJsonMutableLiveData2; + } + public LiveData getFollowerJson() { return this.followerJsonMutableLiveData; } @@ -71,6 +77,34 @@ } + //ユーザーのフォローリストを取得する(衝突回避用) + public void getUserFollows(Integer uid){ + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + final FollowsRest followsRest = retrofit.create(FollowsRest.class); + + //フォローリストの取得 + Call call = followsRest.getFollows(uid); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + if (response.body() != null) { + followJsonMutableLiveData2.setValue(response.body()); + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + + } + //ユーザーをフォローする public void addFollow(Integer uid, String token, Integer followUid){ Retrofit retrofit = new Retrofit.Builder() diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListActivity.java index 9d86815..174d872 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListActivity.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListActivity.java @@ -28,21 +28,22 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_follow_list); + setTitle("フォロー中"); userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); Intent intent = getIntent(); //UserPageActivityからuidをもらう Integer uid = intent.getIntExtra("UID", 0); ListView listView = findViewById(R.id.followListView); - Button returnButton = findViewById(R.id.returnFollowButton); +// Button returnButton = findViewById(R.id.returnFollowButton); //前の画面に戻る処理 - returnButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); +// returnButton.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// finish(); +// } +// }); //フォロー一覧の取得と表示 userPageViewModel.getFollows(uid); diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListActivity.java index 22aad87..b906211 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListActivity.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListActivity.java @@ -30,21 +30,22 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_follower_list); + setTitle("フォロワー"); userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); Intent intent = getIntent(); //UserPageActivityからuidをもらう Integer uid = intent.getIntExtra("UID", 0); ListView listView = findViewById(R.id.followerListView); - Button returnButton = findViewById(R.id.returnFollowerButton); +// Button returnButton = findViewById(R.id.returnFollowerButton); //前の画面に戻る処理 - returnButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); +// returnButton.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// finish(); +// } +// }); //フォロワー一覧の取得と表示 userPageViewModel.getFollowers(uid); diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListActivity.java index 26ed5ca..8f5057c 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListActivity.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListActivity.java @@ -34,21 +34,22 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_work_list); + setTitle("作品一覧"); userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); Intent intent = getIntent(); //UserPageActivityからuidをもらう Integer uid = intent.getIntExtra("UID", 0); ListView listView = findViewById(R.id.workListView); - Button returnButton = findViewById(R.id.returnWorkButton); +// Button returnButton = findViewById(R.id.returnWorkButton); //前の画面に戻る処理 - returnButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); +// returnButton.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// finish(); +// } +// }); //全ユーザーの作品から特定のユーザーの作品を抽出し、一覧として表示する userPageViewModel.getGallery(); diff --git a/app/src/main/res/layout/activity_follow_list.xml b/app/src/main/res/layout/activity_follow_list.xml index 84c25ab..b123b37 100644 --- a/app/src/main/res/layout/activity_follow_list.xml +++ b/app/src/main/res/layout/activity_follow_list.xml @@ -5,19 +5,6 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - - - + + + + + -