Refactor Song model to Media model

This commit is contained in:
CappielloAntonio 2022-02-07 17:37:25 +01:00
parent 4713ff3c90
commit c3c214a6e2

View file

@ -6,17 +6,15 @@ import android.os.Parcelable;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.cappielloantonio.play.subsonic.models.Child; import com.cappielloantonio.play.subsonic.models.Child;
import com.cappielloantonio.play.subsonic.models.PodcastEpisode;
import java.util.Date;
import java.util.UUID;
public class Media implements Parcelable { public class Media implements Parcelable {
private static final String TAG = "Media"; private static final String TAG = "Media";
public static String MEDIA_TYPE_MUSIC = "music"; public static final String MEDIA_TYPE_MUSIC = "music";
public static String MEDIA_TYPE_PODCAST = "podcast"; public static final String MEDIA_TYPE_PODCAST = "podcast";
public static String MEDIA_TYPE_AUDIOBOOK = "audiobook"; public static final String MEDIA_TYPE_AUDIOBOOK = "audiobook";
public static String MEDIA_TYPE_VIDEO = "video"; public static final String MEDIA_TYPE_VIDEO = "video";
public static final String RECENTLY_PLAYED = "RECENTLY_PLAYED"; public static final String RECENTLY_PLAYED = "RECENTLY_PLAYED";
public static final String MOST_PLAYED = "MOST_PLAYED"; public static final String MOST_PLAYED = "MOST_PLAYED";
@ -31,17 +29,20 @@ public class Media implements Parcelable {
private String id; private String id;
private String title; private String title;
private int trackNumber; private String channelId;
private int discNumber; private String streamId;
private int year;
private long duration;
private String albumId; private String albumId;
private String albumName; private String albumName;
private String artistId; private String artistId;
private String artistName; private String artistName;
private String primary; private String coverArtId;
private String blurHash; private int trackNumber;
private boolean favorite; private int discNumber;
private int year;
private long duration;
private String description;
private String status;
private boolean starred;
private String path; private String path;
private long size; private long size;
private String container; private String container;
@ -51,16 +52,7 @@ public class Media implements Parcelable {
private int playCount; private int playCount;
private long lastPlay; private long lastPlay;
private int rating; private int rating;
private long publishDate;
private String streamId;
private String channelId;
private String description;
private String status;
private Date publishDate;
public Media() {
this.id = UUID.randomUUID().toString();
}
public Media(Child child) { public Media(Child child) {
this.id = child.getId(); this.id = child.getId();
@ -73,8 +65,8 @@ public class Media implements Parcelable {
this.albumName = child.getAlbum(); this.albumName = child.getAlbum();
this.artistId = child.getArtistId(); this.artistId = child.getArtistId();
this.artistName = child.getArtist(); this.artistName = child.getArtist();
this.primary = child.getCoverArtId(); this.coverArtId = child.getCoverArtId();
this.favorite = child.getStarred() != null; this.starred = child.getStarred() != null;
this.path = child.getPath(); this.path = child.getPath();
this.size = child.getSize(); this.size = child.getSize();
this.container = child.getContentType(); this.container = child.getContentType();
@ -83,17 +75,40 @@ public class Media implements Parcelable {
this.playCount = 0; this.playCount = 0;
this.lastPlay = 0; this.lastPlay = 0;
this.rating = child.getUserRating() != null ? child.getUserRating() : 0; this.rating = child.getUserRating() != null ? child.getUserRating() : 0;
this.type = child.getType();
}
public Media(PodcastEpisode podcastEpisode) {
this.id = podcastEpisode.getId();
this.title = podcastEpisode.getTitle();
this.albumName = podcastEpisode.getAlbum();
this.artistName = podcastEpisode.getArtist();
this.trackNumber = podcastEpisode.getTrack() != null ? podcastEpisode.getTrack() : 0;
this.year = podcastEpisode.getYear();
this.coverArtId = podcastEpisode.getCoverArtId();
this.duration = podcastEpisode.getDuration();
this.starred = podcastEpisode.getStarred() != null;
this.streamId = podcastEpisode.getStreamId();
this.channelId = podcastEpisode.getChannelId();
this.description = podcastEpisode.getDescription();
this.status = podcastEpisode.getStatus();
this.publishDate = podcastEpisode.getPublishDate().getTime();
this.type = podcastEpisode.getType();
} }
public Media(Queue queue) { public Media(Queue queue) {
this.id = queue.getSongID(); this.id = queue.getId();
this.title = queue.getTitle(); this.title = queue.getTitle();
this.albumId = queue.getAlbumId(); this.albumId = queue.getAlbumId();
this.albumName = queue.getAlbumName(); this.albumName = queue.getAlbumName();
this.artistId = queue.getArtistId(); this.artistId = queue.getArtistId();
this.artistName = queue.getArtistName(); this.artistName = queue.getArtistName();
this.primary = queue.getPrimary(); this.coverArtId = queue.getCoverArtId();
this.duration = queue.getDuration(); this.duration = queue.getDuration();
this.streamId = queue.getStreamId();
this.channelId = queue.getChannelId();
this.publishDate = queue.getPublishingDate();
this.type = queue.getType();
} }
public Media(Download download) { public Media(Download download) {
@ -104,7 +119,7 @@ public class Media implements Parcelable {
this.artistId = download.getArtistId(); this.artistId = download.getArtistId();
this.artistName = download.getArtistName(); this.artistName = download.getArtistName();
this.trackNumber = download.getTrackNumber(); this.trackNumber = download.getTrackNumber();
this.primary = download.getPrimary(); this.coverArtId = download.getPrimary();
this.duration = download.getDuration(); this.duration = download.getDuration();
} }
@ -112,162 +127,194 @@ public class Media implements Parcelable {
return id; return id;
} }
public String getTitle() {
return title;
}
public int getTrackNumber() {
return trackNumber;
}
public int getDiscNumber() {
return discNumber;
}
public int getYear() {
return year;
}
public long getDuration() {
return duration;
}
public String getAlbumId() {
return albumId;
}
public String getAlbumName() {
return albumName;
}
public String getArtistId() {
return artistId;
}
public String getArtistName() {
return artistName;
}
public String getPrimary() {
return primary;
}
public String getBlurHash() {
return blurHash;
}
public boolean isFavorite() {
return favorite;
}
public String getPath() {
return path;
}
public long getSize() {
return size;
}
public String getContainer() {
return container;
}
public int getBitRate() {
return bitRate;
}
public long getAdded() {
return added;
}
public int getPlayCount() {
return playCount;
}
public long getLastPlay() {
return lastPlay;
}
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public String getTitle() {
return title;
}
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }
public void setTrackNumber(int trackNumber) { public String getChannelId() {
this.trackNumber = trackNumber; return channelId;
} }
public void setDiscNumber(int discNumber) { public void setChannelId(String channelId) {
this.discNumber = discNumber; this.channelId = channelId;
} }
public void setYear(int year) { public String getStreamId() {
this.year = year; return streamId;
} }
public void setDuration(long duration) { public void setStreamId(String streamId) {
this.duration = duration; this.streamId = streamId;
}
public String getAlbumId() {
return albumId;
} }
public void setAlbumId(String albumId) { public void setAlbumId(String albumId) {
this.albumId = albumId; this.albumId = albumId;
} }
public String getAlbumName() {
return albumName;
}
public void setAlbumName(String albumName) { public void setAlbumName(String albumName) {
this.albumName = albumName; this.albumName = albumName;
} }
public String getArtistId() {
return artistId;
}
public void setArtistId(String artistId) { public void setArtistId(String artistId) {
this.artistId = artistId; this.artistId = artistId;
} }
public String getArtistName() {
return artistName;
}
public void setArtistName(String artistName) { public void setArtistName(String artistName) {
this.artistName = artistName; this.artistName = artistName;
} }
public void setPrimary(String primary) { public String getCoverArtId() {
this.primary = primary; return coverArtId;
} }
public void setBlurHash(String blurHash) { public void setCoverArtId(String coverArtId) {
this.blurHash = blurHash; this.coverArtId = coverArtId;
} }
public void setFavorite(boolean favorite) { public int getTrackNumber() {
this.favorite = favorite; return trackNumber;
}
public void setTrackNumber(int trackNumber) {
this.trackNumber = trackNumber;
}
public int getDiscNumber() {
return discNumber;
}
public void setDiscNumber(int discNumber) {
this.discNumber = discNumber;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public long getDuration() {
return duration;
}
public void setDuration(long duration) {
this.duration = duration;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public boolean isStarred() {
return starred;
}
public void setStarred(boolean starred) {
this.starred = starred;
}
public String getPath() {
return path;
} }
public void setPath(String path) { public void setPath(String path) {
this.path = path; this.path = path;
} }
public long getSize() {
return size;
}
public void setSize(long size) { public void setSize(long size) {
this.size = size; this.size = size;
} }
public String getContainer() {
return container;
}
public void setContainer(String container) { public void setContainer(String container) {
this.container = container; this.container = container;
} }
public int getBitRate() {
return bitRate;
}
public void setBitRate(int bitRate) { public void setBitRate(int bitRate) {
this.bitRate = bitRate; this.bitRate = bitRate;
} }
public long getAdded() {
return added;
}
public void setAdded(long added) { public void setAdded(long added) {
this.added = added; this.added = added;
} }
public void setLastPlay(long lastPlay) { public String getType() {
this.lastPlay = lastPlay; return type;
}
public void setType(String type) {
this.type = type;
}
public int getPlayCount() {
return playCount;
} }
public void setPlayCount(int playCount) { public void setPlayCount(int playCount) {
this.playCount = playCount; this.playCount = playCount;
} }
public long getLastPlay() {
return lastPlay;
}
public void setLastPlay(long lastPlay) {
this.lastPlay = lastPlay;
}
public int getRating() { public int getRating() {
return rating; return rating;
} }
@ -276,6 +323,14 @@ public class Media implements Parcelable {
this.rating = rating; this.rating = rating;
} }
public long getPublishDate() {
return publishDate;
}
public void setPublishDate(long publishDate) {
this.publishDate = publishDate;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@ -305,47 +360,59 @@ public class Media implements Parcelable {
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.id); dest.writeString(this.id);
dest.writeString(this.title); dest.writeString(this.title);
dest.writeInt(this.trackNumber); dest.writeString(this.channelId);
dest.writeInt(this.discNumber); dest.writeString(this.streamId);
dest.writeInt(this.year);
dest.writeLong(this.duration);
dest.writeString(this.albumId); dest.writeString(this.albumId);
dest.writeString(this.albumName); dest.writeString(this.albumName);
dest.writeString(this.artistId); dest.writeString(this.artistId);
dest.writeString(this.artistName); dest.writeString(this.artistName);
dest.writeString(this.primary); dest.writeString(this.coverArtId);
dest.writeString(Boolean.toString(favorite)); dest.writeInt(this.trackNumber);
dest.writeString(this.blurHash); dest.writeInt(this.discNumber);
dest.writeInt(this.year);
dest.writeLong(this.duration);
dest.writeString(this.description);
dest.writeString(this.status);
dest.writeString(Boolean.toString(starred));
dest.writeString(this.path); dest.writeString(this.path);
dest.writeLong(this.size); dest.writeLong(this.size);
dest.writeString(this.container); dest.writeString(this.container);
dest.writeInt(this.bitRate); dest.writeInt(this.bitRate);
dest.writeLong(this.added); dest.writeLong(this.added);
dest.writeString(this.type);
dest.writeInt(this.playCount); dest.writeInt(this.playCount);
dest.writeLong(this.lastPlay); dest.writeLong(this.lastPlay);
dest.writeInt(this.rating);
dest.writeLong(this.publishDate);
} }
protected Media(Parcel in) { protected Media(Parcel in) {
this.id = in.readString(); this.id = in.readString();
this.title = in.readString(); this.title = in.readString();
this.trackNumber = in.readInt(); this.channelId = in.readString();
this.discNumber = in.readInt(); this.streamId = in.readString();
this.year = in.readInt();
this.duration = in.readLong();
this.albumId = in.readString(); this.albumId = in.readString();
this.albumName = in.readString(); this.albumName = in.readString();
this.artistId = in.readString(); this.artistId = in.readString();
this.artistName = in.readString(); this.artistName = in.readString();
this.primary = in.readString(); this.coverArtId = in.readString();
this.favorite = Boolean.parseBoolean(in.readString()); this.trackNumber = in.readInt();
this.blurHash = in.readString(); this.discNumber = in.readInt();
this.year = in.readInt();
this.duration = in.readLong();
this.description = in.readString();
this.status = in.readString();
this.starred = Boolean.parseBoolean(in.readString());
this.path = in.readString(); this.path = in.readString();
this.size = in.readLong(); this.size = in.readLong();
this.container = in.readString(); this.container = in.readString();
this.bitRate = in.readInt(); this.bitRate = in.readInt();
this.added = in.readLong(); this.added = in.readLong();
this.type = in.readString();
this.playCount = in.readInt(); this.playCount = in.readInt();
this.lastPlay = in.readLong(); this.lastPlay = in.readLong();
this.rating = in.readInt();
this.publishDate = in.readLong();
} }
public static final Creator<Media> CREATOR = new Creator<Media>() { public static final Creator<Media> CREATOR = new Creator<Media>() {