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 4ce2f5c..f805a0a 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 @@ -1,17 +1,22 @@ package org.ntlab.acanthus_client.views.userpage; import android.os.Bundle; +import android.view.View; import android.widget.Button; import android.widget.TextView; +import org.ntlab.acanthus_client.Acanthus; import org.ntlab.acanthus_client.R; import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.ViewModelProvider; public class UserPageActivity extends AppCompatActivity { private UserPageViewModel userPageViewModel; + private Acanthus acanthus; @Override protected void onCreate(Bundle savedInstanceState){ @@ -19,15 +24,80 @@ setContentView(R.layout.activity_userpage); userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); + acanthus = (Acanthus) getApplication(); - TextView userName = findViewById(R.id.userNameText); + TextView userNameText = findViewById(R.id.userNameText); +// userNameText.setText(); + TextView profileText = findViewById(R.id.profileText); Button returnButton = findViewById(R.id.returnButton); + + //前の画面に戻る処理 + returnButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + finish(); + } + }); + Button followUserButton = findViewById(R.id.followUserButton); - Button followButton = findViewById(R.id.followButton); - Button followerButton = findViewById(R.id.followerButton); - Button animationListButton = findViewById(R.id.animationListButton); + //ログインしているユーザーがフォローしているかの有無で画面表示時のボタンの文字を変更する +// if () { +// followUserButton.setText("フォロー解除"); +// }else{ +// followUserButton.setText("フォローする"); +// } + + //ユーザーのフォロー及びフォロー解除の処理 + followUserButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { +// if () { +// //userPageViewModel.addFollow(); +// followUserButton.setText("フォロー解除"); +// }else{ +// //userPageViewModel.releaseFollow(); +// followUserButton.setText("フォローする"); +// } + } + }); + + //ユーザーのフォロー一覧への画面遷移の処理 + Button followListButton = findViewById(R.id.followListButton); + followListButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); +// fragmentTransaction.replace(R.id.container, new ); + fragmentTransaction.commit(); + } + }); + + //ユーザーのフォロワー一覧への画面遷移の処理 + Button followerListButton = findViewById(R.id.followerListButton); + followerListButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); +// fragmentTransaction.replace(R.id.container, new ); + fragmentTransaction.commit(); + } + }); + + //ユーザーの作品一覧への画面遷移の処理 + Button workListButton = findViewById(R.id.workListButton); + workListButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); +// fragmentTransaction.replace(R.id.container, new ); + fragmentTransaction.commit(); + } + }); } 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 081b9a9..d5f9261 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 @@ -1,9 +1,113 @@ package org.ntlab.acanthus_client.views.userpage; +import org.ntlab.acanthus_client.entities.FollowAddJson; +import org.ntlab.acanthus_client.entities.FollowUidJson; +import org.ntlab.acanthus_client.resources.accounts.FollowsRest; + +import java.util.ArrayList; +import java.util.Collection; + import androidx.lifecycle.ViewModel; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; public class UserPageViewModel extends ViewModel { + private Collection followUidList; + public UserPageViewModel(){ + this.followUidList = new ArrayList<>(); + } + + public Collection getFollowUidList(){ + return this.followUidList; + } + + //ユーザーのフォローリストを取得する + public void getFollows(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) { + followUidList = response.body().getUidList(); + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + + } + + //ユーザーをフォローする + public void addFollow(Integer uid, String token, Integer followUid){ + 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.addFollows(uid, token, followUid); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + if (response.body() != null) { + + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + + } + + //ユーザーのフォローを解除 + public void releaseFollow(Integer uid, String token, Integer followUid){ + 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.releaseFollows(uid, token, followUid); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + if (response.body() != null) { + + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + + } } diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListFragment.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListFragment.java new file mode 100644 index 0000000..94e725e --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListFragment.java @@ -0,0 +1,7 @@ +package org.ntlab.acanthus_client.views.userpage.followList; + +public class FollowListFragment { + + + +} diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListFragment.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListFragment.java new file mode 100644 index 0000000..15536c1 --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListFragment.java @@ -0,0 +1,7 @@ +package org.ntlab.acanthus_client.views.userpage.followerList; + +public class FollowerListFragment { + + + +} diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListFragment.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListFragment.java new file mode 100644 index 0000000..dc4899c --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListFragment.java @@ -0,0 +1,7 @@ +package org.ntlab.acanthus_client.views.userpage.workList; + +public class WorkListFragment { + + + +} diff --git a/app/src/main/res/layout/activity_userpage.xml b/app/src/main/res/layout/activity_userpage.xml index 18370e7..83220a8 100644 --- a/app/src/main/res/layout/activity_userpage.xml +++ b/app/src/main/res/layout/activity_userpage.xml @@ -32,7 +32,7 @@ app:layout_constraintVertical_bias="0.029" />