prepare the app for having All files permission

This commit is contained in:
tibbi 2022-05-09 10:44:50 +02:00
parent b3ad40739f
commit c5d9ac6fcc
14 changed files with 56 additions and 42 deletions

View file

@ -7,6 +7,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.extensions.internalStoragePath
import com.simplemobiletools.commons.extensions.isExternalStorageManager
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.gallery.pro.R
@ -29,7 +30,7 @@ class ExcludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener {
beVisibleIf(folders.isEmpty())
setTextColor(getProperTextColor())
if (isRPlus()) {
if (isRPlus() && !isExternalStorageManager()) {
placeholderText = placeholderText.substringBefore("\n")
}

View file

@ -299,13 +299,13 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
findItem(R.id.hide_the_recycle_bin).isVisible = useBin && config.showRecycleBinAtFolders
findItem(R.id.show_the_recycle_bin).isVisible = useBin && !config.showRecycleBinAtFolders
findItem(R.id.set_as_default_folder).isVisible = !config.defaultFolder.isEmpty()
findItem(R.id.create_new_folder).isVisible = !isRPlus()
findItem(R.id.create_new_folder).isVisible = !isRPlus() || isExternalStorageManager()
setupSearch(this)
}
}
menu.findItem(R.id.temporarily_show_hidden).isVisible = !isRPlus() && !config.shouldShowHidden
menu.findItem(R.id.stop_showing_hidden).isVisible = !isRPlus() && config.temporarilyShowHidden
menu.findItem(R.id.temporarily_show_hidden).isVisible = (!isRPlus() || isExternalStorageManager()) && !config.shouldShowHidden
menu.findItem(R.id.stop_showing_hidden).isVisible = (!isRPlus() || isExternalStorageManager()) && config.temporarilyShowHidden
updateMenuItemColors(menu)
return true
@ -932,6 +932,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
}
}
// fetch files from MediaStore only, unless the app has the MANAGE_EXTERNAL_STORAGE permission on Android 11+
val android11Files = mLastMediaFetcher?.getAndroid11FolderMedia(getImagesOnly, getVideosOnly, favoritePaths, false, true, dateTakens)
try {
for (directory in dirs) {
@ -1164,7 +1165,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
directories_empty_placeholder.text = getString(R.string.no_items_found)
directories_empty_placeholder_2.beGone()
} else if (dirs.isEmpty() && config.filterMedia == getDefaultFileFilter()) {
if (isRPlus()) {
if (isRPlus() && !isExternalStorageManager()) {
directories_empty_placeholder.text = getString(R.string.no_items_found)
directories_empty_placeholder_2.beGone()
} else {
@ -1257,7 +1258,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
dirs.filter { !it.areFavorites() && !it.isRecycleBin() }.forEach {
if (!getDoesFilePathExist(it.path, OTGPath)) {
invalidDirs.add(it)
} else if (it.path != config.tempFolderPath && !isRPlus()) {
} else if (it.path != config.tempFolderPath && (!isRPlus() || isExternalStorageManager())) {
// avoid calling file.list() or listfiles() on Android 11+, it became way too slow
val children = if (isPathOnOTG(it.path)) {
getOTGFolderChildrenNames(it.path)

View file

@ -240,8 +240,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
findItem(R.id.about).isVisible = mShowAll
findItem(R.id.create_new_folder).isVisible = !mShowAll && mPath != RECYCLE_BIN && mPath != FAVORITES
findItem(R.id.temporarily_show_hidden).isVisible = !isRPlus() && !config.shouldShowHidden
findItem(R.id.stop_showing_hidden).isVisible = !isRPlus() && config.temporarilyShowHidden
findItem(R.id.temporarily_show_hidden).isVisible = (!isRPlus() || isExternalStorageManager()) && !config.shouldShowHidden
findItem(R.id.stop_showing_hidden).isVisible = (!isRPlus() || isExternalStorageManager()) && config.temporarilyShowHidden
findItem(R.id.set_as_default_folder).isVisible = !isDefaultFolder
findItem(R.id.unset_as_default_folder).isVisible = isDefaultFolder

View file

@ -142,9 +142,9 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
val realPath = intent.extras!!.getString(REAL_FILE_PATH)
if (realPath != null && getDoesFilePathExist(realPath)) {
val avoidShowingHiddenFiles =
isRPlus() && (File(realPath).isHidden || File(realPath.getParentPath(), NOMEDIA).exists() || realPath.contains("/."))
if (!avoidShowingHiddenFiles) {
val isFileFolderHidden = (File(realPath).isHidden || File(realPath.getParentPath(), NOMEDIA).exists() || realPath.contains("/."))
val preventShowingHiddenFile = (isRPlus() && !isExternalStorageManager()) && isFileFolderHidden
if (!preventShowingHiddenFile) {
if (realPath.getFilenameFromPath().contains('.') || filename.contains('.')) {
if (isFileTypeVisible(realPath)) {
bottom_actions.beGone()
@ -168,14 +168,15 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
}
return
} else {
val path = applicationContext.getRealPathFromURI(mUri!!) ?: ""
val avoidShowingHiddenFiles = isRPlus() && File(path).isHidden
if (!avoidShowingHiddenFiles) {
if (path != mUri.toString() && path.isNotEmpty() && mUri!!.authority != "mms" && filename.contains('.') && getDoesFilePathExist(path)) {
if (isFileTypeVisible(path)) {
val realPath = applicationContext.getRealPathFromURI(mUri!!) ?: ""
val isFileFolderHidden = (File(realPath).isHidden || File(realPath.getParentPath(), NOMEDIA).exists() || realPath.contains("/."))
val preventShowingHiddenFile = (isRPlus() && !isExternalStorageManager()) && isFileFolderHidden
if (!preventShowingHiddenFile) {
if (realPath != mUri.toString() && realPath.isNotEmpty() && mUri!!.authority != "mms" && filename.contains('.') && getDoesFilePathExist(realPath)) {
if (isFileTypeVisible(realPath)) {
bottom_actions.beGone()
rescanPaths(arrayListOf(mUri!!.path!!))
sendViewPagerIntent(path)
sendViewPagerIntent(realPath)
finish()
return
}

View file

@ -168,7 +168,7 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupFileLoadingPriority() {
settings_file_loading_priority_holder.beGoneIf(isRPlus())
settings_file_loading_priority_holder.beGoneIf(isRPlus() && !isExternalStorageManager())
settings_file_loading_priority.text = getFileLoadingPriorityText()
settings_file_loading_priority_holder.setOnClickListener {
val items = arrayListOf(
@ -193,7 +193,7 @@ class SettingsActivity : SimpleActivity() {
)
private fun setupManageIncludedFolders() {
settings_manage_included_folders_holder.beGoneIf(isRPlus())
settings_manage_included_folders_holder.beGoneIf(isRPlus() && !isExternalStorageManager())
settings_manage_included_folders_holder.setOnClickListener {
startActivity(Intent(this, IncludedFoldersActivity::class.java))
}
@ -215,7 +215,7 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupShowHiddenItems() {
if (isRPlus()) {
if (isRPlus() && !isExternalStorageManager()) {
settings_show_hidden_items_holder.beGone()
settings_manage_excluded_folders_holder.background = resources.getDrawable(R.drawable.ripple_bottom_corners, theme)
}
@ -315,7 +315,7 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupHiddenItemPasswordProtection() {
settings_hidden_item_password_protection_holder.beGoneIf(isRPlus())
settings_hidden_item_password_protection_holder.beGoneIf(isRPlus() && !isExternalStorageManager())
settings_hidden_item_password_protection.isChecked = config.isHiddenPasswordProtectionOn
settings_hidden_item_password_protection_holder.setOnClickListener {
val tabToShow = if (config.isHiddenPasswordProtectionOn) config.hiddenProtectionType else SHOW_ALL_TABS

View file

@ -203,13 +203,17 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
findItem(R.id.menu_print).isVisible = currentMedium.isImage() || currentMedium.isRaw()
findItem(R.id.menu_resize).isVisible = visibleBottomActions and BOTTOM_ACTION_RESIZE == 0 && currentMedium.isImage()
findItem(R.id.menu_hide).isVisible =
!isRPlus() && !currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
(!isRPlus() || isExternalStorageManager()) && !currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
findItem(R.id.menu_unhide).isVisible =
!isRPlus() && currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
(!isRPlus() || isExternalStorageManager()) && currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
findItem(R.id.menu_add_to_favorites).isVisible =
!currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 && !currentMedium.getIsInRecycleBin()
findItem(R.id.menu_remove_from_favorites).isVisible =
currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 && !currentMedium.getIsInRecycleBin()
findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(recycleBinPath)
findItem(R.id.menu_create_shortcut).isVisible = isOreoPlus()
findItem(R.id.menu_change_orientation).isVisible = rotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0
@ -1188,7 +1192,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val oldPath = getCurrentPath()
val isSDOrOtgRootFolder = isAStorageRootFolder(oldPath.getParentPath()) && !oldPath.startsWith(internalStoragePath)
if (isRPlus() && isSDOrOtgRootFolder) {
if (isRPlus() && isSDOrOtgRootFolder && !isExternalStorageManager()) {
toast(R.string.rename_in_sd_card_system_restriction, Toast.LENGTH_LONG)
return
}

View file

@ -5,12 +5,14 @@ import android.content.pm.ShortcutInfo
import android.content.pm.ShortcutManager
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Icon
import android.os.Build
import android.text.TextUtils
import android.view.Menu
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.annotation.RequiresApi
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
@ -190,8 +192,11 @@ class DirectoryAdapter(
}
private fun checkHideBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
menu.findItem(R.id.cab_hide).isVisible = !isRPlus() && selectedPaths.any { !it.doesThisOrParentHaveNoMedia(HashMap(), null) }
menu.findItem(R.id.cab_unhide).isVisible = !isRPlus() && selectedPaths.any { it.doesThisOrParentHaveNoMedia(HashMap(), null) }
menu.findItem(R.id.cab_hide).isVisible =
(!isRPlus() || isExternalStorageManager()) && selectedPaths.any { !it.doesThisOrParentHaveNoMedia(HashMap(), null) }
menu.findItem(R.id.cab_unhide).isVisible =
(!isRPlus() || isExternalStorageManager()) && selectedPaths.any { it.doesThisOrParentHaveNoMedia(HashMap(), null) }
}
private fun checkPinBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
@ -548,6 +553,7 @@ class DirectoryAdapter(
}
}
@RequiresApi(Build.VERSION_CODES.O)
private fun createShortcut() {
val manager = activity.getSystemService(ShortcutManager::class.java)
if (manager.isRequestPinShortcutSupported) {

View file

@ -211,8 +211,8 @@ class MediaAdapter(
private fun checkHideBtnVisibility(menu: Menu, selectedItems: ArrayList<Medium>) {
val isInRecycleBin = selectedItems.firstOrNull()?.getIsInRecycleBin() == true
menu.findItem(R.id.cab_hide).isVisible = !isRPlus() && !isInRecycleBin && selectedItems.any { !it.isHidden() }
menu.findItem(R.id.cab_unhide).isVisible = !isRPlus() && !isInRecycleBin && selectedItems.any { it.isHidden() }
menu.findItem(R.id.cab_hide).isVisible = (!isRPlus() || isExternalStorageManager()) && !isInRecycleBin && selectedItems.any { !it.isHidden() }
menu.findItem(R.id.cab_unhide).isVisible = (!isRPlus() || isExternalStorageManager()) && !isInRecycleBin && selectedItems.any { it.isHidden() }
}
private fun checkFavoriteBtnVisibility(menu: Menu, selectedItems: ArrayList<Medium>) {

View file

@ -82,7 +82,7 @@ class SaveAsDialog(
val newFile = File(newPath)
val isInDownloadDir = activity.isInDownloadDir(newPath)
val isInSubFolderInDownloadDir = activity.isInSubFolderInDownloadDir(newPath)
if (isRPlus() && isInDownloadDir && !isInSubFolderInDownloadDir && !newFile.canWrite()) {
if ((isRPlus() && !isExternalStorageManager()) && isInDownloadDir && !isInSubFolderInDownloadDir && !newFile.canWrite()) {
val fileDirItem = arrayListOf(File(newPath).toFileDirItem(activity))
val fileUris = activity.getFileUrisFromFileDirItems(fileDirItem).second
activity.updateSDK30Uris(fileUris) { success ->

View file

@ -117,7 +117,7 @@ fun SimpleActivity.launchAbout() {
faqItems.add(FAQItem(R.string.faq_10_title_commons, R.string.faq_10_text_commons))
}
if (isRPlus()) {
if (isRPlus() && !isExternalStorageManager()) {
faqItems.add(0, FAQItem(R.string.faq_16_title, R.string.faq_16_text))
faqItems.add(1, FAQItem(R.string.faq_17_title, R.string.faq_17_text))
faqItems.removeIf { it.text == R.string.faq_7_text }

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.gallery.pro.extensions
import android.os.Environment
import com.simplemobiletools.commons.extensions.isExternalStorageManager
import com.simplemobiletools.commons.helpers.NOMEDIA
import com.simplemobiletools.commons.helpers.isRPlus
import java.io.File
@ -41,7 +42,7 @@ fun String.shouldFolderBeVisible(
val containsNoMedia = if (showHidden) {
false
} else {
folderNoMediaStatuses.getOrElse("$this/$NOMEDIA", { false }) || (!isRPlus() && File(this, NOMEDIA).exists())
folderNoMediaStatuses.getOrElse("$this/$NOMEDIA") { false } || ((!isRPlus() || isExternalStorageManager()) && File(this, NOMEDIA).exists())
}
return if (!showHidden && containsNoMedia) {

View file

@ -167,31 +167,31 @@ class PhotoFragment : ViewPagerFragment() {
}
if (mMedium.path.startsWith("content://") && !mMedium.path.startsWith("content://mms/")) {
mMedium.path = context!!.getRealPathFromURI(Uri.parse(mOriginalPath)) ?: mMedium.path
if (isRPlus() && mMedium.path.startsWith("/storage/") && mMedium.isHidden()) {
mMedium.path = requireContext().getRealPathFromURI(Uri.parse(mOriginalPath)) ?: mMedium.path
if (isRPlus() && !isExternalStorageManager() && mMedium.path.startsWith("/storage/") && mMedium.isHidden()) {
mMedium.path = mOriginalPath
}
if (mMedium.path.isEmpty()) {
var out: FileOutputStream? = null
try {
var inputStream = context!!.contentResolver.openInputStream(Uri.parse(mOriginalPath))
var inputStream = requireContext().contentResolver.openInputStream(Uri.parse(mOriginalPath))
val exif = ExifInterface()
exif.readExif(inputStream, ExifInterface.Options.OPTION_ALL)
val tag = exif.getTag(ExifInterface.TAG_ORIENTATION)
val orientation = tag?.getValueAsInt(-1) ?: -1
inputStream = context!!.contentResolver.openInputStream(Uri.parse(mOriginalPath))
inputStream = requireContext().contentResolver.openInputStream(Uri.parse(mOriginalPath))
val original = BitmapFactory.decodeStream(inputStream)
val rotated = rotateViaMatrix(original, orientation)
exif.setTagValue(ExifInterface.TAG_ORIENTATION, 1)
exif.removeCompressedThumbnail()
val file = File(context!!.externalCacheDir, Uri.parse(mOriginalPath).lastPathSegment)
val file = File(requireContext().externalCacheDir, Uri.parse(mOriginalPath).lastPathSegment)
out = FileOutputStream(file)
rotated.compress(Bitmap.CompressFormat.JPEG, 100, out)
mMedium.path = file.absolutePath
} catch (e: Exception) {
activity!!.toast(R.string.unknown_error_occurred)
requireActivity().toast(R.string.unknown_error_occurred)
return mView
} finally {
out?.close()
@ -199,7 +199,7 @@ class PhotoFragment : ViewPagerFragment() {
}
}
mIsFullscreen = activity!!.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_FULLSCREEN == View.SYSTEM_UI_FLAG_FULLSCREEN
mIsFullscreen = requireActivity().window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_FULLSCREEN == View.SYSTEM_UI_FLAG_FULLSCREEN
loadImage()
initExtendedDetails()
mWasInit = true

View file

@ -42,7 +42,7 @@ class MediaFetcher(val context: Context) {
curMedia.addAll(newMedia)
}
} else {
if (curPath != FAVORITES && curPath != RECYCLE_BIN && isRPlus()) {
if (curPath != FAVORITES && curPath != RECYCLE_BIN && isRPlus() && !isExternalStorageManager()) {
if (android11Files?.containsKey(curPath.toLowerCase()) == true) {
curMedia.addAll(android11Files[curPath.toLowerCase()]!!)
} else if (android11Files == null) {
@ -59,7 +59,7 @@ class MediaFetcher(val context: Context) {
favoritePaths, getVideoDurations, lastModifieds.clone() as HashMap<String, Long>, dateTakens.clone() as HashMap<String, Long>
)
if (curPath == FAVORITES && isRPlus()) {
if (curPath == FAVORITES && isRPlus() && !isExternalStorageManager()) {
val files =
getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, true, getProperDateTaken, dateTakens.clone() as HashMap<String, Long>)
newMedia.forEach { newMedium ->
@ -429,7 +429,7 @@ class MediaFetcher(val context: Context) {
dateTakens: HashMap<String, Long>
): HashMap<String, ArrayList<Medium>> {
val media = HashMap<String, ArrayList<Medium>>()
if (!isRPlus()) {
if (!isRPlus() || Environment.isExternalStorageManager()) {
return media
}

View file

@ -208,7 +208,7 @@ class NewPhotoEditActivity : SimpleActivity() {
// In case the user wants to overwrite the original file and it is on an SD card, delete it manually first. Else the system just appends (1)
private fun handleFileOverwriting(path: String, callback: () -> Unit) {
if (!isRPlus() && getDoesFilePathExist(path) && isPathOnSD(path)) {
if ((!isRPlus() || isExternalStorageManager()) && getDoesFilePathExist(path) && isPathOnSD(path)) {
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
tryDeleteFileDirItem(fileDirItem, false, true) { success ->
if (success) {