新增H5进入房间打开礼物面板方法

This commit is contained in:
huangjian
2022-08-02 11:09:41 +08:00
parent 37a09ae941
commit 4ca1b0c980
5 changed files with 146 additions and 33 deletions

View File

@@ -106,6 +106,7 @@ import com.yizhuan.xchat_android_core.patriarch.event.PmDismissAllLimitDialogEve
import com.yizhuan.xchat_android_core.patriarch.exception.PmRoomLimitException; import com.yizhuan.xchat_android_core.patriarch.exception.PmRoomLimitException;
import com.yizhuan.xchat_android_core.redpackage.RedPackageModel; import com.yizhuan.xchat_android_core.redpackage.RedPackageModel;
import com.yizhuan.xchat_android_core.redpackage.RedPackageNotifyInfo; import com.yizhuan.xchat_android_core.redpackage.RedPackageNotifyInfo;
import com.yizhuan.xchat_android_core.room.anotherroompk.ShowGiftDialogEvent;
import com.yizhuan.xchat_android_core.room.bean.RoomInfo; import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
import com.yizhuan.xchat_android_core.room.bean.RoomModeType; import com.yizhuan.xchat_android_core.room.bean.RoomModeType;
import com.yizhuan.xchat_android_core.room.dragonball.DragonBallModel; import com.yizhuan.xchat_android_core.room.dragonball.DragonBallModel;
@@ -166,6 +167,7 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
private int fromType = FROM_TYPE_NORMAL;// 入口类型 0 其他 1 推荐 2 个人主页或者广场 private int fromType = FROM_TYPE_NORMAL;// 入口类型 0 其他 1 推荐 2 个人主页或者广场
private String fromNick = "";// 从萌圈进入时 需要传入作品发布者的昵称 private String fromNick = "";// 从萌圈进入时 需要传入作品发布者的昵称
private String fromUid = ""; private String fromUid = "";
private int giftId;
private RelativeLayout finishLayout; private RelativeLayout finishLayout;
private ViewStub mVsRoomOffline; private ViewStub mVsRoomOffline;
private ImageView avatarBg; private ImageView avatarBg;
@@ -199,15 +201,20 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
} }
public static void start(Context context, long roomUid, int fromType, String fromNick, @Nullable RedPackageNotifyInfo notifyInfo) { public static void start(Context context, long roomUid, int fromType, String fromNick, @Nullable RedPackageNotifyInfo notifyInfo) {
startForFromType(context, roomUid, fromType, fromNick, null, notifyInfo); startForFromType(context, roomUid, fromType, fromNick, null, notifyInfo, 0);
} }
public static void startForFromType(Context context, long roomUid, int fromType) { public static void startForFromType(Context context, long roomUid, int fromType) {
startForFromType(context, roomUid, fromType, null, null); startForFromType(context, roomUid, fromType, null, null);
} }
public static void startForFromGiftId(Context context, long roomUid, int giftId) {
startForFromType(context, roomUid, FROM_TYPE_NORMAL, null, null, null, giftId);
}
public static void startForFromType(Context context, long roomUid, int fromType, @Nullable String fromNick, @Nullable String fromUid) { public static void startForFromType(Context context, long roomUid, int fromType, @Nullable String fromNick, @Nullable String fromUid) {
startForFromType(context, roomUid, fromType, fromNick, fromUid, null); startForFromType(context, roomUid, fromType, fromNick, fromUid, null, 0);
} }
/** /**
@@ -225,7 +232,13 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_INTO_ROOM_CLICK, "进入房间"); StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_INTO_ROOM_CLICK, "进入房间");
} }
public static void startForFromType(Context context, long roomUid, int fromType, @Nullable String fromNick, @Nullable String fromUid, @Nullable RedPackageNotifyInfo notifyInfo) { public static void startForFromType(Context context,
long roomUid,
int fromType,
@Nullable String fromNick,
@Nullable String fromUid,
@Nullable RedPackageNotifyInfo notifyInfo,
int giftId) {
Intent intent = new Intent(context, AVRoomActivity.class); Intent intent = new Intent(context, AVRoomActivity.class);
intent.putExtra(Constants.ROOM_UID, roomUid); intent.putExtra(Constants.ROOM_UID, roomUid);
intent.putExtra("fromType", fromType); intent.putExtra("fromType", fromType);
@@ -238,6 +251,9 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
if (notifyInfo != null) { if (notifyInfo != null) {
intent.putExtra("notifyInfo", notifyInfo); intent.putExtra("notifyInfo", notifyInfo);
} }
if (giftId != 0) {
intent.putExtra("giftId", giftId);
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); context.startActivity(intent);
StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_INTO_ROOM_CLICK, "进入房间"); StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_INTO_ROOM_CLICK, "进入房间");
@@ -325,19 +341,15 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
// 如果是同一个房间,则只更新房间的信息 // 如果是同一个房间,则只更新房间的信息
long newRoomUid = intent.getLongExtra(Constants.ROOM_UID, 0); long oldRoomUid = roomUid;
fromType = intent.getIntExtra("fromType", 0); initIntentExtra(intent);
fromNick = intent.getStringExtra("fromNick"); if (roomUid != 0 && oldRoomUid == roomUid) {
fromUid = intent.getStringExtra("fromUid");
mRoomInfo = intent.getParcelableExtra(Constants.ROOM_INFO);
if (newRoomUid != 0 && newRoomUid == roomUid) {
updateRoomInfo(); updateRoomInfo();
showRedPackage(AvRoomDataManager.get().mCurrentRoomInfo); showRedPackage(AvRoomDataManager.get().mCurrentRoomInfo);
showRoomFragment(false); showRoomFragment(false);
dismissLoadingDialog(); dismissLoadingDialog();
return; return;
} }
roomUid = newRoomUid;
// 相同类型的房间,但是是不同人的房间 // 相同类型的房间,但是是不同人的房间
if (AvRoomDataManager.get().isFirstEnterRoomOrChangeOtherRoom(roomUid)) { if (AvRoomDataManager.get().isFirstEnterRoomOrChangeOtherRoom(roomUid)) {
showLoadingDialog(); showLoadingDialog();
@@ -358,17 +370,23 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
} }
} }
private void initIntentExtra(Intent intent) {
if (intent == null) return;
roomUid = getIntent().getLongExtra(Constants.ROOM_UID, 0);
fromType = intent.getIntExtra("fromType", 0);
fromNick = intent.getStringExtra("fromNick");
fromUid = intent.getStringExtra("fromUid");
giftId = intent.getIntExtra("giftId", 0);
mRoomInfo = intent.getParcelableExtra(Constants.ROOM_INFO);
}
@SuppressLint("CheckResult") @SuppressLint("CheckResult")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat_room); setContentView(R.layout.activity_chat_room);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
roomUid = getIntent().getLongExtra(Constants.ROOM_UID, 0); initIntentExtra(getIntent());
fromType = getIntent().getIntExtra("fromType", 0);
fromNick = getIntent().getStringExtra("fromNick");
fromUid = getIntent().getStringExtra("fromUid");
mRoomInfo = (RoomInfo) getIntent().getSerializableExtra(Constants.ROOM_INFO);
mVsRoomOffline = findViewById(R.id.vs_room_offline); mVsRoomOffline = findViewById(R.id.vs_room_offline);
mVsNobleOpen = findViewById(R.id.vs_noble_open_notice); mVsNobleOpen = findViewById(R.id.vs_noble_open_notice);
viewpager = findViewById(R.id.fragment_container); viewpager = findViewById(R.id.fragment_container);
@@ -1001,6 +1019,10 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
DemoCache.saveNewUserChargeGift(1); DemoCache.saveNewUserChargeGift(1);
} }
dismissLoadingDialog(); dismissLoadingDialog();
if (giftId != 0) {
EventBus.getDefault().post(new ShowGiftDialogEvent().setGiftId(giftId));
giftId = 0;
}
} }
@Override @Override

View File

@@ -254,7 +254,7 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
RxBus.get().toFlowable(ShowGiftDialogEvent::class.java) RxBus.get().toFlowable(ShowGiftDialogEvent::class.java)
.compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW)) .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe { onSendGiftBtnClick() } .subscribe { onSendGiftBtnClick(it.giftId) }
RxBus.get().toFlowable(ShowUserInfoDialogEvent::class.java) RxBus.get().toFlowable(ShowUserInfoDialogEvent::class.java)
.compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW)) .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
@@ -1126,10 +1126,10 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
} }
} }
private fun onSendGiftBtnClick() { private fun onSendGiftBtnClick(giftId: Int = 0) {
if (giftDialog == null) { if (giftDialog == null) {
GiftDialog.GIFT_DIALOG_FROM = "房间" GiftDialog.GIFT_DIALOG_FROM = "房间"
giftDialog = GiftDialog(context, 0, true) giftDialog = GiftDialog(context, giftId)
giftDialog?.setGiftDialogBtnClickListener(this@BaseRoomFragment) giftDialog?.setGiftDialogBtnClickListener(this@BaseRoomFragment)
giftDialog?.setOnDismissListener { giftDialog = null } giftDialog?.setOnDismissListener { giftDialog = null }
} }

View File

@@ -178,6 +178,25 @@ public class JSInterface {
} }
/**
* 调转房间
*
* @param uid 房主uid
*/
@JavascriptInterface
public void openRoomForGiftId(String uid, int giftId) {
LogUtil.i(TAG, "openRoom" + uid + "giftId=" + giftId);
if (!TextUtils.isEmpty(uid)) {
try {
long uidLong = Long.parseLong(uid);
mActivity.runOnUiThread(() -> AVRoomActivity.startForFromGiftId(context, uidLong, giftId));
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
/** /**
* 获取用户ticket * 获取用户ticket
* *

View File

@@ -179,6 +179,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
* 被送礼物的人的uid * 被送礼物的人的uid
*/ */
private long 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;
@@ -200,6 +201,10 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
private WalletInfo goldWalletInfo; private WalletInfo goldWalletInfo;
private int itemType = ITEM_TYPE_GOLD; private int itemType = ITEM_TYPE_GOLD;
public GiftDialog(Context context, int giftId) {
this(context, 0, true, false, true, giftId);
}
public GiftDialog(Context context, long OtherUid, boolean isInRoom) { public GiftDialog(Context context, long OtherUid, boolean isInRoom) {
this(context, OtherUid, isInRoom, false); this(context, OtherUid, isInRoom, false);
} }
@@ -208,6 +213,10 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
this(context, OtherUid, isInRoom, isMagic, true); this(context, OtherUid, isInRoom, isMagic, true);
} }
public GiftDialog(Context context, long OtherUid, boolean isInRoom, boolean isMagic, boolean isHideMagicTab) {
this(context, OtherUid, isInRoom, isMagic, isHideMagicTab, 0);
}
/*** /***
* *
* @param context context * @param context context
@@ -216,10 +225,11 @@ 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) { public GiftDialog(Context context, long OtherUid, boolean isInRoom, boolean isMagic, 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;
this.giftId = giftId;
this.micMemberInfos = new ArrayList<>(); this.micMemberInfos = new ArrayList<>();
this.micMemberInfos.addAll(transformAvatarList(OtherUid)); this.micMemberInfos.addAll(transformAvatarList(OtherUid));
this.isInRoom = isInRoom; this.isInRoom = isInRoom;
@@ -229,11 +239,16 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
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, List<T> data, boolean isKnap, int pageSize) { private static <T> List<List<IItem>> beanTransformVm(Context context,
List<T> data,
boolean isKnap,
int pageSize,
@Nullable GiftInfo selectGiftInfo) {
List<List<IItem>> result = new ArrayList<>(); List<List<IItem>> result = new ArrayList<>();
if (ListUtils.isListEmpty(data)) { if (ListUtils.isListEmpty(data)) {
return result; return result;
} }
boolean hasSelectGift = false;
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
IItem item = null; IItem item = null;
List<IItem> page = null; List<IItem> page = null;
@@ -245,8 +260,14 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
page = result.get(result.size() - 1); page = result.get(result.size() - 1);
} }
} }
if (data.get(i) instanceof GiftInfo) { if (data.get(i) instanceof GiftInfo) {
item = createGiftItem(context, (GiftInfo) data.get(i), i == 0, isKnap); boolean select = false;
if (selectGiftInfo != null && selectGiftInfo.getGiftId() == ((GiftInfo) data.get(i)).getGiftId()) {
hasSelectGift = true;
select = true;
}
item = createGiftItem(context, (GiftInfo) data.get(i), select, isKnap);
} else if (data.get(i) instanceof MagicInfo) { } else if (data.get(i) instanceof MagicInfo) {
item = createMagicItem(context, (MagicInfo) data.get(i), i == 0); item = createMagicItem(context, (MagicInfo) data.get(i), i == 0);
} }
@@ -254,6 +275,9 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
page.add(item); page.add(item);
} }
} }
if (!hasSelectGift && result.get(0).get(0) instanceof GiftInfoVm) {
((GiftInfoVm) result.get(0).get(0)).isSelect.set(true);
}
return result; return result;
} }
@@ -408,11 +432,6 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
} }
}); });
if (isMagic) { //如果是送魔法则直接指向魔法的tab
giftIndicator.setPosition(GiftIndicator.TYPE_MAGIC);
} else {
giftIndicator.setPosition(GiftIndicator.TYPE_NORMAL);
}
if (isHideMagicTab) { if (isHideMagicTab) {
giftIndicator.hidePosition(GiftIndicator.TYPE_MAGIC); giftIndicator.hidePosition(GiftIndicator.TYPE_MAGIC);
} else { } else {
@@ -458,8 +477,33 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
tvGiftValue = root.findViewById(R.id.tv_gift_value); tvGiftValue = root.findViewById(R.id.tv_gift_value);
ivFirstRecharge.setOnClickListener(this); ivFirstRecharge.setOnClickListener(this);
tvLuckyBagIntro.setOnClickListener(this); tvLuckyBagIntro.setOnClickListener(this);
if (giftId == 0) {
// 更新所有礼物 // 更新所有礼物
giftIndicator.setPosition(GiftIndicator.TYPE_NORMAL);
updateGiftView(giftIndicator.getCurrrentType()); updateGiftView(giftIndicator.getCurrrentType());
} else {
int indicatorType = GiftIndicator.TYPE_NORMAL;
GiftInfo giftInfo = GiftModel.get().findGiftInfoById(giftId);
if (giftInfo != null) {
switch (giftInfo.getGiftType()) {
case GiftType.GIFT_TYPE_NORMAL:
indicatorType = GiftIndicator.TYPE_NORMAL;
break;
case GiftType.GIFT_TYPE_LUCKY:
indicatorType = GiftIndicator.TYPE_LUCKY;
break;
case GiftType.GIFT_TYPE_VIP:
indicatorType = GiftIndicator.TYPE_NOBLE;
break;
case GiftType.GIFT_TYPE_WEEK_STAR:
indicatorType = GiftIndicator.TYPE_WEEK;
break;
}
}
giftIndicator.setPosition(indicatorType);
updateGiftView(giftIndicator.getCurrrentType(), giftInfo);
}
goldWalletInfo = PayModel.get().getCurrentWalletInfo(); goldWalletInfo = PayModel.get().getCurrentWalletInfo();
View descLayout = root.findViewById(R.id.desc_layout); View descLayout = root.findViewById(R.id.desc_layout);
@@ -630,11 +674,15 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
} }
currentMagicInfo = currentMagicInfoList.get(0); currentMagicInfo = currentMagicInfoList.get(0);
etSendMessage.setVisibility(View.GONE); etSendMessage.setVisibility(View.GONE);
List<List<IItem>> pagerList = beanTransformVm(context, currentMagicInfoList, false, 8); List<List<IItem>> pagerList = beanTransformVm(context, currentMagicInfoList, false, 8, null);
setGridViewData(pagerList); setGridViewData(pagerList);
} }
private void updateGiftView(int position) { private void updateGiftView(int position) {
updateGiftView(position, null);
}
private void updateGiftView(int position, @Nullable GiftInfo selectGiftInfo) {
if (position == GiftIndicator.TYPE_MAGIC) { if (position == GiftIndicator.TYPE_MAGIC) {
updateMagicView(); updateMagicView();
return; return;
@@ -677,11 +725,11 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
} }
return; return;
} }
currentGiftInfo = currentGiftInfoList.get(0); currentGiftInfo = selectGiftInfo == null ? currentGiftInfoList.get(0) : selectGiftInfo;
if (currentGiftInfo.isSendMsg()) { if (currentGiftInfo.isSendMsg()) {
etSendMessage.setVisibility(View.VISIBLE); etSendMessage.setVisibility(View.VISIBLE);
} }
pagerList = beanTransformVm(context, currentGiftInfoList, isKnap, position == GiftIndicator.TYPE_WEEK ? 4 : 8); pagerList = beanTransformVm(context, currentGiftInfoList, isKnap, position == GiftIndicator.TYPE_WEEK ? 4 : 8, selectGiftInfo);
setGridViewData(pagerList); setGridViewData(pagerList);
if (isKnap) { if (isKnap) {
tvGiftValue.setVisibility(View.VISIBLE); tvGiftValue.setVisibility(View.VISIBLE);
@@ -813,13 +861,27 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
return; return;
} }
indicatorView.initIndicator(pagerList.size()); indicatorView.initIndicator(pagerList.size());
indicatorView.setSelectedPage(0); int defaultSelectPage = 0;
int defaultSelectItem = 0;
wai:
for (int i = 0; i < pagerList.size(); i++) {
List<IItem> pager = pagerList.get(i);
for (int j = 0; j < pager.size(); j++) {
IItem iItem = pager.get(j);
if (iItem instanceof GiftInfoVm && ((GiftInfoVm) iItem).isSelect.get()) {
defaultSelectPage = i;
defaultSelectItem = j;
break wai;
}
}
}
indicatorView.setSelectedPage(defaultSelectPage);
layoutEmpty.setVisibility(View.GONE); layoutEmpty.setVisibility(View.GONE);
gridView.setVisibility(View.VISIBLE); gridView.setVisibility(View.VISIBLE);
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(0).get(0); LastSelectedItem = pagerList.get(defaultSelectPage).get(defaultSelectItem);
setGoldOrRadishText(LastSelectedItem); setGoldOrRadishText(LastSelectedItem);
gridView.setAdapter(new PagerAdapter() { gridView.setAdapter(new PagerAdapter() {
@@ -896,6 +958,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
container.removeView(recyclerView); container.removeView(recyclerView);
} }
}); });
gridView.setCurrentItem(defaultSelectPage);
gridView.addOnPageChangeListener(new OnPageSelectedListener() { gridView.addOnPageChangeListener(new OnPageSelectedListener() {
@Override @Override
public void onPageSelected(int position) { public void onPageSelected(int position) {

View File

@@ -1,5 +1,14 @@
package com.yizhuan.xchat_android_core.room.anotherroompk; package com.yizhuan.xchat_android_core.room.anotherroompk;
public class ShowGiftDialogEvent { public class ShowGiftDialogEvent {
private int giftId;
public int getGiftId() {
return giftId;
}
public ShowGiftDialogEvent setGiftId(int giftId) {
this.giftId = giftId;
return this;
}
} }