Skip to content

Commit

Permalink
Move current playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
kaaholst committed Aug 26, 2024
1 parent de22d55 commit 33bc9cf
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 29 deletions.
13 changes: 3 additions & 10 deletions Squeezer/src/main/java/uk/org/ngo/squeezer/NowPlayingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
Expand Down Expand Up @@ -606,22 +605,15 @@ private void updatePlayerDropDown(@NonNull List<Player> connectedPlayers, @Nulla
actionBar.setCustomView(R.layout.action_bar_custom_view);
AutoCompleteTextView spinner = actionBar.getCustomView().findViewById(R.id.player);
final Context actionBarContext = actionBar.getThemedContext();
final ArrayAdapter<Player> playerAdapter = new ArrayAdapter<>(actionBarContext, R.layout.dropdown_item, connectedPlayers) {
@Override
public @NonNull View getView(int position, View convertView, @NonNull ViewGroup parent) {
TextView view = (TextView) requireActivity().getLayoutInflater().inflate(R.layout.dropdown_item, parent, false);
view.setText(getItem(position).getName());
return view;
}
};
final PlayerDropdownAdapter playerAdapter = new PlayerDropdownAdapter(actionBarContext, connectedPlayers, activePlayer);
spinner.setAdapter(playerAdapter);
playerAdapter.notifyDataSetChanged();
spinner.setText((activePlayer != null) ? activePlayer.getName() : "", false);
spinner.setOnItemClickListener((adapterView, parent, position, id) -> {
Player selectedItem = playerAdapter.getItem(position);
spinner.setText(selectedItem.getName(), false);
if (getActivePlayer() != selectedItem) {
requireService().setActivePlayer(selectedItem);
requireService().setActivePlayer(selectedItem, playerAdapter.continuePlayback());
}
});
} else {
Expand Down Expand Up @@ -1200,6 +1192,7 @@ public void onEventMainThread(@SuppressWarnings("unused") RegisterSqueezeNetwork
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventMainThread(ActivePlayerChanged event) {
updateUiFromPlayerState(event.player != null ? event.player.getPlayerState() : new PlayerState());
updatePlayerDropDown(requireService().getPlayers(), requireService().getActivePlayer());
}

@MainThread
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package uk.org.ngo.squeezer;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.annotation.NonNull;

import java.util.List;

import uk.org.ngo.squeezer.model.Player;

class PlayerDropdownAdapter extends ArrayAdapter<Player> {
private final Player activePlayer;
private boolean continuePlayback;

public PlayerDropdownAdapter(Context actionBarContext, List<Player> connectedPlayers, Player activePlayer) {
super(actionBarContext, 0);
add(null);
addAll(connectedPlayers);
this.activePlayer = activePlayer;
}

@Override
public @NonNull View getView(int position, View convertView, @NonNull ViewGroup parent) {
Player item = getItem(position);
if (item == null) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.continue_playback, parent, false);
view.setOnClickListener(v -> {
continuePlayback = !continuePlayback;
view.<CheckBox>findViewById(R.id.checkbox).setChecked(continuePlayback);
});
return view;
} else {
TextView view = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.dropdown_item, parent, false);
view.setText(item.getName());
return view;
}
}

@Override
public boolean isEnabled(int position) {
Player item = getItem(position);
return !(item == null || item.equals(activePlayer));
}

