diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index 090ee0e81..22c397473 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -9,7 +9,6 @@ import com.yunbao.common.bean.CustomSidebarInfoModel; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.FaceBookUpModel; import com.yunbao.common.bean.HourRank; -import com.yunbao.common.bean.HttpCallbackModel; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.LinkMicUserBeanV2; import com.yunbao.common.bean.LiveInfoModel; @@ -358,10 +357,10 @@ public interface PDLiveApi { @GET("/api/public/?service=Livepk.setRandomPKType") Observable>> changeRandomPkSwitch(@Query("random_pk") int pk); /** - * 获取随机PK次数 + * 获取自由PK次数 */ - @GET("/api/public/?service=Livepk.getRandomPKType") - Observable> getRandomPkNumber(); + @GET("/api/public/?service=Livepk.getActivePkNum") + Observable> getFreePkNumber(); /** * 发起随机PK */ @@ -376,7 +375,7 @@ public interface PDLiveApi { * 自由PK开始后调用接口扣掉次数 */ @GET("/api/public/?service=Livepk.setActivePkNum") - Observable> setRandomPkNum(); + Observable> setFreePkNum(); /** * 随机PK搜索用户 * @param cs 简体关键字/uid diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index d1613154e..184dd7cdd 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -4,7 +4,6 @@ import android.content.Context; import android.text.TextUtils; import android.util.Log; -import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.R; import com.yunbao.common.bean.ActiveModel; @@ -564,11 +563,11 @@ public class LiveNetManager { } /** - * 获取随机PK次数 + * 获取自由PK次数 */ - public void getRandomPkNumber(HttpCallback callback) { + public void getFreePkNumber(HttpCallback callback) { API.get().pdLiveApi(mContext) - .getRandomPkNumber() + .getFreePkNumber() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Consumer>() { @@ -616,9 +615,9 @@ public class LiveNetManager { /** * 自由PK开始后调用接口扣掉次数 */ - public void setRandomPkNum(HttpCallback callback) { + public void setFreePkNum(HttpCallback callback) { API.get().pdLiveApi(mContext) - .setRandomPkNum() + .setFreePkNum() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Consumer>() { 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 6dbcd5701..acf66fc1e 100644 --- a/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java @@ -17,13 +17,12 @@ 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; import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.http.LiveHttpUtil; -import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; -import cn.rongcloud.rtc.base.RTCErrorCode; +import java.util.Arrays; public class RandomPkRecyclerAdapter extends RefreshAdapter { private static final int HEAD = 0; @@ -46,7 +45,7 @@ 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 ), position ); + ((ItemViewHolder) holder).setData(mList.get(position), position); } else { ((HeadViewHolder) holder).setData(mList.get(position), position); } @@ -102,9 +101,23 @@ public class RandomPkRecyclerAdapter extends RefreshAdapter { ToastUtil.show(R.string.free_pk_user_pking); return; } - ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), - ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() - ); + LiveHttpUtil.getMicList(LiveRyAnchorActivity.mLiveUid, 0, new com.yunbao.common.http.HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + //非0认为未开通连麦权限 + if (code != 0) { + ToastUtil.show("邀请 " + bean.getUserNiceName() + " 发送成功"); + mOnItemClickListener.onItemClick(bean, -1); + ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), + ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() + ); + } else { + ToastUtil.show("請先關閉語言連麥"); + } + } + }); + }); mFollow.setOnClickListener(v -> { RandomPkUserBean bean = (RandomPkUserBean) itemView.getTag(); 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 5fbec0e06..fa3866a2a 100644 --- a/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java @@ -10,6 +10,7 @@ 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; @@ -25,6 +26,7 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordsTypeUtil; import com.yunbao.live.R; import com.yunbao.live.adapter.RandomPkRecyclerAdapter; @@ -49,6 +51,7 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl private CommonRefreshView mRecyclerView; private View mSearchLayout; private EditText mSearch; + private TextView freePkNum; private ImageView mClear; private RandomPkRecyclerAdapter adapter; private DataHelper helper; @@ -75,7 +78,7 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl WindowManager.LayoutParams params = window.getAttributes(); window.setWindowAnimations(R.style.bottomToTopAnim); params.width = WindowManager.LayoutParams.MATCH_PARENT; - params.height = DpUtil.dp2px(330); + params.height = DpUtil.dp2px(400); params.gravity = Gravity.BOTTOM; window.setAttributes(params); } @@ -104,7 +107,9 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl mSearchLayout = findViewById(R.id.random_pk_search_layout); mSearch = (EditText) findViewById(R.id.search_edit); mClear = (ImageView) findViewById(R.id.search_clear); + freePkNum = (TextView) findViewById(R.id.free_pk_num); mClear.setOnClickListener(this); + reset.setOnClickListener(this); mSearch.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -132,10 +137,15 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); mRecyclerView.setDataHelper(helper); mRecyclerView.initData(); + mRecyclerView.setRefreshEnable(false); mRecyclerView.setEmptyLayoutId(R.layout.view_live_search_list_empty); adapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(RandomPkUserBean bean, int position) { + if (position == -1) { + dismiss(); + return; + } mRecyclerView.initData(); } }); @@ -143,6 +153,17 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl private void initData() { + LiveNetManager.get(mContext).getFreePkNumber(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(Integer data) { + freePkNum.setText("" + data); + } + + @Override + public void onError(String error) { + + } + }); } private void initTab() { @@ -198,8 +219,14 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl @Override public void onClick(View v) { int id = v.getId(); - if (id == R.id.live_random_pk_switch) { - + if (id == R.id.menu_reset) { + if (helper.status == DataHelper.LIST_MODEL_LIST) { + mSearch.setText(""); + mRecyclerView.initData(); + mRecyclerView.showEmpty(); + } else { + mRecyclerView.initData(); + } } else if (id == R.id.search_clear) { mSearch.setText(""); } @@ -266,8 +293,11 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl @Override public List processData(String[] info) { Log.i(TAG, "processData: 获取数据成功"); - List beans = JSON.parseArray(Arrays.toString(info), LivePkBean.class); List list = new ArrayList<>(); + if (info == null || info.length == 0) { + return list; + } + List beans = JSON.parseArray(Arrays.toString(info), LivePkBean.class); list.add(null); for (LivePkBean bean : beans) { RandomPkUserBean userBean = new RandomPkUserBean(); @@ -283,7 +313,6 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl @Override public void onRefreshSuccess(List list, int listCount) { - } @Override @@ -298,7 +327,6 @@ public class FreePkDialogFragment extends AbsDialogFragment implements View.OnCl @Override public void onLoadMoreFailure() { - mRecyclerView.showEmpty(); } } } diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index b9bf5440a..2d8f67e12 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -32,9 +32,11 @@ import com.tencent.rtmp.TXLiveConstants; import com.tencent.trtc.TRTCCloudDef; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; +import com.yunbao.common.bean.HttpCallbackModel; import com.yunbao.common.bean.UserBean; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.utils.DialogUitl; @@ -311,6 +313,18 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX } mLiveRyLinkMicPkPresenter.onLinkMicToPk(userBean1); mLiveRyLinkMicPkPresenter.onLinkMicPkStart(inviteeRoomId, 3); + //单人PK,减掉次数 + LiveNetManager.get(mContext).setFreePkNum(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + + } + + @Override + public void onError(String error) { + + } + }); } } }); diff --git a/live/src/main/res/layout/dialog_live_free_pk_function.xml b/live/src/main/res/layout/dialog_live_free_pk_function.xml index 1c5b0422b..11421eed6 100644 --- a/live/src/main/res/layout/dialog_live_free_pk_function.xml +++ b/live/src/main/res/layout/dialog_live_free_pk_function.xml @@ -1,17 +1,18 @@ @@ -105,4 +106,61 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/mipmap-xhdpi/icon_free_pk_waring.png b/live/src/main/res/mipmap-xhdpi/icon_free_pk_waring.png new file mode 100644 index 000000000..c415f9dce Binary files /dev/null and b/live/src/main/res/mipmap-xhdpi/icon_free_pk_waring.png differ