mirror of
https://github.com/FossifyOrg/File-Manager.git
synced 2025-12-23 23:57:55 -05:00
fix: request permission in SaveAsActivity on first-run (#271)
* Fix "Replace characters on save as function, FileNotFoundException" #250 * Update CHANGELOG.md update changelog * Update app/src/main/kotlin/org/fossify/filemanager/activities/SaveAsActivity.kt Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> * Update CHANGELOG.md Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> * Update CHANGELOG.md Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> * Merge branch 'FossifyOrg:main' into main Signed-off-by: Jan Guegel <jan@guegel.eu> * Update CHANGELOG.md * fix PR Feedback Signed-off-by: Jan Guegel <jan@guegel.eu> * fix duplicated code by moving it to SimpleActivity.kt Signed-off-by: Jan Guegel <jan@guegel.eu> * moved handleStoragePermissions() to SimpleActivity.kt from MainActivity.kt introduced tryInitFileManager() to SaveAsActivity.kt removed const MANAGE_STORAGE_RC from MainActivity.kt Signed-off-by: Jan Guegel <jan@guegel.eu> * adjusted toast in try catch in storage permission action Signed-off-by: Jan Guegel <jan@guegel.eu> * catch ActivityNotFoundException with fallback of SecurityException Signed-off-by: Jan Guegel <jan@guegel.eu> * Apply suggestions from code review thanks for the feedback! Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> * remove indent Signed-off-by: Jan Guegel <jan@guegel.eu> * adjust changelog Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> --------- Signed-off-by: Jan Guegel <jan@guegel.eu> Co-authored-by: Jan Guegel <jan@guegel.eu> Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> Refs: https://github.com/FossifyOrg/File-Manager/issues/85
This commit is contained in:
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Fixed
|
||||
- Fixed folders showing up incorrectly as files in copy/move dialog ([#267])
|
||||
- Fixed error when saving files with unsupported characters ([#250])
|
||||
- Fixed missing permission prompt on initial "Save as" launch ([#85])
|
||||
|
||||
## [1.2.3] - 2025-09-15
|
||||
### Fixed
|
||||
@@ -76,6 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
[#251]: https://github.com/FossifyOrg/File-Manager/issues/251
|
||||
[#267]: https://github.com/FossifyOrg/File-Manager/issues/267
|
||||
[#250]: https://github.com/FossifyOrg/File-Manager/issues/250
|
||||
[#85]: https://github.com/FossifyOrg/File-Manager/issues/85
|
||||
|
||||
[Unreleased]: https://github.com/FossifyOrg/File-Manager/compare/1.2.3...HEAD
|
||||
[1.2.3]: https://github.com/FossifyOrg/File-Manager/compare/1.2.2...1.2.3
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
package org.fossify.filemanager.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.ClipData
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.os.Handler
|
||||
import android.provider.Settings
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.stericson.RootTools.RootTools
|
||||
import me.grantland.widget.AutofitHelper
|
||||
import org.fossify.commons.dialogs.ConfirmationAdvancedDialog
|
||||
import org.fossify.commons.dialogs.RadioGroupDialog
|
||||
import org.fossify.commons.extensions.appLaunched
|
||||
import org.fossify.commons.extensions.appLockManager
|
||||
@@ -43,7 +38,6 @@ import org.fossify.commons.extensions.launchMoreAppsFromUsIntent
|
||||
import org.fossify.commons.extensions.onGlobalLayout
|
||||
import org.fossify.commons.extensions.onTabSelectionChanged
|
||||
import org.fossify.commons.extensions.sdCardPath
|
||||
import org.fossify.commons.extensions.showErrorToast
|
||||
import org.fossify.commons.extensions.toast
|
||||
import org.fossify.commons.extensions.updateBottomTabItemColors
|
||||
import org.fossify.commons.extensions.viewBinding
|
||||
@@ -59,7 +53,6 @@ import org.fossify.commons.helpers.TAB_RECENT_FILES
|
||||
import org.fossify.commons.helpers.TAB_STORAGE_ANALYSIS
|
||||
import org.fossify.commons.helpers.VIEW_TYPE_GRID
|
||||
import org.fossify.commons.helpers.ensureBackgroundThread
|
||||
import org.fossify.commons.helpers.isRPlus
|
||||
import org.fossify.commons.models.FAQItem
|
||||
import org.fossify.commons.models.RadioItem
|
||||
import org.fossify.commons.models.Release
|
||||
@@ -84,7 +77,6 @@ import java.io.File
|
||||
class MainActivity : SimpleActivity() {
|
||||
companion object {
|
||||
private const val BACK_PRESS_TIMEOUT = 5000
|
||||
private const val MANAGE_STORAGE_RC = 201
|
||||
private const val PICKED_PATH = "picked_path"
|
||||
}
|
||||
|
||||
@@ -281,15 +273,6 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
isAskingPermissions = false
|
||||
if (requestCode == MANAGE_STORAGE_RC && isRPlus()) {
|
||||
actionOnPermission?.invoke(Environment.isExternalStorageManager())
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateMenuColors() {
|
||||
updateStatusbarColor(getProperBackgroundColor())
|
||||
binding.mainMenu.updateColors()
|
||||
@@ -323,38 +306,6 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
private fun handleStoragePermission(callback: (granted: Boolean) -> Unit) {
|
||||
actionOnPermission = null
|
||||
if (hasStoragePermission()) {
|
||||
callback(true)
|
||||
} else {
|
||||
if (isRPlus()) {
|
||||
ConfirmationAdvancedDialog(this, "", R.string.access_storage_prompt, R.string.ok, 0, false) { success ->
|
||||
if (success) {
|
||||
isAskingPermissions = true
|
||||
actionOnPermission = callback
|
||||
try {
|
||||
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
|
||||
intent.addCategory("android.intent.category.DEFAULT")
|
||||
intent.data = Uri.parse("package:$packageName")
|
||||
startActivityForResult(intent, MANAGE_STORAGE_RC)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
val intent = Intent()
|
||||
intent.action = Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION
|
||||
startActivityForResult(intent, MANAGE_STORAGE_RC)
|
||||
}
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handlePermission(PERMISSION_WRITE_STORAGE, callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initFileManager(refreshRecents: Boolean) {
|
||||
if (intent.action == Intent.ACTION_VIEW && intent.data != null) {
|
||||
val data = intent.data
|
||||
|
||||
@@ -18,7 +18,21 @@ class SaveAsActivity : SimpleActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(binding.root)
|
||||
tryInitFileManager()
|
||||
}
|
||||
|
||||
private fun tryInitFileManager() {
|
||||
handleStoragePermission { granted ->
|
||||
if (granted) {
|
||||
saveAsDialog()
|
||||
} else {
|
||||
toast(R.string.no_storage_permissions)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveAsDialog() {
|
||||
if (intent.action == Intent.ACTION_SEND && intent.extras?.containsKey(Intent.EXTRA_STREAM) == true) {
|
||||
FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden(), showFAB = true, showFavoritesButton = true) {
|
||||
val destination = it
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package org.fossify.filemanager.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import org.fossify.commons.activities.BaseSimpleActivity
|
||||
import org.fossify.commons.dialogs.ConfirmationAdvancedDialog
|
||||
import org.fossify.commons.extensions.hasPermission
|
||||
import android.net.Uri
|
||||
import org.fossify.commons.extensions.showErrorToast
|
||||
import org.fossify.commons.extensions.toast
|
||||
import org.fossify.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||
import org.fossify.commons.helpers.isRPlus
|
||||
import org.fossify.filemanager.R
|
||||
@@ -31,10 +37,23 @@ open class SimpleActivity : BaseSimpleActivity() {
|
||||
R.mipmap.ic_launcher_grey_black
|
||||
)
|
||||
|
||||
companion object {
|
||||
private const val MANAGE_STORAGE_RC = 201
|
||||
}
|
||||
|
||||
override fun getAppLauncherName() = getString(R.string.app_launcher_name)
|
||||
|
||||
override fun getRepositoryName() = "File-Manager"
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
isAskingPermissions = false
|
||||
if (requestCode == MANAGE_STORAGE_RC && isRPlus()) {
|
||||
actionOnPermission?.invoke(Environment.isExternalStorageManager())
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun hasStoragePermission(): Boolean {
|
||||
return if (isRPlus()) {
|
||||
@@ -43,4 +62,39 @@ open class SimpleActivity : BaseSimpleActivity() {
|
||||
hasPermission(PERMISSION_WRITE_STORAGE)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
fun handleStoragePermission(callback: (granted: Boolean) -> Unit) {
|
||||
actionOnPermission = null
|
||||
if (hasStoragePermission()) {
|
||||
callback(true)
|
||||
} else {
|
||||
if (isRPlus()) {
|
||||
ConfirmationAdvancedDialog(this, "", R.string.access_storage_prompt, R.string.ok, 0, false) { success ->
|
||||
if (success) {
|
||||
isAskingPermissions = true
|
||||
actionOnPermission = callback
|
||||
try {
|
||||
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
|
||||
intent.addCategory("android.intent.category.DEFAULT")
|
||||
intent.data = Uri.parse("package:$packageName")
|
||||
startActivityForResult(intent, MANAGE_STORAGE_RC)
|
||||
} catch (e: android.content.ActivityNotFoundException) {
|
||||
showErrorToast(e)
|
||||
val intent = Intent()
|
||||
intent.action = Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION
|
||||
startActivityForResult(intent, MANAGE_STORAGE_RC)
|
||||
} catch (e: SecurityException) {
|
||||
showErrorToast(e)
|
||||
finish()
|
||||
}
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handlePermission(PERMISSION_WRITE_STORAGE, callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user