| |
---|
| | |
---|
| | 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; |
---|
| | |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | // マイページロジックの仲介者 |
---|
| | public class MyPageViewModel extends ViewModel { |
---|
| | private MyPageModelContainer myPageModelContainer; |
---|
| | private MutableLiveData<Boolean> mIsInvited = new MutableLiveData<>(); |
---|
| | private MutableLiveData<String> mUidText = new MutableLiveData<>(); |
---|
| | private MutableLiveData<FollowJson> myFollowJsonMutableLiveData; |
---|
| | private MutableLiveData<FollowerJson> myFollowerJsonMutableLiveData; |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | // getter |
---|
| | public LiveData<Boolean> getImmutableIsInvited() { |
---|
| |
---|
| | public LiveData<String> getImmutableUidText() { |
---|
| | return mUidText; |
---|
| | } |
---|
| | |
---|
| | public LiveData<FollowJson> getMyFollowJson() { |
---|
| | return myFollowJsonMutableLiveData; |
---|
| | } |
---|
| | |
---|
| | public LiveData<FollowerJson> getMyFollowerJson() { |
---|
| | return myFollowerJsonMutableLiveData; |
---|
| | } |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | //----------------------------------------------------------------- |
---|
| | // init |
---|
| | public void init(Acanthus acanthus) { |
---|
| | myPageModelContainer = new MyPageModelContainer(acanthus); |
---|
| | this.myFollowJsonMutableLiveData = new MutableLiveData<>(); |
---|
| | this.myFollowerJsonMutableLiveData = new MutableLiveData<>(); |
---|
| | } |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | // 招待されているかを確認する通信リクエスト |
---|
| |
---|
| | // 招待を承諾するリクエスト |
---|
| | 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<FollowJson> call = followsRest.getFollows(uid); |
---|
| | call.enqueue(new Callback<FollowJson>() { |
---|
| | @Override |
---|
| | public void onResponse(Call<FollowJson> call, Response<FollowJson> response) { |
---|
| | if (response.isSuccessful()) { |
---|
| | if (response.body() != null) { |
---|
| | myFollowJsonMutableLiveData.setValue(response.body()); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onFailure(Call<FollowJson> 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<FollowerJson> call = followersRest.getFollowers(uid); |
---|
| | call.enqueue(new Callback<FollowerJson>() { |
---|
| | @Override |
---|
| | public void onResponse(Call<FollowerJson> call, Response<FollowerJson> response) { |
---|
| | if (response.isSuccessful()) { |
---|
| | if (response.body() != null) { |
---|
| | myFollowerJsonMutableLiveData.setValue(response.body()); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onFailure(Call<FollowerJson> call, Throwable t) { |
---|
| | |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |