| |
---|
| | |
---|
| | //フレンドを取得 |
---|
| | Collection<AccountNameJson> friends = ((Nemophila)getApplication()).getFriends(); |
---|
| | |
---|
| | //Nemophilaから選択中のジャンル(HashSet)を受け取る |
---|
| | HashSet<String> selectingGenre = ((Nemophila)getApplication()).getSelectGenres(); |
---|
| | |
---|
| | //選択中のジャンルが何かあれば表示 |
---|
| | if(!(selectingGenre.isEmpty())) { |
---|
| | TextView genreView = (TextView) findViewById(R.id.shopAcGenre); |
---|
| | genreView.setText("選択中のジャンル:" + selectingGenre); |
---|
| | } |
---|
| | |
---|
| | //Nemophilaから選択中のフレンド(HashSet)を受け取る |
---|
| | HashSet<String> selectingFriend = ((Nemophila)getApplication()).getSelectFriends(); |
---|
| | |
---|
| | //選択したフレンドを表示するために名前を格納するHashSetを宣言 |
---|
| | HashSet<String> selectingFriendName = new HashSet<>(); |
---|
| | //フレンド選択があればフレンド名をHashSetにセットし表示する |
---|
| | if(!(selectingFriend.isEmpty())) { |
---|
| | for (AccountNameJson friendNJ : friends) { |
---|
| | if (selectingFriend.contains(friendNJ.getUid())) { |
---|
| | selectingFriendName.add(friendNJ.getName()); |
---|
| | } |
---|
| | } |
---|
| | TextView friendView = (TextView) findViewById(R.id.shopAcFriend); |
---|
| | friendView.setText("選択中のフレンド:" + selectingFriendName); |
---|
| | } |
---|
| | |
---|
| | //RecyclerViewに表示する中身を格納するリストを宣言 |
---|
| | List<ShopAcDataModel> postsDataset = new ArrayList<>(); |
---|
| | |
---|
| | //RecyclerView(表示の設定、直接表示するところはLivedataを購読しているonChanged内) |
---|
| |
---|
| | postsViewModel.getShopPostLiveData().observe(this, new Observer<List<Post>>() { |
---|
| | @Override |
---|
| | public void onChanged(List<Post> ShopPosts) { |
---|
| | |
---|
| | //Nemophilaから選択中のジャンル(HashSet)を受け取る |
---|
| | HashSet<String> selectingGenre = ((Nemophila)getApplication()).getSelectGenres(); |
---|
| | |
---|
| | //選択中のジャンルが何かあれば表示 |
---|
| | if(!(selectingGenre.isEmpty())) { |
---|
| | TextView genreView = (TextView) findViewById(R.id.shopAcGenre); |
---|
| | genreView.setText("選択中のジャンル:" + selectingGenre); |
---|
| | } |
---|
| | |
---|
| | //Nemophilaから選択中のフレンド(HashSet)を受け取る |
---|
| | HashSet<String> selectingFriend = ((Nemophila)getApplication()).getSelectFriends(); |
---|
| | //選択したフレンドを表示するために名前を格納するHashSetの宣言 |
---|
| | HashSet<String> selectingFriendName = new HashSet<>(); |
---|
| | |
---|
| | //postsDatasetを一旦クリアし、LiveDataから受け取ったデータを一つずつセット(重複しないように) |
---|
| | postsDataset.clear(); |
---|
| | |
---|
| | int postViewFrag; |
---|
| | |
---|
| | for (Post post: ShopPosts){ |
---|
| | //dataを宣言 dataに投稿の必要なデータをセットし、それをpostsDatasetに追加してリストを作る |
---|
| | //dataを宣言 dataに投稿の必要なデータをpostから受け取ってセットし、それをpostsDatasetに追加してリストを作る |
---|
| | ShopAcDataModel data = new ShopAcDataModel(); |
---|
| | //フィルター判定のためにgenreとuidを、表示用のセットのためにnameを先に読み込む |
---|
| | //フィルター判定のためにgenreとuidを先に読み込む |
---|
| | String genre = post.getGenre(); |
---|
| | String uid = post.getUid(); |
---|
| | String name = post.getName(); |
---|
| | |
---|
| | //投稿が自分もしくはフレンドのものかチェック |
---|
| | postViewFrag = 0; |
---|
| | if(uid.equals(myUid)) { |
---|
| |
---|
| | } |
---|
| | |
---|
| | //表示する投稿のみdataにセット |
---|
| | if(postViewFrag == 1) { |
---|
| | // if(friends.contains(uid)){ |
---|
| | //選択が何もない場合は全ての投稿を、選択がある場合は一致する投稿をdataにセット |
---|
| | if (selectingGenre.isEmpty() || selectingGenre.contains(genre)) { |
---|
| | if (selectingFriend.isEmpty() || selectingFriend.contains(uid)) { |
---|
| | data.setName(name); |
---|
| | data.setName(post.getName()); |
---|
| | data.setDate(post.getDate()); |
---|
| | //アイコンをURLで取得、セット |
---|
| | |
---|
| | //rateはintで受け取った評価に対応した星の数のStringに変換してセット |
---|
| | int intRate = post.getRate(); |
---|
| | String strRate = ""; |
---|
| | for (int i = 0; i < 5; i++) { |
---|
| |
---|
| | } |
---|
| | data.setRate(strRate); |
---|
| | data.setGenre(genre); |
---|
| | data.setComment(post.getComment()); |
---|
| | //画像がなければViewの表示をgoneに、あればvisibleにして画像をセット |
---|
| | // if(post.get) { |
---|
| | // } |
---|
| | |
---|
| | //投稿一つの情報がdataに全部セットされたらDatasetに追加 |
---|
| | postsDataset.add(0, data); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | //フレンド名を表示用HashSetにセット |
---|
| | if(!(selectingFriend.isEmpty()) && selectingFriend.contains(uid)) { |
---|
| | selectingFriendName.add(name); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | //フレンド選択があればフレンド名を表示する |
---|
| | if(!(selectingFriend.isEmpty())) { |
---|
| | TextView friendView = (TextView) findViewById(R.id.shopAcFriend); |
---|
| | friendView.setText("表示中のフレンド:" + selectingFriendName); |
---|
| | } |
---|
| | |
---|
| | //RecyclerViewをonChangedが呼ばれるたび表示(アダプターを更新してRecyclerViewにセット) |
---|
| | adapter.setList(postsDataset); |
---|
| |
---|
| | rateView = (TextView) itemView.findViewById(R.id.shopAcRate); |
---|
| | genreView = (TextView) itemView.findViewById(R.id.shopAcGenre); |
---|
| | commentView = (TextView) itemView.findViewById(R.id.shopAcComment); |
---|
| | iconView = (ImageView) itemView.findViewById(R.id.shopAcIconPic); |
---|
| | image1View = (ImageView) itemView.findViewById(R.id.shopAcImage1); |
---|
| | image2View = (ImageView) itemView.findViewById(R.id.shopAcImage2); |
---|
| | image3View = (ImageView) itemView.findViewById(R.id.shopAcImage3); |
---|
| | // image1View = (ImageView) itemView.findViewById(R.id.shopAcImage1); |
---|
| | // image2View = (ImageView) itemView.findViewById(R.id.shopAcImage2); |
---|
| | // image3View = (ImageView) itemView.findViewById(R.id.shopAcImage3); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | //DataModel(投稿1つあたりに必要なデータ) |
---|
| |
---|
| | public void setIcon(String icon) { |
---|
| | this.icon = icon; |
---|
| | } |
---|
| | |
---|
| | public String getImage() { return image1; } |
---|
| | public void setImage1(String image1) { |
---|
| | this.image1 = image1; |
---|
| | } |
---|
| | |
---|
| | public String getImage2() { return image2; } |
---|
| | public void setImage2(String image2) { |
---|
| | this.image2 = image2; |
---|
| | } |
---|
| | |
---|
| | public String getImage3() { return image3; } |
---|
| | public void setImage3(String image3) { |
---|
| | this.image3 = image3; |
---|
| | } |
---|
| | // public String getImage() { return image1; } |
---|
| | // public void setImage1(String image1) { |
---|
| | // this.image1 = image1; |
---|
| | // } |
---|
| | // |
---|
| | // public String getImage2() { return image2; } |
---|
| | // public void setImage2(String image2) { |
---|
| | // this.image2 = image2; |
---|
| | // } |
---|
| | // |
---|
| | // public String getImage3() { return image3; } |
---|
| | // public void setImage3(String image3) { |
---|
| | // this.image3 = image3; |
---|
| | // } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |