From 8af231e526c656f827b00995ea9614fc5a6e5953 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 19 Jul 2023 13:07:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/utils/RouteUtil.java | 1 + .../activity/UserAvatarSelectActivity.java | 27 +++++++++++++++ .../main/adapter/UserAvatarSelectAdapter.java | 33 +++++++++++++++++++ .../layout/activity_user_select_avatar.xml | 22 +++++++++++++ .../res/layout/item_user_avatar_select.xml | 6 ++++ 5 files changed, 89 insertions(+) create mode 100644 main/src/main/java/com/yunbao/main/activity/UserAvatarSelectActivity.java create mode 100644 main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter.java create mode 100644 main/src/main/res/layout/activity_user_select_avatar.xml create mode 100644 main/src/main/res/layout/item_user_avatar_select.xml diff --git a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java index aaae75cc4..e62497908 100644 --- a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java @@ -43,6 +43,7 @@ public class RouteUtil { public static final String PATH_RED_PACKET_LIST = "/main/RedPacketListActivity"; public static final String PATH_RED_PACKET_INFO = "/main/RedPacketInfoActivity"; public static final String PATH_RED_PACKET_USER = "/main/RedPacketUsersActivity"; + public static final String PATH_SELECT_AVATAR="/main/UserAvatarSelectActivity"; public static void forwardFansActivity(String uid) { ARouter.getInstance().build(PATH_FANSACTIVITY) diff --git a/main/src/main/java/com/yunbao/main/activity/UserAvatarSelectActivity.java b/main/src/main/java/com/yunbao/main/activity/UserAvatarSelectActivity.java new file mode 100644 index 000000000..c2a0fc665 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/activity/UserAvatarSelectActivity.java @@ -0,0 +1,27 @@ +package com.yunbao.main.activity; + +import android.os.Bundle; + +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; + +import com.alibaba.android.arouter.facade.annotation.Route; +import com.yunbao.common.activity.AbsActivity; +import com.yunbao.common.utils.RouteUtil; +import com.yunbao.main.R; + +@Route(path = RouteUtil.PATH_SELECT_AVATAR) +public class UserAvatarSelectActivity extends AbsActivity { + RecyclerView recyclerView; + + @Override + protected int getLayoutId() { + return R.layout.activity_user_select_avatar; + } + + @Override + protected void main() { + super.main(); + recyclerView = findViewById(R.id.recyclerView); + } +} diff --git a/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter.java b/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter.java new file mode 100644 index 000000000..336c7a2f0 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter.java @@ -0,0 +1,33 @@ +package com.yunbao.main.adapter; + +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +public class UserAvatarSelectAdapter extends RecyclerView.Adapter{ + @NonNull + @Override + public AvatarSelectViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return null; + } + + @Override + public void onBindViewHolder(@NonNull AvatarSelectViewHolder holder, int position) { + + } + + @Override + public int getItemCount() { + return 0; + } + + public class AvatarSelectViewHolder extends RecyclerView.ViewHolder{ + + public AvatarSelectViewHolder(@NonNull View itemView) { + super(itemView); + } + } + +} diff --git a/main/src/main/res/layout/activity_user_select_avatar.xml b/main/src/main/res/layout/activity_user_select_avatar.xml new file mode 100644 index 000000000..df22e97fa --- /dev/null +++ b/main/src/main/res/layout/activity_user_select_avatar.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/layout/item_user_avatar_select.xml b/main/src/main/res/layout/item_user_avatar_select.xml new file mode 100644 index 000000000..77d9ef65f --- /dev/null +++ b/main/src/main/res/layout/item_user_avatar_select.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file From dd2f3db16a60e8d285e45ed6bfb0fa33ddb05bb9 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 19 Jul 2023 15:35:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/bean/UserAvatarSelectBean.java | 40 ++++++++++++++ .../com/yunbao/common/utils/RouteUtil.java | 8 +++ main/src/main/AndroidManifest.xml | 2 + .../activity/UserAvatarSelectActivity.java | 30 ++++++++++- .../main/adapter/UserAvatarSelectAdapter.java | 54 +++++++++++++++++-- .../yunbao/main/views/MainHomeViewHolder.java | 9 +++- .../bg_user_avatar_select_selected.xml | 5 ++ .../bg_user_avatar_select_unselected.xml | 5 ++ .../layout/activity_user_select_avatar.xml | 1 + .../res/layout/item_user_avatar_select.xml | 50 ++++++++++++++++- 10 files changed, 194 insertions(+), 10 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/bean/UserAvatarSelectBean.java create mode 100644 main/src/main/res/drawable/bg_user_avatar_select_selected.xml create mode 100644 main/src/main/res/drawable/bg_user_avatar_select_unselected.xml diff --git a/common/src/main/java/com/yunbao/common/bean/UserAvatarSelectBean.java b/common/src/main/java/com/yunbao/common/bean/UserAvatarSelectBean.java new file mode 100644 index 000000000..d4efcaca6 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/UserAvatarSelectBean.java @@ -0,0 +1,40 @@ +package com.yunbao.common.bean; + +public class UserAvatarSelectBean { + private int id; + private String url; + private int select; + + public UserAvatarSelectBean(int id, String url, int select) { + this.id = id; + this.url = url; + this.select = select; + } + + public UserAvatarSelectBean() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getSelect() { + return select; + } + + public void setSelect(int select) { + this.select = select; + } +} diff --git a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java index e62497908..6ac480e8c 100644 --- a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java @@ -295,4 +295,12 @@ public class RouteUtil { .withInt("id", id) .navigation(); } + + /** + * 系统头像选择 + */ + public static void forwardUserAvatarSelect(){ + ARouter.getInstance().build(PATH_SELECT_AVATAR) + .navigation(); + } } diff --git a/main/src/main/AndroidManifest.xml b/main/src/main/AndroidManifest.xml index fef1e28bc..40f7204ba 100644 --- a/main/src/main/AndroidManifest.xml +++ b/main/src/main/AndroidManifest.xml @@ -156,6 +156,8 @@ + \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/activity/UserAvatarSelectActivity.java b/main/src/main/java/com/yunbao/main/activity/UserAvatarSelectActivity.java index c2a0fc665..08f4ebda3 100644 --- a/main/src/main/java/com/yunbao/main/activity/UserAvatarSelectActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/UserAvatarSelectActivity.java @@ -1,18 +1,26 @@ package com.yunbao.main.activity; -import android.os.Bundle; +import android.widget.TextView; -import androidx.annotation.Nullable; +import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.alibaba.android.arouter.facade.annotation.Route; import com.yunbao.common.activity.AbsActivity; +import com.yunbao.common.bean.UserAvatarSelectBean; import com.yunbao.common.utils.RouteUtil; import com.yunbao.main.R; +import com.yunbao.main.adapter.UserAvatarSelectAdapter; + +import java.util.ArrayList; +import java.util.List; @Route(path = RouteUtil.PATH_SELECT_AVATAR) public class UserAvatarSelectActivity extends AbsActivity { RecyclerView recyclerView; + UserAvatarSelectAdapter adapter; + List list; + TextView titleView; @Override protected int getLayoutId() { @@ -22,6 +30,24 @@ public class UserAvatarSelectActivity extends AbsActivity { @Override protected void main() { super.main(); + titleView=findViewById(R.id.titleView); + titleView.setText("選擇頭像"); recyclerView = findViewById(R.id.recyclerView); + adapter = new UserAvatarSelectAdapter(mContext); + recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3)); + recyclerView.setAdapter(adapter); + test(); + } + + private void test() { + list = new ArrayList<>(); + for (int i = 0; i < 6; i++) { + UserAvatarSelectBean bean = new UserAvatarSelectBean(i, + "https://downs.yaoulive.com/20220906170849_79c553dc1319fb5c215e06e01674eba4?imageView2/2/w/600/h/600", + i == 3 ? 1 : 0 + ); + list.add(bean); + } + adapter.setList(list); } } diff --git a/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter.java b/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter.java index 336c7a2f0..12cf85782 100644 --- a/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter.java @@ -1,32 +1,76 @@ package com.yunbao.main.adapter; +import android.content.Context; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; -public class UserAvatarSelectAdapter extends RecyclerView.Adapter{ +import com.yunbao.common.bean.UserAvatarSelectBean; +import com.yunbao.common.custom.RatioRoundImageView; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.main.R; + +import java.util.List; + +public class UserAvatarSelectAdapter extends RecyclerView.Adapter { + private Context mContext; + private List list; + private int select = 0; + + public void setList(List list) { + this.list = list; + notifyDataSetChanged(); + } + + public UserAvatarSelectAdapter(Context mContext) { + this.mContext = mContext; + } + @NonNull @Override public AvatarSelectViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return null; + return new AvatarSelectViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_user_avatar_select, parent, false)); } @Override public void onBindViewHolder(@NonNull AvatarSelectViewHolder holder, int position) { - + holder.setData(list.get(position), position); } @Override public int getItemCount() { - return 0; + return list.size(); } - public class AvatarSelectViewHolder extends RecyclerView.ViewHolder{ + public class AvatarSelectViewHolder extends RecyclerView.ViewHolder { + private View hide; + private View show; + private RatioRoundImageView avatar; public AvatarSelectViewHolder(@NonNull View itemView) { super(itemView); + hide = itemView.findViewById(R.id.hideCover); + show = itemView.findViewById(R.id.showCover); + avatar = itemView.findViewById(R.id.avatar); + itemView.setOnClickListener(v -> { + select = (int) v.getTag(); + notifyDataSetChanged(); + }); + } + + public void setData(UserAvatarSelectBean bean, int position) { + ImgLoader.display(itemView.getContext(), bean.getUrl(), avatar); + if (select == position) { + show.setVisibility(View.VISIBLE); + hide.setVisibility(View.GONE); + } else { + show.setVisibility(View.INVISIBLE); + hide.setVisibility(View.VISIBLE); + } + itemView.setTag(position); } } diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java index f04befa48..007d6649b 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java @@ -8,6 +8,7 @@ import android.widget.FrameLayout; import android.widget.ImageView; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.utils.RouteUtil; import com.yunbao.main.R; import com.yunbao.main.activity.RedPacketListActivity; @@ -41,7 +42,13 @@ public class MainHomeViewHolder extends AbsMainHomeParentViewHolder { ImgLoader.display(mContext, "https://downs.yaoulive.com/gif_trophy.gif", img_trophy); - + img_trophy.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + RouteUtil.forwardUserAvatarSelect(); + return false; + } + }); } public void setCurPosition(int position){ diff --git a/main/src/main/res/drawable/bg_user_avatar_select_selected.xml b/main/src/main/res/drawable/bg_user_avatar_select_selected.xml new file mode 100644 index 000000000..0a8069452 --- /dev/null +++ b/main/src/main/res/drawable/bg_user_avatar_select_selected.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/bg_user_avatar_select_unselected.xml b/main/src/main/res/drawable/bg_user_avatar_select_unselected.xml new file mode 100644 index 000000000..85743b326 --- /dev/null +++ b/main/src/main/res/drawable/bg_user_avatar_select_unselected.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/main/src/main/res/layout/activity_user_select_avatar.xml b/main/src/main/res/layout/activity_user_select_avatar.xml index df22e97fa..52c939dc4 100644 --- a/main/src/main/res/layout/activity_user_select_avatar.xml +++ b/main/src/main/res/layout/activity_user_select_avatar.xml @@ -2,6 +2,7 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="85dp" + android:layout_height="85dp" + android:layout_marginStart="22dp" + android:layout_marginTop="32dp"> + + + + + + \ No newline at end of file