Skip to content

Commit

Permalink
Allow Disabling DocumentFileCache
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Apr 15, 2021
1 parent bde7e1c commit e9f477a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
11 changes: 9 additions & 2 deletions app/src/main/java/de/k3b/android/androFotoFinder/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
33 changes: 18 additions & 15 deletions app/src/main/java/de/k3b/android/io/DocumentFileCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e9f477a

Please sign in to comment.