diff --git a/app/build.gradle b/app/build.gradle index cc61d37e6..a18e1440f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,7 +61,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.7.13' + implementation 'com.simplemobiletools:commons:5.7.17' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt index 2916e5ce7..b94d38382 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt @@ -26,7 +26,6 @@ import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.Target import com.simplemobiletools.commons.dialogs.ColorPickerDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REAL_FILE_PATH import com.simplemobiletools.commons.helpers.isNougatPlus @@ -148,7 +147,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener if (intent.extras?.containsKey(REAL_FILE_PATH) == true) { val realPath = intent.extras.getString(REAL_FILE_PATH) uri = when { - realPath.startsWith(OTG_PATH) -> uri + isPathOnOTG(realPath) -> uri realPath.startsWith("file:/") -> Uri.parse(realPath) else -> Uri.fromFile(File(realPath)) } 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 470db0f1b..930b0fa6e 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 @@ -377,7 +377,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { runOnUiThread { ConfirmationDialog(this, getString(R.string.usb_detected), positive = R.string.ok, negative = 0) { handleOTGPermission { - config.addIncludedFolder(OTG_PATH) + if (config.OTGPartition.isNotEmpty()) { + config.addIncludedFolder(config.OTGPath) + } } } } @@ -943,13 +945,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { private fun createDirectoryFromMedia(path: String, curMedia: ArrayList, albumCovers: ArrayList, hiddenString: String, includedFolders: MutableSet, isSortingAscending: Boolean): Directory { - var thumbnail = curMedia.firstOrNull { getDoesFilePathExist(it.path) }?.path ?: "" - if (thumbnail.startsWith(OTG_PATH)) { - thumbnail = thumbnail.getOTGPublicPath(applicationContext) - } - + var thumbnail = curMedia.firstOrNull { File(it.path).exists() }?.path ?: "" albumCovers.forEach { - if (it.path == path && getDoesFilePathExist(it.tmb)) { + if (it.path == path && File(it.tmb).exists()) { thumbnail = it.tmb } } @@ -1033,10 +1031,10 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { private fun checkInvalidDirectories(dirs: ArrayList) { val invalidDirs = ArrayList() dirs.filter { !it.areFavorites() && !it.isRecycleBin() }.forEach { - if (!getDoesFilePathExist(it.path)) { + if (!File(it.path).exists()) { invalidDirs.add(it) } else if (it.path != config.tempFolderPath) { - val children = if (it.path.startsWith(OTG_PATH)) getOTGFolderChildrenNames(it.path) else File(it.path).list()?.asList() + val children = if (isPathOnOTG(it.path)) getOTGFolderChildrenNames(it.path) else File(it.path).list()?.asList() val hasMediaFile = children?.any { it?.isMediaFile() == true } ?: false if (!hasMediaFile) { invalidDirs.add(it) 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 5a474751e..eb06a01c1 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 @@ -23,7 +23,6 @@ import com.bumptech.glide.request.target.SimpleTarget import com.bumptech.glide.request.transition.Transition import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.commons.models.FileDirItem @@ -339,8 +338,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { val dirName = when { mPath == FAVORITES -> getString(R.string.favorites) mPath == RECYCLE_BIN -> getString(R.string.recycle_bin) - mPath == OTG_PATH -> getString(R.string.usb) - mPath.startsWith(OTG_PATH) -> mPath.trimEnd('/').substringAfterLast('/') + mPath == config.OTGPath -> getString(R.string.usb) else -> getHumanizedFilename(mPath) } updateActionBarTitle(if (mShowAll) resources.getString(R.string.all_folders) else dirName) 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 0ea59f08f..f2341cdc8 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 @@ -243,7 +243,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return } - if (!getDoesFilePathExist(mPath)) { + if (!File(mPath).exists()) { finish() return } @@ -267,9 +267,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View isShowingRecycleBin -> RECYCLE_BIN else -> mPath.getParentPath() } - if (mDirectory.startsWith(OTG_PATH.trimEnd('/'))) { - mDirectory += "/" - } supportActionBar?.title = mPath.getFilenameFromPath() view_pager.onGlobalLayout { @@ -867,7 +864,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun deleteConfirmed() { val path = getCurrentMedia().getOrNull(mPos)?.path ?: return - if (getIsPathDirectory(path) || !path.isMediaFile()) { + if (File(path).isDirectory || !path.isMediaFile()) { return } @@ -959,7 +956,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun deleteDirectoryIfEmpty() { - val fileDirItem = FileDirItem(mDirectory, mDirectory.getFilenameFromPath(), getIsPathDirectory(mDirectory)) + val fileDirItem = FileDirItem(mDirectory, mDirectory.getFilenameFromPath(), File(mDirectory).isDirectory) if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory && fileDirItem.getProperFileCount(applicationContext, true) == 0) { tryDeleteFileDirItem(fileDirItem, true, true) } 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 80ec519f3..ee2e02594 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 @@ -12,7 +12,6 @@ import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.dialogs.RenameItemsDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.views.FastScroller import com.simplemobiletools.commons.views.MyRecyclerView @@ -321,12 +320,12 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() val showHidden = activity.config.shouldShowHidden getSelectedPaths().forEach { - if (it.startsWith(OTG_PATH)) { + if (activity.isPathOnOTG(it)) { paths.addAll(getOTGFilePaths(it, showHidden)) } else if (it != FAVORITES) { val filter = config.filterMedia File(it).listFiles()?.filter { - !activity.getIsPathDirectory(it.absolutePath) && + !File(it.absolutePath).isDirectory && it.absolutePath.isMediaFile() && (showHidden || !it.name.startsWith('.')) && ((it.isImageFast() && filter and TYPE_IMAGES != 0) || (it.isVideoFast() && filter and TYPE_VIDEOS != 0) || @@ -358,7 +357,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList Unit) { @@ -66,7 +67,7 @@ class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appen return@setOnClickListener } - if (activity.getDoesFilePathExist(newPath)) { + if (File(newPath).exists()) { val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename) ConfirmationDialog(activity, title) { callback(newPath) 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 487f45272..dbd7bda79 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 @@ -406,7 +406,7 @@ fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String, saveFile(tmpPath, bitmap, it as FileOutputStream, newDegrees) } - if (getDoesFilePathExist(newPath)) { + if (File(newPath).exists()) { tryDeleteFileDirItem(FileDirItem(newPath, newPath.getFilenameFromPath()), false, true) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index 9e2ce8af0..ff82c9b18 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -374,16 +374,10 @@ fun Context.getFolderNameFromPath(path: String): String { return when (path) { internalStoragePath -> getString(R.string.internal) sdCardPath -> getString(R.string.sd_card) - OTG_PATH -> getString(R.string.usb) + otgPath -> getString(R.string.usb) FAVORITES -> getString(R.string.favorites) RECYCLE_BIN -> getString(R.string.recycle_bin) - else -> { - if (path.startsWith(OTG_PATH)) { - path.trimEnd('/').substringAfterLast('/') - } else { - path.getFilenameFromPath() - } - } + else -> path.getFilenameFromPath() } } @@ -431,7 +425,7 @@ fun Context.addTempFolderIfNeeded(dirs: ArrayList): ArrayList LOCATION_SD - path.startsWith(OTG_PATH) -> LOCATION_OTG + isPathOnOTG(path) -> LOCATION_OTG else -> LOCAITON_INTERNAL } } @@ -571,7 +565,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag callback(grouped.clone() as ArrayList) val mediaToDelete = ArrayList() - media.filter { !getDoesFilePathExist(it.path) }.forEach { + media.filter { !File(it.path).exists() }.forEach { if (it.path.startsWith(recycleBinPath)) { deleteDBPath(mediumDao, it.path) } else { @@ -585,7 +579,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag fun Context.removeInvalidDBDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { val dirsToCheck = dirs ?: directoryDao.getAll() - dirsToCheck.filter { !it.areFavorites() && !it.isRecycleBin() && !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach { + dirsToCheck.filter { !it.areFavorites() && !it.isRecycleBin() && !File(it.path).exists() && it.path != config.tempFolderPath }.forEach { directoryDao.deleteDirPath(it.path) } } 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 b426c5a61..70dfafa0d 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 @@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.pro.extensions import android.media.MediaMetadataRetriever import com.bumptech.glide.signature.ObjectKey -import com.simplemobiletools.commons.helpers.OTG_PATH import java.io.File import java.io.IOException @@ -47,7 +46,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPath // recognize /sdcard/DCIM as the same folder as /storage/emulated/0/DCIM fun String.getDistinctPath(): String { return try { - if (startsWith(OTG_PATH)) toLowerCase() else File(this).canonicalPath.toLowerCase() + File(this).canonicalPath.toLowerCase() } catch (e: IOException) { toLowerCase() } 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 65885f31e..aa46b9f83 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 @@ -34,7 +34,6 @@ import com.davemorrissey.labs.subscaleview.ImageRegionDecoder import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.activities.PanoramaPhotoActivity import com.simplemobiletools.gallery.pro.activities.PhotoActivity @@ -529,7 +528,7 @@ class PhotoFragment : ViewPagerFragment() { val exif = android.media.ExifInterface(pathToLoad) orient = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, defaultOrientation) - if (orient == defaultOrientation || mMedium.path.startsWith(OTG_PATH)) { + if (orient == defaultOrientation || context!!.isPathOnOTG(mMedium.path)) { val uri = if (pathToLoad.startsWith("content:/")) Uri.parse(pathToLoad) else Uri.fromFile(File(pathToLoad)) val inputStream = context!!.contentResolver.openInputStream(uri) val exif2 = ExifInterface() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/ViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/ViewPagerFragment.kt index 2cb3cf893..839f67b14 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/ViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/ViewPagerFragment.kt @@ -4,7 +4,6 @@ import android.provider.MediaStore import android.view.MotionEvent import androidx.fragment.app.Fragment import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.gallery.pro.extensions.config import com.simplemobiletools.gallery.pro.helpers.* import com.simplemobiletools.gallery.pro.models.Medium @@ -77,7 +76,7 @@ abstract class ViewPagerFragment : Fragment() { return details.toString().trim() } - fun getPathToLoad(medium: Medium) = if (medium.path.startsWith(OTG_PATH)) medium.path.getOTGPublicPath(context!!) else medium.path + fun getPathToLoad(medium: Medium) = medium.path //if (context!!.isPathOnOTG(medium.path)) medium.path.getOTGPublicPath(context!!) else medium.path private fun getFileLastModified(file: File): String { val projection = arrayOf(MediaStore.Images.Media.DATE_MODIFIED) 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 a5912edce..c532bf4ff 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 @@ -26,7 +26,7 @@ class MediaFetcher(val context: Context) { } val curMedia = ArrayList() - if (curPath.startsWith(OTG_PATH, true)) { + if (context.isPathOnOTG(curPath)) { if (context.hasOTGConnected()) { val newMedia = getMediaOnOTG(curPath, isPickImage, isPickVideo, filterMedia, favoritePaths, getVideoDurations) curMedia.addAll(newMedia) @@ -128,7 +128,7 @@ class MediaFetcher(val context: Context) { val foldersToIgnore = arrayListOf("/storage/emulated/legacy") val config = context.config val includedFolders = config.includedFolders - var foldersToScan = config.everShownFolders.filter { it == FAVORITES || it == RECYCLE_BIN || context.getDoesFilePathExist(it) }.toMutableList() as ArrayList + var foldersToScan = config.everShownFolders.filter { it == FAVORITES || it == RECYCLE_BIN || File(it).exists() }.toMutableList() as ArrayList cursor.use { if (cursor.moveToFirst()) { @@ -154,12 +154,12 @@ class MediaFetcher(val context: Context) { private fun addFolder(curFolders: ArrayList, folder: String) { curFolders.add(folder) - if (folder.startsWith(OTG_PATH)) { + if (context.isPathOnOTG(folder)) { val files = context.getOTGFolderChildren(folder) ?: return for (file in files) { if (file.isDirectory) { val relativePath = file.uri.path.substringAfterLast("${context.config.OTGPartition}:") - addFolder(curFolders, "$OTG_PATH$relativePath") + addFolder(curFolders, "${context.config.OTGPath}/$relativePath") } } } else { @@ -314,7 +314,7 @@ class MediaFetcher(val context: Context) { else -> TYPE_IMAGES } - val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGTreeUri}/document/${context.config.OTGPartition}%3A", OTG_PATH)) + val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGTreeUri}/document/${context.config.OTGPartition}%3A", context.config.OTGPath)) val videoDuration = if (getVideoDurations) path.getVideoDuration() else 0 val isFavorite = favoritePaths.contains(path) val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, videoDuration, isFavorite, 0L)