rescan only paths which arent in mediastore yet

This commit is contained in:
tibbi 2018-03-03 16:45:10 +01:00
parent 7dc0cb660c
commit 443aa9449b
3 changed files with 21 additions and 2 deletions

View file

@ -46,7 +46,7 @@ ext {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:3.14.7' implementation 'com.simplemobiletools:commons:3.14.12'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.code.gson:gson:2.8.2' implementation 'com.google.code.gson:gson:2.8.2'

View file

@ -11,6 +11,7 @@ import android.provider.MediaStore
import android.view.WindowManager import android.view.WindowManager
import com.simplemobiletools.commons.extensions.getStringValue import com.simplemobiletools.commons.extensions.getStringValue
import com.simplemobiletools.commons.extensions.humanizePath import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.gallery.activities.SettingsActivity import com.simplemobiletools.gallery.activities.SettingsActivity
import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.Config
import com.simplemobiletools.gallery.helpers.NOMEDIA import com.simplemobiletools.gallery.helpers.NOMEDIA
@ -110,3 +111,20 @@ fun Context.getNoMediaFolders(callback: (folders: ArrayList<String>) -> Unit) {
callback(folders) callback(folders)
}.start() }.start()
} }
fun Context.isPathInMediaStore(path: String): Boolean {
if (path.startsWith(OTG_PATH)) {
return false
}
val projection = arrayOf(MediaStore.Images.Media.DATE_MODIFIED)
val uri = MediaStore.Files.getContentUri("external")
val selection = "${MediaStore.MediaColumns.DATA} = ?"
val selectionArgs = arrayOf(path)
val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null)
cursor?.use {
return cursor.moveToFirst()
}
return false
}

View file

@ -9,6 +9,7 @@ import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.containsNoMedia import com.simplemobiletools.gallery.extensions.containsNoMedia
import com.simplemobiletools.gallery.extensions.doesParentHaveNoMedia import com.simplemobiletools.gallery.extensions.doesParentHaveNoMedia
import com.simplemobiletools.gallery.extensions.isPathInMediaStore
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import java.io.File import java.io.File
import java.util.LinkedHashMap import java.util.LinkedHashMap
@ -64,7 +65,7 @@ class MediaFetcher(val context: Context) {
files.forEach { files.forEach {
val filePath = it.absolutePath val filePath = it.absolutePath
if ((showHidden || !it.name.startsWith(".")) && !dirPaths.contains(filePath)) { if ((showHidden || !it.name.startsWith(".")) && !dirPaths.contains(filePath)) {
if (it.exists() && it.length() > 0 && it.isImageVideoGif()) { if (it.exists() && it.length() > 0 && it.isImageVideoGif() && !context.isPathInMediaStore(it.absolutePath)) {
newPaths.add(it.absolutePath) newPaths.add(it.absolutePath)
} }
} }