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..27380e1 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; @@ -180,6 +183,8 @@ mypageViewModel = new ViewModelProvider(this).get(MyPageViewModel.class); mypageViewModel.init(acanthus); startObserve(); + observeFollowsSize(acanthus.getPreferenceUid()); + observeFollowersSize(acanthus.getPreferenceUid()); mypageViewModel.checkInvitedRequest(); mypageViewModel.getAccountInfoRequest(); @@ -220,6 +225,36 @@ //----------------------------------------------------------------- // + public void observeFollowsSize(Integer loginUid) { + TextView followsSize = binding.followsSizeText; + + mypageViewModel.getMyFollows(loginUid); + mypageViewModel.getMyFollowJson().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; + + mypageViewModel.getMyFollowers(loginUid); + mypageViewModel.getMyFollowerJson().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/main_menu_ui/mypage/MyPageViewModel.java b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageViewModel.java index ba633d4..bfc4463 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageViewModel.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageViewModel.java @@ -3,8 +3,17 @@ import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; import org.ntlab.acanthus_client.Acanthus; +import org.ntlab.acanthus_client.entities.FollowJson; +import org.ntlab.acanthus_client.entities.FollowerJson; +import org.ntlab.acanthus_client.resources.accounts.FollowersRest; +import org.ntlab.acanthus_client.resources.accounts.FollowsRest; //----------------------------------------------------------------- @@ -13,6 +22,8 @@ private MyPageModelContainer myPageModelContainer; private MutableLiveData mIsInvited = new MutableLiveData<>(); private MutableLiveData mUidText = new MutableLiveData<>(); + private MutableLiveData myFollowJsonMutableLiveData; + private MutableLiveData myFollowerJsonMutableLiveData; //----------------------------------------------------------------- // getter @@ -24,11 +35,21 @@ return mUidText; } + public LiveData getMyFollowJson() { + return myFollowJsonMutableLiveData; + } + + public LiveData getMyFollowerJson() { + return myFollowerJsonMutableLiveData; + } + //----------------------------------------------------------------- //----------------------------------------------------------------- // init public void init(Acanthus acanthus) { myPageModelContainer = new MyPageModelContainer(acanthus); + this.myFollowJsonMutableLiveData = new MutableLiveData<>(); + this.myFollowerJsonMutableLiveData = new MutableLiveData<>(); } //----------------------------------------------------------------- @@ -47,5 +68,62 @@ public void acceptInviteRequest(){ myPageModelContainer.getInvitedConnectionModel().acceptInvite(); } + //----------------------------------------------------------------- + //ログイン中のユーザーのフォローリストを取得する + public void getMyFollows(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) { + myFollowJsonMutableLiveData.setValue(response.body()); + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + } + + //----------------------------------------------------------------- + //ユーザーのフォロワーリストを取得する + public void getMyFollowers(Integer uid){ + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + final FollowersRest followersRest = retrofit.create(FollowersRest.class); + + //フォロワーリストの取得 + Call call = followersRest.getFollowers(uid); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + if (response.body() != null) { + myFollowerJsonMutableLiveData.setValue(response.body()); + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + + } + } \ No newline at end of file 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..c936254 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); @@ -67,8 +71,8 @@ } //ログインしているユーザーがフォローしているかの有無で画面表示時のボタンの文字を変更する - userPageViewModel.getFollows(loginUid); - userPageViewModel.getFollowJson().observe(this, new Observer() { + userPageViewModel.getMyFollows(loginUid); + userPageViewModel.getMyFollowJson().observe(this, new Observer() { @Override public void onChanged(@Nullable FollowJson followJson) { followsUidList = followJson.getFollowUids(); @@ -98,6 +102,25 @@ } }); + //ユーザーのフォロー及びフォロワーの数を表示 + 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..a065b74 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 @@ -21,18 +21,24 @@ public class UserPageViewModel extends ViewModel { - private MutableLiveData followJsonMutableLiveData; + private MutableLiveData myFollowJsonMutableLiveData; + private MutableLiveData userFollowJsonMutableLiveData; private MutableLiveData followerJsonMutableLiveData; private MutableLiveData> animationJsonMutableLiveData; public UserPageViewModel(){ - this.followJsonMutableLiveData = new MutableLiveData<>(); + this.myFollowJsonMutableLiveData = new MutableLiveData<>(); + this.userFollowJsonMutableLiveData = new MutableLiveData<>(); this.followerJsonMutableLiveData = new MutableLiveData<>(); this.animationJsonMutableLiveData = new MutableLiveData<>(); } - public LiveData getFollowJson(){ - return this.followJsonMutableLiveData; + public LiveData getMyFollowJson(){ + return this.myFollowJsonMutableLiveData; + } + + public LiveData getUserFollowJson() { + return this.userFollowJsonMutableLiveData; } public LiveData getFollowerJson() { @@ -43,8 +49,8 @@ return animationJsonMutableLiveData; } - //ユーザーのフォローリストを取得する - public void getFollows(Integer uid){ + //ログイン中のユーザーのフォローリストを取得する + public void getMyFollows(Integer uid){ Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") .addConverterFactory(JacksonConverterFactory.create()) @@ -58,7 +64,35 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { if (response.body() != null) { - followJsonMutableLiveData.setValue(response.body()); + myFollowJsonMutableLiveData.setValue(response.body()); + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + + } + + //ユーザーのフォローリストを取得する(衝突回避用) + 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) { + userFollowJsonMutableLiveData.setValue(response.body()); } } } 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..6c13b23 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 @@ -5,7 +5,6 @@ import android.view.View; import android.widget.AdapterView; import android.widget.BaseAdapter; -import android.widget.Button; import android.widget.ListView; import org.ntlab.acanthus_client.R; @@ -28,25 +27,26 @@ 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); - userPageViewModel.getFollowJson().observe(this, new Observer() { + userPageViewModel.getMyFollows(uid); + userPageViewModel.getMyFollowJson().observe(this, new Observer() { @Override public void onChanged(FollowJson followJson) { ArrayList followUidList = followJson.getFollowUids(); 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..16a5997 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 @@ -7,6 +7,7 @@ import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ListView; +import android.widget.TextView; import org.ntlab.acanthus_client.R; import org.ntlab.acanthus_client.entities.AnimationJson; @@ -34,21 +35,24 @@ 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); + TextView workSize = findViewById(R.id.workSizeText); + +// 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(); @@ -66,6 +70,10 @@ } } + //作品の数を表示 + Integer size = animationJsonHashMap.size(); + workSize.setText("作品 " + size.toString()); + //ユーザー作品の昇順(作品を新しい順に並び変える) List> listEntries = new ArrayList<>(animationJsonHashMap.entrySet()); Collections.sort(listEntries, new Comparator>() { 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"> - - - - - - + + + + + -