diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/Global.java b/app/src/main/java/de/k3b/android/androFotoFinder/Global.java index fdae6572..d03ad17a 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/Global.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/Global.java @@ -149,9 +149,16 @@ public static class Media { // Build.VERSION_CODES.??ANDROID10?? = 29 public static boolean useAo10MediaImageDbReplacement = isAndroid10OrAbove(); - /** map with blue selection markers: how much to area to increase */ + // #169 Android SAF DocumentFile performance improvements fast but disabled because it is still error-prone + public final static boolean android_DocumentFile_find_cache = true; + + /** + * map with blue selection markers: how much to area to increase + */ public static final double mapMultiselectionBoxIncreaseByProcent = 100.0; - /** map with blue selection markers: minimum size of zoom box in degrees */ + /** + * map with blue selection markers: minimum size of zoom box in degrees + */ public static final double mapMultiselectionBoxIncreaseMinSizeInDegrees = 0.01; private static boolean isAndroid10OrAbove() { diff --git a/app/src/main/java/de/k3b/android/io/DocumentFileCache.java b/app/src/main/java/de/k3b/android/io/DocumentFileCache.java index ec4f992d..684a9da8 100644 --- a/app/src/main/java/de/k3b/android/io/DocumentFileCache.java +++ b/app/src/main/java/de/k3b/android/io/DocumentFileCache.java @@ -25,6 +25,7 @@ import java.io.File; import java.util.HashMap; +import de.k3b.android.androFotoFinder.Global; import de.k3b.io.filefacade.IFile; import de.k3b.media.PhotoPropertiesUtil; @@ -52,26 +53,28 @@ public CurrentFileCache getCacheStrategy(int strategyID) { } public DocumentFile findFile(DocumentFile parentDoc, File parentFile, String displayName, int strategyID) { - CurrentFileCache currentFileCache = getCacheStrategy(strategyID); + if (Global.android_DocumentFile_find_cache) { + CurrentFileCache currentFileCache = getCacheStrategy(strategyID); - if (currentFileCache != null) { - if (!parentFile.equals(currentFileCache.lastParentFile)) { - currentFileCache.lastParentFile = parentFile; - currentFileCache.lastChildDocFiles.clear(); - DocumentFile[] childDocuments = parentDoc.listFiles(); - for (DocumentFile childDoc : childDocuments) { - if (childDoc.isFile()) { - String childDocName = childDoc.getName().toLowerCase(); - if (PhotoPropertiesUtil.isImage(childDocName, PhotoPropertiesUtil.IMG_TYPE_ALL | PhotoPropertiesUtil.IMG_TYPE_XMP)) { - currentFileCache.lastChildDocFiles.put(childDocName, childDoc); + if (currentFileCache != null) { + if (!parentFile.equals(currentFileCache.lastParentFile)) { + currentFileCache.lastParentFile = parentFile; + currentFileCache.lastChildDocFiles.clear(); + DocumentFile[] childDocuments = parentDoc.listFiles(); + for (DocumentFile childDoc : childDocuments) { + if (childDoc.isFile()) { + String childDocName = childDoc.getName().toLowerCase(); + if (PhotoPropertiesUtil.isImage(childDocName, PhotoPropertiesUtil.IMG_TYPE_ALL | PhotoPropertiesUtil.IMG_TYPE_XMP)) { + currentFileCache.lastChildDocFiles.put(childDocName, childDoc); + } } } - } - } + } - if (PhotoPropertiesUtil.isImage(displayName, PhotoPropertiesUtil.IMG_TYPE_ALL | PhotoPropertiesUtil.IMG_TYPE_XMP)) { - return currentFileCache.lastChildDocFiles.get(displayName.toLowerCase()); + if (PhotoPropertiesUtil.isImage(displayName, PhotoPropertiesUtil.IMG_TYPE_ALL | PhotoPropertiesUtil.IMG_TYPE_XMP)) { + return currentFileCache.lastChildDocFiles.get(displayName.toLowerCase()); + } } } return parentDoc.findFile(displayName);