Add in fragment that pops up when selected an artist in artists fragment.
This commit is contained in:
@@ -1,22 +1,47 @@
|
|||||||
package com.magnatune.eyecreate.companionformagnatune;
|
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.BitmapDrawable;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.transition.Slide;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.view.Gravity;
|
|
||||||
|
|
||||||
import com.heinrichreimersoftware.materialdrawer.DrawerActivity;
|
import com.heinrichreimersoftware.materialdrawer.DrawerActivity;
|
||||||
import com.heinrichreimersoftware.materialdrawer.structure.DrawerItem;
|
import com.heinrichreimersoftware.materialdrawer.structure.DrawerItem;
|
||||||
import com.heinrichreimersoftware.materialdrawer.structure.DrawerProfile;
|
import com.heinrichreimersoftware.materialdrawer.structure.DrawerProfile;
|
||||||
import com.magnatune.eyecreate.companionformagnatune.fragments.AlbumsFragment;
|
import com.magnatune.eyecreate.companionformagnatune.fragments.AlbumsFragment;
|
||||||
import com.magnatune.eyecreate.companionformagnatune.fragments.ArtistFragment;
|
import com.magnatune.eyecreate.companionformagnatune.fragments.ArtistFragment;
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.fragments.ArtistsFragment;
|
||||||
import com.magnatune.eyecreate.companionformagnatune.login.MagnatuneAccountManager;
|
import com.magnatune.eyecreate.companionformagnatune.login.MagnatuneAccountManager;
|
||||||
|
|
||||||
public class BrowseActivity extends DrawerActivity {
|
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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -46,7 +71,7 @@ public class BrowseActivity extends DrawerActivity {
|
|||||||
public void onClick(DrawerItem drawerItem, long l, int i) {
|
public void onClick(DrawerItem drawerItem, long l, int i) {
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction()
|
||||||
.setCustomAnimations(R.anim.fragment_enter, R.anim.fragment_exit)
|
.setCustomAnimations(R.anim.fragment_enter, R.anim.fragment_exit)
|
||||||
.replace(R.id.fragment_holder, new ArtistFragment(), "artists")
|
.replace(R.id.fragment_holder, new ArtistsFragment(), "artists")
|
||||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||||
.commit();
|
.commit();
|
||||||
closeDrawer();
|
closeDrawer();
|
||||||
@@ -59,4 +84,16 @@ public class BrowseActivity extends DrawerActivity {
|
|||||||
.commit();
|
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package com.magnatune.eyecreate.companionformagnatune.adapters;
|
package com.magnatune.eyecreate.companionformagnatune.adapters;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.BrowseActivity;
|
||||||
import com.magnatune.eyecreate.companionformagnatune.R;
|
import com.magnatune.eyecreate.companionformagnatune.R;
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.fragments.ArtistFragment;
|
||||||
import com.magnatune.eyecreate.companionformagnatune.model.Artist;
|
import com.magnatune.eyecreate.companionformagnatune.model.Artist;
|
||||||
import com.magnatune.eyecreate.companionformagnatune.viewholders.ArtistViewHolder;
|
import com.magnatune.eyecreate.companionformagnatune.viewholders.ArtistViewHolder;
|
||||||
|
|
||||||
@@ -25,7 +30,18 @@ public class ArtistsAdapter extends RealmBasedRecyclerViewAdapter<Artist,ArtistV
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindRealmViewHolder(ArtistViewHolder artistViewHolder, int i) {
|
public void onBindRealmViewHolder(final ArtistViewHolder artistViewHolder, final int i) {
|
||||||
artistViewHolder.artistName.setText(realmResults.get(i).getArtistname());
|
artistViewHolder.artistName.setText(realmResults.get(i).getArtistname());
|
||||||
|
artistViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,16 @@
|
|||||||
package com.magnatune.eyecreate.companionformagnatune.fragments;
|
package com.magnatune.eyecreate.companionformagnatune.fragments;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.magnatune.eyecreate.companionformagnatune.R;
|
import com.magnatune.eyecreate.companionformagnatune.R;
|
||||||
import com.magnatune.eyecreate.companionformagnatune.adapters.ArtistsAdapter;
|
import com.magnatune.eyecreate.companionformagnatune.adapters.AlbumsAdapter;
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.model.Album;
|
||||||
import com.magnatune.eyecreate.companionformagnatune.model.Artist;
|
import com.magnatune.eyecreate.companionformagnatune.model.Artist;
|
||||||
import com.magnatune.eyecreate.companionformagnatune.model.MagnatuneDBManager;
|
import com.magnatune.eyecreate.companionformagnatune.model.MagnatuneDBManager;
|
||||||
|
|
||||||
@@ -23,46 +19,19 @@ import io.realm.Realm;
|
|||||||
|
|
||||||
public class ArtistFragment extends Fragment {
|
public class ArtistFragment extends Fragment {
|
||||||
|
|
||||||
|
public static final String ARG_ARTIST_NAME = "artistname";
|
||||||
|
|
||||||
Realm db;
|
Realm db;
|
||||||
RealmRecyclerView recyclerView;
|
RealmRecyclerView recyclerView;
|
||||||
BroadcastReceiver refreshDone = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
recyclerView.setRefreshing(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
recyclerView = (RealmRecyclerView) inflater.inflate(R.layout.fragment_artists,container,false);
|
|
||||||
recyclerView.setOnRefreshListener(new RealmRecyclerView.OnRefreshListener() {
|
|
||||||
@Override
|
|
||||||
public void onRefresh() {
|
|
||||||
triggerDBUpdate();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
recyclerView.setAdapter(new ArtistsAdapter(getActivity(), db.where(Artist.class).findAllSorted("artistname"), true, true,true,"artistname"));
|
|
||||||
if (db.where(Artist.class).findAll().size() < 1) {
|
|
||||||
triggerDBUpdate();
|
|
||||||
}
|
|
||||||
return recyclerView;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void triggerDBUpdate() {
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... voids) {
|
|
||||||
MagnatuneDBManager.updateDB();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
db = MagnatuneDBManager.getAlbumDB();
|
db = MagnatuneDBManager.getAlbumDB();
|
||||||
|
if(!getArguments().containsKey(ARG_ARTIST_NAME)) {
|
||||||
|
//No artist argument means can't make fragment
|
||||||
|
getActivity().onBackPressed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,21 +40,15 @@ public class ArtistFragment extends Fragment {
|
|||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
super.onResume();
|
View v = inflater.inflate(R.layout.fragment_artist,container,false);;
|
||||||
recyclerView.post(new Runnable() {
|
recyclerView = (RealmRecyclerView) v.findViewById(R.id.artist_albums);
|
||||||
@Override
|
Artist artist = db.where(Artist.class).equalTo("artistname",getArguments().getString(ARG_ARTIST_NAME)).findFirst();
|
||||||
public void run() {
|
((TextView) v.findViewById(R.id.artist_name)).setText(artist.getArtistname());
|
||||||
recyclerView.setRefreshing(!MagnatuneDBManager.isProcessingDone());
|
((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));
|
||||||
});
|
return v;
|
||||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(refreshDone, new IntentFilter(MagnatuneDBManager.ACTION_DB_UPDATE_DONE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(refreshDone);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package com.magnatune.eyecreate.companionformagnatune.fragments;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.R;
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.adapters.ArtistsAdapter;
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.model.Artist;
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.model.MagnatuneDBManager;
|
||||||
|
|
||||||
|
import co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView;
|
||||||
|
import io.realm.Realm;
|
||||||
|
|
||||||
|
public class ArtistsFragment extends Fragment {
|
||||||
|
|
||||||
|
Realm db;
|
||||||
|
RealmRecyclerView recyclerView;
|
||||||
|
BroadcastReceiver refreshDone = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
recyclerView.setRefreshing(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
recyclerView = (RealmRecyclerView) inflater.inflate(R.layout.fragment_artists,container,false);
|
||||||
|
recyclerView.setOnRefreshListener(new RealmRecyclerView.OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
triggerDBUpdate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
recyclerView.setAdapter(new ArtistsAdapter(getActivity(), db.where(Artist.class).findAllSorted("artistname"), true, true,true,"artistname"));
|
||||||
|
if (db.where(Artist.class).findAll().size() < 1) {
|
||||||
|
triggerDBUpdate();
|
||||||
|
}
|
||||||
|
return recyclerView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void triggerDBUpdate() {
|
||||||
|
new AsyncTask<Void, Void, Void>() {
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
MagnatuneDBManager.updateDB();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
db = MagnatuneDBManager.getAlbumDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
recyclerView.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
recyclerView.setRefreshing(!MagnatuneDBManager.isProcessingDone());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(refreshDone, new IntentFilter(MagnatuneDBManager.ACTION_DB_UPDATE_DONE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(refreshDone);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
app/src/main/res/anim/fragment_pop_enter.xml
Normal file
8
app/src/main/res/anim/fragment_pop_enter.xml
Normal 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>
|
||||||
8
app/src/main/res/anim/fragment_pop_exit.xml
Normal file
8
app/src/main/res/anim/fragment_pop_exit.xml
Normal 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>
|
||||||
25
app/src/main/res/layout/fragment_artist.xml
Normal file
25
app/src/main/res/layout/fragment_artist.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?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: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="2"/>
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user