From e0b69be2d43e9809e3fbc9ee3f2a7bdc23357960 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 24 Nov 2022 15:34:51 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E9=9A=8F=E6=9C=BAPk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/adapter/RandomPkRecyclerAdapter.java | 89 +++++++++++-- .../live/dialog/RandomPkDialogFragment.java | 118 +++++++++++++++++- .../res/drawable/bg_item_random_pk_type_2.xml | 9 ++ .../layout/dialog_live_random_pk_function.xml | 27 ++-- .../main/res/layout/item_random_pk_info.xml | 25 ++-- .../src/main/res/layout/item_random_pk_rv.xml | 6 +- .../res/layout/item_random_pk_rv_head.xml | 4 +- .../res/layout/item_random_pk_rv_search.xml | 24 ++-- 8 files changed, 253 insertions(+), 49 deletions(-) create mode 100644 live/src/main/res/drawable/bg_item_random_pk_type_2.xml diff --git a/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java index 6206619c9..47cede1f8 100644 --- a/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java @@ -1,56 +1,121 @@ package com.yunbao.live.adapter; import android.content.Context; +import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import com.makeramen.roundedimageview.RoundedImageView; import com.yunbao.common.adapter.RefreshAdapter; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.live.R; import com.yunbao.live.bean.RandomPkBean; import java.util.ArrayList; import java.util.List; public class RandomPkRecyclerAdapter extends RefreshAdapter { - private List list=new ArrayList<>(); + private static final int HEAD = 0; + private static final int ITEM = 2; public RandomPkRecyclerAdapter(Context context) { super(context); } - @Override - public void setList(List list) { - this.list = list; - } @NonNull @Override - public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return null; + public HeadViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + if (viewType == HEAD) { + return new HeadViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_random_pk_rv_head, parent, false)); + } + return new ItemViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_random_pk_rv, parent, false)); } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - + if (getItemViewType(position) == ITEM) { + ((HeadViewHolder) holder).setData(mList.get(position-1)); + } } @Override public int getItemCount() { - return 0; + return mList.size(); } @Override public int getItemViewType(int position) { - return super.getItemViewType(position); + if (position == 0) { + return HEAD; + } + return ITEM; } - public class ViewHolder extends RecyclerView.ViewHolder{ + private class HeadViewHolder extends RecyclerView.ViewHolder { - public ViewHolder(@NonNull View itemView) { + public HeadViewHolder(@NonNull View itemView) { super(itemView); } + + public void setData(RandomPkBean bean) { + + } + } + + + public class ItemViewHolder extends HeadViewHolder { + private TextView mNum; + private TextView mName; + private TextView mId; + private TextView mStatus; + private RoundedImageView mAvatar; + private ImageView mPkStatus; + private ImageView mFollow; + + public ItemViewHolder(@NonNull View itemView) { + super(itemView); + mNum = itemView.findViewById(R.id.item_id); + mName = itemView.findViewById(R.id.item_name); + mId = itemView.findViewById(R.id.item_uid); + mStatus = itemView.findViewById(R.id.item_status); + mAvatar = itemView.findViewById(R.id.item_avatar); + mPkStatus = itemView.findViewById(R.id.item_pk); + mFollow = itemView.findViewById(R.id.item_follow); + } + + @Override + public void setData(RandomPkBean bean) { + super.setData(bean); + int position = getAbsoluteAdapterPosition(); + mNum.setText((position) + ""); + if (position % 2 == 0) { + itemView.setBackgroundResource(R.drawable.bg_item_random_pk_type_1); + } else { + itemView.setBackgroundResource(R.drawable.bg_item_random_pk_type_2); + } + ImgLoader.display(mContext, bean.getAvatar(), mAvatar); + mName.setText(bean.getUserNiceName()); + mId.setText(bean.getId()); + mStatus.setText(bean.getStatus()); + if (bean.isPkIng()) { + ImgLoader.display(mContext, R.mipmap.ic_random_pk_pk, mPkStatus); + } else { + ImgLoader.display(mContext, R.mipmap.ic_random_pk_pk_unselect, mPkStatus); + } + if (bean.isFollow()) { + ImgLoader.display(mContext, R.mipmap.ic_random_pk_like, mFollow); + } else { + ImgLoader.display(mContext, R.mipmap.ic_random_pk_like_unselect, mFollow); + } + } } } diff --git a/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java index 373da2a29..87ca3a9c1 100644 --- a/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java @@ -1,33 +1,54 @@ package com.yunbao.live.dialog; import android.os.Bundle; +import android.util.Log; import android.view.Gravity; +import android.view.KeyEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; +import android.widget.EditText; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; +import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.tabs.TabLayout; +import com.lzf.easyfloat.interfaces.OnPermissionResult; +import com.lzf.easyfloat.permission.PermissionUtils; +import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.custom.CommonRefreshView; import com.yunbao.common.dialog.AbsDialogFragment; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.live.R; +import com.yunbao.live.adapter.RandomPkRecyclerAdapter; +import com.yunbao.live.bean.RandomPkBean; + +import java.util.ArrayList; +import java.util.List; /** * 随机PK */ public class RandomPkDialogFragment extends AbsDialogFragment { + private static final String TAG = "随机PK"; private TabLayout tabLayout; private View reset; private CommonRefreshView mRecyclerView; private View mPkInfoLayout; + private View mSearchLayout; private View mPkBtn; private TextView mPkBtnTitle; private TextView mPkBtnDesc; - private SwitchCompat mRandomPkSwitch; + private ImageView mRandomPkSwitch; + private EditText mSearch; + private ImageView mClear; + private RandomPkRecyclerAdapter adapter; @Override protected int getLayoutId() { @@ -67,10 +88,92 @@ public class RandomPkDialogFragment extends AbsDialogFragment { reset = findViewById(R.id.menu_reset); mRecyclerView = (CommonRefreshView) findViewById(R.id.random_container_view); mPkInfoLayout = findViewById(R.id.layout_random_pk_info); + mSearchLayout = findViewById(R.id.random_pk_search_layout); mPkBtn = findViewById(R.id.random_pk_info_btn); mPkBtnTitle = (TextView) findViewById(R.id.random_pk_btn_title); mPkBtnDesc = (TextView) findViewById(R.id.random_pk_btn_desc); - mRandomPkSwitch = (SwitchCompat) findViewById(R.id.live_random_pk_switch); + mRandomPkSwitch = (ImageView) findViewById(R.id.live_random_pk_switch); + mSearch = (EditText) findViewById(R.id.search_edit); + mClear = (ImageView) findViewById(R.id.search_clear); + mClear.setOnClickListener(v -> { + mSearch.setText(""); + }); + mRandomPkSwitch.setTag(true); + mRandomPkSwitch.setOnClickListener(v -> { + if (mRandomPkSwitch.getTag() != null && (boolean) mRandomPkSwitch.getTag()) { + ImgLoader.display(mContext, com.yunbao.common.R.mipmap.special_icon_off, mRandomPkSwitch); + mRandomPkSwitch.setTag(false); + } else { + ImgLoader.display(mContext, com.yunbao.common.R.mipmap.special_icon_on, mRandomPkSwitch); + mRandomPkSwitch.setTag(true); + } + }); + mSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + return false; + } + }); + + initRecycler(); + } + + private void initRecycler() { + adapter = new RandomPkRecyclerAdapter(mContext); + mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); + mRecyclerView.setDataHelper(new CommonRefreshView.DataHelper() { + @Override + public RefreshAdapter getAdapter() { + return adapter; + } + + @Override + public void loadData(int p, HttpCallback callback) { + callback.onSuccess(0, "", new String[0]); + } + + @Override + public List processData(String[] info) { + Log.i(TAG, "processData: 获取数据成功"); + return createTmpData(); + } + + @Override + public void onRefreshSuccess(List list, int listCount) { + + } + + @Override + public void onRefreshFailure() { + + } + + @Override + public void onLoadMoreSuccess(List loadItemList, int loadItemCount) { + + } + + @Override + public void onLoadMoreFailure() { + + } + }); + mRecyclerView.initData(); + } + + private List createTmpData() { + List list = new ArrayList<>(); + for (int i = 1; i < 10; i++) { + RandomPkBean bean = new RandomPkBean(); + bean.setId(i + ""); + bean.setAvatar("https://ceshi.yaoulive.com/default.jpg"); + bean.setUserNiceName("测试样本" + i); + bean.setStatus(i % 3 == 0 ? "PK中" : "空闲"); + bean.setPkIng(i % 3 == 0); + bean.setFollow(i % 2 == 0); + list.add(bean); + } + return list; } private void initData() { @@ -94,12 +197,21 @@ public class RandomPkDialogFragment extends AbsDialogFragment { @Override public void onTabSelected(TabLayout.Tab tab) { if (tab.getTag() != null) { + mPkInfoLayout.setVisibility(View.GONE); + mRecyclerView.setVisibility(View.GONE); + mSearchLayout.setVisibility(View.INVISIBLE); switch ((int) tab.getTag()) { case 1: mPkInfoLayout.setVisibility(View.VISIBLE); - mRecyclerView.setVisibility(View.GONE); break; case 2: + mSearchLayout.setVisibility(View.VISIBLE); + mRecyclerView.setVisibility(View.VISIBLE); + mRecyclerView.initData(); + break; + case 3: + mRecyclerView.setVisibility(View.VISIBLE); + mRecyclerView.initData(); break; } } diff --git a/live/src/main/res/drawable/bg_item_random_pk_type_2.xml b/live/src/main/res/drawable/bg_item_random_pk_type_2.xml new file mode 100644 index 000000000..61fcb5aa2 --- /dev/null +++ b/live/src/main/res/drawable/bg_item_random_pk_type_2.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/dialog_live_random_pk_function.xml b/live/src/main/res/layout/dialog_live_random_pk_function.xml index 3035cbbca..d7ce86bc8 100644 --- a/live/src/main/res/layout/dialog_live_random_pk_function.xml +++ b/live/src/main/res/layout/dialog_live_random_pk_function.xml @@ -2,13 +2,13 @@ + android:layout_height="wrap_content" + android:background="@drawable/bg_live_tota"> + android:layout_height="wrap_content" + android:visibility="visible" /> + + + + android:layout_weight="1" + android:visibility="gone"> diff --git a/live/src/main/res/layout/item_random_pk_info.xml b/live/src/main/res/layout/item_random_pk_info.xml index 31aa12d9c..b1fa08829 100644 --- a/live/src/main/res/layout/item_random_pk_info.xml +++ b/live/src/main/res/layout/item_random_pk_info.xml @@ -1,15 +1,17 @@ + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="visible"> + android:textSize="10sp" + android:visibility="gone" /> - \ No newline at end of file diff --git a/live/src/main/res/layout/item_random_pk_rv.xml b/live/src/main/res/layout/item_random_pk_rv.xml index da3ab4643..6aa21c4c6 100644 --- a/live/src/main/res/layout/item_random_pk_rv.xml +++ b/live/src/main/res/layout/item_random_pk_rv.xml @@ -2,7 +2,9 @@ @@ -20,7 +22,7 @@ @@ -17,7 +19,7 @@ diff --git a/live/src/main/res/layout/item_random_pk_rv_search.xml b/live/src/main/res/layout/item_random_pk_rv_search.xml index bfe305ca9..d025fa67d 100644 --- a/live/src/main/res/layout/item_random_pk_rv_search.xml +++ b/live/src/main/res/layout/item_random_pk_rv_search.xml @@ -2,32 +2,36 @@ + android:visibility="visible"> + android:textColorHint="#80FFFFFF" + android:inputType="textPersonName" + android:textColor="#FFFFFF" />