show a Recycle Bin folder on the main screen if not empty
This commit is contained in:
parent
721890ce67
commit
c75f564a35
|
@ -679,7 +679,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
|
||||
// update directories and media files in the local db, delete invalid items
|
||||
updateDBDirectory(directory)
|
||||
if (!directory.isRecycleBin()) {
|
||||
mediumDao.insertAll(curMedia)
|
||||
}
|
||||
getCachedMedia(directory.path, getVideosOnly, getImagesOnly) {
|
||||
it.forEach {
|
||||
if (!curMedia.contains(it)) {
|
||||
|
@ -696,6 +698,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
|
||||
val foldersToScan = mediaFetcher.getFoldersToScan()
|
||||
foldersToScan.add(FAVORITES)
|
||||
foldersToScan.add(RECYCLE_BIN)
|
||||
dirs.forEach {
|
||||
foldersToScan.remove(it.path)
|
||||
}
|
||||
|
@ -720,8 +723,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
dirs.add(newDir)
|
||||
showSortedDirs(dirs)
|
||||
directoryDao.insert(newDir)
|
||||
if (folder != RECYCLE_BIN) {
|
||||
mediumDao.insertAll(newMedia)
|
||||
}
|
||||
}
|
||||
|
||||
mIsGettingDirs = false
|
||||
mLoadedInitialPhotos = true
|
||||
|
@ -764,7 +769,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
}
|
||||
|
||||
val mediaTypes = curMedia.getDirMediaTypes()
|
||||
val dirName = if (path == FAVORITES) getString(R.string.favorites) else checkAppendingHidden(path, hiddenString, includedFolders)
|
||||
val dirName = when (path) {
|
||||
FAVORITES -> getString(R.string.favorites)
|
||||
RECYCLE_BIN -> getString(R.string.recycle_bin)
|
||||
else -> checkAppendingHidden(path, hiddenString, includedFolders)
|
||||
}
|
||||
|
||||
val firstItem = curMedia.first()
|
||||
val lastItem = curMedia.last()
|
||||
|
@ -822,7 +831,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
|
||||
private fun checkInvalidDirectories(dirs: ArrayList<Directory>, directoryDao: DirectoryDao) {
|
||||
val invalidDirs = ArrayList<Directory>()
|
||||
dirs.filter { !it.areFavorites() }.forEach {
|
||||
dirs.filter { !it.areFavorites() && !it.isRecycleBin() }.forEach {
|
||||
if (!getDoesFilePathExist(it.path)) {
|
||||
invalidDirs.add(it)
|
||||
} else if (it.path != config.tempFolderPath) {
|
||||
|
|
|
@ -194,9 +194,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
menu.apply {
|
||||
findItem(R.id.group).isVisible = !config.scrollHorizontally
|
||||
|
||||
findItem(R.id.hide_folder).isVisible = !isFolderHidden && !mShowAll && mPath != FAVORITES
|
||||
findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll && mPath != FAVORITES
|
||||
findItem(R.id.exclude_folder).isVisible = !mShowAll && mPath != FAVORITES
|
||||
findItem(R.id.hide_folder).isVisible = !isFolderHidden && !mShowAll && mPath != FAVORITES && mPath != RECYCLE_BIN
|
||||
findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll && mPath != FAVORITES && mPath != RECYCLE_BIN
|
||||
findItem(R.id.exclude_folder).isVisible = !mShowAll && mPath != FAVORITES && mPath != RECYCLE_BIN
|
||||
|
||||
findItem(R.id.folder_view).isVisible = mShowAll
|
||||
findItem(R.id.open_camera).isVisible = mShowAll
|
||||
|
@ -304,6 +304,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
if (it) {
|
||||
val dirName = when {
|
||||
mPath == FAVORITES -> getString(R.string.favorites)
|
||||
mPath == RECYCLE_BIN -> getString(R.string.recycle_bin)
|
||||
mPath == OTG_PATH -> getString(R.string.otg)
|
||||
mPath.startsWith(OTG_PATH) -> mPath.trimEnd('/').substringAfterLast('/')
|
||||
else -> getHumanizedFilename(mPath)
|
||||
|
@ -525,7 +526,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
|
||||
private fun isDirEmpty(): Boolean {
|
||||
return if (mMedia.size <= 0 && config.filterMedia > 0) {
|
||||
if (mPath != FAVORITES) {
|
||||
if (mPath != FAVORITES && mPath != RECYCLE_BIN) {
|
||||
deleteDirectoryIfEmpty()
|
||||
deleteDBDirectory()
|
||||
}
|
||||
|
@ -736,6 +737,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
putExtra(PATH, path)
|
||||
putExtra(SHOW_ALL, mShowAll)
|
||||
putExtra(SHOW_FAVORITES, mPath == FAVORITES)
|
||||
putExtra(SHOW_RECYCLE_BIN, mPath == RECYCLE_BIN)
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
|
@ -747,7 +749,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
mLatestMediaId = getLatestMediaId()
|
||||
mLatestMediaDateId = getLatestMediaByDateId()
|
||||
if (!isFromCache) {
|
||||
val mediaToInsert = (mMedia.clone() as ArrayList<ThumbnailItem>).filter { it is Medium }.map { it as Medium }
|
||||
val mediaToInsert = (mMedia.clone() as ArrayList<ThumbnailItem>).filter { it is Medium && it.deletedTS == 0L }.map { it as Medium }
|
||||
galleryDB.MediumDao().insertAll(mediaToInsert)
|
||||
}
|
||||
}.start()
|
||||
|
|
|
@ -60,7 +60,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private var mPos = -1
|
||||
private var mShowAll = false
|
||||
private var mIsSlideshowActive = false
|
||||
private var mIsShowingFavorites = false
|
||||
private var mRotationDegrees = 0
|
||||
private var mPrevHashcode = 0
|
||||
|
||||
|
@ -86,7 +85,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_medium)
|
||||
(MediaActivity.mMedia.clone() as ArrayList<ThumbnailItem>).filter { it is Medium }.mapTo(mMediaFiles) { it as Medium }
|
||||
mIsShowingFavorites = intent.getBooleanExtra(SHOW_FAVORITES, false)
|
||||
|
||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||
if (it) {
|
||||
|
@ -216,7 +214,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
showSystemUI()
|
||||
|
||||
mDirectory = if (mIsShowingFavorites) FAVORITES else mPath.getParentPath()
|
||||
val isShowingFavorites = intent.getBooleanExtra(SHOW_FAVORITES, false)
|
||||
val isShowingRecycleBin = intent.getBooleanExtra(SHOW_RECYCLE_BIN, false)
|
||||
mDirectory = when {
|
||||
isShowingFavorites -> FAVORITES
|
||||
isShowingRecycleBin -> RECYCLE_BIN
|
||||
else -> mPath.getParentPath()
|
||||
}
|
||||
if (mDirectory.startsWith(OTG_PATH.trimEnd('/'))) {
|
||||
mDirectory += "/"
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
}
|
||||
|
||||
private fun toggleFoldersVisibility(hide: Boolean) {
|
||||
getSelectedPaths().filter { it != FAVORITES }.forEach {
|
||||
getSelectedPaths().filter { it != FAVORITES && it != RECYCLE_BIN }.forEach {
|
||||
val path = it
|
||||
if (hide) {
|
||||
if (config.wasHideFolderTooltipShown) {
|
||||
|
@ -358,7 +358,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
activity.handleSAFDialog(SAFPath) {
|
||||
selectedPositions.sortedDescending().forEach {
|
||||
val directory = dirs[it]
|
||||
if (directory.areFavorites()) {
|
||||
if (directory.areFavorites() || directory.isRecycleBin()) {
|
||||
if (selectedPositions.size == 1) {
|
||||
finishActMode()
|
||||
} else {
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
|||
import com.simplemobiletools.gallery.databases.GalleryDatabase
|
||||
import com.simplemobiletools.gallery.helpers.*
|
||||
import com.simplemobiletools.gallery.interfaces.DirectoryDao
|
||||
import com.simplemobiletools.gallery.interfaces.MediumDao
|
||||
import com.simplemobiletools.gallery.models.Directory
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import com.simplemobiletools.gallery.models.ThumbnailItem
|
||||
|
@ -330,6 +331,10 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
|
|||
media.addAll(mediumDao.getFavorites())
|
||||
}
|
||||
|
||||
if (path == RECYCLE_BIN) {
|
||||
media.addAll(getUpdatedDeletedMedia(mediumDao))
|
||||
}
|
||||
|
||||
val shouldShowHidden = config.shouldShowHidden
|
||||
foldersToScan.forEach {
|
||||
try {
|
||||
|
@ -367,7 +372,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
|
|||
|
||||
fun Context.removeInvalidDBDirectories(dirs: ArrayList<Directory>? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) {
|
||||
val dirsToCheck = dirs ?: directoryDao.getAll()
|
||||
dirsToCheck.filter { !it.areFavorites() && !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach {
|
||||
dirsToCheck.filter { !it.areFavorites() && !it.isRecycleBin() && !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach {
|
||||
directoryDao.deleteDirPath(it.path)
|
||||
}
|
||||
}
|
||||
|
@ -387,3 +392,11 @@ fun Context.getOTGFolderChildren(path: String) = getDocumentFile(path)?.listFile
|
|||
fun Context.getOTGFolderChildrenNames(path: String) = getOTGFolderChildren(path)?.map { it.name }?.toList()
|
||||
|
||||
fun Context.getFavoritePaths() = galleryDB.MediumDao().getFavoritePaths() as ArrayList<String>
|
||||
|
||||
fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList<Medium> {
|
||||
val media = mediumDao.getDeletedMedia() as ArrayList<Medium>
|
||||
media.forEach {
|
||||
it.path = File(filesDir, it.path).toString()
|
||||
}
|
||||
return media
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ const val NOMEDIA = ".nomedia"
|
|||
const val FAVORITES = "favorites"
|
||||
const val RECYCLE_BIN = "recycle_bin"
|
||||
const val SHOW_FAVORITES = "show_favorites"
|
||||
const val SHOW_RECYCLE_BIN = "show_recycle_bin"
|
||||
const val MAX_COLUMN_COUNT = 20
|
||||
const val SHOW_TEMP_HIDDEN_DURATION = 300000L
|
||||
const val CLICK_MAX_DURATION = 150
|
||||
|
|
|
@ -8,10 +8,7 @@ import android.text.format.DateFormat
|
|||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import com.simplemobiletools.gallery.extensions.getDistinctPath
|
||||
import com.simplemobiletools.gallery.extensions.getOTGFolderChildren
|
||||
import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible
|
||||
import com.simplemobiletools.gallery.extensions.*
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import com.simplemobiletools.gallery.models.ThumbnailItem
|
||||
import com.simplemobiletools.gallery.models.ThumbnailSection
|
||||
|
@ -165,10 +162,10 @@ class MediaFetcher(val context: Context) {
|
|||
favoritePaths: ArrayList<String>): ArrayList<Medium> {
|
||||
val media = ArrayList<Medium>()
|
||||
|
||||
val files = if (folder == FAVORITES) {
|
||||
favoritePaths.map { File(it) }.toTypedArray()
|
||||
} else {
|
||||
File(folder).listFiles() ?: return media
|
||||
val files = when (folder) {
|
||||
FAVORITES -> favoritePaths.map { File(it) }.toTypedArray()
|
||||
RECYCLE_BIN -> context.getUpdatedDeletedMedia(context.galleryDB.MediumDao()).map { File(it.path) }.toTypedArray()
|
||||
else -> File(folder).listFiles() ?: return media
|
||||
}
|
||||
|
||||
val doExtraCheck = context.config.doExtraCheck
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_NAME
|
|||
import com.simplemobiletools.commons.helpers.SORT_BY_PATH
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
||||
import com.simplemobiletools.gallery.helpers.FAVORITES
|
||||
import com.simplemobiletools.gallery.helpers.RECYCLE_BIN
|
||||
import java.io.Serializable
|
||||
|
||||
@Entity(tableName = "directories", indices = [Index(value = "path", unique = true)])
|
||||
|
@ -39,4 +40,6 @@ data class Directory(
|
|||
}
|
||||
|
||||
fun areFavorites() = path == FAVORITES
|
||||
|
||||
fun isRecycleBin() = path == RECYCLE_BIN
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue