Completely rewritten the album model
This commit is contained in:
parent
d80c8f62bf
commit
c2ad4e4541
21 changed files with 292 additions and 332 deletions
|
|
@ -3,34 +3,44 @@ package com.kabouzeid.gramophone.model;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class Album implements Parcelable {
|
||||
public final int id;
|
||||
public final int artistId;
|
||||
public final String title;
|
||||
public final String artistName;
|
||||
public final int songCount;
|
||||
public final int year;
|
||||
public final ArrayList<Song> songs;
|
||||
|
||||
public Album(final int id, final String title, final String artistName, final int artistId,
|
||||
final int songNumber, final int albumYear) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.artistName = artistName;
|
||||
this.artistId = artistId;
|
||||
songCount = songNumber;
|
||||
year = albumYear;
|
||||
public Album(ArrayList<Song> songs) {
|
||||
this.songs = songs;
|
||||
}
|
||||
|
||||
public Album() {
|
||||
this.id = -1;
|
||||
this.title = "";
|
||||
this.artistName = "";
|
||||
this.artistId = -1;
|
||||
songCount = -1;
|
||||
year = -1;
|
||||
this.songs = new ArrayList<>();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return songs.get(0).albumId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return songs.get(0).albumName;
|
||||
}
|
||||
|
||||
public int getArtistId() {
|
||||
return songs.get(0).artistId;
|
||||
}
|
||||
|
||||
public String getArtistName() {
|
||||
return songs.get(0).artistName;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
return songs.get(0).year;
|
||||
}
|
||||
|
||||
public int getSongCount() {
|
||||
return songs.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -38,41 +48,24 @@ public class Album implements Parcelable {
|
|||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Album album = (Album) o;
|
||||
Album that = (Album) o;
|
||||
|
||||
if (id != album.id) return false;
|
||||
if (artistId != album.artistId) return false;
|
||||
if (songCount != album.songCount) return false;
|
||||
if (year != album.year) return false;
|
||||
if (title != null ? !title.equals(album.title) : album.title != null) return false;
|
||||
return artistName != null ? artistName.equals(album.artistName) : album.artistName == null;
|
||||
return songs != null ? songs.equals(that.songs) : that.songs == null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id;
|
||||
result = 31 * result + artistId;
|
||||
result = 31 * result + (title != null ? title.hashCode() : 0);
|
||||
result = 31 * result + (artistName != null ? artistName.hashCode() : 0);
|
||||
result = 31 * result + songCount;
|
||||
result = 31 * result + year;
|
||||
return result;
|
||||
return songs != null ? songs.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Album{" +
|
||||
"id=" + id +
|
||||
", artistId=" + artistId +
|
||||
", title='" + title + '\'' +
|
||||
", artistName='" + artistName + '\'' +
|
||||
", songCount=" + songCount +
|
||||
", year=" + year +
|
||||
"songs=" + songs +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
|
@ -80,24 +73,14 @@ public class Album implements Parcelable {
|
|||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(this.id);
|
||||
dest.writeInt(this.artistId);
|
||||
dest.writeString(this.title);
|
||||
dest.writeString(this.artistName);
|
||||
dest.writeInt(this.songCount);
|
||||
dest.writeInt(this.year);
|
||||
dest.writeTypedList(songs);
|
||||
}
|
||||
|
||||
protected Album(Parcel in) {
|
||||
this.id = in.readInt();
|
||||
this.artistId = in.readInt();
|
||||
this.title = in.readString();
|
||||
this.artistName = in.readString();
|
||||
this.songCount = in.readInt();
|
||||
this.year = in.readInt();
|
||||
this.songs = in.createTypedArrayList(Song.CREATOR);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<Album> CREATOR = new Parcelable.Creator<Album>() {
|
||||
public static final Creator<Album> CREATOR = new Creator<Album>() {
|
||||
public Album createFromParcel(Parcel source) {
|
||||
return new Album(source);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,8 @@ public class PlaylistSong extends Song {
|
|||
public final int playlistId;
|
||||
public final int idInPlayList;
|
||||
|
||||
public PlaylistSong(final int id, final int albumId, final int artistId, final String title, final String artistName,
|
||||
final String albumName, final long duration, final int trackNumber, final String data, final int playlistId, final int idInPlayList) {
|
||||
super(id, albumId, artistId, title, artistName, albumName, duration, trackNumber, data);
|
||||
public PlaylistSong(int id, String title, int trackNumber, int year, long duration, String data, int dateModified, int albumId, String albumName, int artistId, String artistName, final int playlistId, final int idInPlayList) {
|
||||
super(id, title, trackNumber, year, duration, data, dateModified, albumId, albumName, artistId, artistName);
|
||||
this.playlistId = playlistId;
|
||||
this.idInPlayList = idInPlayList;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,38 +8,43 @@ import android.os.Parcelable;
|
|||
*/
|
||||
public class Song implements Parcelable {
|
||||
public final int id;
|
||||
public final int albumId;
|
||||
public final int artistId;
|
||||
public final String title;
|
||||
public final String artistName;
|
||||
public final String albumName;
|
||||
public final long duration;
|
||||
public final int trackNumber;
|
||||
public final int year;
|
||||
public final long duration;
|
||||
public final String data;
|
||||
public final long dateModified;
|
||||
public final int albumId;
|
||||
public final String albumName;
|
||||
public final int artistId;
|
||||
public final String artistName;
|
||||
|
||||
public Song(final int id, final int albumId, final int artistId, final String title, final String artistName,
|
||||
final String albumName, final long duration, final int trackNumber, final String data) {
|
||||
public Song(int id, String title, int trackNumber, int year, long duration, String data, long dateModified, int albumId, String albumName, int artistId, String artistName) {
|
||||
this.id = id;
|
||||
this.albumId = albumId;
|
||||
this.artistId = artistId;
|
||||
this.title = title;
|
||||
this.artistName = artistName;
|
||||
this.albumName = albumName;
|
||||
this.duration = duration;
|
||||
this.trackNumber = trackNumber;
|
||||
this.year = year;
|
||||
this.duration = duration;
|
||||
this.data = data;
|
||||
this.dateModified = dateModified;
|
||||
this.albumId = albumId;
|
||||
this.albumName = albumName;
|
||||
this.artistId = artistId;
|
||||
this.artistName = artistName;
|
||||
}
|
||||
|
||||
public Song() {
|
||||
this.id = -1;
|
||||
this.albumId = -1;
|
||||
this.artistId = -1;
|
||||
this.title = "";
|
||||
this.artistName = "";
|
||||
this.albumName = "";
|
||||
this.duration = -1;
|
||||
this.trackNumber = -1;
|
||||
this.year = -1;
|
||||
this.duration = -1;
|
||||
this.data = "";
|
||||
this.dateModified = -1;
|
||||
this.albumId = -1;
|
||||
this.albumName = "";
|
||||
this.artistId = -1;
|
||||
this.artistName = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -50,30 +55,33 @@ public class Song implements Parcelable {
|
|||
Song song = (Song) o;
|
||||
|
||||
if (id != song.id) return false;
|
||||
if (trackNumber != song.trackNumber) return false;
|
||||
if (year != song.year) return false;
|
||||
if (duration != song.duration) return false;
|
||||
if (dateModified != song.dateModified) return false;
|
||||
if (albumId != song.albumId) return false;
|
||||
if (artistId != song.artistId) return false;
|
||||
if (duration != song.duration) return false;
|
||||
if (trackNumber != song.trackNumber) return false;
|
||||
if (title != null ? !title.equals(song.title) : song.title != null) return false;
|
||||
if (artistName != null ? !artistName.equals(song.artistName) : song.artistName != null)
|
||||
return false;
|
||||
if (data != null ? !data.equals(song.data) : song.data != null) return false;
|
||||
if (albumName != null ? !albumName.equals(song.albumName) : song.albumName != null)
|
||||
return false;
|
||||
return data != null ? data.equals(song.data) : song.data == null;
|
||||
return artistName != null ? artistName.equals(song.artistName) : song.artistName == null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id;
|
||||
result = 31 * result + albumId;
|
||||
result = 31 * result + artistId;
|
||||
result = 31 * result + (title != null ? title.hashCode() : 0);
|
||||
result = 31 * result + (artistName != null ? artistName.hashCode() : 0);
|
||||
result = 31 * result + (albumName != null ? albumName.hashCode() : 0);
|
||||
result = 31 * result + (int) (duration ^ (duration >>> 32));
|
||||
result = 31 * result + trackNumber;
|
||||
result = 31 * result + year;
|
||||
result = 31 * result + (int) (duration ^ (duration >>> 32));
|
||||
result = 31 * result + (data != null ? data.hashCode() : 0);
|
||||
result = 31 * result + (int) (dateModified ^ (dateModified >>> 32));
|
||||
result = 31 * result + albumId;
|
||||
result = 31 * result + (albumName != null ? albumName.hashCode() : 0);
|
||||
result = 31 * result + artistId;
|
||||
result = 31 * result + (artistName != null ? artistName.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -81,14 +89,16 @@ public class Song implements Parcelable {
|
|||
public String toString() {
|
||||
return "Song{" +
|
||||
"id=" + id +
|
||||
", albumId=" + albumId +
|
||||
", artistId=" + artistId +
|
||||
", title='" + title + '\'' +
|
||||
", artistName='" + artistName + '\'' +
|
||||
", albumName='" + albumName + '\'' +
|
||||
", duration=" + duration +
|
||||
", trackNumber=" + trackNumber +
|
||||
", year=" + year +
|
||||
", duration=" + duration +
|
||||
", data='" + data + '\'' +
|
||||
", dateModified=" + dateModified +
|
||||
", albumId=" + albumId +
|
||||
", albumName='" + albumName + '\'' +
|
||||
", artistId=" + artistId +
|
||||
", artistName='" + artistName + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
|
@ -101,26 +111,30 @@ public class Song implements Parcelable {
|
|||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(this.id);
|
||||
dest.writeInt(this.albumId);
|
||||
dest.writeInt(this.artistId);
|
||||
dest.writeString(this.title);
|
||||
dest.writeString(this.artistName);
|
||||
dest.writeString(this.albumName);
|
||||
dest.writeLong(this.duration);
|
||||
dest.writeInt(this.trackNumber);
|
||||
dest.writeInt(this.year);
|
||||
dest.writeLong(this.duration);
|
||||
dest.writeString(this.data);
|
||||
dest.writeLong(this.dateModified);
|
||||
dest.writeInt(this.albumId);
|
||||
dest.writeString(this.albumName);
|
||||
dest.writeInt(this.artistId);
|
||||
dest.writeString(this.artistName);
|
||||
}
|
||||
|
||||
protected Song(Parcel in) {
|
||||
this.id = in.readInt();
|
||||
this.albumId = in.readInt();
|
||||
this.artistId = in.readInt();
|
||||
this.title = in.readString();
|
||||
this.artistName = in.readString();
|
||||
this.albumName = in.readString();
|
||||
this.duration = in.readLong();
|
||||
this.trackNumber = in.readInt();
|
||||
this.year = in.readInt();
|
||||
this.duration = in.readLong();
|
||||
this.data = in.readString();
|
||||
this.dateModified = in.readLong();
|
||||
this.albumId = in.readInt();
|
||||
this.albumName = in.readString();
|
||||
this.artistId = in.readInt();
|
||||
this.artistName = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<Song> CREATOR = new Creator<Song>() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue