pass the MediumDao and DirectoryDao to some activity extension functions
This commit is contained in:
parent
e1214b4d47
commit
5ea99ab22d
|
@ -336,7 +336,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent
|
||||
val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent
|
||||
|
||||
getCachedDirectories(getVideosOnly, getImagesOnly) {
|
||||
getCachedDirectories(getVideosOnly, getImagesOnly, mDirectoryDao) {
|
||||
gotDirectories(addTempFolderIfNeeded(it))
|
||||
}
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
files?.filter { it.absolutePath.isImageVideoGif() }?.mapTo(pathsToDelete) { it.absolutePath }
|
||||
}
|
||||
|
||||
movePathsInRecycleBin(pathsToDelete) {
|
||||
movePathsInRecycleBin(pathsToDelete, mMediumDao) {
|
||||
if (it) {
|
||||
deleteFilteredFolders(fileDirItems, folders)
|
||||
} else {
|
||||
|
@ -733,11 +733,11 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
showSortedDirs(dirs)
|
||||
|
||||
// update directories and media files in the local db, delete invalid items
|
||||
updateDBDirectory(directory)
|
||||
updateDBDirectory(directory, mDirectoryDao)
|
||||
if (!directory.isRecycleBin()) {
|
||||
mMediumDao.insertAll(curMedia)
|
||||
}
|
||||
getCachedMedia(directory.path, getVideosOnly, getImagesOnly) {
|
||||
getCachedMedia(directory.path, getVideosOnly, getImagesOnly, mMediumDao) {
|
||||
it.forEach {
|
||||
if (!curMedia.contains(it)) {
|
||||
val path = (it as? Medium)?.path
|
||||
|
@ -997,7 +997,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
|
||||
override fun updateDirectories(directories: ArrayList<Directory>) {
|
||||
Thread {
|
||||
storeDirectoryItems(directories)
|
||||
storeDirectoryItems(directories, mDirectoryDao)
|
||||
removeInvalidDBDirectories()
|
||||
}.start()
|
||||
}
|
||||
|
|
|
@ -454,7 +454,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
|||
|
||||
private fun restoreAllFiles() {
|
||||
val paths = mMedia.filter { it is Medium }.map { (it as Medium).path } as ArrayList<String>
|
||||
restoreRecycleBinPaths(paths) {
|
||||
restoreRecycleBinPaths(paths, mMediumDao) {
|
||||
Thread {
|
||||
mDirectoryDao.deleteDirPath(RECYCLE_BIN)
|
||||
}.start()
|
||||
|
@ -546,7 +546,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
|||
|
||||
mIsGettingMedia = true
|
||||
if (!mLoadedInitialPhotos) {
|
||||
getCachedMedia(mPath, mIsGetVideoIntent, mIsGetImageIntent) {
|
||||
getCachedMedia(mPath, mIsGetVideoIntent, mIsGetImageIntent, mMediumDao) {
|
||||
if (it.isEmpty()) {
|
||||
runOnUiThread {
|
||||
media_refresh_layout.isRefreshing = true
|
||||
|
@ -834,7 +834,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
|||
toast(deletingItems)
|
||||
|
||||
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) {
|
||||
deleteFilteredFiles(filtered)
|
||||
} else {
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.R
|
|||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||
import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog
|
||||
import com.simplemobiletools.gallery.helpers.NOMEDIA
|
||||
import com.simplemobiletools.gallery.interfaces.MediumDao
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
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 {
|
||||
val mediumDao = galleryDB.MediumDao()
|
||||
var pathsCnt = paths.size
|
||||
paths.forEach {
|
||||
val file = File(it)
|
||||
|
@ -220,12 +220,11 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, callback:
|
|||
}
|
||||
|
||||
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 {
|
||||
val mediumDao = galleryDB.MediumDao()
|
||||
paths.forEach {
|
||||
val source = it
|
||||
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 {
|
||||
galleryDB.DirectoryDao().insertAll(items)
|
||||
directoryDao.insertAll(items)
|
||||
}.start()
|
||||
}
|
||||
|
||||
|
@ -280,9 +280,8 @@ fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boo
|
|||
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 {
|
||||
val directoryDao = galleryDB.DirectoryDao()
|
||||
val directories = try {
|
||||
directoryDao.getAll() as ArrayList<Directory>
|
||||
} catch (e: SQLiteException) {
|
||||
|
@ -326,10 +325,10 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
|
|||
}.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 {
|
||||
val mediaFetcher = MediaFetcher(this)
|
||||
val mediumDao = galleryDB.MediumDao()
|
||||
val foldersToScan = if (path.isEmpty()) mediaFetcher.getFoldersToScan() else arrayListOf(path)
|
||||
var media = ArrayList<Medium>()
|
||||
if (path == FAVORITES) {
|
||||
|
@ -394,8 +393,8 @@ fun Context.updateDBMediaPath(oldPath: String, newPath: String) {
|
|||
galleryDB.MediumDao().updateMedium(oldPath, newParentPath, newFilename, newPath)
|
||||
}
|
||||
|
||||
fun Context.updateDBDirectory(directory: Directory) {
|
||||
galleryDB.DirectoryDao().updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types)
|
||||
fun Context.updateDBDirectory(directory: Directory, directoryDao: DirectoryDao) {
|
||||
directoryDao.updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types)
|
||||
}
|
||||
|
||||
fun Context.getOTGFolderChildren(path: String) = getDocumentFile(path)?.listFiles()
|
||||
|
|
Loading…
Reference in New Issue