riku
2025-07-02 3013b813e5df6977c0be921928f73b1a3adde290
app/src/main/java/cn/flightfeather/thirdappmodule/module/common/OfficeFileReadFragment.kt
@@ -14,6 +14,7 @@
import cn.flightfeather.thirdappmodule.util.file.FileUtils
import com.tencent.smtt.sdk.QbSdk
import com.tencent.smtt.sdk.TbsReaderView
import com.tencent.smtt.sdk.WebView
import kotlinx.android.synthetic.main.fragment_office_file.*
import org.json.JSONException
import org.json.JSONObject
@@ -56,6 +57,7 @@
    private var fileName: String? = ""
    private lateinit var tbsReaderView: TbsReaderView
    private lateinit var webView: WebView
    override fun getLayoutId(): Int = R.layout.fragment_office_file
@@ -82,12 +84,16 @@
    override fun onDetach() {
        super.onDetach()
        tbsReaderView.onStop()
//        tbsReaderView.onStop()
//        web_view.stopLoading()
        web_view.destroy()
    }
    override fun onDestroy() {
        super.onDestroy()
        tbsReaderView.onStop()
//        tbsReaderView.onStop()
//        web_view.stopLoading()
        web_view.destroy()
    }
    private fun init() {
@@ -107,8 +113,9 @@
    }
    private fun openLocalFile() {
        tbsReaderView = TbsReaderView(context, null)
        tbs_reader_container.addView(tbsReaderView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
//        tbsReaderView = TbsReaderView(context, null)
//        tbs_reader_container.addView(tbsReaderView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
//        tbs_reader_container.addView(web_view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        if (!filePath.isNullOrEmpty()) {
            val tempFile = File("/storage/emulated/0/TbsReaderTemp")
            if (!tempFile.exists()) {
@@ -122,10 +129,11 @@
                    "tempPath",
                    Environment.getExternalStorageDirectory().path + File.separator + "TbsReaderTemp"
            )
            val result = tbsReaderView.preOpen(FileUtils.getExtensionName(filePath), false)
            if (result) {
                tbsReaderView.openFile(localBundle)
            }
            web_view.loadUrl(filePath)
//            val result = tbsReaderView.preOpen(FileUtils.getExtensionName(filePath), false)
//            if (result) {
//                tbsReaderView.openFile(localBundle)
//            }
        }
    }
}