Skip to content

Commit

Permalink
Merge remote-tracking branch 'schup/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
kaaholst committed Jun 12, 2024
2 parents db00b11 + b65c256 commit b45e637
Show file tree
Hide file tree
Showing 14 changed files with 384 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import androidx.appcompat.app.ActionBar;
import androidx.core.view.MenuCompat;


import uk.org.ngo.squeezer.framework.BaseActivity;

Expand All @@ -31,6 +34,11 @@ public class NowPlayingActivity extends BaseActivity {
/**
* Called when the activity is first created.
*/

private MenuItem menuItemComposerLine;
private MenuItem menuItemConductorLine;
private MenuItem menuItemClassicalMusicTags;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -55,21 +63,73 @@ public static void show(Context context) {
}
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
Menu trackInfoMenu;

getMenuInflater().inflate(R.menu.nowplaying_menu, menu);
trackInfoMenu = menu.findItem(R.id.menu_nowplaying_trackinfo).getSubMenu();
MenuCompat.setGroupDividerEnabled(trackInfoMenu, true);

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);

return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
updateTrackInfoMenuItems();
return super.onPrepareOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
finish();
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);
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);
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);
return true;
}

return super.onOptionsItemSelected(item);
}

private void updateTrackInfoMenuItems() {
if (menuItemComposerLine != null) {
Preferences preferences = Squeezer.getPreferences();

menuItemComposerLine.setChecked(preferences.addComposerLine());
menuItemConductorLine.setChecked(preferences.addConductorLine());
menuItemClassicalMusicTags.setChecked(preferences.displayClassicalMusicTags());
}
}

@Override
public void onPause() {
if (isFinishing()) {
overridePendingTransition(android.R.anim.fade_in, R.anim.slide_out_down);
}
super.onPause();
}

}
111 changes: 106 additions & 5 deletions Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
Expand Down Expand Up @@ -126,10 +127,15 @@ public class NowPlayingFragment extends Fragment implements OnCrollerChangeList
private TextView artistText;

private TextView trackText;
private TextView conductorText;
private TextView composerText;

private JiveItem albumItem;
private JiveItem artistItem;

private JiveItem conductorItem;
private JiveItem composerItem;

@Nullable
private View btnContextMenu;

Expand Down Expand Up @@ -280,17 +286,20 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
mFullHeightLayout = (container.getLayoutParams().height == ViewGroup.LayoutParams.MATCH_PARENT);
Preferences preferences = Squeezer.getPreferences();
boolean largeArtwork = preferences.isLargeArtwork();

if (mFullHeightLayout) {
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);
conductorText = v.findViewById(R.id.conductorname);
albumText = v.findViewById(R.id.albumname);
shuffleButton = v.findViewById(R.id.shuffle);
repeatButton = v.findViewById(R.id.repeat);
currentTime = v.findViewById(R.id.currenttime);
totalTime = v.findViewById(R.id.totaltime);
showRemainingTime = preferences.isShowRemainingTime();
slider = v.findViewById(R.id.seekbar);

if (largeArtwork) {
albumArt = v.findViewById(R.id.album);
v.findViewById(R.id.icon).setVisibility(View.GONE);
Expand Down Expand Up @@ -320,6 +329,7 @@ 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);
Expand Down Expand Up @@ -354,6 +364,18 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
}
});

composerText.setOnClickListener(v14 -> {
if (composerItem != null) {
JiveItemListActivity.show(mActivity, composerItem, composerItem.goAction);
}
});

conductorText.setOnClickListener(v15 -> {
if (conductorItem != null) {
JiveItemListActivity.show(mActivity, conductorItem, conductorItem.goAction);
}
});

