update 随机Pk

This commit is contained in:
zlzw 2022-11-24 15:34:51 +08:00
parent 9b17c1225a
commit e0b69be2d4
8 changed files with 253 additions and 49 deletions

View File

@ -1,56 +1,121 @@
package com.yunbao.live.adapter; package com.yunbao.live.adapter;
import android.content.Context; import android.content.Context;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.makeramen.roundedimageview.RoundedImageView;
import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.adapter.RefreshAdapter;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.live.R;
import com.yunbao.live.bean.RandomPkBean; import com.yunbao.live.bean.RandomPkBean;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class RandomPkRecyclerAdapter extends RefreshAdapter<RandomPkBean> { public class RandomPkRecyclerAdapter extends RefreshAdapter<RandomPkBean> {
private List<RandomPkBean> list=new ArrayList<>(); private static final int HEAD = 0;
private static final int ITEM = 2;
public RandomPkRecyclerAdapter(Context context) { public RandomPkRecyclerAdapter(Context context) {
super(context); super(context);
} }
@Override
public void setList(List<RandomPkBean> list) {
this.list = list;
}
@NonNull @NonNull
@Override @Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public HeadViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null; 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 @Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (getItemViewType(position) == ITEM) {
((HeadViewHolder) holder).setData(mList.get(position-1));
}
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return 0; return mList.size();
} }
@Override @Override
public int getItemViewType(int position) { 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); 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);
}
}
} }
} }

View File

