|
|
@@ -3,6 +3,7 @@ package com.datarecovery.master.module.mine;
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
+import androidx.lifecycle.MutableLiveData;
|
|
|
import androidx.lifecycle.Transformations;
|
|
|
|
|
|
import com.atmob.app.lib.base.BaseViewModel;
|
|
|
@@ -10,8 +11,10 @@ import com.atmob.app.lib.livedata.SingleLiveEvent;
|
|
|
import com.atmob.common.runtime.ActivityUtil;
|
|
|
import com.atmob.common.runtime.ContextUtil;
|
|
|
import com.datarecovery.master.R;
|
|
|
+import com.datarecovery.master.data.api.response.CustomerUrlResponse;
|
|
|
import com.datarecovery.master.data.consts.EventId;
|
|
|
import com.datarecovery.master.data.repositories.AccountRepository;
|
|
|
+import com.datarecovery.master.data.repositories.ConfigRepository;
|
|
|
import com.datarecovery.master.data.repositories.DeviceFuncRepository;
|
|
|
import com.datarecovery.master.handler.EventHelper;
|
|
|
import com.datarecovery.master.module.about.AboutActivity;
|
|
|
@@ -24,23 +27,34 @@ import com.datarecovery.master.module.member.MemberType;
|
|
|
import com.datarecovery.master.module.wxrecover.WeChatRecoverActivity;
|
|
|
import com.datarecovery.master.sdk.wechat.WechatHelper;
|
|
|
import com.datarecovery.master.utils.BoxingUtil;
|
|
|
+import com.datarecovery.master.utils.ToastUtil;
|
|
|
+
|
|
|
import javax.inject.Inject;
|
|
|
+
|
|
|
+import atmob.reactivex.rxjava3.annotations.NonNull;
|
|
|
+import atmob.reactivex.rxjava3.core.SingleObserver;
|
|
|
+import atmob.reactivex.rxjava3.disposables.Disposable;
|
|
|
import dagger.hilt.android.lifecycle.HiltViewModel;
|
|
|
|
|
|
|
|
|
@HiltViewModel
|
|
|
public class MineViewModel extends BaseViewModel {
|
|
|
|
|
|
+ private final MutableLiveData<Boolean> showLoading = new MutableLiveData<>();
|
|
|
private final SingleLiveEvent<?> showExitDialog = new SingleLiveEvent<>();
|
|
|
private final SingleLiveEvent<?> showLogoutDialog = new SingleLiveEvent<>();
|
|
|
private final LiveData<String> loginTips;
|
|
|
|
|
|
+ private CustomerUrlResponse customerResponse;
|
|
|
private final AccountRepository accountRepository;
|
|
|
private final DeviceFuncRepository deviceFuncRepository;
|
|
|
+ private final ConfigRepository configRepository;
|
|
|
+
|
|
|
|
|
|
@Inject
|
|
|
- public MineViewModel(AccountRepository accountRepository, DeviceFuncRepository deviceFuncRepository) {
|
|
|
+ public MineViewModel(AccountRepository accountRepository, DeviceFuncRepository deviceFuncRepository, ConfigRepository configRepository) {
|
|
|
this.accountRepository = accountRepository;
|
|
|
+ this.configRepository = configRepository;
|
|
|
this.deviceFuncRepository = deviceFuncRepository;
|
|
|
loginTips = Transformations.map(accountRepository.getLoginPhoneNum(), phone -> {
|
|
|
if (TextUtils.isEmpty(phone)) {
|
|
|
@@ -54,6 +68,9 @@ public class MineViewModel extends BaseViewModel {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ public LiveData<Boolean> getShowLoading() {
|
|
|
+ return showLoading;
|
|
|
+ }
|
|
|
|
|
|
public LiveData<?> getShowExitDialog() {
|
|
|
return showExitDialog;
|
|
|
@@ -71,6 +88,30 @@ public class MineViewModel extends BaseViewModel {
|
|
|
return accountRepository.getIsLogin();
|
|
|
}
|
|
|
|
|
|
+ public void refreshCustomerUrl() {
|
|
|
+ configRepository.getCustomerUrl(AccountRepository.getUserId(), AccountRepository.getKeyLoginPhoneNum())
|
|
|
+ .subscribe(new SingleObserver<CustomerUrlResponse>() {
|
|
|
+ @Override
|
|
|
+ public void onSubscribe(@NonNull Disposable d) {
|
|
|
+ addDisposable(d);
|
|
|
+ showLoading.setValue(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(@NonNull CustomerUrlResponse customerUrlResponse) {
|
|
|
+ showLoading.setValue(false);
|
|
|
+ customerResponse = customerUrlResponse;
|
|
|
+ goCustomer();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(@NonNull Throwable e) {
|
|
|
+ showLoading.setValue(false);
|
|
|
+ ToastUtil.show(R.string.net_error, ToastUtil.LENGTH_SHORT);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
public void onLoginClick() {
|
|
|
if (BoxingUtil.boxing(accountRepository.getIsLogin().getValue())) {
|
|
|
return;
|
|
|
@@ -121,12 +162,34 @@ public class MineViewModel extends BaseViewModel {
|
|
|
}
|
|
|
|
|
|
public void onCustomerServiceClick() {
|
|
|
- WechatHelper.launchCustomerService();
|
|
|
EventHelper.report(EventId.hf1001108);
|
|
|
+ if (customerResponse == null) {
|
|
|
+ refreshCustomerUrl();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ goCustomer();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void goCustomer() {
|
|
|
+ switch (customerResponse.getMethod()) {
|
|
|
+ case CustomerUrlResponse.CustomerMethod.METHOD_ALI:
|
|
|
+ CustomerServiceActivity.start(ActivityUtil.getTopActivity(), customerResponse.getCustomerUrl());
|
|
|
+ break;
|
|
|
+ case CustomerUrlResponse.CustomerMethod.METHOD_WX:
|
|
|
+ WechatHelper.launchCustomerService(customerResponse.getCustomerUrl());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ ToastUtil.show(R.string.no_customer_service, ToastUtil.LENGTH_SHORT);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void onAppealClick() {
|
|
|
- CustomerServiceActivity.start(ActivityUtil.getTopActivity());
|
|
|
EventHelper.report(EventId.hf1001115);
|
|
|
+ if (customerResponse == null) {
|
|
|
+ refreshCustomerUrl();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ goCustomer();
|
|
|
}
|
|
|
}
|