Add LoopStatus and Shuffle control to mpris plugin

This commit is contained in:
Łukasz Patron
2021-06-11 01:44:42 +02:00
committed by Nicolas Fella
parent 48abfa0c05
commit d87a65d8b7
9 changed files with 172 additions and 10 deletions

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M7,7h10v3l4,-4 -4,-4v3L5,5v6h2L7,7zM17,17L7,17v-3l-4,4 4,4v-3h12v-6h-2v4z" />
</vector>

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillType="evenOdd"
android:pathData="M21,1L3,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,3c0,-1.1 -0.9,-2 -2,-2zM7,7h10v3l4,-4 -4,-4v3L5,5v6h2L7,7zM17,17L7,17v-3l-4,4 4,4v-3h12v-6h-2v4z" />
</vector>

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillType="evenOdd"
android:pathData="M21,1L3,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,3c0,-1.1 -0.9,-2 -2,-2zM7,7h10v3l4,-4 -4,-4v3L5,5v6h2L7,7zM17,17L7,17v-3l-4,4 4,4v-3h12v-6h-2v4zM13,15L13,9h-1l-2,1v1h1.5v4L13,15z" />
</vector>

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M10.59,9.17L5.41,4 4,5.41l5.17,5.17 1.42,-1.41zM14.5,4l2.04,2.04L4,18.59 5.41,20 17.96,7.46 20,9.5L20,4h-5.5zM14.83,13.41l-1.41,1.41 3.13,3.13L14.5,20L20,20v-5.5l-2.04,2.04 -3.13,-3.13z" />
</vector>

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillType="evenOdd"
android:pathData="M21,1L3,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,3c0,-1.1 -0.9,-2 -2,-2zM10.59,9.17L5.41,4 4,5.41l5.17,5.17 1.42,-1.41zM14.5,4l2.04,2.04L4,18.59 5.41,20 17.96,7.46 20,9.5L20,4h-5.5zM14.83,13.41l-1.41,1.41 3.13,3.13L14.5,20L20,20v-5.5l-2.04,2.04 -3.13,-3.13z" />
</vector>

View File

@@ -36,18 +36,56 @@
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageButton
android:id="@+id/play_button"
android:layout_width="fill_parent"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_gravity="center"
android:layout_weight="0"
android:orientation="horizontal">
<ImageButton
android:id="@+id/loop_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="false"
android:baselineAlignBottom="true"
android:clickable="false"
android:contentDescription="@string/mpris_loop"
android:src="@drawable/ic_loop_none_black"
android:theme="@style/DisableableButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.20" />
<ImageButton
android:id="@+id/play_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="false"
android:baselineAlignBottom="true"
android:clickable="false"
android:contentDescription="@string/mpris_play"
android:src="@drawable/ic_play_black"
android:theme="@style/DisableableButton" />
android:theme="@style/DisableableButton"
app:layout_constraintEnd_toStartOf="@id/shuffle_button"
app:layout_constraintStart_toEndOf="@id/loop_button"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/shuffle_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="false"
android:baselineAlignBottom="true"
android:clickable="false"
android:contentDescription="@string/mpris_shuffle"
android:src="@drawable/ic_shuffle_off_black"
android:theme="@style/DisableableButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintWidth_percent="0.20" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"

View File

@@ -205,6 +205,8 @@
<string name="mpris_rew">Rewind</string>
<string name="mpris_ff">Fast-forward</string>
<string name="mpris_next">Next</string>
<string name="mpris_loop">Loop</string>
<string name="mpris_shuffle">Shuffle</string>
<string name="mpris_volume">Volume</string>
<string name="mpris_time_settings_title">Forward/rewind buttons</string>
<string name="mpris_time_settings_summary">Adjust the time to fast forward/rewind when pressed</string>

View File

