Skip to content

Commit

Permalink
[android] this should close #49 (adding album songs to empty playlist…
Browse files Browse the repository at this point in the history
…) #WIP (more cases pending)
  • Loading branch information
gubatron committed Feb 8, 2016
1 parent 92413f7 commit 81e3e38
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 31 deletions.
3 changes: 3 additions & 0 deletions android/apollo/src/com/andrew/apollo/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public Config() {
*/
public static final String MIME_TYPE = "mime_type";

/** a long[] with the ids of the tracks involved. */
public static final String TRACKS = "tracks";

/**
* Play from search intent
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,16 @@ public void onClick(final View v) {

@Override
public void onClick(final View v) {
NavUtils.openAlbumProfile(AudioPlayerActivity.this, MusicUtils.getAlbumName(),
MusicUtils.getArtistName(), MusicUtils.getCurrentAlbumId());
long albumId = MusicUtils.getCurrentAlbumId();
try {
NavUtils.openAlbumProfile(AudioPlayerActivity.this,
MusicUtils.getAlbumName(),
MusicUtils.getArtistName(),
albumId,
MusicUtils.getSongListForAlbum(AudioPlayerActivity.this, albumId));
} catch (Throwable ignored) {
ignored.printStackTrace();
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.TextView;
import com.andrew.apollo.Config;
import com.andrew.apollo.IApolloService;
import com.andrew.apollo.MusicPlaybackService;
import com.andrew.apollo.MusicStateListener;
Expand Down Expand Up @@ -185,7 +186,7 @@ public boolean onCreateOptionsMenu(final Menu menu) {
// Theme the search icon
mResources.setSearchIcon(menu);

getMenuInflater().inflate(R.menu.new_playlist, menu);
//getMenuInflater().inflate(R.menu.new_playlist, menu);

final SearchView searchView = (SearchView)menu.findItem(R.id.menu_search).getActionView();
// Add voice search
Expand Down Expand Up @@ -221,15 +222,24 @@ public boolean onOptionsItemSelected(final MenuItem item) {
getBackHome(this);
return true;
case R.id.menu_new_playlist:
CreateNewPlaylistMenuAction createPlaylistAction = new CreateNewPlaylistMenuAction(this, null);
createPlaylistAction.onClick();
onOptionsItemNewPlaylistSelected();
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}

protected void onOptionsItemNewPlaylistSelected() {
long[] tracks = null;
if (getIntent() != null && getIntent().hasExtra(Config.TRACKS)) {
tracks = getIntent().getLongArrayExtra(Config.TRACKS);
}
CreateNewPlaylistMenuAction createPlaylistAction = new CreateNewPlaylistMenuAction(this, tracks);
createPlaylistAction.onClick();
MusicUtils.refresh();
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -388,9 +398,13 @@ private void updatePlaybackControls() {
*/
@Override
public void onClick(final View v) {
if (MusicUtils.getCurrentAudioId() != -1) {
NavUtils.openAlbumProfile(BaseActivity.this, MusicUtils.getAlbumName(),
MusicUtils.getArtistName(), MusicUtils.getCurrentAlbumId());
long currentAlbumId = MusicUtils.getCurrentAudioId();
if (currentAlbumId != -1) {
NavUtils.openAlbumProfile(BaseActivity.this,
MusicUtils.getAlbumName(),
MusicUtils.getArtistName(),
MusicUtils.getCurrentAlbumId(),
MusicUtils.getSongListForAlbum(BaseActivity.this,currentAlbumId));
} else {
MusicUtils.shuffleAll(BaseActivity.this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
// Add to playlist
case FragmentMenuItems.NEW_PLAYLIST:
case R.id.menu_new_playlist:
CreateNewPlaylistMenuAction createPlaylistAction = new CreateNewPlaylistMenuAction(this, null);
createPlaylistAction.onClick();
MusicUtils.refresh();
onOptionsItemNewPlaylistSelected();
return true;

case FragmentMenuItems.PLAYLIST_SELECTED: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,12 @@ public void onItemClick(final AdapterView<?> parent, final View view, final int
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST)));
} else if ("album".equals(mimeType)) {
// If it's an album, open the album profile
int albumId = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID);
NavUtils.openAlbumProfile(this,
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM)),
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST)),
cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID)));
cursor.getLong(albumId),
MusicUtils.getSongListForAlbum(this, albumId));
} else if (position >= 0 && id >= 0) {
// If it's a song, play it and leave
final long[] list = new long[] {
Expand All @@ -381,7 +383,6 @@ public void onItemClick(final AdapterView<?> parent, final View view, final int

// Close it up
cursor.close();
cursor = null;
// All done
finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.andrew.apollo.model.Album;
import com.andrew.apollo.ui.activities.BaseActivity;
import com.andrew.apollo.ui.fragments.profile.ApolloFragment;
import com.andrew.apollo.utils.MusicUtils;
import com.andrew.apollo.utils.NavUtils;
import com.andrew.apollo.utils.PreferenceUtils;
import com.frostwire.android.R;
Expand Down Expand Up @@ -76,7 +77,12 @@ protected String getLayoutTypeName() {
public void onItemClick(final AdapterView<?> parent, final View view, final int position,
final long id) {
mItem = mAdapter.getItem(position);
NavUtils.openAlbumProfile(getActivity(), mItem.mAlbumName, mItem.mArtistName, mItem.mAlbumId);
NavUtils.openAlbumProfile(getActivity(),
mItem.mAlbumName,
mItem.mArtistName,
mItem.mAlbumId,
MusicUtils.getSongListForAlbum(getActivity(), mItem.mAlbumId));
getActivity().finish();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ protected AlbumAdapter createAdapter() {
int layout;
if (isSimpleLayout()) {
layout = R.layout.list_item_normal;
} else if (isDetailedLayout()) {
layout = R.layout.list_item_detailed;
} else {
layout = R.layout.grid_items_normal;
}
Expand All @@ -84,19 +82,6 @@ protected String getLayoutTypeName() {
return PreferenceUtils.RECENT_LAYOUT;
}

/**
* {@inheritDoc}
*/
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position,
final long id) {
mItem = mAdapter.getItem(position);
NavUtils.openAlbumProfile(getActivity(), mItem.mAlbumName, mItem.mArtistName, mItem.mAlbumId);
}

/**
* {@inheritDoc}
*/
@Override
public Loader<List<Album>> onCreateLoader(final int id, final Bundle args) {
return new RecentLoader(getActivity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.andrew.apollo.loaders.ArtistAlbumLoader;
import com.andrew.apollo.model.Album;
import com.andrew.apollo.ui.fragments.Fragments;
import com.andrew.apollo.utils.MusicUtils;
import com.andrew.apollo.utils.NavUtils;
import com.andrew.apollo.utils.PreferenceUtils;
import com.andrew.apollo.widgets.VerticalScrollListener;
Expand Down Expand Up @@ -84,7 +85,11 @@ public void onItemClick(final AdapterView<?> parent,
final int position,
final long id) {
mItem = mAdapter.getItem(position);
NavUtils.openAlbumProfile(getActivity(), mItem.mAlbumName, mItem.mArtistName, mItem.mAlbumId);
NavUtils.openAlbumProfile(getActivity(),
mItem.mAlbumName,
mItem.mArtistName,
mItem.mAlbumId,
MusicUtils.getSongListForAlbum(getActivity(), mItem.mAlbumId));
getActivity().finish();
}
}
6 changes: 5 additions & 1 deletion android/apollo/src/com/andrew/apollo/utils/NavUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void openArtistProfile(final Activity context,
* @param albumId The id of the album
*/
public static void openAlbumProfile(final Activity context,
final String albumName, final String artistName, final long albumId) {
final String albumName, final String artistName, final long albumId, final long[] songs) {

// Create a new bundle to transfer the album info
final Bundle bundle = new Bundle();
Expand All @@ -79,6 +79,10 @@ public static void openAlbumProfile(final Activity context,
bundle.putLong(Config.ID, albumId);
bundle.putString(Config.NAME, albumName);

if (songs != null && songs.length > 0) {
bundle.putLongArray(Config.TRACKS, songs);
}

// Create the intent to launch the profile activity
final Intent intent = new Intent(context, ProfileActivity.class);
intent.putExtras(bundle);
Expand Down

0 comments on commit 81e3e38

Please sign in to comment.