Commit 2ab76c6e authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Deduplicate code for listeners in MprisActivity

parent 3f2b8495
...@@ -350,6 +350,17 @@ public class MprisActivity extends AppCompatActivity { ...@@ -350,6 +350,17 @@ public class MprisActivity extends AppCompatActivity {
} }
} }
private interface ClickListener {
void onClick(MprisPlugin.MprisPlayer player);
}
private void onClick(View v, ClickListener l) {
v.setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> {
if (targetPlayer == null) return;
l.onClick(targetPlayer);
}));
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -369,35 +380,17 @@ public class MprisActivity extends AppCompatActivity { ...@@ -369,35 +380,17 @@ public class MprisActivity extends AppCompatActivity {
BackgroundService.RunCommand(MprisActivity.this, service -> service.addConnectionListener(connectionReceiver)); BackgroundService.RunCommand(MprisActivity.this, service -> service.addConnectionListener(connectionReceiver));
connectToPlugin(targetPlayerName); connectToPlugin(targetPlayerName);
playButton.setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> { onClick(playButton, MprisPlugin.MprisPlayer::playPause);
if (targetPlayer == null) return;
targetPlayer.playPause();
}));
prevButton.setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> { onClick(prevButton, MprisPlugin.MprisPlayer::previous);
if (targetPlayer == null) return;
targetPlayer.previous();
}));
rewButton.setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> { onClick(rewButton, p -> targetPlayer.seek(interval_time * -1));
if (targetPlayer == null) return;
targetPlayer.seek(interval_time * -1);
}));
ffButton.setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> { onClick(ffButton, p -> p.seek(interval_time));
if (targetPlayer == null) return;
targetPlayer.seek(interval_time);
}));
nextButton.setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> { onClick(nextButton, MprisPlugin.MprisPlayer::next);
if (targetPlayer == null) return;
targetPlayer.next();
}));
stopButton.setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> { onClick(stopButton, MprisPlugin.MprisPlayer::stop);
if (targetPlayer == null) return;
targetPlayer.stop();
}));
volumeSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { volumeSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment