diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 59cfc4f03..cd0eb87dc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -851,7 +851,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { return } - if (config.useRecycleBin && !filtered.first().path.startsWith(filesDir.absolutePath)) { + if (config.useRecycleBin && !filtered.first().path.startsWith(recycleBinPath)) { val movingItems = resources.getQuantityString(R.plurals.moving_items_into_bin, filtered.size, filtered.size) toast(movingItems) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 6fb63e5d4..efd5fe23b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -176,7 +176,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View findItem(R.id.menu_unhide).isVisible = 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 findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 - findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(filesDir.absolutePath) + findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(recycleBinPath) findItem(R.id.menu_change_orientation).isVisible = mRotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0 findItem(R.id.menu_change_orientation).icon = resources.getDrawable(getChangeOrientationIcon()) findItem(R.id.menu_rotate).setShowAsAction( @@ -594,7 +594,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - val tmpPath = "${filesDir.absolutePath}/.tmp_${newPath.getFilenameFromPath()}" + val tmpPath = "$recycleBinPath/.tmp_${newPath.getFilenameFromPath()}" val tmpFileDirItem = FileDirItem(tmpPath, tmpPath.getFilenameFromPath()) try { getFileOutputStream(tmpFileDirItem) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 66de13acd..acfbac0aa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -115,7 +115,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, mediumDao var pathsCnt = paths.size paths.forEach { val file = File(it) - val internalFile = File(filesDir.absolutePath, it) + val internalFile = File(recycleBinPath, it) try { if (file.copyRecursively(internalFile, true)) { mediumDao.updateDeleted(it, System.currentTimeMillis()) @@ -229,7 +229,7 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList, mediumDa Thread { paths.forEach { val source = it - val destination = it.removePrefix(filesDir.absolutePath) + val destination = it.removePrefix(recycleBinPath) var inputStream: InputStream? = null var out: OutputStream? = null @@ -256,7 +256,7 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList, mediumDa fun BaseSimpleActivity.emptyTheRecycleBin(callback: (() -> Unit)? = null) { Thread { - filesDir.deleteRecursively() + recycleBin.deleteRecursively() galleryDB.MediumDao().clearRecycleBin() galleryDB.DirectoryDao().deleteRecycleBin() toast(R.string.recycle_bin_emptied) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt index 0a54abf6a..2bc1d7c69 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -104,6 +104,10 @@ val Context.config: Config get() = Config.newInstance(applicationContext) val Context.galleryDB: GalleryDatabase get() = GalleryDatabase.getInstance(applicationContext) +val Context.recycleBin: File get() = filesDir + +val Context.recycleBinPath: String get() = filesDir.absolutePath + fun Context.movePinnedDirectoriesToFront(dirs: ArrayList): ArrayList { val foundFolders = ArrayList() val pinnedFolders = config.pinnedFolders @@ -430,7 +434,6 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag val grouped = mediaFetcher.groupMedia(media, pathToUse) callback(grouped.clone() as ArrayList) - val recycleBinPath = filesDir.absolutePath val mediaToDelete = ArrayList() media.filter { !getDoesFilePathExist(it.path) }.forEach { if (it.path.startsWith(recycleBinPath)) { @@ -470,7 +473,7 @@ fun Context.getFavoritePaths() = galleryDB.MediumDao().getFavoritePaths() as Arr fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList { val media = mediumDao.getDeletedMedia() as ArrayList media.forEach { - it.path = File(filesDir.absolutePath, it.path).toString() + it.path = File(recycleBinPath, it.path).toString() } return media }