新增头像选择界面

This commit is contained in:
zlzw 2023-07-19 15:35:30 +08:00
parent 8af231e526
commit dd2f3db16a
10 changed files with 194 additions and 10 deletions

View File

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

View File

@ -295,4 +295,12 @@ public class RouteUtil {
.withInt("id", id) .withInt("id", id)
.navigation(); .navigation();
} }
/**
* 系统头像选择
*/
public static void forwardUserAvatarSelect(){
ARouter.getInstance().build(PATH_SELECT_AVATAR)
.navigation();
}
} }

View File

@ -156,6 +156,8 @@
<activity <activity
android:name=".activity.RedPacketUsersActivity" android:name=".activity.RedPacketUsersActivity"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name=".activity.UserAvatarSelectActivity"
android:screenOrientation="portrait" />
</application> </application>
</manifest> </manifest>

View File

@ -1,18 +1,26 @@
package com.yunbao.main.activity; 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 androidx.recyclerview.widget.RecyclerView;
import com.alibaba.android.arouter.facade.annotation.Route; import com.alibaba.android.arouter.facade.annotation.Route;
import com.yunbao.common.activity.AbsActivity; import com.yunbao.common.activity.AbsActivity;
import com.yunbao.common.bean.UserAvatarSelectBean;
import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.utils.RouteUtil;
import com.yunbao.main.R; 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) @Route(path = RouteUtil.PATH_SELECT_AVATAR)
public class UserAvatarSelectActivity extends AbsActivity { public class UserAvatarSelectActivity extends AbsActivity {
RecyclerView recyclerView; RecyclerView recyclerView;
UserAvatarSelectAdapter adapter;
List<UserAvatarSelectBean> list;
TextView titleView;
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {
@ -22,6 +30,24 @@ public class UserAvatarSelectActivity extends AbsActivity {
@Override @Override
protected void main() { protected void main() {
super.main(); super.main();
titleView=findViewById(R.id.titleView);
titleView.setText("選擇頭像");
recyclerView = findViewById(R.id.recyclerView); 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);
} }
} }

View File

@ -1,32 +1,76 @@
package com.yunbao.main.adapter; package com.yunbao.main.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
public class UserAvatarSelectAdapter extends RecyclerView.Adapter<UserAvatarSelectAdapter.AvatarSelectViewHolder>{ 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<UserAvatarSelectAdapter.AvatarSelectViewHolder> {
private Context mContext;
private List<UserAvatarSelectBean> list;
private int select = 0;
public void setList(List<UserAvatarSelectBean> list) {
this.list = list;
notifyDataSetChanged();
}
public UserAvatarSelectAdapter(Context mContext) {
this.mContext = mContext;
}
@NonNull @NonNull
@Override @Override
public AvatarSelectViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 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 @Override
public void onBindViewHolder(@NonNull AvatarSelectViewHolder holder, int position) { public void onBindViewHolder(@NonNull AvatarSelectViewHolder holder, int position) {
holder.setData(list.get(position), position);
} }
@Override @Override
public int getItemCount() { 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) { public AvatarSelectViewHolder(@NonNull View itemView) {
super(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);
} }
} }

View File

@ -8,6 +8,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.main.R; import com.yunbao.main.R;
import com.yunbao.main.activity.RedPacketListActivity; 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); 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){ public void setCurPosition(int position){

View File

@ -0,0 +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="#FFC300"/>
</shape>

View File

@ -0,0 +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"/>
</shape>

View File

@ -2,6 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#333333"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<include <include

View File

@ -1,6 +1,52 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">
<View
android:id="@+id/showCover"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="@drawable/bg_user_avatar_select_selected"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.yunbao.common.custom.RatioRoundImageView
android:id="@+id/avatar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="2dp"
android:layout_marginBottom="2dp"
android:src="@mipmap/icon_green_science"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:ri_ratio="0.5"
app:riv_oval="true" />
<View
android:id="@+id/hideCover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="2dp"
android:layout_marginBottom="2dp"
android:background="@drawable/bg_user_avatar_select_unselected"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>