Private
Public Access
1
0

Move fragment code into adapter so attempts at shared view transitions might be possible. Code is set up for it, but it doesn't look quite right. Play around with how albums look in port/land mode.

This commit is contained in:
Kevin Whitaker
2015-11-21 22:22:35 -05:00
parent e41c447ae2
commit 24f798e2b2
9 changed files with 70 additions and 50 deletions

View File

@@ -1,47 +1,20 @@
package com.magnatune.eyecreate.companionformagnatune;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
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.support.v4.content.LocalBroadcastManager;
import com.heinrichreimersoftware.materialdrawer.DrawerActivity;
import com.heinrichreimersoftware.materialdrawer.structure.DrawerItem;
import com.heinrichreimersoftware.materialdrawer.structure.DrawerProfile;
import com.magnatune.eyecreate.companionformagnatune.fragments.AlbumsFragment;
import com.magnatune.eyecreate.companionformagnatune.fragments.ArtistFragment;
import com.magnatune.eyecreate.companionformagnatune.fragments.ArtistsFragment;
import com.magnatune.eyecreate.companionformagnatune.login.MagnatuneAccountManager;
public class BrowseActivity extends DrawerActivity {
public static final String ACTION_ONCLICK_ACTIVATED = "browseactivityonclick";
public static final String EXTRA_FRAGMENT = "fragmenttostart";
public static final String EXTRA_FRAGMENT_ARGS = "fragmentargs";
BroadcastReceiver onClickManager = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.hasExtra(EXTRA_FRAGMENT)) {
if(intent.getStringExtra(EXTRA_FRAGMENT).equals(ArtistFragment.class.getName())) {
ArtistFragment fragment = new ArtistFragment();
fragment.setArguments(intent.getBundleExtra(EXTRA_FRAGMENT_ARGS));
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.fragment_enter,R.anim.fragment_exit,R.anim.fragment_pop_enter,R.anim.fragment_pop_exit)
.replace(R.id.fragment_holder,fragment,"artist")
.addToBackStack("artist")
.commit();
}
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -84,16 +57,4 @@ public class BrowseActivity extends DrawerActivity {
.commit();
}
}
@Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(onClickManager,new IntentFilter(ACTION_ONCLICK_ACTIVATED));
}
@Override
protected void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(onClickManager);
}
}

View File

@@ -1,13 +1,15 @@
package com.magnatune.eyecreate.companionformagnatune.adapters;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.app.FragmentManager;
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.BrowseActivity;
import com.magnatune.eyecreate.companionformagnatune.R;
import com.magnatune.eyecreate.companionformagnatune.fragments.ArtistFragment;
import com.magnatune.eyecreate.companionformagnatune.model.Artist;
@@ -18,6 +20,13 @@ import io.realm.RealmResults;
public class ArtistsAdapter extends RealmBasedRecyclerViewAdapter<Artist,ArtistViewHolder> {
FragmentManager fragmentManager;
public ArtistsAdapter(Context context, RealmResults<Artist> realmResults, boolean automaticUpdate, boolean animateResults, boolean addSectionHeaders, String headerColumnName, FragmentManager fragmentManager) {
super(context, realmResults, automaticUpdate, animateResults, addSectionHeaders, headerColumnName);
this.fragmentManager = fragmentManager;
}
public ArtistsAdapter(Context context, RealmResults<Artist> realmResults, boolean automaticUpdate, boolean animateResults, boolean addSectionHeaders, String headerColumnName) {
super(context, realmResults, automaticUpdate, animateResults, addSectionHeaders, headerColumnName);
}
@@ -37,10 +46,20 @@ public class ArtistsAdapter extends RealmBasedRecyclerViewAdapter<Artist,ArtistV
public void onClick(View view) {
Bundle args = new Bundle();
args.putString(ArtistFragment.ARG_ARTIST_NAME,realmResults.get(i).getArtistname());
Intent toArtist = new Intent(BrowseActivity.ACTION_ONCLICK_ACTIVATED);
toArtist.putExtra(BrowseActivity.EXTRA_FRAGMENT, ArtistFragment.class.getName());
toArtist.putExtra(BrowseActivity.EXTRA_FRAGMENT_ARGS,args);
LocalBroadcastManager.getInstance(view.getContext()).sendBroadcast(toArtist);
ArtistFragment fragment = new ArtistFragment();
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(artistViewHolder.artistName, "artist_name")
.replace(R.id.fragment_holder, fragment, "artist")
.addToBackStack("artist")
.commit();
}
});
}

View File

@@ -42,6 +42,7 @@ public class AlbumsFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
recyclerView = (RealmRecyclerView) inflater.inflate(R.layout.fragment_albums,container,false);
recyclerView.setOnRefreshListener(new RealmRecyclerView.OnRefreshListener() {
@Override
public void onRefresh() {

View File

@@ -42,7 +42,7 @@ public class ArtistsFragment extends Fragment {
triggerDBUpdate();
}
});
recyclerView.setAdapter(new ArtistsAdapter(getActivity(), db.where(Artist.class).findAllSorted("artistname"), true, true,true,"artistname"));
recyclerView.setAdapter(new ArtistsAdapter(getActivity(), db.where(Artist.class).findAllSorted("artistname"), true, true,true,"artistname",getFragmentManager()));
if (db.where(Artist.class).findAll().size() < 1) {
triggerDBUpdate();
}

View File

@@ -0,0 +1,10 @@
<?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/album_grid"
app:rrvLayoutType="Grid"
app:rrvIsRefreshable="true"
app:rrvGridLayoutSpanCount="3"
xmlns:android="http://schemas.android.com/apk/res/android" />

View File

@@ -0,0 +1,26 @@
<?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="10dp"
android:textStyle="bold"
android:textSize="20sp"
android:transitionName="artist_name"
android:id="@+id/artist_name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:id="@+id/artist_description"/>
<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_albums"
app:rrvLayoutType="Grid"
app:rrvIsRefreshable="false"
app:rrvGridLayoutSpanCount="3"/>
</LinearLayout>

View File

@@ -8,6 +8,7 @@
android:layout_margin="10dp"
android:textStyle="bold"
android:textSize="20sp"
android:transitionName="artist_name"
android:id="@+id/artist_name"/>
<TextView
android:layout_width="match_parent"

View File

@@ -7,17 +7,18 @@
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_margin="5dp"
android:layout_height="match_parent">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:id="@+id/album_art"/>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_margin="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"

View File

@@ -9,5 +9,6 @@
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="artist_name"
android:id="@+id/artist_name"/>
</LinearLayout>