diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/jobs/NewPhotoFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/jobs/NewPhotoFetcher.kt index 8039ae280..9e0e4ad5f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/jobs/NewPhotoFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/jobs/NewPhotoFetcher.kt @@ -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() if (params.triggeredContentAuthorities != null && params.triggeredContentUris != null) { val ids = arrayListOf() 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 }