diff --git a/.idea/misc.xml b/.idea/misc.xml index 10b388f..867daff 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -19,6 +19,7 @@ + @@ -32,8 +33,12 @@ + + + + diff --git a/app/build.gradle b/app/build.gradle index dd92557..df4b76a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,6 +43,7 @@ implementation 'androidx.annotation:annotation:1.2.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' @@ -51,4 +52,7 @@ implementation 'com.squareup.retrofit2:converter-scalars:2.1.0' implementation 'com.github.bumptech.glide:glide:4.10.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0' + implementation 'com.google.android.material:material:1.1.0-alpha08' + implementation 'androidx.viewpager2:viewpager2:1.0.0-beta02' + } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 993f4ef..5bfc0fe 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,6 +17,9 @@ android:supportsRtl="true" android:theme="@style/Theme.Acanthus" android:usesCleartextTraffic="true"> + @@ -28,6 +31,7 @@ + @@ -36,15 +40,13 @@ - - - - + + + android:windowSoftInputMode="adjustPan" /> \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/animation_detail/AnimationDetailActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/animation_detail/AnimationDetailActivity.java index 7ebf505..db03a5e 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/animation_detail/AnimationDetailActivity.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/animation_detail/AnimationDetailActivity.java @@ -3,31 +3,20 @@ import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.os.Bundle; import android.view.View; -import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import org.ntlab.acanthus_client.Acanthus; import org.ntlab.acanthus_client.R; import org.ntlab.acanthus_client.entities.Animation; import org.ntlab.acanthus_client.entities.AnimationJson; -import org.ntlab.acanthus_client.views.animation.AnimationActivity; import org.ntlab.acanthus_client.views.animation.AnimationCanvas; import org.ntlab.acanthus_client.views.userpage.UserPageActivity; -import org.ntlab.acanthus_client.views.userpage.followerList.FollowerListActivity; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; import java.util.ArrayList; -import java.util.Collection; public class AnimationDetailActivity extends AppCompatActivity { 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 27380e1..b9244e5 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 @@ -13,8 +13,6 @@ import org.ntlab.acanthus_client.Acanthus; import org.ntlab.acanthus_client.R; import org.ntlab.acanthus_client.databinding.FragmentMypageBinding; -import org.ntlab.acanthus_client.entities.FollowJson; -import org.ntlab.acanthus_client.entities.FollowerJson; import org.ntlab.acanthus_client.views.animation.AnimationActivity; import org.ntlab.acanthus_client.views.main_menu_ui.mypage.help.HowToUseActivity; import org.ntlab.acanthus_client.views.main_menu_ui.mypage.help.InquiryActivity; @@ -22,9 +20,7 @@ import org.ntlab.acanthus_client.views.main_menu_ui.mypage.logout.LogoutActivity; import org.ntlab.acanthus_client.views.main_menu_ui.mypage.others.PrivacyPolicyActivity; import org.ntlab.acanthus_client.views.main_menu_ui.mypage.others.TermsOfServiceActivity; -import org.ntlab.acanthus_client.views.userpage.UserPageViewModel; -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.followFollower.FollowFollowerActivity; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -183,8 +179,6 @@ mypageViewModel = new ViewModelProvider(this).get(MyPageViewModel.class); mypageViewModel.init(acanthus); startObserve(); - observeFollowsSize(acanthus.getPreferenceUid()); - observeFollowersSize(acanthus.getPreferenceUid()); mypageViewModel.checkInvitedRequest(); mypageViewModel.getAccountInfoRequest(); @@ -225,39 +219,9 @@ //----------------------------------------------------------------- // - public void observeFollowsSize(Integer loginUid) { - TextView followsSize = binding.followsSizeText; - - mypageViewModel.getMyFollows(loginUid); - mypageViewModel.getMyFollowJson().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(FollowJson followJson) { - Integer size = followJson.getFollowUids().size(); - followsSize.setText(size.toString()); - } - }); - } - - //----------------------------------------------------------------- - // - public void observeFollowersSize(Integer loginUid) { - TextView followersSize = binding.followersSizeText; - - mypageViewModel.getMyFollowers(loginUid); - mypageViewModel.getMyFollowerJson().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(FollowerJson followerJson) { - Integer size = followerJson.getFollowerUids().size(); - followersSize.setText(size.toString()); - } - }); - } - - //----------------------------------------------------------------- - // public void transitionFollowListActivity() { Acanthus acanthus = (Acanthus) getActivity().getApplication(); - Intent intent = new Intent(acanthus, FollowListActivity.class); + Intent intent = new Intent(acanthus, FollowFollowerActivity.class); intent.putExtra("UID", acanthus.getPreferenceUid()); startActivity(intent); } @@ -266,7 +230,7 @@ // public void transitionFollowerListActivity() { Acanthus acanthus = (Acanthus) getActivity().getApplication(); - Intent intent = new Intent(acanthus, FollowerListActivity.class); + Intent intent = new Intent(acanthus, FollowFollowerActivity.class); intent.putExtra("UID", acanthus.getPreferenceUid()); startActivity(intent); } 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 deleted file mode 100644 index 6f8ce34..0000000 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserListViewAdapter.java +++ /dev/null @@ -1,73 +0,0 @@ -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 textViewName; - } - - public UserListViewAdapter(Context context, int layoutId, ArrayList names) { - super(); - this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - this.layoutId = layoutId; - this.nameList = names; - } - - @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.textViewName = convertView.findViewById(R.id.followOrFollowerName); - convertView.setTag(viewHolder); - } else { - //既に初期セットの処理がされている場合、再利用する - viewHolder = (UserListViewAdapter.ViewHolder) convertView.getTag(); - } - - //ViewHolder内のtextViewNameに各ポジションのデータをセット - if (nameList != null) viewHolder.textViewName.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 c936254..38bec0f 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 @@ -10,9 +10,8 @@ import org.ntlab.acanthus_client.Acanthus; import org.ntlab.acanthus_client.R; import org.ntlab.acanthus_client.entities.FollowJson; -import org.ntlab.acanthus_client.entities.FollowerJson; -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.followFollower.FollowFollowerActivity; +import org.ntlab.acanthus_client.views.userpage.followFollower.UserPageViewModel; import org.ntlab.acanthus_client.views.userpage.workList.WorkListActivity; @@ -33,7 +32,6 @@ protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_userpage); - setTitle("ユーザーページ"); userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); acanthus = (Acanthus) getApplication(); @@ -50,18 +48,6 @@ userNameText.setText(uname); TextView profileText = findViewById(R.id.profileText); - TextView followsSize = findViewById(R.id.followsSizeText); - TextView followersSize = findViewById(R.id.followersSizeText); - -// Button returnButton = findViewById(R.id.returnButton); - - //前の画面に戻る処理 -// returnButton.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// finish(); -// } -// }); Button followUserButton = findViewById(R.id.followUserButton); @@ -102,31 +88,12 @@ } }); - //ユーザーのフォロー及びフォロワーの数を表示 - userPageViewModel.getUserFollows(uid); - userPageViewModel.getUserFollowJson().observe(this, new Observer() { - @Override - public void onChanged(FollowJson followJson) { - Integer size = followJson.getFollowUids().size(); - followsSize.setText(size.toString()); - } - }); - - userPageViewModel.getFollowers(uid); - userPageViewModel.getFollowerJson().observe(this, new Observer() { - @Override - public void onChanged(FollowerJson followerJson) { - Integer size = followerJson.getFollowerUids().size(); - followersSize.setText(size.toString()); - } - }); - //ユーザーのフォロー一覧への画面遷移の処理 Button followListButton = findViewById(R.id.followListButton); followListButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(getApplication(), FollowListActivity.class); + Intent intent = new Intent(getApplication(), FollowFollowerActivity.class); intent.putExtra("UID", uid); startActivity(intent); } @@ -137,7 +104,7 @@ followerListButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(getApplication(), FollowerListActivity.class); + Intent intent = new Intent(getApplication(), FollowFollowerActivity.class); intent.putExtra("UID", uid); startActivity(intent); } 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 deleted file mode 100644 index a065b74..0000000 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserPageViewModel.java +++ /dev/null @@ -1,216 +0,0 @@ -package org.ntlab.acanthus_client.views.userpage; - -import org.ntlab.acanthus_client.entities.AnimationJson; -import org.ntlab.acanthus_client.entities.FollowAddJson; -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; -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 MutableLiveData myFollowJsonMutableLiveData; - private MutableLiveData userFollowJsonMutableLiveData; - private MutableLiveData followerJsonMutableLiveData; - private MutableLiveData> animationJsonMutableLiveData; - - public UserPageViewModel(){ - this.myFollowJsonMutableLiveData = new MutableLiveData<>(); - this.userFollowJsonMutableLiveData = new MutableLiveData<>(); - this.followerJsonMutableLiveData = new MutableLiveData<>(); - this.animationJsonMutableLiveData = new MutableLiveData<>(); - } - - public LiveData getMyFollowJson(){ - return this.myFollowJsonMutableLiveData; - } - - public LiveData getUserFollowJson() { - return this.userFollowJsonMutableLiveData; - } - - public LiveData getFollowerJson() { - return this.followerJsonMutableLiveData; - } - - public LiveData> getAnimationJson() { - return animationJsonMutableLiveData; - } - - //ログイン中のユーザーのフォローリストを取得する - public void getMyFollows(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) { - myFollowJsonMutableLiveData.setValue(response.body()); - } - } - } - - @Override - public void onFailure(Call call, Throwable t) { - - } - }); - - } - - //ユーザーのフォローリストを取得する(衝突回避用) - public void getUserFollows(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) { - userFollowJsonMutableLiveData.setValue(response.body()); - } - } - } - - @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) { - - } - - @Override - public void onFailure(Call call, Throwable t) { - - } - }); - - } - - //ユーザーのフォロワーリストを取得する - public void getFollowers(Integer uid){ - 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 call = followersRest.getFollowers(uid); - call.enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - if (response.isSuccessful()) { - if (response.body() != null) { - followerJsonMutableLiveData.setValue(response.body()); - } - } - } - - @Override - 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/followFollower/FollowFollowerActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/FollowFollowerActivity.java new file mode 100644 index 0000000..ec6e8ef --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/FollowFollowerActivity.java @@ -0,0 +1,48 @@ +package org.ntlab.acanthus_client.views.userpage.followFollower; + +import androidx.fragment.app.FragmentActivity; +import androidx.viewpager2.adapter.FragmentStateAdapter; +import androidx.viewpager2.widget.ViewPager2; + +import android.os.Bundle; +import android.view.View; + +import com.google.android.material.tabs.TabLayout; +import com.google.android.material.tabs.TabLayoutMediator; + +import org.ntlab.acanthus_client.R; + +public class FollowFollowerActivity extends FragmentActivity { + + private ViewPager2 pager; + private FragmentStateAdapter adapter; + private String[] tabText = {"フォロー", "フォロワー"}; + + private int currentPage; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_follow_follower); + + pager = findViewById(R.id.pager); + + adapter = new FollowFollowerAdapter(this); + pager.setAdapter(adapter); + currentPage = 0; + + TabLayout tabLayout = findViewById(R.id.tab_layout); + new TabLayoutMediator(tabLayout, pager, + (tab, position) -> tab.setText(tabText[position]) + ).attach(); + } + + public void onClickNext(View view) { + currentPage ++; + pager.setCurrentItem(currentPage); + } + + public void onClickGoToTop(View view) { + currentPage = 0; + pager.setCurrentItem(currentPage); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/FollowFollowerAdapter.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/FollowFollowerAdapter.java new file mode 100644 index 0000000..4b75a14 --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/FollowFollowerAdapter.java @@ -0,0 +1,34 @@ +package org.ntlab.acanthus_client.views.userpage.followFollower; + +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.viewpager2.adapter.FragmentStateAdapter; + +import org.ntlab.acanthus_client.views.userpage.followFollower.followList.FollowListFragment; +import org.ntlab.acanthus_client.views.userpage.followFollower.followerList.FollowerListFragment; + +public class FollowFollowerAdapter extends FragmentStateAdapter { + private static final int PAGE_NUM = 2; + + public FollowFollowerAdapter(FragmentActivity fm) { + super(fm); + } + + @Override + public Fragment createFragment(int position) { + Fragment fragment = null; + switch (position){ + case 0: + fragment = new FollowListFragment(); + break; + default: + fragment = new FollowerListFragment(); + } + return fragment; + } + + @Override + public int getItemCount() { + return PAGE_NUM; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/UserListViewAdapter.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/UserListViewAdapter.java new file mode 100644 index 0000000..1e5b2ed --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/UserListViewAdapter.java @@ -0,0 +1,73 @@ +package org.ntlab.acanthus_client.views.userpage.followFollower; + +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 textViewName; + } + + public UserListViewAdapter(Context context, int layoutId, ArrayList names) { + super(); + this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + this.layoutId = layoutId; + this.nameList = names; + } + + @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.textViewName = convertView.findViewById(R.id.followOrFollowerName); + convertView.setTag(viewHolder); + } else { + //既に初期セットの処理がされている場合、再利用する + viewHolder = (UserListViewAdapter.ViewHolder) convertView.getTag(); + } + + //ViewHolder内のtextViewNameに各ポジションのデータをセット + if (nameList != null) viewHolder.textViewName.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/followFollower/UserPageViewModel.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/UserPageViewModel.java new file mode 100644 index 0000000..c128e73 --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/UserPageViewModel.java @@ -0,0 +1,216 @@ +package org.ntlab.acanthus_client.views.userpage.followFollower; + +import org.ntlab.acanthus_client.entities.AnimationJson; +import org.ntlab.acanthus_client.entities.FollowAddJson; +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; +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 MutableLiveData myFollowJsonMutableLiveData; + private MutableLiveData userFollowJsonMutableLiveData; + private MutableLiveData followerJsonMutableLiveData; + private MutableLiveData> animationJsonMutableLiveData; + + public UserPageViewModel(){ + this.myFollowJsonMutableLiveData = new MutableLiveData<>(); + this.userFollowJsonMutableLiveData = new MutableLiveData<>(); + this.followerJsonMutableLiveData = new MutableLiveData<>(); + this.animationJsonMutableLiveData = new MutableLiveData<>(); + } + + public LiveData getMyFollowJson(){ + return this.myFollowJsonMutableLiveData; + } + + public LiveData getUserFollowJson() { + return this.userFollowJsonMutableLiveData; + } + + public LiveData getFollowerJson() { + return this.followerJsonMutableLiveData; + } + + public LiveData> getAnimationJson() { + return animationJsonMutableLiveData; + } + + //ログイン中のユーザーのフォローリストを取得する + public void getMyFollows(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) { + myFollowJsonMutableLiveData.setValue(response.body()); + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + + } + + //ユーザーのフォローリストを取得する(衝突回避用) + public void getUserFollows(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) { + userFollowJsonMutableLiveData.setValue(response.body()); + } + } + } + + @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) { + + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + + } + + //ユーザーのフォロワーリストを取得する + public void getFollowers(Integer uid){ + 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 call = followersRest.getFollowers(uid); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + if (response.body() != null) { + followerJsonMutableLiveData.setValue(response.body()); + } + } + } + + @Override + 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/followFollower/followList/FollowListFragment.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/followList/FollowListFragment.java new file mode 100644 index 0000000..3a3fbcd --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/followList/FollowListFragment.java @@ -0,0 +1,79 @@ +package org.ntlab.acanthus_client.views.userpage.followFollower.followList; + +import android.content.Intent; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; +import androidx.viewpager2.widget.ViewPager2; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.BaseAdapter; +import android.widget.Button; +import android.widget.ListView; + +import com.google.android.material.tabs.TabLayout; +import com.google.android.material.tabs.TabLayoutMediator; + +import org.ntlab.acanthus_client.Acanthus; +import org.ntlab.acanthus_client.R; +import org.ntlab.acanthus_client.databinding.FragmentEditBinding; +import org.ntlab.acanthus_client.databinding.FragmentFollowListBinding; +import org.ntlab.acanthus_client.entities.FollowJson; +import org.ntlab.acanthus_client.views.userpage.followFollower.FollowFollowerAdapter; +import org.ntlab.acanthus_client.views.userpage.followFollower.UserListViewAdapter; +import org.ntlab.acanthus_client.views.userpage.UserPageActivity; +import org.ntlab.acanthus_client.views.userpage.followFollower.UserPageViewModel; + +import java.util.ArrayList; + +public class FollowListFragment extends Fragment { + + private UserPageViewModel userPageViewModel; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_follow_list, container, false); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); + Intent intent = getActivity().getIntent(); //UserPageActivityからuidをもらう + Integer uid = intent.getIntExtra("UID", 0); + ListView listView = getActivity().findViewById(R.id.followListView); + + //フォロー一覧の取得と表示 + userPageViewModel.getMyFollows(uid); + userPageViewModel.getMyFollowJson().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(FollowJson followJson) { + ArrayList followUidList = followJson.getFollowUids(); + ArrayList followNameList = followJson.getFollowNames(); + BaseAdapter adapter = new UserListViewAdapter(getActivity().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(getActivity().getApplication(), UserPageActivity.class); + intent.putExtra("UID", followUidList.get(position)); + intent.putExtra("NAME", followNameList.get(position)); + startActivity(intent); + } + }); + } + }); + + } + +} diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/followerList/FollowerListFragment.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/followerList/FollowerListFragment.java new file mode 100644 index 0000000..3219cf9 --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followFollower/followerList/FollowerListFragment.java @@ -0,0 +1,73 @@ +package org.ntlab.acanthus_client.views.userpage.followFollower.followerList; + +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.BaseAdapter; +import android.widget.Button; +import android.widget.ListView; + +import androidx.fragment.app.Fragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; + +import org.jetbrains.annotations.Nullable; +import org.ntlab.acanthus_client.Acanthus; +import org.ntlab.acanthus_client.R; +import org.ntlab.acanthus_client.entities.FollowerJson; +import org.ntlab.acanthus_client.views.userpage.followFollower.UserListViewAdapter; +import org.ntlab.acanthus_client.views.userpage.UserPageActivity; +import org.ntlab.acanthus_client.views.userpage.followFollower.UserPageViewModel; + +import java.util.ArrayList; + +public class FollowerListFragment extends Fragment { + + private UserPageViewModel userPageViewModel; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + userPageViewModel = new ViewModelProvider(this).get(UserPageViewModel.class); + + return inflater.inflate(R.layout.fragment_follower_list, container, false); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + Acanthus acanthus = (Acanthus) getActivity().getApplication(); + + Intent intent = getActivity().getIntent(); //UserPageActivityからuidをもらう + Integer uid = intent.getIntExtra("UID", 0); + ListView listView = (ListView) getActivity().findViewById(R.id.followerListView); + + //フォロワー一覧の取得と表示 + userPageViewModel.getFollowers(uid); + userPageViewModel.getFollowerJson().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(@Nullable FollowerJson followerJson) { + ArrayList followerUidList = followerJson.getFollowerUids(); + ArrayList followerNameList = followerJson.getFollowerNames(); + BaseAdapter adapter = new UserListViewAdapter(getActivity(), 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(getActivity(), UserPageActivity.class); + intent.putExtra("UID", followerUidList.get(position)); + intent.putExtra("NAME", followerNameList.get(position)); + startActivity(intent); + } + }); + } + }); + + } + +} 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 deleted file mode 100644 index 6c13b23..0000000 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followList/FollowListActivity.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.ntlab.acanthus_client.views.userpage.followList; - -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.AdapterView; -import android.widget.BaseAdapter; -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 { - - private UserPageViewModel userPageViewModel; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_follow_list); - setTitle("フォロー中"); - - 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); - - //前の画面に戻る処理 -// returnButton.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// finish(); -// } -// }); - - //フォロー一覧の取得と表示 - userPageViewModel.getMyFollows(uid); - userPageViewModel.getMyFollowJson().observe(this, new Observer() { - @Override - public void onChanged(FollowJson followJson) { - ArrayList followUidList = followJson.getFollowUids(); - ArrayList followNameList = followJson.getFollowNames(); - 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)); - intent.putExtra("NAME", followNameList.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 deleted file mode 100644 index b906211..0000000 --- a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/followerList/FollowerListActivity.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.ntlab.acanthus_client.views.userpage.followerList; - -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; - - -public class FollowerListActivity extends AppCompatActivity { - - private UserPageViewModel userPageViewModel; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_follower_list); - setTitle("フォロワー"); - - 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); - - //前の画面に戻る処理 -// returnButton.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// finish(); -// } -// }); - - //フォロワー一覧の取得と表示 - userPageViewModel.getFollowers(uid); - userPageViewModel.getFollowerJson().observe(this, new Observer() { - @Override - public void onChanged(@Nullable FollowerJson followerJson) { - ArrayList followerUidList = followerJson.getFollowerUids(); - ArrayList followerNameList = followerJson.getFollowerNames(); - 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)); - intent.putExtra("NAME", followerNameList.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 16a5997..56d70a0 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 @@ -13,7 +13,7 @@ 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 org.ntlab.acanthus_client.views.userpage.followFollower.UserPageViewModel; import java.util.ArrayList; import java.util.Collection; diff --git a/app/src/main/res/layout/activity_follow_follower.xml b/app/src/main/res/layout/activity_follow_follower.xml new file mode 100644 index 0000000..05da267 --- /dev/null +++ b/app/src/main/res/layout/activity_follow_follower.xml @@ -0,0 +1,19 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_follow_list.xml b/app/src/main/res/layout/activity_follow_list.xml deleted file mode 100644 index b123b37..0000000 --- a/app/src/main/res/layout/activity_follow_list.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - \ 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 deleted file mode 100644 index 6bf1526..0000000 --- a/app/src/main/res/layout/activity_follower_list.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - \ 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 index 0be5af4..de25aef 100644 --- a/app/src/main/res/layout/follow_or_follower_list.xml +++ b/app/src/main/res/layout/follow_or_follower_list.xml @@ -11,6 +11,8 @@ android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginLeft="16dp" + android:layout_marginRight="16dp" android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingRight="7dp" diff --git a/app/src/main/res/layout/fragment_follow_list.xml b/app/src/main/res/layout/fragment_follow_list.xml new file mode 100644 index 0000000..1592b4c --- /dev/null +++ b/app/src/main/res/layout/fragment_follow_list.xml @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_follower_list.xml b/app/src/main/res/layout/fragment_follower_list.xml new file mode 100644 index 0000000..cded169 --- /dev/null +++ b/app/src/main/res/layout/fragment_follower_list.xml @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ad569bd..6a900d6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,4 +25,6 @@ paint_button edit_button editActionBarShare + + Hello blank fragment \ No newline at end of file