Skip to content

Commit

Permalink
Show server scanning progress
Browse files Browse the repository at this point in the history
and reload current page when scanning is complete.
  • Loading branch information
kaaholst committed Sep 16, 2024
1 parent c413e5a commit b267aca
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 13 deletions.
1 change: 1 addition & 0 deletions Squeezer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ slimstrings {
'SETTINGS',
'SCREEN_SETTINGS',
'ADVANCED_SETTINGS',
'RESCANNING_SHORT',
'EXTRAS',
'SETUP_PLAYTRACKALBUM',
'SETUP_PLAYTRACKALBUM_DESC',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,7 @@ public void showDisplayMessage(@StringRes int resId) {
}

public void showDisplayMessage(String text) {
Map<String, Object> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -51,18 +53,22 @@ 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<String, Object> 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");
this.text = (text.startsWith("\n") ? text.substring(1) : text);
icon = Util.getImageUrl(display, display.containsKey("icon-id") ? "icon-id" : "icon");
}

public DisplayMessage(String text) {
this(new FluentHashMap<String, Object>().with("type", "text").with("text", new String[]{ text }));
}

public boolean isIcon() {
return (TYPE_ICON.equals(type) && !TextUtils.isEmpty(style));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -811,6 +822,7 @@ private static String getAdviceAction(Map<String, Object> 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);
Expand Down Expand Up @@ -862,6 +874,9 @@ public void handleMessage(android.os.Message msg) {
}
break;
}
case MSG_REFRESH_SERVER_STATUS:
requestServerStatus();
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package uk.org.ngo.squeezer.service.event;

/**
* Event sent when the current page needs to reload.
*/
public class RefreshEvent {
}
1 change: 1 addition & 0 deletions Squeezer/src/main/res/values-da/serverstrings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Automatically generated file. DO NOT MODIFY
<string name='SETUP_DIGITALVOLUMECONTROL'>Justering af lydstyrke</string>
<string name='X_MINUTES'>%s minutter</string>
<string name='SLEEP'>Slumre</string>
<string name='RESCANNING_SHORT'>Gennemsøger mediebibliotek igen…</string>
<string name='ALARM'>Vækkeur</string>
<string name='SETUP_DIGITALVOLUMECONTROL_OFF'>Udgangsnivau er fast 100%</string>
<string name='SETUP_SYNCPOWER_ON'>Tænd/sluk med gruppe</string>
Expand Down
1 change: 1 addition & 0 deletions Squeezer/src/main/res/values-de/serverstrings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Automatically generated file. DO NOT MODIFY
<string name='ALARM_ALL_ALARMS'>Alle Wecker</string>
<string name='SLEEPING_IN'>Schlafmodus in</string>
<string name='SETUP_DIGITALVOLUMECONTROL'>Lautstärkeregelung</string>
<string name='RESCANNING_SHORT'>Medienbibliothek wird durchsucht…</string>
<string name='SETUP_SYNCPOWER_ON'>In Gruppe ein-/ausschalten</string>
<string name='JIVE_POPUP_REMOVING_FROM_PLAYLIST'>\n%s\nwird aus Wiedergabeliste entfernt…</string>
<string name='ALARM_DELETE'>Wecker entfernen</string>
Expand Down
1 change: 1 addition & 0 deletions Squeezer/src/main/res/values-fr/serverstrings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Automatically generated file. DO NOT MODIFY
<string name='ALARM_ALL_ALARMS'>Tous les réveils</string>
<string name='SLEEPING_IN'>Mise en veille dans</string>
<string name='SETUP_DIGITALVOLUMECONTROL'>Réglage du volume</string>
<string name='RESCANNING_SHORT'>Nouvelle analyse de la bibliothèque multimédia en cours…</string>
<string name='SETUP_SYNCPOWER_ON'>Allumer/éteindre avec groupe</string>
<string name='JIVE_POPUP_REMOVING_FROM_PLAYLIST'>Suppression de\n%s\nde la liste de lecture…</string>
<string name='ALARM_DELETE'>Supprimer le réveil</string>
Expand Down
1 change: 1 addition & 0 deletions Squeezer/src/main/res/values-nl/serverstrings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Automatically generated file. DO NOT MODIFY
<string name='ALARM_ALL_ALARMS'>Alle wekkers</string>
<string name='SLEEPING_IN'>Sluimermodus in</string>
<string name='SETUP_DIGITALVOLUMECONTROL'>Volumeregelaar</string>
<string name='RESCANNING_SHORT'>Mediabibliotheek wordt opnieuw gescand…</string>
<string name='SETUP_SYNCPOWER_ON'>In groep uit-/aanzetten</string>
<string name='JIVE_POPUP_REMOVING_FROM_PLAYLIST'>Bezig met verwijderen van\n%s\nuit afspeellijst…</string>
<string name='ALARM_DELETE'>Wekker verwijderen</string>
Expand Down
1 change: 1 addition & 0 deletions Squeezer/src/main/res/values/serverstrings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Automatically generated file. DO NOT MODIFY
<string name='ALARM_ALL_ALARMS'>All Alarms</string>
<string name='SLEEPING_IN'>Sleeping in</string>
<string name='SETUP_DIGITALVOLUMECONTROL'>Volume Control</string>
<string name='RESCANNING_SHORT'>Rescanning Media Library…</string>
<string name='SETUP_SYNCPOWER_ON'>Power off/on with group</string>
<string name='JIVE_POPUP_REMOVING_FROM_PLAYLIST'>Removing\n%s\nfrom Playlist…</string>
<string name='ALARM_DELETE'>Remove Alarm</string>
Expand Down

0 comments on commit b267aca

Please sign in to comment.