@ -1,33 +1,54 @@
package com.yunbao.live.dialog; package com.yunbao.live.dialog;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat; import androidx.appcompat.widget.SwitchCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.tabs.TabLayout; 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.custom.CommonRefreshView;
import com.yunbao.common.dialog.AbsDialogFragment; 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.R;
import com.yunbao.live.adapter.RandomPkRecyclerAdapter;
import com.yunbao.live.bean.RandomPkBean;
import java.util.ArrayList;
import java.util.List;
/** /**
* 随机PK * 随机PK
*/ */
public class RandomPkDialogFragment extends AbsDialogFragment { public class RandomPkDialogFragment extends AbsDialogFragment {
private static final String TAG = "随机PK";
private TabLayout tabLayout; private TabLayout tabLayout;
private View reset; private View reset;
private CommonRefreshView mRecyclerView; private CommonRefreshView mRecyclerView;
private View mPkInfoLayout; private View mPkInfoLayout;
private View mSearchLayout;
private View mPkBtn; private View mPkBtn;
private TextView mPkBtnTitle; private TextView mPkBtnTitle;
private TextView mPkBtnDesc; private TextView mPkBtnDesc;
private SwitchCompat mRandomPkSwitch; private ImageView mRandomPkSwitch;
private EditText mSearch;
private ImageView mClear;
private RandomPkRecyclerAdapter adapter;
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {
@ -67,10 +88,92 @@ public class RandomPkDialogFragment extends AbsDialogFragment {
reset = findViewById(R.id.menu_reset); reset = findViewById(R.id.menu_reset);
mRecyclerView = (CommonRefreshView) findViewById(R.id.random_container_view); mRecyclerView = (CommonRefreshView) findViewById(R.id.random_container_view);
mPkInfoLayout = findViewById(R.id.layout_random_pk_info); mPkInfoLayout = findViewById(R.id.layout_random_pk_info);
mSearchLayout = findViewById(R.id.random_pk_search_layout);
mPkBtn = findViewById(R.id.random_pk_info_btn); mPkBtn = findViewById(R.id.random_pk_info_btn);
mPkBtnTitle = (TextView) findViewById(R.id.random_pk_btn_title); mPkBtnTitle = (TextView) findViewById(R.id.random_pk_btn_title);
mPkBtnDesc = (TextView) findViewById(R.id.random_pk_btn_desc); 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<RandomPkBean>() {
@Override
public RefreshAdapter<RandomPkBean> getAdapter() {
return adapter;
}
@Override
public void loadData(int p, HttpCallback callback) {
callback.onSuccess(0, "", new String[0]);
}
@Override
public List<RandomPkBean> processData(String[] info) {
Log.i(TAG, "processData: 获取数据成功");
return createTmpData();
}
@Override
public void onRefreshSuccess(List<RandomPkBean> list, int listCount) {
}
@Override
public void onRefreshFailure() {
}
@Override
public void onLoadMoreSuccess(List<RandomPkBean> loadItemList, int loadItemCount) {
}
@Override
public void onLoadMoreFailure() {
}
});
mRecyclerView.initData();
}
private List<RandomPkBean> createTmpData() {
List<RandomPkBean> 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() { private void initData() {
@ -94,12 +197,21 @@ public class RandomPkDialogFragment extends AbsDialogFragment {
@Override @Override
public void onTabSelected(TabLayout.Tab tab) { public void onTabSelected(TabLayout.Tab tab) {
if (tab.getTag() != null) { if (tab.getTag() != null) {
mPkInfoLayout.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.GONE);
mSearchLayout.setVisibility(View.INVISIBLE);
switch ((int) tab.getTag()) { switch ((int) tab.getTag()) {
case 1: case 1:
mPkInfoLayout.setVisibility(View.VISIBLE); mPkInfoLayout.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
break; break;
case 2: case 2:
mSearchLayout.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.VISIBLE);
mRecyclerView.initData();
break;
case 3:
mRecyclerView.setVisibility(View.VISIBLE);
mRecyclerView.initData();
break; break;
} }
} }

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:width="355dp" android:height="36dp">
<shape android:shape="rectangle">
<solid android:color="#000000" />
<corners android:radius="8dp" />
</shape>
</item>
</selector>

View File

@ -2,13 +2,13 @@
<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" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:background="@drawable/bg_live_tota2" android:layout_height="wrap_content"
android:layout_height="wrap_content"> android:background="@drawable/bg_live_tota">
<LinearLayout <LinearLayout
android:id="@+id/random_menu_layout" android:id="@+id/random_menu_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:visibility="visible" android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
@ -19,8 +19,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="45dp" android:layout_height="45dp"
android:gravity="center"
android:layout_marginBottom="5dp" android:layout_marginBottom="5dp"
android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
@ -49,9 +49,9 @@
android:id="@+id/menu_tab" android:id="@+id/menu_tab"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:tabIndicator="@drawable/random_pk_shape_tab_indicator"
app:tabIndicatorColor="#F6F7FB" app:tabIndicatorColor="#F6F7FB"
app:tabIndicatorFullWidth="false" app:tabIndicatorFullWidth="false"
app:tabIndicator="@drawable/random_pk_shape_tab_indicator"
app:tabMaxWidth="100dp" app:tabMaxWidth="100dp"
app:tabMode="scrollable" app:tabMode="scrollable"
app:tabSelectedTextColor="#F6F7FB" app:tabSelectedTextColor="#F6F7FB"
@ -89,17 +89,26 @@
</LinearLayout> </LinearLayout>
<include <include
android:visibility="visible"
layout="@layout/item_random_pk_info" layout="@layout/item_random_pk_info"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:visibility="visible" />
<include
layout="@layout/item_random_pk_rv_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:visibility="gone" />
<com.yunbao.common.custom.CommonRefreshView <com.yunbao.common.custom.CommonRefreshView
android:id="@+id/random_container_view" android:id="@+id/random_container_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="216dp" android:layout_height="216dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:layout_weight="1" > android:layout_weight="1"
android:visibility="gone">
</com.yunbao.common.custom.CommonRefreshView> </com.yunbao.common.custom.CommonRefreshView>
</LinearLayout> </LinearLayout>

View File

@ -1,15 +1,17 @@
<?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" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:visibility="visible"
android:id="@+id/layout_random_pk_info" android:id="@+id/layout_random_pk_info"
android:layout_height="wrap_content"> android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible">
<LinearLayout <LinearLayout
android:id="@+id/linearLayout" android:id="@+id/linearLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:background="@drawable/background_7792d0" android:background="@drawable/background_7792d0"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -104,9 +106,9 @@
android:id="@+id/random_pk_btn_desc" android:id="@+id/random_pk_btn_desc"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="10sp" /> android:textSize="10sp"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
<TextView <TextView
@ -115,21 +117,20 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center" android:gravity="center"
android:text="@string/random_pk_info_switch" android:text="@string/random_pk_info_switch"
android:textColor="#9A9A9A"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/live_random_pk_switch" app:layout_constraintEnd_toStartOf="@+id/live_random_pk_switch"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.SwitchCompat <ImageView
android:id="@+id/live_random_pk_switch" android:id="@+id/live_random_pk_switch"
android:layout_width="wrap_content" android:layout_width="46.67dp"
android:layout_height="wrap_content" android:layout_height="23.33dp"
android:background="@drawable/bg_live_random_pk_info_switch" android:src="@mipmap/special_icon_off"
android:checked="true"
android:thumb="@drawable/bg_live_random_pk_info_switch_thumb"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_goneMarginEnd="10dp"
app:track="@drawable/bg_live_random_pk_info_switch_track" /> app:track="@drawable/bg_live_random_pk_info_switch_track" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,7 +2,9 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="36dp" android:layout_height="52dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:background="@drawable/bg_item_random_pk_type_1" android:background="@drawable/bg_item_random_pk_type_1"
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
@ -20,7 +22,7 @@
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1.5" android:layout_weight="1.4"
android:orientation="horizontal"> android:orientation="horizontal">
<com.makeramen.roundedimageview.RoundedImageView <com.makeramen.roundedimageview.RoundedImageView

View File

@ -2,6 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="36dp" android:layout_height="36dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:background="@drawable/bg_item_random_pk_type_1" android:background="@drawable/bg_item_random_pk_type_1"
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
@ -17,7 +19,7 @@
<TextView <TextView
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1.2"
android:text="头像&amp;昵称" android:text="头像&amp;昵称"
android:textColor="#B3FFFFFF" /> android:textColor="#B3FFFFFF" />

View File

@ -2,32 +2,36 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:visibility="visible" android:layout_height="32dp"
android:id="@+id/random_pk_search_layout"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:background="@drawable/bg_random_pk_rv_search" android:background="@drawable/bg_random_pk_rv_search"
android:layout_height="32dp"> android:visibility="visible">
<ImageView <ImageView
android:id="@+id/search_icon" android:id="@+id/search_icon"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="0.1"
android:layout_height="18dp" android:layout_height="18dp"
android:layout_marginStart="10dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginStart="10dp"
android:layout_weight="0.1"
app:srcCompat="@mipmap/ic_random_pk_search" /> app:srcCompat="@mipmap/ic_random_pk_search" />
<EditText <EditText
android:id="@+id/search_edit" android:id="@+id/search_edit"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginStart="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:background="@null"
android:ems="10" android:ems="10"
android:inputType="textPersonName"
android:hint="@string/random_pk_search_hint" android:hint="@string/random_pk_search_hint"
android:textColor="#FFFFFF" android:textColorHint="#80FFFFFF"
android:background="@null" /> android:inputType="textPersonName"
android:textColor="#FFFFFF" />
<ImageView <ImageView
android:id="@+id/search_clear" android:id="@+id/search_clear"