From c5d9ac6fcc716671340e18200ea76c9b0f61420e Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 9 May 2022 10:44:50 +0200 Subject: [PATCH] prepare the app for having All files permission --- .../pro/activities/ExcludedFoldersActivity.kt | 3 ++- .../gallery/pro/activities/MainActivity.kt | 11 ++++++----- .../gallery/pro/activities/MediaActivity.kt | 4 ++-- .../pro/activities/PhotoVideoActivity.kt | 19 ++++++++++--------- .../pro/activities/SettingsActivity.kt | 8 ++++---- .../pro/activities/ViewPagerActivity.kt | 10 +++++++--- .../gallery/pro/adapters/DirectoryAdapter.kt | 10 ++++++++-- .../gallery/pro/adapters/MediaAdapter.kt | 4 ++-- .../gallery/pro/dialogs/SaveAsDialog.kt | 2 +- .../gallery/pro/extensions/Activity.kt | 2 +- .../gallery/pro/extensions/String.kt | 3 ++- .../gallery/pro/fragments/PhotoFragment.kt | 14 +++++++------- .../gallery/pro/helpers/MediaFetcher.kt | 6 +++--- .../pro/activities/NewPhotoEditActivity.kt | 2 +- 14 files changed, 56 insertions(+), 42 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ExcludedFoldersActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ExcludedFoldersActivity.kt index 9f0111e9c..7eb953c4d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ExcludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ExcludedFoldersActivity.kt @@ -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") } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 05b514a2b..b157311e8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index bcfd428ac..09914b4cd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt index 79e2db729..732cc416e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt @@ -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 } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt index 33a312862..4a58c263f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 3f0e35bba..2c5d75b9f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -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 } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index ed7b65430..bc6ad8279 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -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) { - 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) { @@ -548,6 +553,7 @@ class DirectoryAdapter( } } + @RequiresApi(Build.VERSION_CODES.O) private fun createShortcut() { val manager = activity.getSystemService(ShortcutManager::class.java) if (manager.isRequestPinShortcutSupported) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index eebb97e76..2472fbe9f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -211,8 +211,8 @@ class MediaAdapter( private fun checkHideBtnVisibility(menu: Menu, selectedItems: ArrayList) { 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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt index 8d8484ff5..ca0f11412 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt @@ -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 -> diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index 0005045bc..d9779f999 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -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 } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt index ec0703087..569b383e5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt @@ -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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index 1c747e243..34935ad7c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt index f2cf702a8..f5eafa428 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt @@ -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, dateTakens.clone() as HashMap ) - if (curPath == FAVORITES && isRPlus()) { + if (curPath == FAVORITES && isRPlus() && !isExternalStorageManager()) { val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, true, getProperDateTaken, dateTakens.clone() as HashMap) newMedia.forEach { newMedium -> @@ -429,7 +429,7 @@ class MediaFetcher(val context: Context) { dateTakens: HashMap ): HashMap> { val media = HashMap>() - if (!isRPlus()) { + if (!isRPlus() || Environment.isExternalStorageManager()) { return media } diff --git a/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewPhotoEditActivity.kt b/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewPhotoEditActivity.kt index 97dcf608b..959ddb124 100644 --- a/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewPhotoEditActivity.kt +++ b/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewPhotoEditActivity.kt @@ -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) {