add some helper extension constants for accessing the recycle bin

This commit is contained in:
tibbi 2018-10-28 19:46:48 +01:00
parent 11b04aed43
commit 9f14626f84
5 changed files with 13 additions and 10 deletions

View file

@ -851,7 +851,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
return 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) val movingItems = resources.getQuantityString(R.plurals.moving_items_into_bin, filtered.size, filtered.size)
toast(movingItems) toast(movingItems)

View file

@ -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_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_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_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).isVisible = mRotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0
findItem(R.id.menu_change_orientation).icon = resources.getDrawable(getChangeOrientationIcon()) findItem(R.id.menu_change_orientation).icon = resources.getDrawable(getChangeOrientationIcon())
findItem(R.id.menu_rotate).setShowAsAction( 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()) val tmpFileDirItem = FileDirItem(tmpPath, tmpPath.getFilenameFromPath())
try { try {
getFileOutputStream(tmpFileDirItem) { getFileOutputStream(tmpFileDirItem) {

View file

@ -115,7 +115,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
findItem(R.id.cab_rename).isVisible = selectedItems.firstOrNull()?.getIsInRecycleBin() == false findItem(R.id.cab_rename).isVisible = selectedItems.firstOrNull()?.getIsInRecycleBin() == false
findItem(R.id.cab_open_with).isVisible = isOneItemSelected findItem(R.id.cab_open_with).isVisible = isOneItemSelected
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.isNotEmpty() findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.isNotEmpty()
findItem(R.id.cab_restore_recycle_bin_files).isVisible = selectedPaths.all { it.startsWith(activity.filesDir.absolutePath) } findItem(R.id.cab_restore_recycle_bin_files).isVisible = selectedPaths.all { it.startsWith(activity.recycleBinPath) }
checkHideBtnVisibility(this, selectedItems) checkHideBtnVisibility(this, selectedItems)
checkFavoriteBtnVisibility(this, selectedItems) checkFavoriteBtnVisibility(this, selectedItems)
@ -350,7 +350,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
private fun askConfirmDelete() { private fun askConfirmDelete() {
val items = resources.getQuantityString(R.plurals.delete_items, selectedKeys.size, selectedKeys.size) val items = resources.getQuantityString(R.plurals.delete_items, selectedKeys.size, selectedKeys.size)
val isRecycleBin = getSelectedPaths().first().startsWith(activity.filesDir.absolutePath) val isRecycleBin = getSelectedPaths().first().startsWith(activity.recycleBinPath)
val baseString = if (config.useRecycleBin && !isRecycleBin) R.string.move_to_recycle_bin_confirmation else R.string.deletion_confirmation val baseString = if (config.useRecycleBin && !isRecycleBin) R.string.move_to_recycle_bin_confirmation else R.string.deletion_confirmation
val question = String.format(resources.getString(baseString), items) val question = String.format(resources.getString(baseString), items)
DeleteWithRememberDialog(activity, question) { DeleteWithRememberDialog(activity, question) {

View file

@ -208,7 +208,7 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, mediumDao
var pathsCnt = paths.size var pathsCnt = paths.size
paths.forEach { paths.forEach {
val file = File(it) val file = File(it)
val internalFile = File(filesDir.absolutePath, it) val internalFile = File(recycleBinPath, it)
try { try {
if (file.copyRecursively(internalFile, true)) { if (file.copyRecursively(internalFile, true)) {
mediumDao.updateDeleted(it, System.currentTimeMillis()) mediumDao.updateDeleted(it, System.currentTimeMillis())
@ -229,7 +229,7 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDa
Thread { Thread {
paths.forEach { paths.forEach {
val source = it val source = it
val destination = it.removePrefix(filesDir.absolutePath) val destination = it.removePrefix(recycleBinPath)
var inputStream: InputStream? = null var inputStream: InputStream? = null
var out: OutputStream? = null var out: OutputStream? = null
@ -256,7 +256,7 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDa
fun BaseSimpleActivity.emptyTheRecycleBin(callback: (() -> Unit)? = null) { fun BaseSimpleActivity.emptyTheRecycleBin(callback: (() -> Unit)? = null) {
Thread { Thread {
filesDir.deleteRecursively() recycleBin.deleteRecursively()
galleryDB.MediumDao().clearRecycleBin() galleryDB.MediumDao().clearRecycleBin()
galleryDB.DirectoryDao().deleteRecycleBin() galleryDB.DirectoryDao().deleteRecycleBin()
toast(R.string.recycle_bin_emptied) toast(R.string.recycle_bin_emptied)

View file

@ -104,6 +104,10 @@ val Context.config: Config get() = Config.newInstance(applicationContext)
val Context.galleryDB: GalleryDatabase get() = GalleryDatabase.getInstance(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<Directory>): ArrayList<Directory> { fun Context.movePinnedDirectoriesToFront(dirs: ArrayList<Directory>): ArrayList<Directory> {
val foundFolders = ArrayList<Directory>() val foundFolders = ArrayList<Directory>()
val pinnedFolders = config.pinnedFolders val pinnedFolders = config.pinnedFolders
@ -430,7 +434,6 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
val grouped = mediaFetcher.groupMedia(media, pathToUse) val grouped = mediaFetcher.groupMedia(media, pathToUse)
callback(grouped.clone() as ArrayList<ThumbnailItem>) callback(grouped.clone() as ArrayList<ThumbnailItem>)
val recycleBinPath = filesDir.absolutePath
val mediaToDelete = ArrayList<Medium>() val mediaToDelete = ArrayList<Medium>()
media.filter { !getDoesFilePathExist(it.path) }.forEach { media.filter { !getDoesFilePathExist(it.path) }.forEach {
if (it.path.startsWith(recycleBinPath)) { if (it.path.startsWith(recycleBinPath)) {
@ -470,7 +473,7 @@ fun Context.getFavoritePaths() = galleryDB.MediumDao().getFavoritePaths() as Arr
fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList<Medium> { fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList<Medium> {
val media = mediumDao.getDeletedMedia() as ArrayList<Medium> val media = mediumDao.getDeletedMedia() as ArrayList<Medium>
media.forEach { media.forEach {
it.path = File(filesDir.absolutePath, it.path).toString() it.path = File(recycleBinPath, it.path).toString()
} }
return media return media
} }