涂鸦礼物初版实现
This commit is contained in:
@@ -110,7 +110,6 @@ public class ButtonItemFactory {
|
|||||||
List<ViewItem> buttonItems = new ArrayList<>();
|
List<ViewItem> buttonItems = new ArrayList<>();
|
||||||
//ture则表示需要传入此类型button
|
//ture则表示需要传入此类型button
|
||||||
boolean gift = false;
|
boolean gift = false;
|
||||||
boolean magic = false;
|
|
||||||
if (isNeedGiftItem) {
|
if (isNeedGiftItem) {
|
||||||
gift = true;
|
gift = true;
|
||||||
}
|
}
|
||||||
@@ -162,9 +161,6 @@ public class ButtonItemFactory {
|
|||||||
buttonItems.add(createSendGiftItem(context, uid, isInRoom, listener));
|
buttonItems.add(createSendGiftItem(context, uid, isInRoom, listener));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (magic) {
|
|
||||||
buttonItems.add(createSendMagicItem(context, account, isInRoom, listener));
|
|
||||||
}
|
|
||||||
// 私聊
|
// 私聊
|
||||||
buttonItems.add(createPrivateChatItem(context, account, isInRoom));
|
buttonItems.add(createPrivateChatItem(context, account, isInRoom));
|
||||||
|
|
||||||
@@ -268,23 +264,6 @@ public class ButtonItemFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 送魔法
|
|
||||||
*/
|
|
||||||
public static ViewItem createSendMagicItem(final Context context, String account, boolean isInRoom,
|
|
||||||
final GiftDialog.OnGiftDialogBtnClickListener listener) {
|
|
||||||
return new ViewItem("施魔法", R.drawable.icon_dialog_send_magic, () -> {
|
|
||||||
StatisticManager.Instance().onEvent(StatisticsProtocol.data_card_magic_send_click, "资料卡片-送魔法");
|
|
||||||
|
|
||||||
GiftDialog dialog = new GiftDialog(context, JavaUtil.str2long(account), isInRoom, true);
|
|
||||||
if (listener != null) {
|
|
||||||
dialog.setGiftDialogBtnClickListener(listener);
|
|
||||||
}
|
|
||||||
dialog.show();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 私聊
|
* 私聊
|
||||||
*/
|
*/
|
||||||
|
@@ -683,16 +683,21 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
|
|||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
override fun onSendGiftBtnClick(
|
override fun onSendGiftBtnClick(
|
||||||
giftInfo: GiftInfo, micMemberInfos: ArrayList<MicMemberInfo>,
|
giftInfo: GiftInfo,
|
||||||
number: Int, msg: String?, isKnap: Boolean,
|
micMemberInfos: ArrayList<MicMemberInfo>,
|
||||||
isWholdMic: Boolean, callback: SenGiftCallback
|
number: Int,
|
||||||
|
msg: String?,
|
||||||
|
isKnap: Boolean,
|
||||||
|
isWholdMic: Boolean,
|
||||||
|
drawFixedArray: List<HashMap<String, String>>,
|
||||||
|
callback: SenGiftCallback
|
||||||
) {
|
) {
|
||||||
val targetUids: MutableList<Long> = ArrayList()
|
val targetUids: MutableList<Long> = ArrayList()
|
||||||
for (i in micMemberInfos.indices) {
|
for (i in micMemberInfos.indices) {
|
||||||
targetUids.add(micMemberInfos[i].account.toLong())
|
targetUids.add(micMemberInfos[i].account.toLong())
|
||||||
}
|
}
|
||||||
GiftModel.get()
|
GiftModel.get()
|
||||||
.sendRoomGift(giftInfo.giftId, targetUids, number, msg, isKnap, isWholdMic)
|
.sendRoomGift(giftInfo.giftId, targetUids, number, msg, isKnap, isWholdMic,drawFixedArray)
|
||||||
.compose(bindUntilEvent(FragmentEvent.DESTROY))
|
.compose(bindUntilEvent(FragmentEvent.DESTROY))
|
||||||
.doOnError {
|
.doOnError {
|
||||||
if (it is VipLevelNotEnoughException) {
|
if (it is VipLevelNotEnoughException) {
|
||||||
@@ -713,13 +718,6 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSendMagicBtnClick(
|
|
||||||
magicInfo: MagicInfo,
|
|
||||||
targetUid: Long,
|
|
||||||
callback: SenGiftCallback
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onUpMicro(micPosition: Int) {
|
private fun onUpMicro(micPosition: Int) {
|
||||||
showBottomViewForDifRole()
|
showBottomViewForDifRole()
|
||||||
updateMicBtn()
|
updateMicBtn()
|
||||||
|
@@ -35,6 +35,7 @@ import com.opensource.svgaplayer.SVGAVideoEntity;
|
|||||||
import com.yizhuan.erban.R;
|
import com.yizhuan.erban.R;
|
||||||
import com.yizhuan.erban.common.svga.SimpleSvgaParseCompletion;
|
import com.yizhuan.erban.common.svga.SimpleSvgaParseCompletion;
|
||||||
import com.yizhuan.erban.ui.utils.ImageLoadUtils;
|
import com.yizhuan.erban.ui.utils.ImageLoadUtils;
|
||||||
|
import com.yizhuan.erban.ui.widget.drawgift.DrawGiftHelper;
|
||||||
import com.yizhuan.erban.ui.widget.magicindicator.buildins.UIUtil;
|
import com.yizhuan.erban.ui.widget.magicindicator.buildins.UIUtil;
|
||||||
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
||||||
import com.yizhuan.xchat_android_core.fansteam.FansTeamMsgInfo;
|
import com.yizhuan.xchat_android_core.fansteam.FansTeamMsgInfo;
|
||||||
@@ -57,6 +58,7 @@ import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
|||||||
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
||||||
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterAttackInfo;
|
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterAttackInfo;
|
||||||
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
||||||
|
import com.yizhuan.xchat_android_core.utils.LogUtils;
|
||||||
import com.yizhuan.xchat_android_library.utils.ResolutionUtils;
|
import com.yizhuan.xchat_android_library.utils.ResolutionUtils;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
@@ -98,6 +100,7 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
|
|||||||
private Keyframe[] keyTrans;
|
private Keyframe[] keyTrans;
|
||||||
private SvgaObjectPool mMagicViewPool;
|
private SvgaObjectPool mMagicViewPool;
|
||||||
private volatile Hashtable<Integer, MonsterAttackInfo> currentAnimationMap = new Hashtable<>();
|
private volatile Hashtable<Integer, MonsterAttackInfo> currentAnimationMap = new Hashtable<>();
|
||||||
|
private DrawGiftHelper drawGiftHelper;
|
||||||
|
|
||||||
|
|
||||||
public GiftV2View(Context context) {
|
public GiftV2View(Context context) {
|
||||||
@@ -279,6 +282,12 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
|
|||||||
targetUsers.add(giftReceiver);
|
targetUsers.add(giftReceiver);
|
||||||
}
|
}
|
||||||
GiftReceiveInfo giftReceiveInfo = giftReceiveInfos.get(0);
|
GiftReceiveInfo giftReceiveInfo = giftReceiveInfos.get(0);
|
||||||
|
if (giftReceiveInfo.getDrawFixedArray() != null) {
|
||||||
|
if (drawGiftHelper == null) {
|
||||||
|
drawGiftHelper = new DrawGiftHelper((Activity) context);
|
||||||
|
}
|
||||||
|
drawGiftHelper.prepareShowDrawGift(giftReceiveInfo.getDrawFixedArray(), false);
|
||||||
|
}
|
||||||
GiftInfo giftInfo = giftReceiveInfo.getGift();
|
GiftInfo giftInfo = giftReceiveInfo.getGift();
|
||||||
if (totalCoin >= 520 || (giftInfo != null && giftInfo.isHasEffect())) {
|
if (totalCoin >= 520 || (giftInfo != null && giftInfo.isHasEffect())) {
|
||||||
Message msg = Message.obtain();
|
Message msg = Message.obtain();
|
||||||
|
@@ -6,16 +6,13 @@ import com.yizhuan.xchat_android_core.magic.bean.MagicInfo;
|
|||||||
import com.yizhuan.xchat_android_core.room.queue.bean.MicMemberInfo;
|
import com.yizhuan.xchat_android_core.room.queue.bean.MicMemberInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class OnGiftDialogBtnClickListenerWrapper implements GiftDialog.OnGiftDialogBtnClickListener {
|
public class OnGiftDialogBtnClickListenerWrapper implements GiftDialog.OnGiftDialogBtnClickListener {
|
||||||
@Override
|
@Override
|
||||||
public void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos, int number, String msg, boolean isKnap, boolean isWholeMic, GiftDialog.SenGiftCallback callback) {
|
public void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos, int number, String msg, boolean isKnap, boolean isWholeMic, List<HashMap<String, String>> drawFixedArray, GiftDialog.SenGiftCallback callback) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSendMagicBtnClick(MagicInfo magicInfo, long targetUid, GiftDialog.SenGiftCallback callback) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,18 +1,18 @@
|
|||||||
package com.yizhuan.erban.ui.gift.dialog;
|
package com.yizhuan.erban.ui.gift.dialog;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.viewpager.widget.PagerAdapter;
|
|
||||||
import androidx.viewpager.widget.ViewPager;
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import com.orhanobut.logger.Logger;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.viewpager.widget.PagerAdapter;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
import com.yizhuan.erban.BR;
|
import com.yizhuan.erban.BR;
|
||||||
import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
|
import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
|
||||||
import com.yizhuan.xchat_android_core.magic.bean.MagicInfo;
|
import com.yizhuan.xchat_android_core.magic.bean.MagicInfo;
|
||||||
@@ -151,13 +151,8 @@ public class GiftGridView extends ViewPager {
|
|||||||
page = result.get(result.size() - 1);
|
page = result.get(result.size() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.get(i) instanceof GiftInfo) {
|
item = createGiftItem(context, (GiftInfo) data.get(i), i == 0, isKnap);
|
||||||
item = createGiftItem(context, (GiftInfo) data.get(i), i == 0, isKnap);
|
if (page != null) {
|
||||||
} else if (data.get(i) instanceof MagicInfo) {
|
|
||||||
item = createMagicItem(context, (MagicInfo) data.get(i), i == 0);
|
|
||||||
}
|
|
||||||
Logger.i("pos:" + i + ", item:" + item + ", page:" + page);
|
|
||||||
if (item != null && page != null) {
|
|
||||||
page.add(item);
|
page.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,9 +162,4 @@ public class GiftGridView extends ViewPager {
|
|||||||
public static GiftInfoVm createGiftItem(Context context, GiftInfo giftInfo, boolean select, boolean isKnap) {
|
public static GiftInfoVm createGiftItem(Context context, GiftInfo giftInfo, boolean select, boolean isKnap) {
|
||||||
return new GiftInfoVm(context, giftInfo, select, isKnap);
|
return new GiftInfoVm(context, giftInfo, select, isKnap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MagicInfoVm createMagicItem(Context context, MagicInfo magicInfo, boolean select) {
|
|
||||||
return new MagicInfoVm(context, magicInfo, select);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,37 +0,0 @@
|
|||||||
package com.yizhuan.erban.ui.gift.dialog;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import androidx.databinding.ObservableBoolean;
|
|
||||||
import androidx.databinding.ObservableField;
|
|
||||||
|
|
||||||
import com.yizhuan.erban.R;
|
|
||||||
import com.yizhuan.xchat_android_core.magic.bean.MagicInfo;
|
|
||||||
import com.yizhuan.xchat_android_library.bindinglist.BaseItem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 魔法
|
|
||||||
* Created by lvzebiao on 2018/11/20.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class MagicInfoVm extends BaseItem<MagicInfo> {
|
|
||||||
|
|
||||||
public final ObservableBoolean isSelect = new ObservableBoolean();
|
|
||||||
|
|
||||||
public final ObservableField<String> goldText = new ObservableField<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MagicInfo data() {
|
|
||||||
return super.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
public MagicInfoVm(Context context, MagicInfo data, boolean select) {
|
|
||||||
super(context, data);
|
|
||||||
this.isSelect.set(select);
|
|
||||||
this.goldText.set(data.getPrice() + "钻石");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getType() {
|
|
||||||
return R.layout.list_item_dialog_magic;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -22,6 +22,8 @@ import com.yizhuan.xchat_android_core.utils.net.VipLevelNotEnoughException;
|
|||||||
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by xiaoyu
|
* Created by xiaoyu
|
||||||
@@ -53,7 +55,7 @@ public class GiftAction extends BaseAction implements GiftDialog.OnGiftDialogBtn
|
|||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
@Override
|
@Override
|
||||||
public void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos, int number, String msg, boolean isknap, boolean isWholeMic, GiftDialog.SenGiftCallback callback) {
|
public void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos, int number, String msg, boolean isknap, boolean isWholeMic, List<HashMap<String, String>> drawFixedArray, GiftDialog.SenGiftCallback callback) {
|
||||||
if (giftInfo == null) return;
|
if (giftInfo == null) return;
|
||||||
GiftModel.get().sendPersonalGift(giftInfo.getGiftId(), micMemberInfos.get(0).getAccount(), number, msg, isknap)
|
GiftModel.get().sendPersonalGift(giftInfo.getGiftId(), micMemberInfos.get(0).getAccount(), number, msg, isknap)
|
||||||
.doOnError(throwable -> {
|
.doOnError(throwable -> {
|
||||||
@@ -80,27 +82,4 @@ public class GiftAction extends BaseAction implements GiftDialog.OnGiftDialogBtn
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSendMagicBtnClick(MagicInfo magicInfo, long targetUid, GiftDialog.SenGiftCallback callback) {
|
|
||||||
//赠送魔法的回调
|
|
||||||
MagicModel.get().sendMagic(magicInfo.getMagicId(), targetUid)
|
|
||||||
.subscribe(new BeanObserver<MagicReceivedInfo>() {
|
|
||||||
@Override
|
|
||||||
public void onErrorMsg(String error) {
|
|
||||||
SingleToastUtil.showToast(error);
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onFail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSuccess(MagicReceivedInfo info) {
|
|
||||||
PayModel.get().decreaseLocalGold(magicInfo.getPrice());
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onSuccess();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@@ -1,28 +1,12 @@
|
|||||||
package com.yizhuan.erban.ui.widget;
|
package com.yizhuan.erban.ui.widget;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
|
||||||
|
|
||||||
import androidx.viewpager.widget.PagerAdapter;
|
|
||||||
import androidx.viewpager.widget.ViewPager;
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -40,6 +24,16 @@ import android.widget.FrameLayout;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.viewpager.widget.PagerAdapter;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||||
import com.trello.rxlifecycle3.components.support.RxAppCompatActivity;
|
import com.trello.rxlifecycle3.components.support.RxAppCompatActivity;
|
||||||
import com.yizhuan.erban.BR;
|
import com.yizhuan.erban.BR;
|
||||||
import com.yizhuan.erban.R;
|
import com.yizhuan.erban.R;
|
||||||
@@ -48,16 +42,15 @@ import com.yizhuan.erban.base.BaseActivity;
|
|||||||
import com.yizhuan.erban.common.widget.CircleImageView;
|
import com.yizhuan.erban.common.widget.CircleImageView;
|
||||||
import com.yizhuan.erban.common.widget.dialog.DialogManager;
|
import com.yizhuan.erban.common.widget.dialog.DialogManager;
|
||||||
import com.yizhuan.erban.radish.task.activity.TaskCenterActivity;
|
import com.yizhuan.erban.radish.task.activity.TaskCenterActivity;
|
||||||
import com.yizhuan.erban.radish.wallet.RadishWalletManager;
|
|
||||||
import com.yizhuan.erban.ui.gift.dialog.GiftInfoVm;
|
import com.yizhuan.erban.ui.gift.dialog.GiftInfoVm;
|
||||||
import com.yizhuan.erban.ui.gift.dialog.MagicInfoVm;
|
|
||||||
import com.yizhuan.erban.ui.gift.dialog.PageIndicatorView;
|
import com.yizhuan.erban.ui.gift.dialog.PageIndicatorView;
|
||||||
import com.yizhuan.erban.ui.pay.ChargeActivity;
|
import com.yizhuan.erban.ui.pay.ChargeActivity;
|
||||||
import com.yizhuan.erban.ui.pay.ChargeDialog;
|
import com.yizhuan.erban.ui.pay.ChargeDialog;
|
||||||
import com.yizhuan.erban.ui.utils.ImageLoadUtils;
|
import com.yizhuan.erban.ui.utils.ImageLoadUtils;
|
||||||
import com.yizhuan.erban.ui.webview.DialogWebViewActivity;
|
import com.yizhuan.erban.ui.webview.DialogWebViewActivity;
|
||||||
import com.yizhuan.erban.ui.widget.dialog.GiftManualQuantityDialog;
|
import com.yizhuan.erban.ui.widget.dialog.GiftManualQuantityDialog;
|
||||||
import com.yizhuan.erban.ui.widget.higuide.TuTuGuideHelper;
|
import com.yizhuan.erban.ui.widget.drawgift.DrawGiftHelper;
|
||||||
|
import com.yizhuan.erban.ui.widget.drawgift.DrawGiftView;
|
||||||
import com.yizhuan.erban.ui.widget.magicindicator.GiftIndicator;
|
import com.yizhuan.erban.ui.widget.magicindicator.GiftIndicator;
|
||||||
import com.yizhuan.erban.ui.widget.magicindicator.buildins.UIUtil;
|
import com.yizhuan.erban.ui.widget.magicindicator.buildins.UIUtil;
|
||||||
import com.yizhuan.erban.ui.widget.recyclerview.decoration.VerticalDecoration;
|
import com.yizhuan.erban.ui.widget.recyclerview.decoration.VerticalDecoration;
|
||||||
@@ -84,8 +77,6 @@ import com.yizhuan.xchat_android_core.pay.PayModel;
|
|||||||
import com.yizhuan.xchat_android_core.pay.bean.WalletInfo;
|
import com.yizhuan.xchat_android_core.pay.bean.WalletInfo;
|
||||||
import com.yizhuan.xchat_android_core.pay.event.FirstChargeEvent;
|
import com.yizhuan.xchat_android_core.pay.event.FirstChargeEvent;
|
||||||
import com.yizhuan.xchat_android_core.pay.event.UpdateWalletInfoEvent;
|
import com.yizhuan.xchat_android_core.pay.event.UpdateWalletInfoEvent;
|
||||||
import com.yizhuan.xchat_android_core.radish.RadishModel;
|
|
||||||
import com.yizhuan.xchat_android_core.radish.RadishWalletInfo;
|
|
||||||
import com.yizhuan.xchat_android_core.room.anotherroompk.ShowUserInfoDialogEvent;
|
import com.yizhuan.xchat_android_core.room.anotherroompk.ShowUserInfoDialogEvent;
|
||||||
import com.yizhuan.xchat_android_core.room.pk.model.PkModel;
|
import com.yizhuan.xchat_android_core.room.pk.model.PkModel;
|
||||||
import com.yizhuan.xchat_android_core.room.queue.bean.MicMemberInfo;
|
import com.yizhuan.xchat_android_core.room.queue.bean.MicMemberInfo;
|
||||||
@@ -93,7 +84,6 @@ import com.yizhuan.xchat_android_core.statistic.StatisticManager;
|
|||||||
import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol;
|
import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol;
|
||||||
import com.yizhuan.xchat_android_core.user.UserModel;
|
import com.yizhuan.xchat_android_core.user.UserModel;
|
||||||
import com.yizhuan.xchat_android_core.user.bean.UserInfo;
|
import com.yizhuan.xchat_android_core.user.bean.UserInfo;
|
||||||
import com.yizhuan.xchat_android_core.utils.ActivityUtil;
|
|
||||||
import com.yizhuan.xchat_android_core.utils.StringExtensionKt;
|
import com.yizhuan.xchat_android_core.utils.StringExtensionKt;
|
||||||
import com.yizhuan.xchat_android_core.utils.net.BalanceNotEnoughExeption;
|
import com.yizhuan.xchat_android_core.utils.net.BalanceNotEnoughExeption;
|
||||||
import com.yizhuan.xchat_android_core.utils.net.FreezeException;
|
import com.yizhuan.xchat_android_core.utils.net.FreezeException;
|
||||||
@@ -103,6 +93,7 @@ import com.yizhuan.xchat_android_library.bindinglist.MultiTypeAdapter;
|
|||||||
import com.yizhuan.xchat_android_library.utils.FormatUtils;
|
import com.yizhuan.xchat_android_library.utils.FormatUtils;
|
||||||
import com.yizhuan.xchat_android_library.utils.ListUtils;
|
import com.yizhuan.xchat_android_library.utils.ListUtils;
|
||||||
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
||||||
|
import com.yizhuan.xchat_android_library.utils.TextWatcherWrapper;
|
||||||
import com.zyyoona7.lib.EasyPopup;
|
import com.zyyoona7.lib.EasyPopup;
|
||||||
import com.zyyoona7.lib.HorizontalGravity;
|
import com.zyyoona7.lib.HorizontalGravity;
|
||||||
import com.zyyoona7.lib.VerticalGravity;
|
import com.zyyoona7.lib.VerticalGravity;
|
||||||
@@ -112,6 +103,7 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -119,7 +111,6 @@ import io.reactivex.Single;
|
|||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.functions.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author chenran
|
* @author chenran
|
||||||
@@ -132,19 +123,25 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
private static final int ITEM_TYPE_GOLD = 0; // 钻石
|
private static final int ITEM_TYPE_GOLD = 0; // 钻石
|
||||||
private static final int ITEM_TYPE_RADISH = 1; // 萝卜
|
private static final int ITEM_TYPE_RADISH = 1; // 萝卜
|
||||||
public static String GIFT_DIALOG_FROM = ""; // 埋点用,标识从哪个位置打开弹框
|
public static String GIFT_DIALOG_FROM = ""; // 埋点用,标识从哪个位置打开弹框
|
||||||
private Context context;
|
private final Context context;
|
||||||
|
/**
|
||||||
|
* 被送礼物的人的uid
|
||||||
|
*/
|
||||||
|
private final long uid;
|
||||||
|
private final int giftId;
|
||||||
|
private final boolean isInRoom;
|
||||||
|
/**
|
||||||
|
* 被选中的uid是否在麦上
|
||||||
|
*/
|
||||||
|
private final boolean userOnMic;
|
||||||
|
private View mContentView;
|
||||||
private ViewPager gridView;
|
private ViewPager gridView;
|
||||||
private PageIndicatorView indicatorView;
|
private PageIndicatorView indicatorView;
|
||||||
private RecyclerView avatarList;
|
private RecyclerView avatarList;
|
||||||
private GiftAvatarAdapter avatarListAdapter;
|
private GiftAvatarAdapter avatarListAdapter;
|
||||||
@Nullable
|
@Nullable
|
||||||
private GiftInfo currentGiftInfo;
|
private GiftInfo currentGiftInfo;
|
||||||
/**
|
|
||||||
* 当前选中的魔法礼物
|
|
||||||
*/
|
|
||||||
private MagicInfo currentMagicInfo;
|
|
||||||
private List<GiftInfo> currentGiftInfoList;
|
private List<GiftInfo> currentGiftInfoList;
|
||||||
private List<MagicInfo> currentMagicInfoList;
|
|
||||||
private OnGiftDialogBtnClickListener giftDialogBtnClickListener;
|
private OnGiftDialogBtnClickListener giftDialogBtnClickListener;
|
||||||
private CircleImageView avatarImage;
|
private CircleImageView avatarImage;
|
||||||
private TextView nickText;
|
private TextView nickText;
|
||||||
@@ -165,54 +162,30 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
private GiftIndicator giftIndicator;
|
private GiftIndicator giftIndicator;
|
||||||
private int giftNumber = 1;
|
private int giftNumber = 1;
|
||||||
private View sendContainer;
|
private View sendContainer;
|
||||||
private Button btnSendMagic;
|
|
||||||
private TextView tvTextGold;
|
private TextView tvTextGold;
|
||||||
private TextView tvRecharge;
|
private TextView tvRecharge;
|
||||||
|
|
||||||
private ImageView ivAvatarCharm;
|
private ImageView ivAvatarCharm;
|
||||||
private ImageView ivAvatarLevel;
|
private ImageView ivAvatarLevel;
|
||||||
private TextView tvNickCharm;
|
private TextView tvNickCharm;
|
||||||
private TextView tvNickLevel;
|
private TextView tvNickLevel;
|
||||||
private View llWeekIn;
|
private View llWeekIn;
|
||||||
private View llStarWeek;
|
private View llStarWeek;
|
||||||
/**
|
|
||||||
* 被送礼物的人的uid
|
|
||||||
*/
|
|
||||||
private long uid;
|
|
||||||
private int giftId;
|
|
||||||
private List<MicMemberInfo> micMemberInfos;
|
private List<MicMemberInfo> micMemberInfos;
|
||||||
private View giftNumLayout;
|
private View giftNumLayout;
|
||||||
private Disposable mSubscribe;
|
private Disposable mSubscribe;
|
||||||
private CompositeDisposable compositeDisposable;
|
private CompositeDisposable compositeDisposable;
|
||||||
private boolean isMagic;
|
private GiftInfoVm lastSelectedItem;
|
||||||
private boolean isInRoom;
|
private List<List<GiftInfoVm>> pagerList;
|
||||||
/**
|
|
||||||
* ture则隐藏魔法,默认false
|
|
||||||
*/
|
|
||||||
private boolean isHideMagicTab;
|
|
||||||
/**
|
|
||||||
* 被选中的uid是否在麦上
|
|
||||||
*/
|
|
||||||
private boolean userOnMic;
|
|
||||||
private IItem LastSelectedItem;
|
|
||||||
private List<List<IItem>> pagerList;
|
|
||||||
private Observer<RadishWalletInfo> radishObserver;
|
|
||||||
private RadishWalletInfo radishWalletInfo;
|
|
||||||
private WalletInfo goldWalletInfo;
|
private WalletInfo goldWalletInfo;
|
||||||
private int itemType = ITEM_TYPE_GOLD;
|
private int itemType = ITEM_TYPE_GOLD;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private DrawGiftHelper drawGiftHelper;
|
||||||
|
|
||||||
public GiftDialog(Context context, int giftId) {
|
public GiftDialog(Context context, int giftId) {
|
||||||
this(context, 0, true, false, true, giftId);
|
this(context, 0, true, false, true, giftId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GiftDialog(Context context, long OtherUid, boolean isInRoom) {
|
|
||||||
this(context, OtherUid, isInRoom, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GiftDialog(Context context, long OtherUid, boolean isInRoom, boolean isMagic) {
|
|
||||||
this(context, OtherUid, isInRoom, isMagic, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GiftDialog(Context context, long OtherUid, boolean isInRoom, boolean isMagic, boolean isHideMagicTab) {
|
public GiftDialog(Context context, long OtherUid, boolean isInRoom, boolean isMagic, boolean isHideMagicTab) {
|
||||||
this(context, OtherUid, isInRoom, isMagic, isHideMagicTab, 0);
|
this(context, OtherUid, isInRoom, isMagic, isHideMagicTab, 0);
|
||||||
}
|
}
|
||||||
@@ -225,7 +198,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
* false表示不在房间,此时OtherUid就是被赠送人的ID
|
* false表示不在房间,此时OtherUid就是被赠送人的ID
|
||||||
* @param isHideMagicTab true则隐藏魔法,默认false
|
* @param isHideMagicTab true则隐藏魔法,默认false
|
||||||
*/
|
*/
|
||||||
public GiftDialog(Context context, long OtherUid, boolean isInRoom, boolean isMagic, boolean isHideMagicTab, int giftId) {
|
public GiftDialog(Context context, long OtherUid, boolean isInRoom, @Deprecated boolean isMagic, @Deprecated boolean isHideMagicTab, int giftId) {
|
||||||
super(context, R.style.ErbanBottomSheetDialogDimFalse);
|
super(context, R.style.ErbanBottomSheetDialogDimFalse);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.uid = OtherUid;
|
this.uid = OtherUid;
|
||||||
@@ -233,25 +206,23 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
this.micMemberInfos = new ArrayList<>();
|
this.micMemberInfos = new ArrayList<>();
|
||||||
this.micMemberInfos.addAll(transformAvatarList(OtherUid));
|
this.micMemberInfos.addAll(transformAvatarList(OtherUid));
|
||||||
this.isInRoom = isInRoom;
|
this.isInRoom = isInRoom;
|
||||||
this.isMagic = isMagic;
|
|
||||||
this.isHideMagicTab = isHideMagicTab;
|
|
||||||
//判断用户在不在麦上
|
//判断用户在不在麦上
|
||||||
this.userOnMic = AvRoomDataManager.get().checkIsOnMicByAccount(String.valueOf(uid));
|
this.userOnMic = AvRoomDataManager.get().checkIsOnMicByAccount(String.valueOf(uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> List<List<IItem>> beanTransformVm(Context context,
|
private List<List<GiftInfoVm>> beanTransformVm(Context context,
|
||||||
List<T> data,
|
List<GiftInfo> data,
|
||||||
boolean isKnap,
|
boolean isKnap,
|
||||||
int pageSize,
|
int pageSize,
|
||||||
@Nullable GiftInfo selectGiftInfo) {
|
@Nullable GiftInfo selectGiftInfo) {
|
||||||
List<List<IItem>> result = new ArrayList<>();
|
List<List<GiftInfoVm>> result = new ArrayList<>();
|
||||||
if (ListUtils.isListEmpty(data)) {
|
if (ListUtils.isListEmpty(data)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
boolean hasSelectGift = false;
|
boolean hasSelectGift = false;
|
||||||
for (int i = 0; i < data.size(); i++) {
|
for (int i = 0; i < data.size(); i++) {
|
||||||
IItem item = null;
|
GiftInfoVm item = null;
|
||||||
List<IItem> page = null;
|
List<GiftInfoVm> page = null;
|
||||||
if (i % pageSize == 0) {
|
if (i % pageSize == 0) {
|
||||||
page = new ArrayList<>();
|
page = new ArrayList<>();
|
||||||
result.add(page);
|
result.add(page);
|
||||||
@@ -261,34 +232,22 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.get(i) instanceof GiftInfo) {
|
boolean select = false;
|
||||||
boolean select = false;
|
if (selectGiftInfo != null && selectGiftInfo.getGiftId() == data.get(i).getGiftId()) {
|
||||||
if (selectGiftInfo != null && selectGiftInfo.getGiftId() == ((GiftInfo) data.get(i)).getGiftId()) {
|
hasSelectGift = true;
|
||||||
hasSelectGift = true;
|
select = true;
|
||||||
select = true;
|
|
||||||
}
|
|
||||||
item = createGiftItem(context, (GiftInfo) data.get(i), select, isKnap);
|
|
||||||
} else if (data.get(i) instanceof MagicInfo) {
|
|
||||||
item = createMagicItem(context, (MagicInfo) data.get(i), i == 0);
|
|
||||||
}
|
}
|
||||||
if (item != null && page != null) {
|
item = new GiftInfoVm(context, data.get(i), select, isKnap);
|
||||||
|
if (page != null) {
|
||||||
page.add(item);
|
page.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasSelectGift && result.get(0).get(0) instanceof GiftInfoVm) {
|
if (!hasSelectGift) {
|
||||||
((GiftInfoVm) result.get(0).get(0)).isSelect.set(true);
|
result.get(0).get(0).isSelect.set(true);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GiftInfoVm createGiftItem(Context context, GiftInfo giftInfo, boolean select, boolean isKnap) {
|
|
||||||
return new GiftInfoVm(context, giftInfo, select, isKnap);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MagicInfoVm createMagicItem(Context context, MagicInfo magicInfo, boolean select) {
|
|
||||||
return new MagicInfoVm(context, magicInfo, select);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGiftDialogBtnClickListener(OnGiftDialogBtnClickListener giftDialogBtnClickListener) {
|
public void setGiftDialogBtnClickListener(OnGiftDialogBtnClickListener giftDialogBtnClickListener) {
|
||||||
this.giftDialogBtnClickListener = giftDialogBtnClickListener;
|
this.giftDialogBtnClickListener = giftDialogBtnClickListener;
|
||||||
}
|
}
|
||||||
@@ -357,7 +316,8 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
setCanceledOnTouchOutside(true);
|
setCanceledOnTouchOutside(true);
|
||||||
setContentView(R.layout.dialog_bottom_gift);
|
setContentView(R.layout.dialog_bottom_gift);
|
||||||
compositeDisposable = new CompositeDisposable();
|
compositeDisposable = new CompositeDisposable();
|
||||||
init(findViewById(R.id.ll_dialog_bottom_gift));
|
mContentView = findViewById(R.id.ll_dialog_bottom_gift);
|
||||||
|
init(mContentView);
|
||||||
FrameLayout bottomSheet = findViewById(R.id.design_bottom_sheet);
|
FrameLayout bottomSheet = findViewById(R.id.design_bottom_sheet);
|
||||||
if (bottomSheet != null) {
|
if (bottomSheet != null) {
|
||||||
BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(false);
|
BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(false);
|
||||||
@@ -411,8 +371,8 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_NORMAL, "礼物", "礼物"));
|
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_NORMAL, "礼物", "礼物"));
|
||||||
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_LUCKY, "幸运礼物", "幸运礼物"));
|
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_LUCKY, "幸运礼物", "幸运礼物"));
|
||||||
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_NOBLE, "贵族", "贵族"));
|
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_NOBLE, "贵族", "贵族"));
|
||||||
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_MAGIC, "魔法", "魔法"));
|
|
||||||
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_WEEK, "周星礼物", "周星礼物"));
|
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_WEEK, "周星礼物", "周星礼物"));
|
||||||
|
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_DRAW_GIFT, "涂鸦礼物", "涂鸦礼物"));
|
||||||
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_KNAP, "背包", "背包"));
|
tabInfoList.add(new GiftTab(GiftIndicator.TYPE_KNAP, "背包", "背包"));
|
||||||
giftIndicator = root.findViewById(R.id.gift_indicator);
|
giftIndicator = root.findViewById(R.id.gift_indicator);
|
||||||
giftIndicator.initTab(
|
giftIndicator.initTab(
|
||||||
@@ -432,11 +392,6 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isHideMagicTab) {
|
|
||||||
giftIndicator.hidePosition(GiftIndicator.TYPE_MAGIC);
|
|
||||||
} else {
|
|
||||||
giftIndicator.showPosition(GiftIndicator.TYPE_MAGIC);
|
|
||||||
}
|
|
||||||
if (isInRoom) {
|
if (isInRoom) {
|
||||||
giftIndicator.showPosition(GiftIndicator.TYPE_LUCKY);
|
giftIndicator.showPosition(GiftIndicator.TYPE_LUCKY);
|
||||||
} else {
|
} else {
|
||||||
@@ -469,8 +424,6 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
etSendMessage = root.findViewById(R.id.et_gift_message);
|
etSendMessage = root.findViewById(R.id.et_gift_message);
|
||||||
ivOpenNoble.setOnClickListener(this);
|
ivOpenNoble.setOnClickListener(this);
|
||||||
sendContainer = root.findViewById(R.id.send_container);
|
sendContainer = root.findViewById(R.id.send_container);
|
||||||
btnSendMagic = root.findViewById(R.id.btn_sendMagic);
|
|
||||||
btnSendMagic.setOnClickListener(this);
|
|
||||||
layoutEmpty.setVisibility(View.GONE);
|
layoutEmpty.setVisibility(View.GONE);
|
||||||
ivFirstRecharge = root.findViewById(R.id.iv_first_recharge);
|
ivFirstRecharge = root.findViewById(R.id.iv_first_recharge);
|
||||||
tvLuckyBagIntro = root.findViewById(R.id.tv_lucky_bag_intro);
|
tvLuckyBagIntro = root.findViewById(R.id.tv_lucky_bag_intro);
|
||||||
@@ -516,21 +469,6 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
avatarListAdapter.setMicMemberInfos(micMemberInfos);
|
avatarListAdapter.setMicMemberInfos(micMemberInfos);
|
||||||
avatarListAdapter.setOnItemSelectedListener(this);
|
avatarListAdapter.setOnItemSelectedListener(this);
|
||||||
avatarList.setAdapter(avatarListAdapter);
|
avatarList.setAdapter(avatarListAdapter);
|
||||||
|
|
||||||
//添加高亮引导
|
|
||||||
if (TuTuGuideHelper.isNeedHiGuide(TuTuGuideHelper.KEY_GUIDE_GIFT_DIALOG)) {
|
|
||||||
avatarList.post(() -> {
|
|
||||||
if (!ActivityUtil.isValidContext(context)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!GiftDialog.this.isShowing()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TuTuGuideHelper.setNoNeedHiGuide(TuTuGuideHelper.KEY_GUIDE_GIFT_DIALOG);
|
|
||||||
TuTuGuideHelper helper = new TuTuGuideHelper(context, GiftDialog.this);
|
|
||||||
helper.createHiGuide(() -> helper.createGiftDialogOverLayer(avatarList));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
avatarList.setVisibility(View.INVISIBLE);
|
avatarList.setVisibility(View.INVISIBLE);
|
||||||
@@ -547,17 +485,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
etSendMessage.addTextChangedListener(new TextWatcher() {
|
etSendMessage.addTextChangedListener(new TextWatcherWrapper() {
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
if (s.toString().trim().length() > 15) {
|
if (s.toString().trim().length() > 15) {
|
||||||
@@ -568,15 +496,6 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
});
|
});
|
||||||
|
|
||||||
compositeDisposable.add(GiftModel.get().requestKnapGiftInfos().subscribe());
|
compositeDisposable.add(GiftModel.get().requestKnapGiftInfos().subscribe());
|
||||||
radishObserver = info -> {
|
|
||||||
if (info == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
radishWalletInfo = info;
|
|
||||||
setTvGoldText();
|
|
||||||
};
|
|
||||||
RadishWalletManager.get().getLdRadishNumber().observeForever(radishObserver);
|
|
||||||
RadishModel.get().updateRadishWallet().subscribe();
|
|
||||||
if (isInRoom) {
|
if (isInRoom) {
|
||||||
UserModel.get().getCurrentUserInfo()
|
UserModel.get().getCurrentUserInfo()
|
||||||
.compose(RxHelper.bindContext(context))
|
.compose(RxHelper.bindContext(context))
|
||||||
@@ -621,19 +540,6 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
sendGiftButton.setEnabled(false);
|
sendGiftButton.setEnabled(false);
|
||||||
setUpdateTipsText();
|
setUpdateTipsText();
|
||||||
}
|
}
|
||||||
} else if (lastSelectedItem instanceof MagicInfoVm) {
|
|
||||||
MagicInfoVm magicInfoVm = (MagicInfoVm) lastSelectedItem;
|
|
||||||
MagicInfo magicInfo = magicInfoVm.data;
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
switch (magicInfo.getConsumeType()) {
|
|
||||||
case GiftInfo.CONSUME_TYPE_GOLD:
|
|
||||||
setTvGoldText();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// 未匹配的类型,不允许进行交易
|
|
||||||
btnSendMagic.setEnabled(false);
|
|
||||||
setUpdateTipsText();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,37 +564,12 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
tvTextGold.setText(context.getText(R.string.text_need_update));
|
tvTextGold.setText(context.getText(R.string.text_need_update));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMagicView() {
|
|
||||||
btnSendMagic.setVisibility(View.VISIBLE);
|
|
||||||
sendContainer.setVisibility(View.GONE);
|
|
||||||
currentGiftInfo = null;
|
|
||||||
List<GiftInfo> nobleGiftInfos = getNobleGiftInfos();
|
|
||||||
if (ListUtils.isListEmpty(nobleGiftInfos)) {
|
|
||||||
giftIndicator.hidePosition(GiftIndicator.TYPE_NOBLE);
|
|
||||||
} else {
|
|
||||||
giftIndicator.showPosition(GiftIndicator.TYPE_NOBLE);
|
|
||||||
}
|
|
||||||
if (ListUtils.isListEmpty(currentMagicInfoList)) {
|
|
||||||
showEmptyView();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
currentMagicInfo = currentMagicInfoList.get(0);
|
|
||||||
etSendMessage.setVisibility(View.GONE);
|
|
||||||
List<List<IItem>> pagerList = beanTransformVm(context, currentMagicInfoList, false, 8, null);
|
|
||||||
setGridViewData(pagerList);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateGiftView(int position) {
|
private void updateGiftView(int position) {
|
||||||
updateGiftView(position, null);
|
updateGiftView(position, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGiftView(int position, @Nullable GiftInfo selectGiftInfo) {
|
private void updateGiftView(int position, @Nullable GiftInfo selectGiftInfo) {
|
||||||
if (position == GiftIndicator.TYPE_MAGIC) {
|
|
||||||
updateMagicView();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
showDataView();
|
showDataView();
|
||||||
currentMagicInfo = null;
|
|
||||||
// 获得对应的普通礼物/贵族礼物/背包礼物
|
// 获得对应的普通礼物/贵族礼物/背包礼物
|
||||||
List<GiftInfo> nobleGiftInfos = getNobleGiftInfos();
|
List<GiftInfo> nobleGiftInfos = getNobleGiftInfos();
|
||||||
if (position == GiftIndicator.TYPE_KNAP) {
|
if (position == GiftIndicator.TYPE_KNAP) {
|
||||||
@@ -702,6 +583,22 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
currentGiftInfoList = getLuckyGiftInfos();
|
currentGiftInfoList = getLuckyGiftInfos();
|
||||||
} else if (position == GiftIndicator.TYPE_WEEK) {
|
} else if (position == GiftIndicator.TYPE_WEEK) {
|
||||||
currentGiftInfoList = getWeekStarGiftInfos();
|
currentGiftInfoList = getWeekStarGiftInfos();
|
||||||
|
} else if (position == GiftIndicator.TYPE_DRAW_GIFT) {
|
||||||
|
currentGiftInfoList = getNormalGiftInfos();
|
||||||
|
if (drawGiftHelper == null) {
|
||||||
|
drawGiftHelper = new DrawGiftHelper((Activity) context);
|
||||||
|
}
|
||||||
|
drawGiftHelper.lazyDrawGiftView(mContentView.getHeight(), new DrawGiftView.DrawGiftListener() {
|
||||||
|
@Override
|
||||||
|
public void onGiftPainted(DrawGiftView drawGiftView, int giftId) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTouchEventUpWhenDrawDisable(DrawGiftView drawGiftView) {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// 有贵族礼物才显示贵族礼物的tab
|
// 有贵族礼物才显示贵族礼物的tab
|
||||||
if (ListUtils.isListEmpty(nobleGiftInfos)) {
|
if (ListUtils.isListEmpty(nobleGiftInfos)) {
|
||||||
@@ -741,6 +638,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
}
|
}
|
||||||
updateLuckyBagIntro();
|
updateLuckyBagIntro();
|
||||||
updateWeekStarDesc();
|
updateWeekStarDesc();
|
||||||
|
updateDrawGift();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLuckyBagIntro() {
|
private void updateLuckyBagIntro() {
|
||||||
@@ -796,6 +694,16 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateDrawGift() {
|
||||||
|
if (drawGiftHelper == null || currentGiftInfo == null) return;
|
||||||
|
if (giftIndicator.getCurrrentType() == GiftIndicator.TYPE_DRAW_GIFT) {
|
||||||
|
drawGiftHelper.setCurrentGift(currentGiftInfo.getGiftId(), currentGiftInfo.getGiftUrl(), currentGiftInfo.getGoldPrice());
|
||||||
|
drawGiftHelper.setDrawEnable(true);
|
||||||
|
} else {
|
||||||
|
drawGiftHelper.setDrawEnable(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateTotalPrice() {
|
private void updateTotalPrice() {
|
||||||
String diamond = "";
|
String diamond = "";
|
||||||
double totalValue = 0;
|
double totalValue = 0;
|
||||||
@@ -846,7 +754,6 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
etSendMessage.setVisibility(View.GONE);
|
etSendMessage.setVisibility(View.GONE);
|
||||||
tvLuckyBagIntro.setVisibility(View.GONE);
|
tvLuckyBagIntro.setVisibility(View.GONE);
|
||||||
tvGiftValue.setVisibility(View.GONE);
|
tvGiftValue.setVisibility(View.GONE);
|
||||||
btnSendMagic.setVisibility(View.GONE);
|
|
||||||
ivOpenNoble.setVisibility(View.GONE);
|
ivOpenNoble.setVisibility(View.GONE);
|
||||||
llWeekIn.setVisibility(View.GONE);
|
llWeekIn.setVisibility(View.GONE);
|
||||||
llStarWeek.setVisibility(View.GONE);
|
llStarWeek.setVisibility(View.GONE);
|
||||||
@@ -856,7 +763,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
sendContainer.setVisibility(View.VISIBLE);
|
sendContainer.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setGridViewData(List<List<IItem>> pagerList) {
|
private void setGridViewData(List<List<GiftInfoVm>> pagerList) {
|
||||||
if (ListUtils.isListEmpty(pagerList)) {
|
if (ListUtils.isListEmpty(pagerList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -865,10 +772,10 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
int defaultSelectItem = 0;
|
int defaultSelectItem = 0;
|
||||||
wai:
|
wai:
|
||||||
for (int i = 0; i < pagerList.size(); i++) {
|
for (int i = 0; i < pagerList.size(); i++) {
|
||||||
List<IItem> pager = pagerList.get(i);
|
List<GiftInfoVm> pager = pagerList.get(i);
|
||||||
for (int j = 0; j < pager.size(); j++) {
|
for (int j = 0; j < pager.size(); j++) {
|
||||||
IItem iItem = pager.get(j);
|
GiftInfoVm iItem = pager.get(j);
|
||||||
if (iItem instanceof GiftInfoVm && ((GiftInfoVm) iItem).isSelect.get()) {
|
if (iItem != null && iItem.isSelect.get()) {
|
||||||
defaultSelectPage = i;
|
defaultSelectPage = i;
|
||||||
defaultSelectItem = j;
|
defaultSelectItem = j;
|
||||||
break wai;
|
break wai;
|
||||||
@@ -881,8 +788,8 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
|
|
||||||
indicatorView.setVisibility(pagerList.size() > 1 ? View.VISIBLE : View.INVISIBLE);
|
indicatorView.setVisibility(pagerList.size() > 1 ? View.VISIBLE : View.INVISIBLE);
|
||||||
SparseArray<RecyclerView> cacheItemView = new SparseArray<>();
|
SparseArray<RecyclerView> cacheItemView = new SparseArray<>();
|
||||||
LastSelectedItem = pagerList.get(defaultSelectPage).get(defaultSelectItem);
|
lastSelectedItem = pagerList.get(defaultSelectPage).get(defaultSelectItem);
|
||||||
setGoldOrRadishText(LastSelectedItem);
|
setGoldOrRadishText(lastSelectedItem);
|
||||||
gridView.setAdapter(new PagerAdapter() {
|
gridView.setAdapter(new PagerAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -899,52 +806,38 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
@Override
|
@Override
|
||||||
public Object instantiateItem(@NonNull ViewGroup container, int pagePos) {
|
public Object instantiateItem(@NonNull ViewGroup container, int pagePos) {
|
||||||
RecyclerView recyclerView;
|
RecyclerView recyclerView;
|
||||||
MultiTypeAdapter giftAdapter;
|
MultiTypeAdapter<GiftInfoVm> giftAdapter;
|
||||||
if (cacheItemView.get(pagePos) == null) {
|
if (cacheItemView.get(pagePos) == null) {
|
||||||
recyclerView = new RecyclerView(context);
|
recyclerView = new RecyclerView(context);
|
||||||
recyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
recyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
recyclerView.setLayoutManager(new GridLayoutManager(context, 4));
|
recyclerView.setLayoutManager(new GridLayoutManager(context, 4));
|
||||||
giftAdapter = new MultiTypeAdapter(BR.item, true);
|
giftAdapter = new MultiTypeAdapter<>(BR.item, true);
|
||||||
recyclerView.setAdapter(giftAdapter);
|
recyclerView.setAdapter(giftAdapter);
|
||||||
cacheItemView.put(pagePos, recyclerView);
|
cacheItemView.put(pagePos, recyclerView);
|
||||||
} else {
|
} else {
|
||||||
recyclerView = cacheItemView.get(pagePos);
|
recyclerView = cacheItemView.get(pagePos);
|
||||||
giftAdapter = (MultiTypeAdapter) recyclerView.getAdapter();
|
giftAdapter = (MultiTypeAdapter<GiftInfoVm>) recyclerView.getAdapter();
|
||||||
}
|
}
|
||||||
giftAdapter.clearAllItem();
|
giftAdapter.clearAllItem();
|
||||||
giftAdapter.addData(pagerList.get(pagePos));
|
giftAdapter.addData(pagerList.get(pagePos));
|
||||||
|
|
||||||
giftAdapter.setOnItemClickListener(item -> {
|
giftAdapter.setOnItemClickListener(item -> {
|
||||||
if (item instanceof GiftInfoVm) {
|
if (item.data.isSendMsg()) {
|
||||||
GiftInfoVm giftInfoVm = (GiftInfoVm) item;
|
etSendMessage.setVisibility(View.VISIBLE);
|
||||||
if (giftInfoVm.data.isSendMsg()) {
|
} else {
|
||||||
etSendMessage.setVisibility(View.VISIBLE);
|
etSendMessage.setVisibility(View.GONE);
|
||||||
} else {
|
|
||||||
etSendMessage.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
if (LastSelectedItem != null) {
|
|
||||||
if (LastSelectedItem instanceof GiftInfoVm) {
|
|
||||||
((GiftInfoVm) LastSelectedItem).isSelect.set(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
giftInfoVm.isSelect.set(true);
|
|
||||||
LastSelectedItem = item;
|
|
||||||
currentGiftInfo = giftInfoVm.data;
|
|
||||||
} else if (item instanceof MagicInfoVm) {
|
|
||||||
MagicInfoVm magicInfoVm = (MagicInfoVm) item;
|
|
||||||
if (LastSelectedItem != null) {
|
|
||||||
if (LastSelectedItem instanceof MagicInfoVm) {
|
|
||||||
((MagicInfoVm) LastSelectedItem).isSelect.set(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
magicInfoVm.isSelect.set(true);
|
|
||||||
LastSelectedItem = item;
|
|
||||||
currentMagicInfo = magicInfoVm.data;
|
|
||||||
}
|
}
|
||||||
setGoldOrRadishText(LastSelectedItem);
|
if (lastSelectedItem != null) {
|
||||||
|
lastSelectedItem.isSelect.set(false);
|
||||||
|
}
|
||||||
|
item.isSelect.set(true);
|
||||||
|
lastSelectedItem = item;
|
||||||
|
currentGiftInfo = item.data;
|
||||||
|
setGoldOrRadishText(lastSelectedItem);
|
||||||
updateLuckyBagIntro();
|
updateLuckyBagIntro();
|
||||||
updateWeekStarDesc();
|
updateWeekStarDesc();
|
||||||
|
updateDrawGift();
|
||||||
});
|
});
|
||||||
container.addView(recyclerView);
|
container.addView(recyclerView);
|
||||||
return recyclerView;
|
return recyclerView;
|
||||||
@@ -953,7 +846,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
@Override
|
@Override
|
||||||
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||||
RecyclerView recyclerView = cacheItemView.get(position);
|
RecyclerView recyclerView = cacheItemView.get(position);
|
||||||
MultiTypeAdapter adapter = (MultiTypeAdapter) recyclerView.getAdapter();
|
MultiTypeAdapter<GiftInfoVm> adapter = (MultiTypeAdapter) recyclerView.getAdapter();
|
||||||
adapter.getAllItems().clear();
|
adapter.getAllItems().clear();
|
||||||
container.removeView(recyclerView);
|
container.removeView(recyclerView);
|
||||||
}
|
}
|
||||||
@@ -1058,97 +951,6 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
|
|
||||||
dismiss();
|
dismiss();
|
||||||
break;
|
break;
|
||||||
//送魔法
|
|
||||||
case R.id.btn_sendMagic:
|
|
||||||
btnSendMagic.setEnabled(false);
|
|
||||||
btnSendMagic.setText("施法中...");
|
|
||||||
if (!AuthModel.get().isImLogin()) {
|
|
||||||
SingleToastUtil.showToast("网络异常,请重试!");
|
|
||||||
btnSendMagic.setText("施法");
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (currentMagicInfo == null) {
|
|
||||||
btnSendMagic.setText("施法");
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!isInRoom) {
|
|
||||||
if (giftDialogBtnClickListener != null) {
|
|
||||||
giftDialogBtnClickListener.onSendMagicBtnClick(currentMagicInfo, uid,
|
|
||||||
new SenGiftCallback() {
|
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
if (btnSendMagic == null) return;
|
|
||||||
btnSendMagic.setText("施法");
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFail() {
|
|
||||||
if (btnSendMagic == null) return;
|
|
||||||
btnSendMagic.setText("施法");
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!userOnMic && uid > 0) {
|
|
||||||
//用户不在麦上
|
|
||||||
sendSingleMagic(currentMagicInfo, uid, new SenGiftCallback() {
|
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
if (btnSendMagic == null) return;
|
|
||||||
btnSendMagic.setText("施法");
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFail() {
|
|
||||||
if (btnSendMagic == null) return;
|
|
||||||
btnSendMagic.setText("施法");
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//以下是房间内的操作
|
|
||||||
if (avatarListAdapter == null || micMemberInfos.size() == 0) {
|
|
||||||
// Toast.makeText(context, "暂无成员在麦上", Toast.LENGTH_SHORT).show();
|
|
||||||
SingleToastUtil.showToastShort("暂无成员在麦上");
|
|
||||||
btnSendMagic.setText("施法");
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
dismiss();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<MicMemberInfo> selectedMember = avatarListAdapter.getSelectedMember();
|
|
||||||
if (selectedMember == null || ListUtils.isListEmpty(selectedMember)) {
|
|
||||||
// Toast.makeText(context, "请选择要送魔法的人", Toast.LENGTH_SHORT).show();
|
|
||||||
SingleToastUtil.showToastShort("请选择要送魔法的人");
|
|
||||||
btnSendMagic.setText("施法");
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendBatchMagic(currentMagicInfo, 1, selectedMember,
|
|
||||||
avatarListAdapter.getSelectType() == GiftAvatarAdapter.SELECT_TYPE_WHOLE_MIC,
|
|
||||||
new SenGiftCallback() {
|
|
||||||
@Override
|
|
||||||
public void onSuccess() {
|
|
||||||
if (btnSendMagic == null) return;
|
|
||||||
btnSendMagic.setText("施法");
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFail() {
|
|
||||||
if (btnSendMagic == null) return;
|
|
||||||
btnSendMagic.setText("施法");
|
|
||||||
btnSendMagic.setEnabled(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
//送礼物
|
//送礼物
|
||||||
case R.id.btn_send:
|
case R.id.btn_send:
|
||||||
sendGiftButton.setEnabled(false);
|
sendGiftButton.setEnabled(false);
|
||||||
@@ -1167,8 +969,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
}
|
}
|
||||||
String giftMessage = getGiftMessage();
|
String giftMessage = getGiftMessage();
|
||||||
if (Objects.equals(giftMessage, "")) {
|
if (Objects.equals(giftMessage, "")) {
|
||||||
// Toast.makeText(context, "请输入喊话内容", Toast.LENGTH_SHORT).show();
|
SingleToastUtil.showToast("请输入喊话内容");
|
||||||
SingleToastUtil.showToastShort("请输入喊话内容");
|
|
||||||
sendGiftButton.setText("赠送");
|
sendGiftButton.setText("赠送");
|
||||||
sendGiftButton.setEnabled(true);
|
sendGiftButton.setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
@@ -1178,8 +979,14 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
micMemberInfo.setAccount(String.valueOf(uid));
|
micMemberInfo.setAccount(String.valueOf(uid));
|
||||||
targetUids.add(micMemberInfo);
|
targetUids.add(micMemberInfo);
|
||||||
Log.e(TAG, "onClick: indicator type: " + giftIndicator.getCurrrentType());
|
Log.e(TAG, "onClick: indicator type: " + giftIndicator.getCurrrentType());
|
||||||
giftDialogBtnClickListener.onSendGiftBtnClick(currentGiftInfo, targetUids, giftNumber == -1 ? currentGiftInfo.getCount() : giftNumber, giftMessage,
|
giftDialogBtnClickListener.onSendGiftBtnClick(
|
||||||
giftIndicator.getCurrrentType() == GiftIndicator.TYPE_KNAP, false,
|
currentGiftInfo,
|
||||||
|
targetUids,
|
||||||
|
giftNumber == -1 ? currentGiftInfo.getCount() : giftNumber,
|
||||||
|
giftMessage,
|
||||||
|
giftIndicator.getCurrrentType() == GiftIndicator.TYPE_KNAP,
|
||||||
|
false,
|
||||||
|
getDrawFixedArray(),
|
||||||
new SenGiftCallback() {
|
new SenGiftCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
@@ -1204,10 +1011,14 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
micMemberInfo.setAccount(String.valueOf(uid));
|
micMemberInfo.setAccount(String.valueOf(uid));
|
||||||
targetUids.add(micMemberInfo);
|
targetUids.add(micMemberInfo);
|
||||||
Log.e(TAG, "onClick: indicator type: " + giftIndicator.getCurrrentType());
|
Log.e(TAG, "onClick: indicator type: " + giftIndicator.getCurrrentType());
|
||||||
giftDialogBtnClickListener.onSendGiftBtnClick(currentGiftInfo, targetUids,
|
giftDialogBtnClickListener.onSendGiftBtnClick(
|
||||||
giftNumber == -1 ? currentGiftInfo.getCount() : giftNumber, giftMessage,
|
currentGiftInfo,
|
||||||
|
targetUids,
|
||||||
|
giftNumber == -1 ? currentGiftInfo.getCount() : giftNumber,
|
||||||
|
giftMessage,
|
||||||
giftIndicator.getCurrrentType() == GiftIndicator.TYPE_KNAP,
|
giftIndicator.getCurrrentType() == GiftIndicator.TYPE_KNAP,
|
||||||
false,
|
false,
|
||||||
|
getDrawFixedArray(),
|
||||||
new SenGiftCallback() {
|
new SenGiftCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
@@ -1229,15 +1040,19 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
|
|
||||||
if (giftIndicator.getCurrrentType() == GiftIndicator.TYPE_KNAP
|
if (giftIndicator.getCurrrentType() == GiftIndicator.TYPE_KNAP
|
||||||
&& giftNumber * selectedMembers.size() > currentGiftInfo.getCount()) {
|
&& giftNumber * selectedMembers.size() > currentGiftInfo.getCount()) {
|
||||||
// Toast.makeText(context, "礼物数量不足", Toast.LENGTH_SHORT).show();
|
SingleToastUtil.showToast("礼物数量不足");
|
||||||
SingleToastUtil.showToastShort("礼物数量不足");
|
|
||||||
sendGiftButton.setText("赠送");
|
sendGiftButton.setText("赠送");
|
||||||
sendGiftButton.setEnabled(true);
|
sendGiftButton.setEnabled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
giftDialogBtnClickListener.onSendGiftBtnClick(currentGiftInfo, selectedMembers, giftNumber == -1 ? currentGiftInfo.getCount() : giftNumber, giftMessage,
|
giftDialogBtnClickListener.onSendGiftBtnClick(
|
||||||
|
currentGiftInfo,
|
||||||
|
selectedMembers,
|
||||||
|
giftNumber == -1 ? currentGiftInfo.getCount() : giftNumber,
|
||||||
|
giftMessage,
|
||||||
giftIndicator.getCurrrentType() == GiftIndicator.TYPE_KNAP,
|
giftIndicator.getCurrrentType() == GiftIndicator.TYPE_KNAP,
|
||||||
avatarListAdapter.getSelectType() == GiftAvatarAdapter.SELECT_TYPE_WHOLE_MIC,
|
avatarListAdapter.getSelectType() == GiftAvatarAdapter.SELECT_TYPE_WHOLE_MIC,
|
||||||
|
getDrawFixedArray(),
|
||||||
new SenGiftCallback() {
|
new SenGiftCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
@@ -1256,14 +1071,12 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
|
|
||||||
etSendMessage.setText("");
|
etSendMessage.setText("");
|
||||||
} else if (micMemberInfos.size() == 0) {
|
} else if (micMemberInfos.size() == 0) {
|
||||||
// Toast.makeText(context, "暂无成员在麦上", Toast.LENGTH_SHORT).show();
|
SingleToastUtil.showToast("暂无成员在麦上");
|
||||||
SingleToastUtil.showToastShort("暂无成员在麦上");
|
|
||||||
sendGiftButton.setText("赠送");
|
sendGiftButton.setText("赠送");
|
||||||
sendGiftButton.setEnabled(true);
|
sendGiftButton.setEnabled(true);
|
||||||
dismiss();
|
dismiss();
|
||||||
} else {
|
} else {
|
||||||
// Toast.makeText(context, "请选择送礼物的人", Toast.LENGTH_SHORT).show();
|
SingleToastUtil.showToast("请选择送礼物的人");
|
||||||
SingleToastUtil.showToastShort("请选择送礼物的人");
|
|
||||||
sendGiftButton.setText("赠送");
|
sendGiftButton.setText("赠送");
|
||||||
sendGiftButton.setEnabled(true);
|
sendGiftButton.setEnabled(true);
|
||||||
}
|
}
|
||||||
@@ -1385,80 +1198,9 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GiftIndicator.TYPE_MAGIC:
|
|
||||||
//compositeDisposable.add(getMagicData());
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
|
||||||
private void sendBatchMagic(MagicInfo magicInfo, int magicNum, List<MicMemberInfo> micMemberInfos, boolean isWholeMic, SenGiftCallback callback) {
|
|
||||||
List<Long> targetUids = new ArrayList<>();
|
|
||||||
for (MicMemberInfo memberInfo : micMemberInfos) {
|
|
||||||
targetUids.add(Long.parseLong(memberInfo.getAccount()));
|
|
||||||
}
|
|
||||||
MagicModel.get().sendBatchMagic(magicInfo.getMagicId(), magicNum, targetUids, isWholeMic)
|
|
||||||
.subscribe((multiMagicReceivedInfo, throwable) -> {
|
|
||||||
if (multiMagicReceivedInfo != null) {
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onSuccess();
|
|
||||||
}
|
|
||||||
System.out.println("发送成功");
|
|
||||||
} else {
|
|
||||||
if (throwable instanceof BalanceNotEnoughExeption) {
|
|
||||||
needCharge();
|
|
||||||
} else if (throwable instanceof MagicOutOfDateException) {
|
|
||||||
SingleToastUtil.showToast(throwable.getMessage());
|
|
||||||
} else if (throwable instanceof FreezeException) {
|
|
||||||
SingleToastUtil.showToast(throwable.getMessage());
|
|
||||||
} else {
|
|
||||||
throwable.printStackTrace();
|
|
||||||
}
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onFail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
|
||||||
private void sendSingleMagic(MagicInfo magicInfo, long account, SenGiftCallback callback) {
|
|
||||||
MagicModel.get().sendMagic(magicInfo.getMagicId(), account)
|
|
||||||
.subscribe((magicReceivedInfo, throwable) -> {
|
|
||||||
if (magicReceivedInfo != null) {
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onSuccess();
|
|
||||||
}
|
|
||||||
System.out.println("发送成功");
|
|
||||||
} else {
|
|
||||||
if (throwable instanceof BalanceNotEnoughExeption) {
|
|
||||||
needCharge();
|
|
||||||
} else if (throwable instanceof MagicOutOfDateException) {
|
|
||||||
//魔法过期
|
|
||||||
SingleToastUtil.showToast(throwable.getMessage());
|
|
||||||
} else {
|
|
||||||
throwable.printStackTrace();
|
|
||||||
}
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onFail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void needCharge() {
|
|
||||||
new DialogManager(context).showOkCancelDialog("余额不足,是否充值",
|
|
||||||
true, new DialogManager.AbsOkDialogListener() {
|
|
||||||
@Override
|
|
||||||
public void onOk() {
|
|
||||||
StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_NOT_ENOUGH_TO_RECHARGE,
|
|
||||||
"余额不足_去充值:送礼物");
|
|
||||||
ChargeActivity.start(context);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getGiftMessage() {
|
private String getGiftMessage() {
|
||||||
if (currentGiftInfo != null && currentGiftInfo.isSendMsg()) {
|
if (currentGiftInfo != null && currentGiftInfo.isSendMsg()) {
|
||||||
if (etSendMessage.getText().toString().length() == 0) {
|
if (etSendMessage.getText().toString().length() == 0) {
|
||||||
@@ -1487,6 +1229,11 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
0, -UIUtil.dip2px(context, 11));
|
0, -UIUtil.dip2px(context, 11));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private List<HashMap<String, String>> getDrawFixedArray() {
|
||||||
|
return drawGiftHelper == null ? null : drawGiftHelper.getDrawFixedArray();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetachedFromWindow() {
|
public void onDetachedFromWindow() {
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
@@ -1499,9 +1246,6 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
compositeDisposable.dispose();
|
compositeDisposable.dispose();
|
||||||
compositeDisposable = null;
|
compositeDisposable = null;
|
||||||
}
|
}
|
||||||
if (radishObserver != null) {
|
|
||||||
RadishWalletManager.get().getLdRadishNumber().removeObserver(radishObserver);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
@@ -1514,7 +1258,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void onWalletInfoUpdate(UpdateWalletInfoEvent event) {
|
public void onWalletInfoUpdate(UpdateWalletInfoEvent event) {
|
||||||
goldWalletInfo = PayModel.get().getCurrentWalletInfo();
|
goldWalletInfo = PayModel.get().getCurrentWalletInfo();
|
||||||
setGoldOrRadishText(LastSelectedItem);
|
setGoldOrRadishText(lastSelectedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
@@ -1531,16 +1275,12 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
if (ListUtils.isListEmpty(pagerList)) {
|
if (ListUtils.isListEmpty(pagerList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (List<IItem> page : pagerList) {
|
for (List<GiftInfoVm> page : pagerList) {
|
||||||
for (IItem item : page) {
|
for (GiftInfoVm item : page) {
|
||||||
if (!(item instanceof GiftInfoVm)) {
|
if (item.data.getGiftId() == giftId) {
|
||||||
return;
|
int count = item.data.getCount() - sendNum;
|
||||||
}
|
item.data.setCount(Math.max(count, 0));
|
||||||
GiftInfoVm giftInfoVm = (GiftInfoVm) item;
|
item.updateCount();
|
||||||
if (giftInfoVm.data.getGiftId() == giftId) {
|
|
||||||
int count = giftInfoVm.data.getCount() - sendNum;
|
|
||||||
giftInfoVm.data.setCount(count < 0 ? 0 : count);
|
|
||||||
giftInfoVm.updateCount();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1557,6 +1297,14 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
avatarList.smoothScrollToPosition(position);
|
avatarList.smoothScrollToPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dismiss() {
|
||||||
|
super.dismiss();
|
||||||
|
if (drawGiftHelper != null) {
|
||||||
|
drawGiftHelper.onDialogDismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface OnGiftDialogBtnClickListener {
|
public interface OnGiftDialogBtnClickListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1570,16 +1318,15 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
|||||||
* @param isWholeMic
|
* @param isWholeMic
|
||||||
* @param callback
|
* @param callback
|
||||||
*/
|
*/
|
||||||
void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos,
|
void onSendGiftBtnClick(GiftInfo giftInfo,
|
||||||
int number, String msg, boolean isKnap,
|
ArrayList<MicMemberInfo> micMemberInfos,
|
||||||
boolean isWholeMic, SenGiftCallback callback);
|
int number,
|
||||||
|
String msg,
|
||||||
|
boolean isKnap,
|
||||||
|
boolean isWholeMic,
|
||||||
|
List<HashMap<String, String>> drawFixedArray,
|
||||||
|
SenGiftCallback callback);
|
||||||
|
|
||||||
/**
|
|
||||||
* 送魔法
|
|
||||||
*
|
|
||||||
* @param targetUid 被赠送人id
|
|
||||||
*/
|
|
||||||
void onSendMagicBtnClick(MagicInfo magicInfo, long targetUid, SenGiftCallback callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface SenGiftCallback {
|
public interface SenGiftCallback {
|
||||||
|
@@ -0,0 +1,252 @@
|
|||||||
|
package com.yizhuan.erban.ui.widget.drawgift;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
import android.util.SparseArray;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.request.FutureTarget;
|
||||||
|
import com.bumptech.glide.request.target.CustomTarget;
|
||||||
|
import com.bumptech.glide.request.transition.Transition;
|
||||||
|
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
|
||||||
|
import com.netease.nim.uikit.support.glide.GlideApp;
|
||||||
|
import com.yizhuan.erban.R;
|
||||||
|
import com.yizhuan.xchat_android_core.gift.GiftModel;
|
||||||
|
import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DrawGiftHelper {
|
||||||
|
//为了节省内存。通过giftId当做Key来缓存Bitmap(如果你的giftId是String,那么这里要修改成HashMap<String,Bitmap>)
|
||||||
|
//其实这个东西你可以做成单例。我现在没用单例,就需要每次进入直播间都重新缓存
|
||||||
|
private final SparseArray<Bitmap> cacheBitmapByGiftIdMap;
|
||||||
|
private Activity activity;
|
||||||
|
private MyHandler handler;
|
||||||
|
private List<GiftInfo> giftBeanList;
|
||||||
|
//画礼物的背景View(透明的,并不是灰底)
|
||||||
|
private DrawGiftView drawGiftView;
|
||||||
|
//播放礼物动画的层
|
||||||
|
private DrawGiftPlayView playView;
|
||||||
|
//为了预加载,里面存的是adapter的itemView,你可以不用
|
||||||
|
private LinkedList<View> cachedItemViewList = new LinkedList<>();
|
||||||
|
|
||||||
|
private View cachedBottomGiftSheetView;
|
||||||
|
|
||||||
|
public DrawGiftHelper(Activity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
handler = new MyHandler(this);
|
||||||
|
//key是giftId,value是Bitmap。为了不重复生成Bitmap
|
||||||
|
cacheBitmapByGiftIdMap = new SparseArray<Bitmap>();
|
||||||
|
//本地的 giftBeanList,你肯定是需要从缓存里取出来的,至于什么时候刷新,看你们的逻辑
|
||||||
|
giftBeanList = new ArrayList<GiftInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//播放礼物draw动画,insertToFirst = 是否插入到队列前面
|
||||||
|
public void playDrawGift(List<DrawGiftModel> allDrawGiftArray, boolean insertToFirst) {
|
||||||
|
if (playView == null) {
|
||||||
|
playView = new DrawGiftPlayView(activity);
|
||||||
|
playView.setOnDrawAnimationListener(new DrawGiftPlayView.DrawAnimationListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationNodeEnd(DrawGiftPlayView drawGiftPlayView) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationAllOver(DrawGiftPlayView drawGiftPlayView) {
|
||||||
|
//动画放完了,移除掉播放礼物View层。当然这里你也可以不移除,一直保留
|
||||||
|
FrameLayout contentParent = (FrameLayout) activity.getWindow().getDecorView().findViewById(android.R.id.content);
|
||||||
|
contentParent.removeView(drawGiftPlayView);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playView.getParent() == null) {
|
||||||
|
//添加到decorView
|
||||||
|
FrameLayout contentParent = (FrameLayout) activity.getWindow().getDecorView().findViewById(android.R.id.content);
|
||||||
|
playView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
contentParent.addView(playView);
|
||||||
|
}
|
||||||
|
|
||||||
|
playView.addDrawGifts(allDrawGiftArray, insertToFirst);
|
||||||
|
}
|
||||||
|
|
||||||
|
//从缓存里取出bitmap
|
||||||
|
public Bitmap obtainThumbBitmap(int giftId, Bitmap largeBitmap) {
|
||||||
|
Bitmap thumbGiftBitmap = cacheBitmapByGiftIdMap.get(giftId);
|
||||||
|
if (thumbGiftBitmap == null) {
|
||||||
|
int newSize = ScreenUtil.dip2px(20);
|
||||||
|
thumbGiftBitmap = Bitmap.createScaledBitmap(largeBitmap, newSize, newSize, true);
|
||||||
|
cacheBitmapByGiftIdMap.put(giftId, thumbGiftBitmap);
|
||||||
|
}
|
||||||
|
return thumbGiftBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lazyDrawGiftView(int bottomSheetHeight, DrawGiftView.DrawGiftListener onDrawGiftListener) {
|
||||||
|
if (drawGiftView == null) {
|
||||||
|
drawGiftView = new DrawGiftView(activity);
|
||||||
|
drawGiftView.setOnDrawGiftListener(onDrawGiftListener);
|
||||||
|
drawGiftView.showInActivityWindow(activity, bottomSheetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDialogDismiss() {
|
||||||
|
//底部弹框消失
|
||||||
|
//移除掉draw礼物View层。
|
||||||
|
//FrameLayout contentParent = (FrameLayout) getWindow().getDecorView().findViewById(android.R.id.content);
|
||||||
|
|
||||||
|
WindowManager mWindowManager = activity.getWindowManager();
|
||||||
|
mWindowManager.removeView(drawGiftView);
|
||||||
|
//如果不 = null,leakCanary会报内存泄漏,但其实是误报
|
||||||
|
drawGiftView = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//计算需要的金币并setText
|
||||||
|
public void resetNeedPriceDisplay() {
|
||||||
|
float totalPrice = 0;
|
||||||
|
List<DrawGiftModel> allDrawGiftArray = drawGiftView.getAllDrawGiftArray();
|
||||||
|
for (DrawGiftModel giftModel : allDrawGiftArray) {
|
||||||
|
totalPrice += giftModel.getGiftPrice();
|
||||||
|
}
|
||||||
|
// giftSheetBuilder.costCoinTv.setText("消耗金币:"+totalPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
//子线程处理播放礼物的数据
|
||||||
|
public void prepareShowDrawGift(List<HashMap<String, String>> fixedArray, boolean insertToFirst) {
|
||||||
|
//把服务器推送来的"礼物位置json" 和 本地的 giftBeanList 一一对应上,找到礼物的bitmap
|
||||||
|
final List<DrawGiftModel> allDrawGiftArray = new ArrayList<>();
|
||||||
|
|
||||||
|
//经过测试,这个子线程耗时仅为30ms左右(前提是bitmap已经被是从本地取的)
|
||||||
|
Thread thread = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
//本机屏幕宽高
|
||||||
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||||
|
((WindowManager) activity.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))
|
||||||
|
.getDefaultDisplay().getMetrics(displayMetrics);
|
||||||
|
float viewWidth = displayMetrics.widthPixels;
|
||||||
|
float viewHeight = displayMetrics.heightPixels;
|
||||||
|
|
||||||
|
//fixedArray 是服务器推送过来的礼物json
|
||||||
|
for (HashMap<String, String> fixedMap : fixedArray) {
|
||||||
|
//giftBeanList 是手机本地缓存的全部礼物列表
|
||||||
|
//我们要做的就是两个列表相互匹配,根据礼物id,找出礼物的bitmap(通过glide)
|
||||||
|
int giftId = Integer.parseInt(fixedMap.get("giftid"));
|
||||||
|
GiftInfo giftBean = GiftModel.get().findGiftInfoById(giftId);
|
||||||
|
|
||||||
|
|
||||||
|
//将服务器推送来的x,y转成绝对像素坐标
|
||||||
|
DrawGiftModel drawGiftModel = new DrawGiftModel();
|
||||||
|
drawGiftModel.setX(Float.valueOf(fixedMap.get("x")) * viewWidth);
|
||||||
|
drawGiftModel.setY(Float.valueOf(fixedMap.get("y")) * viewHeight);
|
||||||
|
|
||||||
|
Bitmap thumbGiftBitmap = cacheBitmapByGiftIdMap.get(giftId);
|
||||||
|
if (thumbGiftBitmap != null) {
|
||||||
|
//缓存中就有bitmap
|
||||||
|
drawGiftModel.setGiftBitmap(thumbGiftBitmap);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//缓存没有bitmap
|
||||||
|
//从Glide里找出礼物的bitmap
|
||||||
|
FutureTarget<Bitmap> futureBitmap = Glide.with(activity).asBitmap()
|
||||||
|
.load(giftBean.getGiftUrl())
|
||||||
|
.submit();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Bitmap bitmap = futureBitmap.get();
|
||||||
|
thumbGiftBitmap = obtainThumbBitmap(giftId, bitmap);
|
||||||
|
drawGiftModel.setGiftBitmap(thumbGiftBitmap);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
//万一下载失败了,取本地的图片占位
|
||||||
|
Bitmap errorBitmap = BitmapFactory.decodeResource(activity.getResources(), R.drawable.default_cover);
|
||||||
|
drawGiftModel.setGiftBitmap(errorBitmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allDrawGiftArray.add(drawGiftModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
Message message = Message.obtain(handler, 1, insertToFirst ? 1 : 0, 0, allDrawGiftArray);
|
||||||
|
handler.sendMessage(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentGift(int giftId, String giftUrl, float giftPrice) {
|
||||||
|
if (drawGiftView == null) return;
|
||||||
|
GlideApp.with(activity)
|
||||||
|
.asBitmap()
|
||||||
|
.load(giftUrl)
|
||||||
|
.into(new CustomTarget<Bitmap>() {
|
||||||
|
@Override
|
||||||
|
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||||
|
drawGiftView.setCurrentGift(giftId, obtainThumbBitmap(giftId, resource), giftPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//是否可以画
|
||||||
|
public void setDrawEnable(boolean drawEnable) {
|
||||||
|
if (drawGiftView != null) {
|
||||||
|
drawGiftView.setDrawEnable(drawEnable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HashMap<String, String>> getDrawFixedArray() {
|
||||||
|
if (drawGiftView != null) {
|
||||||
|
return drawGiftView.transformGiftArrayFitScreen(activity);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class MyHandler extends Handler {
|
||||||
|
|
||||||
|
private WeakReference<DrawGiftHelper> reference;
|
||||||
|
|
||||||
|
public MyHandler(DrawGiftHelper context) {
|
||||||
|
super(Looper.getMainLooper());
|
||||||
|
reference = new WeakReference<>(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
final DrawGiftHelper activity = (DrawGiftHelper) reference.get();
|
||||||
|
if (activity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (msg.what == 1) {
|
||||||
|
List<DrawGiftModel> allDrawGiftArray = (List<DrawGiftModel>) msg.obj;
|
||||||
|
activity.playDrawGift(allDrawGiftArray, msg.arg1 == 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,67 @@
|
|||||||
|
package com.yizhuan.erban.ui.widget.drawgift;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Matrix;
|
||||||
|
|
||||||
|
public class DrawGiftModel {
|
||||||
|
|
||||||
|
private float x;
|
||||||
|
private float y;
|
||||||
|
private int giftId;
|
||||||
|
private float giftPrice;//礼物价格,为了方便画的过程中,快速的计算出当前一共画了多少钱的礼物,默认0
|
||||||
|
private Bitmap giftBitmap;
|
||||||
|
|
||||||
|
//在收到礼物显示动画的时候,本demo为了体现出礼物放大消失的动画,引入了这个Matrix参数,如果没有放大动画,就不需要这两个
|
||||||
|
private Matrix matrix;
|
||||||
|
|
||||||
|
public float getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(float x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(float y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getgiftId() {
|
||||||
|
return giftId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setgiftId(int giftId) {
|
||||||
|
this.giftId = giftId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap getGiftBitmap() {
|
||||||
|
return giftBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGiftBitmap(Bitmap giftBitmap) {
|
||||||
|
this.giftBitmap = giftBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Matrix getMatrix() {
|
||||||
|
if (matrix == null){
|
||||||
|
matrix = new Matrix();
|
||||||
|
}
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMatrix(Matrix matrix) {
|
||||||
|
this.matrix = matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getGiftPrice() {
|
||||||
|
return giftPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGiftPrice(float giftPrice) {
|
||||||
|
this.giftPrice = giftPrice;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,217 @@
|
|||||||
|
package com.yizhuan.erban.ui.widget.drawgift;
|
||||||
|
|
||||||
|
import android.animation.Animator;
|
||||||
|
import android.animation.ValueAnimator;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DrawGiftPlayView extends View {
|
||||||
|
|
||||||
|
//需要被画上的全部的礼物,采用链表的方式,每次取第0个
|
||||||
|
private LinkedList<List<DrawGiftModel>> allDrawGiftsLinkedList;
|
||||||
|
|
||||||
|
//当前这幅画播放到第几个礼物
|
||||||
|
private int currentGiftShowIndex;
|
||||||
|
|
||||||
|
private DrawAnimationListener onDrawAnimationListener;
|
||||||
|
|
||||||
|
//为了体现最后的消失动画效果,才引入了这个Paint
|
||||||
|
private Paint mPaint;
|
||||||
|
|
||||||
|
private static final int DRAW_ONE_GIFT = 0;
|
||||||
|
|
||||||
|
private Handler mHandler;
|
||||||
|
|
||||||
|
private Handler.Callback mCallback = new Handler.Callback() {
|
||||||
|
@Override
|
||||||
|
public boolean handleMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case DRAW_ONE_GIFT:
|
||||||
|
//画一个礼物
|
||||||
|
currentGiftShowIndex = msg.arg1;
|
||||||
|
invalidate();
|
||||||
|
|
||||||
|
if (currentGiftShowIndex == allDrawGiftsLinkedList.getFirst().size()){
|
||||||
|
//进入这里,说明已经播放完最后一个礼物了
|
||||||
|
//播放扩大动画,然后消失
|
||||||
|
ValueAnimator valueAnimator = ValueAnimator.ofFloat(1, 2);
|
||||||
|
valueAnimator.setDuration(500);
|
||||||
|
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationUpdate(ValueAnimator animation) {
|
||||||
|
float p = (float) animation.getAnimatedValue();
|
||||||
|
//透明效果(所有礼物都做这个动作)
|
||||||
|
mPaint.setAlpha((int)((2.0F - p) * 255));
|
||||||
|
//放大效果(所有礼物都做这个动作)
|
||||||
|
for (DrawGiftModel giftModel : allDrawGiftsLinkedList.getFirst()) {
|
||||||
|
|
||||||
|
giftModel.getMatrix().reset();
|
||||||
|
giftModel.getMatrix().preTranslate(giftModel.getX() - giftModel.getGiftBitmap().getWidth() / 2F, giftModel.getY() - giftModel.getGiftBitmap().getHeight() / 2F);
|
||||||
|
giftModel.getMatrix().postScale((float) (1.0F + (p - 1) * 0.4), (float) (1.0F + (p - 1) * 0.4), giftModel.getX(), giftModel.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
valueAnimator.addListener(new Animator.AnimatorListener(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationStart(Animator animation) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
//放大动画结束
|
||||||
|
mPaint.reset();
|
||||||
|
|
||||||
|
currentGiftShowIndex = 0;
|
||||||
|
allDrawGiftsLinkedList.removeFirst();
|
||||||
|
|
||||||
|
if (onDrawAnimationListener != null) {
|
||||||
|
//当前的这一幅画结束
|
||||||
|
onDrawAnimationListener.onAnimationNodeEnd(DrawGiftPlayView.this);
|
||||||
|
|
||||||
|
if (allDrawGiftsLinkedList.isEmpty()){
|
||||||
|
//所有画全部结束
|
||||||
|
onDrawAnimationListener.onAnimationAllOver(DrawGiftPlayView.this);
|
||||||
|
} else {
|
||||||
|
//还有画没播完,继续画下一幅画
|
||||||
|
//要先清理掉画布上的上一幅画
|
||||||
|
invalidate();
|
||||||
|
|
||||||
|
Message message = Message.obtain();
|
||||||
|
message.arg1 = 0;
|
||||||
|
message.what = DRAW_ONE_GIFT;
|
||||||
|
mHandler.sendMessageDelayed(message, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationCancel(Animator animation) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationRepeat(Animator animation) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
valueAnimator.start();
|
||||||
|
} else {
|
||||||
|
//继续画下一个礼物
|
||||||
|
Message message = Message.obtain();
|
||||||
|
message.arg1 = currentGiftShowIndex + 1;
|
||||||
|
message.what = DRAW_ONE_GIFT;
|
||||||
|
mHandler.sendMessageDelayed(message, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public DrawGiftPlayView(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawGiftPlayView(Context context, AttributeSet attrs) {
|
||||||
|
this(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawGiftPlayView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
mHandler = new Handler(mCallback);
|
||||||
|
allDrawGiftsLinkedList = new LinkedList<List<DrawGiftModel>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
|
||||||
|
int size = allDrawGiftsLinkedList.getFirst().size();
|
||||||
|
for(int i = 0; i <= currentGiftShowIndex && i < size; i++) {
|
||||||
|
DrawGiftModel giftModel = allDrawGiftsLinkedList.getFirst().get(i);
|
||||||
|
canvas.drawBitmap(giftModel.getGiftBitmap(), giftModel.getMatrix(), mPaint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDrawGifts(List<DrawGiftModel> currentDrawGiftArray, boolean insertToFirst){
|
||||||
|
|
||||||
|
//处理每个小bitmap的大小和位置
|
||||||
|
for(int i = 0; i < currentDrawGiftArray.size(); i++) {
|
||||||
|
DrawGiftModel giftModel = currentDrawGiftArray.get(i);
|
||||||
|
|
||||||
|
giftModel.getMatrix().reset();
|
||||||
|
giftModel.getMatrix().postTranslate(giftModel.getX() - giftModel.getGiftBitmap().getWidth() / 2F, giftModel.getY() - giftModel.getGiftBitmap().getHeight() / 2F);
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加到队列
|
||||||
|
if (insertToFirst){
|
||||||
|
if (allDrawGiftsLinkedList.size() > 0){
|
||||||
|
//说明队列里已经有画在draw了。
|
||||||
|
//由于我目前的逻辑是:取first节点,画完了再remove;而不是先remove再设置为全局变量。所以要插入到第1个元素
|
||||||
|
allDrawGiftsLinkedList.add(1, currentDrawGiftArray);
|
||||||
|
} else {
|
||||||
|
//说明当前列表是空的,直接插入到表头
|
||||||
|
allDrawGiftsLinkedList.offerFirst(currentDrawGiftArray);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//插入到表尾
|
||||||
|
allDrawGiftsLinkedList.offerLast(currentDrawGiftArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allDrawGiftsLinkedList.size() == 1){
|
||||||
|
//刚插入完,size==1,说明是刚开始,这时候要开始播放
|
||||||
|
List<DrawGiftModel> firstDrawGiftArray = this.allDrawGiftsLinkedList.getFirst();
|
||||||
|
|
||||||
|
if (firstDrawGiftArray != null){
|
||||||
|
//说明有需要播放的,开始draw
|
||||||
|
Message message = Message.obtain();
|
||||||
|
message.arg1 = 0;
|
||||||
|
message.what = DRAW_ONE_GIFT;
|
||||||
|
mHandler.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttachedToWindow(){
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
mPaint = new Paint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
mHandler.removeCallbacksAndMessages(null);
|
||||||
|
mPaint.reset();
|
||||||
|
currentGiftShowIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnDrawAnimationListener(DrawAnimationListener onDrawAnimationListener) {
|
||||||
|
this.onDrawAnimationListener = onDrawAnimationListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface DrawAnimationListener{
|
||||||
|
//礼物动画全部结束
|
||||||
|
public void onAnimationNodeEnd(DrawGiftPlayView drawGiftPlayView);
|
||||||
|
//礼物动画当前的这一幅画结束
|
||||||
|
public void onAnimationAllOver(DrawGiftPlayView drawGiftPlayView);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,325 @@
|
|||||||
|
package com.yizhuan.erban.ui.widget.drawgift;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.PixelFormat;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import com.yizhuan.erban.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
//手绘礼物的View
|
||||||
|
public class DrawGiftView extends View {
|
||||||
|
|
||||||
|
private final Bitmap placeholderBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.drawgift_placeholder);
|
||||||
|
private final Paint textPaint = new Paint();
|
||||||
|
//当前被画上去的全部的DrawGiftModel
|
||||||
|
private List<DrawGiftModel> allDrawGiftArray;
|
||||||
|
private float mLastX;
|
||||||
|
private float mLastY;
|
||||||
|
//每一笔的最后一个图的index,所以:这个List.size = 一共几笔
|
||||||
|
private List<Integer> strokeFirstPositionArray;
|
||||||
|
private DrawGiftListener onDrawGiftListener;
|
||||||
|
//当前选中的礼物的id和bitmap
|
||||||
|
private int currentGiftId;
|
||||||
|
private Bitmap currentGiftBitmap;
|
||||||
|
private float currentGiftPrice;
|
||||||
|
//连续两个礼物之间的间距(像素),0表示用当前礼物的宽
|
||||||
|
private int drawStrokeInterval;
|
||||||
|
//是否可以画
|
||||||
|
private boolean drawEnable = false;
|
||||||
|
//没画的时候,显示的默认文本
|
||||||
|
private String placeHolderText = "涂鸦模式,绘制你的图案";
|
||||||
|
|
||||||
|
|
||||||
|
public DrawGiftView(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawGiftView(Context context, AttributeSet attrs) {
|
||||||
|
this(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawGiftView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
|
||||||
|
if (!drawEnable) {
|
||||||
|
//因为选了普通礼物,所以当前View不能画
|
||||||
|
//这时候要清空之前画的内容(一定要draw一些东西,只调用invalidate的话无法清空)
|
||||||
|
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allDrawGiftArray.isEmpty()) {
|
||||||
|
float placeHolderViewHeight = 500;
|
||||||
|
canvas.drawBitmap(placeholderBitmap, (getWidth() - placeholderBitmap.getWidth()) / 2f, (getHeight() - placeHolderViewHeight) / 2, null);
|
||||||
|
textPaint.setStyle(Paint.Style.FILL);
|
||||||
|
textPaint.setColor(0xffffffff);
|
||||||
|
textPaint.setStrokeWidth(8);
|
||||||
|
textPaint.setTextSize(42);
|
||||||
|
textPaint.setTextAlign(Paint.Align.CENTER);
|
||||||
|
if (placeHolderText != null) {
|
||||||
|
float baseline = (getHeight() - placeHolderViewHeight) / 2 + 340;
|
||||||
|
canvas.drawText(placeHolderText, getWidth() / 2f, baseline, textPaint);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (DrawGiftModel giftModel : allDrawGiftArray) {
|
||||||
|
canvas.drawBitmap(giftModel.getGiftBitmap(), giftModel.getX() - giftModel.getGiftBitmap().getWidth() / 2f, giftModel.getY() - giftModel.getGiftBitmap().getHeight() / 2f, null);
|
||||||
|
//这里肯定是不能recycle的
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//正常情况下一个View的如果Down事件return false,那么就吃不到后面的move事件了。
|
||||||
|
//但是本View是被windowManager.addView(view) 添加到windowManager层。那么后续的move up都肯定会触发
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
int action = event.getAction();
|
||||||
|
switch (action) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
if (!drawEnable || currentGiftBitmap == null) {
|
||||||
|
//不允许画 || 当前没选中任何礼物
|
||||||
|
return super.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
//点下
|
||||||
|
mLastX = checkIfBelongHorizontalEdge(event.getX());
|
||||||
|
mLastY = checkIfBelongVerticalEdge(event.getY());
|
||||||
|
addDrawGiftModel(mLastX, mLastY, currentGiftBitmap);
|
||||||
|
invalidate();
|
||||||
|
|
||||||
|
//记录这一笔的开头
|
||||||
|
strokeFirstPositionArray.add(allDrawGiftArray.size() - 1);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
if (!drawEnable || currentGiftBitmap == null) {
|
||||||
|
//不允许画 || 当前没选中任何礼物
|
||||||
|
return super.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
float moveX = checkIfBelongHorizontalEdge(event.getX());
|
||||||
|
float moveY = checkIfBelongVerticalEdge(event.getY());
|
||||||
|
|
||||||
|
//距离上一个礼物的移动距离
|
||||||
|
float distance = (float) (Math.pow(moveX - mLastX, 2) + Math.pow(moveY - mLastY, 2));
|
||||||
|
//理应移动多少才需要画新礼物
|
||||||
|
float reference = (float) Math.pow(drawStrokeInterval == 0 ? currentGiftBitmap.getWidth() : drawStrokeInterval, 2);
|
||||||
|
|
||||||
|
if (distance >= reference) {
|
||||||
|
//距离拉开了,应该画新礼物
|
||||||
|
if (moveX >= getLeft() && moveX < getRight() && moveY >= getTop() && moveY < getBottom()) {
|
||||||
|
//看看新礼物是否在View内
|
||||||
|
addDrawGiftModel(moveX, moveY, currentGiftBitmap);
|
||||||
|
mLastX = moveX;
|
||||||
|
mLastY = moveY;
|
||||||
|
invalidate();
|
||||||
|
|
||||||
|
if (onDrawGiftListener != null) {
|
||||||
|
onDrawGiftListener.onGiftPainted(this, currentGiftId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//越界
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
if (!drawEnable && onDrawGiftListener != null) {
|
||||||
|
//不允许画,那么要回调up事件,为了让底部的sheet收起来
|
||||||
|
onDrawGiftListener.onTouchEventUpWhenDrawDisable(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return super.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addDrawGiftModel(float x, float y, Bitmap bitmap) {
|
||||||
|
DrawGiftModel mDIYGiftModel = new DrawGiftModel();
|
||||||
|
mDIYGiftModel.setGiftBitmap(bitmap);
|
||||||
|
mDIYGiftModel.setgiftId(currentGiftId);
|
||||||
|
mDIYGiftModel.setGiftPrice(currentGiftPrice);
|
||||||
|
mDIYGiftModel.setX(x);
|
||||||
|
mDIYGiftModel.setY(y);
|
||||||
|
allDrawGiftArray.add(mDIYGiftModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
//检查是否是屏幕边缘
|
||||||
|
private float checkIfBelongHorizontalEdge(float intrinsicX) {
|
||||||
|
if (intrinsicX > getWidth() - (currentGiftBitmap.getWidth() / 2)) {
|
||||||
|
//超过右边界
|
||||||
|
return getWidth() - (currentGiftBitmap.getWidth() / 2);
|
||||||
|
} else if (intrinsicX < currentGiftBitmap.getWidth() / 2) {
|
||||||
|
//超过左边界
|
||||||
|
return currentGiftBitmap.getWidth() / 2;
|
||||||
|
} else {
|
||||||
|
return intrinsicX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//检查是否是屏幕边缘
|
||||||
|
private float checkIfBelongVerticalEdge(float intrinsicY) {
|
||||||
|
if (intrinsicY > getHeight() - (currentGiftBitmap.getHeight() / 2)) {
|
||||||
|
//超过右边界
|
||||||
|
return getHeight() - (currentGiftBitmap.getHeight() / 2);
|
||||||
|
} else if (intrinsicY < currentGiftBitmap.getHeight() / 2) {
|
||||||
|
//超过左边界
|
||||||
|
return currentGiftBitmap.getHeight() / 2;
|
||||||
|
} else {
|
||||||
|
return intrinsicY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//清空当前画的所有礼物
|
||||||
|
public void removeAll() {
|
||||||
|
strokeFirstPositionArray.clear();
|
||||||
|
allDrawGiftArray.clear();
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
//移除最后一笔
|
||||||
|
public void removeLastStroke() {
|
||||||
|
if (strokeFirstPositionArray.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lastStrokeIndex = strokeFirstPositionArray.get(strokeFirstPositionArray.size() - 1);
|
||||||
|
|
||||||
|
//先从全部礼物里删除最后一笔礼物
|
||||||
|
for (int i = allDrawGiftArray.size() - 1; i >= lastStrokeIndex; i--) {
|
||||||
|
allDrawGiftArray.remove(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//移除最后一笔的记录点
|
||||||
|
strokeFirstPositionArray.remove(strokeFirstPositionArray.size() - 1);
|
||||||
|
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置当前这笔礼物
|
||||||
|
public void setCurrentGift(int giftId, Bitmap giftBitmap, float giftPrice) {
|
||||||
|
this.currentGiftId = giftId;
|
||||||
|
this.currentGiftBitmap = giftBitmap;
|
||||||
|
this.currentGiftPrice = giftPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
//bottomSheetHeight是底部不能画的区域的高度
|
||||||
|
public void showInActivityWindow(Activity activity, int bottomSheetHeight) {
|
||||||
|
WindowManager mWindowManager = activity.getWindowManager();
|
||||||
|
WindowManager.LayoutParams wl = new WindowManager.LayoutParams();
|
||||||
|
|
||||||
|
//用TYPE_APPLICATION 是本View所在的层级,如果太高了(超过了应用)还要申请权限
|
||||||
|
wl.type = WindowManager.LayoutParams.TYPE_APPLICATION;
|
||||||
|
|
||||||
|
//据说这个可以让触摸事件穿透到view层,但是我们的sheet是dialog,所以无用
|
||||||
|
// wl.flags = WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE;
|
||||||
|
|
||||||
|
wl.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||||
|
wl.gravity = Gravity.TOP;//这个top会盖住titleBar,但是盖不住状态栏
|
||||||
|
wl.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||||
|
wl.height = activity.getWindow().getDecorView().findViewById(android.R.id.content).getHeight() - bottomSheetHeight;
|
||||||
|
wl.token = activity.getWindow().getAttributes().token;
|
||||||
|
wl.format = PixelFormat.TRANSLUCENT;//Toast就是用这个实现的透明
|
||||||
|
mWindowManager.addView(this, wl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
allDrawGiftArray = new ArrayList<>();
|
||||||
|
strokeFirstPositionArray = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
allDrawGiftArray.clear();
|
||||||
|
strokeFirstPositionArray.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinishInflate() {
|
||||||
|
super.onFinishInflate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DrawGiftModel> getAllDrawGiftArray() {
|
||||||
|
return allDrawGiftArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
//由于不同手机屏幕尺寸不同,如果礼物画在大屏幕的最右边(X很大)在小屏幕上绘制礼物的时候,X会超出屏幕。因此在这里转成百分比再上传给服务器
|
||||||
|
public List<HashMap<String, String>> transformGiftArrayFitScreen(Context context) {
|
||||||
|
|
||||||
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||||
|
((WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))
|
||||||
|
.getDefaultDisplay().getMetrics(displayMetrics);
|
||||||
|
|
||||||
|
//fixedArray是需要转成json发送给服务器的
|
||||||
|
List<HashMap<String, String>> fixedArray = new ArrayList<>();
|
||||||
|
float viewWidth = displayMetrics.widthPixels;
|
||||||
|
float viewHeight = displayMetrics.heightPixels;
|
||||||
|
HashMap<String, String> param = null;
|
||||||
|
for (DrawGiftModel giftModel : allDrawGiftArray) {
|
||||||
|
//x 和 y转为屏幕比例
|
||||||
|
param = new HashMap<>();
|
||||||
|
param.put("x", String.valueOf(((int) ((giftModel.getX() / viewWidth) * 1000)) / 1000f));
|
||||||
|
param.put("y", String.valueOf(((int) ((giftModel.getY() / viewHeight) * 1000)) / 1000f));
|
||||||
|
param.put("giftid", String.valueOf(giftModel.getgiftId()));
|
||||||
|
fixedArray.add(param);
|
||||||
|
}
|
||||||
|
return fixedArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
//连续两个礼物之间的间距(像素),0表示用当前礼物的宽
|
||||||
|
public void setDrawStrokeInterval(int drawStrokeInterval) {
|
||||||
|
this.drawStrokeInterval = drawStrokeInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
//还没画的时候,提示语
|
||||||
|
public void setPlaceHolderText(String placeHolderText) {
|
||||||
|
this.placeHolderText = placeHolderText;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
//是否可以画
|
||||||
|
public void setDrawEnable(boolean drawEnable) {
|
||||||
|
if (drawEnable != this.drawEnable) {
|
||||||
|
this.drawEnable = drawEnable;
|
||||||
|
if (!drawEnable) {
|
||||||
|
allDrawGiftArray.clear();
|
||||||
|
strokeFirstPositionArray.clear();
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnDrawGiftListener(DrawGiftListener onDrawGiftListener) {
|
||||||
|
this.onDrawGiftListener = onDrawGiftListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface DrawGiftListener {
|
||||||
|
//新的礼物节点被画上
|
||||||
|
public void onGiftPainted(DrawGiftView drawGiftView, int giftId);
|
||||||
|
|
||||||
|
//当drawDisable的情况下,触发的touchUp回调
|
||||||
|
public void onTouchEventUpWhenDrawDisable(DrawGiftView drawGiftView);
|
||||||
|
}
|
||||||
|
}
|
@@ -47,6 +47,9 @@ public class GiftIndicator extends LinearLayout {
|
|||||||
/**周星礼物*/
|
/**周星礼物*/
|
||||||
public static final int TYPE_WEEK = 6;
|
public static final int TYPE_WEEK = 6;
|
||||||
|
|
||||||
|
/**涂鸦礼物*/
|
||||||
|
public static final int TYPE_DRAW_GIFT = 7;
|
||||||
|
|
||||||
private Map<String, String> map = new HashMap<>();
|
private Map<String, String> map = new HashMap<>();
|
||||||
|
|
||||||
public GiftIndicator(Context context, @Nullable AttributeSet attrs) {
|
public GiftIndicator(Context context, @Nullable AttributeSet attrs) {
|
||||||
|
BIN
app/src/main/res/drawable-xhdpi/drawgift_placeholder.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/drawgift_placeholder.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
@@ -452,18 +452,6 @@
|
|||||||
android:textSize="13dp" />
|
android:textSize="13dp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btn_sendMagic"
|
|
||||||
android:layout_width="65dp"
|
|
||||||
android:layout_height="@dimen/dp_30"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_marginEnd="@dimen/dp_15"
|
|
||||||
android:background="@drawable/bg_magic_dialog_button_send"
|
|
||||||
android:text="施法"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="13dp"
|
|
||||||
android:visibility="gone" />
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@@ -1,63 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
|
||||||
|
|
||||||
<data>
|
|
||||||
|
|
||||||
<variable
|
|
||||||
name="item"
|
|
||||||
type="com.yizhuan.erban.ui.gift.dialog.MagicInfoVm" />
|
|
||||||
|
|
||||||
<import type="android.view.View" />
|
|
||||||
</data>
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="108dp"
|
|
||||||
android:gravity="center"
|
|
||||||
tools:layout_width="86dp">
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:id="@+id/view_room_gift_select"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="@drawable/shape_gift_item_select"
|
|
||||||
android:visibility="@{item.isSelect ? View.VISIBLE : View.INVISIBLE}"
|
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/iv_magic_icon"
|
|
||||||
android:layout_width="48dp"
|
|
||||||
android:layout_height="48dp"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
nomalUrl="@{item.data().icon}"
|
|
||||||
android:layout_marginTop="@dimen/dp_12" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_magic_name"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@id/iv_magic_icon"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:layout_marginTop="@dimen/dp_3"
|
|
||||||
android:text="@{item.data().name}"
|
|
||||||
android:textColor="@{item.isSelect ? @color/appColor : @color/white}"
|
|
||||||
android:textSize="@dimen/dp_10"
|
|
||||||
tools:ignore="SpUsage"
|
|
||||||
tools:text="扔鸡蛋" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_magic_gold"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@id/tv_magic_name"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:text="@{item.goldText}"
|
|
||||||
android:textColor="@{item.isSelect ? @color/color_7154EE_transparent_65 : @color/white_transparent_30}"
|
|
||||||
android:textSize="@dimen/dp_10"
|
|
||||||
tools:text="0钻石"
|
|
||||||
tools:ignore="SpUsage" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
</layout>
|
|
@@ -77,6 +77,7 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@@ -183,7 +184,7 @@ public class MWTeamRoomMessageAct extends BaseMessageActivity implements IMWTeam
|
|||||||
new OnGiftDialogBtnClickListenerWrapper() {
|
new OnGiftDialogBtnClickListenerWrapper() {
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
@Override
|
@Override
|
||||||
public void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos, int number, String msg, boolean isKnap, boolean isWholeMic, GiftDialog.SenGiftCallback callback) {
|
public void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos, int number, String msg, boolean isKnap, boolean isWholeMic, List<HashMap<String, String>> drawFixedArray, GiftDialog.SenGiftCallback callback) {
|
||||||
if (giftInfo == null) return;
|
if (giftInfo == null) return;
|
||||||
|
|
||||||
if (mMwChatInfo != null) {
|
if (mMwChatInfo != null) {
|
||||||
|
@@ -89,6 +89,7 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@@ -206,7 +207,7 @@ public class MiniWorldTeamMessageActivity extends BaseMessageActivity implements
|
|||||||
new OnGiftDialogBtnClickListenerWrapper() {
|
new OnGiftDialogBtnClickListenerWrapper() {
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
@Override
|
@Override
|
||||||
public void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos, int number, String msg, boolean isKnap, boolean isWholeMic, GiftDialog.SenGiftCallback callback) {
|
public void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos, int number, String msg, boolean isKnap, boolean isWholeMic, List<HashMap<String, String>> drawFixedArray, GiftDialog.SenGiftCallback callback) {
|
||||||
if (giftInfo == null) return;
|
if (giftInfo == null) return;
|
||||||
|
|
||||||
if (mMwChatInfo != null) {
|
if (mMwChatInfo != null) {
|
||||||
|
@@ -85,6 +85,7 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -303,7 +304,7 @@ public class PublicChatHallMessageFragment extends TFragment implements ModulePr
|
|||||||
new OnGiftDialogBtnClickListenerWrapper() {
|
new OnGiftDialogBtnClickListenerWrapper() {
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
@Override
|
@Override
|
||||||
public void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos, int number, String msg, boolean isKnap, boolean isWholeMic, GiftDialog.SenGiftCallback callback) {
|
public void onSendGiftBtnClick(GiftInfo giftInfo, ArrayList<MicMemberInfo> micMemberInfos, int number, String msg, boolean isKnap, boolean isWholeMic, List<HashMap<String, String>> drawFixedArray, GiftDialog.SenGiftCallback callback) {
|
||||||
if (giftInfo == null) return;
|
if (giftInfo == null) return;
|
||||||
boolean canUseNobleGiftOrNot = GiftModel.get().canUseNobleGiftOrNot(giftInfo);
|
boolean canUseNobleGiftOrNot = GiftModel.get().canUseNobleGiftOrNot(giftInfo);
|
||||||
if (canUseNobleGiftOrNot) {
|
if (canUseNobleGiftOrNot) {
|
||||||
|
@@ -56,6 +56,7 @@ import org.greenrobot.eventbus.EventBus;
|
|||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
@@ -293,6 +294,11 @@ public class GiftModel extends BaseModel implements IGiftModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Single<ServiceResult<GiftMultiReceiverInfo>> sendGift(int giftId, int giftNum, List<Long> targetUids, int sendType, int source, String msg, boolean isKnap, boolean isWholeMic, String chatSessionId) {
|
||||||
|
return sendGift(giftId, giftNum, targetUids, sendType, source, msg, isKnap, isWholeMic, chatSessionId, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Single<ServiceResult<GiftMultiReceiverInfo>> sendGift(int giftId,
|
public Single<ServiceResult<GiftMultiReceiverInfo>> sendGift(int giftId,
|
||||||
int giftNum,
|
int giftNum,
|
||||||
@@ -301,7 +307,9 @@ public class GiftModel extends BaseModel implements IGiftModel {
|
|||||||
int source,
|
int source,
|
||||||
String msg,
|
String msg,
|
||||||
boolean isKnap,
|
boolean isKnap,
|
||||||
boolean isWholeMic, String chatSessionId) {
|
boolean isWholeMic,
|
||||||
|
String chatSessionId,
|
||||||
|
List<HashMap<String, String>> drawFixedArray) {
|
||||||
if (ListUtils.isListEmpty(targetUids)) {
|
if (ListUtils.isListEmpty(targetUids)) {
|
||||||
return Single.error(new Throwable("targetUids is empty"));
|
return Single.error(new Throwable("targetUids is empty"));
|
||||||
}
|
}
|
||||||
@@ -345,7 +353,7 @@ public class GiftModel extends BaseModel implements IGiftModel {
|
|||||||
String targetUidsString = joinTargetUidsToString(targetUids);
|
String targetUidsString = joinTargetUidsToString(targetUids);
|
||||||
String finalRoomUid = roomUid;
|
String finalRoomUid = roomUid;
|
||||||
single = api.sendGift(uid, targetUidsString, roomUid,
|
single = api.sendGift(uid, targetUidsString, roomUid,
|
||||||
giftInfo.getGiftId(), giftNum, msg, sendType, source, chatSessionId)
|
giftInfo.getGiftId(), giftNum, msg, sendType, source, chatSessionId)
|
||||||
.compose(RxHelper.handleSchedulers())
|
.compose(RxHelper.handleSchedulers())
|
||||||
.flatMap((Function<ServiceResult<GiftMultiReceiverInfo>,
|
.flatMap((Function<ServiceResult<GiftMultiReceiverInfo>,
|
||||||
SingleSource<ServiceResult<GiftMultiReceiverInfo>>>) serviceResult -> {
|
SingleSource<ServiceResult<GiftMultiReceiverInfo>>>) serviceResult -> {
|
||||||
@@ -357,6 +365,7 @@ public class GiftModel extends BaseModel implements IGiftModel {
|
|||||||
PayModel.get().minusGold(giftInfo.getGoldPrice() * giftNum * targetUids.size());
|
PayModel.get().minusGold(giftInfo.getGoldPrice() * giftNum * targetUids.size());
|
||||||
}
|
}
|
||||||
GiftMultiReceiverInfo giftMultiReceiverInfo = serviceResult.getData();
|
GiftMultiReceiverInfo giftMultiReceiverInfo = serviceResult.getData();
|
||||||
|
giftMultiReceiverInfo.setDrawFixedArray(drawFixedArray);
|
||||||
if (giftId != giftMultiReceiverInfo.getGiftId()) {
|
if (giftId != giftMultiReceiverInfo.getGiftId()) {
|
||||||
return Single.error(RxHelper.createThrowable(serviceResult));
|
return Single.error(RxHelper.createThrowable(serviceResult));
|
||||||
}
|
}
|
||||||
@@ -396,10 +405,9 @@ public class GiftModel extends BaseModel implements IGiftModel {
|
|||||||
if (serviceResult.getCode() == BalanceNotEnoughExeption.code) {
|
if (serviceResult.getCode() == BalanceNotEnoughExeption.code) {
|
||||||
IMNetEaseManager.get().getChatRoomEventObservable().onNext(new RoomEvent().setEvent(RoomEvent.RECHARGE));
|
IMNetEaseManager.get().getChatRoomEventObservable().onNext(new RoomEvent().setEvent(RoomEvent.RECHARGE));
|
||||||
return Single.error(new BalanceNotEnoughExeption(serviceResult.getMessage()));
|
return Single.error(new BalanceNotEnoughExeption(serviceResult.getMessage()));
|
||||||
}
|
} else if (serviceResult.getCode() == VipLevelNotEnoughException.code) {
|
||||||
else if (serviceResult.getCode() == VipLevelNotEnoughException.code) {
|
|
||||||
return Single.error(new VipLevelNotEnoughException(serviceResult.getMessage()));
|
return Single.error(new VipLevelNotEnoughException(serviceResult.getMessage()));
|
||||||
}else if (RadishNotEnoughException.code == serviceResult.getCode()) {
|
} else if (RadishNotEnoughException.code == serviceResult.getCode()) {
|
||||||
//萝卜不足
|
//萝卜不足
|
||||||
IMNetEaseManager.get().getChatRoomEventObservable().onNext(
|
IMNetEaseManager.get().getChatRoomEventObservable().onNext(
|
||||||
new RoomEvent().setEvent(RoomEvent.RADISH_NOT_ENOUGH));
|
new RoomEvent().setEvent(RoomEvent.RADISH_NOT_ENOUGH));
|
||||||
@@ -445,12 +453,25 @@ public class GiftModel extends BaseModel implements IGiftModel {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Single<ServiceResult<GiftMultiReceiverInfo>> sendRoomGift(int giftId, List<Long> targetUids,
|
public Single<ServiceResult<GiftMultiReceiverInfo>> sendRoomGift(int giftId,
|
||||||
final int giftNum, String msg, boolean isKnap,
|
List<Long> targetUids,
|
||||||
boolean isWholeMic) {
|
final int giftNum,
|
||||||
|
String msg,
|
||||||
|
boolean isKnap,
|
||||||
|
boolean isWholeMic,
|
||||||
|
List<HashMap<String, String>> drawFixedArray) {
|
||||||
Log.e("GiftDialog", "sendRoomGift() called with: giftId = [" + giftId + "], targetUids = [" + targetUids + "], giftNum = [" + giftNum + "], msg = [" + msg + "], isKnap = [" + isKnap + "], isWholeMic = [" + isWholeMic + "]");
|
Log.e("GiftDialog", "sendRoomGift() called with: giftId = [" + giftId + "], targetUids = [" + targetUids + "], giftNum = [" + giftNum + "], msg = [" + msg + "], isKnap = [" + isKnap + "], isWholeMic = [" + isWholeMic + "]");
|
||||||
return sendGift(giftId, giftNum, targetUids, GiftSendType.TYPE_MIC,
|
return sendGift(
|
||||||
isKnap ? GiftSource.BACKPACK : GiftSource.COMMON, msg, isKnap, isWholeMic, null);
|
giftId,
|
||||||
|
giftNum,
|
||||||
|
targetUids,
|
||||||
|
GiftSendType.TYPE_MIC,
|
||||||
|
isKnap ? GiftSource.BACKPACK : GiftSource.COMMON,
|
||||||
|
msg,
|
||||||
|
isKnap,
|
||||||
|
isWholeMic,
|
||||||
|
null,
|
||||||
|
drawFixedArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -577,14 +598,14 @@ public class GiftModel extends BaseModel implements IGiftModel {
|
|||||||
@Override
|
@Override
|
||||||
public Single<ServiceResult<GiftMultiReceiverInfo>> sendFansTeamGift(int giftId, String targetUid) {
|
public Single<ServiceResult<GiftMultiReceiverInfo>> sendFansTeamGift(int giftId, String targetUid) {
|
||||||
return api.sendJoinFansGift(AuthModel.get().getCurrentUid(),
|
return api.sendJoinFansGift(AuthModel.get().getCurrentUid(),
|
||||||
targetUid,
|
targetUid,
|
||||||
String.valueOf(AvRoomDataManager.get().getRoomUid()),
|
String.valueOf(AvRoomDataManager.get().getRoomUid()),
|
||||||
giftId,
|
giftId,
|
||||||
1,
|
1,
|
||||||
"",
|
"",
|
||||||
GiftSendType.TYPE_ANCHOR,
|
GiftSendType.TYPE_ANCHOR,
|
||||||
GiftSource.COMMON,
|
GiftSource.COMMON,
|
||||||
null)
|
null)
|
||||||
.compose(RxHelper.handleSchAndExce());
|
.compose(RxHelper.handleSchAndExce());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
|
|||||||
import com.yizhuan.xchat_android_core.gift.bean.GiftListInfo;
|
import com.yizhuan.xchat_android_core.gift.bean.GiftListInfo;
|
||||||
import com.yizhuan.xchat_android_core.gift.bean.GiftMultiReceiverInfo;
|
import com.yizhuan.xchat_android_core.gift.bean.GiftMultiReceiverInfo;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
@@ -79,6 +80,17 @@ public interface IGiftModel {
|
|||||||
boolean isKnap,
|
boolean isKnap,
|
||||||
boolean isWholeMic, String chatSessionId);
|
boolean isWholeMic, String chatSessionId);
|
||||||
|
|
||||||
|
Single<ServiceResult<GiftMultiReceiverInfo>> sendGift(int giftId,
|
||||||
|
int giftNum,
|
||||||
|
List<Long> targetUids,
|
||||||
|
int sendType,
|
||||||
|
int source,
|
||||||
|
String msg,
|
||||||
|
boolean isKnap,
|
||||||
|
boolean isWholeMic,
|
||||||
|
String chatSessionId,
|
||||||
|
List<HashMap<String, String>> drawFixedArray);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 房间内发送礼物
|
* 房间内发送礼物
|
||||||
*
|
*
|
||||||
@@ -93,7 +105,8 @@ public interface IGiftModel {
|
|||||||
int giftNum,
|
int giftNum,
|
||||||
String msg,
|
String msg,
|
||||||
boolean isKnap,
|
boolean isKnap,
|
||||||
boolean isWholeMic);
|
boolean isWholeMic,
|
||||||
|
List<HashMap<String, String>> drawFixedArray);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在单聊界面送礼物
|
* 在单聊界面送礼物
|
||||||
|
@@ -90,4 +90,6 @@ public class GiftInfo implements Serializable {
|
|||||||
|
|
||||||
private SimpleUserInfo firstCharmRankUser;
|
private SimpleUserInfo firstCharmRankUser;
|
||||||
|
|
||||||
|
private boolean drawGift;
|
||||||
|
|
||||||
}
|
}
|
@@ -3,6 +3,7 @@ package com.yizhuan.xchat_android_core.gift.bean;
|
|||||||
import com.yizhuan.xchat_android_core.room.giftvalue.bean.IndexGiftValue;
|
import com.yizhuan.xchat_android_core.room.giftvalue.bean.IndexGiftValue;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -26,4 +27,5 @@ public class GiftMultiReceiverInfo implements Serializable {
|
|||||||
private List<LuckyBagGifts> luckyBagGifts;
|
private List<LuckyBagGifts> luckyBagGifts;
|
||||||
private List<Long> targetUids;
|
private List<Long> targetUids;
|
||||||
private LuckyGiftList luckyGiftList;
|
private LuckyGiftList luckyGiftList;
|
||||||
|
private List<HashMap<String, String>> drawFixedArray;
|
||||||
}
|
}
|
||||||
|
@@ -29,5 +29,6 @@ public class GiftReceiveInfo implements Serializable {
|
|||||||
//礼物值
|
//礼物值
|
||||||
private List<IndexGiftValue> giftValueVos;
|
private List<IndexGiftValue> giftValueVos;
|
||||||
private long currentTime;
|
private long currentTime;
|
||||||
|
private List<HashMap<String, String>> drawFixedArray;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -105,6 +105,7 @@ public class GiftToolbox {
|
|||||||
giftReceiveInfo.setDisplayGift(giftMultiReceiverInfo.getDisplayGift());
|
giftReceiveInfo.setDisplayGift(giftMultiReceiverInfo.getDisplayGift());
|
||||||
giftReceiveInfo.setGiftValueVos(giftMultiReceiverInfo.getGiftValueVos());
|
giftReceiveInfo.setGiftValueVos(giftMultiReceiverInfo.getGiftValueVos());
|
||||||
giftReceiveInfo.setCurrentTime(giftMultiReceiverInfo.getCurrentTime());
|
giftReceiveInfo.setCurrentTime(giftMultiReceiverInfo.getCurrentTime());
|
||||||
|
giftReceiveInfo.setDrawFixedArray(giftMultiReceiverInfo.getDrawFixedArray());
|
||||||
|
|
||||||
return giftReceiveInfo;
|
return giftReceiveInfo;
|
||||||
}
|
}
|
||||||
|
@@ -5,12 +5,14 @@ import android.text.TextUtils;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.TypeReference;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
|
import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
|
||||||
import com.yizhuan.xchat_android_core.gift.bean.GiftReceiveInfo;
|
import com.yizhuan.xchat_android_core.gift.bean.GiftReceiveInfo;
|
||||||
import com.yizhuan.xchat_android_core.room.giftvalue.bean.IndexGiftValue;
|
import com.yizhuan.xchat_android_core.room.giftvalue.bean.IndexGiftValue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,6 +24,10 @@ public class GiftAttachment extends CustomAttachment {
|
|||||||
private GiftReceiveInfo giftReceiveInfo;
|
private GiftReceiveInfo giftReceiveInfo;
|
||||||
private String uid;
|
private String uid;
|
||||||
|
|
||||||
|
public GiftAttachment(int first, int second) {
|
||||||
|
super(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
public String getUid() {
|
public String getUid() {
|
||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
@@ -30,11 +36,6 @@ public class GiftAttachment extends CustomAttachment {
|
|||||||
this.uid = uid;
|
this.uid = uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GiftAttachment(int first, int second) {
|
|
||||||
super(first, second);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public GiftReceiveInfo getGiftReceiveInfo() {
|
public GiftReceiveInfo getGiftReceiveInfo() {
|
||||||
return giftReceiveInfo;
|
return giftReceiveInfo;
|
||||||
}
|
}
|
||||||
@@ -78,6 +79,10 @@ public class GiftAttachment extends CustomAttachment {
|
|||||||
giftReceiveInfo.setGiftValueVos(giftValueVos);
|
giftReceiveInfo.setGiftValueVos(giftValueVos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (data.containsKey("drawFixedArray")) {
|
||||||
|
giftReceiveInfo.setDrawFixedArray(data.getObject("drawFixedArray", new TypeReference<List<HashMap<String, String>>>() {
|
||||||
|
}.getType()));
|
||||||
|
}
|
||||||
giftReceiveInfo.setCurrentTime(data.getLong("currentTime"));
|
giftReceiveInfo.setCurrentTime(data.getLong("currentTime"));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -98,6 +103,9 @@ public class GiftAttachment extends CustomAttachment {
|
|||||||
object.put("giftValueVos", giftReceiveInfo.getGiftValueVos());
|
object.put("giftValueVos", giftReceiveInfo.getGiftValueVos());
|
||||||
}
|
}
|
||||||
object.put("currentTime", giftReceiveInfo.getCurrentTime());
|
object.put("currentTime", giftReceiveInfo.getCurrentTime());
|
||||||
|
if (giftReceiveInfo.getDrawFixedArray() != null) {
|
||||||
|
object.put("drawFixedArray", giftReceiveInfo.getDrawFixedArray());
|
||||||
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,9 @@ package com.yizhuan.xchat_android_library.bindinglist;
|
|||||||
|
|
||||||
import androidx.databinding.ObservableArrayList;
|
import androidx.databinding.ObservableArrayList;
|
||||||
import androidx.databinding.ObservableList;
|
import androidx.databinding.ObservableList;
|
||||||
|
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
@@ -16,47 +18,31 @@ import java.util.List;
|
|||||||
* Created by lvzebiao on 2018/10/23.
|
* Created by lvzebiao on 2018/10/23.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
public class MultiTypeAdapter<T extends IItem> extends RecyclerView.Adapter<ItemViewHolder> {
|
||||||
|
|
||||||
private List<IItem> headersItems = new ArrayList<>();
|
private final WeakReferenceOnListChangedCallback<T> callback = new WeakReferenceOnListChangedCallback<>(this);
|
||||||
|
private List<T> headersItems = new ArrayList<>();
|
||||||
public List<IItem> getHeadersItems() {
|
private ObservableList<T> footersItems = new ObservableArrayList<>();
|
||||||
return headersItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ObservableList<IItem> footersItems = new ObservableArrayList<>();
|
|
||||||
/**
|
/**
|
||||||
* 此数据源表示真正的数据, 保留用于其他逻辑计算
|
* 此数据源表示真正的数据, 保留用于其他逻辑计算
|
||||||
*/
|
*/
|
||||||
private List<IItem> dataItems;
|
private List<T> dataItems;
|
||||||
|
|
||||||
public List<IItem> getData() {
|
|
||||||
return dataItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 此list表示RecyclerView显示的所有item,即header+data+footer
|
* 此list表示RecyclerView显示的所有item,即header+data+footer
|
||||||
*/
|
*/
|
||||||
private ObservableList<IItem> allItems = new ObservableArrayList<>();
|
private ObservableList<T> allItems = new ObservableArrayList<>();
|
||||||
|
|
||||||
public List<IItem> getAllItems() {
|
|
||||||
return allItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canLoadMore = false;
|
private boolean canLoadMore = false;
|
||||||
|
|
||||||
public void setCanLoadMore(boolean canLoadMore) {
|
|
||||||
this.canLoadMore = canLoadMore;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
|
|
||||||
private final WeakReferenceOnListChangedCallback callback = new WeakReferenceOnListChangedCallback(this);
|
|
||||||
|
|
||||||
private int variableId;
|
private int variableId;
|
||||||
private boolean needItemClick;
|
private boolean needItemClick;
|
||||||
|
private T loadMoreItem;
|
||||||
|
private List<T> statusList = new ArrayList<>();
|
||||||
|
private T startLoadingItem;
|
||||||
|
private T netErrorItem;
|
||||||
|
private T emptyItem;
|
||||||
|
private OnItemClickListener<T> listener;
|
||||||
|
|
||||||
public MultiTypeAdapter(List<IItem> list, int variableId, boolean needItemClick) {
|
public MultiTypeAdapter(List<T> list, int variableId, boolean needItemClick) {
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new ObservableArrayList<>();
|
list = new ObservableArrayList<>();
|
||||||
}
|
}
|
||||||
@@ -74,6 +60,28 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
this(null, variableId, false);
|
this(null, variableId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ensureChangeOnMainThread() {
|
||||||
|
if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
|
||||||
|
throw new IllegalStateException("You must only modify the ObservableList on the main thread.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> getHeadersItems() {
|
||||||
|
return headersItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> getData() {
|
||||||
|
return dataItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> getAllItems() {
|
||||||
|
return allItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCanLoadMore(boolean canLoadMore) {
|
||||||
|
this.canLoadMore = canLoadMore;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 这方法不会清除header,清除header调用
|
* 这方法不会清除header,清除header调用
|
||||||
* {@link #clearAllItem()}
|
* {@link #clearAllItem()}
|
||||||
@@ -87,7 +95,7 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
if (headersItems.size() == 0) {
|
if (headersItems.size() == 0) {
|
||||||
allItems.clear();
|
allItems.clear();
|
||||||
} else {
|
} else {
|
||||||
// List<IItem> tempList = new ArrayList<>();
|
// List<T> tempList = new ArrayList<>();
|
||||||
// for (int i = headersItems.size(); i < allItems.size(); i++) {
|
// for (int i = headersItems.size(); i < allItems.size(); i++) {
|
||||||
// tempList.add(allItems.get(i));
|
// tempList.add(allItems.get(i));
|
||||||
// }
|
// }
|
||||||
@@ -110,7 +118,7 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
allItems.clear();
|
allItems.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addData(List<IItem> list) {
|
public void addData(List<T> list) {
|
||||||
dataItems.addAll(list);
|
dataItems.addAll(list);
|
||||||
int insertPos = allItems.size() - footersItems.size();
|
int insertPos = allItems.size() - footersItems.size();
|
||||||
if (insertPos < 0) {
|
if (insertPos < 0) {
|
||||||
@@ -119,14 +127,12 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
allItems.addAll(insertPos, list);
|
allItems.addAll(insertPos, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addHeaderItem(IItem headerItem) {
|
public void addHeaderItem(T headerItem) {
|
||||||
headersItems.add(headerItem);
|
headersItems.add(headerItem);
|
||||||
allItems.add(0, headerItem);
|
allItems.add(0, headerItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IItem loadMoreItem;
|
public void setLoadMoreView(T item) {
|
||||||
|
|
||||||
public void setLoadMoreView(IItem item) {
|
|
||||||
if (!canLoadMore || item == null) {
|
if (!canLoadMore || item == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -151,14 +157,11 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<IItem> statusList = new ArrayList<>();
|
|
||||||
private IItem startLoadingItem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 此方法并不是所有list都需要,不需要则传null
|
* 此方法并不是所有list都需要,不需要则传null
|
||||||
* 只是客户端有个加载动画,所以添加
|
* 只是客户端有个加载动画,所以添加
|
||||||
*/
|
*/
|
||||||
public void startLoading(IItem item) {
|
public void startLoading(T item) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -171,12 +174,10 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IItem netErrorItem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果有数据不添加错误item
|
* 如果有数据不添加错误item
|
||||||
*/
|
*/
|
||||||
public void setNetError(IItem item) {
|
public void setNetError(T item) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -195,9 +196,7 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IItem emptyItem;
|
public void setEmpty(T item) {
|
||||||
|
|
||||||
public void setEmpty(IItem item) {
|
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -221,24 +220,22 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
|
|
||||||
public void hideStatus() {
|
public void hideStatus() {
|
||||||
statusList.clear();
|
statusList.clear();
|
||||||
if (startLoadingItem != null && allItems.contains(startLoadingItem)) {
|
if (startLoadingItem != null) {
|
||||||
allItems.remove(startLoadingItem);
|
allItems.remove(startLoadingItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (netErrorItem != null && allItems.contains(netErrorItem)) {
|
if (netErrorItem != null) {
|
||||||
allItems.remove(netErrorItem);
|
allItems.remove(netErrorItem);
|
||||||
}
|
}
|
||||||
if (emptyItem != null && allItems.contains(emptyItem)) {
|
if (emptyItem != null) {
|
||||||
allItems.remove(emptyItem);
|
allItems.remove(emptyItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void clearLoarMoreView() {
|
public void clearLoarMoreView() {
|
||||||
footersItems.clear();
|
footersItems.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
return allItems.get(position).getType();
|
return allItems.get(position).getType();
|
||||||
@@ -252,7 +249,7 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
|
||||||
final IItem item = getIndexItem(position);
|
final T item = getIndexItem(position);
|
||||||
holder.bindTo(variableId, item);
|
holder.bindTo(variableId, item);
|
||||||
if (needItemClick) {
|
if (needItemClick) {
|
||||||
holder.binding.getRoot().setOnClickListener(v -> {
|
holder.binding.getRoot().setOnClickListener(v -> {
|
||||||
@@ -268,7 +265,7 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
return allItems.size();
|
return allItems.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IItem getIndexItem(int position) {
|
public T getIndexItem(int position) {
|
||||||
return allItems.get(position);
|
return allItems.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,16 +277,10 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
this.recyclerView = recyclerView;
|
this.recyclerView = recyclerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnItemClickListener listener;
|
public void setOnItemClickListener(OnItemClickListener<T> listener) {
|
||||||
|
|
||||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnItemClickListener {
|
|
||||||
void onClick(IItem item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
|
public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||||
if (this.recyclerView != null && allItems != null) {
|
if (this.recyclerView != null && allItems != null) {
|
||||||
@@ -298,16 +289,20 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
this.recyclerView = null;
|
this.recyclerView = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class WeakReferenceOnListChangedCallback extends ObservableList.OnListChangedCallback<ObservableList<IItem>> {
|
public interface OnItemClickListener<T extends IItem> {
|
||||||
final WeakReference<MultiTypeAdapter> adapterRef;
|
void onClick(T item);
|
||||||
|
}
|
||||||
|
|
||||||
WeakReferenceOnListChangedCallback(MultiTypeAdapter adapter) {
|
private static class WeakReferenceOnListChangedCallback<T extends IItem> extends ObservableList.OnListChangedCallback<ObservableList<T>> {
|
||||||
|
final WeakReference<MultiTypeAdapter<T>> adapterRef;
|
||||||
|
|
||||||
|
WeakReferenceOnListChangedCallback(MultiTypeAdapter<T> adapter) {
|
||||||
this.adapterRef = new WeakReference<>(adapter);
|
this.adapterRef = new WeakReference<>(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(ObservableList sender) {
|
public void onChanged(ObservableList sender) {
|
||||||
MultiTypeAdapter adapter = adapterRef.get();
|
MultiTypeAdapter<T> adapter = adapterRef.get();
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -317,7 +312,7 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemRangeChanged(ObservableList sender, final int positionStart, final int itemCount) {
|
public void onItemRangeChanged(ObservableList sender, final int positionStart, final int itemCount) {
|
||||||
MultiTypeAdapter adapter = adapterRef.get();
|
MultiTypeAdapter<T> adapter = adapterRef.get();
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -327,7 +322,7 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemRangeInserted(ObservableList sender, final int positionStart, final int itemCount) {
|
public void onItemRangeInserted(ObservableList sender, final int positionStart, final int itemCount) {
|
||||||
MultiTypeAdapter adapter = adapterRef.get();
|
MultiTypeAdapter<T> adapter = adapterRef.get();
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -337,7 +332,7 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemRangeMoved(ObservableList sender, final int fromPosition, final int toPosition, final int itemCount) {
|
public void onItemRangeMoved(ObservableList sender, final int fromPosition, final int toPosition, final int itemCount) {
|
||||||
MultiTypeAdapter adapter = adapterRef.get();
|
MultiTypeAdapter<T> adapter = adapterRef.get();
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -349,7 +344,7 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemRangeRemoved(ObservableList sender, final int positionStart, final int itemCount) {
|
public void onItemRangeRemoved(ObservableList sender, final int positionStart, final int itemCount) {
|
||||||
MultiTypeAdapter adapter = adapterRef.get();
|
MultiTypeAdapter<T> adapter = adapterRef.get();
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -357,10 +352,4 @@ public class MultiTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||||||
adapter.notifyItemRangeRemoved(positionStart, itemCount);
|
adapter.notifyItemRangeRemoved(positionStart, itemCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ensureChangeOnMainThread() {
|
|
||||||
if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
|
|
||||||
throw new IllegalStateException("You must only modify the ObservableList on the main thread.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user