1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-23 03:22:37 +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; return true;
} }
this.player.setRecovery(); return switchTo(PopupVideoPlayer.class);
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(
getSwitchIntent(PopupVideoPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true;
} }
return false; return false;
} }

View File

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

View File

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