3级以上礼物展示列表动画实现方式修改

This commit is contained in:
huangjian
2021-01-06 14:30:13 +08:00
parent 738a5a4f91
commit fe58e3eedd
6 changed files with 137 additions and 143 deletions

View File

@@ -10,21 +10,20 @@ import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.netease.nim.uikit.StatusBarUtil;
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
import com.yizhuan.erban.R;
import com.yizhuan.erban.base.BaseBindingActivity;
import com.yizhuan.erban.databinding.ActivityTreasureBoxBinding;
import com.yizhuan.erban.treasure_box.adapter.BoxPrizeHintAdapter;
import com.yizhuan.erban.treasure_box.widget.dialog.BoxMoreDialog;
import com.yizhuan.erban.treasure_box.widget.dialog.BuyKeyDialog;
import com.yizhuan.erban.ui.utils.ImageLoadUtils;
import com.yizhuan.erban.ui.webview.DialogWebViewActivity;
import com.yizhuan.treasure_box.bean.PrizeInfo;
@@ -52,14 +51,13 @@ public class TreasureBoxActivity extends BaseBindingActivity<ActivityTreasureBox
private int price = 20;
private volatile int keyNum;
private ArrayList<PrizeInfo> cacheList = new ArrayList<>();
private ArrayList<PrizeInfo> hintPrizeCacheList = new ArrayList<>();
private ObjectAnimator translationXAnimator;
private ObjectAnimator translationYAnimator;
private int boxType = IBoxModel.BOX_TYPE_NORMAL;
private int height;
private BoxPrizeHintAdapter hintAdapter;
public static void start(Context context) {
Intent starter = new Intent(context, TreasureBoxActivity.class);
context.startActivity(starter);
@@ -103,14 +101,10 @@ public class TreasureBoxActivity extends BaseBindingActivity<ActivityTreasureBox
mBinding.tvContinuousNum.setText("消耗" + num);
}
});
hintAdapter = new BoxPrizeHintAdapter();
hintAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_BOTTOM);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setStackFromEnd(true);
mBinding.rvPrizeHint.setLayoutManager(layoutManager);
hintAdapter.bindToRecyclerView(mBinding.rvPrizeHint);
loadKeyInfo();
looperPrize();
looperHintPrize();
}
@SuppressLint("CheckResult")
@@ -155,10 +149,6 @@ public class TreasureBoxActivity extends BaseBindingActivity<ActivityTreasureBox
}
}
private void showBuyDialog() {
new BuyKeyDialog(this, price).show();
}
/**
* 检查钥匙(锤子)数量
*
@@ -192,17 +182,21 @@ public class TreasureBoxActivity extends BaseBindingActivity<ActivityTreasureBox
mBinding.ivOpen.setEnabled(true);
SingleToastUtil.showToast(throwable.getMessage());
})
.subscribe(openBoxResult -> {
.toObservable()
.flatMap(openBoxResult -> {
mBinding.ivOpen.setEnabled(true);
changeKeyNum(openBoxResult.getRemainKeyNum());
cacheList.addAll(openBoxResult.getPrizeItemList());
});
return Observable.fromIterable(openBoxResult.getPrizeItemList());
})
.filter(prizeInfo -> prizeInfo.getPrizeLevel() > 2)
.subscribe(prizeInfo -> hintPrizeCacheList.add(prizeInfo));
}
@SuppressLint("CheckResult")
private void looperPrize() {
Observable.interval(0, 200, TimeUnit.MILLISECONDS)
Observable.interval(0, 100, TimeUnit.MILLISECONDS)
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.filter(aLong -> cacheList.size() > 0)
@@ -217,14 +211,56 @@ public class TreasureBoxActivity extends BaseBindingActivity<ActivityTreasureBox
mBinding.svgaGiftBg.startAnimation();
ImageLoadUtils.loadImage(context, url, mBinding.ivGiftAnim);
}
if (prizeInfo.getPrizeLevel() > 2) {
hintAdapter.addData(prizeInfo);
}
}
, e -> looperPrize());//出错了继续looper......
}
private final Runnable removeRunnable = () -> mBinding.llPrizeHint.removeAllViews();
@SuppressLint("CheckResult")
private void looperHintPrize() {
Observable.interval(0, 500, TimeUnit.MILLISECONDS)
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.filter(aLong -> hintPrizeCacheList.size() > 0)
.subscribe(aLong -> addPrizeHintView(hintPrizeCacheList.remove(0))
, e -> looperHintPrize());//出错了继续looper......
}
private void addPrizeHintView(PrizeInfo prizeInfo) {
mBinding.llPrizeHint.removeCallbacks(removeRunnable);
mBinding.llPrizeHint.postDelayed(removeRunnable, 3000);
LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.item_box_prize_hint, null);
ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ScreenUtil.dip2px(24));
layoutParams.setMargins(0, ScreenUtil.dip2px(5), 0, ScreenUtil.dip2px(5));
linearLayout.setLayoutParams(layoutParams);
switch (prizeInfo.getPrizeLevel()) {
case 3:
default:
linearLayout.setBackgroundResource(R.drawable.bg_box_prize_hint_v3);
break;
case 4:
linearLayout.setBackgroundResource(R.drawable.bg_box_prize_hint_v4);
break;
case 5:
linearLayout.setBackgroundResource(R.drawable.bg_box_prize_hint_v5);
break;
}
mBinding.llPrizeHint.addView(linearLayout);
if (mBinding.llPrizeHint.getChildCount() > 6) {
mBinding.llPrizeHint.removeViewAt(0);
}
for (int i = 0; i < mBinding.llPrizeHint.getChildCount(); i++) {
ObjectAnimator.ofFloat(mBinding.llPrizeHint.getChildAt(i), "translationY", ScreenUtil.dip2px(24), 0)
.setDuration(300)
.start();
}
((TextView) linearLayout.findViewById(R.id.tv_prize_name)).setText(prizeInfo.getPrizeName());
((TextView) linearLayout.findViewById(R.id.tv_prize_num)).setText("x" + prizeInfo.getPrizeNum());
}
/**
* 更新钥匙(锤子)数量

View File

@@ -10,19 +10,19 @@ import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.netease.nim.uikit.StatusBarUtil;
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
import com.yizhuan.erban.R;
import com.yizhuan.erban.base.BaseBindingActivity;
import com.yizhuan.erban.databinding.ActivityTreasureBoxHonourBinding;
import com.yizhuan.erban.treasure_box.adapter.BoxPrizeHintAdapter;
import com.yizhuan.erban.treasure_box.widget.dialog.BoxMoreDialog;
import com.yizhuan.erban.treasure_box.widget.dialog.BuyKeyDialog;
import com.yizhuan.erban.ui.utils.ImageLoadUtils;
@@ -52,12 +52,12 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
private int price = 20;
private volatile int keyNum;
private ArrayList<PrizeInfo> cacheList = new ArrayList<>();
private ArrayList<PrizeInfo> hintPrizeCacheList = new ArrayList<>();
private ObjectAnimator translationXAnimator;
private ObjectAnimator translationYAnimator;
private int boxType = IBoxModel.BOX_TYPE_HONOUR;
private int height;
private BoxPrizeHintAdapter hintAdapter;
public static void start(Context context) {
Intent starter = new Intent(context, TreasureBoxHonourActivity.class);
@@ -103,14 +103,9 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
mBinding.tvContinuousNum.setText("消耗" + num * 10);
}
});
hintAdapter = new BoxPrizeHintAdapter();
hintAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_BOTTOM);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setStackFromEnd(true);
mBinding.rvPrizeHint.setLayoutManager(layoutManager);
hintAdapter.bindToRecyclerView(mBinding.rvPrizeHint);
loadKeyInfo();
looperPrize();
looperHintPrize();
}
@@ -155,10 +150,6 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
}
}
private void showBuyDialog() {
new BuyKeyDialog(this, price, IBoxModel.BOX_TYPE_HONOUR).show();
}
/**
* 检查钥匙(锤子)数量
*
@@ -194,16 +185,20 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
mBinding.ivOpen.setEnabled(true);
toast(throwable.getMessage());
})
.subscribe(openBoxResult -> {
.toObservable()
.flatMap(openBoxResult -> {
mBinding.ivOpen.setEnabled(true);
changeKeyNum(openBoxResult.getRemainKeyNum());
cacheList.addAll(openBoxResult.getPrizeItemList());
});
return Observable.fromIterable(openBoxResult.getPrizeItemList());
})
.filter(prizeInfo -> prizeInfo.getPrizeLevel() > 2)
.subscribe(prizeInfo -> hintPrizeCacheList.add(prizeInfo));
}
@SuppressLint("CheckResult")
private void looperPrize() {
Observable.interval(0, 200, TimeUnit.MILLISECONDS)
Observable.interval(0, 100, TimeUnit.MILLISECONDS)
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.filter(aLong -> cacheList.size() > 0)
@@ -218,14 +213,54 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
mBinding.svgaGiftBg.startAnimation();
ImageLoadUtils.loadImage(context, url, mBinding.ivGiftAnim);
}
if (prizeInfo.getPrizeLevel() > 2) {
hintAdapter.addData(prizeInfo);
}
}
, e -> looperPrize());//出错了继续looper......
}
private final Runnable removeRunnable = () -> mBinding.llPrizeHint.removeAllViews();
@SuppressLint("CheckResult")
private void looperHintPrize() {
Observable.interval(0, 500, TimeUnit.MILLISECONDS)
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.filter(aLong -> hintPrizeCacheList.size() > 0)
.subscribe(aLong -> addPrizeHintView(hintPrizeCacheList.remove(0))
, e -> looperHintPrize());//出错了继续looper......
}
private void addPrizeHintView(PrizeInfo prizeInfo) {
mBinding.llPrizeHint.removeCallbacks(removeRunnable);
mBinding.llPrizeHint.postDelayed(removeRunnable, 3000);
LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.item_box_prize_hint, null);
ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ScreenUtil.dip2px(24));
layoutParams.setMargins(0, ScreenUtil.dip2px(5), 0, ScreenUtil.dip2px(5));
linearLayout.setLayoutParams(layoutParams);
switch (prizeInfo.getPrizeLevel()) {
case 3:
default:
linearLayout.setBackgroundResource(R.drawable.bg_box_prize_hint_v3);
break;
case 4:
linearLayout.setBackgroundResource(R.drawable.bg_box_prize_hint_v4);
break;
case 5:
linearLayout.setBackgroundResource(R.drawable.bg_box_prize_hint_v5);
break;
}
mBinding.llPrizeHint.addView(linearLayout);
if (mBinding.llPrizeHint.getChildCount() > 6) {
mBinding.llPrizeHint.removeViewAt(0);
}
for (int i = 0; i < mBinding.llPrizeHint.getChildCount(); i++) {
ObjectAnimator.ofFloat(mBinding.llPrizeHint.getChildAt(i), "translationY", ScreenUtil.dip2px(24), 0)
.setDuration(300)
.start();
}
((TextView) linearLayout.findViewById(R.id.tv_prize_name)).setText(prizeInfo.getPrizeName());
((TextView) linearLayout.findViewById(R.id.tv_prize_num)).setText("x" + prizeInfo.getPrizeNum());
}
/**
* 更新钥匙(锤子)数量
*
@@ -264,6 +299,7 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
});
}
@Override
protected boolean needSteepStateBar() {
return true;

View File

@@ -1,75 +0,0 @@
package com.yizhuan.erban.treasure_box.adapter;
import android.view.View;
import androidx.annotation.NonNull;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yizhuan.erban.R;
import com.yizhuan.treasure_box.bean.PrizeInfo;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
public class BoxPrizeHintAdapter extends BaseQuickAdapter<PrizeInfo, BaseViewHolder> implements Runnable {
public static int MAX_COUNT = 5;
public BoxPrizeHintAdapter() {
super(R.layout.item_box_prize_hint);
}
@Override
protected void convert(@NotNull BaseViewHolder helper, final PrizeInfo prizeInfo) {
View viewBg = helper.getView(R.id.view_bg);
switch (prizeInfo.getPrizeLevel()) {
case 3:
default:
viewBg.setBackgroundResource(R.drawable.bg_box_prize_hint_v3);
break;
case 4:
viewBg.setBackgroundResource(R.drawable.bg_box_prize_hint_v4);
break;
case 5:
viewBg.setBackgroundResource(R.drawable.bg_box_prize_hint_v5);
break;
}
helper.setText(R.id.tv_prize_name, prizeInfo.getPrizeName());
helper.setText(R.id.tv_prize_num, "x" + prizeInfo.getPrizeNum());
}
@Override
public void addData(@NonNull PrizeInfo data) {
super.addData(data);
if (mData.size() > MAX_COUNT) {
remove(0);
}
getRecyclerView().removeCallbacks(this);
getRecyclerView().postDelayed(this, 3000);
}
@Override
public void addData(@NonNull Collection<? extends PrizeInfo> newData) {
throw new RuntimeException("can't use this method addData");
}
@Override
public void addData(int position, @NonNull PrizeInfo data) {
throw new RuntimeException("can't use this method addData");
}
@Override
public void addData(int position, @NonNull Collection<? extends PrizeInfo> newData) {
throw new RuntimeException("can't use this method addData");
}
@Override
public void run() {
setNewData(null);
}
}

View File

@@ -205,10 +205,11 @@
app:layout_constraintStart_toStartOf="@id/view_bg"
app:layout_constraintTop_toBottomOf="@id/iv_sub" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_prize_hint"
<LinearLayout
android:id="@+id/ll_prize_hint"
android:layout_width="wrap_content"
android:layout_height="170dp"
android:gravity="bottom"
android:layout_marginStart="7dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@id/tv_continuous_num"

View File

@@ -209,8 +209,8 @@
app:layout_constraintStart_toStartOf="@id/view_bg"
app:layout_constraintTop_toBottomOf="@id/iv_sub" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_prize_hint"
<LinearLayout
android:id="@+id/ll_prize_hint"
android:layout_width="wrap_content"
android:layout_height="170dp"
android:layout_marginStart="7dp"

View File

@@ -1,26 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp">
<View
android:id="@+id/view_bg"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/bg_box_prize_hint_v3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_marginBottom="5dp"
android:gravity="center"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
tools:background="@drawable/bg_box_prize_hint_v3">
<TextView
android:id="@+id/tv_prize_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:includeFontPadding="false"
android:lines="1"
android:textColor="@color/white"
@@ -28,20 +23,21 @@
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:text="哈哈哈哈" />
<TextView
android:id="@+id/tv_prize_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:includeFontPadding="false"
android:lines="1"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_prize_name"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintTop_toTopOf="parent"
tools:text="x12" />
</LinearLayout>