Rework DB to have artist data separated into Artist table. Rework refresh notifications to be more in line with actions with multiple fragments. Filed bug against what I'm seeing on artist fragment.
https://github.com/thorbenprimke/realm-recyclerview/issues/4
This commit is contained in:
@@ -31,7 +31,7 @@ public class AlbumsAdapter extends RealmBasedRecyclerViewAdapter<Album,AlbumView
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindRealmViewHolder(final AlbumViewHolder albumViewHolder, int i) {
|
public void onBindRealmViewHolder(final AlbumViewHolder albumViewHolder, int i) {
|
||||||
albumViewHolder.artistName.setText(realmResults.get(i).getArtist());
|
albumViewHolder.artistName.setText(realmResults.get(i).getArtist().getArtistname());
|
||||||
albumViewHolder.albumName.setText(realmResults.get(i).getAlbumname());
|
albumViewHolder.albumName.setText(realmResults.get(i).getAlbumname());
|
||||||
Picasso.with(albumViewHolder.itemView.getContext()).load(realmResults.get(i).getCover_small()).into(albumViewHolder.albumArt, new Callback() {
|
Picasso.with(albumViewHolder.itemView.getContext()).load(realmResults.get(i).getCover_small()).into(albumViewHolder.albumArt, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.magnatune.eyecreate.companionformagnatune.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.R;
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.model.Artist;
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.viewholders.ArtistViewHolder;
|
||||||
|
|
||||||
|
import io.realm.RealmBasedRecyclerViewAdapter;
|
||||||
|
import io.realm.RealmResults;
|
||||||
|
|
||||||
|
public class ArtistsAdapter extends RealmBasedRecyclerViewAdapter<Artist,ArtistViewHolder> {
|
||||||
|
|
||||||
|
public ArtistsAdapter(Context context, RealmResults<Artist> realmResults, boolean automaticUpdate, boolean animateResults, boolean addSectionHeaders, String headerColumnName) {
|
||||||
|
super(context, realmResults, automaticUpdate, animateResults, addSectionHeaders, headerColumnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArtistViewHolder onCreateRealmViewHolder(ViewGroup viewGroup, int i) {
|
||||||
|
View v = inflater.inflate(R.layout.listitem_artist,viewGroup,false);
|
||||||
|
ArtistViewHolder holder = new ArtistViewHolder(v);
|
||||||
|
return holder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindRealmViewHolder(ArtistViewHolder artistViewHolder, int i) {
|
||||||
|
artistViewHolder.artistName.setText(realmResults.get(i).getArtistname());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,17 +49,9 @@ public class AlbumsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
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));
|
||||||
recyclerView.post(new Runnable() {
|
if (db.where(Album.class).findAll().size() < 1) {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if(db.where(Album.class).findAll().size()<1) {
|
|
||||||
recyclerView.setRefreshing(true);
|
|
||||||
triggerDBUpdate();
|
triggerDBUpdate();
|
||||||
} else if(!MagnatuneDBManager.isProcessingDone()) {
|
|
||||||
recyclerView.setRefreshing(true);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
return recyclerView;
|
return recyclerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +74,12 @@ public class AlbumsFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.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));
|
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(refreshDone,new IntentFilter(MagnatuneDBManager.ACTION_DB_UPDATE_DONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,91 @@
|
|||||||
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 com.magnatune.eyecreate.companionformagnatune.R;
|
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 ArtistFragment extends Fragment {
|
public class ArtistFragment extends Fragment {
|
||||||
|
|
||||||
|
Realm db;
|
||||||
|
RealmRecyclerView recyclerView;
|
||||||
|
BroadcastReceiver refreshDone = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
recyclerView.setRefreshing(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View v = inflater.inflate(R.layout.fragment_artists,container,false);
|
recyclerView = (RealmRecyclerView) inflater.inflate(R.layout.fragment_artists,container,false);
|
||||||
return v;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,9 @@ public class Album extends RealmObject {
|
|||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
private String albumsku;
|
private String albumsku;
|
||||||
private String albumname;
|
private String albumname;
|
||||||
private String artist;
|
private Artist artist;
|
||||||
private String artistdesc;
|
|
||||||
private String cover_small;
|
private String cover_small;
|
||||||
private String cover_large;
|
private String cover_large;
|
||||||
private String artistphoto;
|
|
||||||
private int year;
|
private int year;
|
||||||
private String album_notes;
|
private String album_notes;
|
||||||
private String homepage;
|
private String homepage;
|
||||||
@@ -40,22 +38,14 @@ public class Album extends RealmObject {
|
|||||||
this.albumname = albumname;
|
this.albumname = albumname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getArtist() {
|
public Artist getArtist() {
|
||||||
return artist;
|
return artist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArtist(String artist) {
|
public void setArtist(Artist artist) {
|
||||||
this.artist = artist;
|
this.artist = artist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getArtistdesc() {
|
|
||||||
return artistdesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setArtistdesc(String artistdesc) {
|
|
||||||
this.artistdesc = artistdesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCover_small() {
|
public String getCover_small() {
|
||||||
return cover_small;
|
return cover_small;
|
||||||
}
|
}
|
||||||
@@ -72,14 +62,6 @@ public class Album extends RealmObject {
|
|||||||
this.cover_large = cover_large;
|
this.cover_large = cover_large;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getArtistphoto() {
|
|
||||||
return artistphoto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setArtistphoto(String artistphoto) {
|
|
||||||
this.artistphoto = artistphoto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getYear() {
|
public int getYear() {
|
||||||
return year;
|
return year;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.magnatune.eyecreate.companionformagnatune.model;
|
||||||
|
|
||||||
|
import io.realm.RealmObject;
|
||||||
|
import io.realm.annotations.PrimaryKey;
|
||||||
|
|
||||||
|
public class Artist extends RealmObject {
|
||||||
|
@PrimaryKey
|
||||||
|
private String artistname;
|
||||||
|
private String artistdesc;
|
||||||
|
private String artistphoto;
|
||||||
|
|
||||||
|
public String getArtistname() {
|
||||||
|
return artistname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArtistname(String artistname) {
|
||||||
|
this.artistname = artistname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArtistdesc() {
|
||||||
|
return artistdesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArtistdesc(String artistdesc) {
|
||||||
|
this.artistdesc = artistdesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArtistphoto() {
|
||||||
|
return artistphoto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArtistphoto(String artistphoto) {
|
||||||
|
this.artistphoto = artistphoto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -100,15 +100,17 @@ public class MagnatuneDBManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Album xmlAlbumToDBAlbum(com.magnatune.eyecreate.companionformagnatune.model.xml.Album album) {
|
public static Album xmlAlbumToDBAlbum(com.magnatune.eyecreate.companionformagnatune.model.xml.Album album) {
|
||||||
|
Artist artist = new Artist();
|
||||||
|
artist.setArtistname(album.artist);
|
||||||
|
artist.setArtistdesc(album.artistdesc);
|
||||||
|
artist.setArtistphoto(album.artistphoto);
|
||||||
Album entry = new Album();
|
Album entry = new Album();
|
||||||
entry.setAlbumsku(album.albumsku);
|
entry.setAlbumsku(album.albumsku);
|
||||||
entry.setAlbumname(album.albumname);
|
entry.setAlbumname(album.albumname);
|
||||||
entry.setArtist(album.artist);
|
entry.setArtist(artist);
|
||||||
entry.setArtistdesc(album.artistdesc);
|
|
||||||
entry.setAlbum_notes(album.album_notes);
|
entry.setAlbum_notes(album.album_notes);
|
||||||
entry.setCover_small(album.cover_small);
|
entry.setCover_small(album.cover_small);
|
||||||
entry.setCover_large(album.cover_small.replace("200", "800"));
|
entry.setCover_large(album.cover_small.replace("200", "800"));
|
||||||
entry.setArtistphoto(album.artistphoto);
|
|
||||||
entry.setYear(album.year);
|
entry.setYear(album.year);
|
||||||
entry.setHomepage(album.home);
|
entry.setHomepage(album.home);
|
||||||
entry.setMp3genre(album.mp3genre);
|
entry.setMp3genre(album.mp3genre);
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.magnatune.eyecreate.companionformagnatune.viewholders;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.R;
|
||||||
|
|
||||||
|
import io.realm.RealmViewHolder;
|
||||||
|
|
||||||
|
public class ArtistViewHolder extends RealmViewHolder {
|
||||||
|
|
||||||
|
public TextView artistName;
|
||||||
|
|
||||||
|
public ArtistViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
artistName = (TextView) itemView.findViewById(R.id.artist_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,6 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/artist_list"
|
android:id="@+id/artist_list"
|
||||||
app:rrvLayoutType="LinearLayout"
|
app:rrvLayoutType="LinearLayoutWithHeaders"
|
||||||
app:rrvIsRefreshable="true"
|
app:rrvIsRefreshable="true"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android" />
|
xmlns:android="http://schemas.android.com/apk/res/android" />
|
||||||
13
app/src/main/res/layout/listitem_artist.xml
Normal file
13
app/src/main/res/layout/listitem_artist.xml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?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_margin="10dp"
|
||||||
|
android:paddingTop="5dp"
|
||||||
|
android:paddingBottom="5dp"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/artist_name"/>
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user