Commit 8a23d1da authored by topjohnwu's avatar topjohnwu

Do not run setMarkdown on I/O thread

parent d3eb61e0
...@@ -10,6 +10,7 @@ import com.topjohnwu.magisk.di.ServiceLocator ...@@ -10,6 +10,7 @@ import com.topjohnwu.magisk.di.ServiceLocator
import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.magisk.view.MagiskDialog
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber import timber.log.Timber
import java.io.IOException import java.io.IOException
...@@ -23,12 +24,13 @@ abstract class MarkDownDialog : DialogEvent() { ...@@ -23,12 +24,13 @@ abstract class MarkDownDialog : DialogEvent() {
val view = LayoutInflater.from(context).inflate(R.layout.markdown_window_md2, null) val view = LayoutInflater.from(context).inflate(R.layout.markdown_window_md2, null)
setView(view) setView(view)
val tv = view.findViewById<TextView>(R.id.md_txt) val tv = view.findViewById<TextView>(R.id.md_txt)
(ownerActivity as BaseActivity).lifecycleScope.launch(Dispatchers.IO) { (ownerActivity as BaseActivity).lifecycleScope.launch {
try { try {
ServiceLocator.markwon.setMarkdown(tv, getMarkdownText()) val text = withContext(Dispatchers.IO) { getMarkdownText() }
ServiceLocator.markwon.setMarkdown(tv, text)
} catch (e: IOException) { } catch (e: IOException) {
Timber.e(e) Timber.e(e)
tv.post { tv.setText(R.string.download_file_error) } tv.setText(R.string.download_file_error)
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment