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