Merge pull request #228 from nitta-lab-2021/UserPageEdit
かくにん!
commit 8d063033ae583975bce99d5bb024f8ebb2a9375d
2 parents 77f939b + 60eebf0
赤木元基 authored on 29 Oct 2021
Showing 5 changed files
View
12
app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserListViewAdapter.java
private ArrayList<String> nameList = new ArrayList<>();
 
//参照保存データ
static class ViewHolder {
TextView textViewUid;
TextView textViewName;
}
 
public UserListViewAdapter(Context context, int layoutId, ArrayList<String> name) {
public UserListViewAdapter(Context context, int layoutId, ArrayList<String> names) {
super();
this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.layoutId = layoutId;
this.nameList = name;
this.nameList = names;
}
 
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//fragment_edit.xmlにlistView用のレイアウトを入れ込む
convertView = inflater.inflate(layoutId, parent, false);
//ViewHolderの生成とレイアウト内テキストのセット
viewHolder = new UserListViewAdapter.ViewHolder();
viewHolder.textViewUid = convertView.findViewById(R.id.followOrFollowerUid);
viewHolder.textViewName = convertView.findViewById(R.id.followOrFollowerName);
convertView.setTag(viewHolder);
} else {
//既に初期セットの処理がされている場合、再利用する
viewHolder = (UserListViewAdapter.ViewHolder) convertView.getTag();
}
 
//ViewHolder内のtextViewName,Dateに各ポジションのデータをセット
if (nameList != null) viewHolder.textViewUid.setText(nameList.get(position));
//ViewHolder内のtextViewNameに各ポジションのデータをセット
if (nameList != null) viewHolder.textViewName.setText(nameList.get(position));
 
return convertView;
}
 
View
40
app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserPageActivity.java
setContentView(R.layout.activity_userpage);
 
userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class);
acanthus = (Acanthus) getApplication();
Integer uid = 1;
// Integer uid = acanthus.getPreferenceUid();
String token = "abc0";
// String token = acanthus.getPreferenceToken();
// Intent intent = getIntent(); //FollowListActivity,FollowerListActivityからそれぞれuidをもらう
// Integer uid2 = intent.getIntExtra("UID", 0);
Integer uid2 = 2;
Integer loginUid = 1;
// Integer loginUid = acanthus.getPreferenceUid();
String loginToken = "abc0";
// String loginToken = acanthus.getPreferenceToken();
Intent intent = getIntent(); //FollowListActivity,FollowerListActivityからそれぞれuidをもらう
// Integer uid = intent.getIntExtra("UID", 0);
Integer uid = 2;
String uname = intent.getStringExtra("NAME");
 
TextView userNameText = findViewById(R.id.userNameText);
// userNameText.setText();
userNameText.setText(uname);
 
TextView profileText = findViewById(R.id.profileText);
 
Button returnButton = findViewById(R.id.returnButton);
 
Button followUserButton = findViewById(R.id.followUserButton);
 
//閲覧しているユーザーページが自分のページならフォローボタンを非表示する
if (uid == uid2) {
if (loginUid == uid) {
followUserButton.setVisibility(View.INVISIBLE);
}
 
//ログインしているユーザーがフォローしているかの有無で画面表示時のボタンの文字を変更する
userPageViewModel.getFollows(uid);
userPageViewModel.getFollows(loginUid);
userPageViewModel.getFollowJson().observe(this, new Observer<FollowJson>() {
@Override
public void onChanged(@Nullable FollowJson followJson) {
followsUidList = followJson.getFollowUids();
 
if (followsUidList.contains(uid2)) {
if (followsUidList.contains(uid)) {
followUserButton.setText("フォロー解除");
}else{
followUserButton.setText("フォローする");
}
//ユーザーのフォロー及びフォロー解除の処理
followUserButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!followsUidList.contains(uid2)) {
userPageViewModel.addFollow(uid, token, uid2);
followsUidList.add(uid2);
if (!followsUidList.contains(uid)) {
userPageViewModel.addFollow(loginUid, loginToken, uid);
followsUidList.add(uid);
followUserButton.setText("フォロー解除");
}else{
userPageViewModel.releaseFollow(uid, token, uid2);
followsUidList.remove(uid2);
userPageViewModel.releaseFollow(loginUid, loginToken, uid);
followsUidList.remove(uid);
followUserButton.setText("フォローする");
}
}
});
followListButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplication(), FollowListActivity.class);
intent.putExtra("UID", uid2);
intent.putExtra("UID", uid);
startActivity(intent);
}
});
 
followerListButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplication(), FollowerListActivity.class);
intent.putExtra("UID", uid2);
intent.putExtra("UID", uid);
startActivity(intent);
}
});
 
workListButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplication(), WorkListActivity.class);
intent.putExtra("UID", uid2);
intent.putExtra("UID", uid);
startActivity(intent);
}
});
 
View
1
■■■■
app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListActivity.java
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getApplication(), UserPageActivity.class);
intent.putExtra("UID", followUidList.get(position));
intent.putExtra("NAME", followNameList.get(position));
startActivity(intent);
}
});
}
View
1
■■■■
app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListActivity.java
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getApplication(), UserPageActivity.class);
intent.putExtra("UID", followerUidList.get(position));
intent.putExtra("NAME", followerNameList.get(position));
startActivity(intent);
}
});
}
View
2
■■■
app/src/main/res/layout/follow_or_follower_list.xml
android:layout_height="match_parent"
android:orientation="vertical" >
 
<TextView
android:id="@+id/followOrFollowerUid"
android:id="@+id/followOrFollowerName"
android:layout_width="match_parent"
android:layout_height="43dp"
android:text="uid"
android:textSize="16sp" />