心愿单完成

This commit is contained in:
18401019693 2023-03-31 16:44:22 +08:00
parent d1d8054c01
commit f12f6a9130
8 changed files with 214 additions and 30 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -7,6 +7,7 @@ public class LiveNewWishListEvent extends BaseModel {
private GiftListModel model;
private int type = 0;
public int getType() {
return type;
}

View File

@ -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<WishModel> wishList = liveNewWishAdapter.getWishList();
wishList.remove(wishList.size() - 1);
LiveNetManager.get(getContext()).
setWishlistV2(type, new Gson().toJson(wishList), new HttpCallback<String>() {
@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<WishModel> wishList = new ArrayList<>();
liveNewWishAdapter.addData(wishList, type);
}
public void saveWish() {
List<WishModel> wishList = liveNewWishAdapter.getWishList();
wishList.remove(wishList.size() - 1);
LiveNetManager.get(getContext()).
setWishlistV2(type, new Gson().toJson(wishList), new HttpCallback<String>() {
@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;
}
}
}

View File

@ -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();
}

View File

@ -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<WishModel> wishList = new ArrayList<>();

View File

@ -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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="270dp"
android:layout_height="180dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
@ -25,10 +25,10 @@
<TextView
android:id="@+id/contest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="90dp"
android:layout_marginStart="10dp"
android:layout_marginTop="14dp"
android:layout_marginEnd="10dp"
android:gravity="center"
android:text="@string/ultra_hd_hint2"
android:textColor="#999999"
android:textSize="12sp" />
@ -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"

View File

@ -1086,6 +1086,8 @@
<string name="sign_up_for">註冊PD LIVE</string>
<string name="register_and_log_in">註冊並登錄</string>
<string name="enjoy_a_lot">開通貴族,尊享超多特權!</string>
<string name="layout_live_anchor_say_ready_title">女神說</string>
<string name="say_something3">說點什麽吧...</string>
<string name="come_hint">%s 来了</string>
<string name="day_wish">日心願</string>
@ -1095,7 +1097,6 @@
<string name="wish_number">心願%s</string>
<string name="aristocrat">貴族</string>
<string name="aristocrat_determine">確定</string>
<string name="layout_live_anchor_say_ready_title">女神說</string>
<string name="replacement_wish_day">重置心願:日</string>
<string name="replacement_wish_zhou">重置心願:周</string>
<string name="replacement_wish_lunar">重置心願:月</string>
@ -1104,6 +1105,9 @@
<string name="replacement_reset_confirmed_hint">重置後將會清空當前心願單列表\n無論心願單是否完成</string>
<string name="replacement_reset_confirmed_sure">確定重置</string>
<string name="replacement_reset_confirmed_cancel">返回列表</string>
<string name="replacement_reset_confirmed_cancel2">是否保存当前心愿单</string>
<string name="replacement_reset_confirmed_cancel3">当前心愿单未保存</string>
<string name="replacement_reset_confirmed_cancel4">不保存</string>
</resources>