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 5531868..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 @@ -37,7 +37,6 @@ public class MyPageFragment extends Fragment { private MyPageViewModel mypageViewModel; - private UserPageViewModel userPageViewModel; private FragmentMypageBinding binding; //----------------------------------------------------------------- @@ -183,7 +182,6 @@ 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()); @@ -230,8 +228,8 @@ public void observeFollowsSize(Integer loginUid) { TextView followsSize = binding.followsSizeText; - userPageViewModel.getFollows(loginUid); - userPageViewModel.getFollowJson().observe(getViewLifecycleOwner(), new Observer() { + mypageViewModel.getMyFollows(loginUid); + mypageViewModel.getMyFollowJson().observe(getViewLifecycleOwner(), new Observer() { @Override public void onChanged(FollowJson followJson) { Integer size = followJson.getFollowUids().size(); @@ -245,8 +243,8 @@ public void observeFollowersSize(Integer loginUid) { TextView followersSize = binding.followersSizeText; - userPageViewModel.getFollowers(loginUid); - userPageViewModel.getFollowerJson().observe(getViewLifecycleOwner(), new Observer() { + mypageViewModel.getMyFollowers(loginUid); + mypageViewModel.getMyFollowerJson().observe(getViewLifecycleOwner(), new Observer() { @Override public void onChanged(FollowerJson followerJson) { Integer size = followerJson.getFollowerUids().size(); 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 f667570..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 @@ -71,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(); @@ -102,7 +102,7 @@ } }); - //フォロー及びフォロワーの数を表示 + //ユーザーのフォロー及びフォロワーの数を表示 userPageViewModel.getUserFollows(uid); userPageViewModel.getUserFollowJson().observe(this, new Observer() { @Override @@ -111,6 +111,7 @@ followsSize.setText(size.toString()); } }); + userPageViewModel.getFollowers(uid); userPageViewModel.getFollowerJson().observe(this, new Observer() { @Override 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 eb378c6..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,24 +21,24 @@ public class UserPageViewModel extends ViewModel { - private MutableLiveData followJsonMutableLiveData; - private MutableLiveData followJsonMutableLiveData2; + private MutableLiveData myFollowJsonMutableLiveData; + private MutableLiveData userFollowJsonMutableLiveData; private MutableLiveData followerJsonMutableLiveData; private MutableLiveData> animationJsonMutableLiveData; public UserPageViewModel(){ - this.followJsonMutableLiveData = new MutableLiveData<>(); - this.followJsonMutableLiveData2 = 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.followJsonMutableLiveData2; + return this.userFollowJsonMutableLiveData; } public LiveData getFollowerJson() { @@ -49,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()) @@ -64,7 +64,7 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { if (response.body() != null) { - followJsonMutableLiveData.setValue(response.body()); + myFollowJsonMutableLiveData.setValue(response.body()); } } } @@ -92,7 +92,7 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { if (response.body() != null) { - followJsonMutableLiveData2.setValue(response.body()); + 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 174d872..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; @@ -46,8 +45,8 @@ // }); //フォロー一覧の取得と表示 - 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/workList/WorkListActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListActivity.java index 8f5057c..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; @@ -41,6 +42,8 @@ Integer uid = intent.getIntExtra("UID", 0); ListView listView = findViewById(R.id.workListView); + TextView workSize = findViewById(R.id.workSizeText); + // Button returnButton = findViewById(R.id.returnWorkButton); //前の画面に戻る処理 @@ -67,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_work_list.xml b/app/src/main/res/layout/activity_work_list.xml index 6786e5e..215ee31 100644 --- a/app/src/main/res/layout/activity_work_list.xml +++ b/app/src/main/res/layout/activity_work_list.xml @@ -15,4 +15,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.86" /> + + \ No newline at end of file