From b5f9c65d174c50fcf20d7f35dc32977194c4b396 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Mon, 26 Apr 2021 19:22:45 +0200 Subject: [PATCH] removed cacheStrategyID --- .../k3b/android/io/AndroidFileCommands.java | 3 +- .../de/k3b/android/io/AndroidFileFacade.java | 29 ++++++++--------- .../de/k3b/android/io/DocumentFileCache.java | 32 ++++++------------- .../android/io/DocumentFileTranslator.java | 25 +++++++-------- .../java/de/k3b/io/FileCommandLogger.java | 3 +- .../src/main/java/de/k3b/io/FileCommands.java | 5 --- .../main/java/de/k3b/media/ExifInterface.java | 6 ++-- .../java/de/k3b/io/filefacade/FileFacade.java | 10 +----- .../de/k3b/io/filefacade/FileWrapper.java | 6 ---- .../main/java/de/k3b/io/filefacade/IFile.java | 7 ---- .../k3b/io/filefacade/StringFileFacade.java | 5 --- 11 files changed, 40 insertions(+), 91 deletions(-) diff --git a/app/src/main/java/de/k3b/android/io/AndroidFileCommands.java b/app/src/main/java/de/k3b/android/io/AndroidFileCommands.java index 701df815..bdc4b39c 100644 --- a/app/src/main/java/de/k3b/android/io/AndroidFileCommands.java +++ b/app/src/main/java/de/k3b/android/io/AndroidFileCommands.java @@ -257,8 +257,7 @@ public void onMoveOrCopyDirectoryPick(boolean move, SelectedFiles selectedFiles, if (destFolder != null) { String copyToPath = destFolder.getAbsolute(); IFile destDirFolder = FileFacade - .convert("AndroidFileCommands.onMoveOrCopyDirectoryPick", copyToPath) - .cacheStrategy(IFile.STRATEGY_OUTPUT); + .convert("AndroidFileCommands.onMoveOrCopyDirectoryPick", copyToPath); setLastCopyToPath(copyToPath); diff --git a/app/src/main/java/de/k3b/android/io/AndroidFileFacade.java b/app/src/main/java/de/k3b/android/io/AndroidFileFacade.java index ac20bf5f..c5ebbec6 100644 --- a/app/src/main/java/de/k3b/android/io/AndroidFileFacade.java +++ b/app/src/main/java/de/k3b/android/io/AndroidFileFacade.java @@ -95,14 +95,13 @@ public static void initFactory(Context context) { } } - private AndroidFileFacade(@Nullable DocumentFile parentFile, @NonNull File parentFile1, int strategyID) { + private AndroidFileFacade(@Nullable DocumentFile parentFile, @NonNull File parentFile1) { super(parentFile1); androidFile = parentFile; - this.strategyID = strategyID; } public AndroidFileFacade(@NonNull File file) { - this(null, file, IFile.STRATEGY_INPUT); + this(null, file); } @Override @@ -119,7 +118,7 @@ public void set(IFile src) { } private DocumentFile getDocumentFileOrDirOrNull(@NonNull File file) { - return documentFileTranslator.getDocumentFileOrDirOrNull(file, null, this.strategyID); + return documentFileTranslator.getDocumentFileOrDirOrNull(file, null); } private boolean copyImpl(@NonNull AndroidFileFacade targetFullPath, boolean deleteSourceWhenSuccess) { @@ -209,7 +208,7 @@ public IFile getCanonicalFile() { public IFile getParentFile() { final DocumentFile androidFile = getAndroidFile(false); if (androidFile != null) { - return new AndroidFileFacade(androidFile.getParentFile(), getFile().getParentFile(), strategyID); + return new AndroidFileFacade(androidFile.getParentFile(), getFile().getParentFile()); } else { return super.getParentFile(); } @@ -252,7 +251,7 @@ public long lastModified() { @Override public boolean mkdirs() { - this.androidFile = documentFileTranslator.getOrCreateDirectory(getFile(), strategyID); + this.androidFile = documentFileTranslator.getOrCreateDirectory(getFile()); invalidateParentDirCache(); return null != this.androidFile; } @@ -261,7 +260,7 @@ public boolean mkdirs() { public IFile[] listFiles() { final DocumentFile androidFile = getAndroidFile(false); if (androidFile != null) { - return get(androidFile.listFiles(), strategyID); + return get(androidFile.listFiles()); } return new IFile[0]; } @@ -275,7 +274,7 @@ public IFile[] listDirs() { if (file != null && (file.isDirectory() || accept(file.getName().toLowerCase()))) { found.add(new AndroidFileFacade( - file, new File(parent, file.getName()), strategyID)); + file, new File(parent, file.getName()))); } } } @@ -299,11 +298,11 @@ public boolean copy(@NonNull IFile targetFullPath, boolean deleteSourceWhenSucce @Override public OutputStream openOutputStream() throws FileNotFoundException { DocumentFile androidFile = getAndroidFile(false); - String context = strategyID + "openOutputStream overwrite existing "; + String context = "openOutputStream overwrite existing "; if (androidFile == null) { - final DocumentFile documentFileParent = documentFileTranslator.getOrCreateDirectory(getFile().getParentFile(), strategyID); + final DocumentFile documentFileParent = documentFileTranslator.getOrCreateDirectory(getFile().getParentFile()); androidFile = this.androidFile = documentFileParent.createFile(null, getFile().getName()); - context = strategyID + "openOutputStream create new "; + context = "openOutputStream create new "; invalidateParentDirCache(); } if (FileFacade.debugLogFacade) { @@ -314,7 +313,7 @@ public OutputStream openOutputStream() throws FileNotFoundException { @Override public InputStream openInputStream() throws FileNotFoundException { - String context = strategyID + "openInputStream "; + String context = "openInputStream "; if ((readUri != null)) { if (debugLogFacade) { Log.i(LOG_TAG, context + this + " for uri " + readUri); @@ -339,16 +338,16 @@ public InputStream openInputStream() throws FileNotFoundException { @Override public void invalidateParentDirCache() { if (documentFileTranslator != null) - documentFileTranslator.documentFileCache.invalidateParentDirCache(strategyID); + documentFileTranslator.documentFileCache.invalidateParentDirCache(); } - private IFile[] get(DocumentFile[] docs, int strategyID) { + private IFile[] get(DocumentFile[] docs) { AndroidFileFacade[] f = new AndroidFileFacade[docs.length]; final File parent = getFile(); for (int i = 0; i < docs.length; i++) { final DocumentFile doc = docs[i]; - f[i] = new AndroidFileFacade(doc, new File(parent, doc.getName()), strategyID); + f[i] = new AndroidFileFacade(doc, new File(parent, doc.getName())); } return f; 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 684a9da8..6af135e0 100644 --- a/app/src/main/java/de/k3b/android/io/DocumentFileCache.java +++ b/app/src/main/java/de/k3b/android/io/DocumentFileCache.java @@ -18,43 +18,29 @@ */ package de.k3b.android.io; -import android.util.Log; - import androidx.documentfile.provider.DocumentFile; 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; public class DocumentFileCache { private static final String TAG = DocumentFileTranslator.TAG; - private CurrentFileCache[] currentFileCaches = null; + private CurrentFileCache currentFileCache = null; - /** - * strategyID : IFile.STRATEGY_XXX. - */ - public CurrentFileCache getCacheStrategy(int strategyID) { - if (currentFileCaches == null) { - currentFileCaches = new CurrentFileCache[IFile.STRATEGY_MAX + 1]; - currentFileCaches[IFile.STRATEGY_INPUT] = new CurrentFileCache(); - currentFileCaches[IFile.STRATEGY_OUTPUT] = new CurrentFileCache(); - currentFileCaches[IFile.STRATEGY_NONE] = null; - } - if (strategyID >= 0 && strategyID < currentFileCaches.length) { - return currentFileCaches[strategyID]; + public CurrentFileCache getCacheStrategy() { + if (currentFileCache == null) { + currentFileCache = new CurrentFileCache(); } - Log.w(TAG, "DocumentFileCache.setCacheStrategy(id=" + strategyID + - ") unknow Strategy"); - return currentFileCaches[IFile.STRATEGY_NONE]; + return currentFileCache; } - public DocumentFile findFile(DocumentFile parentDoc, File parentFile, String displayName, int strategyID) { + public DocumentFile findFile(DocumentFile parentDoc, File parentFile, String displayName) { if (Global.android_DocumentFile_find_cache) { - CurrentFileCache currentFileCache = getCacheStrategy(strategyID); + CurrentFileCache currentFileCache = getCacheStrategy(); if (currentFileCache != null) { if (!parentFile.equals(currentFileCache.lastParentFile)) { @@ -80,8 +66,8 @@ public DocumentFile findFile(DocumentFile parentDoc, File parentFile, String dis return parentDoc.findFile(displayName); } - public void invalidateParentDirCache(int strategyID) { - CurrentFileCache currentFileCache = getCacheStrategy(strategyID); + public void invalidateParentDirCache() { + CurrentFileCache currentFileCache = getCacheStrategy(); if (currentFileCache != null) currentFileCache.lastParentFile = null; } diff --git a/app/src/main/java/de/k3b/android/io/DocumentFileTranslator.java b/app/src/main/java/de/k3b/android/io/DocumentFileTranslator.java index cb941b84..b62ccd16 100644 --- a/app/src/main/java/de/k3b/android/io/DocumentFileTranslator.java +++ b/app/src/main/java/de/k3b/android/io/DocumentFileTranslator.java @@ -179,21 +179,21 @@ public DocumentFileTranslator add(File directory, DocumentFile documentFileDir) return this; } - private DocumentFile getDocumentFileOrDirImpl(File fileOrDir, boolean isDir, int strategyID) { + private DocumentFile getDocumentFileOrDirImpl(File fileOrDir, boolean isDir) { DocumentFile result = null; if (fileOrDir != null) { result = getFromCache(fileOrDir); if (result == null) { - DocumentFile parent = getDocumentFileOrDirImpl(fileOrDir.getParentFile(), true, strategyID); + DocumentFile parent = getDocumentFileOrDirImpl(fileOrDir.getParentFile(), true); if (parent != null) { - result = findFile(parent, fileOrDir, isDir, strategyID); + result = findFile(parent, fileOrDir, isDir); } } } return result; } - private DocumentFile findFile(DocumentFile parentDoc, File fileOrDir, boolean isDir, int strategyID) { + private DocumentFile findFile(DocumentFile parentDoc, File fileOrDir, boolean isDir) { String displayName = fileOrDir.getName(); File parentFile = fileOrDir.getParentFile(); if (isDir) { @@ -212,7 +212,7 @@ private DocumentFile findFile(DocumentFile parentDoc, File fileOrDir, boolean is } return foundDoc; } else { - return documentFileCache.findFile(parentDoc, parentFile, displayName, strategyID); + return documentFileCache.findFile(parentDoc, parentFile, displayName); } } @@ -221,14 +221,14 @@ private DocumentFile findFile(DocumentFile parentDoc, File fileOrDir, boolean is * * @return the found or created directory */ - public DocumentFile getOrCreateDirectory(File directory, int strategyID) { + public DocumentFile getOrCreateDirectory(File directory) { DocumentFile result = null; if (directory != null) { result = getFromCache(directory); if (result == null) { - DocumentFile parent = getOrCreateDirectory(directory.getParentFile(), strategyID); + DocumentFile parent = getOrCreateDirectory(directory.getParentFile()); if ((parent != null) && parent.isDirectory()) { - result = findFile(parent, directory, true, strategyID); + result = findFile(parent, directory, true); if (result == null) { result = parent.createDirectory(directory.getName()); @@ -244,18 +244,17 @@ public DocumentFile getOrCreateDirectory(File directory, int strategyID) { * gets existing DocumentFile that correspondws to fileOrDir * or null if not exists or no write permissions * - * @param fileOrDir where DocumentFile is searched for - * @param isDir if null: return null if isDir is matchning - * @param strategyID + * @param fileOrDir where DocumentFile is searched for + * @param isDir if null: return null if isDir is matchning * @return DocumentFile or null */ - public DocumentFile getDocumentFileOrDirOrNull(File fileOrDir, Boolean isDir, int strategyID) { + public DocumentFile getDocumentFileOrDirOrNull(File fileOrDir, Boolean isDir) { DocumentFile result = null; String path = fileOrDir != null ? fileOrDir.getAbsolutePath() : ""; final String context = FileFacade.debugLogFacade ? (mDebugPrefix + "getDocumentFile('" + path + "') ") : null; try { - result = getDocumentFileOrDirImpl(fileOrDir, isDir == Boolean.TRUE, strategyID); + result = getDocumentFileOrDirImpl(fileOrDir, isDir == Boolean.TRUE); if ((context != null) && (result == null)) { Log.i(TAG, context + "not found"); } diff --git a/fotolib2/src/main/java/de/k3b/io/FileCommandLogger.java b/fotolib2/src/main/java/de/k3b/io/FileCommandLogger.java index c7f26ec3..f67fd5d5 100644 --- a/fotolib2/src/main/java/de/k3b/io/FileCommandLogger.java +++ b/fotolib2/src/main/java/de/k3b/io/FileCommandLogger.java @@ -46,8 +46,7 @@ public void openLogfile() { OutputStream stream = null; try { IFile logFile = FileFacade - .convert("FileCommandLogger.openLogfile", mLogFilePath) - .cacheStrategy(IFile.STRATEGY_OUTPUT); + .convert("FileCommandLogger.openLogfile", mLogFilePath); if (logFile.exists()) { // open existing in append mode diff --git a/fotolib2/src/main/java/de/k3b/io/FileCommands.java b/fotolib2/src/main/java/de/k3b/io/FileCommands.java index 8832ddc6..6c190c74 100644 --- a/fotolib2/src/main/java/de/k3b/io/FileCommands.java +++ b/fotolib2/src/main/java/de/k3b/io/FileCommands.java @@ -216,7 +216,6 @@ int moveOrCopyFilesTo(boolean move, IFile destDirFolder, IProgessListener progessListener) { int result = 0; if (canProcessFile(move ? OP_MOVE : OP_COPY)) { - if (destDirFolder != null) destDirFolder.cacheStrategy(IFile.STRATEGY_OUTPUT); if (osCreateDirIfNeccessary(destDirFolder)) { IFile[] destFiles = createDestFiles(renameProcessor, destDirFolder, selectedFiles.getDatesPhotoTaken(), selectedFiles.getIFiles()); @@ -298,7 +297,6 @@ private IFile[] createDestFiles(IFileNameProcessor renameProcessor, IFile destDi } else { destFile = destDirFolder.create(srcFile.getName()); } - destFile.cacheStrategy(IFile.STRATEGY_OUTPUT); result[pos++] = destFile; } @@ -420,9 +418,6 @@ protected int moveOrCopyFiles(final boolean move, String what, PhotoPropertiesDi // destFile might have renamed it-s extension for private images destFile = FileFacade.convert(mDebugPrefix + "moveOrCopyFiles dest", modifiedOutPath); sameFile = (sourceFile != null) && sourceFile.equals(destFile); - if (!sameFile && destFile != null) { - destFile.cacheStrategy(IFile.STRATEGY_OUTPUT); - } } addProcessedFiles(move, destFile, sourceFile); diff --git a/fotolib2/src/main/java/de/k3b/media/ExifInterface.java b/fotolib2/src/main/java/de/k3b/media/ExifInterface.java index 490782a1..69c6465b 100644 --- a/fotolib2/src/main/java/de/k3b/media/ExifInterface.java +++ b/fotolib2/src/main/java/de/k3b/media/ExifInterface.java @@ -1416,10 +1416,8 @@ public void saveAttributes(IFile inFile, IFile outFile, if (overwriteOriginal) { final String name = inFile.getName(); final String tempName = name + TMP_FILE_SUFFIX; - inFile = renameSouraceFileBeforeReplaceOrThrow(inFile.cacheStrategy(IFile.STRATEGY_NONE), tempName).cacheStrategy(IFile.STRATEGY_NONE); - currentOutFile = outFile.getParentFile().create(name).cacheStrategy(IFile.STRATEGY_NONE); - } else { - currentOutFile.cacheStrategy(IFile.STRATEGY_OUTPUT); + inFile = renameSouraceFileBeforeReplaceOrThrow(inFile, tempName); + currentOutFile = outFile.getParentFile().create(name); } saveJpegAttributes( diff --git a/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/FileFacade.java b/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/FileFacade.java index de5e8773..954a06db 100644 --- a/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/FileFacade.java +++ b/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/FileFacade.java @@ -57,8 +57,6 @@ public IFile convert(String dbgContext, File file) { private File file; - protected int strategyID = 0; - private static final List allowedFileSuffixesLowercase = new ArrayList<>(); static { @@ -315,7 +313,7 @@ public long length() { @Override public String toString() { - return String.format("%s: %d-%s", this.getClass().getSimpleName(), strategyID, file.getAbsoluteFile()); + return String.format("%s: %s", this.getClass().getSimpleName(), file.getAbsoluteFile()); } @Override @@ -331,12 +329,6 @@ protected void setFile(File file) { } - @Override - public IFile cacheStrategy(int strategyID) { - this.strategyID = strategyID; - return this; - } - @Override public void invalidateParentDirCache() { } diff --git a/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/FileWrapper.java b/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/FileWrapper.java index eb0f9b4a..ca21ff92 100644 --- a/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/FileWrapper.java +++ b/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/FileWrapper.java @@ -177,12 +177,6 @@ public long length() { return child.length(); } - @Override - public IFile cacheStrategy(int strategyID) { - child.cacheStrategy(strategyID); - return this; - } - @Override public void invalidateParentDirCache() { child.invalidateParentDirCache(); diff --git a/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/IFile.java b/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/IFile.java index 0f767401..923340cc 100644 --- a/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/IFile.java +++ b/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/IFile.java @@ -33,11 +33,6 @@ * This interface has the similar method names/sinatures as de.k3b.io.File */ public interface IFile { - int STRATEGY_INPUT = 0; - int STRATEGY_OUTPUT = 1; - int STRATEGY_NONE = 2; - int STRATEGY_MAX = STRATEGY_NONE; - void set(IFile src); boolean renameTo(String newName); @@ -99,8 +94,6 @@ public interface IFile { long length(); //------- file cache support - IFile cacheStrategy(int strategyID); - // may be called after delete, renameTo, openOutputStream, mkdirs void invalidateParentDirCache(); } diff --git a/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/StringFileFacade.java b/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/StringFileFacade.java index 208e46b2..503d9346 100644 --- a/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/StringFileFacade.java +++ b/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/StringFileFacade.java @@ -228,11 +228,6 @@ public long length() { return 0; } - @Override - public IFile cacheStrategy(int strategyID) { - return this; - } - @Override public void invalidateParentDirCache() {