@@ -16,6 +16,7 @@ import androidx.core.view.MenuItemCompat
1616import com.simplemobiletools.commons.extensions.*
1717import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
1818import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
19+ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
1920import com.simplemobiletools.commons.models.FileDirItem
2021import com.simplemobiletools.filemanager.pro.R
2122import com.simplemobiletools.filemanager.pro.dialogs.SaveAsDialog
@@ -41,7 +42,9 @@ class ReadTextActivity : SimpleActivity() {
4142
4243 handlePermission(PERMISSION_WRITE_STORAGE ) {
4344 if (it) {
44- checkIntent()
45+ read_text_view.onGlobalLayout {
46+ checkIntent()
47+ }
4548 } else {
4649 toast(R .string.no_storage_permissions)
4750 finish()
@@ -160,30 +163,34 @@ class ReadTextActivity : SimpleActivity() {
160163 return
161164 }
162165
163- originalText = if (uri.scheme == " file" ) {
164- filePath = uri.path
165- val file = File (filePath)
166- if (file.exists()) {
167- file.readText()
166+ ensureBackgroundThread {
167+ originalText = if (uri.scheme == " file" ) {
168+ filePath = uri.path
169+ val file = File (filePath)
170+ if (file.exists()) {
171+ file.readText()
172+ } else {
173+ toast(R .string.unknown_error_occurred)
174+ " "
175+ }
168176 } else {
169- toast(R .string.unknown_error_occurred)
170- " "
171- }
172- } else {
173- try {
174- contentResolver.openInputStream(uri).bufferedReader().use { it.readText() }
175- } catch (e: Exception ) {
176- showErrorToast(e)
177- finish()
178- return
177+ try {
178+ contentResolver.openInputStream(uri).bufferedReader().use { it.readText() }
179+ } catch (e: Exception ) {
180+ showErrorToast(e)
181+ finish()
182+ return @ensureBackgroundThread
183+ }
179184 }
180- }
181185
182- read_text_view.setText(originalText)
183- if (originalText.isNotEmpty()) {
184- hideKeyboard()
185- } else {
186- showKeyboard(read_text_view)
186+ runOnUiThread {
187+ read_text_view.setText(originalText)
188+ if (originalText.isNotEmpty()) {
189+ hideKeyboard()
190+ } else {
191+ showKeyboard(read_text_view)
192+ }
193+ }
187194 }
188195 }
189196}
0 commit comments