diff --git a/common/build.gradle b/common/build.gradle index 09d7dd30a..19700ba89 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -194,5 +194,6 @@ dependencies { //选择器 api 'com.github.gzu-liyujiang.AndroidPicker:Common:4.1.11' api 'com.github.gzu-liyujiang.AndroidPicker:WheelView:4.1.11' - + //自定义圆角图片 + api 'com.makeramen:roundedimageview:2.3.0' } diff --git a/common/src/main/java/com/yunbao/common/adapter/GiftNumberAdapter.java b/common/src/main/java/com/yunbao/common/adapter/GiftNumberAdapter.java new file mode 100644 index 000000000..6dcea6851 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/adapter/GiftNumberAdapter.java @@ -0,0 +1,40 @@ +package com.yunbao.common.adapter; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.common.R; +import com.yunbao.common.bean.GiftQuantityModel; +import com.yunbao.common.views.GiftNumber; + +import java.util.List; + +public class GiftNumberAdapter extends RecyclerView.Adapter { + private List giftQuantityModels; + + public GiftNumberAdapter(List giftQuantityModels) { + this.giftQuantityModels = giftQuantityModels; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View robotSayHelloView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_gift_number, parent, false); + return new GiftNumber(robotSayHelloView); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + GiftNumber giftNumber = (GiftNumber) holder; + giftNumber.showData(giftQuantityModels.get(position)); + } + + @Override + public int getItemCount() { + return giftQuantityModels.size(); + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/GiftQuantityModel.java b/common/src/main/java/com/yunbao/common/bean/GiftQuantityModel.java new file mode 100644 index 000000000..09fda25b7 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/GiftQuantityModel.java @@ -0,0 +1,43 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +/** + * 礼物选择数量 + */ +public class GiftQuantityModel extends BaseModel { + + @SerializedName("id") + private String id; + @SerializedName("gift_quantity") + private String giftQuantity; + @SerializedName("font_colour") + private String fontColour; + + public String getId() { + return id; + } + + public GiftQuantityModel setId(String id) { + this.id = id; + return this; + } + + public String getGiftQuantity() { + return giftQuantity; + } + + public GiftQuantityModel setGiftQuantity(String giftQuantity) { + this.giftQuantity = giftQuantity; + return this; + } + + public String getFontColour() { + return fontColour; + } + + public GiftQuantityModel setFontColour(String fontColour) { + this.fontColour = fontColour; + return this; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java b/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java index c0777d57e..78583150b 100644 --- a/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java +++ b/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java @@ -23,7 +23,7 @@ public class LiveGiftBean { private String name; private String price; private String icon; - private boolean checked; + private boolean checked = false; private int page; private View mView; private String sendType;//支付是金币还是钻石 @@ -36,6 +36,30 @@ public class LiveGiftBean { private String tag; @JSONField(name = "blind_box_type") private int blind_box_type = 0; + //礼物角标 + + @JSONField(name = "corner_mark") + private String cornerMark; + @JSONField(name = "gift_description") + private String giftDescription; + + public String getGiftDescription() { + return giftDescription; + } + + public LiveGiftBean setGiftDescription(String giftDescription) { + this.giftDescription = giftDescription; + return this; + } + + public String getCornerMark() { + return cornerMark; + } + + public LiveGiftBean setCornerMark(String cornerMark) { + this.cornerMark = cornerMark; + return this; + } public int getBlind_box_type() { return blind_box_type; diff --git a/common/src/main/java/com/yunbao/common/event/GiftNumberEvent.java b/common/src/main/java/com/yunbao/common/event/GiftNumberEvent.java new file mode 100644 index 000000000..b4684d0b8 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/event/GiftNumberEvent.java @@ -0,0 +1,16 @@ +package com.yunbao.common.event; + +import com.yunbao.common.bean.BaseModel; + +public class GiftNumberEvent extends BaseModel { + private String mCount; + + public String getmCount() { + return mCount; + } + + public GiftNumberEvent setmCount(String mCount) { + this.mCount = mCount; + return this; + } +} diff --git a/common/src/main/java/com/yunbao/common/glide/ImgLoader.java b/common/src/main/java/com/yunbao/common/glide/ImgLoader.java index 4d7882868..f13262a34 100644 --- a/common/src/main/java/com/yunbao/common/glide/ImgLoader.java +++ b/common/src/main/java/com/yunbao/common/glide/ImgLoader.java @@ -336,6 +336,18 @@ public class ImgLoader { builder.into(imageView); } + public static void displayBlurLive(Context context, int url, ImageView imageView) { + if (!contextIsExist(context)) { + return; + } + RequestBuilder builder = Glide.with(context) + .load(url) + .thumbnail(thumbnail) + .apply(RequestOptions.bitmapTransform(new BlurTransformation(20))) + .placeholder(R.mipmap.live_bg); + builder.into(imageView); + } + private static boolean contextIsExist(Context context) { if (context == null) { return false; diff --git a/common/src/main/java/com/yunbao/common/http/CommonHttpUtil.java b/common/src/main/java/com/yunbao/common/http/CommonHttpUtil.java index 439bc94da..3f038fab2 100644 --- a/common/src/main/java/com/yunbao/common/http/CommonHttpUtil.java +++ b/common/src/main/java/com/yunbao/common/http/CommonHttpUtil.java @@ -19,13 +19,13 @@ import com.yunbao.common.bean.ConfigBean; import com.yunbao.common.event.FollowEvent; import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.manager.APKManager; +import com.yunbao.common.manager.GiftQuantityManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.LiveClassManager; import com.yunbao.common.manager.NewLevelManager; import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.L; -import com.yunbao.common.utils.MD5Util; import com.yunbao.common.utils.SpUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.VersionUtil; @@ -231,6 +231,10 @@ public class CommonHttpUtil { if (obj.containsKey("defaultBubbleUrl")) { IMLoginManager.get(context).setDefaultBubbleUrl(obj.getString("defaultBubbleUrl")); } + if (obj.containsKey("gift_quantity")) { + JSONArray giftQuantity = obj.getJSONArray("gift_quantity"); + new GiftQuantityManager(context).UpGiftQuantity(giftQuantity.toJSONString()); + } } catch (Exception e) { e.printStackTrace(); String error = "info[0]:" + info[0] + "\n\n\n" + "Exception:" + e.getClass() + "---message--->" + e.getMessage(); 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 60938e8fb..ab99cf322 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -829,4 +829,5 @@ public interface PDLiveApi { @Query("stream") String stream, @Query("red_packet_id") String redPacketId ); + } diff --git a/common/src/main/java/com/yunbao/common/manager/GiftQuantityManager.java b/common/src/main/java/com/yunbao/common/manager/GiftQuantityManager.java new file mode 100644 index 000000000..cdb98a0be --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/GiftQuantityManager.java @@ -0,0 +1,53 @@ +package com.yunbao.common.manager; + +import android.content.Context; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.yunbao.common.bean.GiftQuantityModel; +import com.yunbao.common.bean.LiveClassBean; +import com.yunbao.common.manager.base.BaseCacheManager; + +import java.util.List; + +public class GiftQuantityManager extends BaseCacheManager { + private final static String KEY_GIFT_QUANTITY = "GiftQuantity"; + private static GiftQuantityManager manager; + private Context context; + private List giftQuantityModels; + + public GiftQuantityManager(Context context) { + super(context); + } + + /** + * 获取指导员备注信息 + * + * @return + */ + public List getGiftQuantity() { + List giftQuantityModels = getList(KEY_GIFT_QUANTITY, new TypeToken>() { + }.getType()); + if (giftQuantityModels == null || giftQuantityModels.size() == 0) { + giftQuantityModels.add(new GiftQuantityModel().setGiftQuantity("1").setFontColour("#ffffff")); + giftQuantityModels.add(new GiftQuantityModel().setGiftQuantity("10").setFontColour("#ffffff")); + giftQuantityModels.add(new GiftQuantityModel().setGiftQuantity("66").setFontColour("#ffffff")); + giftQuantityModels.add(new GiftQuantityModel().setGiftQuantity("88").setFontColour("#FA62A1")); + giftQuantityModels.add(new GiftQuantityModel().setGiftQuantity("100").setFontColour("#9B62FF")); + giftQuantityModels.add(new GiftQuantityModel().setGiftQuantity("520").setFontColour("#65BFFB")); + giftQuantityModels.add(new GiftQuantityModel().setGiftQuantity("1314").setFontColour("#05F3EC")); + } + return giftQuantityModels; + } + + /** + * 缓存等级图标 + * + * @param json + */ + public void UpGiftQuantity(String json) { + giftQuantityModels = new Gson().fromJson(json, new TypeToken>() { + }.getType()); + put(KEY_GIFT_QUANTITY, giftQuantityModels); + } +} diff --git a/common/src/main/java/com/yunbao/common/utils/BlurBitmapUtil.java b/common/src/main/java/com/yunbao/common/utils/BlurBitmapUtil.java new file mode 100644 index 000000000..b674089a2 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/utils/BlurBitmapUtil.java @@ -0,0 +1,56 @@ +package com.yunbao.common.utils; + +import android.content.Context; +import android.graphics.Bitmap; +import android.renderscript.Allocation; +import android.renderscript.Element; +import android.renderscript.RenderScript; +import android.renderscript.ScriptIntrinsicBlur; + +/** + * Created by L on 2017/10/12. + */ + +public class BlurBitmapUtil { + /** + * 图片缩放比例 + */ + private static final float BITMAP_SCALE = 0.4f; + /** + * 最大模糊度(在0.0到25.0之间) + */ + private static final float BLUR_RADIUS = 25f; + /** + * 模糊图片的具体方法 + * + * @param context 上下文对象 + * @param image 需要模糊的图片 + * @return 模糊处理后的图片 + */ + public static Bitmap blur(Context context, Bitmap image) { + // 计算图片缩小后的长宽 + int width = Math.round(image.getWidth() * BITMAP_SCALE); + int height = Math.round(image.getHeight() * BITMAP_SCALE); + // 将缩小后的图片做为预渲染的图片。 + Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false); + // 创建一张渲染后的输出图片。 + Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap); + // 创建RenderScript内核对象 + RenderScript rs = RenderScript.create(context); + // 创建一个模糊效果的RenderScript的工具对象 + ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); + // 由于RenderScript并没有使用VM来分配内存,所以需要使用Allocation类来创建和分配内存空间。 + // 创建Allocation对象的时候其实内存是空的,需要使用copyTo()将数据填充进去。 + Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap); + Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap); + // 设置渲染的模糊程度, 25f是最大模糊度 + blurScript.setRadius(BLUR_RADIUS); + // 设置blurScript对象的输入内存 + blurScript.setInput(tmpIn); + // 将输出数据保存到输出内存中 + blurScript.forEach(tmpOut); + // 将数据填充到Allocation中 + tmpOut.copyTo(outputBitmap); + return outputBitmap; + } +} diff --git a/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java b/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java index 232ea3a6c..7705efb0b 100644 --- a/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java +++ b/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java @@ -139,7 +139,7 @@ public class CustomDrawerPopupView extends DrawerPopupView { ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.online), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { - XPopup.Builder builder = new XPopup.Builder(getContext()).atView(findViewById(R.id.more_menu)); + XPopup.Builder builder = new XPopup.Builder(getContext()).atView(findViewById(R.id.diamond_linear)); builder.hasShadowBg(false) .isDestroyOnDismiss(true) .isLightStatusBar(false) diff --git a/common/src/main/java/com/yunbao/common/views/GiftNumber.java b/common/src/main/java/com/yunbao/common/views/GiftNumber.java new file mode 100644 index 000000000..c6d021823 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/GiftNumber.java @@ -0,0 +1,34 @@ +package com.yunbao.common.views; + +import android.graphics.Color; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.common.R; +import com.yunbao.common.bean.GiftQuantityModel; +import com.yunbao.common.event.GiftNumberEvent; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.views.weight.ViewClicksAntiShake; + +public class GiftNumber extends RecyclerView.ViewHolder { + private TextView customQuantity; + + public GiftNumber(@NonNull View itemView) { + super(itemView); + customQuantity = itemView.findViewById(R.id.custom_quantity); + } + + public void showData(GiftQuantityModel quantityModel) { + customQuantity.setText(quantityModel.getGiftQuantity()); + customQuantity.setTextColor(Color.parseColor(quantityModel.getFontColour())); + ViewClicksAntiShake.clicksAntiShake(customQuantity, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + Bus.get().post(new GiftNumberEvent().setmCount(quantityModel.getGiftQuantity())); + } + }); + } +} diff --git a/common/src/main/java/com/yunbao/common/views/GiftNumberPopup.java b/common/src/main/java/com/yunbao/common/views/GiftNumberPopup.java new file mode 100644 index 000000000..54ddcdfea --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/GiftNumberPopup.java @@ -0,0 +1,59 @@ +package com.yunbao.common.views; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.lxj.xpopup.core.BottomPopupView; +import com.yunbao.common.R; +import com.yunbao.common.adapter.GiftNumberAdapter; +import com.yunbao.common.event.GiftNumberEvent; +import com.yunbao.common.manager.GiftQuantityManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.views.weight.ViewClicksAntiShake; + +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +public class GiftNumberPopup extends BottomPopupView { + public GiftNumberPopup(@NonNull Context context) { + super(context); + } + + // 返回自定义弹窗的布局 + @Override + protected int getImplLayoutId() { + return R.layout.view_live_gift_number; + } + + // 执行初始化操作,比如:findView,设置点击,或者任何你弹窗内的业务逻辑 + @Override + protected void onCreate() { + Bus.getOn(this); + super.onCreate(); + RecyclerView giftList = findViewById(R.id.gift_list); + giftList.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); + GiftNumberAdapter giftNumberAdapter = new GiftNumberAdapter(new GiftQuantityManager(getContext()).getGiftQuantity()); + giftList.setAdapter(giftNumberAdapter); + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.to_can), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + dismiss(); + } + }); + } + + @Override + protected void onDismiss() { + super.onDismiss(); + Bus.getOff(this); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onGiftNumberEvent(GiftNumberEvent event) { + dismiss(); + } + +} diff --git a/common/src/main/res/drawable/backgroud_custom_gift.xml b/common/src/main/res/drawable/backgroud_custom_gift.xml new file mode 100644 index 000000000..d61532880 --- /dev/null +++ b/common/src/main/res/drawable/backgroud_custom_gift.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/common/src/main/res/drawable/backgroud_custom_gift2.png b/common/src/main/res/drawable/backgroud_custom_gift2.png new file mode 100644 index 000000000..ec7301771 Binary files /dev/null and b/common/src/main/res/drawable/backgroud_custom_gift2.png differ diff --git a/common/src/main/res/drawable/background_gift_description.xml b/common/src/main/res/drawable/background_gift_description.xml new file mode 100644 index 000000000..0e79673a2 --- /dev/null +++ b/common/src/main/res/drawable/background_gift_description.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/common/src/main/res/drawable/background_gift_money.xml b/common/src/main/res/drawable/background_gift_money.xml new file mode 100644 index 000000000..524773a5d --- /dev/null +++ b/common/src/main/res/drawable/background_gift_money.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/common/src/main/res/drawable/background_gift_money2.xml b/common/src/main/res/drawable/background_gift_money2.xml new file mode 100644 index 000000000..eb1babf8d --- /dev/null +++ b/common/src/main/res/drawable/background_gift_money2.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/common/src/main/res/drawable/background_gift_select2.xml b/common/src/main/res/drawable/background_gift_select2.xml new file mode 100644 index 000000000..b7f308b1a --- /dev/null +++ b/common/src/main/res/drawable/background_gift_select2.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/common/src/main/res/drawable/bg_live_gift_send_new.xml b/common/src/main/res/drawable/bg_live_gift_send_new.xml new file mode 100644 index 000000000..0e72f15d9 --- /dev/null +++ b/common/src/main/res/drawable/bg_live_gift_send_new.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/common/src/main/res/drawable/bg_parcel_point.xml b/common/src/main/res/drawable/bg_parcel_point.xml new file mode 100644 index 000000000..1cb330428 --- /dev/null +++ b/common/src/main/res/drawable/bg_parcel_point.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/common/src/main/res/drawable/bg_selection_quantity.png b/common/src/main/res/drawable/bg_selection_quantity.png new file mode 100644 index 000000000..19fc075ce Binary files /dev/null and b/common/src/main/res/drawable/bg_selection_quantity.png differ diff --git a/common/src/main/res/drawable/icon_covering_layer.png b/common/src/main/res/drawable/icon_covering_layer.png new file mode 100644 index 000000000..f343669dc Binary files /dev/null and b/common/src/main/res/drawable/icon_covering_layer.png differ diff --git a/common/src/main/res/drawable/progress_bg_user.xml b/common/src/main/res/drawable/progress_bg_user.xml new file mode 100644 index 000000000..6d3cc5386 --- /dev/null +++ b/common/src/main/res/drawable/progress_bg_user.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common/src/main/res/layout/dialog_live_gift_popup.xml b/common/src/main/res/layout/dialog_live_gift_popup.xml new file mode 100644 index 000000000..63afb262c --- /dev/null +++ b/common/src/main/res/layout/dialog_live_gift_popup.xml @@ -0,0 +1,357 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/view_blind_box.xml b/common/src/main/res/layout/view_blind_box.xml similarity index 100% rename from live/src/main/res/layout/view_blind_box.xml rename to common/src/main/res/layout/view_blind_box.xml diff --git a/common/src/main/res/layout/view_gift_number.xml b/common/src/main/res/layout/view_gift_number.xml new file mode 100644 index 000000000..2a7f8828a --- /dev/null +++ b/common/src/main/res/layout/view_gift_number.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/common/src/main/res/layout/view_live_gift_number.xml b/common/src/main/res/layout/view_live_gift_number.xml new file mode 100644 index 000000000..241947d70 --- /dev/null +++ b/common/src/main/res/layout/view_live_gift_number.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common/src/main/res/layout/view_nobility.xml b/common/src/main/res/layout/view_nobility.xml new file mode 100644 index 000000000..a11e0b664 --- /dev/null +++ b/common/src/main/res/layout/view_nobility.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/mipmap-mdpi/icon_live_gift_lian.png b/common/src/main/res/mipmap-mdpi/icon_live_gift_lian.png similarity index 100% rename from live/src/main/res/mipmap-mdpi/icon_live_gift_lian.png rename to common/src/main/res/mipmap-mdpi/icon_live_gift_lian.png diff --git a/live/src/main/res/mipmap-xxxhdpi/bg_blind_bottom.png b/common/src/main/res/mipmap-xxhdpi/bg_blind_bottom.png similarity index 100% rename from live/src/main/res/mipmap-xxxhdpi/bg_blind_bottom.png rename to common/src/main/res/mipmap-xxhdpi/bg_blind_bottom.png diff --git a/common/src/main/res/mipmap-xxhdpi/icon_aristocrat_tip.png b/common/src/main/res/mipmap-xxhdpi/icon_aristocrat_tip.png new file mode 100644 index 000000000..5bad5e448 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/icon_aristocrat_tip.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/icon_arrow_down.png b/common/src/main/res/mipmap-xxhdpi/icon_arrow_down.png new file mode 100644 index 000000000..9d428a4d1 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/icon_arrow_down.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/icon_arrow_right.png b/common/src/main/res/mipmap-xxhdpi/icon_arrow_right.png new file mode 100644 index 000000000..3175b9743 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/icon_arrow_right.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/icon_empty_parcel.png b/common/src/main/res/mipmap-xxhdpi/icon_empty_parcel.png new file mode 100644 index 000000000..2bcdb7034 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/icon_empty_parcel.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/icon_established_nobility.png b/common/src/main/res/mipmap-xxhdpi/icon_established_nobility.png new file mode 100644 index 000000000..bd0559cbe Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/icon_established_nobility.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/icon_grade_angle_mark.png b/common/src/main/res/mipmap-xxhdpi/icon_grade_angle_mark.png new file mode 100644 index 000000000..5d71cbd2a Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/icon_grade_angle_mark.png differ diff --git a/live/src/main/res/mipmap-mdpi/icon_live_gift_2.png b/common/src/main/res/mipmap-xxhdpi/icon_live_gift_2.png similarity index 100% rename from live/src/main/res/mipmap-mdpi/icon_live_gift_2.png rename to common/src/main/res/mipmap-xxhdpi/icon_live_gift_2.png diff --git a/common/src/main/res/mipmap-xxhdpi/icon_right.png b/common/src/main/res/mipmap-xxhdpi/icon_right.png new file mode 100644 index 000000000..b9d1d45b0 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/icon_right.png differ diff --git a/live/src/main/res/mipmap-xxxhdpi/icon_what.png b/common/src/main/res/mipmap-xxhdpi/icon_what.png similarity index 100% rename from live/src/main/res/mipmap-xxxhdpi/icon_what.png rename to common/src/main/res/mipmap-xxhdpi/icon_what.png diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 6715ce5e3..898591650 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1250,4 +1250,8 @@ Limited ride And limited avatar frame %s drew %s in the lucky red envelope number >Red successfully + 升級還需%s經驗值,升至%s即可領取獎勵 + 包裹中暫無物品哦 + 恭喜,你已達到最高等級 + 自定義數量 diff --git a/config.gradle b/config.gradle index 5bba46103..e31787a93 100644 --- a/config.gradle +++ b/config.gradle @@ -9,9 +9,9 @@ ext { ] manifestPlaceholders = [ //正式、 - serverHost : "https://napi.yaoulive.com", +// serverHost : "https://napi.yaoulive.com", // 测试 -// serverHost : "https://ceshi.yaoulive.com", + serverHost : "https://ceshi.yaoulive.com", diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index c52a984e8..b786ce6f4 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -91,6 +91,7 @@ import com.yunbao.live.bean.LiveChatBean; import com.yunbao.live.dialog.LiveFansFragment; import com.yunbao.live.dialog.LiveGameDialogFragment; import com.yunbao.live.dialog.LiveGiftDialogFragment; +import com.yunbao.live.dialog.LiveGiftPopup; import com.yunbao.live.dialog.LiveHDDialogFragment; import com.yunbao.live.dialog.LiveInputDialogFragment; import com.yunbao.live.dialog.LiveMicUserDialogFragment; @@ -443,18 +444,16 @@ public class LiveAudienceActivity extends LiveActivity { */ public void openGiftWindow() { new Handler(Looper.getMainLooper()).post(() -> { + if (TextUtils.isEmpty(mLiveUid) || TextUtils.isEmpty(mStream)) { return; } - LiveGiftDialogFragment fragment = new LiveGiftDialogFragment(); - fragment.setPkStatus(isPk); - fragment.setLiveGuardInfo(mLiveGuardInfo); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.LIVE_STREAM, mStream); - fragment.setArguments(bundle); - fragment.setOnDismissListener(dialog -> checkMsgRed()); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) + .setmLiveUid(mLiveUid) + .setmStream(mStream) + .setPk(isPk) + .setLiveGuardInfo(mLiveGuardInfo)); }); } @@ -462,16 +461,13 @@ public class LiveAudienceActivity extends LiveActivity { if (TextUtils.isEmpty(mLiveUid) || TextUtils.isEmpty(mStream)) { return; } - LiveGiftDialogFragment fragment = new LiveGiftDialogFragment(); - fragment.setPkStatus(isPk); - fragment.setLiveGuardInfo(mLiveGuardInfo); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.LIVE_STREAM, mStream); - bundle.putString(Constants.LIVE_WISH_GIFTID, giftId); - fragment.setArguments(bundle); - fragment.setOnDismissListener(dialog -> checkMsgRed()); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) + .setmLiveUid(mLiveUid) + .setmStream(mStream) + .setPk(isPk) + .setLiveGuardInfo(mLiveGuardInfo) + .setmWishGiftId(giftId)); } public void openGiftWindow(String giftId, String for_by) { @@ -479,19 +475,15 @@ public class LiveAudienceActivity extends LiveActivity { return; } new Handler(Looper.getMainLooper()).post(() -> { - LiveGiftDialogFragment fragment = new LiveGiftDialogFragment(); - fragment.setPkStatus(isPk); - fragment.setLiveGuardInfo(mLiveGuardInfo); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.LIVE_STREAM, mStream); - bundle.putString(Constants.LIVE_WISH_GIFTID, giftId); - if (for_by.equals("1")) { - bundle.putString("by", "1"); - } - fragment.setArguments(bundle); - fragment.setOnDismissListener(dialog -> checkMsgRed()); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) + .setmLiveUid(mLiveUid) + .setmStream(mStream) + .setPk(isPk) + .setLiveGuardInfo(mLiveGuardInfo) + .setmWishGiftId(giftId) + .setUname("1"));//setUname==by }); } @@ -1023,18 +1015,29 @@ public class LiveAudienceActivity extends LiveActivity { break; case GIFT_POPUP: - - if (TextUtils.isEmpty(mLiveUid) || TextUtils.isEmpty(mStream)) { - return; - } - LiveGiftDialogFragment liveGiftDialogFragment = new LiveGiftDialogFragment(); - liveGiftDialogFragment.setPkStatus(isPk); - liveGiftDialogFragment.setLiveGuardInfo(mLiveGuardInfo); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.LIVE_STREAM, mStream); - liveGiftDialogFragment.setArguments(bundle); - liveGiftDialogFragment.setOnDismissListener(dialog -> checkMsgRed()); - liveGiftDialogFragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + LiveGiftPopup liveGiftPopup = new LiveGiftPopup(); + bundle.putString("mLiveUid", mLiveUid); + bundle.putString("mStream", mStream); + bundle.putString("WishGiftId", event.getmWishGiftId()); + bundle.putBoolean("ContactGift", event.getIsContactGift()); + bundle.putParcelable("GuardInfo", event.getLiveGuardInfo()); + bundle.putBoolean("pk", event.isPk()); + liveGiftPopup.setArguments(bundle); + liveGiftPopup.show(getSupportFragmentManager(), "LiveGiftPopup"); +// new XPopup.Builder(mContext) +// .asCustom(new LiveGiftPopup(mContext, this)) +// .show(); +// if (TextUtils.isEmpty(mLiveUid) || TextUtils.isEmpty(mStream)) { +// return; +// } +// LiveGiftDialogFragment liveGiftDialogFragment = new LiveGiftDialogFragment(); +// liveGiftDialogFragment.setPkStatus(isPk); +// liveGiftDialogFragment.setLiveGuardInfo(mLiveGuardInfo); +// bundle.putString(Constants.LIVE_UID, mLiveUid); +// bundle.putString(Constants.LIVE_STREAM, mStream); +// liveGiftDialogFragment.setArguments(bundle); +// liveGiftDialogFragment.setOnDismissListener(dialog -> checkMsgRed()); +// liveGiftDialogFragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); break; case CURRENT_ACTIVITY: String type = event.getModel().getActiveId(); diff --git a/live/src/main/java/com/yunbao/live/adapter/FrameGiftAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FrameGiftAdapter.java new file mode 100644 index 000000000..05e78fd3b --- /dev/null +++ b/live/src/main/java/com/yunbao/live/adapter/FrameGiftAdapter.java @@ -0,0 +1,69 @@ +package com.yunbao.live.adapter; + +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.utils.Bus; +import com.yunbao.live.R; +import com.yunbao.live.event.LiveGiftItemEvent; +import com.yunbao.live.views.FrameGiftViewHolder; + +import java.util.ArrayList; +import java.util.List; + +public class FrameGiftAdapter extends RecyclerView.Adapter { + private List giftJson = new ArrayList<>(); + private int contextLayoutGiftHeight = 0; + private String mStream, mLiveUid, wishGiftId; + + public FrameGiftAdapter(int contextLayoutGiftHeight, List giftJson, String mStream, String mLiveUid, String wishGiftId) { + this.contextLayoutGiftHeight = contextLayoutGiftHeight; + this.giftJson = giftJson; + this.mStream = mStream; + this.mLiveUid = mLiveUid; + this.wishGiftId = wishGiftId; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View herdView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_frame_gift, parent, false); + return new FrameGiftViewHolder(herdView); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + + if (!TextUtils.isEmpty(wishGiftId) && TextUtils.equals(giftJson.get(position).getId() + "", wishGiftId)) { + Bus.get().post(new LiveGiftItemEvent().setLiveGiftModel(giftJson.get(position))); + } + + FrameGiftViewHolder frameGiftViewHolder = (FrameGiftViewHolder) holder; + frameGiftViewHolder.showData(contextLayoutGiftHeight, giftJson.get(position)); + frameGiftViewHolder.giftSelect(giftJson.get(position), position, mStream, mLiveUid, new FrameGiftViewHolder.FrameGiftClickListener() { + @Override + public void onCallBack(int position, LiveGiftBean model) { + Bus.get().post(new LiveGiftItemEvent().setLiveGiftModel(model)); + wishGiftId = null; + } + }); + } + + public void giftSelect(LiveGiftBean model) { + for (int i = 0; i < giftJson.size(); i++) { + giftJson.get(i).setChecked(giftJson.get(i).getId() == model.getId()); + } + notifyDataSetChanged(); + } + + @Override + public int getItemCount() { + return giftJson.size(); + } +} diff --git a/live/src/main/java/com/yunbao/live/adapter/GiftTitleAdapter.java b/live/src/main/java/com/yunbao/live/adapter/GiftTitleAdapter.java new file mode 100644 index 000000000..898b9da7c --- /dev/null +++ b/live/src/main/java/com/yunbao/live/adapter/GiftTitleAdapter.java @@ -0,0 +1,60 @@ +package com.yunbao.live.adapter; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.live.R; +import com.yunbao.live.bean.GiftTopBean; +import com.yunbao.live.views.GiftTitleViewHolder; + +import java.util.ArrayList; +import java.util.List; + +/** + * + */ +public class GiftTitleAdapter extends RecyclerView.Adapter { + + List name = new ArrayList<>(); + private int index = 0; + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View herdView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gift_top_new, parent, false); + return new GiftTitleViewHolder(herdView); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + GiftTitleViewHolder itemViewHolder = (GiftTitleViewHolder) holder; + itemViewHolder.showData(name.get(position), position, new GiftTitleViewHolder.ClicksCallBack() { + @Override + public void onViewClicks(int mPosition) { + index = mPosition; + notifyDataSetChanged(); + } + }); + itemViewHolder.selectData(index == position); + } + + @Override + public int getItemCount() { + return name.size(); + } + + public void addAllData(List giftTopBeans) { + name.clear(); + name.addAll(giftTopBeans); + notifyDataSetChanged(); + } + + public void uncheck() { + index = -1; + notifyDataSetChanged(); + } +} diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveGiftFragmentPagerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveGiftFragmentPagerAdapter.java new file mode 100644 index 000000000..934be7fc4 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/adapter/LiveGiftFragmentPagerAdapter.java @@ -0,0 +1,33 @@ +package com.yunbao.live.adapter; + +import android.content.Context; + +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; + +import java.util.List; + +public class LiveGiftFragmentPagerAdapter extends FragmentPagerAdapter { + + private List fragmentList; + + + public LiveGiftFragmentPagerAdapter(FragmentManager fm, Context mContext, List fragmentList) { + super(fm); + + this.fragmentList = fragmentList; + + } + + @Override + public Fragment getItem(int i) { + return fragmentList.get(i); + } + + @Override + public int getCount() { + return fragmentList.size(); + } + +} diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveParcelItemAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveParcelItemAdapter.java new file mode 100644 index 000000000..9f06c5816 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/adapter/LiveParcelItemAdapter.java @@ -0,0 +1,85 @@ +package com.yunbao.live.adapter; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.utils.Bus; +import com.yunbao.live.R; +import com.yunbao.live.event.LiveGiftItemEvent; +import com.yunbao.live.views.LiveParcelItemViewHolder; + +import java.util.ArrayList; +import java.util.List; + +public class LiveParcelItemAdapter extends RecyclerView.Adapter { + private List giftJson = new ArrayList<>(); + private int contextLayoutGiftHeight = 0; + private String mStream, mLiveUid; + + public LiveParcelItemAdapter(int contextLayoutGiftHeight, List giftJson, String mStream, String mLiveUid) { + this.contextLayoutGiftHeight = contextLayoutGiftHeight; + this.giftJson = giftJson; + this.mStream = mStream; + this.mLiveUid = mLiveUid; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View herdView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_live_parcel, parent, false); + return new LiveParcelItemViewHolder(herdView); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + LiveParcelItemViewHolder frameGiftViewHolder = (LiveParcelItemViewHolder) holder; + frameGiftViewHolder.showData(contextLayoutGiftHeight, giftJson.get(position)); + frameGiftViewHolder.giftSelect(giftJson.get(position), position, mStream, mLiveUid, new LiveParcelItemViewHolder.FrameGiftClickListener() { + @Override + public void onCallBack(int position, LiveGiftBean model) { + Bus.get().post(new LiveGiftItemEvent().setLiveGiftModel(model)); + } + }); + } + + public void giftSelect(LiveGiftBean model) { + for (int i = 0; i < giftJson.size(); i++) { + giftJson.get(i).setChecked(giftJson.get(i).getId() == model.getId()); + } + notifyDataSetChanged(); + } + + public void refreshWrapListAfterSend(LiveGiftBean model) { + for (int i = 0; i < giftJson.size(); i++) { + if (giftJson.get(i).getId() == model.getId()) { + + + String giftNum = giftJson.get(i).getGiftNum(); + int number = 0; + try { + number = Integer.parseInt(giftNum); + } catch (NumberFormatException e) { + e.printStackTrace(); + number = 0; + } + if (number == 1) { + + giftJson.remove(i); + } else { + giftJson.get(i).setGiftNum(String.valueOf(number - 1)); + } + } + } + notifyDataSetChanged(); + } + + @Override + public int getItemCount() { + return giftJson.size(); + } +} diff --git a/live/src/main/java/com/yunbao/live/bean/CoinModel.java b/live/src/main/java/com/yunbao/live/bean/CoinModel.java new file mode 100644 index 000000000..f80a61da8 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/bean/CoinModel.java @@ -0,0 +1,115 @@ +package com.yunbao.live.bean; + +import com.google.gson.annotations.SerializedName; +import com.yunbao.common.bean.BaseModel; + +public class CoinModel extends BaseModel { + //钻石余额 + @SerializedName("coin") + private String coin; + //金豆余额 + @SerializedName("gold") + private String gold; + + @SerializedName("uid") + private String uid; + //平台最大等级 + @SerializedName("user_level_max") + private String userLevelMax; + //当前用户等级 + @SerializedName("user_level") + private String userLevel; + //升级下一级需要的经验 + @SerializedName("user_next_level_rewards") + private String userNextLevelRewards; + //当前已经获取到的经验值 + @SerializedName("user_level_current_consumption") + private String userLevelCurrentConsumption; + //升级需要的经验值(总的) + @SerializedName("user_level_upgrades") + private String userLevelUpgrades; + //包裹红点 + @SerializedName("users_pack_red_dot") + private String usersPackRedDot; + + public String getCoin() { + return coin; + } + + public CoinModel setCoin(String coin) { + this.coin = coin; + return this; + } + + public String getGold() { + return gold; + } + + public CoinModel setGold(String gold) { + this.gold = gold; + return this; + } + + public String getUid() { + return uid; + } + + public CoinModel setUid(String uid) { + this.uid = uid; + return this; + } + + public String getUserLevelMax() { + return userLevelMax; + } + + public CoinModel setUserLevelMax(String userLevelMax) { + this.userLevelMax = userLevelMax; + return this; + } + + public String getUserLevel() { + return userLevel; + } + + public CoinModel setUserLevel(String userLevel) { + this.userLevel = userLevel; + return this; + } + + public String getUserNextLevelRewards() { + return userNextLevelRewards; + } + + public CoinModel setUserNextLevelRewards(String userNextLevelRewards) { + this.userNextLevelRewards = userNextLevelRewards; + return this; + } + + public String getUserLevelCurrentConsumption() { + return userLevelCurrentConsumption; + } + + public CoinModel setUserLevelCurrentConsumption(String userLevelCurrentConsumption) { + this.userLevelCurrentConsumption = userLevelCurrentConsumption; + return this; + } + + public String getUserLevelUpgrades() { + return userLevelUpgrades; + } + + public CoinModel setUserLevelUpgrades(String userLevelUpgrades) { + this.userLevelUpgrades = userLevelUpgrades; + return this; + } + + public String getUsersPackRedDot() { + return usersPackRedDot; + } + + public CoinModel setUsersPackRedDot(String usersPackRedDot) { + this.usersPackRedDot = usersPackRedDot; + return this; + } +} diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java new file mode 100644 index 000000000..aa1a30b53 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java @@ -0,0 +1,1100 @@ +package com.yunbao.live.dialog; + +import static com.yunbao.common.CommonAppConfig.isGetNewWrap; +import static com.yunbao.common.utils.RouteUtil.PATH_COIN; + +import android.app.Dialog; +import android.content.DialogInterface; +import android.graphics.Color; +import android.graphics.Typeface; +import android.os.Bundle; +import android.os.Handler; +import android.text.Spannable; +import android.text.SpannableStringBuilder; +import android.text.TextUtils; +import android.text.style.ForegroundColorSpan; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; + +import androidx.fragment.app.FragmentTransaction; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.alibaba.android.arouter.launcher.ARouter; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.blankj.utilcode.util.GsonUtils; +import com.lxj.xpopup.XPopup; +import com.opensource.svgaplayer.SVGACallback; +import com.opensource.svgaplayer.SVGADrawable; +import com.opensource.svgaplayer.SVGAImageView; +import com.opensource.svgaplayer.SVGAParser; +import com.opensource.svgaplayer.SVGAVideoEntity; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.Constants; +import com.yunbao.common.R; +import com.yunbao.common.bean.BlindBoxInfoModel; +import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.bean.LiveGiftBean2; +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.dialog.AbsDialogFragment; +import com.yunbao.common.event.GiftNumberEvent; +import com.yunbao.common.event.SendBlindGiftEvent; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.AppManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.NobleUtil; +import com.yunbao.common.utils.SVGAViewUtils; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.views.GiftNumberPopup; +import com.yunbao.common.views.weight.MarqueeTextView; +import com.yunbao.common.views.weight.ViewClicksAntiShake; +import com.yunbao.live.activity.LiveActivity; +import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.adapter.GiftTitleAdapter; +import com.yunbao.live.bean.CoinModel; +import com.yunbao.live.bean.GiftTopBean; +import com.yunbao.live.bean.LiveGuardInfo; +import com.yunbao.live.event.GiftTitleEvent; +import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.live.event.LiveGiftDialogEvent; +import com.yunbao.live.event.LiveGiftItemEvent; +import com.yunbao.live.event.LiveParcelItemRefreshEvent; +import com.yunbao.live.http.LiveHttpUtil; +import com.yunbao.live.views.LiveGiftFragment; +import com.yunbao.live.views.LiveParcelFragment; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +/** + * 直播间新送礼弹窗 + */ +public class LiveGiftPopup extends AbsDialogFragment { + private ImageView gitBackground, nobilityIcon, description, iconArrow; + private JSONArray liveGiftList; + private TextView diamondText, goldText, liveWrap, vipGoldDesc, vipGoldTitle, giftNumber; + private RecyclerView giftTitle; + private GiftTitleAdapter giftTitleAdapter; + private FrameLayout contextLayoutGift; + private String mStream, mLiveUid; + private FrameLayout blindBox, frameBlindTop, noNobility, giftNumberLayout, giftSendLayout; + private ProgressBar progressBlind, progressBlind1, progressBlind2; + private SVGAImageView blindSvga, blindBoxOpen; + private View iconMasking; + private TextView blindNumber, textBlindProgress, textBlindGiftName, liveGiftSend, mLianText, lvStr, leaveHint; + private LinearLayout establishedNobility, levelingLayout; + private View mBtnSendGroup; + private LiveGuardInfo mLiveGuardInfo; + private static final String DEFAULT_COUNT = "1"; + private String mCount = DEFAULT_COUNT; + private String mWishGiftId; + private int isContactGift = 0; + private String by; + private boolean isWrap; + private ProgressBar progressBar; + private MarqueeTextView giftDescription; + private boolean isPk; + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + Bus.getOn(this); + initView(); + initDate(); + } + + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + Bus.getOff(this); + + } + + private void initView() { + gitBackground = mRootView.findViewById(R.id.git_background2); + contextLayoutGift = mRootView.findViewById(R.id.context_layout_gift); + diamondText = mRootView.findViewById(R.id.diamond_text); + goldText = mRootView.findViewById(R.id.gold_text); + giftTitle = mRootView.findViewById(R.id.gift_title); + liveWrap = mRootView.findViewById(R.id.live_wrap); + giftDescription = mRootView.findViewById(R.id.gift_description); + blindBox = mRootView.findViewById(R.id.blind_box); + frameBlindTop = mRootView.findViewById(R.id.frame_blind_top); + progressBlind = mRootView.findViewById(R.id.progress_blind1); + progressBlind1 = mRootView.findViewById(R.id.progress_blind2); + progressBlind2 = mRootView.findViewById(R.id.progress_blind3); + iconMasking = mRootView.findViewById(R.id.icon_masking); + blindSvga = mRootView.findViewById(R.id.blind_svga); + blindBoxOpen = mRootView.findViewById(R.id.blind_box_open); + blindNumber = mRootView.findViewById(R.id.blind_number); + textBlindProgress = mRootView.findViewById(R.id.text_blind_progress); + textBlindGiftName = mRootView.findViewById(R.id.text_blind_gift_name); + noNobility = mRootView.findViewById(R.id.no_nobility); + establishedNobility = mRootView.findViewById(R.id.established_nobility); + nobilityIcon = mRootView.findViewById(R.id.nobility_icon); + vipGoldDesc = mRootView.findViewById(R.id.vipGoldDesc); + vipGoldTitle = mRootView.findViewById(R.id.vipGoldTitle); + giftNumber = mRootView.findViewById(R.id.gift_number); + liveGiftSend = mRootView.findViewById(R.id.live_gift_send); + giftNumberLayout = mRootView.findViewById(R.id.gift_number_layout); + mLianText = mRootView.findViewById(R.id.lian_text); + mBtnSendGroup = mRootView.findViewById(R.id.btn_send_lian); + giftSendLayout = mRootView.findViewById(R.id.gift_send_layout); + description = mRootView.findViewById(R.id.description); + lvStr = mRootView.findViewById(R.id.lv_str); + iconArrow = mRootView.findViewById(R.id.icon_arrow); + leaveHint = mRootView.findViewById(R.id.leave_hint); + progressBar = mRootView.findViewById(R.id.progressBar); + levelingLayout = mRootView.findViewById(R.id.leveling_layout); + //设置礼物弹窗背景 + ImgLoader.displayBlurLive(getContext(), R.drawable.backgroud_custom_gift2, gitBackground); + gitBackground.setAlpha(0.97f); + ImgLoader.display(getContext(), R.mipmap.icon_arrow_right, iconArrow); + //礼物分类tab + LinearLayoutManager manager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); + giftTitle.setLayoutManager(manager); + giftTitleAdapter = new GiftTitleAdapter(); + giftTitle.setAdapter(giftTitleAdapter); + liveWrap.setAlpha(0.5f); + liveWrap.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL); + liveGiftSend.setEnabled(false); + giftNumberLayout.setVisibility(View.INVISIBLE); + giftDescription.setVisibility(View.GONE); + levelingLayout.setVisibility(View.VISIBLE); + //点击包裹 + ViewClicksAntiShake.clicksAntiShake(liveWrap, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + giftTitleAdapter.uncheck(); + liveWrap.setAlpha(1.0f); + liveWrap.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + transaction.replace(R.id.context_layout_gift, LiveParcelFragment.newInstance(mStream, mLiveUid)); + transaction.commit(); + isWrap = true; + } + }); + //;连送 + ViewClicksAntiShake.clicksAntiShake(mBtnSendGroup, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + sendGift(); + } + }); + //送礼 + ViewClicksAntiShake.clicksAntiShake(liveGiftSend, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + sendGift(); + } + }); + // 跳转充值 + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.diamond_linear), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + forwardMyCoin(0); + } + }); + // 跳转充值 + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.gold_layout), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + forwardMyCoin(2); + } + }); + // 盲盒说明 + ViewClicksAntiShake.clicksAntiShake(description, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); + StringBuffer htmlUrl = new StringBuffer(); + htmlUrl.append(CommonAppConfig.HOST) + .append("/h5/info/index.html?uid=") + .append(userInfo.getId()) + .append("&token=") + .append(userInfo.getToken()); + Bundle bundle = new Bundle(); + bundle.putString("url", htmlUrl.toString()); + LiveHDDialogFragment fragment = new LiveHDDialogFragment(); + fragment.setArguments(bundle); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + } + }); + // 跳转贵族 + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.btn_luck_gift_tip), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + dismiss(); + ((LiveActivity) mContext).openLuckGiftTip(); + } + }); + //用户等级 + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.leveling_layout), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo(); + StringBuffer htmlUrl = new StringBuffer(); + htmlUrl.append(CommonAppConfig.HOST) + .append("/h5/Grade/index.html?uid=") + .append(userInfo.getId()) + .append("&token=") + .append(userInfo.getToken()) + .append("&for"); + Bundle bundle = new Bundle(); + bundle.putString("url", htmlUrl.toString()); + LiveHDDialogFragment fragment = new LiveHDDialogFragment(); + fragment.setArguments(bundle); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + } + }); + //选择礼物数量 + ViewClicksAntiShake.clicksAntiShake(giftNumberLayout, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + if (liveGiftModel.getType() == 7) return; + new XPopup.Builder(getContext()) + .asCustom(new GiftNumberPopup(getContext())) + .show(); + ImgLoader.display(getContext(), R.mipmap.icon_arrow_down, iconArrow); + } + }); + } + + private void initDate() { + Bundle bundle = getArguments(); + if (bundle != null) { + mLiveUid = bundle.getString("mLiveUid"); + mStream = bundle.getString("mStream"); + mLiveGuardInfo = bundle.getParcelable("GuardInfo"); + mWishGiftId = bundle.getString("WishGiftId"); + isContactGift = bundle.getBoolean("ContactGift", false) ? 1 : 0; + by = bundle.getString("by"); + isPk = bundle.getBoolean("pk"); + } + + //判断是否缓存礼物列表 + String giftListJson = CommonAppConfig.getInstance().getGiftListJson(); + if (!TextUtils.isEmpty(giftListJson)) { + try { + liveGiftList = JSON.parseArray(giftListJson); + Bus.getOn(this); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (liveGiftList == null) { + 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]); + liveGiftList = obj.getJSONArray("listarray"); + CommonAppConfig.getInstance().setGiftListJson(obj.getString("listarray")); + getCoin(); + goldText.setText(obj.getString("gold")); + diamondText.setText(obj.getString("coin")); + setTitleData(); + + } + } + + @Override + public void onFinish() { +// if (mLoading != null) { +// mLoading.setVisibility(View.INVISIBLE); +// } + } + }); + } else { + getCoin(); + setTitleData(); + } + getBlindBoxInfo(); + loadUserVip(); + } + + //设置礼物类别数据 + private void setTitleData() { + List name = new ArrayList<>(); + for (int i = 0; i < liveGiftList.size(); i++) { + JSONObject data = liveGiftList.getJSONObject(i); + GiftTopBean giftTopBean = new GiftTopBean(); + giftTopBean.setName(data.getString("name")); + name.add(giftTopBean); + } + giftTitleAdapter.addAllData(name); + if (!TextUtils.isEmpty(mWishGiftId) && liveGiftList.size() > 0) { + for (int i = 0; i < liveGiftList.size(); i++) { + JSONObject data = liveGiftList.getJSONObject(i); + String giftJson = data.getString("giftlist"); + List liveGiftBeans = JSONArray.parseArray(giftJson, LiveGiftBean.class); + for (LiveGiftBean model : liveGiftBeans) { + if (TextUtils.equals(model.getId() + "", mWishGiftId)) { + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + transaction.replace(R.id.context_layout_gift, LiveGiftFragment.newInstance(giftJson, + liveGiftList.getJSONObject(i).getString("name"), + mStream, mLiveUid, mWishGiftId)); + transaction.commit(); + } + } + } + } else { + + JSONObject obj2 = liveGiftList.getJSONObject(0); + String giftJson = obj2.getString("giftlist"); + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + transaction.replace(R.id.context_layout_gift, LiveGiftFragment.newInstance(giftJson, + liveGiftList.getJSONObject(0).getString("name"), + mStream, mLiveUid, mWishGiftId)); + transaction.commit(); + } + + + } + + /** + * 设置贵族状态 + */ + private void loadUserVip() { + HttpClient.getInstance().get("User.getBaseInfos", "getBaseInfo") + .params("uid", IMLoginManager.get(mContext).getUserInfo().getId()) + .params("token", IMLoginManager.get(mContext).getUserInfo().getToken()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject user = JSONObject.parseObject(info[0]); + int nobleId = user.getIntValue("noble_id"); + int resId = NobleUtil.nobleIdToImageResId(nobleId); + if (resId != -1) { + nobilityIcon.setImageResource(resId); + vipGoldTitle.setText(user.getString("noble_name")); + vipGoldDesc.setText(com.yunbao.live.R.string.live_gift_buy_gold_desc_to); + noNobility.setVisibility(View.GONE); + establishedNobility.setVisibility(View.VISIBLE); + } else { + noNobility.setVisibility(View.VISIBLE); + establishedNobility.setVisibility(View.GONE); + + } + } + } + }); + } + + /** + * 获取砖石和金豆余额 + */ + private void getCoin() { + LiveHttpUtil.getCoin(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + if (!TextUtils.isEmpty(info[0])) { + CoinModel coinModel = GsonUtils.fromJson(info[0], CoinModel.class); + goldText.setText(coinModel.getGold()); + diamondText.setText(coinModel.getCoin()); + lvStr.setText("Lv." + coinModel.getUserLevel()); + int nextLeve = Integer.parseInt(coinModel.getUserLevel()); + int maxLeve = Integer.parseInt(coinModel.getUserLevelMax()); + if (maxLeve > nextLeve) { + String leveNext = String.valueOf(nextLeve + 1); + String userNextLevel = coinModel.getUserNextLevelRewards(); + String hint = String.format(getString(R.string.leveling_points), + userNextLevel, leveNext); + int leveNextIndexOf = hint.indexOf(leveNext); + int leveNextSize = leveNext.length(); + int userNextLevelIndexOf = msg.indexOf(userNextLevel); + int userNextLevelSize = userNextLevel.length(); + SpannableStringBuilder builder = new SpannableStringBuilder(); + builder.append(msg); + builder.setSpan(new + ForegroundColorSpan(Color.parseColor("#FFC722")), + leveNextIndexOf, leveNextIndexOf + leveNextSize, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + builder.setSpan(new + ForegroundColorSpan(Color.parseColor("#FFC722")), + userNextLevelIndexOf, userNextLevelIndexOf + userNextLevelSize, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + leaveHint.setText(builder); + } else { + String hint = getString(R.string.reach_the_top); + leaveHint.setText(hint); + progressBar.setMax(10); + progressBar.setProgress(10); + } + + } + + + } + } + }); + } + + /** + * 赠送礼物 + */ + public void sendGift() { + if (liveGiftModel == null) return; + if (liveGiftModel.getTag() != null) { + if (mCount.equals("1")) { + LiveHttpUtil.setFrontTask("sendgift", mLiveUid, new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + EventBus.getDefault().post("stop_svga_new_user_gif"); + EventBus.getDefault().post("stop_new_user_gif"); + if (code == 0) { + EventBus.getDefault().post("stop_new_user_gif1"); + } + dismiss(); + } + }); + } else { + ToastUtil.show(com.yunbao.live.R.string.only_one); + } + } else { + if (TextUtils.isEmpty(mLiveUid) || TextUtils.isEmpty(mStream) || liveGiftModel == null) { + return; + } + if (mLiveGuardInfo != null) { + if (liveGiftModel.getMark() == LiveGiftBean2.MARK_GUARD && mLiveGuardInfo.getMyGuardType() != Constants.GUARD_TYPE_YEAR) { + ToastUtil.show(com.yunbao.live.R.string.guard_gift_tip); + return; + } + } + SendGiftCallback callback = new SendGiftCallback(liveGiftModel); + try { + if (!StringUtil.isEmpty(mWishGiftId) && liveGiftModel.getId() != Integer.parseInt(mWishGiftId)) { + isContactGift = 0; + } + } catch (NumberFormatException e) { + isContactGift = 0; + } + if (by != null) { + LiveHttpUtil.sendGift("1", mLiveUid, mStream, liveGiftModel.getId(), mCount, isContactGift, callback); + } else { + LiveHttpUtil.sendGift("0", mLiveUid, mStream, liveGiftModel.getId(), mCount, isContactGift, callback); + } + } + } + + /** + * 跳转到我的钻石 + */ + private void forwardMyCoin(int page) { + dismiss(); + //我们的 + ARouter.getInstance().build(PATH_COIN).withInt("p", page).navigation(); + } + + //连送逻辑 + private int mLianCountDownCount;//连送倒计时的数字 + + private Handler lianSongHandler = new Handler(); + private Runnable lianSongRunnable = new Runnable() { + @Override + public void run() { + if (removeRunnable) { + lianSongHandler.removeCallbacks(lianSongRunnable); + if (mLianText != null) { + mLianText.setText("5s"); + } + mLianCountDownCount = 5; + lianSongHandler.postDelayed(lianSongRunnable, 1000); + removeRunnable = false; + } else { + mLianCountDownCount--; + if (mLianCountDownCount == 0) { + hideLianBtn(); + } else { + if (mLianText != null) { + mLianText.setText(mLianCountDownCount + "s"); + lianSongHandler.postDelayed(lianSongRunnable, 1000); + } + } + } + + } + }; + + /** + * 显示连送按钮 + */ + private boolean mShowLianBtn = false; + private boolean removeRunnable = false; + + private void showLianBtn() { + + + if (mShowLianBtn) { + removeRunnable = true; + } else { + if (mLianText != null) { + mLianText.setText("5s"); + } + mLianCountDownCount = 5; + lianSongHandler.postDelayed(lianSongRunnable, 1000); + mBtnSendGroup.setVisibility(View.VISIBLE); + giftSendLayout.setVisibility(View.INVISIBLE); + mShowLianBtn = true; + } + + + } + + /** + * 隐藏连送按钮 包裹 + */ + private void hideLianBtn() { + mBtnSendGroup.setVisibility(View.INVISIBLE); + giftSendLayout.setVisibility(View.VISIBLE); + lianSongHandler.removeCallbacks(lianSongRunnable); + mShowLianBtn = false; + } + + /** + * 关于点击礼物分类的通知 + */ + @Subscribe(threadMode = ThreadMode.MAIN) + public void onGiftTitleEvent(GiftTitleEvent event) { + liveWrap.setAlpha(0.5f); + liveWrap.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL); + liveGiftSend.setEnabled(false); + giftNumberLayout.setVisibility(View.INVISIBLE); + JSONObject obj2 = liveGiftList.getJSONObject(event.getmPosition()); + String giftJson = obj2.getString("giftlist"); + + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + transaction.replace(R.id.context_layout_gift, LiveGiftFragment.newInstance(giftJson, event.getGiftTitle(), mStream, mLiveUid, mWishGiftId)); + transaction.commit(); + isWrap = false; + if (giftSendLayout.getVisibility() == View.INVISIBLE) { + hideLianBtn(); + } + mCount = DEFAULT_COUNT; + giftNumber.setText(mCount); + giftDescription.setVisibility(View.GONE); + levelingLayout.setVisibility(View.VISIBLE); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onGiftNumberEvent(GiftNumberEvent event) { + if (TextUtils.equals(event.getmCount(), "-1")) { + + } else { + mCount = event.getmCount(); + giftNumber.setText(mCount); + } + + } + + /** + * 选中的礼物数据 + * + * @param event + */ + private LiveGiftBean liveGiftModel = null; + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLiveGiftItemEvent(LiveGiftItemEvent event) { + + liveGiftModel = event.getLiveGiftModel(); + if (liveGiftModel.getType() == 7) { + showBlindProgress(liveGiftModel.getBlind_box_type()); + } else { + blindBox.setVisibility(View.INVISIBLE); + mCount = DEFAULT_COUNT; + giftNumber.setText(mCount); + } + liveGiftSend.setEnabled(true); + giftNumberLayout.setVisibility(View.VISIBLE); + mCount = DEFAULT_COUNT; + giftNumber.setText(mCount); + if (giftSendLayout.getVisibility() == View.INVISIBLE) { + hideLianBtn(); + } + if (TextUtils.isEmpty(liveGiftModel.getGiftDescription())) { + giftDescription.setVisibility(View.GONE); + levelingLayout.setVisibility(View.VISIBLE); + } else { + giftDescription.setText(liveGiftModel.getGiftDescription()); + giftDescription.setVisibility(View.VISIBLE); + levelingLayout.setVisibility(View.GONE); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLiveGiftDialogEvent(LiveGiftDialogEvent event) { + dismiss(); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSendBlindGiftEvent(SendBlindGiftEvent event) { + if (!TextUtils.equals(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()), event.getUid())) + return; + BlindBoxInfoModel model = null; + for (int i = 0; i < blindBoxInfoModels.size(); i++) { + if (TextUtils.equals(blindBoxInfoModels.get(i).getBlindBoxType(), event.getBoxType())) { + blindBoxInfoModels.get(i).setDressThresholdValue(event.getDressThresholdValue()); + blindBoxInfoModels.get(i).setThresholdValue(event.getThresholdValue()); + model = blindBoxInfoModels.get(i); + } + } + + long userID = IMLoginManager.get(mContext).getUserInfo().getId(); + String boxBlindName; + try { + if (!blindBoxOpen.isAnimating()) { + new SVGAParser(mContext).parse(new URL(model.getBlindBoxSwf()), new SVGAParser.ParseCompletion() { + @Override + public void onComplete(SVGAVideoEntity videoItem) { + blindBoxOpen.setVisibility(View.VISIBLE); + SVGADrawable drawable = new SVGADrawable(videoItem); + blindBoxOpen.setImageDrawable(drawable); + blindBoxOpen.setLoops(1); + blindBoxOpen.startAnimation(); + + } + + @Override + public void onError() { + } + }); + + blindBoxOpen.setCallback(new SVGACallback() { + @Override + public void onPause() { + } + + @Override + public void onFinished() { + blindBoxOpen.clear(); + blindBoxOpen.setVisibility(View.GONE); + Log.e("礼物盲盒", "结束播放"); + } + + @Override + public void onRepeat() { + } + + @Override + public void onStep(int i, double v) { + Log.e("礼物盲盒", "onStep: frame " + i + " percentage " + v); + } + }); + } + + } catch (MalformedURLException e) { + e.printStackTrace(); + } + //判断送礼用户更新送礼用户进度 + if (TextUtils.equals(String.valueOf(userID), event.getUid()) && blindBoxType == Integer.parseInt(event.getBoxType())) { + switch (blindBoxType) { + case 1: + boxBlindName = mContext.getString(R.string.mini_blind_box); + + progressBlind.setMax(Integer.parseInt(model.getThresholdValue())); + progressBlind.setProgress(Integer.parseInt(model.getDressThresholdValue())); + break; + case 2: + boxBlindName = mContext.getString(R.string.collection_blind_box); + + progressBlind1.setMax(Integer.parseInt(model.getThresholdValue())); + progressBlind1.setProgress(Integer.parseInt(model.getDressThresholdValue())); + + break; + default: + boxBlindName = mContext.getString(R.string.pd_blind_box); + progressBlind2.setMax(Integer.parseInt(model.getThresholdValue())); + progressBlind2.setProgress(Integer.parseInt(model.getDressThresholdValue())); + break; + } + //进度下方提示语 + if (TextUtils.equals(model.getThresholdValue(), model.getDressThresholdValue())) { + String individualDressing = mContext.getString(R.string.individual_dressing); + String msg = mContext.getString(R.string.have_already_win); + msg = String.format(msg, model.getThresholdDressName()); + int dressNameIndexOf = msg.indexOf(model.getThresholdDressName()); + int individualDressingIndexOf = msg.indexOf(String.valueOf(individualDressing)); + int dressNameSize = model.getThresholdDressName().length(); + int individualDressingSize = String.valueOf(individualDressing).length(); + SpannableStringBuilder builder = new SpannableStringBuilder(); + builder.append(msg); + builder.setSpan(new ForegroundColorSpan(Color.parseColor("#FFF682")), dressNameIndexOf, dressNameIndexOf + dressNameSize, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + builder.setSpan(new ForegroundColorSpan(Color.parseColor("#FFF682")), individualDressingIndexOf, individualDressingIndexOf + individualDressingSize, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + blindNumber.setText(builder); + textBlindProgress.setText(R.string.get_it_done); + } else { + int progress = Integer.parseInt(model.getThresholdValue()) - Integer.parseInt(model.getDressThresholdValue()); + String msg = mContext.getString(R.string.resend_win); + msg = String.format(msg, String.valueOf(progress), model.getThresholdDressName()); + int dressNameIndexOf = msg.indexOf(model.getThresholdDressName()); + int progressIndexOf = msg.indexOf(String.valueOf(progress)); + int dressNameSize = model.getThresholdDressName().length(); + int progressSize = String.valueOf(progress).length(); + SpannableStringBuilder builder = new SpannableStringBuilder(); + builder.append(msg); + builder.setSpan(new ForegroundColorSpan(Color.parseColor("#FFF682")), dressNameIndexOf, dressNameIndexOf + dressNameSize, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + builder.setSpan(new ForegroundColorSpan(Color.parseColor("#FFF682")), progressIndexOf, progressIndexOf + progressSize, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + blindNumber.setText(builder); + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append(model.getDressThresholdValue()) + .append("/") + .append(model.getThresholdValue()); + textBlindProgress.setText(stringBuffer.toString()); + float maskingAlpha = (float) progress / Float.parseFloat(model.getThresholdValue()); + iconMasking.setAlpha(maskingAlpha); + } + if (stringBuilders.size() == 0) { + boxBlindHandler.postDelayed(boxBlindRunnable, 1500); + } + if (!TextUtils.isEmpty(event.getDressName()) && !TextUtils.isEmpty(event.getDressMsg())) { + SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); + String boxBlindMsg = String.format(mContext.getString(R.string.random_availability2), event.getGiftname(), event.getDressName()); + stringBuilder.append(boxBlindMsg); + int dressNameIndex = boxBlindMsg.indexOf(event.getDressName()); + int dressNameSize = event.getDressName().length(); + int giftNameIndex = boxBlindMsg.indexOf(event.getGiftname()); + int giftNameSize = event.getGiftname().length(); + stringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor(event.getDressColour())), + dressNameIndex, + dressNameIndex + dressNameSize, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + stringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor(event.getGiftColour())), + giftNameIndex, + giftNameIndex + giftNameSize, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + stringBuilders.add(stringBuilder); + } else { + SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); + String boxBlindMsg = String.format(mContext.getString(R.string.random_availability3), event.getGiftname()); + stringBuilder.append(boxBlindMsg); + int giftNameIndex = boxBlindMsg.indexOf(event.getGiftname()); + int giftNameSize = event.getGiftname().length(); + stringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor(event.getGiftColour())), + giftNameIndex, + giftNameIndex + giftNameSize, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + stringBuilders.add(stringBuilder); + + } + + + } + } + + private List stringBuilders = new ArrayList<>(); + private Handler boxBlindHandler = new Handler(); + private Runnable boxBlindRunnable = new Runnable() { + @Override + public void run() { + if (stringBuilders != null && stringBuilders.size() > 0) { + SpannableStringBuilder stringBuilder = stringBuilders.get(0); + textBlindGiftName.setText(stringBuilder); + boxBlindHandler.postDelayed(boxBlindRunnable, 1500); + stringBuilders.remove(0); + } else { + textBlindGiftName.setText(String.format(mContext.getString(R.string.random_availability), blindGiftNamesBuffer.toString())); + } + } + }; + public List blindBoxInfoModels = new ArrayList<>(); + + private void getBlindBoxInfo() { + LiveNetManager.get(mContext) + .getBlindBoxInfo(new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List data) { + blindBoxInfoModels = data; + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + } + + /** + * 展示当前盲盒礼物进度 + * + * @param blindBoxType + */ + private StringBuffer blindGiftNamesBuffer = null; + private int blindBoxType; + + private void showBlindProgress(int blindBoxType) { + this.blindBoxType = blindBoxType; + blindGiftNamesBuffer = new StringBuffer(); + BlindBoxInfoModel model = null; + for (BlindBoxInfoModel boxInfoModel : blindBoxInfoModels) { + if (TextUtils.equals(String.valueOf(blindBoxType), boxInfoModel.getBlindBoxType())) { + model = boxInfoModel; + } + } + if (model == null) return; + blindBoxOpen.clear(); + blindBoxOpen.setVisibility(View.GONE); + try { + blindSvga.clear(); + new SVGAParser(mContext).parse(new URL(model.getThresholdEffectSrc()), new SVGAParser.ParseCompletion() { + @Override + public void onComplete(SVGAVideoEntity videoItem) { + SVGADrawable drawable = new SVGADrawable(videoItem); + blindSvga.setImageDrawable(drawable); + SVGAViewUtils.playEndClear(blindSvga, false); + + } + + @Override + public void onError() { + Log.e("errqs", "errl"); + } + }); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + blindBox.setVisibility(View.VISIBLE); + String boxBlindName = ""; + switch (blindBoxType) { + case 1: + boxBlindName = mContext.getString(R.string.mini_blind_box); + progressBlind.setVisibility(View.VISIBLE); + progressBlind1.setVisibility(View.GONE); + progressBlind2.setVisibility(View.GONE); + frameBlindTop.setBackgroundResource(com.yunbao.live.R.mipmap.bg_kirin); + iconMasking.setBackgroundResource(com.yunbao.live.R.mipmap.icon_masking_kirin); + progressBlind.setMax(Integer.parseInt(model.getThresholdValue())); + progressBlind.setProgress(Integer.parseInt(model.getDressThresholdValue())); + textBlindProgress.setTextColor(Color.parseColor("#047771")); + break; + case 2: + boxBlindName = mContext.getString(com.yunbao.live.R.string.collection_blind_box); + progressBlind.setVisibility(View.GONE); + progressBlind1.setVisibility(View.VISIBLE); + progressBlind2.setVisibility(View.GONE); + frameBlindTop.setBackgroundResource(com.yunbao.live.R.mipmap.bg_phoenix); + iconMasking.setBackgroundResource(com.yunbao.live.R.mipmap.icon_masking_phoenix); + progressBlind1.setMax(Integer.parseInt(model.getThresholdValue())); + progressBlind1.setProgress(Integer.parseInt(model.getDressThresholdValue())); + textBlindProgress.setTextColor(Color.parseColor("#6D2E0F")); + + break; + default: + boxBlindName = mContext.getString(com.yunbao.live.R.string.pd_blind_box); + progressBlind.setVisibility(View.GONE); + progressBlind1.setVisibility(View.GONE); + progressBlind2.setVisibility(View.VISIBLE); + frameBlindTop.setBackgroundResource(com.yunbao.live.R.mipmap.bg_dragon); + iconMasking.setBackgroundResource(com.yunbao.live.R.mipmap.icon_masking_dragon); + progressBlind2.setMax(Integer.parseInt(model.getThresholdValue())); + progressBlind2.setProgress(Integer.parseInt(model.getDressThresholdValue())); + textBlindProgress.setTextColor(Color.parseColor("#905E01")); + break; + } + + //进度下方提示语 + if (TextUtils.equals(model.getThresholdValue(), model.getDressThresholdValue())) { + String individualDressing = mContext.getString(com.yunbao.live.R.string.individual_dressing); + String msg = mContext.getString(com.yunbao.live.R.string.have_already_win); + msg = String.format(msg, model.getThresholdDressName()); + int dressNameIndexOf = msg.indexOf(model.getThresholdDressName()); + int individualDressingIndexOf = msg.indexOf(String.valueOf(individualDressing)); + int dressNameSize = model.getThresholdDressName().length(); + int individualDressingSize = String.valueOf(individualDressing).length(); + SpannableStringBuilder builder = new SpannableStringBuilder(); + builder.append(msg); + builder.setSpan(new ForegroundColorSpan(Color.parseColor("#FFF682")), dressNameIndexOf, dressNameIndexOf + dressNameSize, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + builder.setSpan(new ForegroundColorSpan(Color.parseColor("#FFF682")), individualDressingIndexOf, individualDressingIndexOf + individualDressingSize, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + blindNumber.setText(builder); + iconMasking.setAlpha(0.f); + } else { + int progress = Integer.parseInt(model.getThresholdValue()) - Integer.parseInt(model.getDressThresholdValue()); + String msg = mContext.getString(com.yunbao.live.R.string.resend_win); + msg = String.format(msg, String.valueOf(progress), model.getThresholdDressName()); + int dressNameIndexOf = msg.indexOf(model.getThresholdDressName()); + int progressIndexOf = msg.indexOf(String.valueOf(progress)); + int dressNameSize = model.getThresholdDressName().length(); + int progressSize = String.valueOf(progress).length(); + SpannableStringBuilder builder = new SpannableStringBuilder(); + builder.append(msg); + builder.setSpan(new ForegroundColorSpan(Color.parseColor("#FFF682")), dressNameIndexOf, dressNameIndexOf + dressNameSize, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + builder.setSpan(new ForegroundColorSpan(Color.parseColor("#FFF682")), progressIndexOf, progressIndexOf + progressSize, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + blindNumber.setText(builder); + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append(model.getDressThresholdValue()) + .append("/") + .append(model.getThresholdValue()); + textBlindProgress.setText(stringBuffer.toString()); + float maskingAlpha = (float) progress / Float.parseFloat(model.getThresholdValue()); + iconMasking.setAlpha(maskingAlpha); + } + //盲盒礼物文字跑马灯 + for (int i = 0; i < model.getItemName().size(); i++) { + blindGiftNamesBuffer + .append(model.getItemName().get(i)); + + if (i != model.getItemName().size() - 1) { + blindGiftNamesBuffer.append(","); + } + } + textBlindGiftName.setText(String.format(mContext.getString(com.yunbao.live.R.string.random_availability), blindGiftNamesBuffer.toString())); + + } + + // 返回自定义弹窗的布局 + @Override + protected int getLayoutId() { + return R.layout.dialog_live_gift_popup; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog2; + } + + @Override + protected boolean canCancel() { + return true; + } + + @Override + protected void setWindowAttributes(Window window) { + window.setWindowAnimations(R.style.bottomToTopAnim); + window.setDimAmount(0f);//去掉遮罩层(全透明) + WindowManager.LayoutParams params = window.getAttributes(); + params.width = WindowManager.LayoutParams.MATCH_PARENT; + params.height = WindowManager.LayoutParams.WRAP_CONTENT; + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + } + + private class SendGiftCallback extends HttpCallback { + + private LiveGiftBean mGiftBean; + + public SendGiftCallback(LiveGiftBean giftBean) { + mGiftBean = giftBean; + } + + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + if (mGiftBean.getSwf().contains("svga")) { + dismiss(); + } + if (info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + String coin = obj.getString("coin"); + String goldCoin = obj.getString("gold"); + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u != null) { + u.setLevel(obj.getIntValue("level")); + //送礼物后更新粉丝徽章等级 + u.setMedalLevel(obj.getIntValue("medal_level")); + u.setMedalName(obj.getString("medal_name")); + u.setCoin(coin); + } + if (diamondText != null) { + diamondText.setText(coin); + } + if (goldText != null) { + goldText.setText(goldCoin); + } + if (mGiftBean.getType() == LiveGiftBean2.TYPE_NORMAL && !mGiftBean.getSwf().contains("svga")) { + showLianBtn(); + } + if (mGiftBean.getType() == 7) { + showLianBtn(); + } +// //刷新包裹列表wrap_gift_num -1:表示数量没有变化 +// mObjGiftSendback = obj; + isGetNewWrap = true; + if (isWrap) { + Bus.get().post(new LiveParcelItemRefreshEvent().setLiveGiftModel(liveGiftModel)); + } + } + } else if (code == 1007 && mGiftBean.getType() != 0) { + hideLianBtn(); + dismiss(); + LiveAudienceEvent.LiveAudienceType type = null; + String confirmString = mContext.getString(com.yunbao.live.R.string.dialog_fount_submit); + String tips = msg; + switch (mGiftBean.getType()) { + case 1: + type = LiveAudienceEvent.LiveAudienceType.NOBLE; + tips = mContext.getString(com.yunbao.live.R.string.dialog_live_gift_noble); + confirmString = mContext.getString(com.yunbao.live.R.string.dialog_live_gift_open_noble); + break; + case 2: + type = LiveAudienceEvent.LiveAudienceType.GUARD; + tips = mContext.getString(com.yunbao.live.R.string.dialog_live_gift_guard); + confirmString = mContext.getString(com.yunbao.live.R.string.dialog_live_gift_open_guard); + break; + case 3: + type = LiveAudienceEvent.LiveAudienceType.FAN_CLUB; + tips = mContext.getString(com.yunbao.live.R.string.dialog_live_gift_fans); + confirmString = mContext.getString(com.yunbao.live.R.string.dialog_live_gift_open_fans); + } + LiveAudienceEvent.LiveAudienceType finalType = type; + new DialogUitl.Builder(mContext) + .setView(com.yunbao.live.R.layout.dialog_live_unfollow) + .setConfirmString(confirmString) + .setContent(tips) + .setClickCallback((dialog, content) -> { + LiveAudienceEvent event = new LiveAudienceEvent() + .setType(finalType); + if (finalType == LiveAudienceEvent.LiveAudienceType.GUARD) { + event = event.setObject(""); + } + Bus.get().post(event); + }).build().show(); + + AppManager.runDebugCode(() -> { + Log.i("gifBean", mGiftBean.toString()); + }); + } else if (code == 1001) { + hideLianBtn(); + new DialogUitl.Builder(mContext) + .setView(com.yunbao.live.R.layout.dialog_live_unfollow) + .setConfirmString(getString(com.yunbao.live.R.string.charge)) + .setContent(getString(com.yunbao.live.R.string.insufficient_balance)) + .setClickCallback(new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + forwardMyCoin(0); + } + }).build().show(); + } else { + hideLianBtn(); + ToastUtil.show(msg); + } + } + } + +} diff --git a/live/src/main/java/com/yunbao/live/event/GiftTitleEvent.java b/live/src/main/java/com/yunbao/live/event/GiftTitleEvent.java new file mode 100644 index 000000000..2330d2e8e --- /dev/null +++ b/live/src/main/java/com/yunbao/live/event/GiftTitleEvent.java @@ -0,0 +1,26 @@ +package com.yunbao.live.event; + +import com.yunbao.common.bean.BaseModel; + +public class GiftTitleEvent extends BaseModel { + private String giftTitle; + private int mPosition; + + public int getmPosition() { + return mPosition; + } + + public GiftTitleEvent setmPosition(int mPosition) { + this.mPosition = mPosition; + return this; + } + + public String getGiftTitle() { + return giftTitle; + } + + public GiftTitleEvent setGiftTitle(String giftTitle) { + this.giftTitle = giftTitle; + return this; + } +} diff --git a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index 712463b10..7c62ecdf4 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -14,6 +14,7 @@ import com.yunbao.common.bean.WishModel; import com.yunbao.common.bean.XydCompleteModel; import com.yunbao.common.event.AllServerNotifyEvent; import com.yunbao.common.event.CustomFullServiceNotifyEvent; +import com.yunbao.live.bean.LiveGuardInfo; import com.yunbao.live.bean.LivePKUserListBean; import com.yunbao.live.bean.LiveReceiveGiftBean; import com.yunbao.live.bean.OpenParametersModel; @@ -49,6 +50,75 @@ public class LiveAudienceEvent extends BaseModel { private RedPacketModel redPacketModel; private RedPacketInfoModel redPacketInfoModel; private OlineUserlistModel olineUserlistModel; + private LiveGuardInfo liveGuardInfo; + private String mWishGiftId; + private boolean isContactGift; + private boolean isPk; + public String mStream; + public String mLiveUid,giftId; + + public String getGiftId() { + return giftId; + } + + public LiveAudienceEvent setGiftId(String giftId) { + this.giftId = giftId; + return this; + } + + public String getmStream() { + return mStream; + } + + public LiveAudienceEvent setmStream(String mStream) { + this.mStream = mStream; + return this; + } + + public String getmLiveUid() { + return mLiveUid; + } + + public LiveAudienceEvent setmLiveUid(String mLiveUid) { + this.mLiveUid = mLiveUid; + return this; + } + + public boolean isPk() { + return isPk; + } + + public LiveAudienceEvent setPk(boolean pk) { + isPk = pk; + return this; + } + + public boolean getIsContactGift() { + return isContactGift; + } + + public LiveAudienceEvent setIsContactGift(boolean isContactGift) { + this.isContactGift = isContactGift; + return this; + } + + public String getmWishGiftId() { + return mWishGiftId; + } + + public LiveAudienceEvent setmWishGiftId(String mWishGiftId) { + this.mWishGiftId = mWishGiftId; + return this; + } + + public LiveGuardInfo getLiveGuardInfo() { + return liveGuardInfo; + } + + public LiveAudienceEvent setLiveGuardInfo(LiveGuardInfo liveGuardInfo) { + this.liveGuardInfo = liveGuardInfo; + return this; + } public OlineUserlistModel getOlineUserlistModel() { return olineUserlistModel; diff --git a/live/src/main/java/com/yunbao/live/event/LiveGiftItemEvent.java b/live/src/main/java/com/yunbao/live/event/LiveGiftItemEvent.java new file mode 100644 index 000000000..92aeb97b6 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/event/LiveGiftItemEvent.java @@ -0,0 +1,20 @@ +package com.yunbao.live.event; + +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.LiveGiftBean; + +/** + * 选中的礼物 + */ +public class LiveGiftItemEvent extends BaseModel { + private LiveGiftBean liveGiftModel; + + public LiveGiftBean getLiveGiftModel() { + return liveGiftModel; + } + + public LiveGiftItemEvent setLiveGiftModel(LiveGiftBean liveGiftModel) { + this.liveGiftModel = liveGiftModel; + return this; + } +} diff --git a/live/src/main/java/com/yunbao/live/event/LiveParcelItemRefreshEvent.java b/live/src/main/java/com/yunbao/live/event/LiveParcelItemRefreshEvent.java new file mode 100644 index 000000000..db6797e23 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/event/LiveParcelItemRefreshEvent.java @@ -0,0 +1,17 @@ +package com.yunbao.live.event; + +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.LiveGiftBean; + +public class LiveParcelItemRefreshEvent extends BaseModel { + private LiveGiftBean liveGiftModel; + + public LiveGiftBean getLiveGiftModel() { + return liveGiftModel; + } + + public LiveParcelItemRefreshEvent setLiveGiftModel(LiveGiftBean liveGiftModel) { + this.liveGiftModel = liveGiftModel; + return this; + } +} diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java index 214e22522..9f1937601 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java @@ -6,7 +6,6 @@ import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.drawable.Drawable; -import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; @@ -46,6 +45,7 @@ import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.GiftCacheUtil; import com.yunbao.common.utils.HtmlTagHandler; @@ -53,12 +53,11 @@ import com.yunbao.common.utils.L; import com.yunbao.common.utils.MicStatusManager; import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.bean.LiveGiftPrizePoolWinBean; import com.yunbao.live.bean.LiveLuckGiftWinBean; import com.yunbao.live.bean.LiveReceiveGiftBean; import com.yunbao.live.custom.FrameImageView; -import com.yunbao.live.dialog.LiveGiftDialogFragment; +import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.event.LiveRoomChangeEvent; import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.utils.AllMsgTextRender; @@ -339,14 +338,12 @@ public class LiveGiftAnimPresenter { new Handler().postDelayed(new Runnable() { @Override public void run() { - LiveGiftDialogFragment fragment = new LiveGiftDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.LIVE_STREAM, mStream); - bundle.putString(Constants.LIVE_WISH_GIFTID, blindBox.getEvent().getBlindBoxId() + ""); - bundle.putBoolean("isContactGift", true); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) + .setmLiveUid(mLiveUid) + .setmStream(mStream) + .setmWishGiftId(blindBox.getEvent().getBlindBoxId() + "") + .setIsContactGift(true)); } }, 1000); } else { diff --git a/live/src/main/java/com/yunbao/live/views/FrameGiftViewHolder.java b/live/src/main/java/com/yunbao/live/views/FrameGiftViewHolder.java new file mode 100644 index 000000000..709767b88 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/FrameGiftViewHolder.java @@ -0,0 +1,158 @@ +package com.yunbao.live.views; + +import android.content.Context; +import android.graphics.Color; +import android.util.TypedValue; +import android.view.View; +import android.view.animation.AccelerateDecelerateInterpolator; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.view.animation.LinearInterpolator; +import android.view.animation.ScaleAnimation; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.lxj.xpopup.XPopup; +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.interfaces.CommonCallback; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.GiftCacheUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.views.weight.ViewClicksAntiShake; +import com.yunbao.live.R; +import com.yunbao.live.dialog.SendRendPacketPopup; +import com.yunbao.live.event.LiveGiftDialogEvent; + +import java.io.File; + +public class FrameGiftViewHolder extends RecyclerView.ViewHolder { + private ImageView giftIcon, mPayIco, cornerMark; + private Context mContext; + private TextView giftName, mPrice; + private RelativeLayout giftLayout; + private ScaleAnimation mAnimation; + private LinearLayout mLoadingLayout; + private ImageView mLoading; + + public FrameGiftViewHolder(@NonNull View itemView) { + super(itemView); + mContext = itemView.getContext(); + giftIcon = itemView.findViewById(R.id.gift_icon); + giftName = itemView.findViewById(R.id.gift_name); + mPayIco = itemView.findViewById(R.id.pay_ico); + mPrice = itemView.findViewById(R.id.price); + cornerMark = itemView.findViewById(R.id.corner_mark); + giftLayout = itemView.findViewById(R.id.gift_layout); + mLoadingLayout = itemView.findViewById(R.id.gift_loading_layout); + mLoading = itemView.findViewById(R.id.gift_loading); + + mAnimation = new ScaleAnimation(0.9f, 1.1f, 0.9f, 1.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); + mAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); + mAnimation.setDuration(400); + mAnimation.setRepeatMode(Animation.REVERSE); + mAnimation.setRepeatCount(-1); + } + + public void showData(int contextLayoutGiftHeight, LiveGiftBean model) { + //设置高度 + itemView.post(new Runnable() { + @Override + public void run() { + GridLayoutManager.LayoutParams linearParams = (GridLayoutManager.LayoutParams) itemView.getLayoutParams(); + linearParams.height = contextLayoutGiftHeight / 2; + itemView.setLayoutParams(linearParams); + } + }); + giftLayout.setSelected(model.isChecked()); + if (model.isChecked()) { + giftIcon.startAnimation(mAnimation); + } + ImgLoader.display(mContext, model.getIcon(), giftIcon); + ImgLoader.display(mContext, model.getCornerMark(), cornerMark); + giftName.setText(model.getName()); + //特殊礼物红包 + if (model.getType() == 9999999) { + mPayIco.setVisibility(View.GONE); + mPrice.setText(mContext.getString(R.string.build_up_popularity)); + mPrice.setTextColor(Color.parseColor("#db8c4a")); + mPrice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 8); + + } else { + mPrice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11); + mPrice.setTextColor(Color.parseColor("#c8c8c8")); + mPayIco.setVisibility(View.VISIBLE); + //普通礼物 + if (model.getSendType() != null && model.getSendType().equals("1")) { + mPayIco.setImageResource(R.mipmap.gold_coin); + } else { + mPayIco.setImageResource(R.mipmap.diamond); + } + mPrice.setText(model.getPrice()); + } + if (model.getSwf() != null && model.getSwf().isEmpty()) { + mLoadingLayout.setVisibility(View.GONE); + } else { + mLoadingLayout.setVisibility(GiftCacheUtil.checkGiftIsDownload(model.getId()) ? View.GONE : View.VISIBLE); + } + + + } + + public void giftSelect(LiveGiftBean model, int position, String mStream, String mLiveUid, FrameGiftClickListener frameGiftClickListener) { + ViewClicksAntiShake.clicksAntiShake(mLoadingLayout, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + mLoading.setImageResource(R.mipmap.icon_loading_gift); + Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.anim_loading_gift); + animation.setRepeatMode(Animation.RESTART); + animation.setRepeatCount(Animation.INFINITE); + animation.setInterpolator(new LinearInterpolator()); + mLoading.startAnimation(animation); + GiftCacheUtil.getInstance().pause(); + GiftCacheUtil.getInstance().downloadGiftForId(mContext, model, new CommonCallback() { + @Override + public void callback(File bean) { + if (bean == null) { + ToastUtil.show(mContext.getString(R.string.load_failure_2)); + mLoading.setImageResource(R.mipmap.icon_download_gift); + animation.setRepeatCount(0); + animation.setDuration(0); + animation.cancel(); + mLoading.setAnimation(animation); + } else { + mLoadingLayout.setVisibility(View.GONE); + } + GiftCacheUtil.getInstance().restart(); + } + }); + } + }); + ViewClicksAntiShake.clicksAntiShake(giftLayout, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + if (model.getType() == 9999999) { + Bus.get().post(new LiveGiftDialogEvent()); + new XPopup.Builder(mContext) + .asCustom(new SendRendPacketPopup(mContext, mLiveUid)) + .show(); + } else { + if (frameGiftClickListener != null) { + frameGiftClickListener.onCallBack(position, model); + } + } + + } + }); + } + + public interface FrameGiftClickListener { + void onCallBack(int position, LiveGiftBean model); + } +} diff --git a/live/src/main/java/com/yunbao/live/views/GiftTitleViewHolder.java b/live/src/main/java/com/yunbao/live/views/GiftTitleViewHolder.java new file mode 100644 index 000000000..d0732f450 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/GiftTitleViewHolder.java @@ -0,0 +1,50 @@ +package com.yunbao.live.views; + +import android.graphics.Typeface; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.common.custom.DrawableTextView; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.views.weight.ViewClicksAntiShake; +import com.yunbao.live.R; +import com.yunbao.live.bean.GiftTopBean; +import com.yunbao.live.event.GiftTitleEvent; + +public class GiftTitleViewHolder extends RecyclerView.ViewHolder { + private DrawableTextView name; + + public GiftTitleViewHolder(@NonNull View itemView) { + super(itemView); + name = itemView.findViewById(R.id.name); + } + + public void showData(GiftTopBean giftTopBean, int mPosition, ClicksCallBack callBack) { + name.setText(giftTopBean.getName()); + ViewClicksAntiShake.clicksAntiShake(itemView, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + if (callBack != null) { + callBack.onViewClicks(mPosition); + Bus.get().post(new GiftTitleEvent().setmPosition(mPosition).setGiftTitle(giftTopBean.getName())); + } + } + }); + } + + public void selectData(boolean isSelect) { + if (isSelect) { + name.setAlpha(1.0f); + name.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); + } else { + name.setAlpha(0.5f); + name.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL); + } + } + + public interface ClicksCallBack { + void onViewClicks(int mPosition); + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java index 8d8267731..f613222ae 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java @@ -10,7 +10,6 @@ import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.os.Vibrator; -import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.view.LayoutInflater; @@ -20,16 +19,12 @@ import android.view.ViewGroup; import android.view.WindowManager; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.ViewFlipper; import androidx.fragment.app.FragmentActivity; -import com.opensource.svgaplayer.SVGADrawable; -import com.opensource.svgaplayer.SVGAImageView; -import com.opensource.svgaplayer.SVGAParser; -import com.opensource.svgaplayer.SVGAVideoEntity; +import com.lxj.xpopup.XPopup; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.bean.NewPeopleInfo; @@ -39,11 +34,10 @@ import com.yunbao.common.http.API; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.utils.Bus; -import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.ProcessResultUtil; -import com.yunbao.common.utils.SVGAViewUtils; import com.yunbao.common.utils.SpUtil; import com.yunbao.common.utils.ToastUtil; +import com.yunbao.live.dialog.LiveGiftPopup; import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; @@ -200,6 +194,7 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { ViewClicksAntiShake.clicksAntiShake(giftImage, new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { + Bus.get().post(new LiveAudienceEvent() .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP)); } @@ -382,6 +377,7 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { } else if (i == R.id.btn_gift) { openGiftWindow(); + //全屏 } else if (i == R.id.btn_more) { ((LiveActivity) mContext).openMoreWindow(); diff --git a/live/src/main/java/com/yunbao/live/views/LiveGiftFragment.java b/live/src/main/java/com/yunbao/live/views/LiveGiftFragment.java new file mode 100644 index 000000000..6c6103bee --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LiveGiftFragment.java @@ -0,0 +1,149 @@ +package com.yunbao.live.views; + +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.widget.RadioButton; +import android.widget.RadioGroup; + +import androidx.fragment.app.Fragment; +import androidx.viewpager.widget.ViewPager; + +import com.alibaba.fastjson.JSON; +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.fragment.BaseFragment; +import com.yunbao.live.R; +import com.yunbao.live.adapter.LiveGiftFragmentPagerAdapter; + +import java.util.ArrayList; +import java.util.List; + +/** + * 礼物列表 + */ +public class LiveGiftFragment extends BaseFragment { + private ViewPager fragmentViewpager; + private int pageCount; + private static final int GIFT_COUNT = 8;//每页8个礼物 + private RadioGroup mRadioGroup; + private LiveGiftFragmentPagerAdapter giftFragmentPagerAdapter; + private ArrayList ViewList = new ArrayList<>(); //页卡视图集合 + private List giftJson = new ArrayList<>(); + private int contextLayoutGiftHeight = 0; + private String mStream, mLiveUid, wishGiftId, type; + private int currentPage = 0; + + @Override + public View createView(LayoutInflater layoutInflater, ViewGroup viewGroup) { + return layoutInflater.inflate(R.layout.fragment_live_gift, viewGroup, false); + } + + @Override + protected void initVariables(Bundle bundle) { + giftJson = JSON.parseArray(bundle.getString("giftJson"), LiveGiftBean.class); + contextLayoutGiftHeight = bundle.getInt("contextLayoutGiftHeight"); + mStream = bundle.getString("mStream"); + wishGiftId = bundle.getString("wishGiftId"); + mLiveUid = bundle.getString("mLiveUid"); + type = bundle.getString("type"); + pageCount = giftJson.size() / GIFT_COUNT; + if (giftJson.size() % GIFT_COUNT > 0) { + pageCount++; + } + + + } + + @Override + protected void initViews(Bundle savedInstanceState, View contentView) { + + fragmentViewpager = contentView.findViewById(R.id.context_layout); + mRadioGroup = contentView.findViewById(R.id.radio_group); + + + fragmentViewpager.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + contextLayoutGiftHeight = fragmentViewpager.getHeight(); + Log.e("giftJson", "height=" + contextLayoutGiftHeight); + int fromIndex = 0; + int size = giftJson.size(); + for (int i = 0; i < pageCount; i++) { + int endIndex = fromIndex + GIFT_COUNT; + if (endIndex > size) { + endIndex = size; + } + List liveGiftBeans = new ArrayList<>(); + for (int j = fromIndex; j < endIndex; j++) { + LiveGiftBean bean = giftJson.get(j); + bean.setPage(i); + liveGiftBeans.add(bean); + if (!TextUtils.isEmpty(wishGiftId) && TextUtils.equals(bean.getId() + "", wishGiftId)) { + currentPage = i; + Log.e("LiveGiftItemFragment", type); + } + } + fromIndex = endIndex; + ViewList.add(LiveGiftItemFragment.newInstance(JSON.toJSONString(liveGiftBeans), contextLayoutGiftHeight, mStream, mLiveUid, wishGiftId)); + } + giftFragmentPagerAdapter = new LiveGiftFragmentPagerAdapter(getChildFragmentManager(), getActivity(), ViewList); + fragmentViewpager.setAdapter(giftFragmentPagerAdapter); + + LayoutInflater inflater = LayoutInflater.from(getContext()); + for (int i = 0, size2 = ViewList.size(); i < size2; 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); + + } + fragmentViewpager.setCurrentItem(currentPage); + //移除监听 + fragmentViewpager.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } + }); + + fragmentViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + + } + + @Override + public void onPageSelected(int position) { + if (mRadioGroup != null && mRadioGroup.getChildAt(position) != null) { + ((RadioButton) mRadioGroup.getChildAt(position)).setChecked(true); + } + } + + @Override + public void onPageScrollStateChanged(int state) { + + } + }); + } + + @Override + protected void loadData() { + + } + + public static LiveGiftFragment newInstance(String giftJson, String type, + String mStream, String mLiveUid, String wishGiftId) { + LiveGiftFragment liveGiftFragment = new LiveGiftFragment(); + Bundle bundle = new Bundle(); + bundle.putString("giftJson", giftJson); + bundle.putString("type", type); + bundle.putString("mStream", mStream); + bundle.putString("mLiveUid", mLiveUid); + bundle.putString("wishGiftId", wishGiftId); + liveGiftFragment.setArguments(bundle); + return liveGiftFragment; + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveGiftItemFragment.java b/live/src/main/java/com/yunbao/live/views/LiveGiftItemFragment.java new file mode 100644 index 000000000..f2de5474c --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LiveGiftItemFragment.java @@ -0,0 +1,82 @@ +package com.yunbao.live.views; + +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.alibaba.fastjson.JSON; +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.fragment.BaseFragment; +import com.yunbao.common.utils.Bus; +import com.yunbao.live.R; +import com.yunbao.live.adapter.FrameGiftAdapter; +import com.yunbao.live.event.LiveGiftItemEvent; + +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.List; + +public class LiveGiftItemFragment extends BaseFragment { + private List giftJson = new ArrayList<>(); + private RecyclerView frameGiftList; + private int contextLayoutGiftHeight = 0; + private FrameGiftAdapter frameGiftAdapter; + private String mStream, mLiveUid, wishGiftId; + + @Override + public View createView(LayoutInflater layoutInflater, ViewGroup viewGroup) { + return layoutInflater.inflate(R.layout.fragment_live_gift_item, viewGroup, false); + } + + @Override + protected void initVariables(Bundle bundle) { + giftJson = JSON.parseArray(bundle.getString("giftJson"), LiveGiftBean.class); + contextLayoutGiftHeight = bundle.getInt("contextLayoutGiftHeight"); + mStream = bundle.getString("mStream"); + mLiveUid = bundle.getString("mLiveUid"); + wishGiftId = bundle.getString("wishGiftId"); + Log.e("giftJson", giftJson.toString()); + } + + @Override + protected void initViews(Bundle savedInstanceState, View contentView) { + + + frameGiftList = contentView.findViewById(R.id.frame_gift_list); + frameGiftList.setHasFixedSize(true); + frameGiftList.setLayoutManager(new GridLayoutManager(getActivity(), 4, GridLayoutManager.VERTICAL, false)); + frameGiftAdapter = new FrameGiftAdapter(contextLayoutGiftHeight, giftJson, mStream, mLiveUid, wishGiftId); + frameGiftList.setAdapter(frameGiftAdapter); + } + + @Override + protected void loadData() { + + } + + public static LiveGiftItemFragment newInstance(String giftJson, int contextLayoutGiftHeight, + String mStream, String mLiveUid, String wishGiftId) { + LiveGiftItemFragment liveGiftFragment = new LiveGiftItemFragment(); + Bundle bundle = new Bundle(); + bundle.putString("giftJson", giftJson); + bundle.putInt("contextLayoutGiftHeight", contextLayoutGiftHeight); + bundle.putString("mStream", mStream); + bundle.putString("mLiveUid", mLiveUid); + bundle.putString("wishGiftId", wishGiftId); + liveGiftFragment.setArguments(bundle); + return liveGiftFragment; + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLiveGiftItemEvent(LiveGiftItemEvent event) { + frameGiftAdapter.giftSelect(event.getLiveGiftModel()); + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveParcelFragment.java b/live/src/main/java/com/yunbao/live/views/LiveParcelFragment.java new file mode 100644 index 000000000..3fbbbf257 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LiveParcelFragment.java @@ -0,0 +1,162 @@ +package com.yunbao.live.views; + +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.widget.LinearLayout; +import android.widget.RadioButton; +import android.widget.RadioGroup; + +import androidx.fragment.app.Fragment; +import androidx.viewpager.widget.ViewPager; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.fragment.BaseFragment; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.utils.GiftCacheUtil; +import com.yunbao.live.R; +import com.yunbao.live.adapter.LiveGiftFragmentPagerAdapter; +import com.yunbao.live.http.LiveHttpUtil; + +import java.util.ArrayList; +import java.util.List; + +public class LiveParcelFragment extends BaseFragment { + private ViewPager fragmentViewpager; + private int pageCount; + private static final int GIFT_COUNT = 8;//每页8个礼物 + private RadioGroup mRadioGroup; + private LiveGiftFragmentPagerAdapter giftFragmentPagerAdapter; + private ArrayList ViewList = new ArrayList<>(); //页卡视图集合 + private List giftJson = new ArrayList<>(); + private int contextLayoutGiftHeight = 0; + private String mStream, mLiveUid; + private LinearLayout parcelDataList, parcelDataNo; + + @Override + public View createView(LayoutInflater layoutInflater, ViewGroup viewGroup) { + return layoutInflater.inflate(R.layout.fragment_live_parcel, viewGroup, false); + } + + @Override + protected void initVariables(Bundle bundle) { + mStream = bundle.getString("mStream"); + mLiveUid = bundle.getString("mLiveUid"); + } + + @Override + protected void initViews(Bundle savedInstanceState, View contentView) { + fragmentViewpager = contentView.findViewById(R.id.context_layout); + mRadioGroup = contentView.findViewById(R.id.radio_group); + parcelDataList = contentView.findViewById(R.id.parcel_data_list); + parcelDataNo = contentView.findViewById(R.id.parcel_data_no); + + fragmentViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + + } + + @Override + public void onPageSelected(int position) { + if (mRadioGroup != null && mRadioGroup.getChildAt(position) != null) { + ((RadioButton) mRadioGroup.getChildAt(position)).setChecked(true); + } + } + + @Override + public void onPageScrollStateChanged(int state) { + + } + }); + } + + @Override + protected void loadData() { + LiveHttpUtil.getWrapList(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + String giftJson = obj.getString("giftlist"); + List list = JSON.parseArray(giftJson, LiveGiftBean.class); + GiftCacheUtil.getInstance().addDownloadList(list); + if (!GiftCacheUtil.getInstance().isDownloading()) { + GiftCacheUtil.getInstance().downloadAllGift(); + } + if (list.size() == 0) { + parcelDataNo.setVisibility(View.VISIBLE); + parcelDataList.setVisibility(View.GONE); + } else { + parcelDataList.setVisibility(View.VISIBLE); + parcelDataNo.setVisibility(View.GONE); + pageCount = list.size() / GIFT_COUNT; + if (list.size() % GIFT_COUNT > 0) { + pageCount++; + } + + fragmentViewpager.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + contextLayoutGiftHeight = fragmentViewpager.getHeight(); + Log.e("giftJson", "height=" + contextLayoutGiftHeight); + int fromIndex = 0; + int size = list.size(); + for (int i = 0; i < pageCount; i++) { + int endIndex = fromIndex + GIFT_COUNT; + if (endIndex > size) { + endIndex = size; + } + List liveGiftBeans = new ArrayList<>(); + for (int j = fromIndex; j < endIndex; j++) { + LiveGiftBean bean = list.get(j); + bean.setPage(i); + liveGiftBeans.add(bean); + } + fromIndex = endIndex; + ViewList.add(LiveParcelItemFragment.newInstance(JSON.toJSONString(liveGiftBeans), contextLayoutGiftHeight, mStream, mLiveUid)); + } + giftFragmentPagerAdapter = new LiveGiftFragmentPagerAdapter(getChildFragmentManager(), getActivity(), ViewList); + fragmentViewpager.setAdapter(giftFragmentPagerAdapter); + + LayoutInflater inflater = LayoutInflater.from(getContext()); + for (int i = 0, size2 = ViewList.size(); i < size2; 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); + + } + //移除监听 + fragmentViewpager.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } + }); + } + } + } + + @Override + public void onFinish() { +// if (mLoading != null) { +// mLoading.setVisibility(View.INVISIBLE); +// } + } + }); + } + + public static LiveParcelFragment newInstance(String mStream, String mLiveUid) { + LiveParcelFragment liveParcelFragment = new LiveParcelFragment(); + Bundle bundle = new Bundle(); + bundle.putString("mStream", mStream); + bundle.putString("mLiveUid", mLiveUid); + liveParcelFragment.setArguments(bundle); + return liveParcelFragment; + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveParcelItemFragment.java b/live/src/main/java/com/yunbao/live/views/LiveParcelItemFragment.java new file mode 100644 index 000000000..7127f6753 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LiveParcelItemFragment.java @@ -0,0 +1,82 @@ +package com.yunbao.live.views; + +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.alibaba.fastjson.JSON; +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.fragment.BaseFragment; +import com.yunbao.live.R; +import com.yunbao.live.adapter.LiveParcelItemAdapter; +import com.yunbao.live.event.LiveGiftItemEvent; +import com.yunbao.live.event.LiveParcelItemRefreshEvent; + +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.List; + +public class LiveParcelItemFragment extends BaseFragment { + private List giftJson = new ArrayList<>(); + private RecyclerView frameGiftList; + private int contextLayoutGiftHeight = 0; + private LiveParcelItemAdapter frameGiftAdapter; + private String mStream, mLiveUid; + + @Override + public View createView(LayoutInflater layoutInflater, ViewGroup viewGroup) { + return layoutInflater.inflate(R.layout.fragment_live_gift_item, viewGroup, false); + } + + @Override + protected void initVariables(Bundle bundle) { + giftJson = JSON.parseArray(bundle.getString("giftJson"), LiveGiftBean.class); + contextLayoutGiftHeight = bundle.getInt("contextLayoutGiftHeight"); + mStream = bundle.getString("mStream"); + mLiveUid = bundle.getString("mLiveUid"); + Log.e("giftJson", giftJson.toString()); + } + + @Override + protected void initViews(Bundle savedInstanceState, View contentView) { + + frameGiftList = contentView.findViewById(R.id.frame_gift_list); + frameGiftList.setHasFixedSize(true); + frameGiftList.setLayoutManager(new GridLayoutManager(getActivity(), 4, GridLayoutManager.VERTICAL, false)); + frameGiftAdapter = new LiveParcelItemAdapter(contextLayoutGiftHeight, giftJson, mStream, mLiveUid); + frameGiftList.setAdapter(frameGiftAdapter); + } + + @Override + protected void loadData() { + + } + + public static LiveParcelItemFragment newInstance(String giftJson, int contextLayoutGiftHeight, String mStream, String mLiveUid) { + LiveParcelItemFragment liveGiftFragment = new LiveParcelItemFragment(); + Bundle bundle = new Bundle(); + bundle.putString("giftJson", giftJson); + bundle.putInt("contextLayoutGiftHeight", contextLayoutGiftHeight); + bundle.putString("mStream", mStream); + bundle.putString("mLiveUid", mLiveUid); + liveGiftFragment.setArguments(bundle); + return liveGiftFragment; + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLiveGiftItemEvent(LiveGiftItemEvent event) { + frameGiftAdapter.giftSelect(event.getLiveGiftModel()); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLiveParcelItemRefreshEvent(LiveParcelItemRefreshEvent event) { + frameGiftAdapter.refreshWrapListAfterSend(event.getLiveGiftModel()); + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveParcelItemViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveParcelItemViewHolder.java new file mode 100644 index 000000000..a94d35354 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/LiveParcelItemViewHolder.java @@ -0,0 +1,138 @@ +package com.yunbao.live.views; + +import android.content.Context; +import android.view.View; +import android.view.animation.AccelerateDecelerateInterpolator; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.view.animation.LinearInterpolator; +import android.view.animation.ScaleAnimation; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.lxj.xpopup.XPopup; +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.interfaces.CommonCallback; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.GiftCacheUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.views.weight.ViewClicksAntiShake; +import com.yunbao.live.R; +import com.yunbao.live.dialog.SendRendPacketPopup; +import com.yunbao.live.event.LiveGiftDialogEvent; + +import java.io.File; + +public class LiveParcelItemViewHolder extends RecyclerView.ViewHolder { + private ImageView giftIcon, cornerMark; + private Context mContext; + private TextView giftName, mPrice, giftNumber; + private RelativeLayout giftLayout; + private ScaleAnimation mAnimation; + private LinearLayout mLoadingLayout; + private ImageView mLoading; + + public LiveParcelItemViewHolder(@NonNull View itemView) { + super(itemView); + mContext = itemView.getContext(); + giftIcon = itemView.findViewById(R.id.gift_icon); + giftName = itemView.findViewById(R.id.gift_name); + mPrice = itemView.findViewById(R.id.price); + giftLayout = itemView.findViewById(R.id.gift_layout); + giftNumber = itemView.findViewById(R.id.gift_number); + cornerMark = itemView.findViewById(R.id.corner_mark); + mLoadingLayout = itemView.findViewById(R.id.gift_loading_layout); + mLoading = itemView.findViewById(R.id.gift_loading); + + mAnimation = new ScaleAnimation(0.9f, 1.1f, 0.9f, 1.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); + mAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); + mAnimation.setDuration(400); + mAnimation.setRepeatMode(Animation.REVERSE); + mAnimation.setRepeatCount(-1); + } + + public void showData(int contextLayoutGiftHeight, LiveGiftBean model) { + //设置高度 + itemView.post(new Runnable() { + @Override + public void run() { + GridLayoutManager.LayoutParams linearParams = (GridLayoutManager.LayoutParams) itemView.getLayoutParams(); + linearParams.height = contextLayoutGiftHeight / 2; + itemView.setLayoutParams(linearParams); + } + }); + giftLayout.setSelected(model.isChecked()); + if (model.isChecked()) { + giftIcon.startAnimation(mAnimation); + } + ImgLoader.display(mContext, model.getIcon(), giftIcon); + ImgLoader.display(mContext, model.getCornerMark(), cornerMark); + giftName.setText(model.getName()); + mPrice.setText(model.getEnd_time()); + giftNumber.setText(model.getGiftNum()); + + if (model.getSwf() != null && model.getSwf().isEmpty()) { + mLoadingLayout.setVisibility(View.GONE); + } else { + mLoadingLayout.setVisibility(GiftCacheUtil.checkGiftIsDownload(model.getId()) ? View.GONE : View.VISIBLE); + } + } + + public void giftSelect(LiveGiftBean model, int position, String mStream, String mLiveUid, FrameGiftClickListener frameGiftClickListener) { + ViewClicksAntiShake.clicksAntiShake(mLoadingLayout, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + mLoading.setImageResource(R.mipmap.icon_loading_gift); + Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.anim_loading_gift); + animation.setRepeatMode(Animation.RESTART); + animation.setRepeatCount(Animation.INFINITE); + animation.setInterpolator(new LinearInterpolator()); + mLoading.startAnimation(animation); + GiftCacheUtil.getInstance().pause(); + GiftCacheUtil.getInstance().downloadGiftForId(mContext, model, new CommonCallback() { + @Override + public void callback(File bean) { + if (bean == null) { + ToastUtil.show(mContext.getString(R.string.load_failure_2)); + mLoading.setImageResource(R.mipmap.icon_download_gift); + animation.setRepeatCount(0); + animation.setDuration(0); + animation.cancel(); + mLoading.setAnimation(animation); + } else { + mLoadingLayout.setVisibility(View.GONE); + } + GiftCacheUtil.getInstance().restart(); + } + }); + } + }); + ViewClicksAntiShake.clicksAntiShake(giftLayout, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + if (model.getType() == 9999999) { + Bus.get().post(new LiveGiftDialogEvent()); + new XPopup.Builder(mContext) + .asCustom(new SendRendPacketPopup(mContext, mLiveUid)) + .show(); + } else { + if (frameGiftClickListener != null) { + frameGiftClickListener.onCallBack(position, model); + } + } + + } + }); + } + + public interface FrameGiftClickListener { + void onCallBack(int position, LiveGiftBean model); + } +} 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 d191a0f3b..00f2fd4df 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -150,7 +150,6 @@ import com.yunbao.live.custom.TopGradual; import com.yunbao.live.dialog.LiveFaceUnityDialogFragment; import com.yunbao.live.dialog.LiveFansMedalDialogFragment; import com.yunbao.live.dialog.LiveGameDialogFragment; -import com.yunbao.live.dialog.LiveGiftDialogFragment; import com.yunbao.live.dialog.LiveHDDialogFragment; import com.yunbao.live.dialog.LiveUserAnchorMailBoxWebInfoPopDialog; import com.yunbao.live.dialog.LiveUserDialogFragment; @@ -5069,23 +5068,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void onSuccess(LiveAnchorCallMeModel data) { - if (data.getIsGet() == 1) { - new LiveUserAnchorMailBoxWebInfoPopDialog(mContext, mAnchorName, data.getLink()) - .setOnDismissListener(dialog -> loading.dismiss()) - .showDialog(); - return; - } - LiveGiftDialogFragment fragment = new LiveGiftDialogFragment(); - fragment.setOnDismissListener(dialog -> checkNewLetter() - ); - fragment.setOnShowListener(dialog -> mHandler.postDelayed(loading::dismiss, 500)); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.LIVE_STREAM, mStream); - bundle.putString(Constants.LIVE_WISH_GIFTID, data.getGiftId() + ""); - bundle.putBoolean("isContactGift", true); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + loading.dismiss(); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) + .setmLiveUid(mLiveUid) + .setmStream(mStream) + .setmWishGiftId(data.getGiftId() + "") + .setIsContactGift(true)); } @Override @@ -5147,23 +5136,15 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void onSuccess(LiveAnchorCallMeModel data) { - if (data.getIsGet() == 1) { - new LiveUserAnchorMailBoxWebInfoPopDialog(mContext, mAnchorName, data.getLink()) - .setOnDismissListener(dialog -> loading.dismiss()) - .showDialog(); - return; - } - LiveGiftDialogFragment fragment = new LiveGiftDialogFragment(); - fragment.setOnDismissListener(dialog -> checkNewLetter() - ); - fragment.setOnShowListener(dialog -> mHandler.postDelayed(loading::dismiss, 500)); - Bundle bundle = new Bundle(); - bundle.putString(Constants.LIVE_UID, mLiveUid); - bundle.putString(Constants.LIVE_STREAM, mStream); - bundle.putString(Constants.LIVE_WISH_GIFTID, data.getGiftId() + ""); - bundle.putBoolean("isContactGift", true); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGiftDialogFragment"); + loading.dismiss(); + + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP) + .setmLiveUid(mLiveUid) + .setmStream(mStream) + .setmWishGiftId(data.getGiftId() + "") + .setIsContactGift(true)); + } @Override diff --git a/live/src/main/res/drawable/background_gift_select.xml b/live/src/main/res/drawable/background_gift_select.xml new file mode 100644 index 000000000..8e8881c7c --- /dev/null +++ b/live/src/main/res/drawable/background_gift_select.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/fragment_live_gift.xml b/live/src/main/res/layout/fragment_live_gift.xml new file mode 100644 index 000000000..4cbba9e43 --- /dev/null +++ b/live/src/main/res/layout/fragment_live_gift.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/fragment_live_gift_item.xml b/live/src/main/res/layout/fragment_live_gift_item.xml new file mode 100644 index 000000000..d2fae8429 --- /dev/null +++ b/live/src/main/res/layout/fragment_live_gift_item.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/fragment_live_parcel.xml b/live/src/main/res/layout/fragment_live_parcel.xml new file mode 100644 index 000000000..915d8ecfa --- /dev/null +++ b/live/src/main/res/layout/fragment_live_parcel.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_frame_gift.xml b/live/src/main/res/layout/item_frame_gift.xml new file mode 100644 index 000000000..b43e18e44 --- /dev/null +++ b/live/src/main/res/layout/item_frame_gift.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_gift_top_new.xml b/live/src/main/res/layout/item_gift_top_new.xml new file mode 100644 index 000000000..68309d5a7 --- /dev/null +++ b/live/src/main/res/layout/item_gift_top_new.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_live_parcel.xml b/live/src/main/res/layout/item_live_parcel.xml new file mode 100644 index 000000000..c0ff90185 --- /dev/null +++ b/live/src/main/res/layout/item_live_parcel.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/mipmap-xxxhdpi/live_icon_leftt_sliding.png b/live/src/main/res/mipmap-xxxhdpi/live_icon_leftt_sliding.png index 1789eab28..ca957ec23 100644 Binary files a/live/src/main/res/mipmap-xxxhdpi/live_icon_leftt_sliding.png and b/live/src/main/res/mipmap-xxxhdpi/live_icon_leftt_sliding.png differ