From 4baca371f0a97dead8d2817705d9e65a02aec21d Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 15 Jan 2023 10:49:00 +0100 Subject: [PATCH] check proper permission at saving file in ReadTextActivity --- .../pro/activities/MainActivity.kt | 9 ---- .../pro/activities/ReadTextActivity.kt | 19 ++++--- .../pro/activities/SimpleActivity.kt | 52 ++++++++++++------- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index b3a58c17..99961983 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -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) { if (intent.action == Intent.ACTION_VIEW && intent.data != null) { val data = intent.data diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/ReadTextActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/ReadTextActivity.kt index 03183d7a..ac9e1669 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/ReadTextActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/ReadTextActivity.kt @@ -15,7 +15,10 @@ import android.widget.ImageView import android.widget.TextView import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog 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.filemanager.pro.R import com.simplemobiletools.filemanager.pro.dialogs.SaveAsDialog @@ -170,14 +173,14 @@ class ReadTextActivity : SimpleActivity() { } } else { SaveAsDialog(this, filePath, false) { path, _ -> - handlePermission(PERMISSION_WRITE_STORAGE) { isPermissionGranted -> - if (isPermissionGranted) { - val file = File(path) - getFileOutputStream(file.toFileDirItem(this), true) { - val shouldOverwriteOriginalText = path == filePath - saveTextContent(it, shouldExitAfterSaving, shouldOverwriteOriginalText) - } + if (hasStoragePermission()) { + val file = File(path) + getFileOutputStream(file.toFileDirItem(this), true) { + val shouldOverwriteOriginalText = path == filePath + saveTextContent(it, shouldExitAfterSaving, shouldOverwriteOriginalText) } + } else { + toast(R.string.no_storage_permissions) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SimpleActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SimpleActivity.kt index 30231be1..54f7733b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SimpleActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SimpleActivity.kt @@ -1,30 +1,44 @@ package com.simplemobiletools.filemanager.pro.activities +import android.annotation.SuppressLint +import android.os.Environment 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 open class SimpleActivity : BaseSimpleActivity() { override fun getAppIconIDs() = arrayListOf( - R.mipmap.ic_launcher_red, - R.mipmap.ic_launcher_pink, - R.mipmap.ic_launcher_purple, - R.mipmap.ic_launcher_deep_purple, - R.mipmap.ic_launcher_indigo, - R.mipmap.ic_launcher_blue, - R.mipmap.ic_launcher_light_blue, - R.mipmap.ic_launcher_cyan, - R.mipmap.ic_launcher_teal, - R.mipmap.ic_launcher_green, - R.mipmap.ic_launcher_light_green, - R.mipmap.ic_launcher_lime, - R.mipmap.ic_launcher_yellow, - R.mipmap.ic_launcher_amber, - R.mipmap.ic_launcher, - R.mipmap.ic_launcher_deep_orange, - R.mipmap.ic_launcher_brown, - R.mipmap.ic_launcher_blue_grey, - R.mipmap.ic_launcher_grey_black + R.mipmap.ic_launcher_red, + R.mipmap.ic_launcher_pink, + R.mipmap.ic_launcher_purple, + R.mipmap.ic_launcher_deep_purple, + R.mipmap.ic_launcher_indigo, + R.mipmap.ic_launcher_blue, + R.mipmap.ic_launcher_light_blue, + R.mipmap.ic_launcher_cyan, + R.mipmap.ic_launcher_teal, + R.mipmap.ic_launcher_green, + R.mipmap.ic_launcher_light_green, + R.mipmap.ic_launcher_lime, + R.mipmap.ic_launcher_yellow, + R.mipmap.ic_launcher_amber, + R.mipmap.ic_launcher, + R.mipmap.ic_launcher_deep_orange, + R.mipmap.ic_launcher_brown, + R.mipmap.ic_launcher_blue_grey, + R.mipmap.ic_launcher_grey_black ) override fun getAppLauncherName() = getString(R.string.app_launcher_name) + + @SuppressLint("NewApi") + fun hasStoragePermission(): Boolean { + return if (isRPlus()) { + Environment.isExternalStorageManager() + } else { + hasPermission(PERMISSION_WRITE_STORAGE) + } + } }