Skip to content

Commit

Permalink
[android] player cleanup. moved fragment ids to Fragments class.
Browse files Browse the repository at this point in the history
  • Loading branch information
gubatron committed Feb 2, 2016
1 parent 9dd4997 commit ea7b014
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.widget.ImageView;
import com.andrew.apollo.cache.ImageFetcher;
import com.andrew.apollo.model.Album;
import com.andrew.apollo.model.Song;
import com.andrew.apollo.ui.MusicHolder;
import com.andrew.apollo.utils.ApolloUtils;
import com.andrew.apollo.utils.Lists;
Expand Down Expand Up @@ -63,7 +64,7 @@ public abstract class ApolloFragmentAdapter<I> extends ArrayAdapter<I> {
protected MusicHolder.DataHolder[] mData;

public ApolloFragmentAdapter(Context context, int mLayoutId) {
super(context, 0);
super(context, mLayoutId);
this.mLayoutId = mLayoutId;
if (context instanceof Activity) {
mImageFetcher = ApolloUtils.getImageFetcher((Activity) context);
Expand Down Expand Up @@ -94,8 +95,6 @@ public void setDataList(final List<I> data) {
mDataList = data;
}

public abstract long getItemId(int position);

/**
* Starts playing an album if the user touches the artwork in the list.
*
Expand Down Expand Up @@ -162,4 +161,27 @@ public int getCount() {
final int size = mDataList.size();
return size == 0 ? 0 : size + 1;
}

@Override
public long getItemId(int position) {
if (position == 0) {
return -1;
}

int realPosition = position-1;
if (mData != null && realPosition < mData.length) {
return mData[realPosition].mItemId;
} else if (!mDataList.isEmpty() && position < mDataList.size()) {
I item = mDataList.get(realPosition);
long id=-1;
if (item instanceof Song) {
id = ((Song) item).mSongId;
} else if (item instanceof Album) {
id = ((Album) item).mAlbumId;
}
return id;
}

return - 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,6 @@ public int getItemViewType(final int position) {
return ITEM_VIEW_TYPE_MUSIC;
}

/**
* {@inheritDoc}
*/
@Override
public long getItemId(final int position) {
if (position == 0) {
return -1;
}

int realPosition = position-1;
if (mData != null && realPosition < mData.length) {
return mData[realPosition].mItemId;
} else if (!mDataList.isEmpty() && position < mDataList.size()) {
return mDataList.get(realPosition).mAlbumId;
}

return - 1;
}

/**
* Starts playing an album if the user touches the artwork in the list.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public class ProfileSongAdapter extends ApolloFragmentAdapter<Song> {
* @param setting defines the content of the second line
*/
public ProfileSongAdapter(final Context context, final int layoutId, final int setting) {
super(context, 0);
super(context, layoutId);
// Used to create the custom layout
mInflater = LayoutInflater.from(context);
// Cache the header
Expand Down
3 changes: 3 additions & 0 deletions android/apollo/src/com/andrew/apollo/loaders/GenreLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.provider.MediaStore.Audio.GenresColumns;
import com.andrew.apollo.model.Genre;
import com.andrew.apollo.utils.Lists;
import com.frostwire.logging.Logger;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,6 +31,7 @@
* @author Angel Leon (gubatron@gmail.com)
*/
public class GenreLoader extends WrappedAsyncTaskLoader<List<Genre>> {
static Logger LOGGER = Logger.getLogger(GenreLoader.class);

/**
* Constructor of <code>GenreLoader</code>
Expand Down Expand Up @@ -69,6 +71,7 @@ public List<Genre> loadInBackground() {
if (mCursor != null) {
mCursor.close();
}
LOGGER.info("Loaded genre list ("+mGenreList.size()+" genres)");
return mGenreList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void onAttach(final Activity activity) {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int layout = R.layout.list_item_normal;
int layout;
if (isSimpleLayout()) {
layout = R.layout.list_item_normal;
} else if (isDetailedLayout()) {
Expand Down
46 changes: 46 additions & 0 deletions android/apollo/src/com/andrew/apollo/ui/fragments/Fragments.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Created by Angel Leon (@gubatron), Alden Torres (aldenml)
* Copyright (c) 2011-2016, FrostWire(R). All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.andrew.apollo.ui.fragments;

/**
* @author gubatron
* @author aldenml
*/
public class Fragments {
public static int ALBUM_SONG_FRAGMENT_GROUP_ID = 0;
public static int ALBUM_SONG_FRAGMENT_LOADER_ID = 0;

public static int FAVORITE_FRAGMENT_GROUP_ID = 1;
public static int FAVORITE_FRAGMENT_LOADER_ID = 1;

public static int GENRE_SONG_FRAGMENT_GROUP_ID = 2;
public static int GENRE_SONG_FRAGMENT_LOADER_ID = 2;

public static int ARTIST_ALBUM_FRAGMENT_GROUP_ID = 3;
public static int ARTIST_ALBUM_FRAGMENT_LOADER_ID = 3;

public static int ARTIST_SONG_FRAGMENT_GROUP_ID = 4;
public static int ARTIST_SONG_FRAGMENT_LOADER_ID = 4;

public static int LAST_ADDED_FRAGMENT_GROUP_ID = 5;
public static int LAST_ADDED_FRAGMENT_LOADER_ID = 5;

public static int PLAYLIST_SONG_FRAGMENT_GROUP_ID = 6;
public static int PLAYLIST_SONG_FRAGMENT_LOADER_ID = 6;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.andrew.apollo.adapters.ProfileSongAdapter;
import com.andrew.apollo.loaders.AlbumSongLoader;
import com.andrew.apollo.model.Song;
import com.andrew.apollo.ui.fragments.Fragments;
import com.andrew.apollo.utils.MusicUtils;
import com.frostwire.android.R;

Expand All @@ -36,7 +37,7 @@ public class AlbumSongFragment extends ProfileFragment<ProfileSongAdapter, Song>
* Empty constructor as per the {@link Fragment} documentation
*/
public AlbumSongFragment() {
super(ALBUM_SONG_FRAGMENT_GROUP_ID, ALBUM_SONG_FRAGMENT_LOADER_ID);
super(Fragments.ALBUM_SONG_FRAGMENT_GROUP_ID, Fragments.ALBUM_SONG_FRAGMENT_LOADER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

import android.os.Bundle;
import android.support.v4.content.Loader;
import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import com.andrew.apollo.Config;
import com.andrew.apollo.adapters.ArtistAlbumAdapter;
import com.andrew.apollo.loaders.ArtistAlbumLoader;
import com.andrew.apollo.menu.FragmentMenuItems;
import com.andrew.apollo.model.Album;
import com.andrew.apollo.utils.MusicUtils;
import com.andrew.apollo.ui.fragments.Fragments;
import com.andrew.apollo.utils.NavUtils;
import com.andrew.apollo.widgets.VerticalScrollListener;
import com.frostwire.android.R;
Expand All @@ -37,7 +37,7 @@
public class ArtistAlbumFragment extends ProfileFragment<ArtistAlbumAdapter, Album> {

public ArtistAlbumFragment() {
super(ARTIST_ALBUM_FRAGMENT_GROUP_ID,ARTIST_ALBUM_FRAGMENT_LOADER_ID);
super(Fragments.ARTIST_ALBUM_FRAGMENT_GROUP_ID,Fragments.ARTIST_ALBUM_FRAGMENT_LOADER_ID);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.andrew.apollo.adapters.ProfileSongAdapter;
import com.andrew.apollo.loaders.ArtistSongLoader;
import com.andrew.apollo.model.Song;
import com.andrew.apollo.ui.fragments.Fragments;
import com.andrew.apollo.utils.MusicUtils;
import com.frostwire.android.R;

Expand All @@ -37,7 +38,7 @@ public class ArtistSongFragment extends ProfileFragment<ProfileSongAdapter, Song
* Empty constructor as per the {@link Fragment} documentation
*/
public ArtistSongFragment() {
super(ARTIST_SONG_FRAGMENT_GROUP_ID, ARTIST_SONG_FRAGMENT_LOADER_ID);
super(Fragments.ARTIST_SONG_FRAGMENT_GROUP_ID, Fragments.ARTIST_SONG_FRAGMENT_LOADER_ID);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.andrew.apollo.menu.FragmentMenuItems;
import com.andrew.apollo.model.Song;
import com.andrew.apollo.provider.FavoritesStore;
import com.andrew.apollo.ui.fragments.Fragments;
import com.andrew.apollo.utils.MusicUtils;
import com.frostwire.android.R;

Expand All @@ -39,7 +40,7 @@ public class FavoriteFragment extends ProfileFragment<ProfileSongAdapter, Song>
* Empty constructor as per the {@link Fragment} documentation
*/
public FavoriteFragment() {
super(FAVORITE_FRAGMENT_GROUP_ID, FAVORITE_FRAGMENT_LOADER_ID);
super(Fragments.FAVORITE_FRAGMENT_GROUP_ID, Fragments.FAVORITE_FRAGMENT_LOADER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.andrew.apollo.adapters.ProfileSongAdapter;
import com.andrew.apollo.loaders.GenreSongLoader;
import com.andrew.apollo.model.Song;
import com.andrew.apollo.ui.fragments.Fragments;
import com.andrew.apollo.utils.MusicUtils;
import com.frostwire.android.R;

Expand All @@ -36,7 +37,7 @@ public class GenreSongFragment extends ProfileFragment<ProfileSongAdapter, Song>
* Empty constructor as per the {@link Fragment} documentation
*/
public GenreSongFragment() {
super(GENRE_SONG_FRAGMENT_GROUP_ID, GENRE_SONG_FRAGMENT_LOADER_ID);
super(Fragments.GENRE_SONG_FRAGMENT_GROUP_ID, Fragments.GENRE_SONG_FRAGMENT_LOADER_ID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.andrew.apollo.loaders.LastAddedLoader;
import com.andrew.apollo.menu.FragmentMenuItems;
import com.andrew.apollo.model.Song;
import com.andrew.apollo.ui.fragments.Fragments;
import com.andrew.apollo.utils.MusicUtils;
import com.frostwire.android.R;

Expand All @@ -42,7 +43,7 @@ public class LastAddedFragment extends ProfileFragment<ProfileSongAdapter, Song>
* Empty constructor as per the {@link Fragment} documentation
*/
public LastAddedFragment() {
super(LAST_ADDED_FRAGMENT_GROUP_ID, LAST_ADDED_FRAGMENT_LOADER_ID);
super(Fragments.LAST_ADDED_FRAGMENT_GROUP_ID, Fragments.LAST_ADDED_FRAGMENT_LOADER_ID);
}

ProfileSongAdapter createAdapter() {
Expand Down Expand Up @@ -70,7 +71,7 @@ public void onCreateContextMenu(final ContextMenu menu, final View v,
super.onCreateContextMenu(menu, v, menuInfo);

// View more content by the song artist
menu.add(LAST_ADDED_FRAGMENT_GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
menu.add(Fragments.LAST_ADDED_FRAGMENT_GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
getString(R.string.context_menu_more_by_artist));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.andrew.apollo.loaders.PlaylistSongLoader;
import com.andrew.apollo.menu.FragmentMenuItems;
import com.andrew.apollo.model.Song;
import com.andrew.apollo.ui.fragments.Fragments;
import com.andrew.apollo.utils.MusicUtils;
import com.frostwire.android.R;

Expand All @@ -47,7 +48,7 @@ public class PlaylistSongFragment extends ProfileFragment<ProfileSongAdapter, So
* Empty constructor as per the {@link Fragment} documentation
*/
public PlaylistSongFragment() {
super(PLAYLIST_SONG_FRAGMENT_GROUP_ID, PLAYLIST_SONG_FRAGMENT_LOADER_ID);
super(Fragments.PLAYLIST_SONG_FRAGMENT_GROUP_ID, Fragments.PLAYLIST_SONG_FRAGMENT_LOADER_ID);
}

@Override
Expand All @@ -68,11 +69,11 @@ public void onCreateContextMenu(final ContextMenu menu, final View v,
super.onCreateContextMenu(menu, v, menuInfo);

// View more content by the song artist
menu.add(PLAYLIST_SONG_FRAGMENT_GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
menu.add(Fragments.PLAYLIST_SONG_FRAGMENT_GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
getString(R.string.context_menu_more_by_artist));

// Remove the song from playlist
menu.add(PLAYLIST_SONG_FRAGMENT_GROUP_ID, FragmentMenuItems.REMOVE_FROM_PLAYLIST, Menu.NONE,
menu.add(Fragments.PLAYLIST_SONG_FRAGMENT_GROUP_ID, FragmentMenuItems.REMOVE_FROM_PLAYLIST, Menu.NONE,
getString(R.string.context_menu_remove_from_playlist));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,6 @@ public abstract class ProfileFragment<T extends ApolloFragmentAdapter<I>, I>
LoaderManager.LoaderCallbacks<List<I>>,
AdapterView.OnItemClickListener {

protected static int ALBUM_SONG_FRAGMENT_GROUP_ID = 0;
protected static int ALBUM_SONG_FRAGMENT_LOADER_ID = 0;

protected static int FAVORITE_FRAGMENT_GROUP_ID = 1;
protected static int FAVORITE_FRAGMENT_LOADER_ID = 1;

protected static int GENRE_SONG_FRAGMENT_GROUP_ID = 2;
protected static int GENRE_SONG_FRAGMENT_LOADER_ID = 2;

protected static int ARTIST_ALBUM_FRAGMENT_GROUP_ID = 3;
protected static int ARTIST_ALBUM_FRAGMENT_LOADER_ID = 3;

protected static int ARTIST_SONG_FRAGMENT_GROUP_ID = 4;
protected static int ARTIST_SONG_FRAGMENT_LOADER_ID = 4;

protected static int LAST_ADDED_FRAGMENT_GROUP_ID = 5;
protected static int LAST_ADDED_FRAGMENT_LOADER_ID = 5;

protected static int PLAYLIST_SONG_FRAGMENT_GROUP_ID = 6;
protected static int PLAYLIST_SONG_FRAGMENT_LOADER_ID = 6;

private final int GROUP_ID;
/**
* LoaderCallbacks identifier
Expand Down

0 comments on commit ea7b014

Please sign in to comment.