From de22d55e44358b50f1376c49ee3698db08092951 Mon Sep 17 00:00:00 2001 From: Kurt Aaholst Date: Wed, 10 Jul 2024 23:17:38 +0200 Subject: [PATCH] Show technical info and track number Optionally show information about current track above slider. - Technical info, currently bitrate and samplerate - Current track number and queue length Add a scroll view around song information lines, which kicks in if it doesn't fit on screen. E.g. if all options are on, and using a device with a short screen. --- .../org/ngo/squeezer/NowPlayingActivity.java | 36 +++- .../org/ngo/squeezer/NowPlayingFragment.java | 22 ++- .../java/uk/org/ngo/squeezer/Preferences.java | 22 +++ .../uk/org/ngo/squeezer/SettingsFragment.java | 6 + .../main/java/uk/org/ngo/squeezer/Util.java | 2 +- .../ngo/squeezer/framework/BaseActivity.java | 8 + .../java/uk/org/ngo/squeezer/model/Song.java | 13 ++ .../main/res/layout/now_playing_include.xml | 155 ++++++++++-------- .../src/main/res/menu/nowplaying_menu.xml | 10 ++ Squeezer/src/main/res/values-da/strings.xml | 8 + Squeezer/src/main/res/values/strings.xml | 8 + Squeezer/src/main/res/xml/preferences.xml | 12 ++ 12 files changed, 222 insertions(+), 80 deletions(-) diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingActivity.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingActivity.java index cc9fd74e8..1d12d219d 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingActivity.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingActivity.java @@ -28,6 +28,8 @@ import uk.org.ngo.squeezer.framework.BaseActivity; +import uk.org.ngo.squeezer.model.Player; +import uk.org.ngo.squeezer.service.event.MusicChanged; public class NowPlayingActivity extends BaseActivity { @@ -35,6 +37,8 @@ public class NowPlayingActivity extends BaseActivity { * Called when the activity is first created. */ + private MenuItem menuItemTrackCount; + private MenuItem menuItemTechnicalInfo; private MenuItem menuItemComposerLine; private MenuItem menuItemConductorLine; private MenuItem menuItemClassicalMusicTags; @@ -72,6 +76,8 @@ public boolean onCreateOptionsMenu(Menu menu) { trackInfoMenu = menu.findItem(R.id.menu_nowplaying_trackinfo).getSubMenu(); MenuCompat.setGroupDividerEnabled(trackInfoMenu, true); + menuItemTrackCount = trackInfoMenu.findItem(R.id.menu_item_track_info); + menuItemTechnicalInfo = trackInfoMenu.findItem(R.id.menu_item_technical_info); menuItemComposerLine = trackInfoMenu.findItem(R.id.menu_item_composer_line); menuItemConductorLine = trackInfoMenu.findItem(R.id.menu_item_conductor_line); menuItemClassicalMusicTags = trackInfoMenu.findItem(R.id.menu_item_classical_music_tags); @@ -91,33 +97,45 @@ public boolean onOptionsItemSelected(MenuItem item) { if (itemId == android.R.id.home) { finish(); return true; + } else if (itemId == R.id.menu_item_track_info) { + Squeezer.getPreferences().showTrackCount(!menuItemTrackCount.isChecked()); + refreshTrackInfo(); + return true; + } else if (itemId == R.id.menu_item_technical_info) { + Squeezer.getPreferences().showTechnicalInfo(!menuItemTechnicalInfo.isChecked()); + refreshTrackInfo(); + return true; } else if (itemId == R.id.menu_item_composer_line) { Squeezer.getPreferences().addComposerLine(!menuItemComposerLine.isChecked()); - updateTrackInfoMenuItems(); - // Make sure view is updated to reflect changes - NowPlayingActivity.show(this); + refreshTrackInfo(); return true; } else if (itemId == R.id.menu_item_conductor_line) { Squeezer.getPreferences().addConductorLine(!menuItemConductorLine.isChecked()); - updateTrackInfoMenuItems(); - // Make sure view is updated to reflect changes - NowPlayingActivity.show(this); + refreshTrackInfo(); return true; } else if (itemId == R.id.menu_item_classical_music_tags) { Squeezer.getPreferences().displayClassicalMusicTags(!menuItemClassicalMusicTags.isChecked()); - updateTrackInfoMenuItems(); - // Make sure view is updated to reflect changes - NowPlayingActivity.show(this); + refreshTrackInfo(); return true; } return super.onOptionsItemSelected(item); } + private void refreshTrackInfo() { + updateTrackInfoMenuItems(); + Player activePlayer = getActivePlayer(); + if (activePlayer != null) { + requireService().getEventBus().post(new MusicChanged(activePlayer, activePlayer.getPlayerState())); + } + } + private void updateTrackInfoMenuItems() { if (menuItemComposerLine != null) { Preferences preferences = Squeezer.getPreferences(); + menuItemTrackCount.setChecked(preferences.showTrackCount()); + menuItemTechnicalInfo.setChecked(preferences.showTechnicalInfo()); menuItemComposerLine.setChecked(preferences.addComposerLine()); menuItemConductorLine.setChecked(preferences.addConductorLine()); menuItemClassicalMusicTags.setChecked(preferences.displayClassicalMusicTags()); diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingFragment.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingFragment.java index f892aa7f0..9935b93a9 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingFragment.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingFragment.java @@ -128,6 +128,7 @@ public class NowPlayingFragment extends Fragment implements OnCrollerChangeList private TextView trackText; private TextView conductorText; private TextView composerText; + private TextView trackInfo; private JiveItem albumItem; private JiveItem artistItem; @@ -295,8 +296,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, v = inflater.inflate(largeArtwork ? R.layout.now_playing_fragment_full_large_artwork : R.layout.now_playing_fragment_full, container, false); artistText = v.findViewById(R.id.artistname); + composerText = v.findViewById(R.id.composer); conductorText = v.findViewById(R.id.conductorname); albumText = v.findViewById(R.id.albumname); + trackInfo = v.findViewById(R.id.track_info); shuffleButton = v.findViewById(R.id.shuffle); repeatButton = v.findViewById(R.id.repeat); currentTime = v.findViewById(R.id.currenttime); @@ -333,7 +336,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, } trackText = v.findViewById(R.id.trackname); - composerText = v.findViewById(R.id.composer); playPauseButton = v.findViewById(R.id.pause); nextButton = v.findViewById(R.id.next); @@ -830,6 +832,10 @@ else if (!TextUtils.isEmpty(song.songInfo.getBand())) { artistText.setSelected(true); albumText.setSelected(true); + String trackInfoText = formatTrackInfo(preferences, playerState, song); + trackInfo.setText(trackInfoText); + trackInfo.setVisibility(!TextUtils.isEmpty(trackInfoText) ? View.VISIBLE : View.GONE); + requireService().pluginItems(song.moreAction, new IServiceItemListCallback<>() { @Override public void onItemsReceived(int count, int start, Map parameters, List items, Class dataType) { @@ -871,6 +877,20 @@ public Object getClient() { } } + private static String formatTrackInfo(Preferences preferences, PlayerState playerState, CurrentPlaylistItem song) { + return Util.joinSkipEmpty(" - ", formatTechnicalInfo(preferences, song), formatTrackCount(preferences, playerState)); + } + + private static String formatTechnicalInfo(Preferences preferences, CurrentPlaylistItem song) { + return preferences.showTechnicalInfo() ? Util.joinSkipEmpty(" ", song.songInfo.getBitRate(), song.songInfo.getSampleRate()) : ""; + } + + private static String formatTrackCount(Preferences preferences, PlayerState playerState) { + return (preferences.showTrackCount() && playerState.getCurrentPlaylistTracksNum() > 1) + ? String.format("%s/%s", playerState.getCurrentPlaylistIndex() + 1, playerState.getCurrentPlaylistTracksNum()) + : ""; + } + private void updateVolumeInfo() { if (mFullHeightLayout) { ISqueezeService.VolumeInfo volumeInfo = requireService().getVolume(); 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 5a633b66c..8eef38616 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/Preferences.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/Preferences.java @@ -151,6 +151,12 @@ public final class Preferences { // Preferred maximum info per item for a given list layout public static final String KEY_MAX_LINES_FORMAT = "squeezer.%s.maxLines"; + // Show current track and queue length on now playing screen + public static final String KEY_TRACK_COUNT = "squeezer.show_track_count"; + + // Show technical info (bitrate, samplerate etc) on now playing screen + public static final String KEY_TECHNICAL_INFO = "squeezer.show_technical_info"; + // Add line above track title for showing composer public static final String KEY_COMPOSER_LINE = "squeezer.add_composer_line"; @@ -627,6 +633,22 @@ public void setMaxLines(ArtworkListLayout listLayout, int maxLines) { sharedPreferences.edit().putInt(String.format(KEY_MAX_LINES_FORMAT, listLayout.name()), maxLines).apply(); } + public boolean showTrackCount() { + return sharedPreferences.getBoolean(KEY_TRACK_COUNT, true); + } + + public void showTrackCount(boolean b) { + sharedPreferences.edit().putBoolean(Preferences.KEY_TRACK_COUNT, b).apply(); + } + + public boolean showTechnicalInfo() { + return sharedPreferences.getBoolean(KEY_TECHNICAL_INFO, false); + } + + public void showTechnicalInfo(boolean b) { + sharedPreferences.edit().putBoolean(Preferences.KEY_TECHNICAL_INFO, b).apply(); + } + public boolean addComposerLine() { return sharedPreferences.getBoolean(KEY_COMPOSER_LINE, false); } diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/SettingsFragment.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/SettingsFragment.java index 7bd403b8f..3e08d0286 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/SettingsFragment.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/SettingsFragment.java @@ -190,6 +190,12 @@ private void fillDisplayPreferences(Preferences preferences) { } private void fillNowPlayingPreferences(Preferences preferences) { + final SwitchPreferenceCompat trackCount = findPreference(Preferences.KEY_TRACK_COUNT); + trackCount.setChecked(preferences.showTrackCount()); + + final SwitchPreferenceCompat teachnicalInfo = findPreference(Preferences.KEY_TECHNICAL_INFO); + teachnicalInfo.setChecked(preferences.showTechnicalInfo()); + final SwitchPreferenceCompat addComposerLine = findPreference(Preferences.KEY_COMPOSER_LINE); addComposerLine.setChecked(preferences.addComposerLine()); diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/Util.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/Util.java index e67dc840e..139f33f95 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/Util.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/Util.java @@ -87,7 +87,7 @@ public static String joinSkipEmpty(String separator, Iterable parts) { StringBuilder sb = new StringBuilder(); for (String part : parts) { - if (part == null) continue; + if (part == null || part.isEmpty()) continue; if (sb.length() > 0) sb.append(separator); sb.append(part); 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 28afe9e87..2017025fe 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 @@ -62,6 +62,7 @@ import uk.org.ngo.squeezer.model.Action; import uk.org.ngo.squeezer.model.DisplayMessage; import uk.org.ngo.squeezer.model.JiveItem; +import uk.org.ngo.squeezer.model.Player; import uk.org.ngo.squeezer.screensaver.Screensaver; import uk.org.ngo.squeezer.service.ISqueezeService; import uk.org.ngo.squeezer.service.SqueezeService; @@ -450,6 +451,13 @@ public void onEventMainThread(AlertEvent alert) { // Safe accessors + public Player getActivePlayer() { + if (mService == null) { + return null; + } + return mService.getActivePlayer(); + } + /** * Perform the supplied action using parameters in item via * {@link ISqueezeService#action(JiveItem, Action)} diff --git a/Squeezer/src/main/java/uk/org/ngo/squeezer/model/Song.java b/Squeezer/src/main/java/uk/org/ngo/squeezer/model/Song.java index 572389341..a14a9b780 100644 --- a/Squeezer/src/main/java/uk/org/ngo/squeezer/model/Song.java +++ b/Squeezer/src/main/java/uk/org/ngo/squeezer/model/Song.java @@ -8,6 +8,7 @@ import androidx.annotation.NonNull; import java.io.File; +import java.text.DecimalFormat; import java.util.Arrays; import java.util.Map; import java.util.Objects; @@ -145,6 +146,18 @@ public String getLocalPath(DownloadPathStructure downloadPathStructure, Download return new File(downloadPathStructure.get(this), downloadFilenameStructure.get(this)).getPath(); } + public String getSampleRate() { + try { + int sampleRateInteger = Integer.parseInt(sampleRate); + return (sampleRateInteger > 0) ? new DecimalFormat("#.#").format(sampleRateInteger / 1000.0) + " kHz" : ""; + } catch (NumberFormatException ignored) {} + return sampleRate; + } + + public String getBitRate() { + return "0".equals(bitRate) ? "" : bitRate; + } + @Override public String toString() { return "Song{" + diff --git a/Squeezer/src/main/res/layout/now_playing_include.xml b/Squeezer/src/main/res/layout/now_playing_include.xml index c6869a868..5435a223c 100644 --- a/Squeezer/src/main/res/layout/now_playing_include.xml +++ b/Squeezer/src/main/res/layout/now_playing_include.xml @@ -30,86 +30,103 @@ android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_vertical" + android:paddingTop="4dp" + android:paddingBottom="4dp" android:orientation="vertical"> - - - - - - - - - - - + android:orientation="vertical"> - - - - + style="@style/SqueezerWidget.NowPlaying.ComposerName" + tools:text="Composer" /> + + + + + + + + + + + + + + + + + + + + - - - - + + + + + Nej Ja Vis ur ved inaktivitet + Spornummer + Teknisk information (bithastighed, m.v) Vis komponist Oplysninger til klassisk musik Vis orkester og dirigent @@ -143,6 +145,12 @@ Oplysninger under afspilning + Spornummer + Vis ikke spornummer + Vis spornummer over tid i spor + Teknisk information (bithastighed, m.v) + Vis ikke teknisk information + Vis teknisk information over tid i spor Vis ikke komponist Vis komponist foran the nummerets titel Oplysninger om komponist diff --git a/Squeezer/src/main/res/values/strings.xml b/Squeezer/src/main/res/values/strings.xml index 624908050..acacbbbfe 100644 --- a/Squeezer/src/main/res/values/strings.xml +++ b/Squeezer/src/main/res/values/strings.xml @@ -42,6 +42,8 @@ No Yes Show clock when idle + Track number + Technical info (bitrate, etc) Show composer Classical music information Show band and conductor @@ -140,6 +142,12 @@ NowPlaying track information + Track number + Don\'t show track number + Show track number above time in track + Technical info (bitrate, etc) + Don\'t show Technical info + Show technical info above time in track Don\'t show composer Show composer in front of the track title Composer information diff --git a/Squeezer/src/main/res/xml/preferences.xml b/Squeezer/src/main/res/xml/preferences.xml index 1b00bf2eb..5b87b9208 100644 --- a/Squeezer/src/main/res/xml/preferences.xml +++ b/Squeezer/src/main/res/xml/preferences.xml @@ -49,6 +49,18 @@ + + + +