improve threading at the file editor to better handle large files
This commit is contained in:
parent
9b00f60543
commit
87c2eef8bc
|
@ -16,6 +16,7 @@ import androidx.core.view.MenuItemCompat
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.filemanager.pro.R
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
import com.simplemobiletools.filemanager.pro.dialogs.SaveAsDialog
|
import com.simplemobiletools.filemanager.pro.dialogs.SaveAsDialog
|
||||||
|
@ -41,7 +42,9 @@ class ReadTextActivity : SimpleActivity() {
|
||||||
|
|
||||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
read_text_view.onGlobalLayout {
|
||||||
checkIntent()
|
checkIntent()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.no_storage_permissions)
|
toast(R.string.no_storage_permissions)
|
||||||
finish()
|
finish()
|
||||||
|
@ -160,6 +163,7 @@ class ReadTextActivity : SimpleActivity() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensureBackgroundThread {
|
||||||
originalText = if (uri.scheme == "file") {
|
originalText = if (uri.scheme == "file") {
|
||||||
filePath = uri.path
|
filePath = uri.path
|
||||||
val file = File(filePath)
|
val file = File(filePath)
|
||||||
|
@ -175,10 +179,11 @@ class ReadTextActivity : SimpleActivity() {
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
finish()
|
finish()
|
||||||
return
|
return@ensureBackgroundThread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runOnUiThread {
|
||||||
read_text_view.setText(originalText)
|
read_text_view.setText(originalText)
|
||||||
if (originalText.isNotEmpty()) {
|
if (originalText.isNotEmpty()) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
|
@ -187,3 +192,5 @@ class ReadTextActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue