Skip to content

Commit

Permalink
Merge and rename into PlayQueueActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Jan 12, 2021
1 parent ec219ca commit e34c566
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 104 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</service>

<activity
android:name=".player.BackgroundPlayerActivity"
android:name=".player.PlayQueueActivity"
android:label="@string/title_activity_play_queue"
android:launchMode="singleTask" />

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -60,7 +62,6 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
private ServiceConnection serviceConnection;

private boolean seeking;
private boolean redraw;

////////////////////////////////////////////////////////////////////////////
// Views
Expand All @@ -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
////////////////////////////////////////////////////////////////////////////
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -240,7 +222,9 @@ public void onServiceConnected(final ComponentName name, final IBinder service)
finish();
} else {
buildComponents();
startPlayerListener();
if (player != null) {
player.setActivityListener(PlayQueueActivity.this);
}
}
}
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -517,10 +501,8 @@ private void openPlaylistAppendDialog(final List<PlayQueueItem> 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));
}

////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_player_queue_control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/menu_play_queue.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".player.BackgroundPlayerActivity">
tools:context=".player.PlayQueueActivity">

<item
android:id="@+id/action_append_playlist"
Expand Down

0 comments on commit e34c566

Please sign in to comment.