From 19c0c8c6e786d08e34e037f8e4483786ffeb48a7 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Mon, 10 Apr 2023 13:30:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=9F=E6=88=90=E5=BF=83?= =?UTF-8?q?=E6=84=BF=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/event/PopupViewDismissEvent.java | 6 ++ .../fragment/LiveNewWishListFragment.java | 73 +++++++++++-------- .../common/views/LiveNewWishListPopup.java | 6 ++ 3 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/event/PopupViewDismissEvent.java diff --git a/common/src/main/java/com/yunbao/common/event/PopupViewDismissEvent.java b/common/src/main/java/com/yunbao/common/event/PopupViewDismissEvent.java new file mode 100644 index 000000000..736875aa5 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/event/PopupViewDismissEvent.java @@ -0,0 +1,6 @@ +package com.yunbao.common.event; + +import com.yunbao.common.bean.BaseModel; + +public class PopupViewDismissEvent extends BaseModel { +} 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 b42186922..20ee6ddd7 100644 --- a/common/src/main/java/com/yunbao/common/fragment/LiveNewWishListFragment.java +++ b/common/src/main/java/com/yunbao/common/fragment/LiveNewWishListFragment.java @@ -17,6 +17,7 @@ import com.yunbao.common.bean.WishListModel; import com.yunbao.common.bean.WishModel; import com.yunbao.common.bean.WishModel2; import com.yunbao.common.event.LiveNewWishListCloseEvent; +import com.yunbao.common.event.PopupViewDismissEvent; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.utils.Bus; @@ -61,7 +62,13 @@ public class LiveNewWishListFragment extends BaseFragment { .show(); } }); - ViewClicksAntiShake.clicksAntiShake(tvDone, () -> saveWish()); + ViewClicksAntiShake.clicksAntiShake(tvDone, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + saveWish(); + Bus.get().post(new PopupViewDismissEvent()); + } + }); } @Override @@ -100,40 +107,46 @@ public class LiveNewWishListFragment extends BaseFragment { public void saveWish() { List wishList = liveNewWishAdapter.getWishList(); - wishList.remove(wishList.size() - 1); List wishList2 = new ArrayList<>(); Gson gson = new Gson(); for (WishModel model : wishList) { - WishModel2 model2 = gson.fromJson(gson.toJson(model), WishModel2.class); - wishList2.add(model2); + if (model!=null){ + WishModel2 model2 = gson.fromJson(gson.toJson(model), WishModel2.class); + wishList2.add(model2); + } + + } + if (wishList2.size() == 0) { + Bus.get().post(new PopupViewDismissEvent()); + } else { + LiveNetManager.get(getContext()). + setWishlistV2(type, gson.toJson(wishList2), new HttpCallback() { + @Override + public void onSuccess(String 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; + } } - LiveNetManager.get(getContext()). - setWishlistV2(type, gson.toJson(wishList2), 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/LiveNewWishListPopup.java b/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java index e1303d6ee..c532a3581 100644 --- a/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java +++ b/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java @@ -24,6 +24,7 @@ import com.yunbao.common.bean.WishModel; import com.yunbao.common.bean.WishModel2; import com.yunbao.common.event.LiveNewWishListCloseEvent; import com.yunbao.common.event.LiveNewWishListEvent; +import com.yunbao.common.event.PopupViewDismissEvent; import com.yunbao.common.fragment.LiveNewWishListFragment; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; @@ -146,6 +147,11 @@ public class LiveNewWishListPopup extends BottomPopupView { super.onDismiss(); } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onPopupViewDismissEvent(PopupViewDismissEvent event) { + dismiss(); + } + @Subscribe(threadMode = ThreadMode.MAIN) public void onLiveNewWishListCloseEvent(LiveNewWishListCloseEvent event) { dayWish = event.isDayWish();