mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
pass the MediumDao and DirectoryDao to some activity extension functions
This commit is contained in:
parent
e1214b4d47
commit
5ea99ab22d
4 changed files with 19 additions and 21 deletions
|
@ -336,7 +336,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent
|
val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent
|
||||||
val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent
|
val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent
|
||||||
|
|
||||||
getCachedDirectories(getVideosOnly, getImagesOnly) {
|
getCachedDirectories(getVideosOnly, getImagesOnly, mDirectoryDao) {
|
||||||
gotDirectories(addTempFolderIfNeeded(it))
|
gotDirectories(addTempFolderIfNeeded(it))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,7 +423,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
files?.filter { it.absolutePath.isImageVideoGif() }?.mapTo(pathsToDelete) { it.absolutePath }
|
files?.filter { it.absolutePath.isImageVideoGif() }?.mapTo(pathsToDelete) { it.absolutePath }
|
||||||
}
|
}
|
||||||
|
|
||||||
movePathsInRecycleBin(pathsToDelete) {
|
movePathsInRecycleBin(pathsToDelete, mMediumDao) {
|
||||||
if (it) {
|
if (it) {
|
||||||
deleteFilteredFolders(fileDirItems, folders)
|
deleteFilteredFolders(fileDirItems, folders)
|
||||||
} else {
|
} else {
|
||||||
|
@ -733,11 +733,11 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
showSortedDirs(dirs)
|
showSortedDirs(dirs)
|
||||||
|
|
||||||
// update directories and media files in the local db, delete invalid items
|
// update directories and media files in the local db, delete invalid items
|
||||||
updateDBDirectory(directory)
|
updateDBDirectory(directory, mDirectoryDao)
|
||||||
if (!directory.isRecycleBin()) {
|
if (!directory.isRecycleBin()) {
|
||||||
mMediumDao.insertAll(curMedia)
|
mMediumDao.insertAll(curMedia)
|
||||||
}
|
}
|
||||||
getCachedMedia(directory.path, getVideosOnly, getImagesOnly) {
|
getCachedMedia(directory.path, getVideosOnly, getImagesOnly, mMediumDao) {
|
||||||
it.forEach {
|
it.forEach {
|
||||||
if (!curMedia.contains(it)) {
|
if (!curMedia.contains(it)) {
|
||||||
val path = (it as? Medium)?.path
|
val path = (it as? Medium)?.path
|
||||||
|
@ -997,7 +997,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
|
|
||||||
override fun updateDirectories(directories: ArrayList<Directory>) {
|
override fun updateDirectories(directories: ArrayList<Directory>) {
|
||||||
Thread {
|
Thread {
|
||||||
storeDirectoryItems(directories)
|
storeDirectoryItems(directories, mDirectoryDao)
|
||||||
removeInvalidDBDirectories()
|
removeInvalidDBDirectories()
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
|
@ -454,7 +454,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
|
|
||||||
private fun restoreAllFiles() {
|
private fun restoreAllFiles() {
|
||||||
val paths = mMedia.filter { it is Medium }.map { (it as Medium).path } as ArrayList<String>
|
val paths = mMedia.filter { it is Medium }.map { (it as Medium).path } as ArrayList<String>
|
||||||
restoreRecycleBinPaths(paths) {
|
restoreRecycleBinPaths(paths, mMediumDao) {
|
||||||
Thread {
|
Thread {
|
||||||
mDirectoryDao.deleteDirPath(RECYCLE_BIN)
|
mDirectoryDao.deleteDirPath(RECYCLE_BIN)
|
||||||
}.start()
|
}.start()
|
||||||
|
@ -546,7 +546,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
|
|
||||||
mIsGettingMedia = true
|
mIsGettingMedia = true
|
||||||
if (!mLoadedInitialPhotos) {
|
if (!mLoadedInitialPhotos) {
|
||||||
getCachedMedia(mPath, mIsGetVideoIntent, mIsGetImageIntent) {
|
getCachedMedia(mPath, mIsGetVideoIntent, mIsGetImageIntent, mMediumDao) {
|
||||||
if (it.isEmpty()) {
|
if (it.isEmpty()) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
media_refresh_layout.isRefreshing = true
|
media_refresh_layout.isRefreshing = true
|
||||||
|
@ -834,7 +834,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
toast(deletingItems)
|
toast(deletingItems)
|
||||||
|
|
||||||
if (config.useRecycleBin && !filtered.first().path.startsWith(filesDir.absolutePath)) {
|
if (config.useRecycleBin && !filtered.first().path.startsWith(filesDir.absolutePath)) {
|
||||||
movePathsInRecycleBin(filtered.map { it.path } as ArrayList<String>) {
|
movePathsInRecycleBin(filtered.map { it.path } as ArrayList<String>, mMediumDao) {
|
||||||
if (it) {
|
if (it) {
|
||||||
deleteFilteredFiles(filtered)
|
deleteFilteredFiles(filtered)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog
|
import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog
|
||||||
import com.simplemobiletools.gallery.helpers.NOMEDIA
|
import com.simplemobiletools.gallery.helpers.NOMEDIA
|
||||||
|
import com.simplemobiletools.gallery.interfaces.MediumDao
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
@ -200,9 +201,8 @@ fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDelet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, callback: ((wasSuccess: Boolean) -> Unit)?) {
|
fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, mediumDao: MediumDao = galleryDB.MediumDao(), callback: ((wasSuccess: Boolean) -> Unit)?) {
|
||||||
Thread {
|
Thread {
|
||||||
val mediumDao = galleryDB.MediumDao()
|
|
||||||
var pathsCnt = paths.size
|
var pathsCnt = paths.size
|
||||||
paths.forEach {
|
paths.forEach {
|
||||||
val file = File(it)
|
val file = File(it)
|
||||||
|
@ -220,12 +220,11 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, callback:
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.restoreRecycleBinPath(path: String, callback: () -> Unit) {
|
fun BaseSimpleActivity.restoreRecycleBinPath(path: String, callback: () -> Unit) {
|
||||||
restoreRecycleBinPaths(arrayListOf(path), callback)
|
restoreRecycleBinPaths(arrayListOf(path), galleryDB.MediumDao(), callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, callback: () -> Unit) {
|
fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDao: MediumDao = galleryDB.MediumDao(), callback: () -> Unit) {
|
||||||
Thread {
|
Thread {
|
||||||
val mediumDao = galleryDB.MediumDao()
|
|
||||||
paths.forEach {
|
paths.forEach {
|
||||||
val source = it
|
val source = it
|
||||||
val destination = it.removePrefix(filesDir.absolutePath)
|
val destination = it.removePrefix(filesDir.absolutePath)
|
||||||
|
|
|
@ -181,9 +181,9 @@ fun Context.rescanFolderMediaSync(path: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.storeDirectoryItems(items: ArrayList<Directory>) {
|
fun Context.storeDirectoryItems(items: ArrayList<Directory>, directoryDao: DirectoryDao) {
|
||||||
Thread {
|
Thread {
|
||||||
galleryDB.DirectoryDao().insertAll(items)
|
directoryDao.insertAll(items)
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,9 +280,8 @@ fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boo
|
||||||
builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target)
|
builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList<Directory>) -> Unit) {
|
fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, directoryDao: DirectoryDao = galleryDB.DirectoryDao(), callback: (ArrayList<Directory>) -> Unit) {
|
||||||
Thread {
|
Thread {
|
||||||
val directoryDao = galleryDB.DirectoryDao()
|
|
||||||
val directories = try {
|
val directories = try {
|
||||||
directoryDao.getAll() as ArrayList<Directory>
|
directoryDao.getAll() as ArrayList<Directory>
|
||||||
} catch (e: SQLiteException) {
|
} catch (e: SQLiteException) {
|
||||||
|
@ -326,10 +325,10 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList<ThumbnailItem>) -> Unit) {
|
fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, mediumDao: MediumDao = galleryDB.MediumDao(),
|
||||||
|
callback: (ArrayList<ThumbnailItem>) -> Unit) {
|
||||||
Thread {
|
Thread {
|
||||||
val mediaFetcher = MediaFetcher(this)
|
val mediaFetcher = MediaFetcher(this)
|
||||||
val mediumDao = galleryDB.MediumDao()
|
|
||||||
val foldersToScan = if (path.isEmpty()) mediaFetcher.getFoldersToScan() else arrayListOf(path)
|
val foldersToScan = if (path.isEmpty()) mediaFetcher.getFoldersToScan() else arrayListOf(path)
|
||||||
var media = ArrayList<Medium>()
|
var media = ArrayList<Medium>()
|
||||||
if (path == FAVORITES) {
|
if (path == FAVORITES) {
|
||||||
|
@ -394,8 +393,8 @@ fun Context.updateDBMediaPath(oldPath: String, newPath: String) {
|
||||||
galleryDB.MediumDao().updateMedium(oldPath, newParentPath, newFilename, newPath)
|
galleryDB.MediumDao().updateMedium(oldPath, newParentPath, newFilename, newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.updateDBDirectory(directory: Directory) {
|
fun Context.updateDBDirectory(directory: Directory, directoryDao: DirectoryDao) {
|
||||||
galleryDB.DirectoryDao().updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types)
|
directoryDao.updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getOTGFolderChildren(path: String) = getDocumentFile(path)?.listFiles()
|
fun Context.getOTGFolderChildren(path: String) = getDocumentFile(path)?.listFiles()
|
||||||
|
|
Loading…
Reference in a new issue