| | package org.ntlab.acanthus_client.views.paint; |
---|
| | |
---|
| | import android.util.Log; |
---|
| | |
---|
| | import androidx.lifecycle.LiveData; |
---|
| | import androidx.lifecycle.MutableLiveData; |
---|
| | import androidx.lifecycle.ViewModel; |
---|
| | |
---|
| | import org.ntlab.acanthus_client.Acanthus; |
---|
| | import org.ntlab.acanthus_client.entities.Account; |
---|
| | import org.ntlab.acanthus_client.entities.AccountJson; |
---|
| | import org.ntlab.acanthus_client.entities.AidJson; |
---|
| | import org.ntlab.acanthus_client.entities.Animation; |
---|
| | import org.ntlab.acanthus_client.entities.AnimationJson; |
---|
| | import org.ntlab.acanthus_client.entities.EditorJson; |
---|
| | import org.ntlab.acanthus_client.entities.FollowerJson; |
---|
| | import org.ntlab.acanthus_client.entities.InvitesJson; |
---|
| | import org.ntlab.acanthus_client.resources.accounts.AccountsRest; |
---|
| | import org.ntlab.acanthus_client.resources.accounts.FollowersRest; |
---|
| | import org.ntlab.acanthus_client.resources.gallery.EditorsRest; |
---|
| | import org.ntlab.acanthus_client.resources.gallery.GalleryRest; |
---|
| | import org.ntlab.acanthus_client.resources.gallery.InvitesRest; |
---|
| | |
---|
| | import java.io.IOException; |
---|
| | import java.util.ArrayList; |
---|
| | import java.util.Collection; |
---|
| | import java.util.Collections; |
---|
| | |
---|
| | import retrofit2.Call; |
---|
| | import retrofit2.Callback; |
---|
| | import retrofit2.Response; |
---|
| | import retrofit2.Retrofit; |
---|
| | import retrofit2.converter.jackson.JacksonConverterFactory; |
---|
| | |
---|
| | public class InviteViewModel extends ViewModel { |
---|
| | |
---|
| | private MutableLiveData<FollowerJson> followersUidJsonMutableLiveData; |
---|
| | private MutableLiveData<Collection<AccountJson>> collectionAccountJsonMutableLiveData; |
---|
| | private MutableLiveData<InvitesJson> collectionInvitesJsonMutableLiveData; |
---|
| | private MutableLiveData<Boolean> messageMutableLiveData; |
---|
| | private MutableLiveData<EditorJson> editorJsonMutableLiveData; |
---|
| | |
---|
| | |
---|
| | public InviteViewModel() { |
---|
| | this.followersUidJsonMutableLiveData = new MutableLiveData<>(); |
---|
| | this.collectionAccountJsonMutableLiveData = new MutableLiveData<>(); |
---|
| | this.collectionInvitesJsonMutableLiveData = new MutableLiveData<>(); |
---|
| | this.messageMutableLiveData = new MutableLiveData<>(); |
---|
| | this.editorJsonMutableLiveData = new MutableLiveData<>(); |
---|
| | } |
---|
| | |
---|
| | public LiveData<FollowerJson> getFollowerUidJson() { |
---|
| | return this.followersUidJsonMutableLiveData; |
---|
| | } |
---|
| | |
---|
| | public LiveData<Collection<AccountJson>> getCollectionAccountJson() { |
---|
| | return this.collectionAccountJsonMutableLiveData; |
---|
| | } |
---|
| | |
---|
| | public LiveData<InvitesJson> getInvitesJson() { |
---|
| | return this.collectionInvitesJsonMutableLiveData; |
---|
| | } |
---|
| | |
---|
| | public LiveData<Boolean> getMessage() { |
---|
| | return this.messageMutableLiveData; |
---|
| | } |
---|
| | |
---|
| | public LiveData<EditorJson> getEditorJson() { |
---|
| | return this.editorJsonMutableLiveData; |
---|
| | } |
---|
| | |
---|
| | public void startFollowersUidJson(Integer uid, Integer aid, String ownerToken){ |
---|
| | 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) { |
---|
| | followersUidJsonMutableLiveData.setValue(response.body()); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onFailure(Call<FollowerJson> call, Throwable t) { |
---|
| | startGalleryInvites(aid, ownerToken); |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | |
---|
| | public void startGalleryInvites(Integer aid, String ownerToken){ |
---|
| | Retrofit retrofit = new Retrofit.Builder() |
---|
| | .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") |
---|
| | .addConverterFactory(JacksonConverterFactory.create()) |
---|
| | .build(); |
---|
| | final InvitesRest invitesRest = retrofit.create(InvitesRest.class); |
---|
| | Call<InvitesJson> call = invitesRest.isGalleryInvites(aid, null, null, ownerToken); |
---|
| | call.enqueue(new Callback<InvitesJson>() { |
---|
| | @Override |
---|
| | public void onResponse(Call<InvitesJson> call, Response<InvitesJson> response) { |
---|
| | if(response.isSuccessful()){ |
---|
| | if (response.body() != null) { |
---|
| | collectionInvitesJsonMutableLiveData.setValue(response.body()); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onFailure(Call<InvitesJson> call, Throwable t) { |
---|
| | startGalleryEditors(aid); |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | |
---|
| | public void startGalleryEditors(Integer aid){ |
---|
| | Retrofit retrofit = new Retrofit.Builder() |
---|
| | .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") |
---|
| | .addConverterFactory(JacksonConverterFactory.create()) |
---|
| | .build(); |
---|
| | final EditorsRest invitesRest = retrofit.create(EditorsRest.class); |
---|
| | Call<EditorJson> call = invitesRest.getEditors(aid); |
---|
| | call.enqueue(new Callback<EditorJson>() { |
---|
| | @Override |
---|
| | public void onResponse(Call<EditorJson> call, Response<EditorJson> response) { |
---|
| | if(response.isSuccessful()){ |
---|
| | if (response.body() != null) { |
---|
| | editorJsonMutableLiveData.setValue(response.body()); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onFailure(Call<EditorJson> call, Throwable t) { |
---|
| | editorJsonMutableLiveData.setValue(null); |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | |
---|
| | |
---|
| | public void addInvite(Integer aid, String ownerUid, String invitedUid, String ownerToken){ |
---|
| | Retrofit retrofit = new Retrofit.Builder() |
---|
| | .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") |
---|
| | .addConverterFactory(JacksonConverterFactory.create()) |
---|
| | .build(); |
---|
| | final InvitesRest invitesRest = retrofit.create(InvitesRest.class); |
---|
| | Call<Boolean> call = invitesRest.addInvite(aid, ownerUid, invitedUid, ownerToken); |
---|
| | call.enqueue(new Callback<Boolean>() { |
---|
| | @Override |
---|
| | public void onResponse(Call<Boolean> call, Response<Boolean> response) { |
---|
| | if(response.isSuccessful()){ |
---|
| | if (response.body() != null) { |
---|
| | messageMutableLiveData.setValue(response.body()); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onFailure(Call<Boolean> call, Throwable t) { |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |