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/live/src/main/java/com/yunbao/live/bean/PrankTurntableBean.java b/common/src/main/java/com/yunbao/common/bean/PrankTurntableBean.java similarity index 83% rename from live/src/main/java/com/yunbao/live/bean/PrankTurntableBean.java rename to common/src/main/java/com/yunbao/common/bean/PrankTurntableBean.java index cb36417df..4e1124628 100644 --- a/live/src/main/java/com/yunbao/live/bean/PrankTurntableBean.java +++ b/common/src/main/java/com/yunbao/common/bean/PrankTurntableBean.java @@ -1,11 +1,13 @@ -package com.yunbao.live.bean; +package com.yunbao.common.bean; -import com.yunbao.common.bean.BaseModel; public class PrankTurntableBean extends BaseModel { private int id; private String context; + public PrankTurntableBean() { + } + public int getId() { return id; } 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 9924cf37a..50c2eef59 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -18,6 +18,8 @@ import com.yunbao.common.bean.NewPeopleInfo; 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.SearchModel; import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.SlideInBannerModel; @@ -343,7 +345,7 @@ public interface PDLiveApi { * 获取转盘整蛊列表 */ @GET("/api/public/?service=Prank.getAnchorPrankTurntable") - Observable>> getAnchorPrankTurntable( + Observable> getAnchorPrankTurntable( @Query("anchor_id") String anchor_id ); /** @@ -368,4 +370,31 @@ public interface PDLiveApi { 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 73411c166..1acdbfa92 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,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.SetAttentsModel; import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.VipModel; @@ -502,15 +505,17 @@ public class LiveNetManager { }); } - public void getAnchorPrankTurntable(String mLiveUid, HttpCallback callback) { + /** + * 获取转盘整蛊列表 + */ + public void getAnchorPrankTurntable(String mLiveUid, HttpCallback callback) { API.get().pdLiveApi(mContext) .getAnchorPrankTurntable(mLiveUid) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(new Consumer>>() { - @Override - public void accept(ResponseModel> listResponseModel) throws Exception { - + .subscribe(responseModel -> { + if (callback != null) { + callback.onSuccess(responseModel.getData().getInfo()); } }, new Consumer() { @Override @@ -522,6 +527,9 @@ public class LiveNetManager { }).isDisposed(); } + /** + * 提交转盘整蛊 + */ public void setAnchorPrankTurntable(String mLiveUid, String coin, String turntable_one, String turntable_two, @@ -532,13 +540,90 @@ public class LiveNetManager { String status, HttpCallback callback) { API.get().pdLiveApi(mContext) - .getAnchorPrankTurntable(mLiveUid) + .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 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 590052024..076b3f6d8 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -66,6 +66,7 @@ import com.yunbao.live.bean.LiveReceiveGiftBean; 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.event.LinkMicTxMixStreamEvent; import com.yunbao.live.event.LiveAudienceEvent; @@ -236,7 +237,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("開發中,敬請期待"); 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 dd4fae038..a84f4056c 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LivePrankRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LivePrankRecyclerAdapter.java @@ -1,41 +1,75 @@ 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.EditText; +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; -import com.yunbao.live.R; -import com.yunbao.live.bean.PrankTurntableBean; - -import java.util.List; - 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; + 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) { + 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) { - return new PrankRecyclerViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_live_prank_turntable_config, parent, false)); + 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) { - holder.setDate(list.get(position)); + if (viewType == TYPE_TURNTABLE) { + ((TurntableViewHolder) holder).setDate((PrankTurntableBean) list.get(position), position); + } else { + ((GiftViewHolder) holder).setDate((PrankGiftBean) list.get(position), position); + } } @Override @@ -43,22 +77,98 @@ public class LivePrankRecyclerAdapter extends RecyclerView.Adapter 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) { - title.setText(getChineseNum(bean.getId())); + 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) { @@ -96,4 +206,4 @@ public class LivePrankRecyclerAdapter extends RecyclerView.Adapter { + 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 index d19d9e572..df2d0d5dd 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,7 @@ 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; @@ -13,17 +15,38 @@ 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() { @@ -45,7 +68,7 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O WindowManager.LayoutParams params = window.getAttributes(); window.setWindowAnimations(R.style.bottomToTopAnim); params.width = WindowManager.LayoutParams.MATCH_PARENT; - params.height = WindowManager.LayoutParams.WRAP_CONTENT; + params.height = DpUtil.dp2px(400); params.gravity = Gravity.BOTTOM; window.setAttributes(params); } @@ -54,6 +77,8 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); initView(); + initTab(); + initTurntableData(); } private void initView() { @@ -62,16 +87,258 @@ public class LivePrankDialogFragment extends AbsDialogFragment implements View.O 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); - } - private void initData(){ + 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/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_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 index 4cb7e0a8f..70183d9e6 100644 --- a/live/src/main/res/layout/dialog_live_prank.xml +++ b/live/src/main/res/layout/dialog_live_prank.xml @@ -11,27 +11,35 @@ android:layout_height="wrap_content" android:layout_marginStart="16dp" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent"> + app:layout_constraintTop_toTopOf="parent" + app:tabIndicatorColor="#F6F7FB" + app:tabIndicatorFullWidth="false" + app:tabMaxWidth="100dp" + app:tabMode="scrollable" + app:tabSelectedTextColor="#F6F7FB" + app:tabTextColor="#9A9A9A"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 index 39b41c8b1..e8730c99a 100644 --- a/live/src/main/res/layout/item_live_prank_turntable_config.xml +++ b/live/src/main/res/layout/item_live_prank_turntable_config.xml @@ -2,7 +2,8 @@ + android:layout_height="wrap_content" + android:layout_marginBottom="10dp"> - diff --git a/live/src/main/res/layout/view_live_prank_turntable.xml b/live/src/main/res/layout/view_live_prank_turntable.xml index 61e3d9ffd..ccb1f7599 100644 --- a/live/src/main/res/layout/view_live_prank_turntable.xml +++ b/live/src/main/res/layout/view_live_prank_turntable.xml @@ -9,6 +9,7 @@ android:id="@+id/turntable_layout" android:layout_width="match_parent" android:layout_height="wrap_content" + android:visibility="visible" android:orientation="vertical"> @@ -34,7 +34,7 @@ android:layout_marginStart="10dp" android:text="關閉後所有用戶將無法看到轉盤內容" android:textColor="#B3B3B3" - android:textSize="8sp" + android:textSize="10sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/switch1_title_text" /> @@ -61,7 +61,6 @@ android:layout_marginStart="10dp" android:text="轉盤每次消耗鑽石" android:textColor="#A992FF" - android:textSize="10sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -72,7 +71,7 @@ android:layout_marginStart="10dp" android:text="最少1,000鑽石起步" android:textColor="#B3B3B3" - android:textSize="8sp" + android:textSize="10sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/switch2_title_text" /> @@ -100,4 +99,13 @@ android:layout_marginStart="10dp" android:layout_marginTop="10dp" android:layout_marginEnd="10dp" /> + + 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 e823ce93f..98da43136 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -240,7 +240,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 @@ -421,7 +421,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 @@ -901,7 +901,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