diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/InvitedConnectionModel.java b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/InvitedConnectionModel.java index 521075b..20d1ad8 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/InvitedConnectionModel.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/InvitedConnectionModel.java @@ -6,7 +6,9 @@ import org.ntlab.acanthus_client.Acanthus; import org.ntlab.acanthus_client.R; +import org.ntlab.acanthus_client.entities.Work; import org.ntlab.acanthus_client.resources.accounts.InvitedRest; +import org.ntlab.acanthus_client.resources.accounts.WorkRest; import retrofit2.Call; import retrofit2.Callback; @@ -16,10 +18,9 @@ import retrofit2.converter.scalars.ScalarsConverterFactory; //----------------------------------------------------------------- -// +// 招待されているかの問い合わせAPI public class InvitedConnectionModel { - private final String TAG = "InvitedConnectionModel"; private Retrofit retrofit; private Acanthus acanthus; @@ -32,17 +33,15 @@ //----------------------------------------------------------------- // 招待確認 - public void checkInvited(MutableLiveData mText) { + public void checkInvited(MutableLiveData mIsInvitedText) { final InvitedRest invitedRest = retrofit.create(InvitedRest.class); Call call = invitedRest.checkAccountInvited(acanthus.getPreferenceUid(), acanthus.getAid()); call.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { - if (response.isSuccessful()){ - Log.d(TAG, response.body().toString()); - mText.setValue(response.body().toString()); - } + if (response.isSuccessful()) + mIsInvitedText.setValue(response.body().toString()); } @Override @@ -54,6 +53,26 @@ } //----------------------------------------------------------------- + // 招待承認 + public void acceptInvite() { + final WorkRest workRest = retrofit.create(WorkRest.class); + + // 作品への参加 + Call call = workRest.updateWork(acanthus.getPreferenceUid(), acanthus.getPreferenceToken(), acanthus.getAid()); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) ; + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + } + + //----------------------------------------------------------------- //----------------------------------------------------------------- // init private void init(Acanthus acanthus) { 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 c43fb32..2ac5e16 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 @@ -1,7 +1,5 @@ package org.ntlab.acanthus_client.views.main_menu_ui.mypage; -import android.app.Activity; -import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -30,10 +28,9 @@ // public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentMypageBinding.inflate(inflater, container, false); - View root = binding.getRoot(); - init(); + View root = binding.getRoot(); return root; } @@ -55,19 +52,39 @@ startObserve(); mypageViewModel.checkInvitedRequest(); + mypageViewModel.getAccountInfoRequest(); } //----------------------------------------------------------------- - // + // 変数の値の監視 private void startObserve() { - final TextView textView = binding.textMypage; - mypageViewModel.getImmutableText().observe(getViewLifecycleOwner(), new Observer() { + observeInvitedText(); + observeUidText(); + } + + //----------------------------------------------------------------- + // 招待されているテキストの変更監視 + private void observeInvitedText() { + final TextView textIsInvited = binding.textIsInvited; + mypageViewModel.getImmutableIsInvitedText().observe(getViewLifecycleOwner(), new Observer() { @Override public void onChanged(@Nullable String s) { - textView.setText(s); + textIsInvited.setText(s); + } + }); + } + + //----------------------------------------------------------------- + // Uidテキストの変更監視 + // memo: デバッグ用 + private void observeUidText() { + final TextView textUid = binding.textUidNo; + mypageViewModel.getImmutableUidText().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(String s) { + textUid.setText(s); } }); } //----------------------------------------------------------------- - } \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageInfoConnectionModel.java b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageInfoConnectionModel.java new file mode 100644 index 0000000..7471df3 --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageInfoConnectionModel.java @@ -0,0 +1,76 @@ +package org.ntlab.acanthus_client.views.main_menu_ui.mypage; + +import android.text.method.ReplacementTransformationMethod; + +import androidx.lifecycle.MutableLiveData; + +import org.ntlab.acanthus_client.Acanthus; +import org.ntlab.acanthus_client.databinding.ActivityAnimationBinding; +import org.ntlab.acanthus_client.entities.Account; +import org.ntlab.acanthus_client.resources.accounts.AccountsRest; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; +import retrofit2.converter.scalars.ScalarsConverterFactory; + +//----------------------------------------------------------------- +// マイページ情報の通信API (Follow, Followerの取得時に本格的に使うかも) +public class MyPageInfoConnectionModel { + + private Acanthus acanthus; + private Retrofit retrofit; + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + // + public MyPageInfoConnectionModel(Acanthus acanthus) { + init(acanthus); + } + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + // アカウント情報の取得API + public void getAccountByUid(MutableLiveData mUidText) { + final AccountsRest accountsRest = retrofit.create(AccountsRest.class); + mUidText.setValue(acanthus.getPreferenceUid().toString()); + + //Todo: なんもわからん +// String uid = acanthus.getPreferenceUid().toString(); +// String token = acanthus.getPreferenceToken(); +// +// Call call = accountsRest.getAccountByUid(uid, token); +// +// call.enqueue(new Callback() { +// @Override +// public void onResponse(Call call, Response response) { +// if (response.isSuccessful()) { +// Account resAccount = response.body(); +// mUidText.setValue(acanthus.getPreferenceUid().toString()); +// } +// } +// +// @Override +// public void onFailure(Call call, Throwable t) { +// +// } +// }); + } + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + // init + private void init(Acanthus acanthus) { + this.acanthus = acanthus; + this.retrofit = new Retrofit.Builder() + .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") + .addConverterFactory(ScalarsConverterFactory.create()) + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + } + //----------------------------------------------------------------- + + +} diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageModelContainer.java b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageModelContainer.java index 4265072..7a641b3 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageModelContainer.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/mypage/MyPageModelContainer.java @@ -6,22 +6,30 @@ // public class MyPageModelContainer { private InvitedConnectionModel invitedConnectionModel; + private MyPageInfoConnectionModel myPageInfoConnectionModel; //----------------------------------------------------------------- //----------------------------------------------------------------- - public MyPageModelContainer(Acanthus acanthus){ + public MyPageModelContainer(Acanthus acanthus) { init(acanthus); } + //----------------------------------------------------------------- // getter public InvitedConnectionModel getInvitedConnectionModel() { return invitedConnectionModel; } + + public MyPageInfoConnectionModel getMyPageInfoConnectionModel() { + return myPageInfoConnectionModel; + } + //----------------------------------------------------------------- //----------------------------------------------------------------- // init private void init(Acanthus acanthus) { invitedConnectionModel = new InvitedConnectionModel(acanthus); + myPageInfoConnectionModel = new MyPageInfoConnectionModel(acanthus); } //----------------------------------------------------------------- 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 dad604a..d71590b 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 @@ -1,30 +1,27 @@ package org.ntlab.acanthus_client.views.main_menu_ui.mypage; -import android.telephony.mbms.MbmsErrors; - import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import org.ntlab.acanthus_client.Acanthus; -import org.ntlab.acanthus_client.resources.accounts.InvitedRest; - -import retrofit2.Call; -import retrofit2.Retrofit; -import retrofit2.converter.jackson.JacksonConverterFactory; -import retrofit2.converter.scalars.ScalarsConverterFactory; //----------------------------------------------------------------- -// +// マイページロジックの仲介者 public class MyPageViewModel extends ViewModel { private MyPageModelContainer myPageModelContainer; - private MutableLiveData mText = new MutableLiveData<>(); + private MutableLiveData mIsInvitedText = new MutableLiveData<>(); + private MutableLiveData mUidText = new MutableLiveData<>(); //----------------------------------------------------------------- // getter - public LiveData getImmutableText() { - return mText; + public LiveData getImmutableIsInvitedText() { + return mIsInvitedText; + } + + public LiveData getImmutableUidText() { + return mUidText; } //----------------------------------------------------------------- @@ -32,14 +29,18 @@ // init public void init(Acanthus acanthus) { myPageModelContainer = new MyPageModelContainer(acanthus); - myPageModelContainer.getInvitedConnectionModel().checkInvited(mText); } //----------------------------------------------------------------- - // + // 招待されているかを確認する通信リクエスト public void checkInvitedRequest() { - myPageModelContainer.getInvitedConnectionModel().checkInvited(mText); + myPageModelContainer.getInvitedConnectionModel().checkInvited(mIsInvitedText); + } + + //----------------------------------------------------------------- + // アカウント情報を取得するリクエスト + public void getAccountInfoRequest() { + myPageModelContainer.getMyPageInfoConnectionModel().getAccountByUid(mUidText); } //----------------------------------------------------------------- - } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_mypage.xml b/app/src/main/res/layout/fragment_mypage.xml index a0d44e7..c5246db 100644 --- a/app/src/main/res/layout/fragment_mypage.xml +++ b/app/src/main/res/layout/fragment_mypage.xml @@ -7,10 +7,10 @@ tools:context=".views.main_menu_ui.mypage.MyPageFragment"> + + + + + + + \ No newline at end of file