Start of basic track listing. Still needs some work in what is displayed both content and style. Still can't figure out why shared content isn't working like I expect.
This commit is contained in:
@@ -2,12 +2,19 @@ package com.magnatune.eyecreate.companionformagnatune.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.graphics.Palette;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.transition.AutoTransition;
|
||||
import android.transition.Slide;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.magnatune.eyecreate.companionformagnatune.R;
|
||||
import com.magnatune.eyecreate.companionformagnatune.fragments.AlbumFragment;
|
||||
import com.magnatune.eyecreate.companionformagnatune.model.Album;
|
||||
import com.magnatune.eyecreate.companionformagnatune.viewholders.AlbumViewHolder;
|
||||
import com.squareup.picasso.Callback;
|
||||
@@ -18,6 +25,13 @@ import io.realm.RealmResults;
|
||||
|
||||
public class AlbumsAdapter extends RealmBasedRecyclerViewAdapter<Album,AlbumViewHolder> {
|
||||
|
||||
FragmentManager fragmentManager;
|
||||
|
||||
public AlbumsAdapter(Context context, RealmResults<Album> realmResults, boolean automaticUpdate, boolean animateResults, String animateExtraColumnName,FragmentManager fragmentManager) {
|
||||
super(context, realmResults, automaticUpdate, animateResults, animateExtraColumnName);
|
||||
this.fragmentManager = fragmentManager;
|
||||
}
|
||||
|
||||
public AlbumsAdapter(Context context, RealmResults<Album> realmResults, boolean automaticUpdate, boolean animateResults, String animateExtraColumnName) {
|
||||
super(context, realmResults, automaticUpdate, animateResults, animateExtraColumnName);
|
||||
}
|
||||
@@ -30,23 +44,23 @@ public class AlbumsAdapter extends RealmBasedRecyclerViewAdapter<Album,AlbumView
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindRealmViewHolder(final AlbumViewHolder albumViewHolder, int i) {
|
||||
public void onBindRealmViewHolder(final AlbumViewHolder albumViewHolder, final int i) {
|
||||
albumViewHolder.artistName.setText(realmResults.get(i).getArtist().getArtistname());
|
||||
albumViewHolder.albumName.setText(realmResults.get(i).getAlbumname());
|
||||
Picasso.with(albumViewHolder.itemView.getContext()).load(realmResults.get(i).getCover_small()).into(albumViewHolder.albumArt, new Callback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Palette colors = Palette.from(((BitmapDrawable)albumViewHolder.albumArt.getDrawable()).getBitmap()).generate();
|
||||
Palette colors = Palette.from(((BitmapDrawable) albumViewHolder.albumArt.getDrawable()).getBitmap()).generate();
|
||||
Palette.Swatch swatch = null;
|
||||
swatch = colors.getVibrantSwatch();
|
||||
if(swatch == null) {
|
||||
if (swatch == null) {
|
||||
swatch = colors.getMutedSwatch();
|
||||
}
|
||||
if(swatch == null && colors.getSwatches().size()>0) {
|
||||
if (swatch == null && colors.getSwatches().size() > 0) {
|
||||
swatch = colors.getSwatches().get(0);
|
||||
}
|
||||
if(swatch != null) {
|
||||
((CardView)albumViewHolder.itemView).setCardBackgroundColor(swatch.getRgb());
|
||||
if (swatch != null) {
|
||||
((CardView) albumViewHolder.itemView).setCardBackgroundColor(swatch.getRgb());
|
||||
albumViewHolder.albumName.setTextColor(swatch.getTitleTextColor());
|
||||
albumViewHolder.artistName.setTextColor(swatch.getBodyTextColor());
|
||||
}
|
||||
@@ -57,5 +71,26 @@ public class AlbumsAdapter extends RealmBasedRecyclerViewAdapter<Album,AlbumView
|
||||
|
||||
}
|
||||
});
|
||||
albumViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(AlbumFragment.ARG_ALBUM_ID, realmResults.get(i).getAlbumsku());
|
||||
AlbumFragment fragment = new AlbumFragment();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
fragment.setEnterTransition(new Slide(Gravity.BOTTOM));
|
||||
fragment.setExitTransition(new Slide(Gravity.BOTTOM));
|
||||
fragment.setSharedElementEnterTransition(new AutoTransition());
|
||||
fragment.setSharedElementReturnTransition(new AutoTransition());
|
||||
}
|
||||
fragment.setArguments(args);
|
||||
fragmentManager.beginTransaction()
|
||||
.setCustomAnimations(R.anim.fragment_enter,R.anim.fragment_exit,R.anim.fragment_pop_enter,R.anim.fragment_pop_exit)
|
||||
.addSharedElement(albumViewHolder.albumArt,"albumart")
|
||||
.replace(R.id.fragment_holder, fragment, "tracks")
|
||||
.addToBackStack("tracks")
|
||||
.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.magnatune.eyecreate.companionformagnatune.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.magnatune.eyecreate.companionformagnatune.R;
|
||||
import com.magnatune.eyecreate.companionformagnatune.model.Track;
|
||||
|
||||
import io.realm.RealmBaseAdapter;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
public class TracksAdapter extends RealmBaseAdapter<Track> {
|
||||
public TracksAdapter(Context context, RealmResults<Track> realmResults, boolean automaticUpdate) {
|
||||
super(context, realmResults, automaticUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if(convertView == null) {
|
||||
convertView = inflater.inflate(R.layout.listitem_track,parent,false);
|
||||
}
|
||||
TextView trackName = (TextView) convertView.findViewById(R.id.track_name);
|
||||
trackName.setText(realmResults.get(position).getTrackname());
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.magnatune.eyecreate.companionformagnatune.fragments;
|
||||
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.graphics.Palette;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.GridLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.magnatune.eyecreate.companionformagnatune.R;
|
||||
import com.magnatune.eyecreate.companionformagnatune.adapters.TracksAdapter;
|
||||
import com.magnatune.eyecreate.companionformagnatune.model.Album;
|
||||
import com.magnatune.eyecreate.companionformagnatune.model.MagnatuneDBManager;
|
||||
import com.magnatune.eyecreate.companionformagnatune.model.Track;
|
||||
import com.squareup.picasso.Callback;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import io.realm.Realm;
|
||||
|
||||
public class AlbumFragment extends Fragment {
|
||||
|
||||
public static final String ARG_ALBUM_ID = "albumsku";
|
||||
|
||||
Realm db;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
db = MagnatuneDBManager.getAlbumDB();
|
||||
if(!getArguments().containsKey(ARG_ALBUM_ID)) {
|
||||
//No album argument means can't make fragment
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
db.close();
|
||||
}
|
||||
|
||||
private static void setListViewHeightBasedOnChildren(ListView listView) {
|
||||
ListAdapter listAdapter = listView.getAdapter();
|
||||
if (listAdapter == null)
|
||||
return;
|
||||
|
||||
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
|
||||
int totalHeight = 0;
|
||||
View view = null;
|
||||
for (int i = 0; i < listAdapter.getCount(); i++) {
|
||||
view = listAdapter.getView(i, view, listView);
|
||||
if (i == 0)
|
||||
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, GridLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
|
||||
totalHeight += view.getMeasuredHeight();
|
||||
}
|
||||
ViewGroup.LayoutParams params = listView.getLayoutParams();
|
||||
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
|
||||
listView.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View v = inflater.inflate(R.layout.fragment_album, container, false);
|
||||
ListView listView = (ListView) v.findViewById(R.id.album_tracks);
|
||||
Album currentAlbum = db.where(Album.class).equalTo("albumsku",getArguments().getString(ARG_ALBUM_ID)).findFirst();
|
||||
((TextView)v.findViewById(R.id.album_name)).setText(currentAlbum.getAlbumname());
|
||||
Picasso.with(getActivity()).load(currentAlbum.getCover_large()).into((ImageView) v.findViewById(R.id.album_cover), new Callback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Palette colors = Palette.from(((BitmapDrawable) ((ImageView) v.findViewById(R.id.album_cover)).getDrawable()).getBitmap()).generate();
|
||||
Palette.Swatch swatch = null;
|
||||
swatch = colors.getVibrantSwatch();
|
||||
if (swatch == null) {
|
||||
swatch = colors.getMutedSwatch();
|
||||
}
|
||||
if (swatch == null && colors.getSwatches().size() > 0) {
|
||||
swatch = colors.getSwatches().get(0);
|
||||
}
|
||||
if (swatch != null) {
|
||||
((TextView)v.findViewById(R.id.album_name)).setTextColor(swatch.getTitleTextColor());
|
||||
v.findViewById(R.id.album_name).setBackgroundColor(swatch.getRgb());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
TracksAdapter adapter = new TracksAdapter(getActivity(),db.where(Track.class).equalTo("albumname",currentAlbum.getAlbumname()).equalTo("artist",currentAlbum.getArtist().getArtistname()).findAll(),true);
|
||||
listView.setAdapter(adapter);
|
||||
setListViewHeightBasedOnChildren(listView);
|
||||
return v;
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class AlbumsFragment extends Fragment {
|
||||
triggerDBUpdate();
|
||||
}
|
||||
});
|
||||
recyclerView.setAdapter(new AlbumsAdapter(getActivity(), db.where(Album.class).findAllSorted("albumname"), true, true, null));
|
||||
recyclerView.setAdapter(new AlbumsAdapter(getActivity(), db.where(Album.class).findAllSorted("albumname"), true, true, null,getFragmentManager()));
|
||||
if (db.where(Album.class).findAll().size() < 1) {
|
||||
triggerDBUpdate();
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ArtistFragment extends Fragment {
|
||||
Artist artist = db.where(Artist.class).equalTo("artistname",getArguments().getString(ARG_ARTIST_NAME)).findFirst();
|
||||
((TextView) v.findViewById(R.id.artist_name)).setText(artist.getArtistname());
|
||||
((TextView) v.findViewById(R.id.artist_description)).setText(artist.getArtistdesc());
|
||||
recyclerView.setAdapter(new AlbumsAdapter(getActivity(),db.where(Album.class).equalTo("artist.artistname",artist.getArtistname()).findAll(),true,true,null));
|
||||
recyclerView.setAdapter(new AlbumsAdapter(getActivity(),db.where(Album.class).equalTo("artist.artistname",artist.getArtistname()).findAll(),true,true,null,getFragmentManager()));
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
34
app/src/main/res/layout/fragment_album.xml
Normal file
34
app/src/main/res/layout/fragment_album.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/album_cover"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:transitionName="albumart" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/album_name"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:textStyle="bold"
|
||||
android:textSize="20sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/album_tracks"/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
@@ -13,6 +13,7 @@
|
||||
android:layout_height="180dp"
|
||||
android:layout_gravity="center"
|
||||
android:scaleType="fitCenter"
|
||||
android:transitionName="albumart"
|
||||
android:id="@+id/album_art"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
10
app/src/main/res/layout/listitem_track.xml
Normal file
10
app/src/main/res/layout/listitem_track.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:id="@+id/track_name"/>
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user