diff --git a/.idea/misc.xml b/.idea/misc.xml index 743778d..961a5e2 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,9 +12,12 @@ + + + @@ -34,8 +37,6 @@ - - diff --git a/app/src/main/java/com/example/nemophila/FriendActivity.java b/app/src/main/java/com/example/nemophila/FriendActivity.java index d611634..6b084ea 100644 --- a/app/src/main/java/com/example/nemophila/FriendActivity.java +++ b/app/src/main/java/com/example/nemophila/FriendActivity.java @@ -11,11 +11,14 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.Color; +import android.graphics.PorterDuff; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -69,6 +72,15 @@ .create() .show(); } + + @Override + void onFavoriteClick(View view, int position, FriendDataModel friend, ImageView favorite) { + if (favorite.getVisibility() == View.INVISIBLE) { + favorite.setVisibility(View.VISIBLE); + } else { + favorite.setVisibility(View.INVISIBLE); + } + } }; friendViewModel.getFriends(myUid); // 自身のフレンドの一覧を取得するメソッドを呼び出す @@ -120,16 +132,26 @@ // ViewHolderを生成 FriendsViewHolder vh = new FriendsViewHolder(inflate); - // クリックイベントを登録 + // 削除ボタンを押したときのイベントを登録 vh.deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int position = vh.getBindingAdapterPosition(); - // 処理はonItemClick()に丸投げ + // 処理はonDeleteClick()に丸投げ onDeleteClick(v, position, friendDatas.get(position)); } }); + // お気に入りに追加したときのイベントを登録 + vh.favoriteOutline.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int position = vh.getBindingAdapterPosition(); + // 処理はonFavoriteClick()に丸投げ + onFavoriteClick(v, position, friendDatas.get(position), vh.favorite); + } + }); + return vh; } @@ -145,16 +167,21 @@ } abstract void onDeleteClick(View view, int position, FriendDataModel friend); + abstract void onFavoriteClick(View view, int position, FriendDataModel friend, ImageView favorite); } // ViewHolder public class FriendsViewHolder extends RecyclerView.ViewHolder { + public ImageView favorite; + public ImageButton favoriteOutline; public ImageView iconView; public TextView nameView; public Button deleteButton; public FriendsViewHolder(@NonNull View itemView) { super(itemView); + favorite = itemView.findViewById(R.id.favorite); + favoriteOutline = itemView.findViewById(R.id.favorite_outline); iconView = itemView.findViewById(R.id.friendIcon); nameView = itemView.findViewById(R.id.friendName); deleteButton = itemView.findViewById(R.id.friendDelete); diff --git a/app/src/main/res/drawable/ic_star.xml b/app/src/main/res/drawable/ic_star.xml new file mode 100644 index 0000000..f4b4d6a --- /dev/null +++ b/app/src/main/res/drawable/ic_star.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_star_outline.xml b/app/src/main/res/drawable/ic_star_outline.xml new file mode 100644 index 0000000..59aef55 --- /dev/null +++ b/app/src/main/res/drawable/ic_star_outline.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/layout_friends_activity.xml b/app/src/main/res/layout/layout_friends_activity.xml index 7635bd4..b0ec740 100644 --- a/app/src/main/res/layout/layout_friends_activity.xml +++ b/app/src/main/res/layout/layout_friends_activity.xml @@ -5,25 +5,53 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + + + + + + +