|
|
@@ -0,0 +1,183 @@
|
|
|
+package com.datarecovery.master.module.customerservice;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.webkit.WebChromeClient;
|
|
|
+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 CustomerServiceViewModel customerServiceViewModel;
|
|
|
+
|
|
|
+ private CommonLoadingDialog loadingDialog;
|
|
|
+
|
|
|
+ public static void start(Context context) {
|
|
|
+ Intent intent = new Intent(context, CustomerServiceActivity.class);
|
|
|
+ if (!(context instanceof Activity)) {
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ }
|
|
|
+ context.startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void configImmersion(@NonNull ImmersionBar immersionBar) {
|
|
|
+ immersionBar.statusBarDarkFont(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ initView();
|
|
|
+ initObserver();
|
|
|
+ AndroidBug5497Workaround.assistActivity(this);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected boolean shouldImmersion() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initViewModel() {
|
|
|
+ customerServiceViewModel = getViewModelProvider().get(CustomerServiceViewModel.class);
|
|
|
+ binding.setCustomerViewModel(customerServiceViewModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initView() {
|
|
|
+ addTopStatusBarHeight(binding.browserHeader);
|
|
|
+ initWebView();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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() {
|
|
|
+ WebSettings settings = binding.browserWebView.getSettings();
|
|
|
+ settings.setUseWideViewPort(true);
|
|
|
+ settings.setLoadWithOverviewMode(true);
|
|
|
+ settings.setJavaScriptEnabled(true);
|
|
|
+ settings.setDomStorageEnabled(true);
|
|
|
+ settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
|
|
+ settings.setLoadsImagesAutomatically(true);
|
|
|
+ settings.setMediaPlaybackRequiresUserGesture(true);
|
|
|
+ settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
|
|
+ settings.setAllowFileAccess(true);
|
|
|
+ settings.setJavaScriptCanOpenWindowsAutomatically(true);
|
|
|
+ settings.setDefaultTextEncodingName("utf-8");
|
|
|
+ settings.setAllowContentAccess(true);
|
|
|
+ settings.setAllowFileAccessFromFileURLs(true);
|
|
|
+
|
|
|
+ binding.browserWebView.setWebViewClient(new WebViewClient() {
|
|
|
+ @Override
|
|
|
+ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
|
|
+ String url = request.getUrl().toString();
|
|
|
+ if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
|
+ binding.browserWebView.loadUrl(url);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ Intent intent = new Intent(Intent.ACTION_VIEW, request.getUrl());
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ startActivity(intent);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ binding.browserWebView.setWebChromeClient(new WebChromeClient() {
|
|
|
+ @Override
|
|
|
+ public void onReceivedTitle(WebView view, String title) {
|
|
|
+ super.onReceivedTitle(view, title);
|
|
|
+ customerServiceViewModel.setWebTitle(title);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onNewIntent(Intent intent) {
|
|
|
+ super.onNewIntent(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadCustomerUrl(String url) {
|
|
|
+ if (TextUtils.isEmpty(url)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isUrl(url)) {
|
|
|
+ binding.browserWebView.loadUrl(url);
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ Uri uri = Uri.parse(url);
|
|
|
+ startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isUrl(String str) {
|
|
|
+ if (TextUtils.isEmpty(str)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String upperCaseStr = str.toUpperCase();
|
|
|
+ return upperCaseStr.startsWith("HTTP://") || upperCaseStr.startsWith("HTTPS://");
|
|
|
+ }
|
|
|
+}
|