mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
Clean code
This commit is contained in:
@ -87,8 +87,13 @@ class ReadTextActivity : SimpleActivity() {
|
|||||||
super.onActivityResult(requestCode, resultCode, resultData)
|
super.onActivityResult(requestCode, resultCode, resultData)
|
||||||
if (requestCode == SELECT_SAVE_FILE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
|
if (requestCode == SELECT_SAVE_FILE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
|
||||||
val outputStream = contentResolver.openOutputStream(resultData.data!!)
|
val outputStream = contentResolver.openOutputStream(resultData.data!!)
|
||||||
saveTextContent(outputStream, shouldExitAfterSaving = requestCode == SELECT_SAVE_FILE_AND_EXIT_INTENT,
|
|
||||||
shouldOverwriteOriginalText = getRealPathFromURI(intent.data!!) == filePath)
|
val shouldExitAfterSaving = requestCode == SELECT_SAVE_FILE_AND_EXIT_INTENT
|
||||||
|
|
||||||
|
val selectedFilePath = getRealPathFromURI(intent.data!!)
|
||||||
|
val shouldOverwriteOriginalText = selectedFilePath == filePath
|
||||||
|
|
||||||
|
saveTextContent(outputStream, shouldExitAfterSaving, shouldOverwriteOriginalText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +138,7 @@ class ReadTextActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (filePath.isEmpty()) {
|
if (filePath.isEmpty()) {
|
||||||
SaveAsDialog(this, filePath, true) { path, filename ->
|
SaveAsDialog(this, filePath, true) { _, filename ->
|
||||||
Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||||
type = "text/plain"
|
type = "text/plain"
|
||||||
putExtra(Intent.EXTRA_TITLE, filename)
|
putExtra(Intent.EXTRA_TITLE, filename)
|
||||||
@ -148,12 +153,13 @@ class ReadTextActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SaveAsDialog(this, filePath, false) { path, filename ->
|
SaveAsDialog(this, filePath, false) { path, _ ->
|
||||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
handlePermission(PERMISSION_WRITE_STORAGE) { isPermissionGranted ->
|
||||||
if (it) {
|
if (isPermissionGranted) {
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
getFileOutputStream(file.toFileDirItem(this), true) {
|
getFileOutputStream(file.toFileDirItem(this), true) {
|
||||||
saveTextContent(it, shouldExitAfterSaving, shouldOverwriteOriginalText = path == filePath)
|
val shouldOverwriteOriginalText = path == filePath
|
||||||
|
saveTextContent(it, shouldExitAfterSaving, shouldOverwriteOriginalText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user