diff --git a/app/src/main/java/com/yizhuan/erban/avroom/fragment/HomePartyFragment.java b/app/src/main/java/com/yizhuan/erban/avroom/fragment/HomePartyFragment.java index 912e77118..17a903f3e 100644 --- a/app/src/main/java/com/yizhuan/erban/avroom/fragment/HomePartyFragment.java +++ b/app/src/main/java/com/yizhuan/erban/avroom/fragment/HomePartyFragment.java @@ -7,9 +7,8 @@ import android.content.res.AssetFileDescriptor; import android.graphics.Color; import android.media.MediaPlayer; import android.os.Bundle; +import android.os.SystemClock; import android.text.Layout; -import android.text.Spannable; -import android.text.SpannableStringBuilder; import android.text.StaticLayout; import android.text.TextPaint; import android.text.TextUtils; @@ -17,23 +16,18 @@ import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewConfiguration; -import android.view.ViewGroup; import android.view.ViewStub; import android.view.animation.Animation; import android.view.animation.AnimationUtils; -import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatImageView; import androidx.databinding.DataBindingUtil; -import androidx.viewpager.widget.ViewPager; import com.coorchice.library.SuperTextView; import com.netease.nim.uikit.common.util.string.StringUtil; -import com.netease.nim.uikit.common.util.sys.ScreenUtil; import com.netease.nimlib.sdk.chatroom.ChatRoomMessageBuilder; import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage; import com.netease.nimlib.sdk.chatroom.model.ChatRoomNotificationAttachment; @@ -53,7 +47,6 @@ import com.yizhuan.erban.avroom.presenter.HomePartyPresenter; import com.yizhuan.erban.avroom.widget.GiftV2View; import com.yizhuan.erban.avroom.widget.MessageView; import com.yizhuan.erban.base.BaseMvpActivity; -import com.yizhuan.erban.common.widget.OriginalDrawStatusClickSpan; import com.yizhuan.erban.common.widget.dialog.DialogManager; import com.yizhuan.erban.databinding.FragmentChatroomGameMainBinding; import com.yizhuan.erban.friend.view.SelectFriendActivity; @@ -117,7 +110,6 @@ import java.util.concurrent.TimeUnit; import cn.sharesdk.framework.Platform; import io.reactivex.Observable; -import io.reactivex.Single; import io.reactivex.SingleObserver; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -990,12 +982,26 @@ public class HomePartyFragment extends AbsRoomFragment implements View.OnClickLi } private void showLuckyBagNotify(ChatRoomMessage message) { - if (animationLuckyGift == null) - animationLuckyGift = AnimationUtils.loadAnimation(mContext, R.anim.anim_box_notify); + + if (animationLuckyGift != null) { + final Animation tempAnimation = animationLuckyGift; + long animationRunTime = SystemClock.uptimeMillis() - tempAnimation.getStartTime(); + if (animationRunTime < 3000) { + gameMainBinding.flLuckyGiftNotify.postDelayed(() -> { + tempAnimation.setAnimationListener(null); + tempAnimation.cancel(); + if (gameMainBinding.flLuckyGiftNotify.getChildCount() > 1) { + gameMainBinding.flLuckyGiftNotify.getChildAt(0).clearAnimation(); + gameMainBinding.flLuckyGiftNotify.removeViewAt(0); + } + }, 500); + } + } + RoomReceivedLuckyGiftAttachment attachment = (RoomReceivedLuckyGiftAttachment) message.getAttachment(); + TextView textView = (TextView) LayoutInflater.from(mContext).inflate(R.layout.layout_room_lucky_gift_notify, null); LuckyBagNoticeInfo noticeInfo = attachment.getLuckyBagNoticeInfo(); if (noticeInfo == null) return; - SpannableBuilder text = new SpannableBuilder() .append("哇偶! ", new ForegroundColorSpan(Color.WHITE)) .append(noticeInfo.getNick() + " ", new ForegroundColorSpan(getResources().getColor(R.color.notice_nick))) @@ -1003,14 +1009,14 @@ public class HomePartyFragment extends AbsRoomFragment implements View.OnClickLi .append(noticeInfo.getLuckyBagName() + " ", new ForegroundColorSpan(Color.WHITE)) .append("开出了", new ForegroundColorSpan(Color.WHITE)) .append(noticeInfo.getGiftName(), new ForegroundColorSpan(getResources().getColor(R.color.notice_gift))); - - gameMainBinding.tvLuckyGiftNotify.setText(text.build()); - gameMainBinding.flLuckyGiftNotify.setVisibility(View.VISIBLE); - gameMainBinding.flLuckyGiftNotify.startAnimation(animationLuckyGift); + textView.setText(text.build()); + animationLuckyGift = AnimationUtils.loadAnimation(mContext, R.anim.anim_box_notify); + textView.startAnimation(animationLuckyGift); animationLuckyGift.setAnimationListener(new SimpleAnimationListener() { @Override - public void onAnimationEnd(Animation animation) { - gameMainBinding.flLuckyGiftNotify.setVisibility(View.GONE); + public void onAnimationEnd(Animation a) { + animationLuckyGift = null; + gameMainBinding.flLuckyGiftNotify.post(() -> gameMainBinding.flLuckyGiftNotify.removeView(textView)); } }); } @@ -1025,7 +1031,7 @@ public class HomePartyFragment extends AbsRoomFragment implements View.OnClickLi messages.add(chatRoomMessage); if (boxDisposable == null || messages.size() == 1) { isCreate = true; - boxDisposable = Observable.interval(0, ANIM_TIME, TimeUnit.SECONDS) + boxDisposable = Observable.interval(0, 500, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .doOnNext(aLong -> { if (messages.size() > 0 && !isCreate) @@ -1038,23 +1044,38 @@ public class HomePartyFragment extends AbsRoomFragment implements View.OnClickLi } private void showBoxNotify(ChatRoomMessage chatRoomMessage) { + if (animation != null) { + final Animation tempAnimation = animation; + long animationRunTime = SystemClock.uptimeMillis() - tempAnimation.getStartTime(); + if (animationRunTime < 3000) { + gameMainBinding.flBoxNotify.postDelayed(() -> { + tempAnimation.setAnimationListener(null); + tempAnimation.cancel(); + if (gameMainBinding.flBoxNotify.getChildCount() > 1) { + gameMainBinding.flBoxNotify.getChildAt(0).clearAnimation(); + gameMainBinding.flBoxNotify.removeViewAt(0); + } + }, 500); + } + } + RoomBoxPrizeAttachment attachment = (RoomBoxPrizeAttachment) chatRoomMessage.getAttachment(); - // 内容 - SpannableBuilder text = new SpannableBuilder() + TextView textView = (TextView) LayoutInflater.from(mContext).inflate(R.layout.layout_room_box_notify, null); + SpannableBuilder text = new SpannableBuilder() .append("厉害了! ", new ForegroundColorSpan(Color.WHITE)) .append(attachment.getNick() + " ", new ForegroundColorSpan(getResources().getColor(R.color.notice_nick))) .append(attachment.getBoxTypeStr() + " ", new ForegroundColorSpan(Color.WHITE)) .append(attachment.getPrizeName(), new ForegroundColorSpan(getResources().getColor(R.color.notice_gift))) .append("x" + attachment.getPrizeNum(), new ForegroundColorSpan(Color.WHITE)); - gameMainBinding.tvBoxNotify.setText(text.build()); - if (animation == null) - animation = AnimationUtils.loadAnimation(mContext, R.anim.anim_box_notify); - gameMainBinding.flBoxNotify.setVisibility(View.VISIBLE); - gameMainBinding.flBoxNotify.startAnimation(animation); + textView.setText(text.build()); + animation = AnimationUtils.loadAnimation(mContext, R.anim.anim_box_notify); + gameMainBinding.flBoxNotify.addView(textView); + textView.startAnimation(animation); animation.setAnimationListener(new SimpleAnimationListener() { @Override - public void onAnimationEnd(Animation animation) { - gameMainBinding.flBoxNotify.setVisibility(View.GONE); + public void onAnimationEnd(Animation a) { + animation = null; + gameMainBinding.flBoxNotify.post(() -> gameMainBinding.flBoxNotify.removeView(textView)); } }); } diff --git a/app/src/main/res/layout/fragment_chatroom_game_main.xml b/app/src/main/res/layout/fragment_chatroom_game_main.xml index 635b1f0c1..d8bcdc144 100644 --- a/app/src/main/res/layout/fragment_chatroom_game_main.xml +++ b/app/src/main/res/layout/fragment_chatroom_game_main.xml @@ -237,50 +237,18 @@ android:id="@+id/fl_lucky_gift_notify" android:layout_width="match_parent" android:layout_height="0dp" - android:background="@drawable/bg_lucky_gift_notice" - android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintDimensionRatio="75:11" - app:layout_constraintTop_toTopOf="parent"> - - - + app:layout_constraintTop_toTopOf="parent" /> - - - + app:layout_constraintTop_toTopOf="parent" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_room_lucky_gift_notify.xml b/app/src/main/res/layout/layout_room_lucky_gift_notify.xml new file mode 100644 index 000000000..52ceb6fdd --- /dev/null +++ b/app/src/main/res/layout/layout_room_lucky_gift_notify.xml @@ -0,0 +1,13 @@ + + \ No newline at end of file