2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-29 13:17:43 +00:00

Deduplicate code for listeners in MprisActivity

This commit is contained in:
Nicolas Fella 2019-03-30 16:58:01 +01:00
parent 3f2b8495b3
commit 2ab76c6e90

View File

@ -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 {
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