diff --git a/common/src/main/java/com/yunbao/common/bean/PrankGiftResultBean.java b/common/src/main/java/com/yunbao/common/bean/PrankGiftResultBean.java new file mode 100644 index 000000000..3835f31d3 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/PrankGiftResultBean.java @@ -0,0 +1,33 @@ +package com.yunbao.common.bean; + +import java.util.List; + +public class PrankGiftResultBean extends BaseModel{ + private List prank_list; + private String status; + private String prank_type; + + public List getPrank_list() { + return prank_list; + } + + public void setPrank_list(List prank_list) { + this.prank_list = prank_list; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getPrank_type() { + return prank_type; + } + + public void setPrank_type(String prank_type) { + this.prank_type = prank_type; + } +} 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 f9396488f..eda563660 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -54,6 +54,7 @@ import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.OpenAdModel; import com.yunbao.common.bean.PkRankBean; import com.yunbao.common.bean.PrankGiftBean; +import com.yunbao.common.bean.PrankGiftResultBean; import com.yunbao.common.bean.PrankHttpTurntableBean; import com.yunbao.common.bean.QuickGiftSendGiftModel; import com.yunbao.common.bean.RandomPkUserBean; @@ -504,7 +505,10 @@ public interface PDLiveApi { * 获取整蛊列表 */ @GET("/api/public/?service=Prank.prankList") - Observable>> prankList(@Query("anchor_id") String anchor_id); + Observable>prankList( + @Query("anchor_id") String anchor_id, + @Query("prank_type") String prank_type + ); /** * 设置礼物整蛊 @@ -512,9 +516,9 @@ public interface PDLiveApi { @GET("/api/public/?service=Prank.setPrank") Observable>> setPrank( @Query("anchor_id") String anchor_id, - @Query("gift_id") String gift_id, - @Query("gift_num") String gift_num, - @Query("prank_content") String prank_content + @Query("status") String status, + @Query("prank_json") String prank_json, + @Query("prank_type") String prank_type ); /** 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 c781e647d..9dd7d0af1 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 @@ -54,6 +54,7 @@ import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.OpenAdModel; import com.yunbao.common.bean.PkRankBean; import com.yunbao.common.bean.PrankGiftBean; +import com.yunbao.common.bean.PrankGiftResultBean; import com.yunbao.common.bean.PrankHttpTurntableBean; import com.yunbao.common.bean.QuickGiftSendGiftModel; import com.yunbao.common.bean.RandomPkUserBean; @@ -879,9 +880,9 @@ public class LiveNetManager { /** * 获取转盘整蛊列表 */ - public void getPrankGiftList(String mLiveUid, HttpCallback> callback) { + public void getPrankGiftList(String mLiveUid, String prank_type,HttpCallback callback) { API.get().pdLiveApi(mContext) - .prankList(mLiveUid) + .prankList(mLiveUid,prank_type) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(responseModel -> { @@ -901,9 +902,9 @@ public class LiveNetManager { /** * 设置礼物整蛊 */ - public void setPrankGift(String mLiveUid, String gift_id, String gift_num, String prank_content, HttpCallback callback) { + public void setPrankGift(String mLiveUid, String status, String prank_json,String prank_type, HttpCallback callback) { API.get().pdLiveApi(mContext) - .setPrank(mLiveUid, gift_id, gift_num, prank_content) + .setPrank(mLiveUid, status, prank_json, prank_type) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(responseModel -> { diff --git a/live/src/main/java/com/yunbao/live/adapter/LivePrankRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LivePrankRecyclerAdapter.java index 83901573b..d88f1c850 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LivePrankRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LivePrankRecyclerAdapter.java @@ -1,5 +1,6 @@ package com.yunbao.live.adapter; +import android.annotation.SuppressLint; import android.app.Dialog; import android.content.Context; import android.view.LayoutInflater; @@ -108,7 +109,6 @@ public class LivePrankRecyclerAdapter extends RecyclerView.Adapter { PrankGiftBean bean = (PrankGiftBean) v.getTag(); onItemClickListener.onItemClick(bean.getGiftId(), (Integer) itemView.getTag()); }); - } + @SuppressLint("SetTextI18n") public void setDate(PrankGiftBean bean, int position) { ImgLoader.display(mContext, bean.getIcon(), mIcon); itemView.setTag(position); - mName.setText(bean.getName()); + mName.setText(bean.getName()+"*"+bean.getNum()); mTitle.setText(bean.getTitle()); - mNum.setText(bean.getNum() + ""); mRemove.setTag(bean); } diff --git a/live/src/main/java/com/yunbao/live/dialog/LivePrankAddGiftDialog.java b/live/src/main/java/com/yunbao/live/dialog/LivePrankAddGiftDialog.java index 9c83768cd..4c61ae2f7 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LivePrankAddGiftDialog.java +++ b/live/src/main/java/com/yunbao/live/dialog/LivePrankAddGiftDialog.java @@ -1,7 +1,6 @@ package com.yunbao.live.dialog; import android.content.Context; -import android.graphics.drawable.Drawable; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; @@ -11,9 +10,8 @@ import androidx.annotation.NonNull; import com.lxj.xpopup.XPopup; import com.yunbao.common.bean.PrankGiftBean; import com.yunbao.common.dialog.AbsDialogPopupWindow; -import com.yunbao.common.glide.ImgLoader; 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.WordUtil; import com.yunbao.common.views.weight.ViewClicksAntiShake; @@ -71,6 +69,12 @@ public class LivePrankAddGiftDialog extends AbsDialogPopupWindow { numberText = findViewById(R.id.number_text); contentText = findViewById(R.id.content_text); + ViewClicksAntiShake.clicksAntiShake(backBtn, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + dismiss(); + } + }); ViewClicksAntiShake.clicksAntiShake(giftText, new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { @@ -122,14 +126,20 @@ public class LivePrankAddGiftDialog extends AbsDialogPopupWindow { @Override public void onViewClicks() { PrankGiftBean bean = (PrankGiftBean) giftText.getTag(); + String prankContent = contentText.getText().toString(); if (bean == null) { ToastUtil.show(WordUtil.isNewZh() ? "整蠱禮物不能為空" : "A trick gift can't be empty"); return; } - if (numberText.getTag()==null){ + if (numberText.getTag()==null||StringUtil.isEmpty(prankContent)){ ToastUtil.show(WordUtil.isNewZh() ? "整蠱內容或數量不能為空" : "The content or number of pranks cannot be empty"); return; } + bean.setNum(Integer.parseInt(numberText.getText().toString())); + bean.setTitle(prankContent); + onItemClickListener.onItemClick(bean,0); + dismiss(); + } }); } diff --git a/live/src/main/java/com/yunbao/live/dialog/LivePrankDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LivePrankDialogFragment.java index 5025be9a7..45c28a730 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LivePrankDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LivePrankDialogFragment.java @@ -1,5 +1,6 @@ package com.yunbao.live.dialog; +import android.annotation.SuppressLint; import android.app.Dialog; import android.graphics.Color; import android.os.Bundle; @@ -11,12 +12,17 @@ import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.alibaba.fastjson.JSONArray; import com.google.android.material.tabs.TabLayout; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import com.yunbao.common.bean.PrankGiftBean; +import com.yunbao.common.bean.PrankGiftResultBean; import com.yunbao.common.bean.PrankHttpTurntableBean; import com.yunbao.common.bean.PrankTurntableBean; import com.yunbao.common.dialog.AbsDialogFragment; @@ -26,6 +32,7 @@ import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.L; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.ViewUtils; @@ -35,6 +42,9 @@ import com.yunbao.live.R; import com.yunbao.live.adapter.LivePrankRecyclerAdapter; import com.yunbao.live.socket.SocketRyChatUtil; +import org.json.JSONException; +import org.json.JSONObject; + import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -146,17 +156,9 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O break; } } else { - LiveNetManager.get(mContext).deletePrankGift(mLiveUid, position + "", new HttpCallback() { - @Override - public void onSuccess(PrankHttpTurntableBean data) { - initGiftData(); - } - - @Override - public void onError(String error) { - initGiftData(); - } - }); + giftBeans.remove(position); + recyclerAdapter.setList(giftBeans); + recyclerAdapter.notifyDataSetChanged(); } } }); @@ -210,7 +212,7 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O if ((int) mPrankBtn.getTag() == 0) { setPrankConfig(); } else { - + setGiftBean(recyclerAdapter.getList()); } } @@ -230,7 +232,6 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O mPrankBtn.setTag(0); } - private void initTab() { TabLayout.Tab turntable = mTabLayout.newTab(); TabLayout.Tab gift = mTabLayout.newTab(); @@ -246,6 +247,7 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O gift.setTag(1); mTabLayout.addTab(turntable); mTabLayout.addTab(gift); + mPrankBtn.setTag(0); mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { @@ -273,6 +275,7 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O mTurntableConfigLayout.setVisibility(View.GONE); mGiftConfigLayout.setVisibility(View.VISIBLE); mBtnAddGift.setVisibility(View.VISIBLE); + mGiftNotDate.setVisibility(View.VISIBLE); recyclerAdapter.setViewType(LivePrankRecyclerAdapter.TYPE_GIFT); mPrankBtn.setBackgroundResource(R.drawable.bg_live_prank_gift_set); @@ -283,7 +286,6 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O } mPrankBtn.setTag(1); recyclerAdapter.clearList(); - mGiftNotDate.setVisibility(View.VISIBLE); initGiftData(); } } @@ -301,7 +303,24 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O } private void showGiftDialog() { - new LivePrankAddGiftDialog(mContext).setGiftBeans(giftBeans).showDialog(); + LivePrankAddGiftDialog livePrankAddGiftDialog = new LivePrankAddGiftDialog(mContext).setGiftBeans(giftBeans); + livePrankAddGiftDialog.setOnItemClickListener(new OnItemClickListener() { + @SuppressLint("NotifyDataSetChanged") + @Override + public void onItemClick(PrankGiftBean bean, int position) { + giftBeans.add(bean); + recyclerAdapter.setList(giftBeans); + recyclerAdapter.notifyDataSetChanged(); + if (giftBeans.size() < 6) { + mBtnAddGift.setVisibility(View.VISIBLE); + mGiftNotDate.setVisibility(View.VISIBLE); + } else { + mBtnAddGift.setVisibility(View.GONE); + mGiftNotDate.setVisibility(View.VISIBLE); + } + } + }); + livePrankAddGiftDialog.showDialog(); } private void initGiftConfigLayoutView() { @@ -312,6 +331,7 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O giftTypeTodoText = (TextView) findViewById(R.id.gift_type_todo); giftTypeNowSwitchText = (TextView) findViewById(R.id.gift_type_now_switch); mBtnAddGift = (Button) findViewById(R.id.gift_add_btn); + mBtnAddGift.setVisibility(View.GONE); ViewClicksAntiShake.clicksAntiShake(giftSwitch1Btn, new ViewClicksAntiShake.ViewClicksCallBack() { @Override @@ -356,11 +376,17 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O }); } - private void setGiftBean(PrankGiftBean bean) { - LiveNetManager.get(mContext).setPrankGift(mLiveUid, bean.getGiftId(), bean.getNum() + "", bean.getTitle(), new HttpCallback() { + private void setGiftBean(List prankGiftBeans) { + JSONArray prankJson = getJsonObjects(prankGiftBeans); + LiveNetManager.get(mContext).setPrankGift(mLiveUid, giftSwitch1Btn.getTag().equals("true")?"1":"0", new Gson().toJson(prankJson), "1", new HttpCallback() { @Override public void onSuccess(PrankHttpTurntableBean data) { initGiftData(); + if (WordUtil.isNewZh()) { + ToastUtil.show("設置成功"); + } else { + ToastUtil.show("successful"); + } } @Override @@ -370,21 +396,40 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O }); } + @NonNull + private static JSONArray getJsonObjects(List prankGiftBeans) { + JSONArray prankJson = new JSONArray(); + for (int i = 0; i < prankGiftBeans.size(); i++) { + JsonObject temp = new JsonObject(); + temp.addProperty("gift_id", prankGiftBeans.get(i).getGiftId()); + temp.addProperty("gift_num", prankGiftBeans.get(i).getNum()); + temp.addProperty("prank_content", prankGiftBeans.get(i).getTitle()); + prankJson.add(temp); + } + return prankJson; + } + private void initGiftData() { - LiveNetManager.get(mContext).getPrankGiftList(mLiveUid, new HttpCallback>() { + LiveNetManager.get(mContext).getPrankGiftList(mLiveUid, mPrankBtn.getTag().equals("0")?"2":"1",new HttpCallback() { @Override - public void onSuccess(List data) { - if (data.size() < 6) { - mBtnAddGift.setVisibility(View.VISIBLE); - } else { - mBtnAddGift.setVisibility(View.GONE); + public void onSuccess(PrankGiftResultBean data) { + if(mPrankBtn.getTag().toString().equals("1")){ + if(data.getPrank_list()!=null){ + if (data.getPrank_list().size() < 6) { + mBtnAddGift.setVisibility(View.VISIBLE); + mGiftNotDate.setVisibility(View.VISIBLE); + } else { + mBtnAddGift.setVisibility(View.GONE); + mGiftNotDate.setVisibility(View.VISIBLE); + } + mPrankRecyclerView.setVisibility(View.VISIBLE); + recyclerAdapter.setViewType(LivePrankRecyclerAdapter.TYPE_GIFT); + giftBeans = data.getPrank_list(); + recyclerAdapter.setList(giftBeans); + recyclerAdapter.notifyDataSetChanged(); + } } - mGiftNotDate.setVisibility(View.GONE); - mPrankRecyclerView.setVisibility(View.VISIBLE); - recyclerAdapter.setViewType(LivePrankRecyclerAdapter.TYPE_GIFT); - giftBeans = data; - recyclerAdapter.setList(data); - recyclerAdapter.notifyDataSetChanged(); + /*if (!data.isEmpty()) { } else { diff --git a/live/src/main/java/com/yunbao/live/dialog/LivePrankExplainDialog.java b/live/src/main/java/com/yunbao/live/dialog/LivePrankExplainDialog.java new file mode 100644 index 000000000..05fff8d0e --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/LivePrankExplainDialog.java @@ -0,0 +1,63 @@ +package com.yunbao.live.dialog; + +import android.content.Context; +import android.text.Html; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import com.lxj.xpopup.XPopup; +import com.yunbao.common.dialog.AbsDialogPopupWindow; +import com.yunbao.live.R; + +public class LivePrankExplainDialog extends AbsDialogPopupWindow { + TextView content; + String contentText = "" + + "1、當前整蠱分類有哪些? 當前分爲轉盤整蠱和禮物整蠱。可根據實際情況決定,例如都設置或只設置一種。" + + " " + + "2、轉盤整蠱如何填寫? \n" + + "打開開關→設置價格→填寫6個整蠱→保存設置。\n" + + "\n" + + " 注意:若有人發起整蠱,將提示你完成該整蠱,期間若有人花費鑽石拯救你,則不用完成整蠱。\n" + + "3、禮物整蠱如何填寫? \n" + + "當前分爲禮物數達成整蠱和連擊數最高整蠱。\n" + + "\n" + + "禮物數達成整蠱:打開開關→選擇禮物→填寫數量→填寫整蠱→保存設置。\n" + + "\n" + + "連擊數最高整蠱:打開開關→切換→選擇禮物→填寫整蠱→保存設置。\n" + + "4、整蠱如何填寫? \n" + + "根據你的實際情況決定。例如:唱歌、跳舞、情書、下蹲、吃辣或其他任意才藝。\n" + + "5、我怎麽知道該做哪些整蠱? \n" + + "系統將發送消息至彈幕;\n" + + "你需要做的整蠱會自動挂起。"; + + public LivePrankExplainDialog(@NonNull Context context) { + super(context); + } + + @Override + public void buildDialog(XPopup.Builder builder) { + + } + + @Override + public int bindLayoutId() { + return R.layout.dialog_live_prank_add_gift_number; + } + + @Override + protected void onCreate() { + super.onCreate(); + initView(); + } + + @Override + protected void onDismiss() { + super.onDismiss(); + } + + void initView() { + content = findViewById(R.id.content); + content.setText(Html.fromHtml(contentText)); + } +} diff --git a/live/src/main/res/layout/dialog_live_prank_explain.xml b/live/src/main/res/layout/dialog_live_prank_explain.xml new file mode 100644 index 000000000..5aee17c77 --- /dev/null +++ b/live/src/main/res/layout/dialog_live_prank_explain.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_live_prank_gift.xml b/live/src/main/res/layout/item_live_prank_gift.xml index 843dd2b27..d902716ba 100644 --- a/live/src/main/res/layout/item_live_prank_gift.xml +++ b/live/src/main/res/layout/item_live_prank_gift.xml @@ -1,93 +1,49 @@ - - + + android:textSize="14sp" /> - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/live/src/main/res/values-en/strings.xml b/live/src/main/res/values-en/strings.xml index 411546555..e695323e2 100644 --- a/live/src/main/res/values-en/strings.xml +++ b/live/src/main/res/values-en/strings.xml @@ -128,4 +128,7 @@ You can add up to 6, and it is recommended to add 4. Confirm + Quantity + + Set other quantity (up to 9999) + Trick instructions \ No newline at end of file diff --git a/live/src/main/res/values/strings.xml b/live/src/main/res/values/strings.xml index 9eb4649ab..9d14c000e 100644 --- a/live/src/main/res/values/strings.xml +++ b/live/src/main/res/values/strings.xml @@ -134,4 +134,5 @@ 確定 禮物數量 + 設置其他數量(最多9999) + 整蠱說明