1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 19:12:45 +01:00

Deduplicate code switching to another player into a function

This commit is contained in:
Raphaël Jakse 2020-01-16 20:46:11 +01:00
parent 570dded8d6
commit ef90493c27
3 changed files with 12 additions and 22 deletions

View File

@ -55,13 +55,7 @@ public final class BackgroundPlayerActivity extends ServicePlayerActivity {
return true;
}
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(
getSwitchIntent(PopupVideoPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true;
return switchTo(PopupVideoPlayer.class);
}
return false;
}

View File

@ -48,13 +48,7 @@ public final class PopupVideoPlayerActivity extends ServicePlayerActivity {
@Override
public boolean onPlayerOptionSelected(MenuItem item) {
if (item.getItemId() == R.id.action_switch_background) {
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(
getSwitchIntent(BackgroundPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true;
return switchTo(BackgroundPlayer.class);
}
return false;
}

View File

@ -165,13 +165,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
return true;
case R.id.action_switch_main:
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startActivity(
getSwitchIntent(MainVideoPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true;
return switchTo(MainVideoPlayer.class);
}
return onPlayerOptionSelected(item) || super.onOptionsItemSelected(item);
}
@ -194,7 +188,15 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
null,
false,
false
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying());
}
protected boolean switchTo(final Class clazz) {
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startActivity(getSwitchIntent(clazz));
return true;
}
////////////////////////////////////////////////////////////////////////////