check proper permission at saving file in ReadTextActivity

This commit is contained in:
tibbi 2023-01-15 10:49:00 +01:00
parent ce4952751d
commit 4baca371f0
3 changed files with 44 additions and 36 deletions

View File

@ -345,15 +345,6 @@ class MainActivity : SimpleActivity() {
} }
} }
@SuppressLint("NewApi")
private fun hasStoragePermission(): Boolean {
return if (isRPlus()) {
Environment.isExternalStorageManager()
} else {
hasPermission(PERMISSION_WRITE_STORAGE)
}
}
private fun initFileManager(refreshRecents: Boolean) { private fun initFileManager(refreshRecents: Boolean) {
if (intent.action == Intent.ACTION_VIEW && intent.data != null) { if (intent.action == Intent.ACTION_VIEW && intent.data != null) {
val data = intent.data val data = intent.data

View File

@ -15,7 +15,10 @@ import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
import com.simplemobiletools.commons.helpers.SAVE_DISCARD_PROMPT_INTERVAL
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.views.MyEditText import com.simplemobiletools.commons.views.MyEditText
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.dialogs.SaveAsDialog import com.simplemobiletools.filemanager.pro.dialogs.SaveAsDialog
@ -170,14 +173,14 @@ class ReadTextActivity : SimpleActivity() {
} }
} else { } else {
SaveAsDialog(this, filePath, false) { path, _ -> SaveAsDialog(this, filePath, false) { path, _ ->
handlePermission(PERMISSION_WRITE_STORAGE) { isPermissionGranted -> if (hasStoragePermission()) {
if (isPermissionGranted) { val file = File(path)
val file = File(path) getFileOutputStream(file.toFileDirItem(this), true) {
getFileOutputStream(file.toFileDirItem(this), true) { val shouldOverwriteOriginalText = path == filePath
val shouldOverwriteOriginalText = path == filePath saveTextContent(it, shouldExitAfterSaving, shouldOverwriteOriginalText)
saveTextContent(it, shouldExitAfterSaving, shouldOverwriteOriginalText)
}
} }
} else {
toast(R.string.no_storage_permissions)
} }
} }
} }

View File

@ -1,30 +1,44 @@
package com.simplemobiletools.filemanager.pro.activities package com.simplemobiletools.filemanager.pro.activities
import android.annotation.SuppressLint
import android.os.Environment
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.hasPermission
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
open class SimpleActivity : BaseSimpleActivity() { open class SimpleActivity : BaseSimpleActivity() {
override fun getAppIconIDs() = arrayListOf( override fun getAppIconIDs() = arrayListOf(
R.mipmap.ic_launcher_red, R.mipmap.ic_launcher_red,
R.mipmap.ic_launcher_pink, R.mipmap.ic_launcher_pink,
R.mipmap.ic_launcher_purple, R.mipmap.ic_launcher_purple,
R.mipmap.ic_launcher_deep_purple, R.mipmap.ic_launcher_deep_purple,
R.mipmap.ic_launcher_indigo, R.mipmap.ic_launcher_indigo,
R.mipmap.ic_launcher_blue, R.mipmap.ic_launcher_blue,
R.mipmap.ic_launcher_light_blue, R.mipmap.ic_launcher_light_blue,
R.mipmap.ic_launcher_cyan, R.mipmap.ic_launcher_cyan,
R.mipmap.ic_launcher_teal, R.mipmap.ic_launcher_teal,
R.mipmap.ic_launcher_green, R.mipmap.ic_launcher_green,
R.mipmap.ic_launcher_light_green, R.mipmap.ic_launcher_light_green,
R.mipmap.ic_launcher_lime, R.mipmap.ic_launcher_lime,
R.mipmap.ic_launcher_yellow, R.mipmap.ic_launcher_yellow,
R.mipmap.ic_launcher_amber, R.mipmap.ic_launcher_amber,
R.mipmap.ic_launcher, R.mipmap.ic_launcher,
R.mipmap.ic_launcher_deep_orange, R.mipmap.ic_launcher_deep_orange,
R.mipmap.ic_launcher_brown, R.mipmap.ic_launcher_brown,
R.mipmap.ic_launcher_blue_grey, R.mipmap.ic_launcher_blue_grey,
R.mipmap.ic_launcher_grey_black R.mipmap.ic_launcher_grey_black
) )
override fun getAppLauncherName() = getString(R.string.app_launcher_name) override fun getAppLauncherName() = getString(R.string.app_launcher_name)
@SuppressLint("NewApi")
fun hasStoragePermission(): Boolean {
return if (isRPlus()) {
Environment.isExternalStorageManager()
} else {
hasPermission(PERMISSION_WRITE_STORAGE)
}
}
} }