From d4a7120df22870a77afb2008bc318c88e80deae0 Mon Sep 17 00:00:00 2001 From: aj Date: Sun, 8 Apr 2018 22:09:17 -0700 Subject: [PATCH] added time play ratio, added wrapping and scrollbar to wiki view --- .../src/sarsoo/fmframework/gui/AlbumView.java | 121 +++++++++------- .../sarsoo/fmframework/gui/FMObjListView.java | 31 +++- .../src/sarsoo/fmframework/gui/FMObjView.java | 53 ++++--- .../src/sarsoo/fmframework/gui/MainMenu.java | 1 + .../sarsoo/fmframework/gui/TagMenuView.java | 2 +- .../src/sarsoo/fmframework/gui/TrackView.java | 21 ++- .../src/sarsoo/fmframework/gui/WikiView.java | 132 ++---------------- .../src/sarsoo/fmframework/music/FMObj.java | 5 + .../sarsoo/fmframework/test/NetworkTest.java | 3 +- .../src/sarsoo/fmframework/util/Maths.java | 40 ++++-- 10 files changed, 196 insertions(+), 213 deletions(-) diff --git a/fmframework/src/sarsoo/fmframework/gui/AlbumView.java b/fmframework/src/sarsoo/fmframework/gui/AlbumView.java index 0ed155d..d3f844c 100644 --- a/fmframework/src/sarsoo/fmframework/gui/AlbumView.java +++ b/fmframework/src/sarsoo/fmframework/gui/AlbumView.java @@ -31,6 +31,7 @@ public class AlbumView extends JFrame { JLabel listeners = new JLabel(); JLabel playCount = new JLabel(); JLabel userPlayCount = new JLabel(); + JLabel timePlayRatio = new JLabel(); JButton open = new JButton("View Online"); JButton viewArtist = new JButton("View Artist"); @@ -41,19 +42,19 @@ public class AlbumView extends JFrame { public AlbumView(Album album) { super(album.getName()); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setLayout(new GridLayout(6, 1)); + setLayout(new GridLayout(7, 1)); setSize(300, 300); setResizable(false); buttons.setLayout(new FlowLayout()); buttons2.setLayout(new FlowLayout()); -// System.out.println(album.getName()); -// if (album.getTrackList() != null) -// buttons2.setLayout(new GridLayout(album.getTrackList().size(), 1)); + // System.out.println(album.getName()); + // if (album.getTrackList() != null) + // buttons2.setLayout(new GridLayout(album.getTrackList().size(), 1)); buttons.add(open); -// buttons2.add(viewArtist); - + // buttons2.add(viewArtist); + if (album.getWiki() != null) buttons.add(viewWiki); if (album.getMbid() != null) @@ -71,24 +72,38 @@ public class AlbumView extends JFrame { artist.setText(album.getArtist().getName()); artist.setHorizontalAlignment(SwingConstants.CENTER); artist.setFont(sub); - + listeners.setText(numberFormat.format(album.getListeners()) + " Listeners"); listeners.setHorizontalAlignment(SwingConstants.CENTER); playCount.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles"); playCount.setHorizontalAlignment(SwingConstants.CENTER); - - userPlayCount.setText(numberFormat.format(album.getUserPlayCount()) + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName()))); + + userPlayCount.setText(numberFormat.format(album.getUserPlayCount()) + + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName()))); userPlayCount.setHorizontalAlignment(SwingConstants.CENTER); userPlayCount.setFont(sub); + double ratio = album.getTimeListenRatio(); + +// int ratioRound = (int) Math.round(ratio); +// int oneOverRatioRound = (int) Math.round(1/ratio); + if (ratio > 1) { + timePlayRatio.setText(String.format("listen every %.2f days", ratio)); + } else if (ratio == 1) { + timePlayRatio.setText("listen every day"); + } else { + timePlayRatio.setText(String.format("%.2f times a day", 1/ratio)); + } + timePlayRatio.setHorizontalAlignment(SwingConstants.CENTER); + timePlayRatio.setFont(sub); + artist.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { album.getArtist().view(); } }); - - + open.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Network.openURL(album.getUrl()); @@ -117,55 +132,57 @@ public class AlbumView extends JFrame { } }); -// if (album.getTrackList() != null) { -// int counter; -// ArrayList trackList = album.getTrackList(); -// for (counter = 0; counter < trackList.size(); counter++) { -// Track track = trackList.get(counter); -// JLabel name = new JLabel(track.getName()); -// -// int playCountString = track.getUserPlayCount(); -// -// JLabel userPlays; -// if (playCountString == 0) -// userPlays = new JLabel("0"); -// else -// userPlays = new JLabel(Integer.toString(track.getUserPlayCount())); -// -// JLabel plays = new JLabel(numberFormat.format(track.getPlayCount())); -// JButton openExternal = new JButton("Open Online"); -// openExternal.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent arg0) { -// Network.openURL(track.getUrl()); -// } -// }); -// JButton openInternal = new JButton("Open " + track.getClass().getSimpleName()); -// openInternal.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent arg0) { -// track.view(); -// } -// }); -// JPanel panel = new JPanel(); -// panel.setLayout(new GridLayout(1, 5)); -// panel.add(name); -// panel.add(userPlays); -// panel.add(plays); -// panel.add(openInternal); -// panel.add(openExternal); -// -// trackListPanel.add(panel); -// } -// } + // if (album.getTrackList() != null) { + // int counter; + // ArrayList trackList = album.getTrackList(); + // for (counter = 0; counter < trackList.size(); counter++) { + // Track track = trackList.get(counter); + // JLabel name = new JLabel(track.getName()); + // + // int playCountString = track.getUserPlayCount(); + // + // JLabel userPlays; + // if (playCountString == 0) + // userPlays = new JLabel("0"); + // else + // userPlays = new JLabel(Integer.toString(track.getUserPlayCount())); + // + // JLabel plays = new JLabel(numberFormat.format(track.getPlayCount())); + // JButton openExternal = new JButton("Open Online"); + // openExternal.addActionListener(new ActionListener() { + // public void actionPerformed(ActionEvent arg0) { + // Network.openURL(track.getUrl()); + // } + // }); + // JButton openInternal = new JButton("Open " + + // track.getClass().getSimpleName()); + // openInternal.addActionListener(new ActionListener() { + // public void actionPerformed(ActionEvent arg0) { + // track.view(); + // } + // }); + // JPanel panel = new JPanel(); + // panel.setLayout(new GridLayout(1, 5)); + // panel.add(name); + // panel.add(userPlays); + // panel.add(plays); + // panel.add(openInternal); + // panel.add(openExternal); + // + // trackListPanel.add(panel); + // } + // } add(name); add(artist); add(userPlayCount); + add(timePlayRatio); add(listeners); add(playCount); -// add(trackListPanel); + // add(trackListPanel); add(buttons); -// add(buttons2); + // add(buttons2); pack(); } } diff --git a/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java b/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java index 0fec403..0137016 100644 --- a/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java +++ b/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java @@ -17,6 +17,7 @@ import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; +import javax.swing.JScrollPane; import javax.swing.SwingConstants; import sarsoo.fmframework.music.Album; @@ -32,10 +33,19 @@ public class FMObjListView extends JFrame { public FMObjListView(FMObjList objects, String title) { super(title); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setLayout(new GridLayout(objects.size() + 2, 0)); - setResizable(false); +// setLayout(new GridLayout(objects.size() + 2, 0)); +// setResizable(false); // createMenu(); - + + int limit = 20; + + if(objects.size() > limit) { + setSize(600, 800); + } + + JPanel container = new JPanel(); + container.setLayout(new GridLayout(objects.size() + 2, 0)); + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); Font font = new Font("Arial", Font.PLAIN, 20); Font header = new Font("Arial", Font.BOLD, 16); @@ -63,7 +73,7 @@ public class FMObjListView extends JFrame { headerLabels.add(new JLabel("")); // headerLabels.add(new JLabel("")); - add(headerLabels); + container.add(headerLabels); Collections.sort(objects); Collections.reverse(objects); @@ -112,7 +122,7 @@ public class FMObjListView extends JFrame { // panel.add(openInternal); panel.add(openExternal); - add(panel); + container.add(panel); } JPanel info = new JPanel(); @@ -133,8 +143,15 @@ public class FMObjListView extends JFrame { // } - add(info); - pack(); + container.add(info); + + JScrollPane scroll = new JScrollPane(container); + add(scroll); + + if(objects.size() <= limit) { + pack(); + } + } private void createMenu() { diff --git a/fmframework/src/sarsoo/fmframework/gui/FMObjView.java b/fmframework/src/sarsoo/fmframework/gui/FMObjView.java index 0739849..ff5533f 100644 --- a/fmframework/src/sarsoo/fmframework/gui/FMObjView.java +++ b/fmframework/src/sarsoo/fmframework/gui/FMObjView.java @@ -19,49 +19,65 @@ import sarsoo.fmframework.net.Network; import sarsoo.fmframework.util.Maths; import sarsoo.fmframework.util.Reference; -public class FMObjView extends JFrame{ +public class FMObjView extends JFrame { JPanel buttons = new JPanel(); - + JLabel name = new JLabel(); JLabel listeners = new JLabel(); JLabel playCount = new JLabel(); JLabel userPlayCount = new JLabel(); - + JLabel timePlayRatio = new JLabel(); + JButton viewWiki = new JButton("View Wiki"); JButton open = new JButton("View Online"); JButton musicBrainz = new JButton("Open MusicBrainz"); - + public FMObjView(FMObj obj) { super(obj.toString()); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setLayout(new GridLayout(5,0)); + setLayout(new GridLayout(6, 1)); setSize(300, 300); -// setResizable(false); - + // setResizable(false); + buttons.setLayout(new FlowLayout()); buttons.add(open); if (obj.getWiki() != null) buttons.add(viewWiki); - if(obj.getMbid() != null) + if (obj.getMbid() != null) buttons.add(musicBrainz); - + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); Font title = new Font("Arial", Font.BOLD, 24); Font sub = new Font("Arial", Font.PLAIN, 20); - + name.setText(obj.getName()); name.setHorizontalAlignment(SwingConstants.CENTER); name.setFont(title); - + listeners.setText(numberFormat.format(obj.getListeners()) + " Listeners"); listeners.setHorizontalAlignment(SwingConstants.CENTER); playCount.setText(numberFormat.format(obj.getPlayCount()) + " Total Scrobbles"); playCount.setHorizontalAlignment(SwingConstants.CENTER); - userPlayCount.setText(numberFormat.format(obj.getUserPlayCount()) + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(obj, Reference.getUserName()))); + userPlayCount.setText(numberFormat.format(obj.getUserPlayCount()) + + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(obj, Reference.getUserName()))); userPlayCount.setHorizontalAlignment(SwingConstants.CENTER); userPlayCount.setFont(sub); - + + double ratio = obj.getTimeListenRatio(); + + // int ratioRound = (int) Math.round(ratio); + // int oneOverRatioRound = (int) Math.round(1/ratio); + if (ratio > 1) { + timePlayRatio.setText(String.format("listen every %.2f days", ratio)); + } else if (ratio == 1) { + timePlayRatio.setText("listen every day"); + } else { + timePlayRatio.setText(String.format("%.2f times a day", 1 / ratio)); + } + timePlayRatio.setHorizontalAlignment(SwingConstants.CENTER); + timePlayRatio.setFont(sub); + viewWiki.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { obj.getWiki().view(obj.getName()); @@ -74,18 +90,19 @@ public class FMObjView extends JFrame{ }); musicBrainz.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - Network.openURL(obj.getMusicBrainzURL());; + Network.openURL(obj.getMusicBrainzURL()); + ; } }); add(name); add(userPlayCount); + add(timePlayRatio); add(listeners); add(playCount); -// add(info); + // add(info); add(buttons); - + pack(); } - - + } diff --git a/fmframework/src/sarsoo/fmframework/gui/MainMenu.java b/fmframework/src/sarsoo/fmframework/gui/MainMenu.java index ad1ee70..99d8c21 100644 --- a/fmframework/src/sarsoo/fmframework/gui/MainMenu.java +++ b/fmframework/src/sarsoo/fmframework/gui/MainMenu.java @@ -77,6 +77,7 @@ public class MainMenu extends JFrame { today.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Network.openURL(String.format("https://www.last.fm/user/%s/library?date_preset=LAST_30_DAYS", Reference.getUserName())); + today.setText("Today: " + Integer.toString(Getter.getScrobblesToday(Reference.getUserName()))); } }); add(viewLastTrack); diff --git a/fmframework/src/sarsoo/fmframework/gui/TagMenuView.java b/fmframework/src/sarsoo/fmframework/gui/TagMenuView.java index cf67f3e..a15a75d 100644 --- a/fmframework/src/sarsoo/fmframework/gui/TagMenuView.java +++ b/fmframework/src/sarsoo/fmframework/gui/TagMenuView.java @@ -22,7 +22,7 @@ public class TagMenuView extends JFrame { ArrayList tags = Getter.getUserTags(Reference.getUserName()); setLayout(new GridLayout(4, 4)); - setSize(300, 300); + setSize(700, 700); setResizable(false); int counter; diff --git a/fmframework/src/sarsoo/fmframework/gui/TrackView.java b/fmframework/src/sarsoo/fmframework/gui/TrackView.java index f24a736..8a48382 100644 --- a/fmframework/src/sarsoo/fmframework/gui/TrackView.java +++ b/fmframework/src/sarsoo/fmframework/gui/TrackView.java @@ -34,6 +34,7 @@ public class TrackView extends JFrame { JLabel listeners = new JLabel(); JLabel playCount = new JLabel(); JLabel userPlayCount = new JLabel(); + JLabel timePlayRatio = new JLabel(); JButton open = new JButton("View Online"); JButton viewArtist = new JButton("View Artist"); @@ -46,9 +47,9 @@ public class TrackView extends JFrame { super(track.getName()); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); if (track.getAlbum() != null) { - setLayout(new GridLayout(7, 1)); + setLayout(new GridLayout(8, 1)); } else { - setLayout(new GridLayout(6, 1)); + setLayout(new GridLayout(7, 1)); } // setSize(300, 300); setResizable(false); @@ -74,6 +75,7 @@ public class TrackView extends JFrame { NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); Font title = new Font("Arial", Font.BOLD, 24); Font sub = new Font("Arial", Font.PLAIN, 20); + Font subSub = new Font("Arial", Font.PLAIN, 16); name.setText(track.getName()); name.setHorizontalAlignment(SwingConstants.CENTER); @@ -94,6 +96,20 @@ public class TrackView extends JFrame { artist.setText(track.getArtist().getName()); artist.setHorizontalAlignment(SwingConstants.CENTER); artist.setFont(sub); + + double ratio = track.getTimeListenRatio(); + + // int ratioRound = (int) Math.round(ratio); + // int oneOverRatioRound = (int) Math.round(1/ratio); + if (ratio > 1) { + timePlayRatio.setText(String.format("listen every %.2f days", ratio)); + } else if (ratio == 1) { + timePlayRatio.setText("listen every day"); + } else { + timePlayRatio.setText(String.format("%.2f times a day", 1 / ratio)); + } + timePlayRatio.setHorizontalAlignment(SwingConstants.CENTER); + timePlayRatio.setFont(subSub); listeners.setText(numberFormat.format(track.getListeners()) + " Listeners"); listeners.setHorizontalAlignment(SwingConstants.CENTER); @@ -161,6 +177,7 @@ public class TrackView extends JFrame { add(album); add(artist); add(userPlayCount); + add(timePlayRatio); add(listeners); add(playCount); diff --git a/fmframework/src/sarsoo/fmframework/gui/WikiView.java b/fmframework/src/sarsoo/fmframework/gui/WikiView.java index 91c36e4..74ef25c 100644 --- a/fmframework/src/sarsoo/fmframework/gui/WikiView.java +++ b/fmframework/src/sarsoo/fmframework/gui/WikiView.java @@ -12,6 +12,8 @@ import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; import sarsoo.fmframework.music.Album; import sarsoo.fmframework.music.FMObj; @@ -20,134 +22,22 @@ import sarsoo.fmframework.music.Wiki; import sarsoo.fmframework.net.Network; public class WikiView extends JFrame { -// JPanel date = new JPanel(); -// JPanel content = new JPanel(); -// JPanel trackListPanel = new JPanel(); - -// JLabel dateLabel = new JLabel(); - JLabel contentLabel = new JLabel(); -// JLabel listeners = new JLabel(); -// JLabel playCount = new JLabel(); -// JLabel userPlayCount = new JLabel(); -// -// JButton open = new JButton("View Online"); -// JButton viewArtist = new JButton("View Artist"); -// JButton viewWiki = new JButton("View Wiki"); -// JButton musicBrainz = new JButton("Open MusicBrainz"); -// JButton rym = new JButton("Open RYM"); + JTextArea contentLabel = new JTextArea(); public WikiView(Wiki wiki, String name) { super(name); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setLayout(new GridLayout(1,1)); setSize(500, 700); -// setResizable(false); - -// buttons.setLayout(new FlowLayout()); -// buttons2.setLayout(new FlowLayout()); -//// System.out.println(album.getName()); -//// if (album.getTrackList() != null) -//// buttons2.setLayout(new GridLayout(album.getTrackList().size(), 1)); -// -// buttons.add(open); -// buttons.add(viewArtist); -// if (album.getWiki() != null) -// buttons2.add(viewWiki); -// if (album.getMbid() != null) -// buttons2.add(musicBrainz); -// buttons2.add(rym); -// -// NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); -// -// dateLabel.setText(wiki.getDate()); - contentLabel.setText("" + wiki.getContent() + "

" + wiki.getDate() + ""); - -// artist.setText(album.getArtist().getName()); -// listeners.setText(numberFormat.format(album.getListeners()) + " Listeners"); -// playCount.setText(numberFormat.format(album.getPlayCount()) + " Scrobbles"); -// userPlayCount.setText(numberFormat.format(album.getUserPlayCount()) + " Your Scrobbles"); -// -// open.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent arg0) { -// Network.openURL(album.getUrl()); -// } -// }); -// viewArtist.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent arg0) { -// album.getArtist().view(); -// } -// }); -// viewWiki.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent arg0) { -// album.getWiki().view(); -// } -// }); -// musicBrainz.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent arg0) { -// Network.openURL(album.getMusicBrainzURL()); -// ; -// } -// }); -// rym.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent arg0) { -// Network.openURL(album.getRymURL()); -// ; -// } -// }); - -// if (album.getTrackList() != null) { -// int counter; -// ArrayList trackList = album.getTrackList(); -// for (counter = 0; counter < trackList.size(); counter++) { -// Track track = trackList.get(counter); -// JLabel name = new JLabel(track.getName()); -// -// int playCountString = track.getUserPlayCount(); -// -// JLabel userPlays; -// if (playCountString == 0) -// userPlays = new JLabel("0"); -// else -// userPlays = new JLabel(Integer.toString(track.getUserPlayCount())); -// -// JLabel plays = new JLabel(numberFormat.format(track.getPlayCount())); -// JButton openExternal = new JButton("Open Online"); -// openExternal.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent arg0) { -// Network.openURL(track.getUrl()); -// } -// }); -// JButton openInternal = new JButton("Open " + track.getClass().getSimpleName()); -// openInternal.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent arg0) { -// track.view(); -// } -// }); -// JPanel panel = new JPanel(); -// panel.setLayout(new GridLayout(1, 5)); -// panel.add(name); -// panel.add(userPlays); -// panel.add(plays); -// panel.add(openInternal); -// panel.add(openExternal); -// -// trackListPanel.add(panel); -// } -// } - -// add(name); -// add(artist); -// add(listeners); -// add(playCount); -// add(userPlayCount); -// -// add(trackListPanel); -// JPanel datePanel = new JPanel(); -// datePanel.setLayout(new FlowLayout()); -// datePanel.add(dateLabel); + contentLabel.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); -// add(datePanel); - add(contentLabel); + contentLabel.setLineWrap(true); +// contentLabel.setText("" + wiki.getContent() + "

" + wiki.getDate() + ""); + + JScrollPane scroll = new JScrollPane(contentLabel); + add(scroll); + +// add(contentLabel); // pack(); } } diff --git a/fmframework/src/sarsoo/fmframework/music/FMObj.java b/fmframework/src/sarsoo/fmframework/music/FMObj.java index ed28b84..c397dec 100644 --- a/fmframework/src/sarsoo/fmframework/music/FMObj.java +++ b/fmframework/src/sarsoo/fmframework/music/FMObj.java @@ -1,6 +1,7 @@ package sarsoo.fmframework.music; import sarsoo.fmframework.gui.FMObjView; +import sarsoo.fmframework.util.Maths; public abstract class FMObj implements Comparable{ @@ -39,6 +40,10 @@ public abstract class FMObj implements Comparable{ return userPlayCount - obj.getUserPlayCount(); } + public double getTimeListenRatio() { + return Maths.getDaysScrobbling() / (double) userPlayCount; + } + public String getName() { return name; } diff --git a/fmframework/src/sarsoo/fmframework/test/NetworkTest.java b/fmframework/src/sarsoo/fmframework/test/NetworkTest.java index d2704b2..aae7100 100644 --- a/fmframework/src/sarsoo/fmframework/test/NetworkTest.java +++ b/fmframework/src/sarsoo/fmframework/test/NetworkTest.java @@ -20,6 +20,7 @@ import sarsoo.fmframework.parser.AlbumParser; import sarsoo.fmframework.parser.Parser; import sarsoo.fmframework.util.FMObjList; import sarsoo.fmframework.util.Getter; +import sarsoo.fmframework.util.Maths; import sarsoo.fmframework.util.Reference; class NetworkTest { @@ -57,7 +58,7 @@ class NetworkTest { void testTag() { // System.out.println(Instant.parse("2018-04-05T07:00:00.00Z").getEpochSecond()); - System.out.println(Getter.getScrobblesToday("sarsoo")); + System.out.println(Maths.getDaysScrobbling()); // System.out.println(url); } diff --git a/fmframework/src/sarsoo/fmframework/util/Maths.java b/fmframework/src/sarsoo/fmframework/util/Maths.java index 7a55b1b..08b577c 100644 --- a/fmframework/src/sarsoo/fmframework/util/Maths.java +++ b/fmframework/src/sarsoo/fmframework/util/Maths.java @@ -1,40 +1,58 @@ package sarsoo.fmframework.util; -import javax.swing.JLabel; -import javax.swing.SwingConstants; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.concurrent.TimeUnit; import sarsoo.fmframework.music.FMObj; public class Maths { public static double getPercentListening(FMObj obj, String username) { - + int userScrobbles = Getter.getScrobbles(Reference.getUserName()); double plays = (double) obj.getUserPlayCount(); if (userScrobbles > 0 && plays > 0) { - + double userScrobblesDouble = (double) userScrobbles; double percentage = (plays / userScrobblesDouble) * 100; return percentage; } - - return 0; + + return 0; } - -public static double getPercentListening(FMObjList objList, String username) { - + + public static double getPercentListening(FMObjList objList, String username) { + int userScrobbles = Getter.getScrobbles(Reference.getUserName()); double plays = (double) objList.getTotalUserScrobbles(); if (userScrobbles > 0 && plays > 0) { - + double userScrobblesDouble = (double) userScrobbles; double percentage = (plays / userScrobblesDouble) * 100; return percentage; } + + return 0; + } + + public static int getDaysScrobbling() { + + Calendar calendar = new GregorianCalendar(2017, 10, 2); + +// System.out.println(calendar.getTime().getTime()); + + Date date = new Date(); +// System.out.println(date.getTime()); - return 0; + long diff = date.getTime() - calendar.getTime().getTime(); + +// System.out.println(diff/(1000*60*60*24)); + + return (int) (diff/(1000*60*60*24)); } }