diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3509f2d1331..ac33a7f0f4d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,7 +53,7 @@ diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java deleted file mode 100644 index eb1c74dadaa..00000000000 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.schabi.newpipe.player; - -import android.content.Intent; -import android.view.Menu; - -import org.schabi.newpipe.R; - -public final class BackgroundPlayerActivity extends ServicePlayerActivity { - - private static final String TAG = "BackgroundPlayerActivity"; - - @Override - public String getTag() { - return TAG; - } - - @Override - public String getSupportActionTitle() { - return getResources().getString(R.string.title_activity_play_queue); - } - - @Override - public Intent getBindIntent() { - return new Intent(this, MainPlayer.class); - } - - @Override - public void startPlayerListener() { - if (player != null) { - player.setActivityListener(this); - } - } - - @Override - public void stopPlayerListener() { - if (player != null) { - player.removeActivityListener(this); - } - } - - @Override - public int getPlayerOptionMenuResource() { - return R.menu.menu_play_queue_bg; - } - - @Override - public void setupMenu(final Menu menu) { - if (player != null) { - menu.findItem(R.id.action_switch_popup) - .setVisible(!player.popupPlayerSelected()); - menu.findItem(R.id.action_switch_background) - .setVisible(!player.audioPlayerSelected()); - } - } -} diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java similarity index 94% rename from app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java rename to app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java index 7e2f53ff73d..6c083662881 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java @@ -16,7 +16,6 @@ import android.widget.SeekBar; import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -48,9 +47,12 @@ import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed; import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; -public abstract class ServicePlayerActivity extends AppCompatActivity +public final class PlayQueueActivity extends AppCompatActivity implements PlayerEventListener, SeekBar.OnSeekBarChangeListener, View.OnClickListener, PlaybackParameterDialog.Callback { + + private static final String TAG = PlayQueueActivity.class.getSimpleName(); + private static final int RECYCLER_ITEM_POPUP_MENU_GROUP_ID = 47; private static final int SMOOTH_SCROLL_MAXIMUM_DISTANCE = 80; @@ -60,7 +62,6 @@ public abstract class ServicePlayerActivity extends AppCompatActivity private ServiceConnection serviceConnection; private boolean seeking; - private boolean redraw; //////////////////////////////////////////////////////////////////////////// // Views @@ -72,24 +73,6 @@ public abstract class ServicePlayerActivity extends AppCompatActivity private Menu menu; - //////////////////////////////////////////////////////////////////////////// - // Abstracts - //////////////////////////////////////////////////////////////////////////// - - public abstract String getTag(); - - public abstract String getSupportActionTitle(); - - public abstract Intent getBindIntent(); - - public abstract void startPlayerListener(); - - public abstract void stopPlayerListener(); - - public abstract int getPlayerOptionMenuResource(); - - public abstract void setupMenu(Menu m); - //////////////////////////////////////////////////////////////////////////// // Activity Lifecycle //////////////////////////////////////////////////////////////////////////// @@ -106,27 +89,18 @@ protected void onCreate(final Bundle savedInstanceState) { setSupportActionBar(queueControlBinding.toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setTitle(getSupportActionTitle()); + getSupportActionBar().setTitle(R.string.title_activity_play_queue); } serviceConnection = getServiceConnection(); bind(); } - @Override - protected void onResume() { - super.onResume(); - if (redraw) { - ActivityCompat.recreate(this); - redraw = false; - } - } - @Override public boolean onCreateOptionsMenu(final Menu m) { this.menu = m; getMenuInflater().inflate(R.menu.menu_play_queue, m); - getMenuInflater().inflate(getPlayerOptionMenuResource(), m); + getMenuInflater().inflate(R.menu.menu_play_queue_bg, m); onMaybeMuteChanged(); onPlaybackParameterChanged(player.getPlaybackParameters()); return true; @@ -135,7 +109,12 @@ public boolean onCreateOptionsMenu(final Menu m) { // Allow to setup visibility of menuItems @Override public boolean onPrepareOptionsMenu(final Menu m) { - setupMenu(m); + if (player != null) { + menu.findItem(R.id.action_switch_popup) + .setVisible(!player.popupPlayerSelected()); + menu.findItem(R.id.action_switch_background) + .setVisible(!player.audioPlayerSelected()); + } return super.onPrepareOptionsMenu(m); } @@ -191,7 +170,8 @@ protected void onDestroy() { //////////////////////////////////////////////////////////////////////////// private void bind() { - final boolean success = bindService(getBindIntent(), serviceConnection, BIND_AUTO_CREATE); + final Intent bindIntent = new Intent(this, MainPlayer.class); + final boolean success = bindService(bindIntent, serviceConnection, BIND_AUTO_CREATE); if (!success) { unbindService(serviceConnection); } @@ -202,7 +182,9 @@ private void unbind() { if (serviceBound) { unbindService(serviceConnection); serviceBound = false; - stopPlayerListener(); + if (player != null) { + player.removeActivityListener(this); + } if (player != null && player.getPlayQueueAdapter() != null) { player.getPlayQueueAdapter().unsetSelectedListener(); @@ -221,12 +203,12 @@ private ServiceConnection getServiceConnection() { return new ServiceConnection() { @Override public void onServiceDisconnected(final ComponentName name) { - Log.d(getTag(), "Player service is disconnected"); + Log.d(TAG, "Player service is disconnected"); } @Override public void onServiceConnected(final ComponentName name, final IBinder service) { - Log.d(getTag(), "Player service is connected"); + Log.d(TAG, "Player service is connected"); if (service instanceof PlayerServiceBinder) { player = ((PlayerServiceBinder) service).getPlayerInstance(); @@ -240,7 +222,9 @@ public void onServiceConnected(final ComponentName name, final IBinder service) finish(); } else { buildComponents(); - startPlayerListener(); + if (player != null) { + player.setActivityListener(PlayQueueActivity.this); + } } } }; @@ -463,7 +447,7 @@ private void openPlaybackParameterDialog() { return; } PlaybackParameterDialog.newInstance(player.getPlaybackSpeed(), player.getPlaybackPitch(), - player.getPlaybackSkipSilence(), this).show(getSupportFragmentManager(), getTag()); + player.getPlaybackSkipSilence(), this).show(getSupportFragmentManager(), TAG); } @Override @@ -517,10 +501,8 @@ private void openPlaylistAppendDialog(final List playlist) { final PlaylistAppendDialog d = PlaylistAppendDialog.fromPlayQueueItems(playlist); PlaylistAppendDialog.onPlaylistFound(getApplicationContext(), - () -> d.show(getSupportFragmentManager(), getTag()), - () -> PlaylistCreationDialog.newInstance(d) - .show(getSupportFragmentManager(), getTag() - )); + () -> d.show(getSupportFragmentManager(), TAG), + () -> PlaylistCreationDialog.newInstance(d).show(getSupportFragmentManager(), TAG)); } //////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index ea02e0f6be3..c90bb302577 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -46,7 +46,7 @@ import org.schabi.newpipe.local.playlist.LocalPlaylistFragment; import org.schabi.newpipe.local.subscription.SubscriptionFragment; import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment; -import org.schabi.newpipe.player.BackgroundPlayerActivity; +import org.schabi.newpipe.player.PlayQueueActivity; import org.schabi.newpipe.player.Player; import org.schabi.newpipe.player.MainPlayer; import org.schabi.newpipe.player.helper.PlayerHelper; @@ -530,7 +530,7 @@ public static void openDownloads(final Activity activity) { } public static Intent getPlayQueueActivityIntent(final Context context) { - final Intent intent = new Intent(context, BackgroundPlayerActivity.class); + final Intent intent = new Intent(context, PlayQueueActivity.class); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } diff --git a/app/src/main/res/layout-land/activity_player_queue_control.xml b/app/src/main/res/layout-land/activity_player_queue_control.xml index 2adea98683c..b106e743788 100644 --- a/app/src/main/res/layout-land/activity_player_queue_control.xml +++ b/app/src/main/res/layout-land/activity_player_queue_control.xml @@ -6,7 +6,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" - tools:context="org.schabi.newpipe.player.BackgroundPlayerActivity"> + tools:context="org.schabi.newpipe.player.PlayQueueActivity"> + tools:context="org.schabi.newpipe.player.PlayQueueActivity"> + tools:context=".player.PlayQueueActivity">