新增头像选择界面

This commit is contained in:
zlzw 2023-07-19 18:30:32 +08:00
parent 3108c898c2
commit 736592b4e1
19 changed files with 249 additions and 56 deletions

View File

@ -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;
}
}

View File

@ -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<ResponseModel<List<UserAvatarSelectBean>>> getSystemUserAvatar();
/**
* 设置系统默认头像
* @param id 头像id
*/
@GET("/api/public/?service=Userhome.setAvatar")
Observable<ResponseModel<Object>> setSystemUserAvatar(
@Query("avatar_id") int id
);
}

View File

@ -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<List<UserAvatarSelectBean>> callback) {
API.get().pdLiveApi(mContext)
.getSystemUserAvatar()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ResponseModel<List<UserAvatarSelectBean>>>() {
@Override
public void accept(ResponseModel<List<UserAvatarSelectBean>> objectResponseModel) throws Exception {
if (objectResponseModel.getData().getCode() == 0) {
callback.onSuccess(objectResponseModel.getData().getInfo());
} else {
callback.onError(objectResponseModel.getData().getMsg());
}
}
}, new Consumer<Throwable>() {
@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<String> callback) {
API.get().pdLiveApi(mContext)
.setSystemUserAvatar(id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ResponseModel<Object>>() {
@Override
public void accept(ResponseModel<Object> objectResponseModel) throws Exception {
if (objectResponseModel.getData().getCode() == 0) {
callback.onSuccess(objectResponseModel.getData().getMsg());
} else {
callback.onError(objectResponseModel.getData().getMsg());
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (callback != null) {
callback.onError(mContext.getString(R.string.net_error));
}
}
}).isDisposed();
}
/**
* 直播间取消网络请求
*/

View File

@ -1249,6 +1249,8 @@ Limited ride And limited avatar frame</string>
<string name="lucky_red_envelope">%s drew %s in the lucky red envelope</string>
<string name="lucky_red_envelope_amount">number</string>
<string name="red_envelope_released_successfully">Red successfully</string>
<string name="me_edit_avatar_system">Select System Avatar</string>
<string name="me_edit_avatar_system_tip">This function needs to be used to use it after lv.5, please work hard to upgrade ~</string>
</resources>

View File

@ -1244,4 +1244,6 @@
<string name="lucky_red_envelope">" %s 在 好運紅包 中抽到了 %s"</string>
<string name="lucky_red_envelope_amount">数量</string>
<string name="red_envelope_released_successfully">红包发布成功</string>
<string name="me_edit_avatar_system">選擇系統頭像</string>
<string name="me_edit_avatar_system_tip">該功能需升至Lv.5后使用,請努力升級吧~</string>
</resources>

View File

@ -1243,4 +1243,6 @@
<string name="lucky_red_envelope">" %s 在 好運紅包 中抽到了 %s"</string>
<string name="lucky_red_envelope_amount">数量</string>
<string name="red_envelope_released_successfully">红包发布成功</string>
<string name="me_edit_avatar_system">選擇系統頭像</string>
<string name="me_edit_avatar_system_tip">該功能需升至Lv.5后使用,請努力升級吧~</string>
</resources>

View File

@ -1244,6 +1244,8 @@
<string name="lucky_red_envelope">" %s 在 好運紅包 中抽到了 %s"</string>
<string name="lucky_red_envelope_amount">数量</string>
<string name="red_envelope_released_successfully">红包发布成功</string>
<string name="me_edit_avatar_system">選擇系統頭像</string>
<string name="me_edit_avatar_system_tip">該功能需升至Lv.5后使用,請努力升級吧~</string>
</resources>

View File

@ -1250,4 +1250,6 @@ Limited ride And limited avatar frame</string>
<string name="lucky_red_envelope">%s drew %s in the lucky red envelope</string>
<string name="lucky_red_envelope_amount">number</string>
<string name="red_envelope_released_successfully">>Red successfully</string>
<string name="me_edit_avatar_system">Select System Avatar</string>
<string name="me_edit_avatar_system_tip">This function needs to be used to use it after lv.5, please work hard to upgrade ~</string>
</resources>

View File

@ -3,7 +3,7 @@
<item android:width="96dp" android:height="22dp">
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#00000000" />
<gradient android:type="linear" android:useLevel="true" android:startColor="#FFA900" android:endColor="#FFC300" android:angle="270" />
<gradient android:type="linear" android:useLevel="true" android:startColor="#FFC300" android:endColor="#FFA900" android:angle="225" />
<corners android:topLeftRadius="22dp" android:topRightRadius="22dp" android:bottomLeftRadius="22dp" android:bottomRightRadius="22dp" />
</shape>
</item>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:width="96dp" android:height="22dp">
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#00000000" />
<gradient android:type="linear" android:useLevel="true" android:startColor="#E1E1E1" android:endColor="#E1E1E1" android:angle="270" />
<corners android:topLeftRadius="22dp" android:topRightRadius="22dp" android:bottomLeftRadius="22dp" android:bottomRightRadius="22dp" />
</shape>
</item>
</selector>

View File

@ -97,4 +97,6 @@
<string name="live_details_sned_gift_text1">Give</string>
<string name="live_details_sned_gift_text2">Obtain the</string>
<string name="live_details_sned_gift_text3">letter and contact information</string>
<string name="me_edit_avatar_title">Select Avatar</string>
<string name="me_edit_avatar_submit">Confirm</string>
</resources>

View File

@ -95,4 +95,6 @@
<string name="live_details_sned_gift_text1">贈送</string>
<string name="live_details_sned_gift_text2">會獲取到</string>
<string name="live_details_sned_gift_text3">的信件與聯繫方式</string>
<string name="me_edit_avatar_title">選擇頭像</string>
<string name="me_edit_avatar_submit">確認使用</string>
</resources>

View File

@ -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();
}
}
});

