diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/Preferences.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/Preferences.java index 919a87493..02ea402b8 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/Preferences.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/Preferences.java @@ -82,6 +82,9 @@ public final class Preferences { // Optional Squeezebox Server password private static final String KEY_MAC = "squeezer.mac"; + // Timestamp when the last scan finished per server + private static final String KEY_LAST_SCAN = "lastScan"; + private static final String KEY_LAST_RUN_VERSION_CODE = "lastRunVersionCode"; // The playerId that we were last connected to. e.g. "00:04:20:17:04:7f" @@ -291,6 +294,7 @@ private void readServerAddress(ServerAddress serverAddress, String address, int serverAddress.password = getStringPreference(prefix(serverAddress) + KEY_PASSWORD); serverAddress.wakeOnLan = sharedPreferences.getBoolean(prefix(serverAddress) + KEY_WOL, false); serverAddress.mac = Util.parseMac(getStringPreference(prefix(serverAddress) + KEY_MAC)); + serverAddress.lastScan = sharedPreferences.getLong(prefix(serverAddress) + KEY_LAST_SCAN, 0); } private String getBssId() { @@ -342,6 +346,8 @@ public static class ServerAddress { public boolean wakeOnLan; public byte[] mac; + public long lastScan; + private ServerAddress(String bssId, int defaultPort) { this.defaultPort = defaultPort; this.bssId = bssId; @@ -444,6 +450,13 @@ public void saveServerAddress(ServerAddress serverAddress) { editor.apply(); } + public void saveLastScan(ServerAddress serverAddress, long lastScan) { + serverAddress.lastScan = lastScan; + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putLong(prefix(serverAddress) + KEY_LAST_SCAN, lastScan); + editor.apply(); + } + public long getLastRunVersionCode() { return sharedPreferences.getLong(KEY_LAST_RUN_VERSION_CODE, 0); } diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/service/CometClient.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/service/CometClient.java index 2eca21cc4..998d7f0da 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/service/CometClient.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/service/CometClient.java @@ -75,6 +75,7 @@ import uk.org.ngo.squeezer.service.event.PlayerVolume; import uk.org.ngo.squeezer.service.event.RegisterSqueezeNetwork; import uk.org.ngo.squeezer.util.FluentHashMap; +import uk.org.ngo.squeezer.util.ImageFetcher; import uk.org.ngo.squeezer.util.Reflection; import uk.org.ngo.squeezer.util.SendWakeOnLan; @@ -360,6 +361,14 @@ private void parseServerStatus(ClientSessionChannel channel, Message message) { // so we check the server version which is also set from server status boolean firstTimePlayersReceived = (getConnectionState().getServerVersion() == null); + final Preferences preferences = Squeezer.getPreferences(); + final Preferences.ServerAddress serverAddress = preferences.getServerAddress(); + long lastScan = Util.getLong(data, "lastscan"); + if (lastScan > 0 && lastScan != serverAddress.lastScan) { + preferences.saveLastScan(serverAddress, lastScan); + ImageFetcher.getInstance(Squeezer.getInstance()).clearCache(); + } + getConnectionState().setMediaDirs(Util.getStringArray(data, ConnectionState.MEDIA_DIRS)); getConnectionState().setServerVersion((String) data.get("version")); Object[] item_data = (Object[]) data.get("players_loop"); diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/util/DiskLruCache.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/util/DiskLruCache.java index 9747f7d65..83931d619 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/util/DiskLruCache.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/util/DiskLruCache.java @@ -642,9 +642,7 @@ public synchronized boolean remove(String key) throws IOException { for (int i = 0; i < valueCount; i++) { File file = entry.getCleanFile(i); - if (!file.delete()) { - throw new IOException("failed to delete " + file); - } + deleteIfExists(file); size -= entry.lengths[i]; entry.lengths[i] = 0; } diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/util/ImageCache.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/util/ImageCache.java index e15641ea1..dfc110fea 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/util/ImageCache.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/util/ImageCache.java @@ -408,7 +408,7 @@ public void clearCache() { synchronized (mDiskCacheLock) { mDiskCacheStarting = true; - if (mDiskLruCache != null && !mDiskLruCache.isClosed()) { + if (mDiskLruCache != null) { try { mDiskLruCache.delete(); if (BuildConfig.DEBUG) {