improve threading at the file editor to better handle large files

This commit is contained in:
tibbi 2019-08-28 22:40:35 +02:00
parent 9b00f60543
commit 87c2eef8bc
1 changed files with 29 additions and 22 deletions

View File

@ -16,6 +16,7 @@ import androidx.core.view.MenuItemCompat
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.dialogs.SaveAsDialog
@ -41,7 +42,9 @@ class ReadTextActivity : SimpleActivity() {
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
read_text_view.onGlobalLayout {
checkIntent()
}
} else {
toast(R.string.no_storage_permissions)
finish()
@ -160,6 +163,7 @@ class ReadTextActivity : SimpleActivity() {
return
}
ensureBackgroundThread {
originalText = if (uri.scheme == "file") {
filePath = uri.path
val file = File(filePath)
@ -175,10 +179,11 @@ class ReadTextActivity : SimpleActivity() {
} catch (e: Exception) {
showErrorToast(e)
finish()
return
return@ensureBackgroundThread
}
}
runOnUiThread {
read_text_view.setText(originalText)
if (originalText.isNotEmpty()) {
hideKeyboard()
@ -186,4 +191,6 @@ class ReadTextActivity : SimpleActivity() {
showKeyboard(read_text_view)
}
}
}
}
}