工作空间 v3.6.5.2版本的 MD5 值为:58e65af156c65a63bf64ed2e64960853

以下内容为反编译后的 FileDetailFragment.java 源代码,内容仅作参考


package com.uusafe.portal.mcm.fragment;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.http.SslError;
import android.os.Bundle;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.CallSuper;
import androidx.annotation.MainThread;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Lifecycle;
import com.uber.autodispose.l;
import com.uusafe.base.modulesdk.module.activity.ActivityLifeController;
import com.uusafe.base.modulesdk.module.manager.BaseModuleManager;
import com.uusafe.base.modulesdk.module.netapi.BaseApis;
import com.uusafe.base.modulesdk.module.router.ARouterConfig;
import com.uusafe.commbase.bean.DownloadInfo;
import com.uusafe.commbase.bean.FileDetail;
import com.uusafe.commbase.global.BaseGlobal;
import com.uusafe.commbase.module.listener.DownloadListener;
import com.uusafe.commbase.utils.CommUtils;
import com.uusafe.commbase.utils.DateUtils;
import com.uusafe.download.manager.DownloadManager;
import com.uusafe.download.task.DownloadTask;
import com.uusafe.emm.policy.DevicePolicyWrapper;
import com.uusafe.mbs.mcm.R;
import com.uusafe.net.NetClient;
import com.uusafe.net.https.SSLHelper;
import com.uusafe.portal.mcm.FilePresenterImpl;
import com.uusafe.uibase.dialog.CommonDialog;
import com.uusafe.uibase.event.StartFragmentEvent;
import com.uusafe.uibase.fragment.SwipeBackFragment;
import com.uusafe.utils.common.FileAccessorUtil;
import com.uusafe.utils.common.MyUtils;
import com.uusafe.utils.common.NativeUtil;
import com.uusafe.utils.common.StringUtils;
import com.zhizhangyi.platform.widget.button.DownloadButton;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import okhttp3.Request;
import okhttp3.Response;
import org.greenrobot.eventbus.n;
public class FileDetailFragment extends SwipeBackFragment {
    DownloadButton downloadButton;
    DownloadInfo downloadInfo;
    DownloadListener downloadListener;
    DownloadTask downloadTask;
    public FileDetail fileDetail;
    boolean hasDownload;
    ImageView img_file_icon;
    LinearLayout ll_file_info;
    Dialog mDialog;
    TextView txt_fileName;
    TextView txt_fileSize;
    WebView webview_file_preview;

    public static FileDetailFragment newInstance(FileDetail fileDetail) {
        Bundle bundle = new Bundle();
        FileDetailFragment fileDetailFragment = new FileDetailFragment();
        fileDetailFragment.fileDetail = fileDetail;
        fileDetailFragment.setArguments(bundle);
        return fileDetailFragment;
    }

    @Override
    public int attachLayoutRes() {
        return R.layout.uu_mos_file_fragment_detail;
    }

    @Override
    public <T> l<T> bindLifecycle() {
        return null;
    }

    @Override
    public void closeWindow() {
        AppCompatActivity appCompatActivity = this.mActivity;
        if (appCompatActivity != null) {
            appCompatActivity.finish();
        }
    }

    @Override
    public Context getCurrentContext() {
        return this.mActivity;
    }

    @Override
    protected String getPageName() {
        return getString(com.uusafe.base.commsdk.view.R.string.uu_mbs_uaa_page_filedetail);
    }

    @Override
    public void initData() {
        long j;
        FileDetail fileDetail = this.fileDetail;
        if (fileDetail != null) {
            setTitleText(fileDetail.getName());
            TextView textView = (TextView) findViewById(R.id.txt_file_endtime);
            if (this.fileDetail.getValidityType() == 1) {
                textView.setText(((Object) getText(R.string.feature_file_endtime)) + " " + ((Object) getText(R.string.feature_file_forever)));
            } else {
                textView.setText(((Object) getText(R.string.feature_file_endtime)) + " " + DateUtils.getShortDateText(getContext(), Long.parseLong(this.fileDetail.getCustomEndDate())));
            }
            if (this.fileDetail.getDownloadFlag() == 0) {
                this.downloadButton.setVisibility(8);
            } else {
                this.downloadButton.setButtonState(0);
                this.downloadButton.setNormalText(getString(R.string.feature_file_download));
                this.downloadTask = DownloadManager.getInstance().getTask(BaseApis.getDownloadUrlByFileid(this.fileDetail.getDownloadFileId()));
                DownloadTask downloadTask = this.downloadTask;
                if (downloadTask != null) {
                    this.downloadInfo = downloadTask.getDownloadInfo();
                    DownloadInfo downloadInfo = this.downloadInfo;
                    if (downloadInfo != null) {
                        if (((int) (downloadInfo.getFraction() * 100.0f)) == 100) {
                            if (this.downloadInfo.isLocalFileExist()) {
                                this.hasDownload = true;
                                this.downloadButton.setNormalText(getText(com.uusafe.base.commsdk.view.R.string.uu_mos_app_state_open));
                            } else {
                                this.downloadButton.setNormalText(getText(com.uusafe.base.commsdk.view.R.string.feature_file_download));
                            }
                        } else if (this.downloadInfo.getStatus() == 2) {
                            initListener();
                            this.downloadTask.register(this.downloadListener);
                        } else {
                            this.downloadButton.setNormalText(getText(com.uusafe.base.commsdk.view.R.string.uu_mos_app_state_continue));
                        }
                    }
                }
                this.downloadButton.postInvalidate();
                this.downloadButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        FileDetailFragment fileDetailFragment = FileDetailFragment.this;
                        if (fileDetailFragment.hasDownload) {
                            if (fileDetailFragment.downloadInfo == null) {
                                fileDetailFragment.downloadTask = DownloadManager.getInstance().getTask(BaseApis.getDownloadUrlByFileid(FileDetailFragment.this.fileDetail.getDownloadFileId()));
                                FileDetailFragment fileDetailFragment2 = FileDetailFragment.this;
                                DownloadTask downloadTask2 = fileDetailFragment2.downloadTask;
                                if (downloadTask2 != null) {
                                    fileDetailFragment2.downloadInfo = downloadTask2.getDownloadInfo();
                                }
                            }
                            DownloadInfo downloadInfo2 = FileDetailFragment.this.downloadInfo;
                            if (downloadInfo2 != null) {
                                String saveFileFullPath = downloadInfo2.getSaveFileFullPath();
                                if (StringUtils.areNotEmpty(saveFileFullPath) && new File(saveFileFullPath).exists()) {
                                    NativeUtil.openFile(FileDetailFragment.this.getContext(), saveFileFullPath);
                                    return;
                                }
                                return;
                            }
                            return;
                        }
                        fileDetailFragment.downloadTask = DownloadManager.getInstance().getTask(BaseApis.getDownloadUrlByFileid(FileDetailFragment.this.fileDetail.getDownloadFileId()));
                        FileDetailFragment fileDetailFragment3 = FileDetailFragment.this;
                        DownloadTask downloadTask3 = fileDetailFragment3.downloadTask;
                        if (downloadTask3 != null) {
                            fileDetailFragment3.downloadInfo = downloadTask3.getDownloadInfo();
                            FileDetailFragment fileDetailFragment4 = FileDetailFragment.this;
                            if (fileDetailFragment4.downloadInfo != null) {
                                fileDetailFragment4.initListener();
                                FileDetailFragment fileDetailFragment5 = FileDetailFragment.this;
                                fileDetailFragment5.downloadTask.register(fileDetailFragment5.downloadListener);
                                if (FileDetailFragment.this.downloadInfo.getStatus() == 2) {
                                    FileDetailFragment.this.downloadTask.pause(true);
                                    return;
                                } else {
                                    FileDetailFragment.this.downloadTask.start();
                                    return;
                                }
                            }
                        }
                        FileDetailFragment.this.initListener();
                        BaseModuleManager.getInstance().getUaaModule().onClickEvent("uu_mbs_uaa_event_download_file", FileDetailFragment.this.getString(R.string.uu_mbs_uaa_event_download_file), FileDetailFragment.this.getContext());
                        DownloadManager downloadManager = DownloadManager.getInstance();
                        String downloadUrlByFileid = BaseApis.getDownloadUrlByFileid(FileDetailFragment.this.fileDetail.getDownloadFileId());
                        String name = FileDetailFragment.this.fileDetail.getName();
                        String str = FileAccessorUtil.DOWNLOAD_PATH;
                        FileDetailFragment fileDetailFragment6 = FileDetailFragment.this;
                        downloadManager.downloadFile(downloadUrlByFileid, name, str, fileDetailFragment6.downloadListener, fileDetailFragment6.fileDetail.getCustomEndDate(), FileDetailFragment.this.fileDetail.getFileId());
                    }
                });
            }
            if (this.fileDetail.getPreviewFlag() == 1) {
                this.ll_file_info.setVisibility(8);
                this.webview_file_preview.loadUrl(BaseApis.getBaseUrl() + this.fileDetail.getPreviewUri());
                return;
            }
            this.webview_file_preview.setVisibility(8);
            this.img_file_icon.setImageResource(CommUtils.getFileResourceByName(this.fileDetail.getName()));
            this.txt_fileName.setText(this.fileDetail.getName());
            try {
                j = Long.parseLong(this.fileDetail.getFileSize());
            } catch (Exception unused) {
                j = 0;
            }
            this.txt_fileSize.setText(j > 0 ? MyUtils.formatFileSize(j) : "");
        }
    }

    @Override
    protected void initInjector() {
    }

    @Override
    @CallSuper
    @MainThread
    public void initLifecycleObserver(Lifecycle lifecycle) {
    }

    void initListener() {
        if (this.downloadListener == null) {
            this.downloadListener = new DownloadListener(FileDetailFragment.class.getSimpleName(), false) {
                @Override
                public void onAddTask(DownloadInfo downloadInfo) {
                    FileDetailFragment fileDetailFragment = FileDetailFragment.this;
                    if (fileDetailFragment.fileDetail == null) {
                        return;
                    }
                    fileDetailFragment.downloadButton.setButtonState(1);
                }

                @Override
                public void onError(DownloadInfo downloadInfo) {
                    FileDetailFragment fileDetailFragment = FileDetailFragment.this;
                    if (fileDetailFragment.fileDetail == null) {
                        return;
                    }
                    fileDetailFragment.showToast("error");
                    FileDetailFragment.this.downloadButton.setButtonState(0);
                    FileDetailFragment fileDetailFragment2 = FileDetailFragment.this;
                    fileDetailFragment2.downloadButton.setNormalText(fileDetailFragment2.getText(com.uusafe.base.commsdk.view.R.string.feature_file_download));
                    FileDetailFragment.this.downloadButton.postInvalidate();
                }

                @Override
                public void onFinish(DownloadInfo downloadInfo) {
                    FileDetailFragment fileDetailFragment = FileDetailFragment.this;
                    if (fileDetailFragment.fileDetail == null) {
                        return;
                    }
                    fileDetailFragment.hasDownload = true;
                    fileDetailFragment.downloadButton.setButtonState(0);
                    FileDetailFragment fileDetailFragment2 = FileDetailFragment.this;
                    fileDetailFragment2.downloadButton.setNormalText(fileDetailFragment2.getText(com.uusafe.base.commsdk.view.R.string.uu_mos_app_state_open));
                    FileDetailFragment.this.downloadButton.postInvalidate();
                    new FilePresenterImpl().downloadReport(FileDetailFragment.this.fileDetail.getFileId());
                }

                @Override
                public void onPause(DownloadInfo downloadInfo) {
                    FileDetailFragment fileDetailFragment = FileDetailFragment.this;
                    if (fileDetailFragment.fileDetail == null) {
                        return;
                    }
                    fileDetailFragment.downloadButton.setButtonState(0);
                    FileDetailFragment fileDetailFragment2 = FileDetailFragment.this;
                    fileDetailFragment2.downloadButton.setNormalText(fileDetailFragment2.getText(com.uusafe.base.commsdk.view.R.string.uu_mos_app_state_continue));
                    FileDetailFragment.this.downloadButton.postInvalidate();
                }

                @Override
                public void onProgress(DownloadInfo downloadInfo) {
                    FileDetailFragment fileDetailFragment = FileDetailFragment.this;
                    if (fileDetailFragment.fileDetail == null) {
                        return;
                    }
                    fileDetailFragment.downloadButton.setButtonState(1);
                    FileDetailFragment.this.downloadButton.setProgressText((int) (downloadInfo.getFraction() * 100.0f));
                }
            };
        }
    }

    @Override
    public void initView(Bundle bundle) {
        this.downloadButton = (DownloadButton) findViewById(R.id.btn_file_download);
        this.ll_file_info = (LinearLayout) findViewById(R.id.ll_file_info);
        this.img_file_icon = (ImageView) findViewById(R.id.img_file_icon);
        this.txt_fileName = (TextView) findViewById(R.id.txt_fileName);
        this.txt_fileSize = (TextView) findViewById(R.id.txt_fileSize);
        this.webview_file_preview = (WebView) findViewById(R.id.webview_file_preview);
        this.webview_file_preview.setBackgroundColor(0);
        setWebview();
        BaseGlobal.getInstance().setWaterMarkDrawable((RelativeLayout) findViewById(R.id.feature_contact_fragment_contact_rl));
    }

    @Override
    public void onActivityCreated(@Nullable Bundle bundle) {
        super.onActivityCreated(bundle);
    }

    @Override
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public boolean onBackPressedSupport() {
        return super.onBackPressedSupport();
    }

    @Override
    public void onClick(View view) {
        view.getId();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.fileDetail = null;
        this.downloadListener = null;
        this.webview_file_preview.destroy();
        this.webview_file_preview = null;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    @Override
    public void onRightButtonClick(View view) {
    }

    @Override
    public void onSupportInvisible() {
        super.onSupportInvisible();
        hideSoftInput();
    }

    @Override
    protected void restoreView() {
    }

    @Override
    public void setListener() {
    }

    void setWebview() {
        WebSettings settings = this.webview_file_preview.getSettings();
        settings.setAllowFileAccess(false);
        String userAgentString = settings.getUserAgentString();
        settings.setSavePassword(false);
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
        settings.setUseWideViewPort(true);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setLoadWithOverviewMode(true);
        settings.setUserAgentString(userAgentString + "; Mbs/3.6.5.2");
        this.webview_file_preview.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedSslError(WebView webView, final SslErrorHandler sslErrorHandler, SslError sslError) {
                if (SSLHelper.sMbsSSL_Mode_Value.equals(DevicePolicyWrapper.DEFAULT_ID) && webView != null) {
                    FileDetailFragment fileDetailFragment = FileDetailFragment.this;
                    fileDetailFragment.mDialog = new CommonDialog.Builder(fileDetailFragment.mActivity).setTitleShow(false).setMessage(FileDetailFragment.this.getText(R.string.h5sdk_network_https)).setCancelable(false).setPositiveListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            sslErrorHandler.proceed();
                            FileDetailFragment.this.mDialog.dismiss();
                        }
                    }).setNegativeListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            sslErrorHandler.cancel();
                            FileDetailFragment.this.mDialog.dismiss();
                        }
                    }).create();
                    FileDetailFragment.this.mDialog.show();
                    return;
                }
                super.onReceivedSslError(webView, sslErrorHandler, sslError);
            }

            @Override
            @TargetApi(21)
            public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
                if (FileDetailFragment.this.webview_file_preview == null) {
                    return null;
                }
                if (SSLHelper.sMbsSSL_Mode_Value.equals(DevicePolicyWrapper.DEFAULT_ID)) {
                    return super.shouldInterceptRequest(webView, webResourceRequest);
                }
                try {
                    Response execute = NetClient.getInstance().getOkHttpClient().newCall(new Request.Builder().url(new URL(webResourceRequest.getUrl().toString())).build()).execute();
                    InputStream byteStream = execute.body().byteStream();
                    String type = execute.body().contentType().type();
                    String header = execute.header("Content-Encoding");
                    if (type != null) {
                        if (type.contains(";")) {
                            type = type.split(";")[0].trim();
                        }
                        return new WebResourceResponse(type, header, byteStream);
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                return null;
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView webView, String str) {
                webView.loadUrl(str);
                return true;
            }
        });
    }

    @n
    public void startBrother(StartFragmentEvent startFragmentEvent) {
        Activity currentActivity = ActivityLifeController.currentActivity();
        if (currentActivity == null || currentActivity == this.mActivity) {
            if (startFragmentEvent.target == ARouterConfig.OpenTarget._SELF) {
                startWithPop(startFragmentEvent.targetFragment);
            } else {
                start(startFragmentEvent.targetFragment);
            }
        }
    }
}