diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 6ef053c4a..327305f16 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -392,8 +392,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl break; case Constants.LIVE_FUNC_LINK_MIC://连麦 if (isDRPK != 1) { - openLinkMicAnchorWindow(false); - //openFreePkWindow(); + //openLinkMicAnchorWindow(false); + openFreePkWindow(); } else { ToastUtil.show("您已在PK中"); } 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 ffacaeae0..6dbcd5701 100644 --- a/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java @@ -13,7 +13,10 @@ import androidx.recyclerview.widget.RecyclerView; import com.makeramen.roundedimageview.RoundedImageView; import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.bean.RandomPkUserBean; +import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.R; @@ -43,9 +46,9 @@ public class RandomPkRecyclerAdapter extends RefreshAdapter { @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (getItemViewType(position) == ITEM) { - ((ItemViewHolder) holder).setData(mList.get(position-1)); - }else{ - ((HeadViewHolder) holder).setData(mList.get(position)); + ((ItemViewHolder) holder).setData(mList.get(position ), position ); + } else { + ((HeadViewHolder) holder).setData(mList.get(position), position); } } @@ -69,7 +72,7 @@ public class RandomPkRecyclerAdapter extends RefreshAdapter { super(itemView); } - public void setData(RandomPkUserBean bean) { + public void setData(RandomPkUserBean bean, int position) { } } @@ -103,12 +106,33 @@ public class RandomPkRecyclerAdapter extends RefreshAdapter { ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() ); }); + mFollow.setOnClickListener(v -> { + RandomPkUserBean bean = (RandomPkUserBean) itemView.getTag(); + LiveNetManager.get(mContext).setAttents(bean.getId(), new HttpCallback() { + @Override + public void onSuccess(SetAttentsModel data) { + bean.setAttention(data.getIsattent()); + if ("1" .equals(data.getIsattent())) { + ToastUtil.show(R.string.following); + mOnItemClickListener.onItemClick(bean, 1); + } else { + ToastUtil.show(R.string.unfollow_cancel); + mOnItemClickListener.onItemClick(bean, 0); + } + + } + + @Override + public void onError(String error) { + + } + }); + }); } @Override - public void setData(RandomPkUserBean bean) { - super.setData(bean); - int position = getAbsoluteAdapterPosition(); + public void setData(RandomPkUserBean bean, int position) { + super.setData(bean, position); if (bean == null) { return; } diff --git a/live/src/main/java/com/yunbao/live/bean/LivePkBean.java b/live/src/main/java/com/yunbao/live/bean/LivePkBean.java index 509f66921..14dde6181 100644 --- a/live/src/main/java/com/yunbao/live/bean/LivePkBean.java +++ b/live/src/main/java/com/yunbao/live/bean/LivePkBean.java @@ -3,6 +3,7 @@ package com.yunbao.live.bean; import android.text.TextUtils; import com.alibaba.fastjson.annotation.JSONField; +import com.yunbao.common.utils.StringUtil; /** * Created by cxf on 2018/11/15. @@ -19,6 +20,20 @@ public class LivePkBean { private int level; private int levelAnchor; private int sex; + private String attention; + + @JSONField(name = "isattention") + public String getAttention() { + if(StringUtil.isEmpty(attention)){ + attention="0"; + } + return attention; + } + + @JSONField(name = "isattention") + public void setAttention(String attention) { + this.attention = attention; + } public String getUid() { return uid; @@ -56,6 +71,9 @@ public class LivePkBean { @JSONField(name = "pkuid") public String getPkUid() { + if (pkUid == null) { + pkUid = "0"; + } return pkUid; } @@ -94,7 +112,7 @@ public class LivePkBean { * 是否在连麦中 */ public boolean isLinkMic() { - return !TextUtils.isEmpty(pkUid) && !"0".equals(pkUid); + return !TextUtils.isEmpty(pkUid) && !"0" .equals(pkUid); } } diff --git a/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java index bb82dda15..5fbec0e06 100644 --- a/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java @@ -1,9 +1,6 @@ package com.yunbao.live.dialog; -import android.app.Dialog; import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; @@ -13,7 +10,6 @@ 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.recyclerview.widget.LinearLayoutManager; @@ -21,18 +17,14 @@ import androidx.recyclerview.widget.LinearLayoutManager; import com.alibaba.fastjson.JSON; import com.google.android.material.tabs.TabLayout; import com.yunbao.common.adapter.RefreshAdapter; -import com.yunbao.common.bean.HttpCallbackModel; import com.yunbao.common.bean.RandomPkUserBean; 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.http.live.LiveNetManager; -import com.yunbao.common.manager.RandomPkManager; -import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.DpUtil; -import com.yunbao.common.utils.ToastUtil; -import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.WordsTypeUtil; import com.yunbao.live.R; import com.yunbao.live.adapter.RandomPkRecyclerAdapter; @@ -42,8 +34,6 @@ import com.yunbao.live.http.LiveHttpUtil; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Timer; -import java.util.TimerTask; /** * 自由PK @@ -137,10 +127,18 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl private void initRecycler() { helper = new DataHelper(); + helper.setStatus(DataHelper.LIST_MODEL_LIST); adapter = new RandomPkRecyclerAdapter(mContext); mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); mRecyclerView.setDataHelper(helper); mRecyclerView.initData(); + mRecyclerView.setEmptyLayoutId(R.layout.view_live_search_list_empty); + adapter.setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(RandomPkUserBean bean, int position) { + mRecyclerView.initData(); + } + }); } @@ -166,13 +164,19 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl mSearchLayout.setVisibility(View.GONE); switch (tabStatus) { case TAB_STATUS_SEARCH: + helper.setStatus(DataHelper.LIST_MODEL_LIST); mSearchLayout.setVisibility(View.VISIBLE); mRecyclerView.setVisibility(View.VISIBLE); mRecyclerView.initData(); + mRecyclerView.setRefreshEnable(false); + mRecyclerView.showEmpty(); break; case TAB_STATUS_FOLLOW: + mSearch.setText(""); + helper.setStatus(DataHelper.LIST_MODEL_FOLLOW); mRecyclerView.setVisibility(View.VISIBLE); mRecyclerView.initData(); + mRecyclerView.setRefreshEnable(true); break; } } @@ -202,12 +206,31 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl } public class DataHelper implements CommonRefreshView.DataHelper { + private final static int LIST_MODEL_LIST = 0; + private final static int LIST_MODEL_FOLLOW = 1; + private int status; + private String searchKey; + + public void setStatus(int status) { + this.status = status; + } public void search(String key) { + if (StringUtil.isEmpty(key)) { + adapter.getList().clear(); + adapter.notifyDataSetChanged(); + mRecyclerView.showEmpty(); + searchKey = null; + return; + } + searchKey = key; LiveNetManager.get(mContext) .randomPkSearchUser(key, WordsTypeUtil.changeTraditional(key), new com.yunbao.common.http.base.HttpCallback>() { @Override public void onSuccess(List data) { + if (!data.isEmpty()) { + mRecyclerView.hideEmpty(); + } List list = new ArrayList<>(); list.add(null); list.addAll(data); @@ -228,7 +251,16 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl @Override public void loadData(int p, HttpCallback callback) { - LiveHttpUtil.getLivePkList(p, callback); + if (status == LIST_MODEL_LIST) { + if (searchKey == null) { + callback.onSuccess(0, "", new String[]{}); + mRecyclerView.showEmpty(); + return; + } + search(searchKey); + } else { + LiveHttpUtil.getHomeFollow(p, callback); + } } @Override @@ -236,14 +268,14 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl Log.i(TAG, "processData: 获取数据成功"); List beans = JSON.parseArray(Arrays.toString(info), LivePkBean.class); List list = new ArrayList<>(); + list.add(null); for (LivePkBean bean : beans) { RandomPkUserBean userBean = new RandomPkUserBean(); userBean.setId(bean.getUid()); - userBean.setSex(bean.getSex()); userBean.setUserNiceName(bean.getUserNiceName()); userBean.setAvatar(bean.getAvatar()); userBean.setPk(bean.getPkUid().equals("0") ? 0 : 1); - userBean.setAttention("0"); + userBean.setAttention("1"); list.add(userBean); } return list; @@ -256,7 +288,7 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl @Override public void onRefreshFailure() { - + mRecyclerView.showEmpty(); } @Override @@ -266,7 +298,7 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl @Override public void onLoadMoreFailure() { - + mRecyclerView.showEmpty(); } } } diff --git a/live/src/main/java/com/yunbao/live/http/LiveHttpUtil.java b/live/src/main/java/com/yunbao/live/http/LiveHttpUtil.java index f200f9881..864ec1fe6 100644 --- a/live/src/main/java/com/yunbao/live/http/LiveHttpUtil.java +++ b/live/src/main/java/com/yunbao/live/http/LiveHttpUtil.java @@ -917,4 +917,13 @@ public class LiveHttpUtil { .execute(callback); } + /** + * 首页关注直播 + */ + public static void getHomeFollow(int p, HttpCallback callback) { + HttpClient.getInstance().get("Home.getFollow", "Home.getFollow") + .params("p", p) + .execute(callback); + } + } diff --git a/live/src/main/res/layout/view_live_search_list_empty.xml b/live/src/main/res/layout/view_live_search_list_empty.xml new file mode 100644 index 000000000..6c4319be8 --- /dev/null +++ b/live/src/main/res/layout/view_live_search_list_empty.xml @@ -0,0 +1,27 @@ + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/mipmap-xxxhdpi/img_live_search_list_empty.png b/live/src/main/res/mipmap-xxxhdpi/img_live_search_list_empty.png new file mode 100644 index 000000000..696d55a52 Binary files /dev/null and b/live/src/main/res/mipmap-xxxhdpi/img_live_search_list_empty.png differ