show file name at ReadTextActivity if available

This commit is contained in:
tibbi 2022-05-15 20:19:24 +02:00
parent 376b521170
commit e0802b72fe
1 changed files with 49 additions and 44 deletions

View File

@ -54,13 +54,32 @@ class ReadTextActivity : SimpleActivity() {
searchPrevBtn = findViewById(R.id.search_previous) searchPrevBtn = findViewById(R.id.search_previous)
searchNextBtn = findViewById(R.id.search_next) searchNextBtn = findViewById(R.id.search_next)
searchClearBtn = findViewById(R.id.search_clear) searchClearBtn = findViewById(R.id.search_clear)
read_text_view.setTextColor(config.textColor)
if (checkAppSideloading()) { if (checkAppSideloading()) {
return return
} }
val uri = if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
Uri.fromFile(File(intent.extras?.get(REAL_FILE_PATH).toString()))
} else {
intent.data
}
if (uri == null) {
finish()
return
}
val filename = getFilenameFromUri(uri)
if (filename.isNotEmpty()) {
title = filename
}
read_text_view.onGlobalLayout { read_text_view.onGlobalLayout {
checkIntent() ensureBackgroundThread {
checkIntent(uri)
}
} }
setupSearchButtons() setupSearchButtons()
@ -213,20 +232,7 @@ class ReadTextActivity : SimpleActivity() {
} }
} }
private fun checkIntent() { private fun checkIntent(uri: Uri) {
read_text_view.setTextColor(config.textColor)
val uri = if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
Uri.fromFile(File(intent.extras?.get(REAL_FILE_PATH).toString()))
} else {
intent.data
}
if (uri == null) {
finish()
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)
@ -246,11 +252,11 @@ class ReadTextActivity : SimpleActivity() {
contentResolver.openInputStream(uri)!!.bufferedReader().use { it.readText() } contentResolver.openInputStream(uri)!!.bufferedReader().use { it.readText() }
} catch (e: OutOfMemoryError) { } catch (e: OutOfMemoryError) {
showErrorToast(e.toString()) showErrorToast(e.toString())
return@ensureBackgroundThread return
} catch (e: Exception) { } catch (e: Exception) {
showErrorToast(e) showErrorToast(e)
finish() finish()
return@ensureBackgroundThread return
} }
} }
@ -263,7 +269,6 @@ class ReadTextActivity : SimpleActivity() {
} }
} }
} }
}
private fun setupSearchButtons() { private fun setupSearchButtons() {
searchQueryET.onTextChangeListener { searchQueryET.onTextChangeListener {