@@ -144,6 +144,7 @@ class ReadTextActivity : SimpleActivity() {
144144 when (menuItem.itemId) {
145145 R .id.menu_search -> openSearch()
146146 R .id.menu_save -> saveText()
147+ R .id.menu_save_as -> saveAsText()
147148 R .id.menu_open_with -> openPath(intent.dataString!! , true )
148149 R .id.menu_print -> printText()
149150 else -> return @setOnMenuItemClickListener false
@@ -165,10 +166,14 @@ class ReadTextActivity : SimpleActivity() {
165166 }, 250 )
166167 }
167168
168- private fun saveText ( shouldExitAfterSaving : Boolean = false ) {
169+ private fun updateFilePath ( ) {
169170 if (filePath.isEmpty()) {
170171 filePath = getRealPathFromURI(intent.data!! ) ? : " "
171172 }
173+ }
174+
175+ private fun saveAsText (shouldExitAfterSaving : Boolean = false) {
176+ updateFilePath()
172177
173178 if (filePath.isEmpty()) {
174179 SaveAsDialog (this , filePath, true ) { _, filename ->
@@ -182,6 +187,7 @@ class ReadTextActivity : SimpleActivity() {
182187 } else {
183188 SELECT_SAVE_FILE_INTENT
184189 }
190+ @Suppress(" DEPRECATION" )
185191 startActivityForResult(this , requestCode)
186192 }
187193 }
@@ -200,6 +206,21 @@ class ReadTextActivity : SimpleActivity() {
200206 }
201207 }
202208
209+ private fun saveText (shouldExitAfterSaving : Boolean = false) {
210+ updateFilePath()
211+
212+ if (filePath.isEmpty()) {
213+ saveAsText(shouldExitAfterSaving)
214+ } else if (hasStoragePermission()) {
215+ val file = File (filePath)
216+ getFileOutputStream(file.toFileDirItem(this ), true ) {
217+ saveTextContent(it, shouldExitAfterSaving, true )
218+ }
219+ } else {
220+ toast(R .string.no_storage_permissions)
221+ }
222+ }
223+
203224 private fun saveTextContent (outputStream : OutputStream ? , shouldExitAfterSaving : Boolean , shouldOverwriteOriginalText : Boolean ) {
204225 if (outputStream != null ) {
205226 val currentText = binding.readTextView.text.toString()
0 commit comments