diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserListViewAdapter.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserListViewAdapter.java new file mode 100644 index 0000000..0f50618 --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserListViewAdapter.java @@ -0,0 +1,73 @@ +package org.ntlab.acanthus_client.views.userpage; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import org.ntlab.acanthus_client.R; + +import java.util.ArrayList; + +public class UserListViewAdapter extends BaseAdapter { + + private final LayoutInflater inflater; + private int layoutId; + private ArrayList nameList = new ArrayList<>(); + + //参照保存データ + static class ViewHolder { + TextView textViewUid; + } + + public UserListViewAdapter(Context context, int layoutId, ArrayList name) { + super(); + this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + this.layoutId = layoutId; + this.nameList = name; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + //Viewのinflate(拡張) + if (convertView == null) { + //fragment_edit.xmlにlistView用のレイアウトを入れ込む + convertView = inflater.inflate(layoutId, parent, false); + //ViewHolderの生成とレイアウト内テキストのセット + viewHolder = new UserListViewAdapter.ViewHolder(); + viewHolder.textViewUid = convertView.findViewById(R.id.followOrFollowerUid); + convertView.setTag(viewHolder); + } else { + //既に初期セットの処理がされている場合、再利用する + viewHolder = (UserListViewAdapter.ViewHolder) convertView.getTag(); + } + + //ViewHolder内のtextViewName,Dateに各ポジションのデータをセット + if (nameList != null) viewHolder.textViewUid.setText(nameList.get(position)); + + return convertView; + } + + public void setNameList(ArrayList nameList) { + this.nameList = nameList; + } + + @Override + public int getCount() { + return nameList.size(); + } + + @Override + public Object getItem(int position) { + return null; + } + + @Override + public long getItemId(int position) { + return 0; + } + +} 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 70fcf3b..d25add8 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 @@ -9,7 +9,7 @@ import org.jetbrains.annotations.Nullable; import org.ntlab.acanthus_client.Acanthus; import org.ntlab.acanthus_client.R; -import org.ntlab.acanthus_client.entities.FollowUidJson; +import org.ntlab.acanthus_client.entities.FollowJson; import org.ntlab.acanthus_client.views.userpage.followList.FollowListActivity; import org.ntlab.acanthus_client.views.userpage.followerList.FollowerListActivity; import org.ntlab.acanthus_client.views.userpage.workList.WorkListActivity; @@ -39,6 +39,8 @@ // 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; TextView userNameText = findViewById(R.id.userNameText); @@ -65,10 +67,10 @@ //ログインしているユーザーがフォローしているかの有無で画面表示時のボタンの文字を変更する userPageViewModel.getFollows(uid); - userPageViewModel.getFollowUidJson().observe(this, new Observer() { + userPageViewModel.getFollowJson().observe(this, new Observer() { @Override - public void onChanged(@Nullable FollowUidJson followUidJson) { - followsList = followUidJson.getFollowsUid(); + public void onChanged(@Nullable FollowJson followJson) { + followsList = followJson.getFollows().keySet(); if (followsList.contains(uid2)) { followUserButton.setText("フォロー解除"); 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 c3264b3..6f787a6 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,12 +1,14 @@ package org.ntlab.acanthus_client.views.userpage; -import android.util.Log; - +import org.ntlab.acanthus_client.entities.AnimationJson; import org.ntlab.acanthus_client.entities.FollowAddJson; -import org.ntlab.acanthus_client.entities.FollowUidJson; -import org.ntlab.acanthus_client.entities.FollowerUidJson; +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; +import org.ntlab.acanthus_client.resources.gallery.GalleryRest; + +import java.util.Collection; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; @@ -19,20 +21,26 @@ public class UserPageViewModel extends ViewModel { - private MutableLiveData followUidJsonMutableLiveData; - private MutableLiveData followerUidJsonMutableLiveData; + private MutableLiveData followJsonMutableLiveData; + private MutableLiveData followerJsonMutableLiveData; + private MutableLiveData> animationJsonMutableLiveData; public UserPageViewModel(){ - this.followUidJsonMutableLiveData = new MutableLiveData<>(); - this.followerUidJsonMutableLiveData = new MutableLiveData<>(); + this.followJsonMutableLiveData = new MutableLiveData<>(); + this.followerJsonMutableLiveData = new MutableLiveData<>(); + this.animationJsonMutableLiveData = new MutableLiveData<>(); } - public LiveData getFollowUidJson(){ - return this.followUidJsonMutableLiveData; + public LiveData getFollowJson(){ + return this.followJsonMutableLiveData; } - public LiveData getFollowerUidJson() { - return this.followerUidJsonMutableLiveData; + public LiveData getFollowerJson() { + return this.followerJsonMutableLiveData; + } + + public LiveData> getAnimationJson() { + return animationJsonMutableLiveData; } //ユーザーのフォローリストを取得する @@ -44,19 +52,19 @@ final FollowsRest followsRest = retrofit.create(FollowsRest.class); //フォローリストの取得 - Call call = followsRest.getFollows(uid); - call.enqueue(new Callback() { + Call call = followsRest.getFollows(uid); + call.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { if (response.isSuccessful()) { if (response.body() != null) { - followUidJsonMutableLiveData.setValue(response.body()); + followJsonMutableLiveData.setValue(response.body()); } } } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); @@ -124,19 +132,47 @@ final FollowersRest followersRest = retrofit.create(FollowersRest.class); //フォロワーリストの取得 - Call call = followersRest.getFollowers(uid); - call.enqueue(new Callback() { + Call call = followersRest.getFollowers(uid); + call.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { if (response.isSuccessful()) { if (response.body() != null) { - followerUidJsonMutableLiveData.setValue(response.body()); + followerJsonMutableLiveData.setValue(response.body()); } } } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { + + } + }); + + } + + //全ユーザーの作品一覧の取得 + public void getGallery(){ + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + final GalleryRest galleryRest = retrofit.create(GalleryRest.class); + + //全ユーザーの作品の取得 + Call> call = galleryRest.getGallery(null); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + if (response.isSuccessful()){ + if (response.body() != null){ + animationJsonMutableLiveData.setValue(response.body()); + } + } + } + + @Override + public void onFailure(Call> call, Throwable t) { } }); diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListActivity.java index 8d3568e..358a85b 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListActivity.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListActivity.java @@ -3,12 +3,21 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; +import android.widget.AdapterView; +import android.widget.BaseAdapter; import android.widget.Button; +import android.widget.ListView; import org.ntlab.acanthus_client.R; +import org.ntlab.acanthus_client.entities.FollowJson; +import org.ntlab.acanthus_client.views.userpage.UserListViewAdapter; +import org.ntlab.acanthus_client.views.userpage.UserPageActivity; import org.ntlab.acanthus_client.views.userpage.UserPageViewModel; +import java.util.ArrayList; + import androidx.appcompat.app.AppCompatActivity; +import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; public class FollowListActivity extends AppCompatActivity { @@ -23,6 +32,7 @@ userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); Intent intent = getIntent(); //UserPageActivityからuidをもらう Integer uid = intent.getIntExtra("UID", 0); + ListView listView = findViewById(R.id.followListView); Button returnButton = findViewById(R.id.returnFollowButton); @@ -34,7 +44,27 @@ } }); + //フォロー一覧の取得と表示 + userPageViewModel.getFollows(uid); + userPageViewModel.getFollowJson().observe(this, new Observer() { + @Override + public void onChanged(FollowJson followJson) { + ArrayList followUidList = (ArrayList) followJson.getFollows().keySet(); + ArrayList followNameList = (ArrayList) followJson.getFollows().values(); + BaseAdapter adapter = new UserListViewAdapter(getApplication(), R.layout.follow_or_follower_list, followNameList); + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + //フォローのユーザーページへの遷移 + @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)); + startActivity(intent); + } + }); + } + }); } diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListActivity.java index caffbad..9bf7595 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListActivity.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListActivity.java @@ -3,12 +3,22 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; +import android.widget.AdapterView; +import android.widget.BaseAdapter; import android.widget.Button; +import android.widget.ListView; +import org.jetbrains.annotations.Nullable; import org.ntlab.acanthus_client.R; +import org.ntlab.acanthus_client.entities.FollowerJson; +import org.ntlab.acanthus_client.views.userpage.UserListViewAdapter; +import org.ntlab.acanthus_client.views.userpage.UserPageActivity; import org.ntlab.acanthus_client.views.userpage.UserPageViewModel; +import java.util.ArrayList; + import androidx.appcompat.app.AppCompatActivity; +import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; @@ -24,6 +34,7 @@ userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); Intent intent = getIntent(); //UserPageActivityからuidをもらう Integer uid = intent.getIntExtra("UID", 0); + ListView listView = findViewById(R.id.followerListView); Button returnButton = findViewById(R.id.returnFollowerButton); @@ -35,7 +46,27 @@ } }); + //フォロワー一覧の取得と表示 + userPageViewModel.getFollowers(uid); + userPageViewModel.getFollowerJson().observe(this, new Observer() { + @Override + public void onChanged(@Nullable FollowerJson followerJson) { + ArrayList followerUidList = (ArrayList) followerJson.getFollowers().keySet(); + ArrayList followerNameList = (ArrayList) followerJson.getFollowers().values(); + BaseAdapter adapter = new UserListViewAdapter(getApplication(), R.layout.follow_or_follower_list, followerNameList); + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + //フォロワーのユーザーページへの遷移 + @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)); + startActivity(intent); + } + }); + } + }); } diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListActivity.java index 9656aa4..59a7182 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListActivity.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/workList/WorkListActivity.java @@ -3,12 +3,28 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; +import android.widget.AdapterView; +import android.widget.BaseAdapter; import android.widget.Button; +import android.widget.ListView; import org.ntlab.acanthus_client.R; +import org.ntlab.acanthus_client.entities.AnimationJson; +import org.ntlab.acanthus_client.views.animation.AnimationActivity; +import org.ntlab.acanthus_client.views.main_menu_ui.edit.WorkListViewAdapter; import org.ntlab.acanthus_client.views.userpage.UserPageViewModel; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import androidx.appcompat.app.AppCompatActivity; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; public class WorkListActivity extends AppCompatActivity { @@ -19,8 +35,10 @@ super.onCreate(savedInstanceState); setContentView(R.layout.activity_work_list); + userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); Intent intent = getIntent(); //UserPageActivityからuidをもらう Integer uid = intent.getIntExtra("UID", 0); + ListView listView = findViewById(R.id.workListView); Button returnButton = findViewById(R.id.returnWorkButton); @@ -32,7 +50,51 @@ } }); + //全ユーザーの作品から特定のユーザーの作品を抽出し、一覧として表示する + userPageViewModel.getGallery(); + userPageViewModel.getAnimationJson().observe(this, new Observer>() { + @Override + public void onChanged(Collection animationJsons) { + HashMap animationJsonHashMap = new HashMap<>(); + ArrayList animationJsonList = new ArrayList<>(); + ArrayList animationNameList = new ArrayList<>(); + ArrayList animationLastUpdateList = new ArrayList<>(); + for (AnimationJson animationJson : animationJsons){ + if (animationJson.getEditorIds().contains(uid)){ + animationJsonHashMap.put(animationJson.getLastUpdate(), animationJson); + } + } + + //ユーザー作品の昇順(作品を新しい順に並び変える) + List> listEntries = new ArrayList<>(animationJsonHashMap.entrySet()); + Collections.sort(listEntries, new Comparator>() { + @Override + public int compare(Map.Entry o1, Map.Entry o2) { + return o1.getKey().compareTo(o2.getKey()); + } + }); + for (Map.Entry entry : listEntries){ + animationLastUpdateList.add(entry.getKey()); + animationJsonList.add(entry.getValue()); + animationNameList.add(entry.getValue().getAnimationName()); + } + + + BaseAdapter adapter = new WorkListViewAdapter(getApplication(), R.layout.work_list, animationNameList, animationLastUpdateList); + + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + //ユーザーの作品への遷移 + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Intent intent = new Intent(getApplication(), AnimationActivity.class); + intent.putExtra("AnimationJsonData", animationJsonList.get(position)); + startActivity(intent); + } + }); + } + }); } diff --git a/app/src/main/res/layout/activity_follow_list.xml b/app/src/main/res/layout/activity_follow_list.xml index 3dd42ce..e269aec 100644 --- a/app/src/main/res/layout/activity_follow_list.xml +++ b/app/src/main/res/layout/activity_follow_list.xml @@ -16,4 +16,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.023" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_follower_list.xml b/app/src/main/res/layout/activity_follower_list.xml index 24350a6..de04485 100644 --- a/app/src/main/res/layout/activity_follower_list.xml +++ b/app/src/main/res/layout/activity_follower_list.xml @@ -12,8 +12,19 @@ android:text="<" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.114" + app:layout_constraintHorizontal_bias="0.049" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintVertical_bias="0.087" /> + app:layout_constraintVertical_bias="0.023" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_work_list.xml b/app/src/main/res/layout/activity_work_list.xml index ae053ea..3b963e7 100644 --- a/app/src/main/res/layout/activity_work_list.xml +++ b/app/src/main/res/layout/activity_work_list.xml @@ -12,8 +12,19 @@ android:text="<" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.154" + app:layout_constraintHorizontal_bias="0.049" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintVertical_bias="0.079" /> + app:layout_constraintVertical_bias="0.042" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/follow_or_follower_list.xml b/app/src/main/res/layout/follow_or_follower_list.xml new file mode 100644 index 0000000..878d951 --- /dev/null +++ b/app/src/main/res/layout/follow_or_follower_list.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file