diff --git a/app/src/main/java/com/naman14/timber/adapters/ArtistSongAdapter.java b/app/src/main/java/com/naman14/timber/adapters/ArtistSongAdapter.java deleted file mode 100644 index 59c2a77bb..000000000 --- a/app/src/main/java/com/naman14/timber/adapters/ArtistSongAdapter.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (C) 2015 Naman Dwivedi - * - * Licensed under the GNU General Public License v3 - * - * This 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 software 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. - */ - -package com.naman14.timber.adapters; - -import android.app.Activity; -import android.graphics.Rect; -import android.os.Handler; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.PopupMenu; -import android.widget.TextView; - -import com.naman14.timber.MusicPlayer; -import com.naman14.timber.R; -import com.naman14.timber.dataloaders.ArtistAlbumLoader; -import com.naman14.timber.dialogs.AddPlaylistDialog; -import com.naman14.timber.models.Song; -import com.naman14.timber.utils.NavigationUtils; -import com.naman14.timber.utils.TimberUtils; -import com.nostra13.universalimageloader.core.DisplayImageOptions; -import com.nostra13.universalimageloader.core.ImageLoader; - -import java.util.ArrayList; -import java.util.List; - -public class ArtistSongAdapter extends RecyclerView.Adapter { - - private List arraylist; - private Activity mContext; - private long artistID; - private long[] songIDs; - - public ArtistSongAdapter(Activity context, List arraylist, long artistID) { - this.arraylist = arraylist; - this.mContext = context; - this.artistID = artistID; - this.songIDs = getSongIds(); - } - - @Override - public ItemHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { - if (viewType == 0) { - View v0 = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.artist_detail_albums_header, null); - ItemHolder ml = new ItemHolder(v0); - return ml; - } else { - View v2 = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_artist_song, null); - ItemHolder ml = new ItemHolder(v2); - return ml; - } - } - - @Override - public void onBindViewHolder(ItemHolder itemHolder, int i) { - - if (getItemViewType(i) == 0) { - //nothing - setUpAlbums(itemHolder.albumsRecyclerView); - } else { - Song localItem = arraylist.get(i); - itemHolder.title.setText(localItem.title); - itemHolder.album.setText(localItem.albumName); - - ImageLoader.getInstance().displayImage(TimberUtils.getAlbumArtUri(localItem.albumId).toString(), itemHolder.albumArt, new DisplayImageOptions.Builder().cacheInMemory(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).build()); - setOnPopupMenuListener(itemHolder, i - 1); - } - - } - - @Override - public void onViewRecycled(ItemHolder itemHolder) { - - if (itemHolder.getItemViewType() == 0) - clearExtraSpacingBetweenCards(itemHolder.albumsRecyclerView); - - } - - @Override - public int getItemCount() { - return (null != arraylist ? arraylist.size() : 0); - } - - private void setOnPopupMenuListener(ItemHolder itemHolder, final int position) { - - itemHolder.menu.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - final PopupMenu menu = new PopupMenu(mContext, v); - menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.popup_song_play: - MusicPlayer.playAll(mContext, songIDs, position, -1, TimberUtils.IdType.NA, false); - break; - case R.id.popup_song_play_next: - long[] ids = new long[1]; - ids[0] = arraylist.get(position + 1).id; - MusicPlayer.playNext(mContext, ids, -1, TimberUtils.IdType.NA); - break; - case R.id.popup_song_goto_album: - NavigationUtils.goToAlbum(mContext, arraylist.get(position + 1).albumId); - break; - case R.id.popup_song_goto_artist: - NavigationUtils.goToArtist(mContext, arraylist.get(position + 1).artistId); - break; - case R.id.popup_song_addto_queue: - long[] id = new long[1]; - id[0] = arraylist.get(position + 1).id; - MusicPlayer.addToQueue(mContext, id, -1, TimberUtils.IdType.NA); - break; - case R.id.popup_song_addto_playlist: - AddPlaylistDialog.newInstance(arraylist.get(position + 1)).show(((AppCompatActivity) mContext).getSupportFragmentManager(), "ADD_PLAYLIST"); - break; - case R.id.popup_song_share: - TimberUtils.shareTrack(mContext, arraylist.get(position).id); - break; - case R.id.popup_song_delete: - long[] deleteIds = {arraylist.get(position).id}; - TimberUtils.showDeleteDialog(mContext,arraylist.get(position).title, deleteIds, ArtistSongAdapter.this, position); - break; - } - return false; - } - }); - menu.inflate(R.menu.popup_song); - menu.show(); - } - }); - } - - private void setUpAlbums(RecyclerView albumsRecyclerview) { - - albumsRecyclerview.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false)); - albumsRecyclerview.setHasFixedSize(true); - - //to add spacing between cards - int spacingInPixels = mContext.getResources().getDimensionPixelSize(R.dimen.spacing_card); - albumsRecyclerview.addItemDecoration(new SpacesItemDecoration(spacingInPixels)); - albumsRecyclerview.setNestedScrollingEnabled(false); - - - ArtistAlbumAdapter mAlbumAdapter = new ArtistAlbumAdapter(mContext, ArtistAlbumLoader.getAlbumsForArtist(mContext, artistID)); - albumsRecyclerview.setAdapter(mAlbumAdapter); - } - - private void clearExtraSpacingBetweenCards(RecyclerView albumsRecyclerview) { - //to clear any extra spacing between cards - int spacingInPixelstoClear = -(mContext.getResources().getDimensionPixelSize(R.dimen.spacing_card)); - albumsRecyclerview.addItemDecoration(new SpacesItemDecoration(spacingInPixelstoClear)); - - } - - public long[] getSongIds() { - List actualArraylist = new ArrayList(arraylist); - actualArraylist.remove(0); - long[] ret = new long[actualArraylist.size()]; - for (int i = 0; i < actualArraylist.size(); i++) { - ret[i] = actualArraylist.get(i).id; - } - return ret; - } - - @Override - public int getItemViewType(int position) { - int viewType; - if (position == 0) { - viewType = 0; - } else viewType = 1; - return viewType; - } - - public class ItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener { - protected TextView title, album; - protected ImageView albumArt, menu; - protected RecyclerView albumsRecyclerView; - - public ItemHolder(View view) { - super(view); - - this.albumsRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view_album); - - this.title = (TextView) view.findViewById(R.id.song_title); - this.album = (TextView) view.findViewById(R.id.song_album); - this.albumArt = (ImageView) view.findViewById(R.id.albumArt); - this.menu = (ImageView) view.findViewById(R.id.popup_menu); - - - view.setOnClickListener(this); - } - - @Override - public void onClick(View v) { - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - MusicPlayer.playAll(mContext, songIDs, getAdapterPosition() - 1, artistID, TimberUtils.IdType.Artist, false); - NavigationUtils.navigateToNowplaying(mContext, true); - } - }, 100); - - } - - } - - public class SpacesItemDecoration extends RecyclerView.ItemDecoration { - private int space; - - public SpacesItemDecoration(int space) { - this.space = space; - } - - @Override - public void getItemOffsets(Rect outRect, View view, - RecyclerView parent, RecyclerView.State state) { - - //the padding from left - outRect.left = space; - - - } - } -} - - - - diff --git a/app/src/main/java/com/naman14/timber/fragments/ArtistMusicFragment.java b/app/src/main/java/com/naman14/timber/fragments/ArtistMusicFragment.java index db6eaeb08..3bf07f8a2 100644 --- a/app/src/main/java/com/naman14/timber/fragments/ArtistMusicFragment.java +++ b/app/src/main/java/com/naman14/timber/fragments/ArtistMusicFragment.java @@ -16,26 +16,26 @@ import android.os.Bundle; import android.support.v4.app.Fragment; -import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.naman14.timber.R; -import com.naman14.timber.adapters.ArtistSongAdapter; -import com.naman14.timber.dataloaders.ArtistSongLoader; -import com.naman14.timber.models.Song; +import com.naman14.timber.adapters.AlbumAdapter; +import com.naman14.timber.adapters.ArtistAlbumAdapter; +import com.naman14.timber.dataloaders.ArtistAlbumLoader; +import com.naman14.timber.models.Album; import com.naman14.timber.utils.Constants; -import com.naman14.timber.widgets.DividerItemDecoration; import java.util.ArrayList; public class ArtistMusicFragment extends Fragment { - public static RecyclerView songsRecyclerview; + public static RecyclerView albumsRecyclerView; long artistID = -1; - ArtistSongAdapter mSongAdapter; + AlbumAdapter albumAdapter; public static ArtistMusicFragment newInstance(long id) { ArtistMusicFragment fragment = new ArtistMusicFragment(); @@ -58,28 +58,21 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa View rootView = inflater.inflate( R.layout.fragment_artist_music, container, false); - songsRecyclerview = (RecyclerView) rootView.findViewById(R.id.recycler_view_songs); + albumsRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view_albums); - setUpSongs(); + setUpAlbums(); return rootView; } - private void setUpSongs() { - songsRecyclerview.setLayoutManager(new LinearLayoutManager(getActivity())); + private void setUpAlbums() { + albumsRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2)); - ArrayList songList; - songList = ArtistSongLoader.getSongsForArtist(getActivity(), artistID); - - // adding one dummy song to top of arraylist - //there will be albums header at this position in recyclerview - songList.add(0, new Song(-1, -1, -1, "dummy", "dummy", "dummy", -1, -1)); - - mSongAdapter = new ArtistSongAdapter(getActivity(), songList, artistID); - songsRecyclerview.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST)); - songsRecyclerview.setAdapter(mSongAdapter); + ArrayList albumList = ArtistAlbumLoader.getAlbumsForArtist(getActivity(), artistID); + ArtistAlbumAdapter albumAdapter = new ArtistAlbumAdapter(getActivity(), albumList); + albumsRecyclerView.setAdapter(albumAdapter); } diff --git a/app/src/main/res/layout/fragment_artist_music.xml b/app/src/main/res/layout/fragment_artist_music.xml index b8a4d0d04..86290f633 100644 --- a/app/src/main/res/layout/fragment_artist_music.xml +++ b/app/src/main/res/layout/fragment_artist_music.xml @@ -3,7 +3,7 @@ diff --git a/app/src/main/res/layout/item_artist_album.xml b/app/src/main/res/layout/item_artist_album.xml index 9728b0ad8..0050d9e39 100644 --- a/app/src/main/res/layout/item_artist_album.xml +++ b/app/src/main/res/layout/item_artist_album.xml @@ -1,8 +1,8 @@ - - + android:transitionName="transition_album_art" />