diff --git a/ReadMe.txt b/ReadMe.txt index 2390e90..a6d42d9 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -54,12 +54,13 @@ NOT WORKING YET CHANGES -Version 1.7 (2019-11-29) +Version 1.7beta2 (2019-11-03) - Updated source code from Eric Rechlin's Emu48 version 1.61+ that was merged from Christoph Gießelink's Emu48 version 1.62. - Allow to take a screenshot of the fullscreen including the skin. - Add the KML Icon if present in the navigation menu header (only support PNG or 32bits BMP in the ICO file). - Add an optional overlapping LCD part stuck to the screen when swiping the 2 calc parts (Experimental). +- Improve loading speed by caching the KML folder. Version 1.6 (2019-07-15) diff --git a/app/src/main/assets/ReadMe.txt b/app/src/main/assets/ReadMe.txt index 8a6dbb8..8a55222 100644 --- a/app/src/main/assets/ReadMe.txt +++ b/app/src/main/assets/ReadMe.txt @@ -54,12 +54,13 @@ NOT WORKING YET CHANGES -Version 1.7 (2019-11-29) +Version 1.7beta2 (2019-11-03) - Updated source code from Eric Rechlin's Emu48 version 1.61+ that was merged from Christoph Gießelink's Emu48 version 1.62. - Allow to take a screenshot of the fullscreen including the skin. - Add the KML Icon if present in the navigation menu header (only support PNG or 32bits BMP in the ICO file). - Add an optional overlapping LCD part stuck to the screen when swiping the 2 calc parts (Experimental). +- Improve loading speed by caching the KML folder. Version 1.6 (2019-07-15) diff --git a/app/src/main/java/org/emulator/forty/eight/MainActivity.java b/app/src/main/java/org/emulator/forty/eight/MainActivity.java index e9df5b4..88b4c0f 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -81,6 +81,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -289,6 +290,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On if(lcdOverlappingView != null) lcdOverlappingView.saveViewLayout(); + clearFolderCache(); + super.onStop(); } @@ -1290,20 +1293,29 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On return fd; } + + String folderURLCached = null; + HashMap folderCache = new HashMap<>(); + + public void clearFolderCache() { + folderURLCached = null; + folderCache.clear(); + } + @SuppressWarnings("unused") public int openFileInFolderFromContentResolver(String filename, String folderURL, int writeAccess) { - Uri folderURI = Uri.parse(folderURL); - DocumentFile folderDocumentFile = DocumentFile.fromTreeUri(this, folderURI); - if(folderDocumentFile != null) { - for (DocumentFile file : folderDocumentFile.listFiles()) { - String url = file.getUri().toString(); - String name = file.getName(); - //Log.d(TAG, "url: " + url + ", name: " + name); - if (filename.equals(name)) { - return openFileFromContentResolver(url, writeAccess); - } - } + if(folderURLCached == null || !folderURLCached.equals(folderURL)) { + folderURLCached = folderURL; + folderCache.clear(); + Uri folderURI = Uri.parse(folderURL); + DocumentFile folderDocumentFile = DocumentFile.fromTreeUri(this, folderURI); + if (folderDocumentFile != null) + for (DocumentFile file : folderDocumentFile.listFiles()) + folderCache.put(file.getName(), file.getUri().toString()); } + String filenameUrl = folderCache.get(filename); + if(filenameUrl != null) + return openFileFromContentResolver(filenameUrl, writeAccess); return -1; }