Moved shortcut handling from MainActivity to MusicService. Cleaned up the code.

This commit is contained in:
Karim Abou Zeid 2017-03-27 12:28:37 +02:00
commit b0590bf5e1
7 changed files with 50 additions and 80 deletions

View file

@ -60,12 +60,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity {
private static final int LIBRARY = 0;
private static final int FOLDERS = 1;
public static final String PHONOGRAPH_PACKAGE_NAME = "com.kabouzeid.gramophone";
public static final String INTENT_ACTION_MEDIA_PLAY_SHUFFLED = PHONOGRAPH_PACKAGE_NAME + ".intent_action.play_shuffled";
public static final String INTENT_ACTION_MEDIA_PLAY = PHONOGRAPH_PACKAGE_NAME + ".intent_action.play";
public static final String INTENT_EXTRA_SONGS = PHONOGRAPH_PACKAGE_NAME + ".intent_extra.songs";
@BindView(R.id.navigation_view)
NavigationView navigationView;
@BindView(R.id.drawer_layout)
@ -264,13 +258,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity {
handlePlaybackIntent(getIntent());
}
//Called when there's already an instance of MainActivity
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handlePlaybackIntent(intent);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
@ -309,25 +296,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity {
} else {
MusicPlayerRemote.openQueue(songs, 0, true);
}
} else if (intent.getAction() != null && intent.getAction().equals(MainActivity.INTENT_ACTION_MEDIA_PLAY_SHUFFLED)){
//Shuffle songs in extras
final ArrayList<Song> songs = intent.getExtras().getParcelableArrayList(INTENT_EXTRA_SONGS);
//Start the songs, setting the shuffle mode to shuffle
MusicPlayerRemote.openAndShuffleQueue(songs, true);
handled = true;
} else if (intent.getAction() != null && intent.getAction().equals(MainActivity.INTENT_ACTION_MEDIA_PLAY)){
//Shuffle songs in extras
final ArrayList<Song> songs = intent.getExtras().getParcelableArrayList(INTENT_EXTRA_SONGS);
//Start the songs, preserving the user's shuffle mode
if (MusicPlayerRemote.getShuffleMode() == MusicService.SHUFFLE_MODE_SHUFFLE) {
MusicPlayerRemote.openAndShuffleQueue(songs, true);
} else {
MusicPlayerRemote.openQueue(songs, 0, true);
}
handled = true;
}