From 736592b4e117fdc953877fbfc49e4be9347e953f Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 19 Jul 2023 18:30:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=B4=E5=83=8F=E9=80=89?= =?UTF-8?q?=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 | 46 +++++++----- .../com/yunbao/common/http/PDLiveApi.java | 16 ++++ .../common/http/live/LiveNetManager.java | 48 +++++++++++- common/src/main/res/values-en-rUS/string.xml | 2 + common/src/main/res/values-zh-rHK/strings.xml | 2 + common/src/main/res/values-zh-rTW/strings.xml | 2 + common/src/main/res/values-zh/strings.xml | 2 + common/src/main/res/values/strings.xml | 2 + .../bg_item_live_send_details_gift.xml | 2 +- ...g_item_live_send_details_gift_unselect.xml | 10 +++ live/src/main/res/values-en/strings.xml | 2 + live/src/main/res/values/strings.xml | 2 + .../main/activity/EditProfileActivity.java | 11 ++- .../activity/UserAvatarSelectActivity.java | 75 +++++++++++++++---- .../main/adapter/UserAvatarSelectAdapter.java | 38 ++++++++-- .../yunbao/main/views/MainHomeViewHolder.java | 7 -- .../bg_user_avatar_select_unselected.xml | 2 +- .../layout/activity_user_select_avatar.xml | 32 +++++++- .../res/layout/item_user_avatar_select.xml | 4 +- 19 files changed, 249 insertions(+), 56 deletions(-) create mode 100644 live/src/main/res/drawable/bg_item_live_send_details_gift_unselect.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 index d4efcaca6..632dbc21a 100644 --- a/common/src/main/java/com/yunbao/common/bean/UserAvatarSelectBean.java +++ b/common/src/main/java/com/yunbao/common/bean/UserAvatarSelectBean.java @@ -1,18 +1,16 @@ package com.yunbao.common.bean; -public class UserAvatarSelectBean { +import com.google.gson.annotations.SerializedName; + +public class UserAvatarSelectBean extends BaseModel { + @SerializedName("id") 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() { - } + @SerializedName("name") + private String name; + @SerializedName("path") + private String path; + @SerializedName("checked") + private int checked; public int getId() { return id; @@ -22,19 +20,27 @@ public class UserAvatarSelectBean { this.id = id; } - public String getUrl() { - return url; + public String getName() { + return name; } - public void setUrl(String url) { - this.url = url; + public void setName(String name) { + this.name = name; } - public int getSelect() { - return select; + public String getPath() { + return path; } - public void setSelect(int select) { - this.select = select; + public void setPath(String path) { + this.path = path; + } + + public int getChecked() { + return checked; + } + + public void setChecked(int checked) { + this.checked = checked; } } diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index 60938e8fb..173989589 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -45,6 +45,7 @@ import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.SlideInBannerModel; import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.UserAreaBean; +import com.yunbao.common.bean.UserAvatarSelectBean; import com.yunbao.common.bean.VipModel; import com.yunbao.common.bean.WishListGiftConfModel; import com.yunbao.common.bean.WishListModel; @@ -829,4 +830,19 @@ public interface PDLiveApi { @Query("stream") String stream, @Query("red_packet_id") String redPacketId ); + + /** + * 获取系统默认头像列表 + */ + @GET("/api/public/?service=Userhome.getDefaultAvatarList") + Observable>> getSystemUserAvatar(); + + /** + * 设置系统默认头像 + * @param id 头像id + */ + @GET("/api/public/?service=Userhome.setAvatar") + Observable> setSystemUserAvatar( + @Query("avatar_id") int id + ); } diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index 6e1313e02..e187257be 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -41,6 +41,7 @@ import com.yunbao.common.bean.RedPacketListBean; import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.UserAreaBean; +import com.yunbao.common.bean.UserAvatarSelectBean; import com.yunbao.common.bean.VipModel; import com.yunbao.common.bean.WishListGiftConfModel; import com.yunbao.common.bean.WishListModel; @@ -1795,7 +1796,52 @@ public class LiveNetManager { } }).isDisposed(); } - + public void getSystemUserAvatar(HttpCallback> callback) { + API.get().pdLiveApi(mContext) + .getSystemUserAvatar() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>>() { + @Override + public void accept(ResponseModel> objectResponseModel) throws Exception { + if (objectResponseModel.getData().getCode() == 0) { + callback.onSuccess(objectResponseModel.getData().getInfo()); + } else { + callback.onError(objectResponseModel.getData().getMsg()); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + } + public void setSystemUserAvatar(int id, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .setSystemUserAvatar(id) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel objectResponseModel) throws Exception { + if (objectResponseModel.getData().getCode() == 0) { + callback.onSuccess(objectResponseModel.getData().getMsg()); + } else { + callback.onError(objectResponseModel.getData().getMsg()); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + } /** * 直播间取消网络请求 */ diff --git a/common/src/main/res/values-en-rUS/string.xml b/common/src/main/res/values-en-rUS/string.xml index 73e2c8718..47e3da0db 100644 --- a/common/src/main/res/values-en-rUS/string.xml +++ b/common/src/main/res/values-en-rUS/string.xml @@ -1249,6 +1249,8 @@ Limited ride And limited avatar frame %s drew %s in the lucky red envelope number Red successfully + Select System Avatar + This function needs to be used to use it after lv.5, please work hard to upgrade ~ diff --git a/common/src/main/res/values-zh-rHK/strings.xml b/common/src/main/res/values-zh-rHK/strings.xml index 1c2e77cb7..514eb9059 100644 --- a/common/src/main/res/values-zh-rHK/strings.xml +++ b/common/src/main/res/values-zh-rHK/strings.xml @@ -1244,4 +1244,6 @@ " %s 在 好運紅包 中抽到了 %s" 数量 红包发布成功 + 選擇系統頭像 + 該功能需升至Lv.5后使用,請努力升級吧~ diff --git a/common/src/main/res/values-zh-rTW/strings.xml b/common/src/main/res/values-zh-rTW/strings.xml index 6d306b272..059b2de87 100644 --- a/common/src/main/res/values-zh-rTW/strings.xml +++ b/common/src/main/res/values-zh-rTW/strings.xml @@ -1243,4 +1243,6 @@ " %s 在 好運紅包 中抽到了 %s" 数量 红包发布成功 + 選擇系統頭像 + 該功能需升至Lv.5后使用,請努力升級吧~ diff --git a/common/src/main/res/values-zh/strings.xml b/common/src/main/res/values-zh/strings.xml index 94d89a69d..e72161809 100644 --- a/common/src/main/res/values-zh/strings.xml +++ b/common/src/main/res/values-zh/strings.xml @@ -1244,6 +1244,8 @@ " %s 在 好運紅包 中抽到了 %s" 数量 红包发布成功 + 選擇系統頭像 + 該功能需升至Lv.5后使用,請努力升級吧~ diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 6715ce5e3..95597dd4e 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1250,4 +1250,6 @@ Limited ride And limited avatar frame %s drew %s in the lucky red envelope number >Red successfully + Select System Avatar + This function needs to be used to use it after lv.5, please work hard to upgrade ~ diff --git a/live/src/main/res/drawable/bg_item_live_send_details_gift.xml b/live/src/main/res/drawable/bg_item_live_send_details_gift.xml index 07cd54a13..04103a50b 100644 --- a/live/src/main/res/drawable/bg_item_live_send_details_gift.xml +++ b/live/src/main/res/drawable/bg_item_live_send_details_gift.xml @@ -3,7 +3,7 @@ - + diff --git a/live/src/main/res/drawable/bg_item_live_send_details_gift_unselect.xml b/live/src/main/res/drawable/bg_item_live_send_details_gift_unselect.xml new file mode 100644 index 000000000..813f394d2 --- /dev/null +++ b/live/src/main/res/drawable/bg_item_live_send_details_gift_unselect.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/values-en/strings.xml b/live/src/main/res/values-en/strings.xml index 62effd87e..54e79e718 100644 --- a/live/src/main/res/values-en/strings.xml +++ b/live/src/main/res/values-en/strings.xml @@ -97,4 +97,6 @@ Give Obtain the letter and contact information + Select Avatar + Confirm \ No newline at end of file diff --git a/live/src/main/res/values/strings.xml b/live/src/main/res/values/strings.xml index 46d3ec1c6..8fa740d03 100644 --- a/live/src/main/res/values/strings.xml +++ b/live/src/main/res/values/strings.xml @@ -95,4 +95,6 @@ 贈送 會獲取到 的信件與聯繫方式 + 選擇頭像 + 確認使用 diff --git a/main/src/main/java/com/yunbao/main/activity/EditProfileActivity.java b/main/src/main/java/com/yunbao/main/activity/EditProfileActivity.java index 61df9bfd0..cad0cae1b 100644 --- a/main/src/main/java/com/yunbao/main/activity/EditProfileActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/EditProfileActivity.java @@ -36,6 +36,7 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.interfaces.ActivityResultCallback; import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.interfaces.ImageResultCallback; +import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.CityUtil; import com.yunbao.common.utils.DialogUitl; @@ -414,13 +415,19 @@ public class EditProfileActivity extends AbsActivity { private void editAvatar() { DialogUitl.showStringArrayDialog(mContext, new Integer[]{ - R.string.camera, R.string.alumb}, new DialogUitl.StringArrayDialogCallback() { + R.string.camera, R.string.alumb, R.string.me_edit_avatar_system}, new DialogUitl.StringArrayDialogCallback() { @Override public void onItemClick(String text, int tag) { + if (Integer.parseInt(IMLoginManager.get(mContext).getUserInfo().getLevel()) < 5 && tag != R.string.me_edit_avatar_system) { + ToastUtil.show(R.string.me_edit_avatar_system_tip); + return; + } if (tag == R.string.camera) { mImageUtil.getImageByCamera(); - } else { + } else if (tag == R.string.alumb) { mImageUtil.getImageByAlumb(); + } else { + RouteUtil.forwardUserAvatarSelect(); } } }); 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 08f4ebda3..af6ba92a1 100644 --- a/main/src/main/java/com/yunbao/main/activity/UserAvatarSelectActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/UserAvatarSelectActivity.java @@ -1,5 +1,6 @@ package com.yunbao.main.activity; +import android.view.View; import android.widget.TextView; import androidx.recyclerview.widget.GridLayoutManager; @@ -8,9 +9,16 @@ 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.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.RouteUtil; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.main.R; import com.yunbao.main.adapter.UserAvatarSelectAdapter; +import com.yunbao.main.event.EditProfileEvent; import java.util.ArrayList; import java.util.List; @@ -19,8 +27,8 @@ import java.util.List; public class UserAvatarSelectActivity extends AbsActivity { RecyclerView recyclerView; UserAvatarSelectAdapter adapter; - List list; TextView titleView; + View submit; @Override protected int getLayoutId() { @@ -30,24 +38,63 @@ public class UserAvatarSelectActivity extends AbsActivity { @Override protected void main() { super.main(); - titleView=findViewById(R.id.titleView); - titleView.setText("選擇頭像"); + titleView = findViewById(R.id.titleView); + submit = findViewById(R.id.send); + titleView.setText(R.string.me_edit_avatar_title); recyclerView = findViewById(R.id.recyclerView); adapter = new UserAvatarSelectAdapter(mContext); recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3)); recyclerView.setAdapter(adapter); - test(); + initData(); + + submit.setOnClickListener(v -> { + int id = adapter.getSelect(); + if (id > -1) { + adapter.setDef(id); + LiveNetManager.get(mContext) + .setSystemUserAvatar(id, new HttpCallback() { + @Override + public void onSuccess(String data) { + ToastUtil.show(data); + IMLoginManager.get(mContext).upDataUserInfo(); + Bus.get().post(new EditProfileEvent()); + submit.setBackgroundResource(R.drawable.bg_item_live_send_details_gift_unselect); + submit.setEnabled(false); + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + } + }); + adapter.setOnClickListener(new OnItemClickListener() { + @Override + public void onItemClick(Integer bean, int position) { + if (bean == position) { + submit.setBackgroundResource(R.drawable.bg_item_live_send_details_gift_unselect); + submit.setEnabled(false); + } else { + submit.setBackgroundResource(R.drawable.bg_item_live_send_details_gift); + submit.setEnabled(true); + } + } + }); } - 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); + private void initData() { + LiveNetManager.get(mContext) + .getSystemUserAvatar(new HttpCallback>() { + @Override + public void onSuccess(List data) { + adapter.setList(data); + } + + @Override + public void onError(String error) { + adapter.setList(new ArrayList<>()); + } + }); } } 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 12cf85782..6e79dc956 100644 --- a/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter.java @@ -11,20 +11,39 @@ import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.bean.UserAvatarSelectBean; import com.yunbao.common.custom.RatioRoundImageView; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.main.R; +import java.util.ArrayList; import java.util.List; public class UserAvatarSelectAdapter extends RecyclerView.Adapter { private Context mContext; - private List list; - private int select = 0; + private List list = new ArrayList<>(); + private OnItemClickListener onClickListener; + private int select = -1; + private int defId = -1; public void setList(List list) { this.list = list; notifyDataSetChanged(); } + public int getSelect() { + if (select == -1 && getItemCount() > 0) { + return list.get(0).getId(); + } + return select; + } + + public void setOnClickListener(OnItemClickListener onClickListener) { + this.onClickListener = onClickListener; + } + + public int getDefId() { + return defId; + } + public UserAvatarSelectAdapter(Context mContext) { this.mContext = mContext; } @@ -45,6 +64,10 @@ public class UserAvatarSelectAdapter extends RecyclerView.Adapter { select = (int) v.getTag(); notifyDataSetChanged(); + onClickListener.onItemClick(select, defId); }); } public void setData(UserAvatarSelectBean bean, int position) { - ImgLoader.display(itemView.getContext(), bean.getUrl(), avatar); - if (select == position) { + ImgLoader.display(itemView.getContext(), bean.getPath(), avatar); + if (select == -1 && bean.getChecked() == 1) { + select = bean.getId(); + defId = bean.getId(); + } + if (select == bean.getId()) { show.setVisibility(View.VISIBLE); hide.setVisibility(View.GONE); } else { show.setVisibility(View.INVISIBLE); hide.setVisibility(View.VISIBLE); } - itemView.setTag(position); + itemView.setTag(bean.getId()); } } 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 007d6649b..7b559dec5 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java @@ -42,13 +42,6 @@ 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_unselected.xml b/main/src/main/res/drawable/bg_user_avatar_select_unselected.xml index 85743b326..5f2e8b64c 100644 --- a/main/src/main/res/drawable/bg_user_avatar_select_unselected.xml +++ b/main/src/main/res/drawable/bg_user_avatar_select_unselected.xml @@ -1,5 +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 52c939dc4..23882e354 100644 --- a/main/src/main/res/layout/activity_user_select_avatar.xml +++ b/main/src/main/res/layout/activity_user_select_avatar.xml @@ -1,9 +1,10 @@ + android:background="#333333"> + app:layout_constraintTop_toBottomOf="@+id/include" + app:spanCount="3" + tools:itemCount="18" + tools:listitem="@layout/item_user_avatar_select" /> + + \ 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 index 38550d8e2..2f82ca3c7 100644 --- a/main/src/main/res/layout/item_user_avatar_select.xml +++ b/main/src/main/res/layout/item_user_avatar_select.xml @@ -1,6 +1,7 @@ + app:layout_constraintTop_toTopOf="parent" + tools:visibility="visible" /> \ No newline at end of file