修复 "寻爱之旅"活动页面 购买数量问题

This commit is contained in:
wzq
2023-09-21 17:50:21 +08:00
parent 3f341362bc
commit c4c69169aa
4 changed files with 118 additions and 92 deletions

View File

@@ -5126,5 +5126,6 @@
<string name="interesting_people_are_here">有趣的人都在這</string>
<string name="buy_debris">購買%d個碎片</string>
<string name="buy_love_num">購買%d個愛心</string>
<string name="please_select_or_enter_the_quantity_of_hearts_purchased">請選擇或輸入購買的愛心數量</string>
</resources>

View File

@@ -45,6 +45,7 @@ import com.yizhuan.erban.treasure_box.widget.dialog.BoxMoreDialog;
import com.yizhuan.erban.treasure_box.widget.dialog.BuyLoveDialog;
import com.yizhuan.erban.treasure_box.widget.dialog.TreasureBoxDialog;
import com.yizhuan.erban.ui.utils.ImageLoadUtils;
import com.yizhuan.erban.utils.KeyBoardUtils;
import com.yizhuan.erban.utils.UserUtils;
import com.yizhuan.treasure_box.bean.PrizeNewInfo;
import com.yizhuan.treasure_box.bean.UserTicketInfo;
@@ -73,6 +74,7 @@ import com.yizhuan.xchat_android_library.utils.FormatUtils;
import com.yizhuan.xchat_android_library.utils.ResUtil;
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
import com.yizhuan.xchat_android_library.utils.TimeUtils;
import com.yizhuan.xchat_android_library.utils.keyboard.KeyboardUtil;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -84,6 +86,7 @@ import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
@ActLayoutRes(R.layout.activity_treasure_box)
public class TreasureBoxActivity extends BaseBindingActivity<ActivityTreasureBoxBinding> implements View.OnClickListener {
@@ -95,9 +98,7 @@ public class TreasureBoxActivity extends BaseBindingActivity<ActivityTreasureBox
private int height;
private int sendMessageSwitchLevel;
private int mNum = 1;
private String inputNumber = "";
private int mNum = -1;
private UserTicketInfo userTicketInfo;
@@ -157,39 +158,44 @@ public class TreasureBoxActivity extends BaseBindingActivity<ActivityTreasureBox
@Override
public void afterTextChanged(Editable s) {
if (!TextUtils.isEmpty(s)) {
inputNumber = s.toString();
} else {
inputNumber = "";
try {
mNum = Integer.parseInt(s.toString());
setBoxPriceSelect(0);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
});
mBinding.tvBuy.setOnClickListener(v -> {
if (userTicketInfo != null) {
long date = SPUtils.getLong(SpConstants.BOX_BUY_LOVE, 0L);
int num = TextUtils.isEmpty(inputNumber) ? mNum : Integer.parseInt(inputNumber);
if (date != 0L) {
if (TimeUtils.isToday(date)) {
BoxModel.get()
.buyTicket(num)
.compose(bindToLifecycle())
.subscribe(userTicketInfo -> {
ToastUtils.show("購買成功");
loadUserTicket();
});
} else {
BuyLoveDialog.Companion.newInstance(num, (int) userTicketInfo.getTicketPrice() * num).show(this);
}
if (userTicketInfo == null) {
return;
}
if (mNum == -1) {
toast(getString(R.string.please_select_or_enter_the_quantity_of_hearts_purchased));
return;
}
long date = SPUtils.getLong(SpConstants.BOX_BUY_LOVE, 0L);
if (date != 0L) {
if (TimeUtils.isToday(date)) {
BoxModel.get()
.buyTicket(mNum)
.compose(bindToLifecycle())
.doOnError(throwable -> toast(throwable.getMessage()))
.subscribe(userTicketInfo -> {
ToastUtils.show("購買成功");
loadUserTicket();
});
} else {
BuyLoveDialog.Companion.newInstance(num, (int) userTicketInfo.getTicketPrice() * num).show(this);
BuyLoveDialog.Companion.newInstance(mNum, (int) userTicketInfo.getTicketPrice() * mNum).show(this);
}
} else {
BuyLoveDialog.Companion.newInstance(mNum, (int) userTicketInfo.getTicketPrice() * mNum).show(this);
}
});
mBinding.view1.setSelected(true);
mBinding.tv1.setAlpha(1f);
loadUserTicket();
loadKeyInfo();
looperPrize();
@@ -217,6 +223,20 @@ public class TreasureBoxActivity extends BaseBindingActivity<ActivityTreasureBox
}
private void setBoxPriceSelect(int pos) {
if (pos == 0) {
mBinding.view1.setSelected(false);
mBinding.view2.setSelected(false);
mBinding.view3.setSelected(false);
mBinding.tv1.setAlpha(0.4f);
mBinding.tv2.setAlpha(0.4f);
mBinding.tv3.setAlpha(0.4f);
return;
}
mBinding.edInputNum.setText(null);
KeyBoardUtils.hideKeyBoard(this, mBinding.edInputNum);
mBinding.edInputNum.clearFocus();
if (pos == 1) {
mNum = 1;
mBinding.view1.setSelected(true);

View File

@@ -64,7 +64,8 @@ class BuyLoveDialog : BaseDialog<TreasureBoxDialogBuyLoveBinding>() {
if (TimeUtils.isToday(date)) {
BoxModel.get()
.buyTicket(num)
.compose<UserTicketInfo>(bindToLifecycle<UserTicketInfo>())
.compose(bindToLifecycle())
.doOnError { ToastUtils.show(it.message) }
.subscribe { userTicketInfo: UserTicketInfo ->
ToastUtils.show("購買成功")
dismissAllowingStateLoss()
@@ -72,7 +73,8 @@ class BuyLoveDialog : BaseDialog<TreasureBoxDialogBuyLoveBinding>() {
} else {
BoxModel.get()
.buyTicket(num)
.compose<UserTicketInfo>(bindToLifecycle<UserTicketInfo>())
.compose(bindToLifecycle())
.doOnError { ToastUtils.show(it.message) }
.subscribe { userTicketInfo: UserTicketInfo ->
BuyLoveSuccessDialog.newInstance(num).show(context)
dismissAllowingStateLoss()
@@ -81,7 +83,8 @@ class BuyLoveDialog : BaseDialog<TreasureBoxDialogBuyLoveBinding>() {
} else {
BoxModel.get()
.buyTicket(num)
.compose<UserTicketInfo>(bindToLifecycle<UserTicketInfo>())
.compose(bindToLifecycle())
.doOnError { ToastUtils.show(it.message) }
.subscribe { userTicketInfo: UserTicketInfo ->
BuyLoveSuccessDialog.newInstance(num).show(context)
dismissAllowingStateLoss()

View File

@@ -119,35 +119,35 @@
android:layout_height="@dimen/dp_28"
android:layout_marginTop="@dimen/dp_12"
android:background="@drawable/bg_8651e0_stroke_ffffff"
app:layout_constraintStart_toStartOf="@+id/iv_first_box"
app:layout_constraintEnd_toEndOf="@+id/iv_first_box"
app:layout_constraintStart_toStartOf="@+id/iv_first_box"
app:layout_constraintTop_toBottomOf="@+id/iv_first_box">
<com.coorchice.library.SuperTextView
android:id="@+id/tv_box_num"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="0"
android:textSize="@dimen/sp_10"
android:textColor="@color/color_white"
android:gravity="center"
android:layout_marginStart="@dimen/dp_16"
app:solid="@color/color_7748C7"
app:corner="@dimen/dp_8"
app:layout_constraintDimensionRatio="42:16"
app:layout_constraintWidth_percent="0.145"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<com.coorchice.library.SuperTextView
android:id="@+id/tv_box_num"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/dp_16"
android:gravity="center"
android:text="0"
android:textColor="@color/color_white"
android:textSize="@dimen/sp_10"
app:corner="@dimen/dp_8"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="42:16"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.145"
app:solid="@color/color_7748C7" />
<androidx.appcompat.widget.AppCompatImageView
android:src="@drawable/ic_token"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:layout_marginStart="@dimen/dp_4"
android:src="@drawable/ic_token"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/view_1"
@@ -155,24 +155,24 @@
android:layout_height="@dimen/dp_0"
android:layout_marginStart="@dimen/dp_8"
android:background="@drawable/selector_bg_box_price"
app:layout_constraintDimensionRatio="30:16"
app:layout_constraintWidth_percent="0.104"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/tv_box_num"/>
app:layout_constraintDimensionRatio="30:16"
app:layout_constraintStart_toEndOf="@+id/tv_box_num"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.104" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_1"
android:text="1"
android:textSize="@dimen/sp_10"
android:textColor="@color/color_white"
android:alpha="0.4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="@+id/view_1"
android:alpha="0.4"
android:text="1"
android:textColor="@color/color_white"
android:textSize="@dimen/sp_10"
app:layout_constraintBottom_toBottomOf="@+id/view_1"
app:layout_constraintEnd_toEndOf="@+id/view_1"
app:layout_constraintTop_toTopOf="@+id/view_1"
app:layout_constraintBottom_toBottomOf="@+id/view_1"/>
app:layout_constraintStart_toStartOf="@+id/view_1"
app:layout_constraintTop_toTopOf="@+id/view_1" />
<View
android:id="@+id/view_2"
@@ -180,24 +180,24 @@
android:layout_height="@dimen/dp_0"
android:layout_marginStart="@dimen/dp_8"
android:background="@drawable/selector_bg_box_price"
app:layout_constraintDimensionRatio="30:16"
app:layout_constraintWidth_percent="0.104"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/view_1"/>
app:layout_constraintDimensionRatio="30:16"
app:layout_constraintStart_toEndOf="@+id/view_1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.104" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:textSize="@dimen/sp_10"
android:textColor="@color/color_white"
android:alpha="0.4"
app:layout_constraintStart_toStartOf="@+id/view_2"
android:text="10"
android:textColor="@color/color_white"
android:textSize="@dimen/sp_10"
app:layout_constraintBottom_toBottomOf="@+id/view_2"
app:layout_constraintEnd_toEndOf="@+id/view_2"
app:layout_constraintTop_toTopOf="@+id/view_2"
app:layout_constraintBottom_toBottomOf="@+id/view_2"/>
app:layout_constraintStart_toStartOf="@+id/view_2"
app:layout_constraintTop_toTopOf="@+id/view_2" />
<View
android:id="@+id/view_3"
@@ -205,24 +205,24 @@
android:layout_height="@dimen/dp_0"
android:layout_marginStart="@dimen/dp_8"
android:background="@drawable/selector_bg_box_price"
app:layout_constraintDimensionRatio="30:16"
app:layout_constraintWidth_percent="0.104"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/view_2"/>
app:layout_constraintDimensionRatio="30:16"
app:layout_constraintStart_toEndOf="@+id/view_2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.104" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textSize="@dimen/sp_10"
android:textColor="@color/color_white"
android:alpha="0.4"
app:layout_constraintStart_toStartOf="@+id/view_3"
android:text="100"
android:textColor="@color/color_white"
android:textSize="@dimen/sp_10"
app:layout_constraintBottom_toBottomOf="@+id/view_3"
app:layout_constraintEnd_toEndOf="@+id/view_3"
app:layout_constraintTop_toTopOf="@+id/view_3"
app:layout_constraintBottom_toBottomOf="@+id/view_3"/>
app:layout_constraintStart_toStartOf="@+id/view_3"
app:layout_constraintTop_toTopOf="@+id/view_3" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/ed_input_num"
@@ -230,33 +230,35 @@
android:layout_height="@dimen/dp_18"
android:layout_marginStart="@dimen/dp_6"
android:layout_marginEnd="@dimen/dp_6"
android:background="@drawable/bg_7748c7_r10"
android:gravity="center"
android:hint="輸入數量"
android:inputType="number"
android:maxLength="4"
android:maxLines="1"
android:textColor="@color/white"
android:textColorHint="@color/white_tran_40"
android:textSize="@dimen/sp_10"
android:textColor="@color/white"
android:background="@drawable/bg_7748c7_r10"
android:maxLength="4"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tv_buy"
app:layout_constraintStart_toEndOf="@+id/view_3"
app:layout_constraintEnd_toStartOf="@+id/tv_buy"/>
app:layout_constraintTop_toTopOf="parent" />
<com.coorchice.library.SuperTextView
android:id="@+id/tv_buy"
android:text="購買"
android:textSize="@dimen/sp_10"
android:textColor="@color/color_white"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/bg_box_buy"
android:layout_marginEnd="@dimen/dp_4"
android:background="@drawable/bg_box_buy"
android:gravity="center"
android:text="購買"
android:textColor="@color/color_white"
android:textSize="@dimen/sp_10"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="52:22"
app:layout_constraintWidth_percent="0.18"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
app:layout_constraintWidth_percent="0.18" />
</androidx.constraintlayout.widget.ConstraintLayout>