mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
allow saving files in the file editor
This commit is contained in:
@ -3,14 +3,20 @@ package com.simplemobiletools.filemanager.activities
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.simplemobiletools.commons.extensions.getFileOutputStream
|
||||
import com.simplemobiletools.commons.extensions.getRealPathFromURI
|
||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||
import com.simplemobiletools.filemanager.R
|
||||
import com.simplemobiletools.filemanager.dialogs.SaveAsDialog
|
||||
import com.simplemobiletools.filemanager.extensions.config
|
||||
import kotlinx.android.synthetic.main.activity_read_text.*
|
||||
import java.io.File
|
||||
|
||||
class ReadTextActivity : SimpleActivity() {
|
||||
var filePath = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_read_text)
|
||||
@ -39,13 +45,28 @@ class ReadTextActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun saveText() {
|
||||
if (filePath.isEmpty()) {
|
||||
filePath = getRealPathFromURI(intent.data) ?: ""
|
||||
}
|
||||
|
||||
SaveAsDialog(this, filePath) {
|
||||
getFileOutputStream(File(it)) {
|
||||
if (it != null) {
|
||||
it.bufferedWriter().use { it.write(read_text_view.text.toString()) }
|
||||
toast(R.string.file_saved)
|
||||
hideKeyboard()
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkIntent() {
|
||||
read_text_view.setTextColor(config.textColor)
|
||||
val uri = intent.data
|
||||
val text = if (uri.scheme == "file") {
|
||||
filePath = uri.path
|
||||
File(uri.path).readText()
|
||||
} else {
|
||||
contentResolver.openInputStream(uri).bufferedReader().use { it.readText() }
|
||||
|
Reference in New Issue
Block a user