| | |
| | | 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 |
| | |
| | | private var fileName: String? = "" |
| | | |
| | | private lateinit var tbsReaderView: TbsReaderView |
| | | private lateinit var webView: WebView |
| | | |
| | | override fun getLayoutId(): Int = R.layout.fragment_office_file |
| | | |
| | |
| | | |
| | | 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() { |
| | |
| | | } |
| | | |
| | | 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()) { |
| | |
| | | "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) |
| | | // } |
| | | } |
| | | } |
| | | } |