diff --git a/common/src/main/java/com/yunbao/common/bean/PrankGiftBean.java b/common/src/main/java/com/yunbao/common/bean/PrankGiftBean.java new file mode 100644 index 000000000..a7e6c95a7 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/PrankGiftBean.java @@ -0,0 +1,59 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +public class PrankGiftBean extends BaseModel{ + @SerializedName("prank_content") + private String title; + @SerializedName("gift_name") + private String name; + @SerializedName("gift_icon") + private String icon; + @SerializedName("gift_num") + private int num; + @SerializedName("gift_id") + private String giftId; + + public PrankGiftBean() { + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getGiftId() { + return giftId; + } + + public void setGiftId(String giftId) { + this.giftId = giftId; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/PrankHttpTurntableBean.java b/common/src/main/java/com/yunbao/common/bean/PrankHttpTurntableBean.java new file mode 100644 index 000000000..815ddec46 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/PrankHttpTurntableBean.java @@ -0,0 +1,121 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.utils.StringUtil; + +public class PrankHttpTurntableBean extends BaseModel { + @SerializedName("id") + private int id; + @SerializedName("anchor_id") + private String anchor_id; + @SerializedName("coin") + private long coin = 1000; + @SerializedName("hope_coin") + private long hopeCoin = 1000; + @SerializedName("turntable_one") + private String turntable1; + @SerializedName("turntable_two") + private String turntable2; + @SerializedName("turntable_three") + private String turntable3; + @SerializedName("turntable_four") + private String turntable4; + @SerializedName("turntable_five") + private String turntable5; + @SerializedName("turntable_six") + private String turntable6; + @SerializedName("status") + private int status; + + public PrankHttpTurntableBean() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getAnchor_id() { + return anchor_id; + } + + public void setAnchor_id(String anchor_id) { + this.anchor_id = anchor_id; + } + + public long getCoin() { + return coin; + } + + public void setCoin(long coin) { + this.coin = coin; + } + + public long getHopeCoin() { + return hopeCoin; + } + + public void setHopeCoin(long hopeCoin) { + this.hopeCoin = hopeCoin; + } + + public String getTurntable1() { + return turntable1; + } + + public void setTurntable1(String turntable1) { + this.turntable1 = turntable1; + } + + public String getTurntable2() { + return turntable2; + } + + public void setTurntable2(String turntable2) { + this.turntable2 = turntable2; + } + + public String getTurntable3() { + return turntable3; + } + + public void setTurntable3(String turntable3) { + this.turntable3 = turntable3; + } + + public String getTurntable4() { + return turntable4; + } + + public void setTurntable4(String turntable4) { + this.turntable4 = turntable4; + } + + public String getTurntable5() { + return turntable5; + } + + public void setTurntable5(String turntable5) { + this.turntable5 = turntable5; + } + + public String getTurntable6() { + return turntable6; + } + + public void setTurntable6(String turntable6) { + this.turntable6 = turntable6; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/PrankTurntableBean.java b/common/src/main/java/com/yunbao/common/bean/PrankTurntableBean.java new file mode 100644 index 000000000..4e1124628 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/PrankTurntableBean.java @@ -0,0 +1,26 @@ +package com.yunbao.common.bean; + + +public class PrankTurntableBean extends BaseModel { + private int id; + private String context; + + public PrankTurntableBean() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getContext() { + return context; + } + + public void setContext(String context) { + this.context = context; + } +} 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 22c397473..3ceaaa533 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -20,6 +20,8 @@ import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.PkRankBean; import com.yunbao.common.bean.RandomPkUserBean; import com.yunbao.common.bean.RankPkInfoBean; +import com.yunbao.common.bean.PrankGiftBean; +import com.yunbao.common.bean.PrankHttpTurntableBean; import com.yunbao.common.bean.SearchModel; import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.SlideInBannerModel; @@ -393,4 +395,61 @@ public interface PDLiveApi { */ @GET("/api/public/?service=Ranking.getRankingInfo") Observable> getRankingInfo(); + + /** + * 获取转盘整蛊列表 + */ + @GET("/api/public/?service=Prank.getAnchorPrankTurntable") + Observable> getAnchorPrankTurntable( + @Query("anchor_id") String anchor_id + ); + /** + * 提交整蛊 + */ + @GET("/api/public/?service=Prank.setAnchorPrankTurntable") + Observable>> setAnchorPrankTurntable( + @Query("anchor_id") String anchor_id, + @Query("coin") String coin, + @Query("turntable_one") String turntable_one, + @Query("turntable_two") String turntable_two, + @Query("turntable_three") String turntable_three, + @Query("turntable_four") String turntable_four, + @Query("turntable_five") String turntable_five, + @Query("turntable_six") String turntable_six, + @Query("status") String status + ); + /** + * 转盘整蛊结束后调用的接口 + */ + @GET("/api/public/?service=Prank.endPrankTurntable") + Observable>> endPrankTurntable( + @Query("anchor_id") String anchor_id + ); + + + /** + * 获取整蛊列表 + */ + @GET("/api/public/?service=Prank.prankList") + Observable>> prankList( @Query("anchor_id") String anchor_id); + + /** + * 设置礼物整蛊 + */ + @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 + ); + /** + * 删除礼物整蛊 + */ + @GET("/api/public/?service=Prank.deletePrank") + Observable>> deletePrank( + @Query("anchor_id") String anchor_id, + @Query("prank_index") String prank_index + ); + } 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 184dd7cdd..b5ff172fb 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 @@ -19,6 +19,9 @@ import com.yunbao.common.bean.LiveRoomActivityBanner; import com.yunbao.common.bean.NobleRankHideUserListModel; import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.PkRankBean; +import com.yunbao.common.bean.PrankGiftBean; +import com.yunbao.common.bean.PrankHttpTurntableBean; +import com.yunbao.common.bean.PrankTurntableBean; import com.yunbao.common.bean.RandomPkUserBean; import com.yunbao.common.bean.RankPkInfoBean; import com.yunbao.common.bean.SetAttentsModel; @@ -36,6 +39,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; +import retrofit2.http.Query; /** @@ -742,6 +746,158 @@ public class LiveNetManager { }).isDisposed(); } + /** + * 获取转盘整蛊列表 + */ + public void getAnchorPrankTurntable(String mLiveUid, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .getAnchorPrankTurntable(mLiveUid) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(responseModel -> { + if (callback != null) { + callback.onSuccess(responseModel.getData().getInfo()); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + + /** + * 提交转盘整蛊 + */ + public void setAnchorPrankTurntable(String mLiveUid, String coin, + String turntable_one, + String turntable_two, + String turntable_three, + String turntable_four, + String turntable_five, + String turntable_six, + String status, + HttpCallback callback) { + API.get().pdLiveApi(mContext) + .setAnchorPrankTurntable(mLiveUid, + coin, + turntable_one, + turntable_two, + turntable_three, + turntable_four, + turntable_five, + turntable_six, + status) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .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 getPrankGiftList(String mLiveUid, HttpCallback> callback) { + API.get().pdLiveApi(mContext) + .prankList(mLiveUid) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(responseModel -> { + if (callback != null) { + callback.onSuccess(responseModel.getData().getInfo()); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + + /** + * 设置礼物整蛊 + */ + public void setPrankGift(String mLiveUid, String gift_id, String gift_num, String prank_content, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .setPrank(mLiveUid, gift_id, gift_num, prank_content) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(responseModel -> { + if (callback != null) { + callback.onSuccess(null); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + + /** + * 删除礼物整蛊 + */ + public void deletePrankGift(String mLiveUid, String prank_index, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .deletePrank(mLiveUid, prank_index) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(responseModel -> { + if (callback != null) { + callback.onSuccess(null); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + + /** + * 整蛊结束 + */ + public void endPrankTurntable(String mLiveUid,HttpCallback callback){ + API.get().pdLiveApi(mContext) + .endPrankTurntable(mLiveUid) + .subscribeOn(Schedulers.io()) + .subscribe(responseModel -> { + if (callback != null) { + callback.onSuccess(null); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + + } + /** * 直播间取消网络请求 */ 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 f3d430686..cf12e812e 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -74,6 +74,7 @@ import com.yunbao.live.dialog.FreePkDialogFragment; import com.yunbao.live.dialog.LiveLinkMicListDialogFragment; import com.yunbao.live.dialog.LiveNewFunctionDialogFragment; import com.yunbao.live.dialog.LiveNewWishListDialogFragment; +import com.yunbao.live.dialog.LivePrankDialogFragment; import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience; import com.yunbao.live.dialog.RandomPkDialogFragment; import com.yunbao.live.event.LinkMicTxMixStreamEvent; @@ -279,7 +280,10 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl public void onClick(int functionID) { switch (functionID) { case Constants.LIVE_FUNC_ZG://zg - ToastUtil.show("開發中,敬請期待"); + // ToastUtil.show("開發中,敬請期待"); + LivePrankDialogFragment fragment = new LivePrankDialogFragment(); + fragment.setmLiveUid(mLiveUid); + fragment.show(getSupportFragmentManager(), "LivePrankDialogFragment"); break; case Constants.LIVE_FUNC_MIC://語音 //ToastUtil.show("開發中,敬請期待"); @@ -1295,7 +1299,9 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl @Override public void prankTurntable(String msgtype, int time, JSONObject jsonObject) { - + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.closeAndOpenTrickery(msgtype, time, jsonObject); + } } diff --git a/live/src/main/java/com/yunbao/live/adapter/LivePrankRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LivePrankRecyclerAdapter.java new file mode 100644 index 000000000..a84f4056c --- /dev/null +++ b/live/src/main/java/com/yunbao/live/adapter/LivePrankRecyclerAdapter.java @@ -0,0 +1,209 @@ +package com.yunbao.live.adapter; + +import android.app.Dialog; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.yunbao.common.bean.PrankGiftBean; +import com.yunbao.common.bean.PrankTurntableBean; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.live.R; + +import java.util.ArrayList; +import java.util.List; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +public class LivePrankRecyclerAdapter extends RecyclerView.Adapter { + public static final int TYPE_TURNTABLE = 0; + public static final int TYPE_GIFT = 1; + + private Context mContext; + private List list = new ArrayList<>(); + private OnItemClickListener onItemClickListener; + private int viewType = TYPE_TURNTABLE; + + + public LivePrankRecyclerAdapter(Context mContext) { + this.mContext = mContext; + } + + public void setList(List list) { + this.list = list; + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.onItemClickListener = onItemClickListener; + } + + public void setViewType(int viewType) { + this.viewType = viewType; + } + + @Override + public int getItemViewType(int position) { + return this.viewType; + } + + @NonNull + @Override + public PrankRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + if (viewType == TYPE_TURNTABLE) { + return new TurntableViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_live_prank_turntable_config, parent, false)); + } else { + return new GiftViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_live_prank_gift, parent, false)); + } + } + + @Override + public void onBindViewHolder(@NonNull PrankRecyclerViewHolder holder, int position) { + if (viewType == TYPE_TURNTABLE) { + ((TurntableViewHolder) holder).setDate((PrankTurntableBean) list.get(position), position); + } else { + ((GiftViewHolder) holder).setDate((PrankGiftBean) list.get(position), position); + } + } + + @Override + public int getItemCount() { + return list.size(); + } + + public void clearList() { + list.clear(); + notifyDataSetChanged(); + } + + public List getList() { + return (List) list; + } + + public boolean getViewTypeOfList() { + return viewType==TYPE_TURNTABLE; + } + + public static abstract class PrankRecyclerViewHolder extends RecyclerView.ViewHolder { + + + public PrankRecyclerViewHolder(@NonNull View itemView) { + super(itemView); + } + + + } + + public class GiftViewHolder extends PrankRecyclerViewHolder { + private ImageView mIcon; + private TextView mTitle; + private TextView mName; + private TextView mNum; + private ImageView mRemove; + + public GiftViewHolder(View itemView) { + super(itemView); + mIcon = itemView.findViewById(R.id.gift_icon); + mTitle = itemView.findViewById(R.id.gift_title); + mName = itemView.findViewById(R.id.gift_name); + mNum = itemView.findViewById(R.id.gift_num); + mRemove = itemView.findViewById(R.id.gift_close); + mRemove.setOnClickListener(v -> { + PrankGiftBean bean = (PrankGiftBean) v.getTag(); + onItemClickListener.onItemClick(bean.getGiftId(), (Integer) itemView.getTag()); + }); + + } + + public void setDate(PrankGiftBean bean, int position) { + ImgLoader.display(mContext, bean.getIcon(), mIcon); + itemView.setTag(position); + mName.setText(bean.getName()); + mTitle.setText(bean.getTitle()); + mNum.setText(bean.getNum() + ""); + mRemove.setTag(bean); + } + + } + + + public class TurntableViewHolder extends PrankRecyclerViewHolder { + private TextView title; + private TextView probability; + private TextView context; + + public TurntableViewHolder(@NonNull View itemView) { + super(itemView); + title = itemView.findViewById(R.id.prank_turntable_title); + probability = itemView.findViewById(R.id.prank_turntable_probability); + context = itemView.findViewById(R.id.prank_turntable_val); + context.setOnClickListener(v -> { + DialogUitl.showSimpleInputDialog(mContext, "填寫整蠱內容", DialogUitl.INPUT_TYPE_TEXT, 10, new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + if (content.length() >= 2 && content.length() <= 10) { + context.setText(content); + onItemClickListener.onItemClick(content, ((PrankTurntableBean)list.get((Integer) itemView.getTag())).getId()); + ((PrankTurntableBean)list.get((Integer) itemView.getTag())).setContext(content); + dialog.dismiss(); + } /*else if (content.length() == 0) { + context.setText(""); + onItemClickListener.onItemClick(content, ((PrankTurntableBean)list.get((Integer) itemView.getTag())).getId()); + dialog.dismiss(); + } */else { + ToastUtil.show("最少2個字,最多10個字"); + } + } + }); + }); + } + + public void setDate(PrankTurntableBean bean, int position) { + title.setText("轉盤" + getChineseNum(bean.getId()) + "號位"); + probability.setText(getProbability(bean.getId())); + context.setText(bean.getContext()); + itemView.setTag(position); + } + + private String getChineseNum(int id) { + switch (id) { + case 1: + return "一"; + case 2: + return "二"; + case 3: + return "三"; + case 4: + return "四"; + case 5: + return "五"; + case 6: + return "六"; + } + return ""; + } + + private String getProbability(int id) { + switch (id) { + case 1: + return "抽取幾率:40%"; + case 2: + return "抽取幾率:30%"; + case 3: + return "抽取幾率:15%"; + case 4: + return "抽取幾率:10%"; + case 5: + return "抽取幾率:4%"; + default: + return "抽取幾率:1%"; + } + } + } +} \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/dialog/GiftPopDialog.java b/live/src/main/java/com/yunbao/live/dialog/GiftPopDialog.java new file mode 100644 index 000000000..9821e70e2 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/GiftPopDialog.java @@ -0,0 +1,278 @@ +package com.yunbao.live.dialog; + +import android.app.Dialog; +import android.content.Context; +import android.graphics.drawable.ColorDrawable; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; +import android.view.inputmethod.InputMethodManager; +import android.widget.PopupWindow; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.TextView; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.bean.PrankGiftBean; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.live.R; +import com.yunbao.live.adapter.GiftTopAdapter; +import com.yunbao.live.adapter.LiveGiftPagerAdapter; +import com.yunbao.live.adapter.LiveGiftPagerAdapter.ActionListener; +import com.yunbao.live.bean.GiftTopBean; +import com.yunbao.live.http.LiveHttpUtil; + +import java.util.ArrayList; +import java.util.List; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager.widget.ViewPager; + +public class GiftPopDialog extends PopupWindow implements ActionListener, View.OnClickListener { + + private View mParent; + private Context mContext; + private View mContentView; + private LiveGiftPagerAdapter mLiveGiftPagerAdapter; + private GiftPopDialog.ActionListener mActionListener; + private View mLoading; + private RecyclerView items; + private ViewPager mViewPager; + private RadioGroup mRadioGroup; + private TextView mBtnSend, mBtnContext; + public int type = 0; + private GiftTopAdapter giftTopAdapter; + private String type_name; + private View mBack; + private View mBtn; + private LiveGiftBean bean; + private String prangContext; + private int prangNum; + private InputMethodManager imm; + + private void initView(View mRootView) { + mLoading = mRootView.findViewById(R.id.loading); + items = (RecyclerView) mRootView.findViewById(R.id.items); + mViewPager = (ViewPager) mRootView.findViewById(R.id.viewPager); + mRadioGroup = (RadioGroup) mRootView.findViewById(R.id.radio_group); + mBtnSend = mRootView.findViewById(R.id.btn_send); + mBtnContext = mRootView.findViewById(R.id.btn_context); + mBtn = mRootView.findViewById(R.id.gift_btn); + mBack = mRootView.findViewById(R.id.gift_back); + final LinearLayoutManager manager = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false); + items.setLayoutManager(manager); + mViewPager.setOffscreenPageLimit(5); + giftTopAdapter = new GiftTopAdapter(mContext); + items.setAdapter(giftTopAdapter); + items.setOnClickListener(this); + mBtn.setOnClickListener(this); + mBack.setOnClickListener(this); + mBtnSend.setOnClickListener(this); + mBtnContext.setOnClickListener(this); + imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE); + + giftTopAdapter.setOnItemClickListener((bean, position) -> { + manager.scrollToPositionWithOffset(position, 0); + giftTopAdapter.notifyDataSetChanged(); + type = position; + type_name = bean.getName(); + initDate(); + //点击礼物,展示礼物列表 + if (mViewPager != null) { + mViewPager.setVisibility(View.VISIBLE); + mRadioGroup.setVisibility(View.VISIBLE); + } + }); + mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + + } + + @Override + public void onPageSelected(int position) { + if (mRadioGroup != null) { + ((RadioButton) mRadioGroup.getChildAt(position)).setChecked(true); + } + } + + @Override + public void onPageScrollStateChanged(int state) { + + } + }); + } + + public GiftPopDialog(Context mContext, View parent, GiftPopDialog.ActionListener actionListener) { + this.mContext = mContext; + mParent = parent; + mActionListener = actionListener; + mContentView = LayoutInflater.from(mContext).inflate(R.layout.dialog_live_select_gift_wrap, null); + ViewParent viewParent = mContentView.getParent(); + if (viewParent != null) { + ((ViewGroup) viewParent).removeView(mContentView); + } + setContentView(mContentView); + setWidth(ViewGroup.LayoutParams.MATCH_PARENT); + setHeight(ViewGroup.LayoutParams.MATCH_PARENT); + setBackgroundDrawable(new ColorDrawable()); + setOutsideTouchable(true); + setFocusable(true); + setAnimationStyle(R.style.leftToRightAnim); + setOnDismissListener(new OnDismissListener() { + @Override + public void onDismiss() { + if (mActionListener != null) { + if (bean == null || StringUtil.isEmpty(prangContext) || prangNum==0) { + mActionListener.onDismiss(); + return; + } + PrankGiftBean giftBean = new PrankGiftBean(); + giftBean.setGiftId(bean.getId() + ""); + giftBean.setNum(prangNum); + giftBean.setIcon(bean.getIcon()); + giftBean.setTitle(prangContext); + giftBean.setName(bean.getName()); + mActionListener.onSelectGift(giftBean); + System.out.println("gift.bean = " + bean); + } + ViewParent viewParent = mContentView.getParent(); + if (viewParent != null) { + ((ViewGroup) viewParent).removeView(mContentView); + } + mContentView = null; + } + }); + initView(mContentView); + initDate(); + } + + private void initDate() { + LiveHttpUtil.getNewGiftList(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + JSONArray list = obj.getJSONArray("listarray"); + setDate(list); + + } + } + + @Override + public void onFinish() { + if (mLoading != null) { + mLoading.setVisibility(View.INVISIBLE); + } + } + }); + } + + private void setDate(JSONArray list) { + List name = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + JSONObject data = list.getJSONObject(i); + GiftTopBean giftTopBean = new GiftTopBean(); + giftTopBean.setName(data.getString("name")); + name.add(giftTopBean); + } + + giftTopAdapter.setList(name); + + + JSONObject obj2 = list.getJSONObject(type); + String giftJson = obj2.getString("giftlist"); + showGiftList(JSON.parseArray(giftJson, LiveGiftBean.class)); + } + + private void showGiftList(List list) { + + mLiveGiftPagerAdapter = new LiveGiftPagerAdapter(mContext, list); + mLiveGiftPagerAdapter.setActionListener(this); + + mViewPager.setAdapter(mLiveGiftPagerAdapter); + LayoutInflater inflater = LayoutInflater.from(mContext); + mRadioGroup.removeAllViews(); + for (int i = 0, size = mLiveGiftPagerAdapter.getCount(); i < size; i++) { + RadioButton radioButton = (RadioButton) inflater.inflate(R.layout.view_gift_indicator, mRadioGroup, false); + radioButton.setId(i + 10000); + if (i == 0) { + radioButton.setChecked(true); + } + mRadioGroup.addView(radioButton); + } + } + + public void show() { + showAtLocation(mParent, Gravity.CENTER, 0, 0); + } + + + @Override + public void onItemChecked(LiveGiftBean bean) { + this.bean = bean; + } + + @Override + public void onClick(View view) { + int id = view.getId(); + if (id == R.id.btn_send) { + DialogUitl.showSimpleInputDialog(mContext, "輸入數量", DialogUitl.INPUT_TYPE_NUMBER, new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + try { + prangNum = Integer.parseInt(content); + if (prangNum <= 0) { + ToastUtil.show("數量錯誤"); + return; + } + mBtnSend.setText(content); + if (imm != null) { + imm.hideSoftInputFromWindow(dialog.getCurrentFocus().getWindowToken(), 0); + } + dialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); + ToastUtil.show("輸入錯誤"); + } + } + }); + } else if (id == R.id.btn_context) { + DialogUitl.showSimpleInputDialog(mContext, "輸入整蠱內容...", new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + prangContext = content; + mBtnContext.setText(content); + if (imm != null) { + imm.hideSoftInputFromWindow(dialog.getCurrentFocus().getWindowToken(), 0); + } + dialog.dismiss(); + } + }); + } else if (id == R.id.gift_btn) { + if (bean == null || StringUtil.isEmpty(prangContext) || prangNum==0) { + ToastUtil.show("整蠱內容或數量不能為空"); + return; + } + dismiss(); + } else if (id == R.id.gift_back) { + dismiss(); + } + } + + + public interface ActionListener { + void onSelectGift(PrankGiftBean bean); + + void onDismiss(); + } +} diff --git a/live/src/main/java/com/yunbao/live/dialog/LivePrankDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LivePrankDialogFragment.java new file mode 100644 index 000000000..df2d0d5dd --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/LivePrankDialogFragment.java @@ -0,0 +1,344 @@ +package com.yunbao.live.dialog; + +import android.app.Dialog; +import android.graphics.Color; +import android.os.Bundle; +import android.view.Gravity; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.tabs.TabLayout; +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.bean.PrankGiftBean; +import com.yunbao.common.bean.PrankHttpTurntableBean; +import com.yunbao.common.bean.PrankTurntableBean; +import com.yunbao.common.dialog.AbsDialogFragment; +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.DialogUitl; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.live.R; +import com.yunbao.live.adapter.LivePrankRecyclerAdapter; + +import java.util.ArrayList; +import java.util.List; + +public class LivePrankDialogFragment extends AbsDialogFragment implements View.OnClickListener { + private TabLayout mTabLayout; + private View mTurntableConfigLayout; + private TextView mPrankBtn; + private ImageView mTurntableConfigImageView; + private TextView mCoinTextView; + private TextView mGiftNotDate; + private RecyclerView mPrankRecyclerView; + private LivePrankRecyclerAdapter recyclerAdapter; + private String mLiveUid; + private PrankHttpTurntableBean bean = new PrankHttpTurntableBean(); + + public void setmLiveUid(String mLiveUid) { + this.mLiveUid = mLiveUid; + } + + @Override + protected int getLayoutId() { + return R.layout.dialog_live_prank; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog2; + } + + @Override + protected boolean canCancel() { + return true; + } + + @Override + protected void setWindowAttributes(Window window) { + WindowManager.LayoutParams params = window.getAttributes(); + window.setWindowAnimations(R.style.bottomToTopAnim); + params.width = WindowManager.LayoutParams.MATCH_PARENT; + params.height = DpUtil.dp2px(400); + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + initView(); + initTab(); + initTurntableData(); + } + + private void initView() { + mTabLayout = (TabLayout) findViewById(R.id.prank_tabLayout); + mTurntableConfigLayout = findViewById(R.id.turntable_layout); + mTurntableConfigImageView = (ImageView) findViewById(R.id.switch1_btn); + mCoinTextView = (TextView) findViewById(R.id.switch2_btn); + mPrankRecyclerView = (RecyclerView) findViewById(R.id.prank_config); + mPrankBtn = (TextView) findViewById(R.id.prank_btn); + mGiftNotDate = (TextView) findViewById(R.id.gift_prank_not_date); + mPrankRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false)); + recyclerAdapter = new LivePrankRecyclerAdapter(mContext); + mPrankRecyclerView.setAdapter(recyclerAdapter); + mCoinTextView.setOnClickListener(this); + mTurntableConfigImageView.setOnClickListener(this); + recyclerAdapter.setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + if (recyclerAdapter.getViewTypeOfList()) { + switch (position) { + case 1: + LivePrankDialogFragment.this.bean.setTurntable1(bean); + break; + case 2: + LivePrankDialogFragment.this.bean.setTurntable2(bean); + break; + case 3: + LivePrankDialogFragment.this.bean.setTurntable3(bean); + break; + case 4: + LivePrankDialogFragment.this.bean.setTurntable4(bean); + break; + case 5: + LivePrankDialogFragment.this.bean.setTurntable5(bean); + break; + case 6: + LivePrankDialogFragment.this.bean.setTurntable6(bean); + break; + } + } else { + LiveNetManager.get(mContext).deletePrankGift(mLiveUid, position + "", new HttpCallback() { + @Override + public void onSuccess(PrankHttpTurntableBean data) { + initGiftData(); + } + + @Override + public void onError(String error) { + initGiftData(); + } + }); + } + } + }); + mPrankBtn.setOnClickListener(view -> { + if ((int) view.getTag() == 1) { + GiftPopDialog dialog = new GiftPopDialog(mContext, mRootView, new GiftPopDialog.ActionListener() { + + @Override + public void onSelectGift(PrankGiftBean bean) { + if (bean != null) { + setGiftBean(bean); + } + } + + @Override + public void onDismiss() { + + } + }); + dialog.show(); + } else { + setPrankConfig(); + } + }); + mPrankBtn.setTag(0); + } + + private void initTab() { + TabLayout.Tab turntable = mTabLayout.newTab(); + TabLayout.Tab gift = mTabLayout.newTab(); + turntable.setText("轉盤整蠱"); + gift.setText("禮物整蠱"); + turntable.setTag(0); + gift.setTag(1); + mTabLayout.addTab(turntable); + mTabLayout.addTab(gift); + mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { + @Override + public void onTabSelected(TabLayout.Tab tab) { + if (tab.getTag() == null) { + return; + } + if ((int) tab.getTag() == 0) { + mTurntableConfigLayout.setVisibility(View.VISIBLE); + mPrankRecyclerView.setVisibility(View.VISIBLE); + mGiftNotDate.setVisibility(View.GONE); + recyclerAdapter.setViewType(LivePrankRecyclerAdapter.TYPE_TURNTABLE); + mPrankBtn.setBackgroundResource(R.drawable.bg_live_prank_turntable_save); + mPrankBtn.setText("保存設置"); + mPrankBtn.setTag(0); + recyclerAdapter.clearList(); + initTurntableData(); + } else { + mTurntableConfigLayout.setVisibility(View.GONE); + mPrankBtn.setBackgroundResource(R.drawable.bg_live_prank_gift_set); + mPrankBtn.setText("添加禮物"); + mPrankBtn.setTag(1); + recyclerAdapter.clearList(); + mGiftNotDate.setVisibility(View.VISIBLE); + initGiftData(); + } + } + + @Override + public void onTabUnselected(TabLayout.Tab tab) { + + } + + @Override + public void onTabReselected(TabLayout.Tab tab) { + + } + }); + } + + private void initTurntableData() { + LiveNetManager.get(mContext).getAnchorPrankTurntable(mLiveUid, new HttpCallback() { + @Override + public void onSuccess(PrankHttpTurntableBean data) { + setDate(data); + } + + @Override + public void onError(String error) { + setDate(bean); + } + }); + } + + private void setGiftBean(PrankGiftBean bean) { + LiveNetManager.get(mContext).setPrankGift(mLiveUid, bean.getGiftId(), bean.getNum() + "", bean.getTitle(), new HttpCallback() { + @Override + public void onSuccess(PrankHttpTurntableBean data) { + initGiftData(); + } + + @Override + public void onError(String error) { + initGiftData(); + } + }); + } + + private void initGiftData() { + LiveNetManager.get(mContext).getPrankGiftList(mLiveUid, new HttpCallback>() { + @Override + public void onSuccess(List data) { + if (!data.isEmpty()) { + mGiftNotDate.setVisibility(View.GONE); + mPrankRecyclerView.setVisibility(View.VISIBLE); + recyclerAdapter.setViewType(LivePrankRecyclerAdapter.TYPE_GIFT); + recyclerAdapter.setList(data); + recyclerAdapter.notifyDataSetChanged(); + }else{ + mPrankRecyclerView.setVisibility(View.GONE); + mGiftNotDate.setVisibility(View.VISIBLE); + } + } + + @Override + public void onError(String error) { + + } + }); + } + + private void setDate(PrankHttpTurntableBean bean) { + this.bean = bean; + List list = new ArrayList<>(); + list.add(buildBean(1, bean.getTurntable1())); + list.add(buildBean(2, bean.getTurntable2())); + list.add(buildBean(3, bean.getTurntable3())); + list.add(buildBean(4, bean.getTurntable4())); + list.add(buildBean(5, bean.getTurntable5())); + list.add(buildBean(6, bean.getTurntable6())); + recyclerAdapter.setList(list); + recyclerAdapter.notifyDataSetChanged(); + if (bean.getStatus() == 1) { + mTurntableConfigImageView.setImageResource(R.mipmap.special_icon_on); + } else { + mTurntableConfigImageView.setImageResource(R.mipmap.special_icon_off); + } + } + + private void setCoin(long coin) { + mCoinTextView.setText((coin / 1000) + "," + String.format("%03d", (coin % 1000))); + bean.setCoin(coin); + } + + private PrankTurntableBean buildBean(int id, String context) { + PrankTurntableBean bean = new PrankTurntableBean(); + bean.setId(id); + bean.setContext(context); + return bean; + } + + private void setPrankConfig() { + LiveNetManager.get(mContext).setAnchorPrankTurntable( + mLiveUid, + bean.getCoin() + "", + bean.getTurntable1(), + bean.getTurntable2(), + bean.getTurntable3(), + bean.getTurntable4(), + bean.getTurntable5(), + bean.getTurntable6(), + bean.getStatus() + "", + new HttpCallback() { + @Override + public void onSuccess(Object data) { + ToastUtil.show("保存成功"); + } + + @Override + public void onError(String error) { + ToastUtil.show("保存失败:" + error); + } + } + ); + } + + @Override + public void onClick(View v) { + int id = v.getId(); + if (id == R.id.switch1_btn) { + bean.setStatus(bean.getStatus() == 1 ? 0 : 1); + if (bean.getStatus() == 1) { + mTurntableConfigImageView.setImageResource(R.mipmap.special_icon_on); + } else { + mTurntableConfigImageView.setImageResource(R.mipmap.special_icon_off); + } + } else if (id == R.id.switch2_btn) { + DialogUitl.showSimpleInputDialog(mContext, "請輸入數量", DialogUitl.INPUT_TYPE_NUMBER, new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + try { + int coin = Integer.parseInt(content); + if (coin < 1000) { + ToastUtil.show("最少1000鑽石"); + return; + } + setCoin(Long.parseLong(content)); + dialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); + ToastUtil.show("最少1000鑽石"); + } + } + }); + } + } +} 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 661f11679..52f6b28f9 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -60,6 +60,7 @@ import com.yunbao.common.Constants; import com.yunbao.common.activity.AbsActivity; import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.BannerBean; +import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.GiftModel; import com.yunbao.common.bean.GuardUserModel; import com.yunbao.common.bean.HourRank; @@ -3449,6 +3450,17 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis countDownTimerTrickery.cancel(); countDownTimerTrickery = null; lt_trickery.setVisibility(View.GONE); + LiveNetManager.get(mContext).endPrankTurntable(mLiveUid, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(BaseModel data) { + + } + + @Override + public void onError(String error) { + + } + }); } } diff --git a/live/src/main/res/drawable/bg_live_prank_gift_add.xml b/live/src/main/res/drawable/bg_live_prank_gift_add.xml new file mode 100644 index 000000000..893f14574 --- /dev/null +++ b/live/src/main/res/drawable/bg_live_prank_gift_add.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_live_prank_gift_set.xml b/live/src/main/res/drawable/bg_live_prank_gift_set.xml new file mode 100644 index 000000000..85d302583 --- /dev/null +++ b/live/src/main/res/drawable/bg_live_prank_gift_set.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_live_prank_turntable_save.xml b/live/src/main/res/drawable/bg_live_prank_turntable_save.xml new file mode 100644 index 000000000..212e3cbe0 --- /dev/null +++ b/live/src/main/res/drawable/bg_live_prank_turntable_save.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_prank_coin.xml b/live/src/main/res/drawable/bg_prank_coin.xml new file mode 100644 index 000000000..943be8118 --- /dev/null +++ b/live/src/main/res/drawable/bg_prank_coin.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_prank_gift_item.xml b/live/src/main/res/drawable/bg_prank_gift_item.xml new file mode 100644 index 000000000..c9a9aae37 --- /dev/null +++ b/live/src/main/res/drawable/bg_prank_gift_item.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/dialog_live_prank.xml b/live/src/main/res/layout/dialog_live_prank.xml new file mode 100644 index 000000000..70183d9e6 --- /dev/null +++ b/live/src/main/res/layout/dialog_live_prank.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/dialog_live_select_gift_wrap.xml b/live/src/main/res/layout/dialog_live_select_gift_wrap.xml new file mode 100644 index 000000000..347248502 --- /dev/null +++ b/live/src/main/res/layout/dialog_live_select_gift_wrap.xml @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 new file mode 100644 index 000000000..1b86bd40c --- /dev/null +++ b/live/src/main/res/layout/item_live_prank_gift.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_live_prank_turntable_config.xml b/live/src/main/res/layout/item_live_prank_turntable_config.xml new file mode 100644 index 000000000..e8730c99a --- /dev/null +++ b/live/src/main/res/layout/item_live_prank_turntable_config.xml @@ -0,0 +1,46 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/view_live_prank_turntable.xml b/live/src/main/res/layout/view_live_prank_turntable.xml new file mode 100644 index 000000000..ccb1f7599 --- /dev/null +++ b/live/src/main/res/layout/view_live_prank_turntable.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/live/src/main/res/mipmap-xhdpi/icon_live_prank_gift_item_close.png b/live/src/main/res/mipmap-xhdpi/icon_live_prank_gift_item_close.png new file mode 100644 index 000000000..5e3a9e355 Binary files /dev/null and b/live/src/main/res/mipmap-xhdpi/icon_live_prank_gift_item_close.png differ diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index 226758ba2..37e1c32ee 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -244,7 +244,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); } @Override @@ -425,7 +425,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); } @Override @@ -907,7 +907,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() { @Override public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) { - RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); + RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal)); } @Override