diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/PhotoPropertiesEditActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/PhotoPropertiesEditActivity.java index 8c71f15e..e9c5375d 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/PhotoPropertiesEditActivity.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/PhotoPropertiesEditActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 by k3b. + * Copyright (c) 2017-2022 by k3b. * * This file is part of AndroFotoFinder / #APhotoManager. * @@ -278,7 +278,7 @@ private static SelectedFiles getSelectedFiles(String dbgContext, Context ctx, In if (result == null) { String path = IntentUtil.getFilePath(ctx, IntentUtil.getUri(intent)); - String fileNames[] = SelectedFiles.getFileNameList(path); + String[] fileNames = SelectedFiles.getFileNameList(path); Long[] ids = null; int itemCount = (fileNames != null) ? fileNames.length : 0; @@ -849,7 +849,7 @@ public void afterGrant(FilePermissionActivity activity) { return false; } - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Log.i(FilePermissionActivity.TAG, "PhotoPropertiesEditActivity.execExifUpdate.do"); } diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java index b7500275..6dea96e4 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2020 by k3b. + * Copyright (c) 2015-2021 by k3b. * * This file is part of AndroFotoFinder / #APhotoManager. * @@ -63,100 +63,7 @@ public class SettingsActivity extends PreferenceActivity { private ListPreference mediaUpdateStrategyPreference; private ListPreference themePreference; // #21: Support to change locale at runtime - private int INSTALL_REQUEST_CODE = 1927; - - @Override - protected void onCreate(final Bundle savedInstanceState) { - LocalizedActivity.fixThemeAndLocale(this); // #21: Support to change locale at runtime - super.onCreate(savedInstanceState); - - if (Global.debugEnabled) { - // todo create junit integration tests with arabic locale from this. - StringFormatResourceTests.test(this); - } - - final Intent intent = getIntent(); - if (Global.debugEnabled && (intent != null)){ - Log.d(Global.LOG_CONTEXT, "SettingsActivity onCreate " + intent.toUri(Intent.URI_INTENT_SCHEME)); - } - - if (FileFacade.debugLogFacade) { - this.addPreferencesFromResource(R.xml.preferences_saf169_test); - findPreference("debugClearSafCache").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - DocumentFileTranslator.clearCache(); - Toast.makeText(SettingsActivity.this, "debugClearSafCache", - Toast.LENGTH_LONG).show(); - finish(); - return true; // do close - } - }); - } - - this.addPreferencesFromResource(R.xml.preferences); - prefsInstance = PreferenceManager - .getDefaultSharedPreferences(this); - global2Prefs(this.getApplication()); - - // #21: Support to change locale at runtime - defaultLocalePreference = - (ListPreference) findPreference(Global.PREF_KEY_USER_LOCALE); - defaultLocalePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - setLanguage((String) newValue); - LocalizedActivity.recreate(SettingsActivity.this); - return true; // change is allowed - } - }); - - themePreference = (ListPreference) findPreference(UserTheme.PREF_KEY_USER_THEME); - themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - setUserTheme((String) newValue); - LocalizedActivity.recreate(SettingsActivity.this); - return true; // change is allowed - } - }); - mediaUpdateStrategyPreference = - (ListPreference) findPreference("mediaUpdateStrategy"); - mediaUpdateStrategyPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - LibGlobal.mediaUpdateStrategy = (String) newValue; - setPrefSummayFromKey(LibGlobal.mediaUpdateStrategy, mediaUpdateStrategyPreference, R.array.pref_media_update_strategy_names); - return true; - } - }); - setPrefSummayFromKey(LibGlobal.mediaUpdateStrategy, mediaUpdateStrategyPreference, R.array.pref_media_update_strategy_names); - - findPreference("debugClearLog").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - onDebugClearLogCat(); - return false; // donot close - } - }); - findPreference("debugSaveLog").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - onDebugSaveLogCat(); - return false; // donot close - } - }); - findPreference("translate").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - onTranslate(); - return false; // donot close - } - }); - - // #21: Support to change locale at runtime - updateSummary(); - } + private final int INSTALL_REQUEST_CODE = 1927; public static void global2Prefs(Context context) { fixDefaults(context, null, null); @@ -190,7 +97,7 @@ public static void global2Prefs(Context context) { prefs.putBoolean("xmp_file_schema_long", LibGlobal.preferLongXmpFormat); prefs.putBoolean("mapsForgeEnabled", Global.mapsForgeEnabled); - prefs.putBoolean("debugLogFacade", FileFacade.debugLogFacade); + prefs.putBoolean("debugLogFacade", FileFacade.debugLogSAFFacade); if (Global.allow_emulate_ao10) { prefs.putBoolean(PREF_KEY_USE_MEDIA_IMAGE_DB_REPLACEMENT, Global.useAo10MediaImageDbReplacement); } @@ -267,7 +174,7 @@ public static void prefs2Global(Context context) { LibGlobal.preferLongXmpFormat = getPref(prefs, "xmp_file_schema_long", LibGlobal.preferLongXmpFormat); Global.mapsForgeEnabled = getPref(prefs, "mapsForgeEnabled", Global.mapsForgeEnabled); - FileFacade.debugLogFacade = getPref(prefs, "debugLogFacade", FileFacade.debugLogFacade); + FileFacade.debugLogSAFFacade = getPref(prefs, "debugLogFacade", FileFacade.debugLogSAFFacade); boolean useAo10MediaImageDbReplacement = Global.useAo10MediaImageDbReplacement; @@ -318,6 +225,99 @@ public static void prefs2Global(Context context) { fixDefaults(context, previousCacheRoot, previousMapsForgeDir); } + @Override + protected void onCreate(final Bundle savedInstanceState) { + LocalizedActivity.fixThemeAndLocale(this); // #21: Support to change locale at runtime + super.onCreate(savedInstanceState); + + if (Global.debugEnabled) { + // todo create junit integration tests with arabic locale from this. + StringFormatResourceTests.test(this); + } + + final Intent intent = getIntent(); + if (Global.debugEnabled && (intent != null)) { + Log.d(Global.LOG_CONTEXT, "SettingsActivity onCreate " + intent.toUri(Intent.URI_INTENT_SCHEME)); + } + + if (FileFacade.debugLogSAFFacade) { + this.addPreferencesFromResource(R.xml.preferences_saf169_test); + findPreference("debugClearSafCache").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + DocumentFileTranslator.clearCache(); + Toast.makeText(SettingsActivity.this, "debugClearSafCache", + Toast.LENGTH_LONG).show(); + finish(); + return true; // do close + } + }); + } + + this.addPreferencesFromResource(R.xml.preferences); + prefsInstance = PreferenceManager + .getDefaultSharedPreferences(this); + global2Prefs(this.getApplication()); + + // #21: Support to change locale at runtime + defaultLocalePreference = + (ListPreference) findPreference(Global.PREF_KEY_USER_LOCALE); + defaultLocalePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + setLanguage((String) newValue); + LocalizedActivity.recreate(SettingsActivity.this); + return true; // change is allowed + } + }); + + themePreference = (ListPreference) findPreference(UserTheme.PREF_KEY_USER_THEME); + themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + setUserTheme((String) newValue); + LocalizedActivity.recreate(SettingsActivity.this); + return true; // change is allowed + } + }); + mediaUpdateStrategyPreference = + (ListPreference) findPreference("mediaUpdateStrategy"); + mediaUpdateStrategyPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + LibGlobal.mediaUpdateStrategy = (String) newValue; + setPrefSummayFromKey(LibGlobal.mediaUpdateStrategy, mediaUpdateStrategyPreference, R.array.pref_media_update_strategy_names); + return true; + } + }); + setPrefSummayFromKey(LibGlobal.mediaUpdateStrategy, mediaUpdateStrategyPreference, R.array.pref_media_update_strategy_names); + + findPreference("debugClearLog").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + onDebugClearLogCat(); + return false; // donot close + } + }); + findPreference("debugSaveLog").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + onDebugSaveLogCat(); + return false; // donot close + } + }); + findPreference("translate").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + onTranslate(); + return false; // donot close + } + }); + + // #21: Support to change locale at runtime + updateSummary(); + } + @Override public void onPause() { prefs2Global(this); diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java b/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java index 7b46f3d6..f516c373 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java @@ -271,7 +271,7 @@ private boolean cmdMoveOrCopyWithDestDirPicker(final boolean move, final String public void afterGrant(FilePermissionActivity activity) { // does not work in frag,emt mFileCommands.setContext(activity); - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Log.i(FileFacade.LOG_TAG, this.getClass().getSimpleName() + ": afterGrant " + activity + "-" + this); } diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java b/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java index c65aa5a4..a15e7c3a 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java @@ -731,7 +731,7 @@ public void afterGrant(FilePermissionActivity activity) { return false; } - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Log.i(FilePermissionActivity.TAG, "PhotoPropertiesEditActivity.execExifUpdate.do"); } 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 bdc4b39c..5d1efd0f 100644 --- a/app/src/main/java/de/k3b/android/io/AndroidFileCommands.java +++ b/app/src/main/java/de/k3b/android/io/AndroidFileCommands.java @@ -307,7 +307,7 @@ public void afterGrant(FilePermissionActivity activity) { return false; } - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Log.i(FilePermissionActivity.TAG, "AndroidFileCommands.cmdDeleteFileWithQuestion.do"); } 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 e6a6b0d3..a094bee6 100644 --- a/app/src/main/java/de/k3b/android/io/AndroidFileFacade.java +++ b/app/src/main/java/de/k3b/android/io/AndroidFileFacade.java @@ -80,7 +80,7 @@ public String toString() { @Override public IFile convert(String dbgContext, File file) { final IFile result = new AndroidFileFacade(file); - if (debugLogFacade) { + if (debugLogSAFFacade) { Log.i(LOG_TAG, dbgContext + " convert => " + result); } return result; @@ -259,7 +259,7 @@ public boolean mkdirs() { @Override public IFile[] listFiles() { - reEnableCache(); + enableCache("listFiles", true); final DocumentFile androidFile = getAndroidFile(false); if (androidFile != null) { return get(androidFile.listFiles()); @@ -267,15 +267,23 @@ public IFile[] listFiles() { return new IFile[0]; } - private void reEnableCache() { - if (!Global.android_DocumentFile_find_cache) { - Global.android_DocumentFile_find_cache = true; - invalidateParentDirCache(); + private void enableCache(String dbgContext, boolean enable) { + if (enable != Global.android_DocumentFile_find_cache) { + if (FileFacade.debugLogSAFFacade) { + Log.i(FileFacade.LOG_TAG, this.getClass().getSimpleName() + + " " + dbgContext + ": enableCache(" + enable + ")"); + } + + Global.android_DocumentFile_find_cache = enable; + + if (enable) { + invalidateParentDirCache(); + } } } public IFile[] listDirs() { - reEnableCache(); + enableCache("listDirs", true); List found = new ArrayList<>(); final DocumentFile androidFile = getAndroidFile(false); if (androidFile != null) { @@ -315,12 +323,11 @@ public OutputStream openOutputStream() throws FileNotFoundException { context = "openOutputStream create new "; } - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Log.i(LOG_TAG, context + this); } OutputStream result = documentFileTranslator.createOutputStream(androidFile); - Global.android_DocumentFile_find_cache = false; - invalidateParentDirCache(); + enableCache("openOutputStream", false); return result; } @@ -328,7 +335,7 @@ public OutputStream openOutputStream() throws FileNotFoundException { public InputStream openInputStream() throws FileNotFoundException { String context = "openInputStream "; if ((readUri != null)) { - if (debugLogFacade) { + if (debugLogSAFFacade) { Log.i(LOG_TAG, context + this + " for uri " + readUri); } return documentFileTranslator.openInputStream(readUri); @@ -341,7 +348,7 @@ public InputStream openInputStream() throws FileNotFoundException { Log.w(LOG_TAG, msg); getAndroidFile(true); // allow debugger to step in throw new FileNotFoundException(msg); - } else if (debugLogFacade) { + } else if (debugLogSAFFacade) { Log.i(LOG_TAG, context + this + " for uri " + androidFile.getUri()); } return resultInputStream; 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 6af135e0..38824f16 100644 --- a/app/src/main/java/de/k3b/android/io/DocumentFileCache.java +++ b/app/src/main/java/de/k3b/android/io/DocumentFileCache.java @@ -18,12 +18,15 @@ */ 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.FileFacade; import de.k3b.media.PhotoPropertiesUtil; public class DocumentFileCache { @@ -59,11 +62,21 @@ public DocumentFile findFile(DocumentFile parentDoc, File parentFile, String dis } if (PhotoPropertiesUtil.isImage(displayName, PhotoPropertiesUtil.IMG_TYPE_ALL | PhotoPropertiesUtil.IMG_TYPE_XMP)) { - return currentFileCache.lastChildDocFiles.get(displayName.toLowerCase()); + return logFindFileResult(parentFile, currentFileCache.lastChildDocFiles.get(displayName.toLowerCase())); } } } - return parentDoc.findFile(displayName); + return logFindFileResult(parentFile, parentDoc.findFile(displayName)); + } + + private DocumentFile logFindFileResult(File parentFile, DocumentFile documentFile) { + if (FileFacade.debugLogSAFFacade) { + Log.i(FileFacade.LOG_TAG, this.getClass().getSimpleName() + + ".findFile(" + parentFile + ",cache=" + + Global.android_DocumentFile_find_cache + + ") ==> " + documentFile); + } + return documentFile; } public void invalidateParentDirCache() { 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 2b537f04..e5362375 100644 --- a/app/src/main/java/de/k3b/android/io/DocumentFileTranslator.java +++ b/app/src/main/java/de/k3b/android/io/DocumentFileTranslator.java @@ -170,7 +170,7 @@ protected DocumentFile getFromCache(File fileOrDir) { */ public DocumentFileTranslator add(File directory, DocumentFile documentFileDir) { if ((documentFileDir != null) && documentFileDir.isDirectory()) { - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Uri uri = (documentFileDir != null) ? documentFileDir.getUri() : null; Log.d(TAG, mDebugPrefix + "dirCache.put(" + directory + " -> " + uri + ")"); @@ -232,6 +232,11 @@ public DocumentFile getOrCreateDirectory(File directory) { result = findFile(parent, directory, true); if (result == null) { + if (Global.android_DocumentFile_find_cache && FileFacade.debugLogSAFFacade) { + Log.i(FileFacade.LOG_TAG, this.getClass().getSimpleName() + + " CreateDirectory: enableCache(false)"); + } + Global.android_DocumentFile_find_cache = false; result = parent.createDirectory(directory.getName()); add(directory, result); @@ -253,7 +258,7 @@ public DocumentFile getOrCreateDirectory(File directory) { public DocumentFile getDocumentFileOrDirOrNull(File fileOrDir, Boolean isDir) { DocumentFile result = null; String path = fileOrDir != null ? fileOrDir.getAbsolutePath() : ""; - final String context = FileFacade.debugLogFacade ? (mDebugPrefix + "getDocumentFile('" + final String context = FileFacade.debugLogSAFFacade ? (mDebugPrefix + "getDocumentFile('" + path + "') ") : null; try { result = getDocumentFileOrDirImpl(fileOrDir, isDir == Boolean.TRUE); @@ -327,7 +332,7 @@ private static class Root { public Root(Context context) { this.context = context.getApplicationContext(); loadFromPrefs(); - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Log.i(TAG, "DocumentFileTranslator.Root.loaded(" + this + ")"); } } @@ -390,7 +395,7 @@ private void saveToPrefs() { Log.e(TAG, "err saveToPrefs(" + dir2uri + ")", ex); } finally { edit.commit(); - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Log.i(TAG, "DocumentFileTranslator.Root.saveToPrefs(" + this + ")"); } diff --git a/app/src/main/java/de/k3b/android/widget/FilePermissionActivity.java b/app/src/main/java/de/k3b/android/widget/FilePermissionActivity.java index e7859757..401b2f2d 100644 --- a/app/src/main/java/de/k3b/android/widget/FilePermissionActivity.java +++ b/app/src/main/java/de/k3b/android/widget/FilePermissionActivity.java @@ -93,7 +93,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in && (grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED); if (success) { - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Log.i(FileFacade.LOG_TAG, this.getClass().getSimpleName() + ": onRequestPermissionsResult(success) "); } @@ -164,7 +164,7 @@ public File getMissingRootDirFileOrNull(String dbgContext, File... dirs) { final File dir = dirs[i]; if (!getDocumentFileTranslator().isKnownRoot(dir)) { final File anddroidRootDir = FileNameUtil.getAnddroidRootDir(dir); - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Log.i(TAG, dbgContext + ":" + this.documentFileTranslator + ":getMissingRootDirFileOrNull(" + dir + ") needs " + anddroidRootDir); @@ -204,7 +204,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } private void onRootUriResult(Uri documentRootUri) { - if (FileFacade.debugLogFacade) { + if (FileFacade.debugLogSAFFacade) { Log.i(FileFacade.LOG_TAG, this.getClass().getSimpleName() + ": onRootUriResult(" + documentRootUri + ") "); } 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 4bed03b3..ef851139 100644 --- a/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/FileFacade.java +++ b/libK3bFilefacade/src/main/java/de/k3b/io/filefacade/FileFacade.java @@ -43,12 +43,12 @@ public class FileFacade implements IFile { public static final String LOG_TAG = "k3b.FileFacade"; private static final Logger logger = LoggerFactory.getLogger(LOG_TAG); - public static boolean debugLogFacade = false; + public static boolean debugLogSAFFacade = false; private static Converter fileFacade = new Converter() { @Override public IFile convert(String dbgContext, File file) { final IFile result = new FileFacade(file); - if (debugLogFacade) { + if (debugLogSAFFacade) { logger.info(dbgContext + " convert => " + result); } return result; @@ -318,7 +318,7 @@ public String toString() { @Override public File getFile() { - if (debugLogFacade) { + if (debugLogSAFFacade) { logger.info("getFile() " + file + " from " + this); } return file;