mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
update the stored directories at background media adding too
This commit is contained in:
parent
b77e7fbca6
commit
d9a3dda095
1 changed files with 27 additions and 1 deletions
|
@ -12,8 +12,14 @@ import android.net.Uri
|
|||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.provider.MediaStore
|
||||
import com.simplemobiletools.commons.extensions.getParentPath
|
||||
import com.simplemobiletools.commons.extensions.getStringValue
|
||||
import com.simplemobiletools.gallery.pro.extensions.addPathToDB
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
import com.simplemobiletools.gallery.pro.R
|
||||
import com.simplemobiletools.gallery.pro.extensions.*
|
||||
import com.simplemobiletools.gallery.pro.helpers.MediaFetcher
|
||||
|
||||
// based on https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri)
|
||||
@TargetApi(Build.VERSION_CODES.N)
|
||||
|
@ -54,6 +60,7 @@ class NewPhotoFetcher : JobService() {
|
|||
override fun onStartJob(params: JobParameters): Boolean {
|
||||
mRunningParams = params
|
||||
|
||||
val affectedFolderPaths = HashSet<String>()
|
||||
if (params.triggeredContentAuthorities != null && params.triggeredContentUris != null) {
|
||||
val ids = arrayListOf<String>()
|
||||
for (uri in params.triggeredContentUris!!) {
|
||||
|
@ -80,6 +87,7 @@ class NewPhotoFetcher : JobService() {
|
|||
cursor = contentResolver.query(it, projection, selection.toString(), null, null)
|
||||
while (cursor!!.moveToNext()) {
|
||||
val path = cursor!!.getStringValue(MediaStore.Images.ImageColumns.DATA)
|
||||
affectedFolderPaths.add(path.getParentPath())
|
||||
addPathToDB(path)
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +98,24 @@ class NewPhotoFetcher : JobService() {
|
|||
}
|
||||
}
|
||||
|
||||
Thread {
|
||||
affectedFolderPaths.forEach {
|
||||
val mediaFetcher = MediaFetcher(applicationContext)
|
||||
val getImagesOnly = false
|
||||
val getVideosOnly = false
|
||||
val hiddenString = getString(R.string.hidden)
|
||||
val albumCovers = config.parseAlbumCovers()
|
||||
val includedFolders = config.includedFolders
|
||||
val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0
|
||||
val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0
|
||||
val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0
|
||||
val favoritePaths = getFavoritePaths()
|
||||
val curMedia = mediaFetcher.getFilesFrom(it, getImagesOnly, getVideosOnly, getProperDateTaken, getProperFileSize, favoritePaths, false)
|
||||
val directory = createDirectoryFromMedia(it, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending, getProperFileSize)
|
||||
updateDBDirectory(directory, galleryDB.DirectoryDao())
|
||||
}
|
||||
}.start()
|
||||
|
||||
mHandler.post(mWorker)
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue