Browse Source

优化客服显示问题

zk 1 year ago
parent
commit
1ee31765ef

+ 2 - 3
app/src/main/AndroidManifest.xml

@@ -7,6 +7,7 @@
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+
     <uses-permission
         android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
         tools:ignore="ScopedStorage" />
@@ -96,11 +97,9 @@
             android:screenOrientation="portrait" />
         <activity
             android:name=".module.customerservice.CustomerServiceActivity"
-            android:launchMode="singleInstance"
-            android:taskAffinity="${applicationId}.customer_service"
+            android:launchMode="singleTask"
             android:screenOrientation="portrait" />
 
-
     </application>
 
 </manifest>

+ 20 - 0
app/src/main/java/com/datarecovery/master/data/api/response/CustomerUrlResponse.java

@@ -1,12 +1,32 @@
 package com.datarecovery.master.data.api.response;
 
+import androidx.annotation.IntDef;
+
 import com.google.gson.annotations.SerializedName;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
 public class CustomerUrlResponse {
 
     @SerializedName("customerUrl")
     private String customerUrl;
 
+    @SerializedName("method")
+    private int method;
+
+    @IntDef({CustomerMethod.METHOD_ALI, CustomerMethod.METHOD_WX})
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface CustomerMethod {
+        int METHOD_ALI = 1;
+        int METHOD_WX = 2;
+    }
+
+    @CustomerMethod
+    public int getMethod() {
+        return method;
+    }
+
     public String getCustomerUrl() {
         return customerUrl;
     }

+ 7 - 44
app/src/main/java/com/datarecovery/master/module/customerservice/CustomerServiceActivity.java

@@ -12,39 +12,30 @@ import android.webkit.WebResourceRequest;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
-
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
-
 import com.atmob.app.lib.base.BaseActivity;
-import com.atmob.common.runtime.ActivityUtil;
 import com.datarecovery.master.databinding.ActivityCustomerServiceBinding;
-import com.datarecovery.master.dialog.CommonLoadingDialog;
-import com.datarecovery.master.module.main.MainActivity;
-import com.datarecovery.master.utils.ActivityUtilHelper;
 import com.datarecovery.master.utils.AndroidBug5497Workaround;
-import com.datarecovery.master.utils.BoxingUtil;
 import com.gyf.immersionbar.ImmersionBar;
-
-
 import dagger.hilt.android.AndroidEntryPoint;
 
-
 @AndroidEntryPoint
 public class CustomerServiceActivity extends BaseActivity<ActivityCustomerServiceBinding> {
 
+    private static final String KEY_URL = "key_browser_url";
     private CustomerServiceViewModel customerServiceViewModel;
 
-    private CommonLoadingDialog loadingDialog;
-
-    public static void start(Context context) {
+    public static void start(Context context, String url) {
         Intent intent = new Intent(context, CustomerServiceActivity.class);
         if (!(context instanceof Activity)) {
             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         }
+        intent.putExtra(KEY_URL, url);
         context.startActivity(intent);
     }
 
+
     @Override
     protected void configImmersion(@NonNull ImmersionBar immersionBar) {
         immersionBar.statusBarDarkFont(true);
@@ -55,6 +46,7 @@ public class CustomerServiceActivity extends BaseActivity<ActivityCustomerServic
         super.onCreate(savedInstanceState);
         initView();
         initObserver();
+        checkIntent(getIntent());
         AndroidBug5497Workaround.assistActivity(this);
     }
 
@@ -76,39 +68,9 @@ public class CustomerServiceActivity extends BaseActivity<ActivityCustomerServic
     }
 
     private void initObserver() {
-        customerServiceViewModel.getCustomerUrl().observe(this, this::loadCustomerUrl);
-        customerServiceViewModel.getShowLoading().observe(this, this::showLoadingDialog);
         customerServiceViewModel.getOnFinishEvent().observe(this, o -> onBackPressed());
     }
 
-    @Override
-    public void onBackPressed() {
-        Activity activity = null;
-        if (ActivityUtil.getActivityCount() >= 2 && (activity = ActivityUtilHelper.getActivity(ActivityUtilHelper.getActivityCount() - 2)) != null && !(activity instanceof MainActivity)) {
-            startActivity(new Intent(this, activity.getClass()));
-        } else {
-            MainActivity.start(this);
-        }
-    }
-
-    @Override
-    protected void onResume() {
-        super.onResume();
-        customerServiceViewModel.checkCustomerUrl();
-    }
-
-    public void showLoadingDialog(Boolean show) {
-        if (BoxingUtil.boxing(show)) {
-            if (loadingDialog == null) {
-                loadingDialog = new CommonLoadingDialog(this);
-            }
-            loadingDialog.show();
-        } else {
-            if (loadingDialog != null) {
-                loadingDialog.dismiss();
-            }
-        }
-    }
 
     @SuppressLint("SetJavaScriptEnabled")
     private void initWebView() {
@@ -156,7 +118,8 @@ public class CustomerServiceActivity extends BaseActivity<ActivityCustomerServic
         super.onNewIntent(intent);
     }
 
-    private void loadCustomerUrl(String url) {
+    private void checkIntent(Intent intent) {
+        String url = intent.getStringExtra(KEY_URL);
         if (TextUtils.isEmpty(url)) {
             return;
         }

+ 1 - 52
app/src/main/java/com/datarecovery/master/module/customerservice/CustomerServiceViewModel.java

@@ -2,45 +2,21 @@ package com.datarecovery.master.module.customerservice;
 
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MutableLiveData;
-import androidx.lifecycle.ViewModel;
-
 import com.atmob.app.lib.base.BaseViewModel;
 import com.atmob.app.lib.livedata.SingleLiveEvent;
-import com.datarecovery.master.R;
-import com.datarecovery.master.data.api.response.CustomerUrlResponse;
-import com.datarecovery.master.data.repositories.AccountRepository;
-import com.datarecovery.master.data.repositories.ConfigRepository;
-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 CustomerServiceViewModel extends BaseViewModel {
 
 
-    private final ConfigRepository configRepository;
-    private final MutableLiveData<String> customerUrl = new MutableLiveData<>();
-    private final MutableLiveData<Boolean> showLoading = new MutableLiveData<>();
     private final SingleLiveEvent<?> onFinishEvent = new SingleLiveEvent<>();
 
     private final MutableLiveData<String> webTitle = new MutableLiveData<>();
 
     @Inject
-    public CustomerServiceViewModel(ConfigRepository configRepository) {
-        this.configRepository = configRepository;
-    }
-
-    public LiveData<String> getCustomerUrl() {
-        return customerUrl;
-    }
-
-    public LiveData<Boolean> getShowLoading() {
-        return showLoading;
+    public CustomerServiceViewModel() {
     }
 
     public LiveData<?> getOnFinishEvent() {
@@ -60,32 +36,5 @@ public class CustomerServiceViewModel extends BaseViewModel {
     }
 
 
-    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);
-                        customerUrl.setValue(customerUrlResponse.getCustomerUrl());
-                    }
 
-                    @Override
-                    public void onError(@NonNull Throwable e) {
-                        showLoading.setValue(false);
-                        ToastUtil.show(R.string.net_error, ToastUtil.LENGTH_SHORT);
-                    }
-                });
-    }
-
-    public void checkCustomerUrl() {
-        if (customerUrl.getValue() == null) {
-            refreshCustomerUrl();
-        }
-    }
 }

+ 18 - 0
app/src/main/java/com/datarecovery/master/module/mine/MineFragment.java

@@ -10,8 +10,10 @@ import com.atmob.app.lib.base.BaseFragment;
 import com.datarecovery.master.R;
 import com.datarecovery.master.data.consts.EventId;
 import com.datarecovery.master.databinding.FragmentMineBinding;
+import com.datarecovery.master.dialog.CommonLoadingDialog;
 import com.datarecovery.master.dialog.CommonSureDialog;
 import com.datarecovery.master.handler.EventHelper;
+import com.datarecovery.master.utils.BoxingUtil;
 import com.gyf.immersionbar.ImmersionBar;
 
 import dagger.hilt.android.AndroidEntryPoint;
@@ -24,6 +26,7 @@ public class MineFragment extends BaseFragment<FragmentMineBinding> {
     private MineViewModel mineViewModel;
     private CommonSureDialog exitDialog;
     private CommonSureDialog logoutDialog;
+    private CommonLoadingDialog loadingDialog;
 
     @Override
     public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
@@ -33,6 +36,7 @@ public class MineFragment extends BaseFragment<FragmentMineBinding> {
     }
 
     private void initObserver() {
+        mineViewModel.getShowLoading().observe(getViewLifecycleOwner(), this::showLoadingDialog);
         mineViewModel.getShowExitDialog().observe(getViewLifecycleOwner(), o -> showExitDialog());
         mineViewModel.getShowLogoutDialog().observe(getViewLifecycleOwner(), o -> showLogoutDialog());
     }
@@ -41,6 +45,20 @@ public class MineFragment extends BaseFragment<FragmentMineBinding> {
 
     }
 
+    public void showLoadingDialog(Boolean show) {
+        if (BoxingUtil.boxing(show)) {
+            if (loadingDialog == null) {
+                loadingDialog = new CommonLoadingDialog(requireActivity());
+            }
+            loadingDialog.show();
+        } else {
+            if (loadingDialog != null) {
+                loadingDialog.dismiss();
+            }
+        }
+    }
+
+
     public void showExitDialog() {
         if (exitDialog == null) {
             exitDialog = new CommonSureDialog(requireContext());

+ 66 - 3
app/src/main/java/com/datarecovery/master/module/mine/MineViewModel.java

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

+ 7 - 2
app/src/main/java/com/datarecovery/master/sdk/wechat/WechatHelper.java

@@ -53,18 +53,23 @@ public class WechatHelper {
         api.handleIntent(intent, iwxapiEventHandler);
     }
 
-    public static void launchCustomerService() {
+
+    public static void launchCustomerService(String url) {
         if (api == null) {
             throw new IllegalStateException("WechatHelper not init");
         }
         if (api.getWXAppSupportAPI() >= Build.SUPPORT_OPEN_CUSTOMER_SERVICE_CHAT && api.isWXAppInstalled()) {
             WXOpenCustomerServiceChat.Req req = new WXOpenCustomerServiceChat.Req();
             req.corpId = CROP_ID;
-            req.url = CUSTOMER_SERVICE_URL;
+            req.url = url;
             api.sendReq(req);
         } else {
             ToastUtil.show(R.string.wechat_version_too_low_toast, ToastUtil.LENGTH_SHORT);
         }
     }
 
+    public static void launchCustomerService() {
+        launchCustomerService(CUSTOMER_SERVICE_URL);
+    }
+
 }

+ 1 - 1
app/src/main/res/layout/fragment_mine.xml

@@ -201,7 +201,7 @@
                         android:onClick="@{()->mineViewModel.onCustomerServiceClick()}" />
 
                     <include
-                        isGone="@{AtmobUser.getAtmobTgPlatformId() == ChannelId.BD}"
+                        isGone="@{!mineViewModel.isLogin || AtmobUser.getAtmobTgPlatformId() == ChannelId.BD}"
                         layout="@layout/layout_item_settings"
                         settingsIcon="@{@drawable/icon_small_appeal}"
                         settingsName="@{@string/mine_appeal}"

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -213,4 +213,5 @@
     <string name="member_choose_services">选择开通服务</string>
     <string name="member_good_comment">随机挑选3条优质评论</string>
     <string name="member_has_this_permission">已有该服务,不可重复购买</string>
+    <string name="no_customer_service">暂无客服</string>
 </resources>