|
|
@@ -48,6 +48,7 @@ import atmob.reactivex.rxjava3.functions.Function;
|
|
|
import atmob.reactivex.rxjava3.schedulers.Schedulers;
|
|
|
import atmob.rxjava.utils.RxJavaUtil;
|
|
|
import dagger.hilt.android.lifecycle.HiltViewModel;
|
|
|
+import kotlin.Pair;
|
|
|
|
|
|
@HiltViewModel
|
|
|
public class SubscriptionPageViewModel extends BaseViewModel {
|
|
|
@@ -65,6 +66,7 @@ public class SubscriptionPageViewModel extends BaseViewModel {
|
|
|
private List<PayOptionsBean> payList;
|
|
|
private final MutableLiveData<CharSequence> autoRenewableText = new MutableLiveData<>();
|
|
|
private final MutableLiveData<CharSequence> subCancelTxt = new MutableLiveData<>();
|
|
|
+ private final SingleLiveEvent<Pair<Boolean, String>> showLoading = new SingleLiveEvent<>();
|
|
|
private final MemberRepository memberRepository;
|
|
|
private GoodsBean checkGoodsBean;
|
|
|
private boolean isRequestSubmitOrder;
|
|
|
@@ -80,6 +82,10 @@ public class SubscriptionPageViewModel extends BaseViewModel {
|
|
|
EventHandler.report(EventId.purchase_001);
|
|
|
}
|
|
|
|
|
|
+ public LiveData<Pair<Boolean, String>> getShowLoading() {
|
|
|
+ return showLoading;
|
|
|
+ }
|
|
|
+
|
|
|
public void setCheckGoodsBean(GoodsBean checkGoodsBean) {
|
|
|
this.checkGoodsBean = checkGoodsBean;
|
|
|
}
|
|
|
@@ -140,16 +146,20 @@ public class SubscriptionPageViewModel extends BaseViewModel {
|
|
|
@Override
|
|
|
public void onSubscribe(@NonNull Disposable d) {
|
|
|
addDisposable(d);
|
|
|
+ showLoading.setValue(new Pair<>(true, ContextUtil.getContext().getString(R.string.query_order_status_loading_txt)));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onSuccess(@NonNull Object object) {
|
|
|
EventHandler.report(EventId.restoresuccess_001);
|
|
|
+ showLoading.setValue(new Pair<>(false, null));
|
|
|
+ finishEvent.call();
|
|
|
ToastUtil.show(R.string.member_restore_success, ToastUtil.LENGTH_SHORT);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(@NonNull Throwable e) {
|
|
|
+ showLoading.setValue(new Pair<>(false, null));
|
|
|
if (e instanceof RxHttpHandler.ServerErrorException) {
|
|
|
RxHttpHandler.ServerErrorException serverErrorException = (RxHttpHandler.ServerErrorException) e;
|
|
|
if (serverErrorException.getCode() != ErrorCode.ERROR_SUBSCRIPTION_NOT_FOUND) {
|
|
|
@@ -239,17 +249,20 @@ public class SubscriptionPageViewModel extends BaseViewModel {
|
|
|
public void onSubscribe(@NonNull Disposable d) {
|
|
|
addDisposable(d);
|
|
|
isRequestSubmitOrder = true;
|
|
|
+ showLoading.setValue(new Pair<>(true, null));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onSuccess(@NonNull OrderPayResponse orderPayResponse) {
|
|
|
isRequestSubmitOrder = false;
|
|
|
+ showLoading.setValue(new Pair<>(false, null));
|
|
|
requestPayment(checkGoodsBean, orderPayResponse.getOutTradeNo());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(@NonNull Throwable e) {
|
|
|
isRequestSubmitOrder = false;
|
|
|
+ showLoading.setValue(new Pair<>(false, null));
|
|
|
ErrorHelper.errorThrowableToast(e, ToastUtil.LENGTH_SHORT);
|
|
|
}
|
|
|
});
|
|
|
@@ -284,10 +297,16 @@ public class SubscriptionPageViewModel extends BaseViewModel {
|
|
|
@Override
|
|
|
public void onSubscribe(@NonNull Disposable d) {
|
|
|
addDisposable(d);
|
|
|
+ addDisposable(RxJavaUtil.timer(25, TimeUnit.SECONDS, () -> {
|
|
|
+ showLoading.setValue(new Pair<>(false, null));
|
|
|
+ ToastUtil.show(R.string.query_order_time_out, ToastUtil.LENGTH_SHORT);
|
|
|
+ }));
|
|
|
+ showLoading.setValue(new Pair<>(true, ContextUtil.getContext().getString(R.string.query_order_status_loading_txt)));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onSuccess(@NonNull Boolean aBoolean) {
|
|
|
+ showLoading.setValue(new Pair<>(false, null));
|
|
|
if (BoxingUtil.boxing(aBoolean)) {
|
|
|
ToastUtil.show(R.string.pay_success, ToastUtil.LENGTH_SHORT);
|
|
|
finishEvent.call();
|
|
|
@@ -296,7 +315,7 @@ public class SubscriptionPageViewModel extends BaseViewModel {
|
|
|
|
|
|
@Override
|
|
|
public void onError(@NonNull Throwable e) {
|
|
|
-
|
|
|
+ showLoading.setValue(new Pair<>(false, null));
|
|
|
}
|
|
|
});
|
|
|
}
|