View File

@ -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<UserAvatarSelectBean> list;
TextView titleView;
View submit;
@Override
protected int getLayoutId() {
@ -31,23 +39,62 @@ public class UserAvatarSelectActivity extends AbsActivity {
protected void main() {
super.main();
titleView = findViewById(R.id.titleView);
titleView.setText("選擇頭像");
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<String>() {
@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);
}
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);
@Override
public void onError(String error) {
ToastUtil.show(error);
}
adapter.setList(list);
});
}
});
adapter.setOnClickListener(new OnItemClickListener<Integer>() {
@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 initData() {
LiveNetManager.get(mContext)
.getSystemUserAvatar(new HttpCallback<List<UserAvatarSelectBean>>() {
@Override
public void onSuccess(List<UserAvatarSelectBean> data) {
adapter.setList(data);
}
@Override
public void onError(String error) {
adapter.setList(new ArrayList<>());
}
});
}
}

View File

@ -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<UserAvatarSelectAdapter.AvatarSelectViewHolder> {
private Context mContext;
private List<UserAvatarSelectBean> list;
private int select = 0;
private List<UserAvatarSelectBean> list = new ArrayList<>();
private OnItemClickListener<Integer> onClickListener;
private int select = -1;
private int defId = -1;
public void setList(List<UserAvatarSelectBean> list) {
this.list = list;
notifyDataSetChanged();
}
public int getSelect() {
if (select == -1 && getItemCount() > 0) {
return list.get(0).getId();
}
return select;
}
public void setOnClickListener(OnItemClickListener<Integer> 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<UserAvatarSele
return list.size();
}
public void setDef(int id) {
this.defId = id;
}
public class AvatarSelectViewHolder extends RecyclerView.ViewHolder {
private View hide;
private View show;
@ -58,19 +81,24 @@ public class UserAvatarSelectAdapter extends RecyclerView.Adapter<UserAvatarSele
itemView.setOnClickListener(v -> {
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());
}
}

View File

@ -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){

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#80000000"/>
<solid android:color="#99000000"/>
</shape>

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#333333"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:background="#333333">
<include
android:id="@+id/include"
@ -16,8 +17,31 @@
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="60dp"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintBottom_toTopOf="@+id/send"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/include" />
app:layout_constraintTop_toBottomOf="@+id/include"
app:spanCount="3"
tools:itemCount="18"
tools:listitem="@layout/item_user_avatar_select" />
<TextView
android:id="@+id/send"
android:layout_width="185dp"
android:layout_height="51dp"
android:layout_marginBottom="72dp"
android:background="@drawable/bg_item_live_send_details_gift_unselect"
android:gravity="center"
android:paddingStart="10dp"
android:paddingTop="4dp"
android:paddingEnd="10dp"
android:paddingBottom="4dp"
android:text="@string/me_edit_avatar_submit"
android:textColor="#FFF"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_marginStart="22dp"
@ -47,6 +48,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>