礼物盲盒基本逻辑

This commit is contained in:
18401019693
2023-05-24 14:50:39 +08:00
parent 3e72b4a9eb
commit 1f7aef91a8
17 changed files with 491 additions and 8 deletions

View File

@@ -11,7 +11,10 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
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.LayoutInflater;
@@ -19,9 +22,11 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
@@ -37,12 +42,14 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants;
import com.yunbao.common.bean.BlindBoxInfoModel;
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.http.HttpCallback;
import com.yunbao.common.http.HttpClient;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.AppManager;
@@ -120,6 +127,8 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
private RecyclerView items;
private LinearLayout mVipGold;
private FrameLayout blindBox, frameBlindTop;
private ProgressBar progressBlind, progressBlind1, progressBlind2;
private GiftTopAdapter giftTopAdapter;
public int type = 0;
private static String type_name = "熱門";
@@ -127,7 +136,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
private ImageView mVipGoldIcon;
private TextView mVipGoldTitle;
private TextView mVipGoldDesc;
private TextView mGiftPackage;
private TextView mGiftPackage, blindNumber, textBlindProgress, textBlindGiftName;
private boolean isPk;
private int isContactGift = 0;
DialogInterface.OnDismissListener onDismissListener;
@@ -152,6 +161,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
@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 = DpUtil.dp2px(355);
@@ -191,6 +201,11 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
mTvGoCharge = (TextView) mRootView.findViewById(R.id.go_charge);
items = (RecyclerView) mRootView.findViewById(R.id.items);
mLoading = mRootView.findViewById(R.id.loading);
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);
mArrow = mRootView.findViewById(R.id.arrow);
mBtnSend = mRootView.findViewById(R.id.btn_send);
mBtnSendGroup = mRootView.findViewById(R.id.btn_send_group);
@@ -285,6 +300,9 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
mVipGoldDesc = mRootView.findViewById(R.id.vipGoldDesc);
mVipGold.setOnClickListener(this);
mGiftPackage = mRootView.findViewById(R.id.btn_gift_package);
blindNumber = mRootView.findViewById(R.id.blind_number);
textBlindProgress = mRootView.findViewById(R.id.text_blind_progress);
textBlindGiftName = mRootView.findViewById(R.id.text_blind_gift_name);
mGiftPackage.setOnClickListener(this);
mRootView.findViewById(R.id.live_gift_download_all).setOnClickListener(this);
mHandler = new Handler() {
@@ -319,6 +337,24 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
if (isPk) {
mVipGold.setVisibility(View.GONE);
}
getBlindBoxInfo();
}
public List<BlindBoxInfoModel> blindBoxInfoModels = new ArrayList<>();
private void getBlindBoxInfo() {
LiveNetManager.get(mContext)
.getBlindBoxInfo(new com.yunbao.common.http.base.HttpCallback<List<BlindBoxInfoModel>>() {
@Override
public void onSuccess(List<BlindBoxInfoModel> data) {
blindBoxInfoModels = data;
}
@Override
public void onError(String error) {
ToastUtil.show(error);
}
});
}
/**
@@ -666,6 +702,122 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
mArrow.setVisibility(View.VISIBLE);
mBtnSend.setBackground(mDrawable1);
}
if (bean.getType() == 5) {
showBlindProgress(bean.getBlind_box_type());
} else {
mVipGold.setVisibility(View.VISIBLE);
blindBox.setVisibility(View.GONE);
WindowManager.LayoutParams params = getDialog().getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = DpUtil.dp2px(355);
params.gravity = Gravity.BOTTOM;
getDialog().getWindow().setAttributes(params);
}
}
/**
* 展示当前盲盒礼物进度
*
* @param blindBoxType
*/
private StringBuffer blindGiftNamesBuffer = null;
private void showBlindProgress(int 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;
mVipGold.setVisibility(View.GONE);
blindBox.setVisibility(View.VISIBLE);
WindowManager.LayoutParams params = getDialog().getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = DpUtil.dp2px(433);
params.gravity = Gravity.BOTTOM;
getDialog().getWindow().setAttributes(params);
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(R.mipmap.bg_kirin);
progressBlind.setMax(Integer.parseInt(model.getThresholdValue()));
progressBlind.setProgress(Integer.parseInt(model.getDressThresholdValue()));
textBlindProgress.setTextColor(Color.parseColor("#047771"));
break;
case 2:
boxBlindName = mContext.getString(R.string.collection_blind_box);
progressBlind.setVisibility(View.GONE);
progressBlind1.setVisibility(View.VISIBLE);
progressBlind2.setVisibility(View.GONE);
frameBlindTop.setBackgroundResource(R.mipmap.bg_phoenix);
progressBlind1.setMax(Integer.parseInt(model.getThresholdValue()));
progressBlind1.setProgress(Integer.parseInt(model.getDressThresholdValue()));
textBlindProgress.setTextColor(Color.parseColor("#6D2E0F"));
break;
default:
boxBlindName = mContext.getString(R.string.pd_blind_box);
progressBlind.setVisibility(View.GONE);
progressBlind1.setVisibility(View.GONE);
progressBlind2.setVisibility(View.VISIBLE);
frameBlindTop.setBackgroundResource(R.mipmap.bg_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(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);
} 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), boxBlindName, 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());
}
//盲盒礼物文字跑马灯
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(R.string.random_availability), blindGiftNamesBuffer.toString()));
}
/**

View File

@@ -23,11 +23,11 @@
android:visibility="gone">
<ImageView
android:visibility="gone"
android:layout_width="19dp"
android:layout_height="19dp"
android:layout_marginEnd="7dp"
android:src="@mipmap/icon_small_download" />
android:src="@mipmap/icon_small_download"
android:visibility="gone" />
<TextView
android:layout_width="wrap_content"
@@ -84,6 +84,18 @@
</LinearLayout>
<FrameLayout
android:id="@+id/blind_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:visibility="gone">
<include
layout="@layout/view_blind_box" />
</FrameLayout>
</RelativeLayout>
<RelativeLayout

View File

@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="159dp"
android:layout_height="110dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<!--凤凰,龙,麒麟-->
<FrameLayout
android:id="@+id/frame_blind_top"
android:layout_width="match_parent"
android:layout_height="86.5dp"
android:background="@mipmap/bg_phoenix">
<com.yunbao.common.views.weight.ClipPathCircleImage
android:layout_width="29dp"
android:layout_height="29dp"
android:layout_marginStart="14dp"
android:layout_marginTop="51dp"
android:src="@mipmap/icon_avatar_test" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="51dp"
android:layout_marginTop="59dp"
android:orientation="vertical">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progress_blind3"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="74dp"
android:layout_height="6dp"
android:layout_gravity="center"
android:max="100"
android:progress="30"
android:progressDrawable="@drawable/bg_blind_progres"
android:visibility="gone" />
<ProgressBar
android:id="@+id/progress_blind1"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="74dp"
android:layout_height="6dp"
android:layout_gravity="center"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/bg_blind_progress"
android:visibility="visible" />
<ProgressBar
android:id="@+id/progress_blind2"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="74dp"
android:layout_height="6dp"
android:layout_gravity="center"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/bg_blind_progress1"
android:visibility="gone" />
<TextView
android:id="@+id/text_blind_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="6sp" />
</FrameLayout>
<TextView
android:id="@+id/blind_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textColor="@color/white"
android:textSize="6sp" />
</LinearLayout>
<ImageView
android:layout_width="13dp"
android:layout_height="13dp"
android:layout_gravity="end"
android:layout_marginTop="47dp"
android:layout_marginEnd="19dp"
android:src="@mipmap/icon_what" />
</FrameLayout>
<FrameLayout
android:layout_width="139dp"
android:layout_height="match_parent"
android:background="@mipmap/bg_blind_bottom">
<com.yunbao.common.views.weight.MarqueeTextView
android:id="@+id/text_blind_gift_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="7dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:textSize="7sp"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="@color/white" />
</FrameLayout>
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB