implemented config system, broke get last track

This commit is contained in:
aj 2019-05-12 21:39:28 +01:00
parent 64029f1d6f
commit 4639ecd318
26 changed files with 419 additions and 352 deletions

View File

@ -2,17 +2,17 @@ package sarsoo.fmframework.cache;
import java.util.ArrayList;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Reference;
public class TagPool{
public class TagPool {
private static TagPool instance;
private TagPool(){
tagList = new ArrayList<FMObjList>();
private TagPool() {
tagList = new ArrayList<FMObjList>();
}
// public static synchronized TagPool getInstance() {
@ -22,15 +22,15 @@ public class TagPool{
// return instance;
// }
public static TagPool getPool(){
if(instance == null){
synchronized (TagPool.class) {
if(instance == null){
instance = new TagPool();
}
}
}
return instance;
public static TagPool getPool() {
if (instance == null) {
synchronized (TagPool.class) {
if (instance == null) {
instance = new TagPool();
}
}
}
return instance;
}
private ArrayList<FMObjList> tagList;
@ -39,8 +39,8 @@ public class TagPool{
System.out.println("gettag " + name);
int i;
boolean containedInPool = false;
for(i = 0; i < tagList.size(); i++) {
if(tagList.get(i).getGroupName().equals(name)) {
for (i = 0; i < tagList.size(); i++) {
if (tagList.get(i).getGroupName().equals(name)) {
containedInPool = true;
System.out.println("found in pool");
@ -48,11 +48,13 @@ public class TagPool{
}
}
if(containedInPool) {
if (containedInPool) {
System.out.println("returned from pool");
return tagList.get(i);
}else {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
} else {
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
FMObjList tag = net.getTag(name);
tagList.add(tag);
System.out.println("pulling tag");

View File

@ -0,0 +1,60 @@
package sarsoo.fmframework.config;
import java.util.ArrayList;
import java.util.List;
public class Config {
protected List<ConfigVariable> variables;
public Config() {
this.variables = new ArrayList<ConfigVariable>();
}
public Config(ArrayList<ConfigVariable> variables) {
for(ConfigVariable i: variables) {
addVariable(i);
}
}
public Config addVariable(ConfigVariable variable) {
for(ConfigVariable i: variables) {
if(variable.getKey().equalsIgnoreCase(i.getKey())) {
i.setValue(variable.getValue());
for(VariableListener j: variable.getListeners()) {
i.addListener(j);
}
return this;
}
}
variables.add(variable);
return this;
}
public ConfigVariable getVariable(String key) {
for(ConfigVariable i: variables) {
if (i.getKey() == key) {
return i;
}
}
return null;
}
public String getValue(String key) {
ConfigVariable variable = getVariable(key);
if(variable != null) {
return variable.getValue();
}
return null;
}
}

View File

@ -0,0 +1,47 @@
package sarsoo.fmframework.config;
import java.util.ArrayList;
import java.util.List;
public class ConfigVariable {
protected String key;
protected String value;
protected List<VariableListener> listeners;
public ConfigVariable(String key, String value) {
this.key = key;
this.value = value;
this.listeners = new ArrayList<VariableListener>();
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
VariableEvent event = new VariableEvent(this);
for(VariableListener i: listeners) {
i.listen(event);
}
}
public void addListener(VariableListener listener) {
listeners.add(listener);
}
public List<VariableListener> getListeners() {
return listeners;
}
}

View File

@ -0,0 +1,17 @@
package sarsoo.fmframework.config;
public class VariableEvent {
protected ConfigVariable variable;
public VariableEvent(ConfigVariable variable) {
this.variable = variable;
}
public ConfigVariable getVariable() {
return variable;
}
}

View File

@ -0,0 +1,7 @@
package sarsoo.fmframework.config;
public interface VariableListener {
public void listen(VariableEvent event);
}

View File

@ -5,20 +5,28 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.config.ConfigVariable;
import sarsoo.fmframework.fx.controller.RootController;
import sarsoo.fmframework.util.Reference;
import sarsoo.fmframework.net.Key;
public class FmFramework extends Application {
private static Stage stage;
private Scene rootScene;
private static Config config;
private static RootController control;
@Override
public void start(Stage stage) throws Exception {
FmFramework.stage = stage;
Reference.setUserName("sarsoo");
config = new Config();
config.addVariable(new ConfigVariable("username", "sarsoo"));
config.addVariable(new ConfigVariable("api_key", Key.getKey()));
FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/RootPane.fxml"));
@ -41,6 +49,10 @@ public class FmFramework extends Application {
}
public static Config getSessionConfig() {
return config;
}
public static void main(String[] args) {
launch(args);
}

View File

@ -3,9 +3,9 @@ package sarsoo.fmframework.fx.chart;
import java.util.ArrayList;
import javafx.scene.chart.PieChart;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.Reference;
import sarsoo.fmframework.fx.FmFramework;
public class GenreTotalPieChart extends GenrePieChart{
@ -14,7 +14,9 @@ public class GenreTotalPieChart extends GenrePieChart{
setTitle(name + " total");
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
int totalScrobbles = net.getUserScrobbleCount();

View File

@ -14,6 +14,7 @@ import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.tab.ArtistTab;
@ -22,7 +23,6 @@ import sarsoo.fmframework.music.FMObj;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Maths;
import sarsoo.fmframework.util.Reference;
import javafx.scene.layout.*;
import javafx.scene.chart.*;
import javafx.scene.chart.PieChart.Data;
@ -49,7 +49,9 @@ public class FMObjListPaneController {
public void populate(FMObjList list) {
this.list = list;
double percent = Maths.getPercentListening(list, Reference.getUserName());
String username = FmFramework.getSessionConfig().getValue("username");
double percent = Maths.getPercentListening(list, username);
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
labelTotalScrobbles.setText(numberFormat.format(list.getTotalUserScrobbles()));
@ -92,14 +94,15 @@ public class FMObjListPaneController {
}
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data(list.getGroupName(), list.getTotalUserScrobbles()),
new PieChart.Data("other", new FmUserNetwork(Key.getKey(), Reference.getUserName()).getUserScrobbleCount() - list.getTotalUserScrobbles()));
new PieChart.Data("other",
new FmUserNetwork(FmFramework.getSessionConfig().getValue("api_key"), username)
.getUserScrobbleCount() - list.getTotalUserScrobbles()));
ObservableList<PieChart.Data> pieChartArtistsData = FXCollections.observableArrayList();
int counter2;
for(counter2 = 0; counter2 < list.size(); counter2++) {
for (counter2 = 0; counter2 < list.size(); counter2++) {
PieChart.Data data = new PieChart.Data(list.get(counter2).getName(), list.get(counter2).getUserPlayCount());
@ -123,10 +126,14 @@ public class FMObjListPaneController {
@FXML
protected void handleRefresh(ActionEvent event) {
list = new FmUserNetwork(Key.getKey(), Reference.getUserName()).getTag(list.getGroupName());
Config config = FmFramework.getSessionConfig();
String username = config.getValue("username");
String api_key = config.getValue("api_key");
double percent = Maths.getPercentListening(list, Reference.getUserName());
list = new FmUserNetwork(api_key, username).getTag(list.getGroupName());
double percent = Maths.getPercentListening(list, username);
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK);
labelTotalScrobbles.setText(numberFormat.format(list.getTotalUserScrobbles()));
@ -171,13 +178,12 @@ public class FMObjListPaneController {
}
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data(list.getGroupName(), list.getTotalUserScrobbles()),
new PieChart.Data("other", new FmUserNetwork(Key.getKey(), Reference.getUserName()).getUserScrobbleCount() - list.getTotalUserScrobbles()));
new PieChart.Data("other",
new FmUserNetwork(FmFramework.getSessionConfig().getValue("api_key"), username)
.getUserScrobbleCount() - list.getTotalUserScrobbles()));
pieChart.setData(pieChartData);
}
}

View File

@ -14,6 +14,7 @@ import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.file.ListPersister;
import sarsoo.fmframework.fm.FmNetwork;
import sarsoo.fmframework.fm.FmUserNetwork;
@ -28,10 +29,10 @@ import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Maths;
import sarsoo.fmframework.util.Reference;
import javafx.scene.layout.*;
import javafx.scene.chart.*;
import javafx.stage.FileChooser;
public class FMObjListPaneEditController {
@FXML
@ -141,7 +142,8 @@ public class FMObjListPaneEditController {
public void updateList() {
FmNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
FmNetwork net = new FmUserNetwork(FmFramework.getSessionConfig().getValue("api_key"),
FmFramework.getSessionConfig().getValue("username"));
FMObjList newList = new FMObjList();
int counter;
@ -154,7 +156,7 @@ public class FMObjListPaneEditController {
}
public void refresh() {
double percent = Maths.getPercentListening(list, Reference.getUserName());
double percent = Maths.getPercentListening(list, FmFramework.getSessionConfig().getValue("username"));
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK);
labelTotalScrobbles.setText(numberFormat.format(list.getTotalUserScrobbles()));
@ -221,7 +223,10 @@ public class FMObjListPaneEditController {
}
int other = new FmUserNetwork(Key.getKey(), Reference.getUserName()).getUserScrobbleCount() - list.getTotalUserScrobbles();
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
int other = net.getUserScrobbleCount() - list.getTotalUserScrobbles();
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data(String.format("%d%%", (int) list.getTotalUserScrobbles() * 100 / other),
list.getTotalUserScrobbles()),
@ -249,7 +254,8 @@ public class FMObjListPaneEditController {
@FXML
protected void handleAddTrack(ActionEvent event) {
FmNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
String name = textTrack.getText();
String album = textAlbum.getText();
@ -276,7 +282,9 @@ public class FMObjListPaneEditController {
@FXML
protected void handleAddAlbum(ActionEvent event) {
FmNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
String album = textAlbum.getText();
String artist = textArtist.getText();
@ -295,7 +303,8 @@ public class FMObjListPaneEditController {
@FXML
protected void handleAddArtist(ActionEvent event) {
FmNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
String artist = textArtist.getText();
@ -316,15 +325,15 @@ public class FMObjListPaneEditController {
protected void handleSave(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("save fm list");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("FMObjList", "*.fmlist"));
File file = fileChooser.showSaveDialog(FmFramework.getStage());
fileChooser.setTitle("save fm list");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("FMObjList", "*.fmlist"));
File file = fileChooser.showSaveDialog(FmFramework.getStage());
if(file != null) {
if (file != null) {
ListPersister persist = new ListPersister();
persist.saveListToFile(file, list);
ListPersister persist = new ListPersister();
persist.saveListToFile(file, list);
}
}
}
}

View File

@ -1,14 +1,11 @@
package sarsoo.fmframework.fx.controller;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import javax.swing.JOptionPane;
@ -16,12 +13,10 @@ import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.stage.FileChooser;
import sarsoo.fmframework.cache.TagPool;
import sarsoo.fmframework.config.VariableEvent;
import sarsoo.fmframework.config.VariableListener;
import sarsoo.fmframework.file.ListPersister;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.TextAreaConsole;
import sarsoo.fmframework.fx.chart.GenrePieChartTitledPane;
import sarsoo.fmframework.fx.chart.PieChartTitledPane;
import sarsoo.fmframework.fx.service.GetLastTrackService;
import sarsoo.fmframework.fx.service.GetScrobbleCountService;
import sarsoo.fmframework.fx.service.GetTagMenuItemsService;
@ -31,42 +26,44 @@ import sarsoo.fmframework.fx.tab.AlbumTab;
import sarsoo.fmframework.fx.tab.ArtistTab;
import sarsoo.fmframework.fx.tab.ConsoleTab;
import sarsoo.fmframework.fx.tab.FMObjListEditTab;
import sarsoo.fmframework.fx.tab.FMObjListTab;
import sarsoo.fmframework.fx.tab.GenrePieChartTab;
import sarsoo.fmframework.fx.tab.ScrobbleChartTab;
import sarsoo.fmframework.fx.tab.TrackTab;
import sarsoo.fmframework.log.Log;
import sarsoo.fmframework.log.Logger;
import sarsoo.fmframework.log.entry.InfoEntry;
import sarsoo.fmframework.log.entry.LogEntry;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.music.Tag;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Reference;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*;
import javafx.concurrent.*;
import javafx.application.Platform;
import org.json.*;
public class RootController {
@FXML
public void initialize() {
Logger.setLog(new Log(TextAreaConsole.getInstance(), false));
FmFramework.getSessionConfig().getVariable("username").addListener(new VariableListener() {
@Override
public void listen(VariableEvent event) {
refresh();
}
});
refresh();
}
public void refresh() {
labelStatsUsername.setText(Reference.getUserName());
labelStatsUsername.setText(FmFramework.getSessionConfig().getValue("username"));
refreshScrobbleCounts();
addLastTrackTab();
refreshTagMenu();
@ -189,14 +186,8 @@ public class RootController {
String username = JOptionPane.showInputDialog("enter username:");
if (username != null) {
Reference.setUserName(username);
FmFramework.getSessionConfig().getVariable("username").setValue(username);
Platform.runLater(new Runnable() {
@Override
public void run() {
refresh();
}
});
}
return null;
}

View File

@ -8,7 +8,9 @@ import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.net.Key;
import javafx.scene.chart.BarChart;
@ -57,7 +59,9 @@ public class ScrobbleChartPaneController {
@Override
protected Void call() throws Exception {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
String value = (String) dropDownTimeRange.getValue();
int dayLength = 0;

View File

@ -3,7 +3,6 @@ package sarsoo.fmframework.fx.controller.borderpane;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javafx.application.Platform;
import javafx.concurrent.Service;
@ -14,6 +13,7 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.controller.info.AlbumPaneController;
@ -21,9 +21,7 @@ import sarsoo.fmframework.fx.tab.ArtistTab;
import sarsoo.fmframework.log.Logger;
import sarsoo.fmframework.log.entry.ErrorEntry;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.Reference;
public class AlbumBorderPaneController extends FMObjBorderPaneController {
@ -126,7 +124,9 @@ public class AlbumBorderPaneController extends FMObjBorderPaneController {
@Override
protected Void call() throws Exception {
album = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(album);
Config config = FmFramework.getSessionConfig();
album = new FmUserNetwork(config.getValue("api_key"), config.getValue("username")).refresh(album);
Platform.runLater(new Runnable() {
@Override

View File

@ -12,12 +12,11 @@ import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.AnchorPane;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.controller.info.ArtistPaneController;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.Reference;
public class ArtistBorderPaneController extends FMObjBorderPaneController{
@ -91,7 +90,9 @@ public class ArtistBorderPaneController extends FMObjBorderPaneController{
@Override
protected Void call() throws Exception {
artist = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(artist);
Config config = FmFramework.getSessionConfig();
artist = new FmUserNetwork(config.getValue("api_key"), config.getValue("username")).refresh(artist);
Platform.runLater(new Runnable() {
@Override

View File

@ -14,15 +14,13 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.controller.info.TrackPaneController;
import sarsoo.fmframework.fx.tab.AlbumTab;
import sarsoo.fmframework.fx.tab.ArtistTab;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.Reference;
public class TrackBorderPaneController extends FMObjBorderPaneController {
@ -132,7 +130,9 @@ public class TrackBorderPaneController extends FMObjBorderPaneController {
@Override
protected Void call() throws Exception {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
track = net.refresh(track);
track.setScrobbles(net.getTrackScrobbles(track));

View File

@ -1,23 +1,15 @@
package sarsoo.fmframework.fx.controller.info;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.Locale;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.tab.ArtistTab;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Wiki;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.Maths;
import sarsoo.fmframework.util.Reference;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
public class AlbumPaneController {
@ -52,22 +44,20 @@ public class AlbumPaneController {
}
public void refresh(Album album) {
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK);
labelAlbumName.setText(album.getName());
labelArtistName.setText(album.getArtist().getName());
labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount())
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName())));
labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount()) + String.format(" Scrobbles (%.2f%%)",
Maths.getPercentListening(album, FmFramework.getSessionConfig().getValue("username"))));
labelTotalListeners.setText(numberFormat.format(album.getListeners()) + " Listeners");
labelTotalScrobbles.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles");
double ratio = album.getTimeListenRatio();
if (ratio > 1) {
labelRatio.setText(String.format("listen every %.2f days", ratio));
} else if (ratio == 1) {
@ -78,62 +68,13 @@ public class AlbumPaneController {
Wiki wiki = album.getWiki();
if(wiki != null) {
if (wiki != null) {
textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
}else {
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
} else {
// albumBorderPane.setCenter(infoAnchorPane);
}
}
// @FXML
// protected void handleRefresh(ActionEvent event) {
// refresh();
// }
// @FXML
// protected void viewOnline(ActionEvent event) {
// Network.openURL(album.getUrl());
// }
// @FXML
// protected void viewArtist(ActionEvent event) throws IOException {
// FmFramework.getController().addTab(new ArtistTab(album.getArtist()));
// }
//
// @FXML
// protected void viewRYM(ActionEvent event) {
// Network.openURL(album.getRymURL());
// }
// public void refresh() {
// album = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(album);
//
// NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
//
// labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount())
// + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName())));
//
// labelTotalListeners.setText(numberFormat.format(album.getListeners()) + " Listeners");
// labelTotalScrobbles.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles");
//
// double ratio = album.getTimeListenRatio();
//
//
// if (ratio > 1) {
// labelRatio.setText(String.format("listen every %.2f days", ratio));
// } else if (ratio == 1) {
// labelRatio.setText("listen every day");
// } else {
// labelRatio.setText(String.format("%.2f times a day", 1 / ratio));
// }
//
// Wiki wiki = album.getWiki();
//
// if(wiki != null) {
//
// textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
// }
// }
}

View File

@ -3,20 +3,15 @@ package sarsoo.fmframework.fx.controller.info;
import java.text.NumberFormat;
import java.util.Locale;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.music.Wiki;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.Maths;
import sarsoo.fmframework.util.Reference;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
public class ArtistPaneController{
public class ArtistPaneController {
@FXML
private Label labelArtistName;
@ -42,24 +37,21 @@ public class ArtistPaneController{
@FXML
public void initialize() {
}
public void refresh(Artist artist) {
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
labelArtistName.setText(artist.getName());
labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount())
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(artist, Reference.getUserName())));
labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount()) + String.format(" Scrobbles (%.2f%%)",
Maths.getPercentListening(artist, FmFramework.getSessionConfig().getValue("username"))));
labelTotalListeners.setText(numberFormat.format(artist.getListeners()) + " Listeners");
labelTotalScrobbles.setText(numberFormat.format(artist.getPlayCount()) + " Total Scrobbles");
double ratio = artist.getTimeListenRatio();
if (ratio > 1) {
labelRatio.setText(String.format("listen every %.2f days", ratio));
} else if (ratio == 1) {
@ -70,41 +62,12 @@ public class ArtistPaneController{
Wiki wiki = artist.getWiki();
if(wiki != null) {
if (wiki != null) {
textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
}else {
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
} else {
// artistBorderPane.setCenter(infoAnchorPane);
}
}
//
// public void refresh(Artist artist) {
//
// NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
//
// labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount())
// + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(artist, Reference.getUserName())));
//
// labelTotalListeners.setText(numberFormat.format(artist.getListeners()) + " Listeners");
// labelTotalScrobbles.setText(numberFormat.format(artist.getPlayCount()) + " Total Scrobbles");
//
// double ratio = artist.getTimeListenRatio();
//
//
// if (ratio > 1) {
// labelRatio.setText(String.format("listen every %.2f days", ratio));
// } else if (ratio == 1) {
// labelRatio.setText("listen every day");
// } else {
// labelRatio.setText(String.format("%.2f times a day", 1 / ratio));
// }
//
// Wiki wiki = artist.getWiki();
//
// if(wiki != null) {
//
// textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
// }
// }
}

View File

@ -1,24 +1,15 @@
package sarsoo.fmframework.fx.controller.info;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.Locale;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.tab.AlbumTab;
import sarsoo.fmframework.fx.tab.ArtistTab;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.music.Wiki;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.Maths;
import sarsoo.fmframework.util.Reference;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
public class TrackPaneController {
@ -71,8 +62,8 @@ public class TrackPaneController {
labelAlbumName.setText(track.getAlbum().getName());
labelArtistName.setText(track.getArtist().getName());
labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount())
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName())));
labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount()) + String.format(" Scrobbles (%.2f%%)",
Maths.getPercentListening(track, FmFramework.getSessionConfig().getValue("username"))));
labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners");
labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles");
@ -92,7 +83,7 @@ public class TrackPaneController {
if (wiki != null) {
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
}else {
} else {
// trackBorderPane.setCenter(infoAnchorPane);
}

View File

@ -2,12 +2,14 @@ package sarsoo.fmframework.fx.service;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.log.Logger;
import sarsoo.fmframework.log.entry.ErrorEntry;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.Reference;
public class GetLastTrackService extends Service<Track>{
public class GetLastTrackService extends Service<Track> {
@Override
protected Task<Track> createTask() {
@ -16,11 +18,22 @@ public class GetLastTrackService extends Service<Track>{
@Override
protected Track call() throws Exception {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
System.out.println(config.getValue("api_key") + config.getValue("username"));
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
return net.getLastTrack();
}
@Override
protected void failed() {
super.failed();
Logger.getLog().logError(new ErrorEntry("failed to get last track"));
}
};
}

View File

@ -2,11 +2,13 @@ package sarsoo.fmframework.fx.service;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.Reference;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.log.Logger;
import sarsoo.fmframework.log.entry.ErrorEntry;
public class GetScrobbleCountService extends Service<ScrobbleCount>{
public class GetScrobbleCountService extends Service<ScrobbleCount> {
@Override
protected Task<ScrobbleCount> createTask() {
@ -15,11 +17,21 @@ public class GetScrobbleCountService extends Service<ScrobbleCount>{
@Override
protected ScrobbleCount call() throws Exception {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
return new ScrobbleCount(net.getScrobblesToday(), net.getUserScrobbleCount());
}
@Override
protected void failed() {
super.failed();
Logger.getLog().logError(new ErrorEntry("failed to get scrobble count"));
}
};
}

View File

@ -11,6 +11,8 @@ import javafx.scene.control.MenuItem;
import sarsoo.fmframework.cache.TagPool;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.tab.FMObjListTab;
import sarsoo.fmframework.log.Logger;
import sarsoo.fmframework.log.entry.ErrorEntry;
import sarsoo.fmframework.music.Tag;
public class GetTagMenuItemsService extends Service<ArrayList<MenuItem>> {
@ -78,4 +80,12 @@ public class GetTagMenuItemsService extends Service<ArrayList<MenuItem>> {
};
}
@Override
protected void failed() {
super.failed();
Logger.getLog().logError(new ErrorEntry("failed to get tag menu items"));
}
}

View File

@ -4,12 +4,14 @@ import java.util.ArrayList;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.log.Logger;
import sarsoo.fmframework.log.entry.ErrorEntry;
import sarsoo.fmframework.music.Tag;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.Reference;
public class GetTagsService extends Service<ArrayList<Tag>>{
public class GetTagsService extends Service<ArrayList<Tag>> {
@Override
protected Task<ArrayList<Tag>> createTask() {
@ -18,7 +20,9 @@ public class GetTagsService extends Service<ArrayList<Tag>>{
@Override
protected ArrayList<Tag> call() throws Exception {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
return net.getTags();
}
@ -26,4 +30,12 @@ public class GetTagsService extends Service<ArrayList<Tag>>{
};
}
@Override
protected void failed() {
super.failed();
Logger.getLog().logError(new ErrorEntry("failed to get tags"));
}
}

View File

@ -2,17 +2,19 @@ package sarsoo.fmframework.jframe;
import javax.swing.JOptionPane;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.Reference;
public class Getter {
public static Album getAlbum() {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
String albumName = JOptionPane.showInputDialog(null, "Enter Album Name");
if (albumName != null) {
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
@ -24,7 +26,9 @@ public class Getter {
}
public static Artist getArtist() {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
if (artistName != null) {
return net.getArtist(artistName);
@ -33,7 +37,9 @@ public class Getter {
}
public static Track getTrack() {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
String trackName = JOptionPane.showInputDialog(null, "Enter Track Name");
if (trackName != null) {
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
@ -45,7 +51,9 @@ public class Getter {
}
public static Track getTrack(Album album) {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
String trackName = JOptionPane.showInputDialog(null, "Enter Track Name");
if (trackName != null) {
Track track = net.getTrack(trackName, album.getArtist().getName());

View File

@ -3,10 +3,10 @@ package sarsoo.fmframework.music;
import java.io.Serializable;
import java.util.ArrayList;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.util.Maths;
import sarsoo.fmframework.util.Reference;
public abstract class FMObj implements Comparable<FMObj>, Serializable{
@ -64,7 +64,9 @@ public abstract class FMObj implements Comparable<FMObj>, Serializable{
}
public double getPercent() {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
return ((double)userPlayCount*100)/(double) net.getUser().getScrobbleCount();
}

View File

@ -3,12 +3,13 @@ package sarsoo.fmframework.util;
import java.io.Serializable;
import java.util.ArrayList;
import sarsoo.fmframework.config.Config;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.music.FMObj;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.net.Key;
public class FMObjList extends ArrayList<FMObj> implements Comparable<FMObjList>, Serializable {
@ -86,7 +87,9 @@ public class FMObjList extends ArrayList<FMObj> implements Comparable<FMObjList>
}
public void refresh() {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
stream().forEach(item->net.refresh(item));
Config config = FmFramework.getSessionConfig();
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
stream().forEach(item -> net.refresh(item));
}
}

View File

@ -5,13 +5,14 @@ import java.util.Date;
import java.util.GregorianCalendar;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.music.FMObj;
import sarsoo.fmframework.net.Key;
public class Maths {
public static double getPercentListening(FMObj obj, String username) {
int userScrobbles = new FmUserNetwork(Key.getKey(), username).getUserScrobbleCount();
int userScrobbles = new FmUserNetwork(FmFramework.getSessionConfig().getValue("api_key"), username)
.getUserScrobbleCount();
double plays = (double) obj.getUserPlayCount();
if (userScrobbles > 0 && plays > 0) {
@ -27,7 +28,8 @@ public class Maths {
public static double getPercentListening(FMObjList objList, String username) {
int userScrobbles = new FmUserNetwork(Key.getKey(), username).getUserScrobbleCount();
int userScrobbles = new FmUserNetwork(FmFramework.getSessionConfig().getValue("api_key"), username)
.getUserScrobbleCount();
double plays = (double) objList.getTotalUserScrobbles();
if (userScrobbles > 0 && plays > 0) {
@ -54,6 +56,6 @@ public class Maths {
// System.out.println(diff/(1000*60*60*24));
return (int) (diff/(1000*60*60*24));
return (int) (diff / (1000 * 60 * 60 * 24));
}
}

View File

@ -1,48 +0,0 @@
package sarsoo.fmframework.util;
import java.util.ArrayList;
import sarsoo.fmframework.log.console.Console;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist;
public class Reference {
private static String userName;
private static boolean isVerbose = false;
private static boolean isHeadless = false;
private static Console console;
public static String getUserName() {
return userName;
}
public static void setUserName(String userNameIn) {
userName = userNameIn;
}
public static boolean isHeadless() {
return isHeadless;
}
public static void setIsHeadless(boolean headlessIn) {
isHeadless = headlessIn;
}
public static Console getConsole() {
return console;
}
public static boolean isVerbose() {
return isVerbose;
}
public static void setVerbose(Console consoleIn) {
if(consoleIn == null)
isVerbose = false;
else
isVerbose = true;
console = consoleIn;
}
}