feat:补充解锁礼物点击联动逻辑
This commit is contained in:
@@ -3,6 +3,7 @@ package com.nnbc123.app.ui.widget
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.cardview.widget.CardView
|
||||
import androidx.core.util.Consumer
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.nnbc123.app.R
|
||||
@@ -65,4 +66,14 @@ class GIftDialogUnlockPanel : CardView {
|
||||
fun refreshState() {
|
||||
adapter.notifyItemRangeChanged(0, adapter.itemCount, true)
|
||||
}
|
||||
|
||||
fun setOnItemClickListener(listener: Consumer<Int>) {
|
||||
adapter.setOnItemClickListener { adapter, view, position ->
|
||||
val item = adapter.getItem(position) as? UnlockItem
|
||||
val giftId = item?.getGiftData()?.giftId
|
||||
if (giftId != null) {
|
||||
listener.accept(giftId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -31,6 +31,7 @@ import androidx.appcompat.widget.AppCompatTextView;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.util.Consumer;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -219,6 +220,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
||||
private Group groupPrivilege;
|
||||
private GIftDialogUnlockPanel unLockPanel;
|
||||
private ImageView dressUpBannerView;
|
||||
private SparseArray<RecyclerViewNoViewpagerScroll> cacheItemView = new SparseArray<>();
|
||||
|
||||
private int mPrivilegePosition = 0;
|
||||
|
||||
@@ -595,6 +597,15 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
||||
if (DemoCache.readNewGiftTypeTipIndicator()) {
|
||||
viewNewFeature.setVisibility(View.VISIBLE);
|
||||
}
|
||||
unLockPanel.setOnItemClickListener(new Consumer<Integer>() {
|
||||
@Override
|
||||
public void accept(Integer integer) {
|
||||
if (integer == null) {
|
||||
return;
|
||||
}
|
||||
trySelectGift(integer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initVipPager() {
|
||||
@@ -626,6 +637,33 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
||||
pagerViewVip.setPlayDelay(3000);
|
||||
}
|
||||
|
||||
private boolean trySelectGift(int giftId) {
|
||||
if (pagerList == null) {
|
||||
return false;
|
||||
}
|
||||
int currentPage = gridView.getCurrentItem();
|
||||
if (currentPage < 0 || currentPage >= pagerList.size()) {
|
||||
return false;
|
||||
}
|
||||
List<GiftInfoVm> list = pagerList.get(currentPage);
|
||||
if (list == null) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
GiftInfoVm item = list.get(i);
|
||||
GiftInfo itemInfo = item.data();
|
||||
if (itemInfo != null && itemInfo.getGiftId() == giftId) {
|
||||
onGiftClick(item);
|
||||
RecyclerView recyclerView = cacheItemView.get(currentPage);
|
||||
if (recyclerView != null) {
|
||||
recyclerView.smoothScrollToPosition(i);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showLoadingAnimation() {
|
||||
Animation rotateAnimation = new RotateAnimation(0, 360,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f,
|
||||
@@ -1158,7 +1196,6 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
||||
layoutEmpty.setVisibility(View.GONE);
|
||||
gridView.setVisibility(View.VISIBLE);
|
||||
|
||||
SparseArray<RecyclerViewNoViewpagerScroll> cacheItemView = new SparseArray<>();
|
||||
lastSelectedItem = pagerList.get(defaultSelectPage).get(defaultSelectItem);
|
||||
setGoldOrRadishText(lastSelectedItem);
|
||||
gridView.setAdapter(new PagerAdapter() {
|
||||
@@ -1194,24 +1231,7 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
||||
giftAdapter.addData(pagerList.get(pagePos));
|
||||
|
||||
giftAdapter.setOnItemClickListener(item -> {
|
||||
if (item.data.isSendMsg()) {
|
||||
etSendMessage.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
etSendMessage.setVisibility(View.GONE);
|
||||
}
|
||||
if (lastSelectedItem != null) {
|
||||
lastSelectedItem.isSelect.set(false);
|
||||
}
|
||||
item.isSelect.set(true);
|
||||
lastSelectedItem = item;
|
||||
currentGiftInfo = item.data;
|
||||
setGoldOrRadishText(lastSelectedItem);
|
||||
updateLuckyBagIntro();
|
||||
updateWeekStarDesc();
|
||||
isShowDrawGiftModel = true;
|
||||
updateDrawGift();
|
||||
updateUnLockTips();
|
||||
updateDressUpTips();
|
||||
onGiftClick(item);
|
||||
});
|
||||
container.addView(recyclerView);
|
||||
return recyclerView;
|
||||
@@ -1228,6 +1248,27 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene
|
||||
gridView.setCurrentItem(defaultSelectPage);
|
||||
}
|
||||
|
||||
private void onGiftClick(GiftInfoVm item) {
|
||||
if (item.data.isSendMsg()) {
|
||||
etSendMessage.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
etSendMessage.setVisibility(View.GONE);
|
||||
}
|
||||
if (lastSelectedItem != null) {
|
||||
lastSelectedItem.isSelect.set(false);
|
||||
}
|
||||
item.isSelect.set(true);
|
||||
lastSelectedItem = item;
|
||||
currentGiftInfo = item.data;
|
||||
setGoldOrRadishText(lastSelectedItem);
|
||||
updateLuckyBagIntro();
|
||||
updateWeekStarDesc();
|
||||
isShowDrawGiftModel = true;
|
||||
updateDrawGift();
|
||||
updateUnLockTips();
|
||||
updateDressUpTips();
|
||||
}
|
||||
|
||||
private List<GiftInfo> loadGiftInfoList() {
|
||||
List<GiftInfo> giftInfos;
|
||||
String roomUid = null;
|
||||
|
Reference in New Issue
Block a user