final GestureDetectorCompat detector = new GestureDetectorCompat(mActivity, new OnSwipeListener() {
@Override
public boolean onSwipeDown() {
Expand Down Expand Up @@ -712,6 +734,7 @@ private void updateUiFromPlayerState(@NonNull PlayerState playerState) {
private void updateSongInfo(@NonNull PlayerState playerState) {
updateTimeDisplayTo(playerState.getTrackElapsed(), playerState.getCurrentSongDuration());

Preferences preferences = Squeezer.getPreferences();
CurrentPlaylistItem song = playerState.getCurrentSong();
if (song == null) {
// Create empty song if this is called (via _HandshakeComplete) before status is received
Expand All @@ -720,24 +743,96 @@ private void updateSongInfo(@NonNull PlayerState playerState) {

// TODO handle button remapping (buttons in status response)
if (!song.getName().isEmpty()) {
trackText.setText(song.getName());

// don't remove rew and fwd for remote tracks, because a single track playlist
// is not an indication that fwd and rwd are invalid actions
boolean canSkip = !((playerState.getCurrentPlaylistTracksNum() == 1) && !playerState.isRemote());
nextButton.setEnabled(canSkip);
prevButton.setEnabled(canSkip);

boolean addComposerLine = preferences.addComposerLine();
boolean addConductorLine = preferences.addConductorLine();
boolean classicalMusicTags = preferences.displayClassicalMusicTags();

trackText.setText(addComposerLine && !mFullHeightLayout ? Util.joinSkipEmpty(": ", song.songInfo.getComposer(), song.getName()) : song.getName());

if (mFullHeightLayout) {
btnContextMenu.setVisibility(View.VISIBLE);
artistText.setText(song.songInfo.getArtist());
albumText.setText(song.songInfo.album);

composerText.setText(song.songInfo.getComposer());
composerText.setVisibility(addComposerLine && !TextUtils.isEmpty(song.songInfo.getComposer()) ? View.VISIBLE : View.GONE);

if (classicalMusicTags) {
if (TextUtils.isEmpty(song.songInfo.getArtist())) {
artistText.setVisibility(View.GONE);
}
// if there is no band, no need to describe that the
// artists are soloists
else if (!TextUtils.isEmpty(song.songInfo.getBand())) {
// Show description of soloists, depending on whether there is
// one or more of them
if (song.songInfo.artists.length>1) {
artistText.setText(getString(R.string.soloists, song.songInfo.getArtist()));
}
else {
artistText.setText(getString(R.string.soloist, song.songInfo.getArtist()));
}
artistText.setVisibility(View.VISIBLE);
}
else {
artistText.setText(song.songInfo.getArtist());
artistText.setVisibility(View.VISIBLE);
}
}
else {
artistText.setText(song.songInfo.getArtist());
artistText.setVisibility(View.VISIBLE);
}

if (addConductorLine) {
// show band instead of album
albumText.setText(song.songInfo.getBand());

// remove album line if there is no band
albumText.setVisibility((classicalMusicTags && TextUtils.isEmpty(song.songInfo.getBand())) ? View.GONE : View.VISIBLE);

if (!classicalMusicTags && TextUtils.isEmpty(song.songInfo.getBand())) {
// don't show "Unknown album" if line is intended
// for showing the band and there is no band
albumText.setText(" ");
}
}
else {
// standard view
albumText.setText(song.songInfo.album);
albumText.setVisibility(View.VISIBLE);
}

if (addConductorLine && !TextUtils.isEmpty(song.songInfo.getConductor())) {
if (classicalMusicTags) {
// show description of conductor
conductorText.setText(getString(R.string.conductor, song.songInfo.getConductor()));
}
else {
// just show conductor's name
conductorText.setText(song.songInfo.getConductor());
}
conductorText.setVisibility(View.VISIBLE);
}
else {
// remove line if it should not be shown
conductorText.setVisibility(View.GONE);
}
artistText.setSelected(true);
albumText.setSelected(true);

requireService().pluginItems(song.moreAction, new IServiceItemListCallback<>() {
@Override
public void onItemsReceived(int count, int start, Map<String, Object> parameters, List<JiveItem> items, Class<JiveItem> dataType) {
albumItem = findBrowseAction(items, "album_id");
artistItem = findBrowseAction(items, "artist_id");
artistItem = findBrowseAction(items, "artist_ids");
composerItem = findBrowseAction(items, "composer_ids");
conductorItem = findBrowseAction(items, "conductor_ids");
}

@Override
Expand All @@ -746,7 +841,13 @@ public Object getClient() {
}
});
} else {
artistAlbumText.setText(song.artistAlbum());
if (addConductorLine) {
artistAlbumText.setText(Util.joinSkipEmpty(" - ", song.songInfo.getArtist(), song.songInfo.getBand(),song.songInfo.getConductor()));
}
else {
artistAlbumText.setText(song.artistAlbum());
}
artistAlbumText.setSelected(true);
}
} else {
trackText.setText("");
Expand Down
33 changes: 33 additions & 0 deletions Squeezer/src/main/java/uk/org/ngo/squeezer/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ 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";

// Add line above track title for showing composer
public static final String KEY_COMPOSER_LINE = "squeezer.add_composer_line";

// Add line below artist line for showing conductor and use album line for band
public static final String KEY_CONDUCTOR_LINE = "squeezer.add_conductor_line";

// Display artists as "soloists", explicitly show "conductor", and
// collapse band, soloist and conductor lines if not used
public static final String KEY_CLASSICAL_MUSIC_TAGS = "squeezer.display_classical_music_tags";
// Use flat icons or legacy LMS icons
public static final String KEY_FLAT_ICONS = "squeezer.use_flat_icons";

Expand Down Expand Up @@ -618,6 +627,30 @@ public void setMaxLines(ArtworkListLayout listLayout, int maxLines) {
sharedPreferences.edit().putInt(String.format(KEY_MAX_LINES_FORMAT, listLayout.name()), maxLines).apply();
}

public boolean addComposerLine() {
return sharedPreferences.getBoolean(KEY_COMPOSER_LINE, false);
}

public void addComposerLine(boolean b) {
sharedPreferences.edit().putBoolean(Preferences.KEY_COMPOSER_LINE, b).apply();
}

public boolean addConductorLine() {
return sharedPreferences.getBoolean(KEY_CONDUCTOR_LINE, false);
}

public void addConductorLine(boolean b) {
sharedPreferences.edit().putBoolean(Preferences.KEY_CONDUCTOR_LINE, b).apply();
}

public boolean displayClassicalMusicTags() {
return sharedPreferences.getBoolean(KEY_CLASSICAL_MUSIC_TAGS, false);
}

public void displayClassicalMusicTags(boolean b) {
sharedPreferences.edit().putBoolean(Preferences.KEY_CLASSICAL_MUSIC_TAGS, b).apply();
}

public boolean useFlatIcons() {
return sharedPreferences.getBoolean(KEY_FLAT_ICONS, true);
}
Expand Down
13 changes: 13 additions & 0 deletions Squeezer/src/main/java/uk/org/ngo/squeezer/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

fillDisplayPreferences(preferences);

fillNowPlayingPreferences(preferences);

fillUserInterfacePreferences(preferences);

fillScrobblePreferences(sharedPreferences);
Expand Down Expand Up @@ -187,6 +189,17 @@ private void fillDisplayPreferences(Preferences preferences) {
fillEnumPreference(screensaverPref, Preferences.ScreensaverMode.class, preferences.getScreensaverMode());
}

private void fillNowPlayingPreferences(Preferences preferences) {
final SwitchPreferenceCompat addComposerLine = findPreference(Preferences.KEY_COMPOSER_LINE);
addComposerLine.setChecked(preferences.addComposerLine());

final SwitchPreferenceCompat addConductorLine = findPreference(Preferences.KEY_CONDUCTOR_LINE);
addConductorLine.setChecked(preferences.addConductorLine());

final SwitchPreferenceCompat displayClassicalMusicAppearance = findPreference(Preferences.KEY_CLASSICAL_MUSIC_TAGS);
displayClassicalMusicAppearance.setChecked(preferences.displayClassicalMusicTags());
}

private void fillUserInterfacePreferences(Preferences preferences) {
final SwitchPreferenceCompat clearPlaylistConfirmation = findPreference(Preferences.KEY_CLEAR_PLAYLIST_CONFIRMATION);
clearPlaylistConfirmation.setChecked(preferences.isClearPlaylistConfirmation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public void onDialogDismissed(DialogInterface dialog) {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.plugin_list_menu, menu);
getMenuInflater().inflate(R.menu.jiveitemlist_menu, menu);
viewMenu = menu.findItem(R.id.menu_item_view).getSubMenu();
MenuCompat.setGroupDividerEnabled(viewMenu, true);
menuItemLight = viewMenu.findItem(R.id.menu_item_light);
Expand Down
11 changes: 11 additions & 0 deletions Squeezer/src/main/java/uk/org/ngo/squeezer/model/Song.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ public String getArtist() {
return TextUtils.join(", ", artists);
}

public String getBand() {
return TextUtils.join(", ", bands);
}

public String getConductor() {
return TextUtils.join(", ", conductors);
}

public String getComposer() {
return TextUtils.join(", ", composers);
}
public String getAlbumArtists() {
return TextUtils.join(", ", albumArtists);
}
Expand Down
Loading

0 comments on commit b45e637

Please sign in to comment.