@@ -121,8 +121,24 @@ public class MprisNowPlayingFragment extends Fragment implements VolumeKeyListen
BackgroundService.RunCommand(requireContext(), service -> service.addConnectionListener(connectionReceiver));
connectToPlugin(targetPlayerName);
performActionOnClick(mprisControlBinding.loopButton, p -> {
switch (p.getLoopStatus()) {
case "None":
p.setLoopStatus("Track");
break;
case "Track":
p.setLoopStatus("Playlist");
break;
case "Playlist":
p.setLoopStatus("None");
break;
}
});
performActionOnClick(mprisControlBinding.playButton, MprisPlugin.MprisPlayer::playPause);
performActionOnClick(mprisControlBinding.shuffleButton, p -> p.setShuffle(!p.getShuffle()));
performActionOnClick(mprisControlBinding.prevButton, MprisPlugin.MprisPlayer::previous);
performActionOnClick(mprisControlBinding.rewButton, p -> targetPlayer.seek(interval_time * -1));
@@ -332,6 +348,28 @@ public class MprisNowPlayingFragment extends Fragment implements VolumeKeyListen
mprisControlBinding.playButton.setEnabled(playerStatus.isPlayAllowed());
}
String loopStatus = playerStatus.getLoopStatus();
switch (loopStatus) {
case "None":
mprisControlBinding.loopButton.setImageResource(R.drawable.ic_loop_none_black);
break;
case "Track":
mprisControlBinding.loopButton.setImageResource(R.drawable.ic_loop_track_black);
break;
case "Playlist":
mprisControlBinding.loopButton.setImageResource(R.drawable.ic_loop_playlist_black);
break;
}
boolean shuffle = playerStatus.getShuffle();
if (shuffle) {
mprisControlBinding.shuffleButton.setImageResource(R.drawable.ic_shuffle_on_black);
} else {
mprisControlBinding.shuffleButton.setImageResource(R.drawable.ic_shuffle_off_black);
}
mprisControlBinding.loopButton.setVisibility(playerStatus.isLoopStatusAllowed() ? View.VISIBLE : View.GONE);
mprisControlBinding.shuffleButton.setVisibility(playerStatus.isShuffleAllowed() ? View.VISIBLE : View.GONE);
mprisControlBinding.volumeLayout.setVisibility(playerStatus.isSetVolumeAllowed() ? View.VISIBLE : View.GONE);
mprisControlBinding.rewButton.setVisibility(playerStatus.isSeekAllowed() ? View.VISIBLE : View.GONE);
mprisControlBinding.ffButton.setVisibility(playerStatus.isSeekAllowed() ? View.VISIBLE : View.GONE);

View File

@@ -41,6 +41,10 @@ public class MprisPlugin extends Plugin {
private String album = "";
private String albumArtUrl = "";
private String url = "";
private String loopStatus = "";
private boolean loopStatusAllowed = false;
private boolean shuffle = false;
private boolean shuffleAllowed = false;
private int volume = 50;
private long length = -1;
private long lastPosition = 0;
@@ -79,6 +83,14 @@ public class MprisPlugin extends Plugin {
return getPlayer().toLowerCase().equals("spotify");
}
public String getLoopStatus() {
return loopStatus;
}
public boolean getShuffle() {
return shuffle;
}
public int getVolume() {
return volume;
}
@@ -129,6 +141,14 @@ public class MprisPlugin extends Plugin {
return url;
}
public boolean isLoopStatusAllowed() {
return loopStatusAllowed && !isSpotify();
}
public boolean isShuffleAllowed() {
return shuffleAllowed && !isSpotify();
}
public boolean isSetVolumeAllowed() {
return !isSpotify();
}
@@ -175,6 +195,14 @@ public class MprisPlugin extends Plugin {
}
}
public void setLoopStatus(String loopStatus) {
MprisPlugin.this.sendCommand(getPlayer(), "setLoopStatus", loopStatus);
}
public void setShuffle(boolean shuffle) {
MprisPlugin.this.sendCommand(getPlayer(), "setShuffle", String.valueOf(shuffle));
}
public void setVolume(int volume) {
if (isSetVolumeAllowed()) {
MprisPlugin.this.sendCommand(getPlayer(), "setVolume", volume);
@@ -276,6 +304,14 @@ public class MprisPlugin extends Plugin {
playerStatus.artist = np.getString("artist", playerStatus.artist);
playerStatus.album = np.getString("album", playerStatus.album);
playerStatus.url = np.getString("url", playerStatus.url);
if (np.has("loopStatus")) {
playerStatus.loopStatus = np.getString("loopStatus", playerStatus.loopStatus);
playerStatus.loopStatusAllowed = true;
}
if (np.has("shuffle")) {
playerStatus.shuffle = np.getBoolean("shuffle", playerStatus.shuffle);
playerStatus.shuffleAllowed = true;
}
playerStatus.volume = np.getInt("volume", playerStatus.volume);
playerStatus.length = np.getLong("length", playerStatus.length);
if (np.has("pos")) {