update the stored directories at background media adding too

This commit is contained in:
tibbi 2019-05-25 21:53:12 +02:00
parent b77e7fbca6
commit d9a3dda095

View file

@ -12,8 +12,14 @@ import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Handler import android.os.Handler
import android.provider.MediaStore import android.provider.MediaStore
import com.simplemobiletools.commons.extensions.getParentPath
import com.simplemobiletools.commons.extensions.getStringValue 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) // based on https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri)
@TargetApi(Build.VERSION_CODES.N) @TargetApi(Build.VERSION_CODES.N)
@ -54,6 +60,7 @@ class NewPhotoFetcher : JobService() {
override fun onStartJob(params: JobParameters): Boolean { override fun onStartJob(params: JobParameters): Boolean {
mRunningParams = params mRunningParams = params
val affectedFolderPaths = HashSet<String>()
if (params.triggeredContentAuthorities != null && params.triggeredContentUris != null) { if (params.triggeredContentAuthorities != null && params.triggeredContentUris != null) {
val ids = arrayListOf<String>() val ids = arrayListOf<String>()
for (uri in params.triggeredContentUris!!) { for (uri in params.triggeredContentUris!!) {
@ -80,6 +87,7 @@ class NewPhotoFetcher : JobService() {
cursor = contentResolver.query(it, projection, selection.toString(), null, null) cursor = contentResolver.query(it, projection, selection.toString(), null, null)
while (cursor!!.moveToNext()) { while (cursor!!.moveToNext()) {
val path = cursor!!.getStringValue(MediaStore.Images.ImageColumns.DATA) val path = cursor!!.getStringValue(MediaStore.Images.ImageColumns.DATA)
affectedFolderPaths.add(path.getParentPath())
addPathToDB(path) 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) mHandler.post(mWorker)
return true return true
} }