diff --git a/common/src/main/res/layout/dialog_live_gift_popup2.xml b/common/src/main/res/layout/dialog_live_gift_popup2.xml index dc87fa3a1..aa156192a 100644 --- a/common/src/main/res/layout/dialog_live_gift_popup2.xml +++ b/common/src/main/res/layout/dialog_live_gift_popup2.xml @@ -161,12 +161,14 @@ diff --git a/common/src/main/res/values/colors.xml b/common/src/main/res/values/colors.xml index 48c57b325..77ca97d92 100644 --- a/common/src/main/res/values/colors.xml +++ b/common/src/main/res/values/colors.xml @@ -11,6 +11,7 @@ #00000000 #323232 #fff + #feea36 #99FFFFFF #85ffffff #969696 diff --git a/live/src/main/java/com/yunbao/live/adapter/FrameGiftNewAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FrameGiftNewAdapter.java new file mode 100644 index 000000000..ccdf7d50b --- /dev/null +++ b/live/src/main/java/com/yunbao/live/adapter/FrameGiftNewAdapter.java @@ -0,0 +1,249 @@ +package com.yunbao.live.adapter; + +import android.content.Context; +import android.graphics.Color; +import android.text.TextUtils; +import android.util.TypedValue; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +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.TextView; + +import androidx.annotation.IdRes; +import androidx.annotation.NonNull; +import androidx.constraintlayout.widget.Group; +import androidx.recyclerview.widget.RecyclerView; + +import com.lxj.xpopup.XPopup; +import com.makeramen.roundedimageview.RoundedImageView; +import com.yunbao.common.bean.LiveGiftBean; +import com.yunbao.common.event.LiveGiftDialogEvent; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.interfaces.CommonCallback; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.GiftCacheUtil; +import com.yunbao.common.utils.MobclickAgent; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.views.weight.MarqueeTextView; +import com.yunbao.common.views.weight.ViewClicksAntiShake; +import com.yunbao.live.R; +import com.yunbao.live.dialog.SendRendPacketPopup; +import com.yunbao.live.event.LiveGiftItemEvent; +import com.yunbao.live.views.FrameGiftViewHolder; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class FrameGiftNewAdapter extends RecyclerView.Adapter { + + private List giftJson = new ArrayList<>(); + private String mStream, mLiveUid, wishGiftId; + + public FrameGiftNewAdapter(List giftJson, String mStream, String mLiveUid, String wishGiftId) { + ; + 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_new, parent, false); + return new FrameGiftViewHolder(herdView); + } + + + 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 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))); + wishGiftId = null; + } + + GiftViewHolder frameGiftViewHolder = (GiftViewHolder) holder; + frameGiftViewHolder.showData(giftJson.get(position)); + frameGiftViewHolder.giftSelect(giftJson.get(position), position, mStream, mLiveUid, new GiftViewHolder.FrameGiftClickListener() { + @Override + public void onCallBack(int position, LiveGiftBean model) { + Bus.get().post(new LiveGiftItemEvent().setLiveGiftModel(model)); + wishGiftId = null; + giftSelect(model); + } + }); + } + + + @Override + public int getItemCount() { + return giftJson.size(); + } + + + public static class GiftViewHolder extends RecyclerView.ViewHolder { + // 声明所有需要初始化的视图组件 + private View isSelectView; + private ImageView giftIconImg; + private TextView giftNameTv; + private TextView priceTv; + private ImageView payIco; + private ImageView giftNamingBg; + private RoundedImageView avatar; + private MarqueeTextView namingName; + private Group namingGroup; + private ImageView cornerMark; + private ScaleAnimation mAnimation; + private View rootView; + + + public GiftViewHolder(@NonNull View itemView) { + super(itemView); + rootView = itemView; + // 初始化所有视图组件 + this.isSelectView = findViewById(R.id.isSelectView); + this.giftIconImg = findViewById(R.id.giftIconImg); + this.giftNameTv = findViewById(R.id.giftNameTv); + this.priceTv = findViewById(R.id.priceTv); + this.payIco = findViewById(R.id.pay_ico); + this.giftNamingBg = findViewById(R.id.giftNamingBg); + this.avatar = findViewById(R.id.avatar); + this.namingName = findViewById(R.id.naming_name); + this.namingGroup = findViewById(R.id.namingGroup); + this.cornerMark = findViewById(R.id.corner_mark); + + 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); + } + + + private Context getContext() { + return rootView.getContext(); + } + + private final T findViewById(@IdRes int id) { + return rootView.findViewById(id); + } + + public void showData(LiveGiftBean model) { + isSelectView.setVisibility(model.isChecked() ? View.VISIBLE : View.INVISIBLE); + if (model.isChecked()) { + giftIconImg.startAnimation(mAnimation); + } + ImgLoader.display(getContext(), model.getIcon(), giftIconImg); + ImgLoader.display(getContext(), model.getCornerMark(), cornerMark); + giftNameTv.setText(model.getName()); + if (model.getNaming_user_gift_hall_rank_hide() == 1 && !model.getNamingUid().equals(IMLoginManager.get(getContext()).getUserInfo().getId() + "")) { + avatar.setImageResource(com.yunbao.common.R.mipmap.hide); + namingName.setText(WordUtil.getNewString(com.yunbao.common.R.string.mystery_man)); + } else { + ImgLoader.display(getContext(), model.getNamingUserAvatar(), avatar); + namingName.setText(model.getNamingUserName()); + } + //特殊礼物红包 + if (model.getType() == 9999999) { + payIco.setVisibility(View.GONE); + priceTv.setText(getContext().getString(R.string.build_up_popularity)); + priceTv.setTextColor(Color.parseColor("#db8c4a")); + priceTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 8); + + } else { + priceTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11); + priceTv.setTextColor(Color.parseColor("#c8c8c8")); + payIco.setVisibility(View.VISIBLE); + //普通礼物 + if (model.getSendType() != null && model.getSendType().equals("1")) { + payIco.setImageResource(R.mipmap.gold_coin); + } else { + payIco.setImageResource(R.mipmap.diamond); + } + priceTv.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); + } + if (model.isChecked() && !StringUtil.isEmpty(model.getNamingUserName())) { + namingLayout.setVisibility(View.VISIBLE); + } else { + namingLayout.setVisibility(View.GONE); + } + + } + + 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(getContext(), 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(getContext(), model, new CommonCallback() { + @Override + public void callback(File bean) { + if (bean == null) { + ToastUtil.show(getContext().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) { + MobclickAgent.onEvent(getContext(), "gif_list_redpk", "用户点开礼物列表红包"); + Bus.get().post(new LiveGiftDialogEvent()); + new XPopup.Builder(getContext()) + .asCustom(new SendRendPacketPopup(getContext(), 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/adapter/GiftTitleAdapter.java b/live/src/main/java/com/yunbao/live/adapter/GiftTitleAdapter.java index a70ea3042..f45ffb195 100644 --- a/live/src/main/java/com/yunbao/live/adapter/GiftTitleAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/GiftTitleAdapter.java @@ -1,5 +1,6 @@ package com.yunbao.live.adapter; +import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -11,6 +12,8 @@ import com.yunbao.live.R; import com.yunbao.live.bean.GiftTopBean; import com.yunbao.live.views.GiftTitleViewHolder; +import net.lucode.hackware.magicindicator.buildins.UIUtil; + import java.util.ArrayList; import java.util.List; @@ -22,10 +25,23 @@ public class GiftTitleAdapter extends RecyclerView.Adapter { List name = new ArrayList<>(); private int index = 0; + + private int itemWidth = -1; + + private int getItemWidth(Context context) { + if (itemWidth < 0) { + itemWidth = (UIUtil.getScreenWidth(context) - UIUtil.dip2px(context, 60)) / 5; + } + return itemWidth; + } + @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); + ViewGroup.LayoutParams layoutParams = herdView.getLayoutParams(); + layoutParams.width=getItemWidth(parent.getContext()); + herdView.setLayoutParams(layoutParams); return new GiftTitleViewHolder(herdView); } @@ -39,7 +55,7 @@ public class GiftTitleAdapter extends RecyclerView.Adapter { notifyDataSetChanged(); } }); - itemViewHolder.selectData(index == position,name.get(position).getName()); + itemViewHolder.selectData(index == position, name.get(position).getName()); } @Override @@ -59,7 +75,7 @@ public class GiftTitleAdapter extends RecyclerView.Adapter { } public void setTitleIndex(int i) { - index=i; + index = i; notifyDataSetChanged(); } } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup2.java b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup2.java index fc76bae61..1ae26a7e1 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup2.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup2.java @@ -27,6 +27,7 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -286,7 +287,6 @@ public class LiveGiftPopup2 extends AbsDialogFragment { giftTitleAdapter = new GiftTitleAdapter(); giftTitleRecyclerView.setAdapter(giftTitleAdapter); giftWrapTv.setAlpha(0.5f); - giftWrapTv.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL); liveGiftSend.setEnabled(false); giftSendGroup.setVisibility(View.INVISIBLE); giftDescription.setVisibility(View.GONE); @@ -326,6 +326,7 @@ public class LiveGiftPopup2 extends AbsDialogFragment { giftTitleAdapter.uncheck(); giftWrapTv.setAlpha(1.0f); giftWrapTv.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); + giftWrapTv.setTextColor(ContextCompat.getColor(mContext, com.yunbao.live.R.color.feea36)); //TODO 切换到包裹取消更爱 // transaction = getTransaction(); // contentFragment = LiveParcelFragment.newInstance(mStream, mLiveUid); @@ -1096,7 +1097,8 @@ public class LiveGiftPopup2 extends AbsDialogFragment { public void onGiftTitleEvent(GiftTitleEvent event) { giftWrapTv.setAlpha(0.5f); - giftWrapTv.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL); + giftWrapTv.setTextColor(ContextCompat.getColor(mContext, com.yunbao.live.R.color.white)); + liveGiftSend.setEnabled(false); giftSendGroup.setVisibility(View.INVISIBLE); JSONObject obj2 = liveGiftList.getJSONObject(event.getmPosition()); diff --git a/live/src/main/java/com/yunbao/live/views/GiftTitleViewHolder.java b/live/src/main/java/com/yunbao/live/views/GiftTitleViewHolder.java index 854fe4b61..6489cf87f 100644 --- a/live/src/main/java/com/yunbao/live/views/GiftTitleViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/GiftTitleViewHolder.java @@ -4,6 +4,7 @@ import android.graphics.Typeface; import android.view.View; import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.utils.MobclickAgent; @@ -63,9 +64,11 @@ public class GiftTitleViewHolder extends RecyclerView.ViewHolder { break; } name.setAlpha(1.0f); - name.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); + //FEEA36 + name.setTextColor(ContextCompat.getColor(itemView.getContext(),R.color.feea36)); } else { name.setAlpha(0.5f); + name.setTextColor(ContextCompat.getColor(itemView.getContext(),R.color.white)); name.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL); } } diff --git a/live/src/main/res/drawable/background_gift_select2.xml b/live/src/main/res/drawable/background_gift_select2.xml new file mode 100644 index 000000000..9622340b3 --- /dev/null +++ b/live/src/main/res/drawable/background_gift_select2.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/live/src/main/res/layout/item_frame_gift.xml b/live/src/main/res/layout/item_frame_gift.xml index c8dc84f19..5e3758c88 100644 --- a/live/src/main/res/layout/item_frame_gift.xml +++ b/live/src/main/res/layout/item_frame_gift.xml @@ -114,7 +114,8 @@ android:layout_height="match_parent" android:background="#C0000000" android:gravity="center" - android:visibility="gone"> + android:visibility="gone" + tools:visibility="visible"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 index 68309d5a7..02b628504 100644 --- a/live/src/main/res/layout/item_gift_top_new.xml +++ b/live/src/main/res/layout/item_gift_top_new.xml @@ -1,7 +1,9 @@ - + android:layout_height="match_parent" + xmlns:tools="http://schemas.android.com/tools" + tools:background="@color/black1"> - \ No newline at end of file + \ No newline at end of file