From c2bc146e7bdc68978106c9e60797c3d4b0ef5937 Mon Sep 17 00:00:00 2001 From: dgis Date: Fri, 10 Apr 2020 00:26:59 +0200 Subject: [PATCH] Remove the non loadable file from the most recent used state file list (Fix #13). --- .../org/emulator/forty/eight/MainActivity.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 cff20f5..ebf132b 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -123,6 +123,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On private int selectedRAMSize = -1; private boolean[] objectsToSaveItemChecked = null; + // Most Recently Used state files private int MRU_ID_START = 10000; private int MAX_MRU = 5; private LinkedHashMap mruLinkedHashMap = new LinkedHashMap(5, 1.0f, true) { @@ -254,8 +255,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On Set mruLinkedHashMapKeySet = mruLinkedHashMap.keySet(); String[] mrus = mruLinkedHashMapKeySet.toArray(new String[0]); for (int i = mrus.length - 1; i >= 0; i--) { - String displayName = getFilenameFromURL(mrus[i]); - recentsSubMenu.add(Menu.NONE, MRU_ID_START + i, Menu.NONE, displayName); + String mostRecentlyUsedFile = mrus[i]; + String displayName = getFilenameFromURL(mostRecentlyUsedFile); + if(displayName == null || displayName.equals("") || displayName.equals(mostRecentlyUsedFile)) { + // We should remove this file because it seems impossible to get the display name of this Most Recently Used state file. + // It might be deleted or the permissions does not allow to reach it anymore. + mruLinkedHashMap.remove(mostRecentlyUsedFile); + } else + recentsSubMenu.add(Menu.NONE, MRU_ID_START + i, Menu.NONE, displayName); } } } @@ -398,6 +405,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ensureDocumentSaved(() -> { if(onFileOpen(url) != 0) { saveLastDocument(url); + } else { + // We should remove this file from the MRU list because it might be deleted or the permissions does not allow to reach it anymore. + mruLinkedHashMap.remove(url); + navigationView.post(this::updateMRU); } });