fmobj comparable, objects in objlist get sorted

This commit is contained in:
aj 2018-04-05 00:10:58 -07:00
parent e90f12f6dd
commit 4c18bd07a2
6 changed files with 116 additions and 92 deletions

View File

@ -9,17 +9,17 @@ import sarsoo.fmframework.util.Reference;
public class Driver { public class Driver {
public static void main(String[] args) { public static void main(String[] args) {
String username = JOptionPane.showInputDialog(null, "Enter User-Name"); // String username = JOptionPane.showInputDialog(null, "Enter User-Name");
// System.out.println(username); // System.out.println(username);
if (username != null) { // if (username != null) {
// Reference.setUserName("sarsoo"); Reference.setUserName("sarsoo");
Reference.setUserName(username); // Reference.setUserName(username);
// System.out.println(Getter.getScrobbles(Reference.getUserName())); // System.out.println(Getter.getScrobbles(Reference.getUserName()));
MainMenu main = new MainMenu(); MainMenu main = new MainMenu();
main.setVisible(true); main.setVisible(true);
} // }
} }
} }

View File

@ -7,6 +7,7 @@ import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Collections;
import java.util.Locale; import java.util.Locale;
import javax.swing.JButton; import javax.swing.JButton;
@ -64,6 +65,9 @@ public class FMObjListView extends JFrame {
add(headerLabels); add(headerLabels);
Collections.sort(objects);
Collections.reverse(objects);
int counter; int counter;
for (counter = 0; counter < objects.size(); counter++) { for (counter = 0; counter < objects.size(); counter++) {
FMObj fmObj = objects.get(counter); FMObj fmObj = objects.get(counter);

View File

@ -9,56 +9,61 @@ import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.parser.Parser; import sarsoo.fmframework.parser.Parser;
import sarsoo.fmframework.util.Reference; import sarsoo.fmframework.util.Reference;
public class Album extends FMObj{ public class Album extends FMObj {
protected Artist artist; protected Artist artist;
protected ArrayList<Tag> tagList; protected ArrayList<Tag> tagList;
// protected ArrayList<Track> trackList; // protected ArrayList<Track> trackList;
public Album(String name, String artist) { public Album(String name, String artist) {
super(name, null, null, 0, 0, 0, null); super(name, null, null, 0, 0, 0, null);
this.artist = Artist.getArtist(artist, Reference.getUserName()); this.artist = Artist.getArtist(artist, Reference.getUserName());
} }
public Album(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount, Wiki wiki) { public Album(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount,
Wiki wiki) {
super(name, url, mbid, listeners, playCount, userPlayCount, wiki); super(name, url, mbid, listeners, playCount, userPlayCount, wiki);
this.artist = artist; this.artist = artist;
} }
public Artist getArtist() { public Artist getArtist() {
return artist; return artist;
} }
public static Album getAlbum(String name, String artist, String username) { public static Album getAlbum(String name, String artist, String username) {
String url = Network.getAlbumInfoUrl(name, artist, username); String url = Network.getAlbumInfoUrl(name, artist, username);
Document response = Network.getResponse(url); Document response = Network.getResponse(url);
Album album = Parser.parseAlbum(response); if (response != null) {
return album; Album album = Parser.parseAlbum(response);
return album;
}
return null;
} }
// public Track getTrack(int track) { // public Track getTrack(int track) {
// return trackList.get(track); // return trackList.get(track);
// } // }
// //
// public ArrayList<Track> getTrackList(){ // public ArrayList<Track> getTrackList(){
// return trackList; // return trackList;
// } // }
// //
// public void addTrack(Track track) { // public void addTrack(Track track) {
// trackList.add(track); // trackList.add(track);
// } // }
// //
public ArrayList<Tag> getTags(){ public ArrayList<Tag> getTags() {
return tagList; return tagList;
} }
public String getRymURL() { public String getRymURL() {
return "https://rateyourmusic.com/release/album/" + getArtist().getName().replaceAll(" ", "_").toLowerCase() + "/" + getName().replaceAll(" ", "_").toLowerCase(); return "https://rateyourmusic.com/release/album/" + getArtist().getName().replaceAll(" ", "_").toLowerCase()
+ "/" + getName().replaceAll(" ", "_").toLowerCase();
} }
@Override @Override
public String getMusicBrainzURL() { public String getMusicBrainzURL() {
return "https://musicbrainz.org/release/" + mbid; return "https://musicbrainz.org/release/" + mbid;
} }
@Override @Override
@ -69,18 +74,19 @@ public class Album extends FMObj{
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(obj.getClass() != this.getClass()) return false; if (obj.getClass() != this.getClass())
return false;
Album album = (Album)obj;
if(getName() == album.getName()) Album album = (Album) obj;
if(getArtist().equals(album.getArtist())) if (getName() == album.getName())
if (getArtist().equals(album.getArtist()))
return true; return true;
return false; return false;
} }
public String toString() { public String toString() {
return name + " - " + artist.getName(); return name + " - " + artist.getName();
} }
} }

View File

@ -8,71 +8,74 @@ import sarsoo.fmframework.net.Network;
//import sarsoo.fmframework.net.TestCall; //import sarsoo.fmframework.net.TestCall;
import sarsoo.fmframework.parser.Parser; import sarsoo.fmframework.parser.Parser;
public class Artist extends FMObj{ public class Artist extends FMObj {
// protected boolean streamable; // protected boolean streamable;
// protected boolean onTour; // protected boolean onTour;
protected ArrayList<Album> albums; protected ArrayList<Album> albums;
protected ArrayList<Artist> similarArtists; protected ArrayList<Artist> similarArtists;
protected ArrayList<Tag> tagList; protected ArrayList<Tag> tagList;
public Artist(String name) { public Artist(String name) {
super(name, null, null, 0, 0, 0, null); super(name, null, null, 0, 0, 0, null);
} }
public Artist(String name, String url, String mbid, int listeners, int playCount, int userPlayCount, Wiki wiki) { public Artist(String name, String url, String mbid, int listeners, int playCount, int userPlayCount, Wiki wiki) {
super(name, url, mbid, listeners, playCount, userPlayCount, wiki); super(name, url, mbid, listeners, playCount, userPlayCount, wiki);
} }
public static Artist getArtist(String name, String username) { public static Artist getArtist(String name, String username) {
String url = Network.getArtistInfoUrl(name, username); String url = Network.getArtistInfoUrl(name, username);
// TestCall.test(url); // TestCall.test(url);
Document response = Network.getResponse(url); Document response = Network.getResponse(url);
Artist artist = Parser.parseArtist(response); if (response != null) {
return artist; Artist artist = Parser.parseArtist(response);
return artist;
}
return null;
} }
public static Artist getArtistByMbid(String mbid, String username) { public static Artist getArtistByMbid(String mbid, String username) {
String url = Network.getArtistInfoMbidUrl(mbid, username); String url = Network.getArtistInfoMbidUrl(mbid, username);
Document response = Network.getResponse(url); Document response = Network.getResponse(url);
Artist artist = Parser.parseArtist(response); Artist artist = Parser.parseArtist(response);
return artist; return artist;
} }
public ArrayList<Album> getAlbum(){ public ArrayList<Album> getAlbum() {
return albums; return albums;
} }
public ArrayList<Artist> getSimilarArtists(){ public ArrayList<Artist> getSimilarArtists() {
return similarArtists; return similarArtists;
} }
public ArrayList<Tag> getTags(){ public ArrayList<Tag> getTags() {
return tagList; return tagList;
} }
@Override @Override
public String getMusicBrainzURL() { public String getMusicBrainzURL() {
return "https://musicbrainz.org/artist/" + mbid; return "https://musicbrainz.org/artist/" + mbid;
} }
public String getRymURL() { public String getRymURL() {
return "https://rateyourmusic.com/artist/" + getName().replaceAll(" ", "_").toLowerCase(); return "https://rateyourmusic.com/artist/" + getName().replaceAll(" ", "_").toLowerCase();
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(obj.getClass() != this.getClass()) return false; if (obj.getClass() != this.getClass())
return false;
Artist artist = (Artist)obj;
if(getName() == artist.getName()) Artist artist = (Artist) obj;
return true; if (getName() == artist.getName())
return true;
return false; return false;
} }
public String toString() { public String toString() {
return name; return name;
} }
} }

View File

@ -2,7 +2,7 @@ package sarsoo.fmframework.music;
import sarsoo.fmframework.gui.FMObjView; import sarsoo.fmframework.gui.FMObjView;
public abstract class FMObj { public abstract class FMObj implements Comparable<FMObj>{
protected String name; protected String name;
protected String url; protected String url;
@ -33,6 +33,12 @@ public abstract class FMObj {
return name; return name;
} }
@Override
public int compareTo(FMObj obj) {
return userPlayCount - obj.getUserPlayCount();
}
public String getName() { public String getName() {
return name; return name;
} }

View File

@ -9,7 +9,7 @@ import sarsoo.fmframework.net.Network;
//import sarsoo.fmframework.net.TestCall; //import sarsoo.fmframework.net.TestCall;
import sarsoo.fmframework.parser.Parser; import sarsoo.fmframework.parser.Parser;
public class Track extends FMObj{ public class Track extends FMObj {
protected Album album; protected Album album;
protected Artist artist; protected Artist artist;
protected int trackNumber; protected int trackNumber;
@ -17,59 +17,64 @@ public class Track extends FMObj{
protected boolean streamable; protected boolean streamable;
protected boolean isLoved; protected boolean isLoved;
protected ArrayList<Tag> tagList; protected ArrayList<Tag> tagList;
public Track(String name, String artist) { public Track(String name, String artist) {
super(name, null, null, 0, 0, 0, null); super(name, null, null, 0, 0, 0, null);
this.artist = new Artist(artist); this.artist = new Artist(artist);
} }
public Track(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount, Wiki wiki) { public Track(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount,
Wiki wiki) {
super(name, url, mbid, listeners, playCount, userPlayCount, wiki); super(name, url, mbid, listeners, playCount, userPlayCount, wiki);
this.artist = artist; this.artist = artist;
} }
public static Track getTrack(String name, String artist, String username) { public static Track getTrack(String name, String artist, String username) {
String url = Network.getTrackInfoUrl(name, artist, username); String url = Network.getTrackInfoUrl(name, artist, username);
// TestCall.test(url); // TestCall.test(url);
Document response = Network.getResponse(url); Document response = Network.getResponse(url);
Track track = Parser.parseTrack(response); if (response != null) {
return track; Track track = Parser.parseTrack(response);
return track;
}
return null;
} }
public Artist getArtist() { public Artist getArtist() {
return artist; return artist;
} }
public ArrayList<Tag> getTags(){ public ArrayList<Tag> getTags() {
return tagList; return tagList;
} }
public void setAlbum(Album album) { public void setAlbum(Album album) {
this.album = album; this.album = album;
} }
@Override @Override
public String getMusicBrainzURL() { public String getMusicBrainzURL() {
return "https://musicbrainz.org/artist/" + mbid; return "https://musicbrainz.org/artist/" + mbid;
} }
public String getLyricsURL() { public String getLyricsURL() {
return Network.getLyricsUrl(name, artist.getName()); return Network.getLyricsUrl(name, artist.getName());
} }
public Album getAlbum() { public Album getAlbum() {
return album; return album;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(obj.getClass() != this.getClass()) return false; if (obj.getClass() != this.getClass())
return false;
Track track = (Track)obj;
if(getName() == track.getName()) Track track = (Track) obj;
if(getArtist().equals(track.getArtist())) if (getName() == track.getName())
if (getArtist().equals(track.getArtist()))
return true; return true;
return false; return false;
} }
@ -78,9 +83,9 @@ public class Track extends FMObj{
TrackView view = new TrackView(this); TrackView view = new TrackView(this);
view.setVisible(true); view.setVisible(true);
} }
public String toString() { public String toString() {
return name + " - " + artist.getName(); return name + " - " + artist.getName();
} }
} }