Private
Public Access
1
0

Implement drawer switches to have animations. Layout enough of artist fragment to demo this. Try out using dynamic colors based on album art for albums.

This commit is contained in:
Kevin Whitaker
2015-11-21 18:18:39 -05:00
parent e4c13ad6d3
commit 74b4e31fc7
7 changed files with 75 additions and 4 deletions

View File

@@ -3,7 +3,10 @@ package com.magnatune.eyecreate.companionformagnatune;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.transition.Slide;
import android.view.Gravity;
import com.heinrichreimersoftware.materialdrawer.DrawerActivity;
import com.heinrichreimersoftware.materialdrawer.structure.DrawerItem;
@@ -30,6 +33,7 @@ public class BrowseActivity extends DrawerActivity {
@Override
public void onClick(DrawerItem drawerItem, long l, int i) {
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.fragment_enter, R.anim.fragment_exit)
.replace(R.id.fragment_holder, new AlbumsFragment(), "albums")
.commit();
closeDrawer();
@@ -41,7 +45,9 @@ public class BrowseActivity extends DrawerActivity {
@Override
public void onClick(DrawerItem drawerItem, long l, int i) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_holder,new ArtistFragment(),"artists")
.setCustomAnimations(R.anim.fragment_enter, R.anim.fragment_exit)
.replace(R.id.fragment_holder, new ArtistFragment(), "artists")
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
closeDrawer();
}

View File

@@ -1,12 +1,16 @@
package com.magnatune.eyecreate.companionformagnatune.adapters;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.CardView;
import android.view.View;
import android.view.ViewGroup;
import com.magnatune.eyecreate.companionformagnatune.R;
import com.magnatune.eyecreate.companionformagnatune.model.Album;
import com.magnatune.eyecreate.companionformagnatune.viewholders.AlbumViewHolder;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import io.realm.RealmBasedRecyclerViewAdapter;
@@ -26,9 +30,32 @@ public class AlbumsAdapter extends RealmBasedRecyclerViewAdapter<Album,AlbumView
}
@Override
public void onBindRealmViewHolder(AlbumViewHolder albumViewHolder, int i) {
public void onBindRealmViewHolder(final AlbumViewHolder albumViewHolder, int i) {
albumViewHolder.artistName.setText(realmResults.get(i).getArtist());
albumViewHolder.albumName.setText(realmResults.get(i).getAlbumname());
Picasso.with(albumViewHolder.itemView.getContext()).load(realmResults.get(i).getCover_small()).into(albumViewHolder.albumArt);
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.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) {
((CardView)albumViewHolder.itemView).setCardBackgroundColor(swatch.getRgb());
albumViewHolder.albumName.setTextColor(swatch.getTitleTextColor());
albumViewHolder.artistName.setTextColor(swatch.getBodyTextColor());
}
}
@Override
public void onError() {
}
});
}
}

View File

@@ -48,7 +48,7 @@ public class AlbumsFragment extends Fragment {
triggerDBUpdate();
}
});
recyclerView.setAdapter(new AlbumsAdapter(getActivity(), db.where(Album.class).findAll(), true, true, null));
recyclerView.setAdapter(new AlbumsAdapter(getActivity(), db.where(Album.class).findAllSorted("albumname"), true, true, null));
recyclerView.post(new Runnable() {
@Override
public void run() {

View File

@@ -1,6 +1,19 @@
package com.magnatune.eyecreate.companionformagnatune.fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.magnatune.eyecreate.companionformagnatune.R;
public class ArtistFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_artists,container,false);
return v;
}
}

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%"
android:toXDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="-100%"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/artist_list"
app:rrvLayoutType="LinearLayout"
app:rrvIsRefreshable="true"
xmlns:android="http://schemas.android.com/apk/res/android" />