From f12f6a913040cc998caf9fe7fe71fe5cefc66f25 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Fri, 31 Mar 2023 16:44:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=83=E6=84=BF=E5=8D=95=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/adapter/LiveNewWishAdapter.java | 26 ++++++ .../event/LiveNewWishListCloseEvent.java | 46 +++++++++++ .../common/event/LiveNewWishListEvent.java | 1 + .../fragment/LiveNewWishListFragment.java | 53 ++++++++----- .../yunbao/common/views/HintCustomPopup.java | 21 ++++- .../common/views/LiveNewWishListPopup.java | 79 +++++++++++++++++++ .../src/main/res/layout/hint_custom_popup.xml | 12 ++- common/src/main/res/values/strings.xml | 6 +- 8 files changed, 214 insertions(+), 30 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/event/LiveNewWishListCloseEvent.java diff --git a/common/src/main/java/com/yunbao/common/adapter/LiveNewWishAdapter.java b/common/src/main/java/com/yunbao/common/adapter/LiveNewWishAdapter.java index 9e2add60e..e6550b62d 100644 --- a/common/src/main/java/com/yunbao/common/adapter/LiveNewWishAdapter.java +++ b/common/src/main/java/com/yunbao/common/adapter/LiveNewWishAdapter.java @@ -9,6 +9,8 @@ import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.R; import com.yunbao.common.bean.WishModel; +import com.yunbao.common.event.LiveNewWishListCloseEvent; +import com.yunbao.common.utils.Bus; import com.yunbao.common.views.DayWishItemViewHolder; import com.yunbao.common.views.LunarWishItemViewHolder; import com.yunbao.common.views.SeasonalWishItemViewHolder; @@ -30,6 +32,21 @@ public class LiveNewWishAdapter extends RecyclerView.Adapter { } public void addGiftListModel(WishModel model) { + switch (type) { + case 1: + Bus.get().post(new LiveNewWishListCloseEvent().setDayWish(true)); + break; + case 2: + Bus.get().post(new LiveNewWishListCloseEvent().setZhouXin(true)); + break; + case 3: + Bus.get().post(new LiveNewWishListCloseEvent().setLunarWish(true)); + break; + case 4: + Bus.get().post(new LiveNewWishListCloseEvent().setSeasonalWish(true)); + break; + } + wishList.add(0, model); notifyDataSetChanged(); } @@ -66,12 +83,14 @@ public class LiveNewWishAdapter extends RecyclerView.Adapter { dayWishItemViewHolder.steDayWishData(wishList.get(position), position, new DayWishItemViewHolder.DayWishItemListener() { @Override public void onDelete(int index) { + Bus.get().post(new LiveNewWishListCloseEvent().setDayWish(true)); wishList.remove(index); notifyDataSetChanged(); } @Override public void onUpdate(WishModel model, int index) { + Bus.get().post(new LiveNewWishListCloseEvent().setDayWish(true)); wishList.remove(index); wishList.add(index, model); notifyItemChanged(index); @@ -82,12 +101,15 @@ public class LiveNewWishAdapter extends RecyclerView.Adapter { weekWishItemViewHolder.steWeekWishData(wishList.get(position), position, new WeekWishItemViewHolder.WeekWishItemListener() { @Override public void onDelete(int index) { + Bus.get().post(new LiveNewWishListCloseEvent().setZhouXin(true)); wishList.remove(index); notifyDataSetChanged(); + } @Override public void onUpdate(WishModel model, int index) { + Bus.get().post(new LiveNewWishListCloseEvent().setZhouXin(true)); wishList.remove(index); wishList.add(index, model); notifyItemChanged(index); @@ -98,12 +120,14 @@ public class LiveNewWishAdapter extends RecyclerView.Adapter { lunarWishItemViewHolder.steLunarWishData(wishList.get(position), position, new LunarWishItemViewHolder.LunarWishItemListener() { @Override public void onDelete(int index) { + Bus.get().post(new LiveNewWishListCloseEvent().setLunarWish(true)); wishList.remove(index); notifyDataSetChanged(); } @Override public void onUpdate(WishModel model, int index) { + Bus.get().post(new LiveNewWishListCloseEvent().setLunarWish(true)); wishList.remove(index); wishList.add(index, model); notifyItemChanged(index); @@ -114,12 +138,14 @@ public class LiveNewWishAdapter extends RecyclerView.Adapter { seasonalWishItemViewHolder.steSeasonalWish(wishList.get(position), position, new SeasonalWishItemViewHolder.SeasonalWishItemListener() { @Override public void onDelete(int index) { + Bus.get().post(new LiveNewWishListCloseEvent().setSeasonalWish(true)); wishList.remove(index); notifyDataSetChanged(); } @Override public void onUpdate(WishModel model, int index) { + Bus.get().post(new LiveNewWishListCloseEvent().setSeasonalWish(true)); wishList.remove(index); wishList.add(index, model); notifyItemChanged(index); diff --git a/common/src/main/java/com/yunbao/common/event/LiveNewWishListCloseEvent.java b/common/src/main/java/com/yunbao/common/event/LiveNewWishListCloseEvent.java new file mode 100644 index 000000000..08ab2105b --- /dev/null +++ b/common/src/main/java/com/yunbao/common/event/LiveNewWishListCloseEvent.java @@ -0,0 +1,46 @@ +package com.yunbao.common.event; + +import com.yunbao.common.bean.BaseModel; + +public class LiveNewWishListCloseEvent extends BaseModel { + private boolean dayWish = false; + private boolean zhouXin = false; + private boolean lunarWish = false; + private boolean seasonalWish = false; + + public boolean isDayWish() { + return dayWish; + } + + public LiveNewWishListCloseEvent setDayWish(boolean dayWish) { + this.dayWish = dayWish; + return this; + } + + public boolean isZhouXin() { + return zhouXin; + } + + public LiveNewWishListCloseEvent setZhouXin(boolean zhouXin) { + this.zhouXin = zhouXin; + return this; + } + + public boolean isLunarWish() { + return lunarWish; + } + + public LiveNewWishListCloseEvent setLunarWish(boolean lunarWish) { + this.lunarWish = lunarWish; + return this; + } + + public boolean isSeasonalWish() { + return seasonalWish; + } + + public LiveNewWishListCloseEvent setSeasonalWish(boolean seasonalWish) { + this.seasonalWish = seasonalWish; + return this; + } +} diff --git a/common/src/main/java/com/yunbao/common/event/LiveNewWishListEvent.java b/common/src/main/java/com/yunbao/common/event/LiveNewWishListEvent.java index 171bbf898..6a1ad5285 100644 --- a/common/src/main/java/com/yunbao/common/event/LiveNewWishListEvent.java +++ b/common/src/main/java/com/yunbao/common/event/LiveNewWishListEvent.java @@ -7,6 +7,7 @@ public class LiveNewWishListEvent extends BaseModel { private GiftListModel model; private int type = 0; + public int getType() { return type; } diff --git a/common/src/main/java/com/yunbao/common/fragment/LiveNewWishListFragment.java b/common/src/main/java/com/yunbao/common/fragment/LiveNewWishListFragment.java index e32712cef..f7c912e08 100644 --- a/common/src/main/java/com/yunbao/common/fragment/LiveNewWishListFragment.java +++ b/common/src/main/java/com/yunbao/common/fragment/LiveNewWishListFragment.java @@ -15,8 +15,10 @@ import com.yunbao.common.R; import com.yunbao.common.adapter.LiveNewWishAdapter; import com.yunbao.common.bean.WishListModel; import com.yunbao.common.bean.WishModel; +import com.yunbao.common.event.LiveNewWishListCloseEvent; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.LiveNewWishGiftPopup; import com.yunbao.common.views.weight.ViewClicksAntiShake; @@ -58,25 +60,7 @@ public class LiveNewWishListFragment extends BaseFragment { .show(); } }); - ViewClicksAntiShake.clicksAntiShake(tvDone, new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - List wishList = liveNewWishAdapter.getWishList(); - wishList.remove(wishList.size() - 1); - LiveNetManager.get(getContext()). - setWishlistV2(type, new Gson().toJson(wishList), new HttpCallback() { - @Override - public void onSuccess(String data) { - ToastUtil.show(data); - } - - @Override - public void onError(String error) { - ToastUtil.show(R.string.net_error); - } - }); - } - }); + ViewClicksAntiShake.clicksAntiShake(tvDone, () -> saveWish()); } @Override @@ -112,4 +96,35 @@ public class LiveNewWishListFragment extends BaseFragment { List wishList = new ArrayList<>(); liveNewWishAdapter.addData(wishList, type); } + + public void saveWish() { + List wishList = liveNewWishAdapter.getWishList(); + wishList.remove(wishList.size() - 1); + LiveNetManager.get(getContext()). + setWishlistV2(type, new Gson().toJson(wishList), new HttpCallback() { + @Override + public void onSuccess(String data) { + ToastUtil.show(data); + } + + @Override + public void onError(String error) { + ToastUtil.show(R.string.net_error); + } + }); + switch (type) { + case 1: + Bus.get().post(new LiveNewWishListCloseEvent().setDayWish(false)); + break; + case 2: + Bus.get().post(new LiveNewWishListCloseEvent().setZhouXin(false)); + break; + case 3: + Bus.get().post(new LiveNewWishListCloseEvent().setLunarWish(false)); + break; + case 4: + Bus.get().post(new LiveNewWishListCloseEvent().setSeasonalWish(false)); + break; + } + } } diff --git a/common/src/main/java/com/yunbao/common/views/HintCustomPopup.java b/common/src/main/java/com/yunbao/common/views/HintCustomPopup.java index 874c3d1db..59ec74044 100644 --- a/common/src/main/java/com/yunbao/common/views/HintCustomPopup.java +++ b/common/src/main/java/com/yunbao/common/views/HintCustomPopup.java @@ -11,7 +11,8 @@ import com.yunbao.common.R; import com.yunbao.common.views.weight.ViewClicksAntiShake; public class HintCustomPopup extends CenterPopupView { - private String title, contest; + private String title, contest,openCancel,openOk; + private TextView liveOpenCancel, liveOpenOk; public HintCustomPopup(@NonNull Context context, String title, String contest) { super(context); @@ -23,6 +24,16 @@ public class HintCustomPopup extends CenterPopupView { super(context); } + public HintCustomPopup setLiveOpenCancel(String openCancel) { + this.openCancel = openCancel; + return this; + } + + public HintCustomPopup setLiveOpenOk(String openOk) { + this.openOk = openOk; + return this; + } + // 返回自定义弹窗的布局 @Override protected int getImplLayoutId() { @@ -35,19 +46,23 @@ public class HintCustomPopup extends CenterPopupView { super.onCreate(); TextView titleText = findViewById(R.id.title); TextView contestText = findViewById(R.id.contest); + liveOpenCancel = findViewById(R.id.live_open_cancel); + liveOpenOk = findViewById(R.id.live_open_ok); + liveOpenOk.setText(openOk); + liveOpenCancel.setText(openCancel); if (!TextUtils.isEmpty(title)) { titleText.setText(title); } if (!TextUtils.isEmpty(contest)) { contestText.setText(contest); } - ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.live_open_ok), () -> { + ViewClicksAntiShake.clicksAntiShake(liveOpenOk, () -> { if (callBack != null) { callBack.onSure(); } dismiss(); }); - ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.live_open_cancel), () -> { + ViewClicksAntiShake.clicksAntiShake(liveOpenCancel, () -> { if (callBack != null) { callBack.onCancel(); } diff --git a/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java b/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java index d7f54cfd1..b4a636abc 100644 --- a/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java +++ b/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java @@ -19,6 +19,7 @@ import com.lxj.xpopup.core.BottomPopupView; import com.yunbao.common.R; import com.yunbao.common.adapter.LiveNewWishListAdapter; import com.yunbao.common.bean.WishModel; +import com.yunbao.common.event.LiveNewWishListCloseEvent; import com.yunbao.common.event.LiveNewWishListEvent; import com.yunbao.common.fragment.LiveNewWishListFragment; import com.yunbao.common.http.base.HttpCallback; @@ -46,6 +47,11 @@ public class LiveNewWishListPopup extends BottomPopupView { private int type = 1; private TextView replacementWish; + private boolean dayWish; + private boolean zhouXin; + private boolean lunarWish; + private boolean seasonalWish; + private LiveNewWishListFragment dayWishFragment, zhouXinFragment, lunarWishFragment, seasonalWishFragment; public LiveNewWishListPopup(@NonNull FragmentActivity context) { @@ -69,12 +75,77 @@ public class LiveNewWishListPopup extends BottomPopupView { } + + @Override + public void dismiss() { + if (dayWish || zhouXin || lunarWish || seasonalWish) { + saveWishDialog(true); + return; + } + super.dismiss(); + } + + private HintCustomPopup hintCustomPopup; + + private void saveWishDialog(boolean isDismiss) { + if (hintCustomPopup != null) return; + + hintCustomPopup = new HintCustomPopup( + getContext(), + getContext().getString(R.string.replacement_reset_confirmed_cancel3), + getContext().getString(R.string.replacement_reset_confirmed_cancel2)) + .setLiveOpenCancel(getContext().getString(R.string.replacement_reset_confirmed_cancel4)) + .setLiveOpenOk(getContext().getString(R.string.save)) + .setCallBack(new HintCustomPopup.HintCustomCallBack() { + @Override + public void onSure() { + hintCustomPopup = null; + if (dayWish) { + dayWishFragment.saveWish(); + } else if (zhouXin) { + zhouXinFragment.saveWish(); + } else if (lunarWish) { + lunarWishFragment.saveWish(); + } else if (seasonalWish) { + seasonalWishFragment.saveWish(); + } + if (isDismiss) { + dismiss(); + } + } + + @Override + public void onCancel() { + dayWish = false; + zhouXin = false; + lunarWish = false; + seasonalWish = false; + hintCustomPopup = null; + if (isDismiss) { + dismiss(); + } + } + }); + new XPopup.Builder(getContext()) + .asCustom(hintCustomPopup) + .show(); + } + @Override protected void onDismiss() { Bus.getOff(this); + super.onDismiss(); } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLiveNewWishListCloseEvent(LiveNewWishListCloseEvent event) { + dayWish = event.isDayWish(); + zhouXin = event.isZhouXin(); + lunarWish = event.isLunarWish(); + seasonalWish = event.isSeasonalWish(); + } + @Subscribe(threadMode = ThreadMode.MAIN) public void onLiveNewWishListEvent(LiveNewWishListEvent event) { WishModel model = new WishModel(); @@ -183,6 +254,9 @@ public class LiveNewWishListPopup extends BottomPopupView { public void onTabUnselected(TabLayout.Tab tab) { View customView = tab.getCustomView(); customView.setSelected(false); + if (dayWish || zhouXin || lunarWish || seasonalWish) { + saveWishDialog(false); + } } @Override @@ -195,15 +269,20 @@ public class LiveNewWishListPopup extends BottomPopupView { switch (type) { case 1: dayWishFragment.clearGiftListModel(); + dayWish = false; break; case 2: zhouXinFragment.clearGiftListModel(); + zhouXin = false; break; case 3: lunarWishFragment.clearGiftListModel(); + lunarWish = false; + break; case 4: seasonalWishFragment.clearGiftListModel(); + seasonalWish = false; break; } List wishList = new ArrayList<>(); diff --git a/common/src/main/res/layout/hint_custom_popup.xml b/common/src/main/res/layout/hint_custom_popup.xml index 8b7059e50..3d77b201e 100644 --- a/common/src/main/res/layout/hint_custom_popup.xml +++ b/common/src/main/res/layout/hint_custom_popup.xml @@ -3,13 +3,13 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="270dp" android:layout_height="180dp" - android:orientation="vertical" app:cardCornerRadius="18dp" app:cardElevation="16dp"> @@ -42,7 +42,6 @@ android:layout_width="100dp" android:layout_height="36dp" android:layout_marginStart="16dp" - android:layout_marginTop="24dp" android:background="@drawable/backgroud_live_open_lfet" android:gravity="center" android:text="@string/back" @@ -58,7 +57,6 @@ android:id="@+id/live_open_ok" android:layout_width="100dp" android:layout_height="36dp" - android:layout_marginTop="24dp" android:layout_marginEnd="16dp" android:background="@drawable/backgroud_live_open_right" android:gravity="center" diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index ecf31dd7a..557d9c73b 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1086,6 +1086,8 @@ 註冊PD LIVE 註冊並登錄 開通貴族,尊享超多特權! + 女神說 + 說點什麽吧... %s 来了 日心願 @@ -1095,7 +1097,6 @@ 心願%s 貴族 確定 - 女神說 重置心願:日 重置心願:周 重置心願:月 @@ -1104,6 +1105,9 @@ 重置後將會清空當前心願單列表\n無論心願單是否完成 確定重置 返回列表 + 是否保存当前心愿单 + 当前心愿单未保存 + 不保存