public boolean continuePlayback() {
return continuePlayback;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@

public enum RemoteButton {
OPEN((context, service, player) -> {
service.setActivePlayer(service.getPlayer(player.getId()));
service.setActivePlayer(service.getPlayer(player.getId()), false);
Handler handler = new Handler();
float animationDelay = Settings.Global.getFloat(context.getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f);
handler.postDelayed(() -> HomeActivity.show(context), (long) (300 * animationDelay));
}, R.string.remote_openPlayer, R.drawable.ic_home),
OPEN_NOW_PLAYING((context, service, player) -> {
service.setActivePlayer(service.getPlayer(player.getId()));
service.setActivePlayer(service.getPlayer(player.getId()), false);
Handler handler = new Handler();
float animationDelay = Settings.Global.getFloat(context.getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f);
handler.postDelayed(() -> NowPlayingActivity.show(context), (long) (300 * animationDelay));
}, R.string.remote_openNowPlaying, R.drawable.ic_action_nowplaying),
OPEN_CURRENT_PLAYLIST((context, service, player) -> {
service.setActivePlayer(service.getPlayer(player.getId()));
service.setActivePlayer(service.getPlayer(player.getId()), false);
Handler handler = new Handler();
float animationDelay = Settings.Global.getFloat(context.getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void onReceive(final Context context, Intent intent) {
if (SQUEEZER_REMOTE_OPEN.equals(action)) {
runOnService(context, service -> {
Log.d(TAG, "setting active player: " + playerId);
service.setActivePlayer(service.getPlayer(playerId));
service.setActivePlayer(service.getPlayer(playerId), false);
Handler handler = new Handler();
float animationDelay = Settings.Global.getFloat(context.getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public interface ISqueezeService {
* Change the player that is controlled by Squeezer (the "active" player).
*
* @param player May be null, in which case no players are controlled.
* @param continuePlaying Continue playback on the supplied player
*/
void setActivePlayer(@NonNull Player player);
void setActivePlayer(@NonNull Player player, boolean continuePlaying);

// Returns the player we are currently controlling
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ private boolean isPlaying() {
/**
* Change the player that is controlled by Squeezer (the "active" player).
*
* @param newActivePlayer The new active player. May be null, in which case no players
* are controlled.
* @param newActivePlayer The new active player. May be null, in which case no players are controlled.
* @param continuePlaying Continue playback on the supplied player
*/
private void changeActivePlayer(@Nullable final Player newActivePlayer) {
private void changeActivePlayer(@Nullable final Player newActivePlayer, boolean continuePlaying) {
Player prevActivePlayer = mDelegate.getActivePlayer();

// Do nothing if the player hasn't actually changed.
Expand All @@ -338,9 +338,15 @@ private void changeActivePlayer(@Nullable final Player newActivePlayer) {

updateAllPlayerSubscriptionStates();
requestPlayerData();
if (continuePlaying && prevActivePlayer != null) moveCurrentPlaylist(prevActivePlayer, newActivePlayer);
Squeezer.getPreferences().setLastPlayer(newActivePlayer);
}

private void moveCurrentPlaylist(Player from, Player to) {
squeezeService.syncPlayerToPlayer(to, from.getId());
squeezeService.unsyncPlayer(from);
}

class HomeMenuReceiver implements IServiceItemListCallback<JiveItem> {

private final List<JiveItem> homeMenu = new ArrayList<>();
Expand Down Expand Up @@ -805,7 +811,7 @@ public void onEvent(PlayersChanged event) {
Player activePlayer = mDelegate.getActivePlayer();
if (activePlayer == null) {
// Figure out the new active player, let everyone know.
changeActivePlayer(getPreferredPlayer(mDelegate.getPlayers().values()));
changeActivePlayer(getPreferredPlayer(mDelegate.getPlayers().values()), false);
} else {
activePlayer = mDelegate.getPlayer(activePlayer.getId());
mDelegate.setActivePlayer(activePlayer);
Expand Down Expand Up @@ -1323,8 +1329,8 @@ public boolean button(Player player, IRButton button) {
}

@Override
public void setActivePlayer(@Nullable final Player newActivePlayer) {
changeActivePlayer(newActivePlayer);
public void setActivePlayer(@Nullable final Player newActivePlayer, boolean continuePlaying) {
changeActivePlayer(newActivePlayer, continuePlaying);
}

@Override
Expand Down
20 changes: 20 additions & 0 deletions Squeezer/src/main/res/layout/continue_playback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:clickable="false" />

<TextView
style="@style/SqueezerWidget.DropdownText"
android:layout_weight="1"
android:layout_width="0dp"
android:text="@string/continue_playback"/>

</LinearLayout>
13 changes: 5 additions & 8 deletions Squeezer/src/main/res/layout/dropdown_item.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:padding="16dp"
android:textAppearance="?attr/textAppearanceSubtitle1"
tools:text= "text"/>
xmlns:tools="http://schemas.android.com/tools"
style="@style/SqueezerWidget.DropdownText"
android:layout_width="match_parent"
android:padding="12dp"
tools:text="text" />
1 change: 1 addition & 0 deletions Squeezer/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,6 @@
<string name="forward_seconds">Sekunder frem</string>
<string name="RANDOM_PLAY_UNABLE">Fejl ved start af tilfældig afspilning</string>
<string name="RANDOM_PLAY_STARTED">Tilfældig afspilning er start</string>
<string name="continue_playback">Fortsæt afspilning</string>

</resources>
1 change: 1 addition & 0 deletions Squeezer/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,6 @@
<string name="player_group_volume_on">Lautstärke für synchronisierte Player anpassen</string>
<string name="player_group_volume_off">Lautstärke für ausgewählte Player anpassen</string>
<string name="set_sleep_timer">Einschlaftimer setzen</string>
<string name="continue_playback">Wiedergabe fortsetzen</string>

</resources>
1 change: 1 addition & 0 deletions Squeezer/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@
<string name="download_filename_structure_number_dot_artist_title">Nombre. Artiste - Titre</string>
<string name="NOTIFICATION_DOWNLOAD_MEDIA_SCANNER_ERROR">n\'a pas pu être ajouté à la base de données multimédia de l\'appareil</string>
<string name="pref_cat_third_party">Intégration tierce</string>
<string name="continue_playback">Continue playback</string>
</resources>
1 change: 1 addition & 0 deletions Squeezer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,5 @@ of your accepting any such warranty or additional liability.&lt;/p&gt;</string>
<string name="forward_seconds">Forward seconds</string>
<string name="RANDOM_PLAY_UNABLE">Unable to start Random Play</string>
<string name="RANDOM_PLAY_STARTED">Random Play started</string>
<string name="continue_playback">Continue playback</string>
</resources>
8 changes: 8 additions & 0 deletions Squeezer/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@
<item name="android:focusableInTouchMode">true</item>
</style>

<!-- Texts in dropdowns -->
<style name="SqueezerWidget.DropdownText">
<item name="android:layout_height">48dp</item>
<item name="android:ellipsize">end</item>
<item name="android:maxLines">1</item>
<item name="android:textAppearance">?attr/textAppearanceSubtitle1</item>
</style>

<style name="SqueezerWidget.NowPlaying.ComposerName" parent="SqueezerWidget.SingleLine">
<item name="android:textAppearance">@style/SqueezerTextAppearance.NowPlaying.ComposerName</item>
</style>
Expand Down

0 comments on commit 33bc9cf

Please sign in to comment.