diff --git a/common/src/main/java/com/yunbao/common/Constants.java b/common/src/main/java/com/yunbao/common/Constants.java index 164614260..b597b23f7 100644 --- a/common/src/main/java/com/yunbao/common/Constants.java +++ b/common/src/main/java/com/yunbao/common/Constants.java @@ -179,6 +179,9 @@ public class Constants { public static final String CUSTOM_FULL_SERVICE_NOTIFY = "customFullServiceNotify";//全服通知 public static final String XYD_COMPLETE = "XydComplete";//心愿单完成通知 public static final String WISH_LIST_PROGRESS = "wishListProgress";//心愿单进度通知 + public static final String LIVE_VOTE_CREATE="createVote"; + public static final String LIVE_VOTE_UPDATE="updateVote"; + public static final String LIVE_VOTE_END="endVote"; //游戏socket public static final String SOCKET_GAME_ZJH = "startGame";//炸金花 diff --git a/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java b/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java index 1a6af9aa9..34e300886 100644 --- a/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java +++ b/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java @@ -104,12 +104,22 @@ public class EnterRoomInfoModel extends BaseModel { private String anchorGoodnum; @SerializedName("jackpot_level") private String jackpotLevel="-1"; + @SerializedName("live_vote") + private LiveRoomVoteModel voteModel; public String getJackpotLevel() { return jackpotLevel; } + public LiveRoomVoteModel getVoteModel() { + return voteModel; + } + + public void setVoteModel(LiveRoomVoteModel voteModel) { + this.voteModel = voteModel; + } + public EnterRoomInfoModel setJackpotLevel(String jackpotLevel) { this.jackpotLevel = jackpotLevel; return this; diff --git a/common/src/main/java/com/yunbao/common/bean/LiveRoomVoteModel.java b/common/src/main/java/com/yunbao/common/bean/LiveRoomVoteModel.java new file mode 100644 index 000000000..e08329ec4 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/LiveRoomVoteModel.java @@ -0,0 +1,173 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; +import com.yunbao.common.utils.StringUtil; + +import java.util.List; + +/** + * 主播创建投票 + * { + * "live_vote_id": "20", + * "question_content": "123", + * "vote_end_time": 180, + * "option_content_first_num": 0, + * "option_content_second_num": 0, + * "users_id": [] + * } + */ +public class LiveRoomVoteModel extends BaseModel { + @SerializedName("vote_status") + private int status; + @SerializedName("live_vote_id") + private String voteId; + @SerializedName("question_content") + private String content; + @SerializedName("vote_end_time") + private int time; + @SerializedName("option_content_first_num") + private int answer1Num; + @SerializedName("option_content_second_num") + private int answer2Num; + @SerializedName("users_id") + private List userIds; + @SerializedName("option_content_first") + private String answer1; + @SerializedName("option_content_second") + private String answer2; + @SerializedName("result") + private String result; + @SerializedName("option_text") + private String optionText; + @SerializedName("option_content_key") + private String vote; + + private String liveUid; + + public String getLiveUid() { + return liveUid; + } + + public void setLiveUid(String liveUid) { + this.liveUid = liveUid; + } + + public String getAnswer1() { + return answer1; + } + + public void setAnswer1(String answer1) { + this.answer1 = answer1; + } + + public String getAnswer2() { + return answer2; + } + + public void setAnswer2(String answer2) { + this.answer2 = answer2; + } + + public String getVoteId() { + return voteId; + } + + public void setVoteId(String voteId) { + this.voteId = voteId; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public int getTime() { + return time; + } + + public void setTime(int time) { + this.time = time; + } + + public int getAnswer1Num() { + return answer1Num; + } + + public void setAnswer1Num(int answer1Num) { + this.answer1Num = answer1Num; + } + + public int getAnswer2Num() { + return answer2Num; + } + + public void setAnswer2Num(int answer2Num) { + this.answer2Num = answer2Num; + } + + public List getUserIds() { + return userIds; + } + + public void setUserIds(List userIds) { + this.userIds = userIds; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getResult() { + return result; + } + + public void setResult(String result) { + this.result = result; + } + + public String getOptionText() { + return optionText; + } + + public void setOptionText(String optionText) { + this.optionText = optionText; + } + + @Override + public String toString() { + return "LiveRoomVoteModel{" + + "status=" + status + + ", voteId='" + voteId + '\'' + + ", content='" + content + '\'' + + ", time=" + time + + ", answer1Num=" + answer1Num + + ", answer2Num=" + answer2Num + + ", userIds=" + userIds + + ", answer1='" + answer1 + '\'' + + ", answer2='" + answer2 + '\'' + + ", result='" + result + '\'' + + ", optionText='" + optionText + '\'' + + ", vote='" + vote + '\'' + + ", liveUid='" + liveUid + '\'' + + '}'; + } + + public String getVote() { + return vote; + } + + public void setVote(String vote) { + this.vote = vote; + } + public boolean isVoteLeft(){ + return vote.equals("option_content_first_num"); + } + +} diff --git a/common/src/main/java/com/yunbao/common/dialog/AbsDialogPopupWindow.java b/common/src/main/java/com/yunbao/common/dialog/AbsDialogPopupWindow.java index 94503aa4b..c74e3ea45 100644 --- a/common/src/main/java/com/yunbao/common/dialog/AbsDialogPopupWindow.java +++ b/common/src/main/java/com/yunbao/common/dialog/AbsDialogPopupWindow.java @@ -16,6 +16,9 @@ public abstract class AbsDialogPopupWindow extends BottomPopupView { this.mContext = context; } + /** + * 参考配置 + */ public abstract void buildDialog(XPopup.Builder builder); public abstract int bindLayoutId(); 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 555f0108a..3119fff54 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -17,6 +17,7 @@ import com.yunbao.common.bean.LinkMicUserBeanV2; import com.yunbao.common.bean.ListInfoMessageModel; import com.yunbao.common.bean.LiveAiRobotBean; import com.yunbao.common.bean.LiveAnchorCallMeModel; +import com.yunbao.common.bean.LiveRoomVoteModel; import com.yunbao.common.bean.LiveAnchorSayModel; import com.yunbao.common.bean.LiveDataInfoModel; import com.yunbao.common.bean.LiveInfoModel; @@ -694,4 +695,25 @@ public interface PDLiveApi { */ @GET("/api/public/?service=User.setLogOff") Observable>> setLogOff(); + + /** + * 创建投票 + */ + @GET("/api/public/?service=Live.createLiveVote") + Observable> createLiveVote(@Query("liveuid") String liveUid, + @Query("question_content") String content, + @Query("option_content_first") String first, + @Query("option_content_second") String second); + + /** + * 更新投票 + */ + @GET("/api/public/?service=Live.setLiveVote") + Observable>> updateLiveVote(@Query("liveuid") String liveUid, + @Query("option_content_key") String key); + /** + * 主动结束投票 + */ + @GET("/api/public/?service=Live.endLiveVote") + Observable>> endLiveVote(@Query("liveuid") String liveUid); } 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 41bfecaaf..083b6babe 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 @@ -18,6 +18,7 @@ import com.yunbao.common.bean.LinkMicUserBeanV2; import com.yunbao.common.bean.ListInfoMessageModel; import com.yunbao.common.bean.LiveAiRobotBean; import com.yunbao.common.bean.LiveAnchorCallMeModel; +import com.yunbao.common.bean.LiveRoomVoteModel; import com.yunbao.common.bean.LiveAnchorSayModel; import com.yunbao.common.bean.LiveDataInfoModel; import com.yunbao.common.bean.LiveInfoModel; @@ -1427,6 +1428,78 @@ public class LiveNetManager { }).isDisposed(); } + public void createLiveVote(String liveUid, String content, String first, String second, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .createLiveVote(liveUid, content, first, second) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel listResponseModel) throws Exception { + if (callback != null) { + callback.onSuccess(listResponseModel.getData().getInfo()); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + + public void updateLiveVote(String liveUid, boolean isLeftVote, HttpCallback callback) { + String key; + if (isLeftVote) {//是左边的投票 + key = "option_content_first_num"; + } else { + key = "option_content_second_num"; + } + API.get().pdLiveApi(mContext) + .updateLiveVote(liveUid, key) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>>() { + @Override + public void accept(ResponseModel> listResponseModel) throws Exception { + if (callback != null) { + callback.onSuccess(""); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + + public void endLiveVote(String liveUid, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .endLiveVote(liveUid) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>>() { + @Override + public void accept(ResponseModel> listResponseModel) throws Exception { + if (callback != null) { + callback.onSuccess(listResponseModel.getData().getMsg()); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + /** * 直播间取消网络请求 */ diff --git a/common/src/main/res/layout/dialog_live_new_function.xml b/common/src/main/res/layout/dialog_live_new_function.xml index 7a444507f..8a1234d84 100644 --- a/common/src/main/res/layout/dialog_live_new_function.xml +++ b/common/src/main/res/layout/dialog_live_new_function.xml @@ -246,140 +246,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/common/src/main/res/values-en-rUS/string.xml b/common/src/main/res/values-en-rUS/string.xml index 4c3a07c0c..5bfc21860 100644 --- a/common/src/main/res/values-en-rUS/string.xml +++ b/common/src/main/res/values-en-rUS/string.xml @@ -1155,4 +1155,15 @@ Limited ride And limited avatar frame VIP Open Guard Open Fan group + QA + submit + cancel + question: + answer: + Do you want to end this voting early? + Yes + No + VOTE + %s \n box disappears after %s seconds + Please complete the form. diff --git a/common/src/main/res/values-zh-rHK/strings.xml b/common/src/main/res/values-zh-rHK/strings.xml index 0de513139..aca95a68b 100644 --- a/common/src/main/res/values-zh-rHK/strings.xml +++ b/common/src/main/res/values-zh-rHK/strings.xml @@ -1150,4 +1150,15 @@ 開通貴族 開通守護 開通粉絲團 + 發啟問答 + 發啟問答 + 取消 + 問題設置: + 答案設置: + 是否提前結束本次投票? + + + 投票中 + %s \n 問答框%s秒后消失 + 請完整填寫 diff --git a/common/src/main/res/values-zh-rTW/strings.xml b/common/src/main/res/values-zh-rTW/strings.xml index 245ff9e8c..c41ee0c59 100644 --- a/common/src/main/res/values-zh-rTW/strings.xml +++ b/common/src/main/res/values-zh-rTW/strings.xml @@ -1149,4 +1149,15 @@ 開通貴族 開通守護 開通粉絲團 + 發啟問答 + 發啟問答 + 取消 + 問題設置: + 答案設置: + 是否提前結束本次投票? + + + 投票中 + %s \n 問答框%s秒后消失 + 請完整填寫 diff --git a/common/src/main/res/values-zh/strings.xml b/common/src/main/res/values-zh/strings.xml index 0de513139..aca95a68b 100644 --- a/common/src/main/res/values-zh/strings.xml +++ b/common/src/main/res/values-zh/strings.xml @@ -1150,4 +1150,15 @@ 開通貴族 開通守護 開通粉絲團 + 發啟問答 + 發啟問答 + 取消 + 問題設置: + 答案設置: + 是否提前結束本次投票? + + + 投票中 + %s \n 問答框%s秒后消失 + 請完整填寫 diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index ee792f556..62463aead 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1156,4 +1156,15 @@ Limited ride And limited avatar frame VIP Open Guard Open Fan group + QA + submit + cancel + question: + answer: + Do you want to end this voting early? + Yes + No + VOTE + %s \n box disappears after %s seconds + Please complete the form. diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 094db35c3..2f2a4e1ab 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -1,5 +1,6 @@ package com.yunbao.live.activity; + import android.annotation.SuppressLint; import android.app.Dialog; import android.content.Intent; @@ -47,6 +48,7 @@ import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.LinkMicUserBean; import com.yunbao.common.bean.LiveBean; import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.bean.LiveRoomVoteModel; import com.yunbao.common.bean.LiveUserGiftBean; import com.yunbao.common.bean.LiveUserMailBoxModel; import com.yunbao.common.bean.SlideInfoModel; @@ -1044,9 +1046,9 @@ public class LiveAudienceActivity extends LiveActivity { liveFansFragment.show(getSupportFragmentManager(), "LiveGuardDialogFragment"); break; case GUARD: - if(event.getObject()==null) { + if (event.getObject() == null) { openNewGuardListWindow(mContext instanceof LiveRyAnchorActivity); - }else{ + } else { openNewBuyGuardWindow(true); } break; @@ -1333,6 +1335,31 @@ public class LiveAudienceActivity extends LiveActivity { manager.showXydComplete(event.getXydCompleteModel(), event.getLiveReceiveGiftBean()); } break; + case VOTE_CREATE: + case VOTE_UPDATE: + JSONObject map = (JSONObject) event.getObject(); + manager.mLiveRoomViewHolder.setVoteData( + map.getString("question"), + map.getString("answer1"), + map.getString("answer2"), + map.getString("num1"), + map.getString("num2") + ); + break; + case VOTE_END: + try { + LiveRoomVoteModel voteModel = JSONObject.parseObject(event.getObject().toString(), LiveRoomVoteModel.class); + System.out.println(">>>" + voteModel); + String content = voteModel.getResult(); + if (!StringUtil.isEmpty(voteModel.getOptionText())) { + content =voteModel.getResult().replace(voteModel.getOptionText(), "" + voteModel.getOptionText() + ""); + } + manager.mLiveRoomViewHolder.dismissVote(voteModel.getResult(), content); + } catch (Exception e) { + e.printStackTrace(); + } + + break; } diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java index 3022cd9c5..06c2750fe 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -5,6 +5,7 @@ import static com.yunbao.live.bean.LiveChatBean.LUCKY_100_CHECK; import static com.yunbao.live.bean.LiveChatBean.LUCKY_ANGEL; import static com.yunbao.live.bean.LiveChatBean.RECOMMEND_CARD_NOTIFY; import static com.yunbao.live.bean.LiveChatBean.STAR_CHALLENGE_UPGRADE_NOTIFY; +import static com.yunbao.live.bean.LiveChatBean.SYSTEM3_COLOR; import static com.yunbao.live.bean.LiveChatBean.WISH_LIST_PROGRESS; import static com.yunbao.live.bean.LiveChatBean.XYD_COMPLETE; @@ -13,6 +14,7 @@ import android.content.Context; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.text.Html; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.Spanned; @@ -47,6 +49,7 @@ import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.SpUtil; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.weight.ClipPathCircleImage; import com.yunbao.live.R; import com.yunbao.live.activity.LiveAudienceActivity; @@ -82,7 +85,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { private int mPosition; private boolean isBottom = false; - private int fountSize=13; + private int fountSize = 13; public LiveChatAdapter(Context context) { mContext = context; @@ -100,10 +103,10 @@ public class LiveChatAdapter extends RecyclerView.Adapter { } } }; - if(SpUtil.getInstance().isExists("pd_live_room_fount_size")){ + if (SpUtil.getInstance().isExists("pd_live_room_fount_size")) { try { - fountSize=Integer.parseInt(SpUtil.getStringValue("pd_live_room_fount_size")); - }catch (Exception ignored){ + fountSize = Integer.parseInt(SpUtil.getStringValue("pd_live_room_fount_size")); + } catch (Exception ignored) { } } @@ -173,8 +176,8 @@ public class LiveChatAdapter extends RecyclerView.Adapter { } public void switchFount(int fount) { - fountSize=fount; - SpUtil.setStringValue("pd_live_room_fount_size",fountSize+""); + fountSize = fount; + SpUtil.setStringValue("pd_live_room_fount_size", fountSize + ""); notifyDataSetChanged(); } @@ -198,7 +201,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { class Vh extends RecyclerView.ViewHolder { LinearLayout mBg, view_follow, view_action_game, view_zg, xydComplete; - TextView mTextView, tv_chat_active_into, tv_chat_avtive_name, tv_zg_anchorname, textTxt2,automatic_chat; + TextView mTextView, tv_chat_active_into, tv_chat_avtive_name, tv_zg_anchorname, textTxt2, automatic_chat; RoundedImageView avatar; View v_chat_active_close; RecyclerView rv_chat_active; @@ -477,6 +480,8 @@ public class LiveChatAdapter extends RecyclerView.Adapter { new LoadDian9TuUtil().loadDian9Tu(mContext, mBg, bean.getMsgModel().getSystem_bubble(), 1); new LiveTextRender().lucky100(mContext, mTextView, bean.getMsgModel()); } + } else if (bean.getType() == SYSTEM3_COLOR) { + mTextView.setText(Html.fromHtml(bean.getContent())); } else { if (bean.getBubble() != null && !bean.getBubble().equals("")) { //加载.9图聊天气泡 diff --git a/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java b/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java index 85a6697cd..c57e9fb9f 100644 --- a/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java +++ b/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java @@ -23,6 +23,7 @@ public class LiveChatBean { public static final int STAR_CHALLENGE_UPGRADE_NOTIFY = 105; public static final int LUCKY_ANGEL = 106;//幸运天使 public static final int LUCKY_100_CHECK = 107;//幸运天使 + public static final int SYSTEM3_COLOR = 108;//带颜色的系统消息,格式 XXXXYYY public static final int XYD_COMPLETE = 207;//心愿单完成通知 public static final int WISH_LIST_PROGRESS = 307;//心愿单进度通知 diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveAnchorCreateQADialog.java b/live/src/main/java/com/yunbao/live/dialog/LiveAnchorCreateQADialog.java new file mode 100644 index 000000000..243f2a568 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/LiveAnchorCreateQADialog.java @@ -0,0 +1,75 @@ +package com.yunbao.live.dialog; + +import android.content.Context; +import android.widget.Button; +import android.widget.EditText; + +import androidx.annotation.NonNull; + +import com.lxj.xpopup.XPopup; +import com.yunbao.common.dialog.AbsDialogPopupWindow; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.live.R; +import com.yunbao.live.utils.LiveAnchorVoteManager; + +/** + * 主播创建问答弹框 + */ +public class LiveAnchorCreateQADialog extends AbsDialogPopupWindow { + private EditText question, answer1, answer2; + private Button submit, cancel; + + private String liveUid; + + public LiveAnchorCreateQADialog setLiveUid(String liveUid) { + this.liveUid = liveUid; + return this; + } + + + public LiveAnchorCreateQADialog(@NonNull Context context) { + super(context); + } + + @Override + public void buildDialog(XPopup.Builder builder) { + builder.dismissOnTouchOutside(false); + builder.autoFocusEditText(false); + } + + @Override + public int bindLayoutId() { + return R.layout.dialog_live_anchor_create_qa; + } + + @Override + protected void onCreate() { + super.onCreate(); + question = findViewById(R.id.edit_question); + answer1 = findViewById(R.id.edit_answer1); + answer2 = findViewById(R.id.edit_answer2); + submit = findViewById(R.id.submit); + cancel = findViewById(R.id.cancel); + cancel.setOnClickListener(v -> dismiss()); + submit.setOnClickListener(v -> { + if (question.getText().toString().trim().length() == 0 || + answer1.getText().toString().trim().length() == 0 || + answer2.getText().toString().trim().length() == 0 + ) { + ToastUtil.show(getContext().getString(R.string.live_anchor_vote_tip)); + return; + } + createVote(question.getText().toString(), answer1.getText().toString(), answer2.getText().toString()); + }); + } + + private void createVote(String question, String answer1, String answer2) { + LiveAnchorVoteManager.getInstance().createVote(liveUid, question, answer1, answer2, (bean, position) -> { + if(position!=0){ + ToastUtil.show(bean.getContent()); + return; + } + dismiss(); + }); + } +} diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java index 12a8fd209..00aca5d9c 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java @@ -120,6 +120,7 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements findViewById(R.id.live_tool_robot).setOnClickListener(this); findViewById(R.id.live_tool_call_me).setOnClickListener(this); findViewById(R.id.live_tool_anchor_say).setOnClickListener(this); + findViewById(R.id.live_tool_qa).setOnClickListener(this); if (leave == 0) { ((ImageView) mLeaveView.findViewById(R.id.live_tool_leave_img)).setImageResource(R.mipmap.icon_leave); @@ -198,7 +199,9 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements new LiveAnchorEditCallMeDialog(mContext).setLiveUid(liveUid).showDialog(); } else if (id == R.id.live_tool_anchor_say) { new LiveAnchorSayPopDialog(mContext).setLiveUid(liveUid).setOnItemClickListener((bean, position) - -> mLiveRoomHandler.postDelayed(()-> ((LiveRyAnchorActivity)(mContext)).mLiveRoomViewHolder.initAnchorSayData(),1000)).showDialog(); + -> mLiveRoomHandler.postDelayed(() -> ((LiveRyAnchorActivity) (mContext)).mLiveRoomViewHolder.initAnchorSayData(), 1000)).showDialog(); + } else if (id == R.id.live_tool_qa) { + new LiveAnchorCreateQADialog(mContext).setLiveUid(liveUid).showDialog(); } } diff --git a/live/src/main/java/com/yunbao/live/event/LiveAnchorEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAnchorEvent.java new file mode 100644 index 000000000..5138ce67c --- /dev/null +++ b/live/src/main/java/com/yunbao/live/event/LiveAnchorEvent.java @@ -0,0 +1,295 @@ +package com.yunbao.live.event; + +import com.alibaba.fastjson.JSONArray; +import com.yunbao.common.bean.ActiveModel; +import com.yunbao.common.bean.AiAutomaticSpeechModel; +import com.yunbao.common.bean.AnchorRecommendItemModel; +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.LiveBean; +import com.yunbao.common.bean.MsgModel; +import com.yunbao.common.bean.WishModel; +import com.yunbao.common.bean.XydCompleteModel; +import com.yunbao.common.event.CustomFullServiceNotifyEvent; +import com.yunbao.live.bean.LivePKUserListBean; +import com.yunbao.live.bean.LiveReceiveGiftBean; +import com.yunbao.live.bean.OpenParametersModel; + + +public class LiveAnchorEvent extends BaseModel { + private LiveAnchorType type; + private ActiveModel model = new ActiveModel(); + private String avatar = ""; + private OpenParametersModel parametersModel = new OpenParametersModel(); + private AnchorRecommendItemModel anchorRecommendItemModel = new AnchorRecommendItemModel(); + private int micIng = 0;//连麦状态 + private LiveBean bean; + private Object object; + private int liveType; + private int liveTypeVal; + private MsgModel msgModel;//全服消息 + private AiAutomaticSpeechModel aiAutomaticSpeechModel;//机器人消息 + private boolean voicePress = false; + private boolean isActivity = false;//是否展示趣味活动和增值权益 + private JSONArray pkScores; + private String uid; + private int time; + private CustomFullServiceNotifyEvent customFullServiceNotifyEvent; + private LivePKUserListBean livePKUserListBean; + private String votes; + private String length; + private int nums; + private String uname; + private WishModel wishListProgress; + private XydCompleteModel xydCompleteModel; + private LiveReceiveGiftBean liveReceiveGiftBean; + + public LiveReceiveGiftBean getLiveReceiveGiftBean() { + return liveReceiveGiftBean; + } + + public LiveAnchorEvent setLiveReceiveGiftBean(LiveReceiveGiftBean liveReceiveGiftBean) { + this.liveReceiveGiftBean = liveReceiveGiftBean; + return this; + } + + public XydCompleteModel getXydCompleteModel() { + return xydCompleteModel; + } + + public LiveAnchorEvent setXydCompleteModel(XydCompleteModel xydCompleteModel) { + this.xydCompleteModel = xydCompleteModel; + return this; + } + + public WishModel getWishListProgress() { + return wishListProgress; + } + + public LiveAnchorEvent setWishListProgress(WishModel wishListProgress) { + this.wishListProgress = wishListProgress; + return this; + } + + public String getVotes() { + return votes; + } + + public LiveAnchorEvent setVotes(String votes) { + this.votes = votes; + return this; + } + + public String getLength() { + return length; + } + + public LiveAnchorEvent setLength(String length) { + this.length = length; + return this; + } + + public int getNums() { + return nums; + } + + public LiveAnchorEvent setNums(int nums) { + this.nums = nums; + return this; + } + + public String getUname() { + return uname; + } + + public LiveAnchorEvent setUname(String uname) { + this.uname = uname; + return this; + } + + public LivePKUserListBean getLivePKUserListBean() { + return livePKUserListBean; + } + + public LiveAnchorEvent setLivePKUserListBean(LivePKUserListBean livePKUserListBean) { + this.livePKUserListBean = livePKUserListBean; + return this; + } + + public CustomFullServiceNotifyEvent getCustomFullServiceNotifyEvent() { + return customFullServiceNotifyEvent; + } + + public LiveAnchorEvent setCustomFullServiceNotifyEvent(CustomFullServiceNotifyEvent customFullServiceNotifyEvent) { + this.customFullServiceNotifyEvent = customFullServiceNotifyEvent; + return this; + } + + public JSONArray getPkScores() { + return pkScores; + } + + public LiveAnchorEvent setPkScores(JSONArray pkScores) { + this.pkScores = pkScores; + return this; + } + + public String getUid() { + return uid; + } + + public LiveAnchorEvent setUid(String uid) { + this.uid = uid; + return this; + } + + public int getTime() { + return time; + } + + public LiveAnchorEvent setTime(int time) { + this.time = time; + return this; + } + + public boolean isActivity() { + return isActivity; + } + + public LiveAnchorEvent setActivity(boolean activity) { + isActivity = activity; + return this; + } + + public boolean isVoicePress() { + return voicePress; + } + + public LiveAnchorEvent setVoicePress(boolean voicePress) { + this.voicePress = voicePress; + return this; + } + + public AiAutomaticSpeechModel getAiAutomaticSpeechModel() { + return aiAutomaticSpeechModel; + } + + public LiveAnchorEvent setAiAutomaticSpeechModel(AiAutomaticSpeechModel aiAutomaticSpeechModel) { + this.aiAutomaticSpeechModel = aiAutomaticSpeechModel; + return this; + } + + public MsgModel getMsgModel() { + return msgModel; + } + + public LiveAnchorEvent setMsgModel(MsgModel msgModel) { + this.msgModel = msgModel; + return this; + } + + public int getLiveType() { + return liveType; + } + + public LiveAnchorEvent setLiveType(int liveType) { + this.liveType = liveType; + return this; + } + + public int getLiveTypeVal() { + return liveTypeVal; + } + + public LiveAnchorEvent setLiveTypeVal(int liveTypeVal) { + this.liveTypeVal = liveTypeVal; + return this; + } + + public LiveBean getBean() { + return bean; + } + + public LiveAnchorEvent setBean(LiveBean bean) { + this.bean = bean; + return this; + } + + public int getMicIng() { + return micIng; + } + + public LiveAnchorEvent setMicIng(int micIng) { + this.micIng = micIng; + return this; + } + + public AnchorRecommendItemModel getAnchorRecommendItemModel() { + return anchorRecommendItemModel; + } + + public LiveAnchorEvent setAnchorRecommendItemModel(AnchorRecommendItemModel anchorRecommendItemModel) { + this.anchorRecommendItemModel = anchorRecommendItemModel; + return this; + } + + public OpenParametersModel getParametersModel() { + return parametersModel; + } + + public LiveAnchorEvent setParametersModel(OpenParametersModel parametersModel) { + this.parametersModel = parametersModel; + return this; + } + + public String getAvatar() { + return avatar; + } + + public LiveAnchorEvent setAvatar(String avatar) { + this.avatar = avatar; + return this; + } + + public ActiveModel getModel() { + return model; + } + + public LiveAnchorEvent setModel(ActiveModel model) { + this.model = model; + return this; + } + + public LiveAnchorType getType() { + return type; + } + + public LiveAnchorEvent setType(LiveAnchorType type) { + this.type = type; + return this; + } + + public Object getObject() { + return object; + } + + public LiveAnchorEvent setObject(Object object) { + this.object = object; + return this; + } + + public enum LiveAnchorType { + VOTE_CREATE(1, "创建投票"), + VOTE_ANCHOR_END(2, "投票结束"), + VOTE_ANCHOR_UPDATE(3, "投票结束"); + + + private int type; + private String name; + + LiveAnchorType(int type, String name) { + this.type = type; + this.name = name; + } + + } +} diff --git a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index bf09ae1e1..7d72304c6 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -341,7 +341,10 @@ public class LiveAudienceEvent extends BaseModel { WISH_LIST_PROGRESS(61, "心愿单进度"), CLOSE_LIVE_ROOM(62, "关闭直播间"), FONT_SIZE(63, "侧边字号设置"), - LIVE_FONT_SIZE(64, "字号设置"); + LIVE_FONT_SIZE(64, "字号设置"), + VOTE_CREATE(65, "创建投票"), + VOTE_UPDATE(66, "更新投票"), + VOTE_END(67, "投票结束"); private int type; private String name; diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index f86d0ab75..332c18aa8 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -52,6 +52,7 @@ import com.yunbao.live.bean.LiveGiftPrizePoolWinBean; import com.yunbao.live.bean.LiveLuckGiftWinBean; import com.yunbao.live.bean.LivePKUserListBean; import com.yunbao.live.bean.LiveReceiveGiftBean; +import com.yunbao.live.event.LiveAnchorEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.views.LiveEndViewHolder; import com.yunbao.live.views.LivePlayKsyViewHolder; @@ -72,10 +73,10 @@ import io.rong.imlib.chatroom.base.RongChatRoomClient; public class SocketRyClient { - private final String TAG = "socket"; + private final String TAG = "socket"; private String mLiveUid; private String mStream; - public static SocketRyClient.SocketHandler mSocketHandler; + public static SocketRyClient.SocketHandler mSocketHandler; private Context mContext; public SocketRyClient(String mLiveUid, SocketMessageListener listener, Activity mContext) { @@ -111,11 +112,11 @@ public class SocketRyClient { mSocketHandler = null; } - public class SocketHandler extends Handler { + public class SocketHandler extends Handler { - private SocketMessageListener mListener; + private SocketMessageListener mListener; private LivePushRyViewHolder livePushRyViewHolder; - private String mLiveUid; + private String mLiveUid; public SocketHandler(SocketMessageListener listener) { mListener = new WeakReference<>(listener).get(); @@ -621,11 +622,39 @@ public class SocketRyClient { .setGiftType(map.getInteger("giftId")) .setLuid(conString.toString())).setUname(map.getString("userName")).setLiveType(Integer.parseInt(map.getString("level")))); break; + case Constants.LIVE_VOTE_CREATE: + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.VOTE_CREATE) + .setObject(map) + ); + break; + case Constants.LIVE_VOTE_END: + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.VOTE_END) + .setObject(map) + ); + EventBus.getDefault().post(new LiveAnchorEvent() + .setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_END) + .setObject(map) + ); + break; + case Constants.LIVE_VOTE_UPDATE: + //通知给观众 + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.VOTE_UPDATE) + .setObject(map) + ); + //通知给主播 + EventBus.getDefault().post(new LiveAnchorEvent() + .setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_UPDATE) + .setObject(map) + ); + break; } } - private void buyGuardInSameRoom(JSONObject map) { + private void buyGuardInSameRoom(JSONObject map) { LiveBuyGuardMsgBean buyGuardMsgBean = new LiveBuyGuardMsgBean(); buyGuardMsgBean.setUid(map.getString("uid")); buyGuardMsgBean.setUserName(map.getString("ct")); @@ -635,7 +664,7 @@ public class SocketRyClient { mListener.onBuyGuard(buyGuardMsgBean); } - private void buyGuardByNotify(JSONObject map) { + private void buyGuardByNotify(JSONObject map) { if (mLiveUid.equals(map.getString("liveuid"))) { buyGuardInSameRoom(map); //同一直播间,玩家自己开通,也能看到全服通知 @@ -668,7 +697,7 @@ public class SocketRyClient { } - private void buyZuoJiByNotify(JSONObject map) { + private void buyZuoJiByNotify(JSONObject map) { LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); receiveGiftBean.setUserNiceName(map.getString("nickname")); receiveGiftBean.setCarName(map.getString("carname")); @@ -677,7 +706,7 @@ public class SocketRyClient { } - private void buyLiangNameByNotify(JSONObject map) { + private void buyLiangNameByNotify(JSONObject map) { LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); receiveGiftBean.setUserNiceName(map.getString("nickname")); receiveGiftBean.setLiangName(map.getString("liangname")); @@ -685,7 +714,7 @@ public class SocketRyClient { mListener.onBuyLiangName(receiveGiftBean); } - private void buyVipByNotify(JSONObject map) { + private void buyVipByNotify(JSONObject map) { LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); receiveGiftBean.setUserNiceName(map.getString("nicename")); receiveGiftBean.setVipName(map.getString("ct")); @@ -709,7 +738,7 @@ public class SocketRyClient { mListener.onBuyVip(receiveGiftBean); } - private void sendActiveMsg(JSONObject map, SocketReceiveBean received) { + private void sendActiveMsg(JSONObject map, SocketReceiveBean received) { String msgtype = map.getString("msgtype"); if ("1".equals(msgtype)) {//新年大作战活动 LiveChatBean chatBean = new LiveChatBean(); @@ -900,7 +929,7 @@ public class SocketRyClient { } } - private void xydComplete(JSONObject map) { + private void xydComplete(JSONObject map) { LiveReceiveGiftBean receiveGiftBean = new LiveReceiveGiftBean(); receiveGiftBean.setAvatar(map.getString("uhead") + ""); receiveGiftBean.setUserNiceName(map.getString("uname")); @@ -1014,7 +1043,7 @@ public class SocketRyClient { /** * 接收到系统消息,显示在聊天栏中 */ - private void systemChatMessage(String content) { + private void systemChatMessage(String content) { LiveChatBean bean = new LiveChatBean(); bean.setContent(content); bean.setType(LiveChatBean.SYSTEM); @@ -1024,7 +1053,7 @@ public class SocketRyClient { /** * 接收到系统消息,显示在聊天栏中 */ - private void systemChatMessage2(String content) { + private void systemChatMessage2(String content) { LiveChatBean bean = new LiveChatBean(); bean.setContent(content); bean.setType(LiveChatBean.SYSTEM2); @@ -1034,7 +1063,7 @@ public class SocketRyClient { /** * 处理观众与主播连麦逻辑 */ - private void processLinkMic(JSONObject map) { + private void processLinkMic(JSONObject map) { int action = map.getIntValue("action"); switch (action) { case 1://主播收到观众连麦的申请 @@ -1089,7 +1118,7 @@ public class SocketRyClient { * * @param map */ - private void processLinkMicAnchor(JSONObject map) { + private void processLinkMicAnchor(JSONObject map) { int action = map.getIntValue("action"); switch (action) { case 1://收到其他主播连麦的邀请的回调 @@ -1128,7 +1157,7 @@ public class SocketRyClient { * * @param map */ - private void processAnchorLinkMicPk(JSONObject map) { + private void processAnchorLinkMicPk(JSONObject map) { int action = map.getIntValue("action"); Log.i("Socket", "action = " + action + " json = " + map.toString()); diff --git a/live/src/main/java/com/yunbao/live/utils/LiveAnchorVoteManager.java b/live/src/main/java/com/yunbao/live/utils/LiveAnchorVoteManager.java new file mode 100644 index 000000000..8ea230e2a --- /dev/null +++ b/live/src/main/java/com/yunbao/live/utils/LiveAnchorVoteManager.java @@ -0,0 +1,121 @@ +package com.yunbao.live.utils; + +import android.os.Handler; +import android.os.Looper; + +import com.yunbao.common.CommonAppContext; +import com.yunbao.common.bean.LiveRoomVoteModel; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.live.event.LiveAnchorEvent; + +import org.greenrobot.eventbus.EventBus; + +import java.util.Timer; +import java.util.TimerTask; + +/** + * 主播投票管理器,可以创建投票和手动结束投票 + */ +public class LiveAnchorVoteManager { + private static LiveAnchorVoteManager manager; + private String liveUid; + private boolean isVoting = false; + private LiveRoomVoteModel vote; + private TimerTask task; + + + private LiveAnchorVoteManager() { + } + + + public static LiveAnchorVoteManager getInstance() { + if (manager == null) { + manager = new LiveAnchorVoteManager(); + } + return manager; + } + + + public void createVote(String liveUid, String question, String answer1, String answer2, OnItemClickListener listener) { + if (isVoting) { + return; + } + this.liveUid = liveUid; + LiveNetManager.get(CommonAppContext.getTopActivity()) + .createLiveVote(liveUid, question, answer1, answer2, new HttpCallback() { + @Override + public void onSuccess(LiveRoomVoteModel data) { + data.setAnswer1(answer1); + data.setAnswer2(answer2); + data.setLiveUid(liveUid); + vote = data; + createTimerTask(); + EventBus.getDefault().post(new LiveAnchorEvent() + .setType(LiveAnchorEvent.LiveAnchorType.VOTE_CREATE) + .setObject(data) + ); + listener.onItemClick(vote, 0); + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + LiveRoomVoteModel voteModel = new LiveRoomVoteModel(); + voteModel.setContent(error); + listener.onItemClick(voteModel, -1); + } + }); + } + + private void createTimerTask() { + if (isVoting) { + task.cancel(); + } + task = new TimerTask() { + @Override + public void run() { + isVoting = true; + new Handler(Looper.getMainLooper()).post(() -> { + entVote((bean, position) -> { + EventBus.getDefault().post(new LiveAnchorEvent() + .setType(LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_END) + .setObject(bean) + ); + }); + }); + } + }; + new Timer().schedule(task, vote.getTime() * 1000L); + + } + + public void entVote(OnItemClickListener msg) { + if (isVoting) { + task.cancel(); + } + LiveNetManager.get(CommonAppContext.getTopActivity()) + .endLiveVote(liveUid, new HttpCallback() { + @Override + public void onSuccess(String data) { + isVoting = false; + msg.onItemClick(data, 0); + } + + @Override + public void onError(String error) { + msg.onItemClick(error, -1); + } + }); + + } + + public void clear() { + if (task != null) { + task.cancel(); + task = null; + } + } +} diff --git a/live/src/main/java/com/yunbao/live/utils/LiveRoomVoteManager.java b/live/src/main/java/com/yunbao/live/utils/LiveRoomVoteManager.java new file mode 100644 index 000000000..4bdd5ec68 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/utils/LiveRoomVoteManager.java @@ -0,0 +1,259 @@ +package com.yunbao.live.utils; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.Looper; +import android.view.View; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.yunbao.common.bean.LiveRoomVoteModel; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveRyAnchorActivity; + +import java.util.Timer; +import java.util.TimerTask; + +/** + * 直播间投票控件管理器 + */ +public class LiveRoomVoteManager { + private final Context mContext; + private final View voteLayout; + private final View voteRoot; + private final View mVoteShow; + private final View mClose; + private final ImageView mAnchorVoteHide; + private final boolean isAnchor; + + private final TextView mTitle; + private final TextView mSubmit; + private final TextView mCancel; + private final ProgressBar mProgress; + + + LiveRoomVoteModel createVoteModel; + + public LiveRoomVoteManager(Context mContext, View root) { + this.mContext = mContext; + mAnchorVoteHide = root.findViewById(R.id.vote_hide); + mVoteShow = root.findViewById(R.id.vote_show); + mClose = root.findViewById(R.id.vote_close); + voteLayout = root.findViewById(R.id.vote_layout); + voteRoot = root.findViewById(R.id.live_room_vote); + mTitle = root.findViewById(R.id.title); + mSubmit = root.findViewById(R.id.vote_sub1); + mCancel = root.findViewById(R.id.vote_sub2); + mProgress = root.findViewById(R.id.vote_progress); + mAnchorVoteHide.setOnClickListener(v -> hideAnchorVote()); + mVoteShow.setOnClickListener(v -> hideAnchorVote()); + mClose.setOnClickListener(v -> close()); + if (mContext instanceof LiveRyAnchorActivity) { + isAnchor = true; + } else { + isAnchor = false; + mClose.setVisibility(View.INVISIBLE); + } + hide(); + initClick(); + } + + private void close() { + mTitle.setText(R.string.live_vote_close_title); + mSubmit.setText(R.string.live_vote_close_yes); + mCancel.setText(R.string.live_vote_close_no); + mCancel.setOnClickListener(v -> { + mTitle.setText(createVoteModel.getContent()); + mSubmit.setText(createVoteModel.getAnswer1()); + mCancel.setText(createVoteModel.getAnswer2()); + initClick(); + }); + mSubmit.setOnClickListener(v -> endAnchorVote()); + } + + private void initClick() { + if (isAnchor) { + return; + } + mSubmit.setOnClickListener(v -> updateVote(true)); + mCancel.setOnClickListener(v -> updateVote(false)); + } + + private void updateVote(boolean isSubmit) { + LiveNetManager.get(mContext) + .updateLiveVote(createVoteModel.getLiveUid(), isSubmit, new HttpCallback() { + @Override + public void onSuccess(String data) { + mCancel.setOnClickListener(null); + mSubmit.setOnClickListener(null); + + if (isSubmit) { + mSubmit.setTextColor(Color.parseColor("#FFB800")); + mCancel.setTextColor(Color.parseColor("#999999")); + } else { + mCancel.setTextColor(Color.parseColor("#FFB800")); + mSubmit.setTextColor(Color.parseColor("#999999")); + } + mSubmit.setTag(createVoteModel.getLiveUid()); + + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + } + + private void endAnchorVote() { + LiveAnchorVoteManager.getInstance().entVote((bean, position) -> { + if (position == -1) { + ToastUtil.show(bean); + return; + } + mClose.setVisibility(View.INVISIBLE); + }); + } + + public void endTimerTask(String msg) { + if (isAnchor) { + LiveAnchorVoteManager.getInstance().clear(); + } + mCancel.setOnClickListener(null); + mSubmit.setOnClickListener(null); + + mSubmit.setText(createVoteModel.getAnswer1()); + mCancel.setText(createVoteModel.getAnswer2()); + + new Timer().schedule(new TimerTask() { + int time = 6; + + @Override + public void run() { + new Handler(Looper.getMainLooper()).post(() -> { + if (--time == 0) { + hide(); + cancel(); + return; + } + mTitle.setText(String.format(mContext.getString(R.string.live_room_vote_over_tip), msg, time + "")); + }); + } + }, 0, 1000); + } + + public void setCreateVoteModel(LiveRoomVoteModel createVoteModel) { + try { + if (createVoteModel.getStatus() == 0) { + hide(); + return; + } + this.createVoteModel = createVoteModel; + mTitle.setText(createVoteModel.getContent()); + mSubmit.setText(createVoteModel.getAnswer1()); + mCancel.setText(createVoteModel.getAnswer2()); + mCancel.setOnClickListener(null); + mSubmit.setOnClickListener(null); + if (mSubmit.getTag() == null || !mSubmit.getTag().equals(createVoteModel.getLiveUid())) { + mSubmit.setTextColor(Color.WHITE); + mCancel.setTextColor(Color.WHITE); + initClick(); + } + if (!StringUtil.isEmpty(createVoteModel.getVote())) { + mCancel.setOnClickListener(null); + mSubmit.setOnClickListener(null); + + if (createVoteModel.isVoteLeft()) { + mSubmit.setTextColor(Color.parseColor("#FFB800")); + mCancel.setTextColor(Color.parseColor("#999999")); + } else { + mCancel.setTextColor(Color.parseColor("#FFB800")); + mSubmit.setTextColor(Color.parseColor("#999999")); + } + mSubmit.setTag(createVoteModel.getLiveUid()); + } + if (createVoteModel.getAnswer1Num() == 0 && createVoteModel.getAnswer2Num() == 0) { + mProgress.setMax(20); + setLength(10); + } else { + mProgress.setMax(createVoteModel.getAnswer1Num() + createVoteModel.getAnswer2Num()); + setLength(createVoteModel.getAnswer1Num()); + } + show(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + public void setLength(int length) { + length = mProgress.getMax() - length; + mProgress.setProgress(length); + } + + private void hideAnchorVote() { + boolean hide = mAnchorVoteHide.getTag() == null || (boolean) mAnchorVoteHide.getTag(); + Animation animation; + if (hide) { + animation = AnimationUtils.loadAnimation(mContext, R.anim.view_live_anchor_vote_out); + } else { + animation = AnimationUtils.loadAnimation(mContext, R.anim.view_live_anchor_vote_in); + } + animation.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + if (!hide) { + voteRoot.setVisibility(View.VISIBLE); + mAnchorVoteHide.setVisibility(View.VISIBLE); + mVoteShow.setVisibility(View.GONE); + if (isAnchor) { + mClose.setVisibility(View.VISIBLE); + } + } + } + + @Override + public void onAnimationEnd(Animation animation) { + if (hide) { + voteRoot.setVisibility(View.INVISIBLE); + mAnchorVoteHide.setVisibility(View.GONE); + mVoteShow.setVisibility(View.VISIBLE); + if (isAnchor) { + mClose.setVisibility(View.INVISIBLE); + } + } + mAnchorVoteHide.setTag(!hide); + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + }); + voteRoot.startAnimation(animation); + } + + public void setMarginPosition(int position) { + RelativeLayout.LayoutParams voteLayoutParams = (RelativeLayout.LayoutParams) voteLayout.getLayoutParams(); + voteLayoutParams.topMargin = position; + voteLayout.setLayoutParams(voteLayoutParams); + } + + public void show() { + voteLayout.setVisibility(View.VISIBLE); + } + + public void hide() { + voteLayout.setVisibility(View.GONE); + mSubmit.setTag(null); + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 1b409fe14..18ca369c4 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -71,6 +71,7 @@ import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.LevelBean; import com.yunbao.common.bean.LinkMicUserBean; import com.yunbao.common.bean.LiveAnchorCallMeModel; +import com.yunbao.common.bean.LiveRoomVoteModel; import com.yunbao.common.bean.LiveAnchorSayModel; import com.yunbao.common.bean.LiveBean; import com.yunbao.common.bean.LiveGiftBean; @@ -99,6 +100,7 @@ import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.RandomPkManager; +import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DialogUitl; @@ -148,6 +150,7 @@ import com.yunbao.live.dialog.LiveHDDialogFragment; import com.yunbao.live.dialog.LiveUserAnchorMailBoxWebInfoPopDialog; import com.yunbao.live.dialog.LiveUserDialogFragment; import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience; +import com.yunbao.live.event.LiveAnchorEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.event.LiveRoomChangeEvent; import com.yunbao.live.http.LiveHttpConsts; @@ -157,6 +160,7 @@ import com.yunbao.live.presenter.LiveEnterRoomAnimPresenter; import com.yunbao.live.presenter.LiveGiftAnimPresenter; import com.yunbao.live.presenter.LiveLightAnimPresenter; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; +import com.yunbao.live.utils.LiveRoomVoteManager; import com.yunbao.live.utils.LiveTextRender; import com.yunbao.live.utils.LoadDian9TuUtil; @@ -352,6 +356,9 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis private TextView mAnchorSayText; private ImageView mAnchorSayHide; //----!主播说组件---// + //----投票组件---// + private LiveRoomVoteManager voteManager; + //----!投票组件---// private Banner topBanner1, topBanner2;//心愿单&联系方式 public SVGAImageView svga_new_user_gif, svga_new_user_double, svga_new_user_follow; private String mAnchorName;//主播名字 @@ -996,6 +1003,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis }; mRoot = (ViewGroup) findViewById(R.id.root); + voteManager = new LiveRoomVoteManager(mContext, mRoot); mAvatar = (ImageView) findViewById(R.id.avatar); mLevelAnchor = (ImageView) findViewById(R.id.level_anchor); @@ -1085,6 +1093,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis RelativeLayout.LayoutParams msgLayoutLayoutParams = (RelativeLayout.LayoutParams) msgLayout.getLayoutParams(); msgLayoutLayoutParams.topMargin = topMargin + DpUtil.dp2px(50); msgLayout.setLayoutParams(msgLayoutLayoutParams); + voteManager.setMarginPosition(topMargin + DpUtil.dp2px(50)); RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) mChatRecyclerView.getLayoutParams(); @@ -1475,6 +1484,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (!IMLoginManager.get(mContext).hintChat()) { msgLayout.setVisibility(View.VISIBLE); } + AppManager.runDebugCode(() -> msgLayout.setVisibility(View.GONE)); + voteManager.hide(); if (d_pk_view != null) { d_pk_view.setVisibility(View.GONE); } @@ -3104,7 +3115,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis if (mContext instanceof LiveAudienceActivity) { int type = 0; GuardUserModel model = new GuardUserModel(); - if (TextUtils.isEmpty(guardUserModel.getGuardType())) { + if (guardUserModel != null && TextUtils.isEmpty(guardUserModel.getGuardType())) { type = Integer.parseInt(guardUserModel.getGuardType()); } if (chatBean.getGuardType() != 0 && chatBean.getGuardType() > type) { @@ -3669,6 +3680,39 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } } + public void setVoteData(String question, String answer1, String answer2, String num1, String num2) { + try { + LiveRoomVoteModel voteModel = new LiveRoomVoteModel(); + voteModel.setStatus(1); + voteModel.setContent(question); + voteModel.setAnswer1(answer1); + voteModel.setAnswer2(answer2); + voteModel.setAnswer1Num(Integer.parseInt(num1)); + voteModel.setAnswer2Num(Integer.parseInt(num2)); + voteModel.setLiveUid(mLiveUid); + Log.i("voteManager", voteManager.toString()); + voteManager.setCreateVoteModel(voteModel); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + public void dismissVote(String msg, String data) { + voteManager.endTimerTask(msg); + LiveChatBean bean = new LiveChatBean(); + bean.setType(LiveChatBean.SYSTEM3_COLOR); + bean.setContent(data); + mLiveChatAdapter.insertItem(bean); + } + + public void setVoteData(LiveRoomVoteModel voteModel) { + Log.i("voteModel", voteModel.toString()); + voteModel.setLiveUid(mLiveUid); + voteManager.setCreateVoteModel(voteModel); + } + + private static class LiveRoomHandler extends Handler { private LiveRoomViewHolder mLiveRoomViewHolder; @@ -4232,6 +4276,33 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } } + @Subscribe(threadMode = ThreadMode.MAIN) + public void updateSubForAnchor(LiveAnchorEvent event) { + if (mContext instanceof LiveAudienceActivity) { + return; + } + if (event.getType() == LiveAnchorEvent.LiveAnchorType.VOTE_CREATE) { + voteManager.setCreateVoteModel((LiveRoomVoteModel) event.getObject()); + } else if (event.getType() == LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_END) { + LiveRoomVoteModel voteModel = JSONObject.parseObject(event.getObject().toString(), LiveRoomVoteModel.class); + Log.i(">>>", voteModel.toString()); + String content = voteModel.getResult(); + if (!StringUtil.isEmpty(voteModel.getOptionText())) { + content = voteModel.getResult().replace(voteModel.getOptionText(), "" + voteModel.getOptionText() + ""); + } + dismissVote(voteModel.getResult(), content); + } else if (event.getType() == LiveAnchorEvent.LiveAnchorType.VOTE_ANCHOR_UPDATE) { + JSONObject map = (JSONObject) event.getObject(); + setVoteData( + map.getString("question"), + map.getString("answer1"), + map.getString("answer2"), + map.getString("num1"), + map.getString("num2") + ); + } + } + @Subscribe(threadMode = ThreadMode.MAIN) public void updateSub(LiveAudienceEvent event) { switch (event.getType()) { @@ -4914,6 +4985,9 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void onBannerClick(List datas, int position) { if (datas.size() > 0) { + if (position >= mTopBannerList.size()) { + position = 0; + } if (mTopBannerList.get(position).getType() == TopBannerCustomViewHolder.TYPE_CALL_ANCHOR) { Dialog loading = DialogUitl.loadingDialog(mContext); loading.show(); @@ -4999,7 +5073,9 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis call.setType(TopBannerCustomViewHolder.TYPE_CALL_ANCHOR); mTopBannerList.add(0, call); topBanner1.update(mTopBannerList); - topBanner2.update(mTopBannerList); + if (topBanner2.getVisibility() == View.VISIBLE) { + topBanner2.update(mTopBannerList); + } } } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index ec5f3a44d..40aff0c3d 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -269,6 +269,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void run() { + try{ + Log.e("ImgLoader1", data.getAvatar()); if (mLiveRyLinkMicPkPresenter != null) { mLiveRyLinkMicPkPresenter.clearData(); @@ -364,6 +366,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveLinkMicPresenter.setSocketClient(mSocketClient); } enterRoomNew(); + + }catch (Exception e){ + e.printStackTrace(); + } } }); @@ -497,6 +503,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //初始化顶部banner mLiveRoomViewHolder.initTopBanner(); mLiveRoomViewHolder.updateTopBanner(); + mLiveRoomViewHolder.setVoteData(data.getEnterRoomInfo().getVoteModel()); isattention = Integer.parseInt(data.getEnterRoomInfo().getIsattention()); if (isattention == 0) { diff --git a/live/src/main/res/anim/view_live_anchor_vote_in.xml b/live/src/main/res/anim/view_live_anchor_vote_in.xml new file mode 100644 index 000000000..66653d76e --- /dev/null +++ b/live/src/main/res/anim/view_live_anchor_vote_in.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/live/src/main/res/anim/view_live_anchor_vote_out.xml b/live/src/main/res/anim/view_live_anchor_vote_out.xml new file mode 100644 index 000000000..7cc876eeb --- /dev/null +++ b/live/src/main/res/anim/view_live_anchor_vote_out.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/background_292929.xml b/live/src/main/res/drawable/background_292929.xml new file mode 100644 index 000000000..1d68201b3 --- /dev/null +++ b/live/src/main/res/drawable/background_292929.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/background_cc000.xml b/live/src/main/res/drawable/background_cc000.xml new file mode 100644 index 000000000..a242d6264 --- /dev/null +++ b/live/src/main/res/drawable/background_cc000.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/background_live_vote_cc000.xml b/live/src/main/res/drawable/background_live_vote_cc000.xml new file mode 100644 index 000000000..985c06422 --- /dev/null +++ b/live/src/main/res/drawable/background_live_vote_cc000.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_live_room_vote_hide.xml b/live/src/main/res/drawable/bg_live_room_vote_hide.xml new file mode 100644 index 000000000..8fc2af891 --- /dev/null +++ b/live/src/main/res/drawable/bg_live_room_vote_hide.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/live_room_qa_progress.xml b/live/src/main/res/drawable/live_room_qa_progress.xml new file mode 100644 index 000000000..586780551 --- /dev/null +++ b/live/src/main/res/drawable/live_room_qa_progress.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/dialog_anchor_call_edit_app.xml b/live/src/main/res/layout/dialog_anchor_call_edit_app.xml index 329aea0e5..5002ca0bd 100644 --- a/live/src/main/res/layout/dialog_anchor_call_edit_app.xml +++ b/live/src/main/res/layout/dialog_anchor_call_edit_app.xml @@ -69,7 +69,7 @@ android:layout_marginTop="16dp" android:layout_marginEnd="16dp" android:background="@drawable/bg_live_ready_btn2" - android:text="保存" + android:text="@string/save" android:textColor="@color/white" android:textSize="16sp" app:layout_constraintEnd_toEndOf="parent" diff --git a/live/src/main/res/layout/dialog_live_anchor_create_qa.xml b/live/src/main/res/layout/dialog_live_anchor_create_qa.xml new file mode 100644 index 000000000..a88e63a8c --- /dev/null +++ b/live/src/main/res/layout/dialog_live_anchor_create_qa.xml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + +