-
-
Save eyecreate/deb1835ef58e4708f2ba to your computer and use it in GitHub Desktop.
RRV Supporting Classes for https://github.com/thorbenprimke/realm-recyclerview/issues/4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Album extends RealmObject { | |
@PrimaryKey | |
private String albumsku; | |
private String albumname; | |
private Artist artist; | |
private String cover_small; | |
private String cover_large; | |
private int year; | |
private String album_notes; | |
private String homepage; | |
private String mp3genre; | |
private Date launchdate; | |
private RealmList<MGenre> genres; | |
private RealmList<Track> tracks; | |
public String getAlbumsku() { | |
return albumsku; | |
} | |
public void setAlbumsku(String albumsku) { | |
this.albumsku = albumsku; | |
} | |
public String getAlbumname() { | |
return albumname; | |
} | |
public void setAlbumname(String albumname) { | |
this.albumname = albumname; | |
} | |
public Artist getArtist() { | |
return artist; | |
} | |
public void setArtist(Artist artist) { | |
this.artist = artist; | |
} | |
public String getCover_small() { | |
return cover_small; | |
} | |
public void setCover_small(String cover_small) { | |
this.cover_small = cover_small; | |
} | |
public String getCover_large() { | |
return cover_large; | |
} | |
public void setCover_large(String cover_large) { | |
this.cover_large = cover_large; | |
} | |
public int getYear() { | |
return year; | |
} | |
public void setYear(int year) { | |
this.year = year; | |
} | |
public String getAlbum_notes() { | |
return album_notes; | |
} | |
public void setAlbum_notes(String album_notes) { | |
this.album_notes = album_notes; | |
} | |
public String getHomepage() { | |
return homepage; | |
} | |
public void setHomepage(String homepage) { | |
this.homepage = homepage; | |
} | |
public String getMp3genre() { | |
return mp3genre; | |
} | |
public void setMp3genre(String mp3genre) { | |
this.mp3genre = mp3genre; | |
} | |
public Date getLaunchdate() { | |
return launchdate; | |
} | |
public void setLaunchdate(Date launchdate) { | |
this.launchdate = launchdate; | |
} | |
public RealmList<MGenre> getGenres() { | |
return genres; | |
} | |
public void setGenres(RealmList<MGenre> genres) { | |
this.genres = genres; | |
} | |
public RealmList<Track> getTracks() { | |
return tracks; | |
} | |
public void setTracks(RealmList<Track> tracks) { | |
this.tracks = tracks; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(final ArtistViewHolder artistViewHolder, final int i) { | |
artistViewHolder.artistName.setText(realmResults.get(i).getArtistname()); | |
artistViewHolder.itemView.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
//Do click event | |
} | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArtistsFragment extends Fragment { | |
Realm db; | |
RealmRecyclerView recyclerView; | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
recyclerView = (RealmRecyclerView) inflater.inflate(R.layout.fragment_artists,container,false); | |
recyclerView.setAdapter(new ArtistsAdapter(getActivity(), db.where(Artist.class).findAllSorted("artistname"), true, true, true, "artistname")); | |
return recyclerView; | |
} | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
//Need line below to grab correct Realm DB instance. | |
//db = Realm... | |
} | |
@Override | |
public void onDestroy() { | |
super.onDestroy(); | |
db.close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArtistViewHolder extends RealmViewHolder { | |
public TextView artistName; | |
public ArtistViewHolder(View itemView) { | |
super(itemView); | |
artistName = (TextView) itemView.findViewById(R.id.artist_name); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MGenre extends RealmObject { | |
@PrimaryKey | |
private String genre_name; | |
public String getGenre_name() { | |
return genre_name; | |
} | |
public void setGenre_name(String genre_name) { | |
this.genre_name = genre_name; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Track extends RealmObject { | |
@PrimaryKey | |
private String isrc; | |
private String trackname; | |
private String artist; | |
private String albumname; | |
private int tracknumber; | |
private int year; | |
private String mp3genre; | |
private RealmList<MGenre> genres; | |
private String license; | |
private long seconds; | |
private String url; | |
private String mp3_low_quality; | |
private String ogg_url; | |
public String getIsrc() { | |
return isrc; | |
} | |
public void setIsrc(String isrc) { | |
this.isrc = isrc; | |
} | |
public String getTrackname() { | |
return trackname; | |
} | |
public void setTrackname(String trackname) { | |
this.trackname = trackname; | |
} | |
public String getArtist() { | |
return artist; | |
} | |
public void setArtist(String artist) { | |
this.artist = artist; | |
} | |
public String getAlbumname() { | |
return albumname; | |
} | |
public void setAlbumname(String albumname) { | |
this.albumname = albumname; | |
} | |
public int getTracknumber() { | |
return tracknumber; | |
} | |
public void setTracknumber(int tracknumber) { | |
this.tracknumber = tracknumber; | |
} | |
public int getYear() { | |
return year; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Take note of the commented out line to init DB and that I didn't include the two layouts. They are simply one that is only a RRV and one that is just a textview.