Skip to content

Commit 4baca37

Browse files
committed
check proper permission at saving file in ReadTextActivity
1 parent ce49527 commit 4baca37

3 files changed

Lines changed: 44 additions & 36 deletions

File tree

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,6 @@ class MainActivity : SimpleActivity() {
345345
}
346346
}
347347

348-
@SuppressLint("NewApi")
349-
private fun hasStoragePermission(): Boolean {
350-
return if (isRPlus()) {
351-
Environment.isExternalStorageManager()
352-
} else {
353-
hasPermission(PERMISSION_WRITE_STORAGE)
354-
}
355-
}
356-
357348
private fun initFileManager(refreshRecents: Boolean) {
358349
if (intent.action == Intent.ACTION_VIEW && intent.data != null) {
359350
val data = intent.data

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/ReadTextActivity.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import android.widget.ImageView
1515
import android.widget.TextView
1616
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
1717
import com.simplemobiletools.commons.extensions.*
18-
import com.simplemobiletools.commons.helpers.*
18+
import com.simplemobiletools.commons.helpers.NavigationIcon
19+
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
20+
import com.simplemobiletools.commons.helpers.SAVE_DISCARD_PROMPT_INTERVAL
21+
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
1922
import com.simplemobiletools.commons.views.MyEditText
2023
import com.simplemobiletools.filemanager.pro.R
2124
import com.simplemobiletools.filemanager.pro.dialogs.SaveAsDialog
@@ -170,14 +173,14 @@ class ReadTextActivity : SimpleActivity() {
170173
}
171174
} else {
172175
SaveAsDialog(this, filePath, false) { path, _ ->
173-
handlePermission(PERMISSION_WRITE_STORAGE) { isPermissionGranted ->
174-
if (isPermissionGranted) {
175-
val file = File(path)
176-
getFileOutputStream(file.toFileDirItem(this), true) {
177-
val shouldOverwriteOriginalText = path == filePath
178-
saveTextContent(it, shouldExitAfterSaving, shouldOverwriteOriginalText)
179-
}
176+
if (hasStoragePermission()) {
177+
val file = File(path)
178+
getFileOutputStream(file.toFileDirItem(this), true) {
179+
val shouldOverwriteOriginalText = path == filePath
180+
saveTextContent(it, shouldExitAfterSaving, shouldOverwriteOriginalText)
180181
}
182+
} else {
183+
toast(R.string.no_storage_permissions)
181184
}
182185
}
183186
}
Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
package com.simplemobiletools.filemanager.pro.activities
22

3+
import android.annotation.SuppressLint
4+
import android.os.Environment
35
import com.simplemobiletools.commons.activities.BaseSimpleActivity
6+
import com.simplemobiletools.commons.extensions.hasPermission
7+
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
8+
import com.simplemobiletools.commons.helpers.isRPlus
49
import com.simplemobiletools.filemanager.pro.R
510

611
open class SimpleActivity : BaseSimpleActivity() {
712
override fun getAppIconIDs() = arrayListOf(
8-
R.mipmap.ic_launcher_red,
9-
R.mipmap.ic_launcher_pink,
10-
R.mipmap.ic_launcher_purple,
11-
R.mipmap.ic_launcher_deep_purple,
12-
R.mipmap.ic_launcher_indigo,
13-
R.mipmap.ic_launcher_blue,
14-
R.mipmap.ic_launcher_light_blue,
15-
R.mipmap.ic_launcher_cyan,
16-
R.mipmap.ic_launcher_teal,
17-
R.mipmap.ic_launcher_green,
18-
R.mipmap.ic_launcher_light_green,
19-
R.mipmap.ic_launcher_lime,
20-
R.mipmap.ic_launcher_yellow,
21-
R.mipmap.ic_launcher_amber,
22-
R.mipmap.ic_launcher,
23-
R.mipmap.ic_launcher_deep_orange,
24-
R.mipmap.ic_launcher_brown,
25-
R.mipmap.ic_launcher_blue_grey,
26-
R.mipmap.ic_launcher_grey_black
13+
R.mipmap.ic_launcher_red,
14+
R.mipmap.ic_launcher_pink,
15+
R.mipmap.ic_launcher_purple,
16+
R.mipmap.ic_launcher_deep_purple,
17+
R.mipmap.ic_launcher_indigo,
18+
R.mipmap.ic_launcher_blue,
19+
R.mipmap.ic_launcher_light_blue,
20+
R.mipmap.ic_launcher_cyan,
21+
R.mipmap.ic_launcher_teal,
22+
R.mipmap.ic_launcher_green,
23+
R.mipmap.ic_launcher_light_green,
24+
R.mipmap.ic_launcher_lime,
25+
R.mipmap.ic_launcher_yellow,
26+
R.mipmap.ic_launcher_amber,
27+
R.mipmap.ic_launcher,
28+
R.mipmap.ic_launcher_deep_orange,
29+
R.mipmap.ic_launcher_brown,
30+
R.mipmap.ic_launcher_blue_grey,
31+
R.mipmap.ic_launcher_grey_black
2732
)
2833

2934
override fun getAppLauncherName() = getString(R.string.app_launcher_name)
35+
36+
@SuppressLint("NewApi")
37+
fun hasStoragePermission(): Boolean {
38+
return if (isRPlus()) {
39+
Environment.isExternalStorageManager()
40+
} else {
41+
hasPermission(PERMISSION_WRITE_STORAGE)
42+
}
43+
}
3044
}

0 commit comments

Comments
 (0)