diff --git a/Squeezer/build.gradle b/Squeezer/build.gradle index 5ee59bf61..e46c11dbc 100644 --- a/Squeezer/build.gradle +++ b/Squeezer/build.gradle @@ -178,6 +178,7 @@ slimstrings { 'SETTINGS', 'SCREEN_SETTINGS', 'ADVANCED_SETTINGS', + 'RESCANNING_SHORT', 'EXTRAS', 'SETUP_PLAYTRACKALBUM', 'SETUP_PLAYTRACKALBUM_DESC', diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/framework/BaseActivity.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/framework/BaseActivity.java index 2017025fe..14f00e22d 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/framework/BaseActivity.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/framework/BaseActivity.java @@ -385,12 +385,7 @@ public void showDisplayMessage(@StringRes int resId) { } public void showDisplayMessage(String text) { - Map display = new HashMap<>(); - display.put("text", new String[]{ text }); - display.put("type", "text"); - display.put("style", "style"); // TODO: What is the proper object for style? - DisplayMessage displayMessage = new DisplayMessage(display); - showDisplayMessage(displayMessage); + showDisplayMessage(new DisplayMessage(text)); } @Subscribe(threadMode = ThreadMode.MAIN) diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/framework/ItemListActivity.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/framework/ItemListActivity.java index 67becc6e8..91a59cd57 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/framework/ItemListActivity.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/framework/ItemListActivity.java @@ -47,6 +47,7 @@ import uk.org.ngo.squeezer.service.SqueezeService; import uk.org.ngo.squeezer.service.event.ActivePlayerChanged; import uk.org.ngo.squeezer.service.event.HandshakeComplete; +import uk.org.ngo.squeezer.service.event.RefreshEvent; import uk.org.ngo.squeezer.util.RetainFragment; /** @@ -287,6 +288,12 @@ public void onEventMainThread(ActivePlayerChanged event) { } } + @MainThread + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEventMainThread(RefreshEvent event) { + clearAndReOrderItems(); + } + /** * Orders any pages requested before the handshake completed. */ diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/model/DisplayMessage.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/model/DisplayMessage.java index 8fc35795f..25a61ba29 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/model/DisplayMessage.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/model/DisplayMessage.java @@ -26,12 +26,14 @@ import uk.org.ngo.squeezer.R; import uk.org.ngo.squeezer.Util; +import uk.org.ngo.squeezer.util.FluentHashMap; /** * The purpose of the showBriefly is (typically) to show a brief popup message on the display to * convey something to the user. */ public class DisplayMessage { + private static final int DEFAULT_DURATION = 3000; private static final String TYPE_ICON = "icon"; private static final String TYPE_TEXT = "text"; private static final String TYPE_MIXED = "mixed"; @@ -51,11 +53,11 @@ public class DisplayMessage { public final String text; /** Remote icon or {@link Uri#EMPTY} */ - @NonNull public Uri icon; + @NonNull public final Uri icon; public DisplayMessage(Map display) { type = Util.getString(display, "type", TYPE_TEXT); - duration = Util.getInt(display, "duration", 3000); + duration = Util.getInt(display, "duration", DEFAULT_DURATION); style = Util.getString(display, "style"); Object[] texts = (Object[]) display.get("text"); String text = TextUtils.join("\n",texts).replaceAll("\\\\n", "\n"); @@ -63,6 +65,10 @@ public DisplayMessage(Map display) { icon = Util.getImageUrl(display, display.containsKey("icon-id") ? "icon-id" : "icon"); } + public DisplayMessage(String text) { + this(new FluentHashMap().with("type", "text").with("text", new String[]{ text })); + } + public boolean isIcon() { return (TYPE_ICON.equals(type) && !TextUtils.isEmpty(style)); } 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 1ec0fccfa..c637d8db2 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 @@ -391,6 +391,17 @@ private void parseServerStatus(ClientSessionChannel channel, Message message) { ImageFetcher.getInstance(Squeezer.getInstance()).clearCache(); } + boolean rescan = Util.getInt(data, "rescan") != 0; + getConnectionState().setRescan( + rescan, + Util.getString(data, "progressname"), + Util.getString(data, "progressdone"), + Util.getString(data, "progresstotal")); + if (rescan) { + mBackgroundHandler.removeMessages(MSG_REFRESH_SERVER_STATUS); + mBackgroundHandler.sendEmptyMessageDelayed(MSG_REFRESH_SERVER_STATUS, 2000); + } + getConnectionState().setMediaDirs(Util.getStringArray(data, ConnectionState.MEDIA_DIRS)); getConnectionState().setServerVersion((String) data.get("version")); Object[] item_data = (Object[]) data.get("players_loop"); @@ -811,6 +822,7 @@ private static String getAdviceAction(Map advice) { private static final int MSG_TIME_UPDATE = 6; private static final int MSG_SLEEP_UPDATE = 7; private static final int MSG_MUSIC_CHANGED = 8; + private static final int MSG_REFRESH_SERVER_STATUS = 9; private class CliHandler extends Handler { CliHandler(Looper looper) { super(looper); @@ -862,6 +874,9 @@ public void handleMessage(android.os.Message msg) { } break; } + case MSG_REFRESH_SERVER_STATUS: + requestServerStatus(); + break; } } } diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/service/ConnectionState.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/service/ConnectionState.java index 814fb571f..a8351db72 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/service/ConnectionState.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/service/ConnectionState.java @@ -20,11 +20,8 @@ import android.text.TextUtils; import android.util.Log; -import androidx.annotation.IntDef; import androidx.annotation.NonNull; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -35,15 +32,19 @@ import java.util.concurrent.atomic.AtomicReference; import org.greenrobot.eventbus.EventBus; + +import uk.org.ngo.squeezer.R; +import uk.org.ngo.squeezer.Squeezer; import uk.org.ngo.squeezer.Util; -import uk.org.ngo.squeezer.model.CustomJiveItemHandling; +import uk.org.ngo.squeezer.model.DisplayMessage; import uk.org.ngo.squeezer.model.MenuStatusMessage; import uk.org.ngo.squeezer.model.Player; -import uk.org.ngo.squeezer.model.PlayerState; import uk.org.ngo.squeezer.service.event.ActivePlayerChanged; import uk.org.ngo.squeezer.service.event.ConnectionChanged; +import uk.org.ngo.squeezer.service.event.DisplayEvent; import uk.org.ngo.squeezer.service.event.HandshakeComplete; import uk.org.ngo.squeezer.service.event.PlayersChanged; +import uk.org.ngo.squeezer.service.event.RefreshEvent; public class ConnectionState { @@ -295,6 +296,23 @@ boolean canRehandshake() { && ((SystemClock.elapsedRealtime() - rehandshake) < REHANDSHAKE_TIMEOUT); } + private volatile boolean rescan; + + public void setRescan(boolean rescan, String progressName, String progressDone, String progressTotal) { + if (rescan || rescan != this.rescan) { + this.rescan = rescan; + mEventBus.post(rescan + ? new DisplayEvent(new DisplayMessage(formatScanningProgress(progressName, progressDone, progressTotal))) + : new RefreshEvent() + ); + } + } + + private String formatScanningProgress(String progressName, String progressDone, String progressTotal) { + if (progressName == null) return Squeezer.getInstance().getString(R.string.RESCANNING_SHORT); + return progressName + (progressDone != null && progressTotal != null ? String.format(" %s/%s", progressDone, progressTotal) : ""); + } + @NonNull @Override public String toString() { diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/service/event/RefreshEvent.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/service/event/RefreshEvent.java new file mode 100644 index 000000000..6046eb610 --- /dev/null +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/service/event/RefreshEvent.java @@ -0,0 +1,7 @@ +package uk.org.ngo.squeezer.service.event; + +/** + * Event sent when the current page needs to reload. + */ +public class RefreshEvent { +} diff --git a/Squeezer/src/main/res/values-da/serverstrings.xml b/Squeezer/src/main/res/values-da/serverstrings.xml index 695bb3101..53a726f16 100644 --- a/Squeezer/src/main/res/values-da/serverstrings.xml +++ b/Squeezer/src/main/res/values-da/serverstrings.xml @@ -4,6 +4,7 @@ Automatically generated file. DO NOT MODIFY Justering af lydstyrke %s minutter Slumre + Gennemsøger mediebibliotek igen… Vækkeur Udgangsnivau er fast 100% Tænd/sluk med gruppe diff --git a/Squeezer/src/main/res/values-de/serverstrings.xml b/Squeezer/src/main/res/values-de/serverstrings.xml index 622f51c5b..bc4d46da5 100644 --- a/Squeezer/src/main/res/values-de/serverstrings.xml +++ b/Squeezer/src/main/res/values-de/serverstrings.xml @@ -31,6 +31,7 @@ Automatically generated file. DO NOT MODIFY Alle Wecker Schlafmodus in Lautstärkeregelung + Medienbibliothek wird durchsucht… In Gruppe ein-/ausschalten \n%s\nwird aus Wiedergabeliste entfernt… Wecker entfernen diff --git a/Squeezer/src/main/res/values-fr/serverstrings.xml b/Squeezer/src/main/res/values-fr/serverstrings.xml index 6c60e1b1f..cc2a0a6ad 100644 --- a/Squeezer/src/main/res/values-fr/serverstrings.xml +++ b/Squeezer/src/main/res/values-fr/serverstrings.xml @@ -31,6 +31,7 @@ Automatically generated file. DO NOT MODIFY Tous les réveils Mise en veille dans Réglage du volume + Nouvelle analyse de la bibliothèque multimédia en cours… Allumer/éteindre avec groupe Suppression de\n%s\nde la liste de lecture… Supprimer le réveil diff --git a/Squeezer/src/main/res/values-nl/serverstrings.xml b/Squeezer/src/main/res/values-nl/serverstrings.xml index f7a223675..f1de29e6b 100644 --- a/Squeezer/src/main/res/values-nl/serverstrings.xml +++ b/Squeezer/src/main/res/values-nl/serverstrings.xml @@ -31,6 +31,7 @@ Automatically generated file. DO NOT MODIFY Alle wekkers Sluimermodus in Volumeregelaar + Mediabibliotheek wordt opnieuw gescand… In groep uit-/aanzetten Bezig met verwijderen van\n%s\nuit afspeellijst… Wekker verwijderen diff --git a/Squeezer/src/main/res/values/serverstrings.xml b/Squeezer/src/main/res/values/serverstrings.xml index 5110f65b3..5b0366754 100644 --- a/Squeezer/src/main/res/values/serverstrings.xml +++ b/Squeezer/src/main/res/values/serverstrings.xml @@ -31,6 +31,7 @@ Automatically generated file. DO NOT MODIFY All Alarms Sleeping in Volume Control + Rescanning Media Library… Power off/on with group Removing\n%s\nfrom Playlist… Remove Alarm