implemented config system, broke get last track
This commit is contained in:
parent
64029f1d6f
commit
4639ecd318
@ -2,17 +2,17 @@ package sarsoo.fmframework.cache;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
import sarsoo.fmframework.net.Key;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
|
|
||||||
public class TagPool{
|
public class TagPool {
|
||||||
|
|
||||||
private static TagPool instance;
|
private static TagPool instance;
|
||||||
|
|
||||||
private TagPool(){
|
private TagPool() {
|
||||||
tagList = new ArrayList<FMObjList>();
|
tagList = new ArrayList<FMObjList>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static synchronized TagPool getInstance() {
|
// public static synchronized TagPool getInstance() {
|
||||||
@ -21,47 +21,49 @@ public class TagPool{
|
|||||||
// }
|
// }
|
||||||
// return instance;
|
// return instance;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static TagPool getPool(){
|
public static TagPool getPool() {
|
||||||
if(instance == null){
|
if (instance == null) {
|
||||||
synchronized (TagPool.class) {
|
synchronized (TagPool.class) {
|
||||||
if(instance == null){
|
if (instance == null) {
|
||||||
instance = new TagPool();
|
instance = new TagPool();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<FMObjList> tagList;
|
private ArrayList<FMObjList> tagList;
|
||||||
|
|
||||||
public FMObjList getTag(String name) {
|
public FMObjList getTag(String name) {
|
||||||
System.out.println("gettag " + name);
|
System.out.println("gettag " + name);
|
||||||
int i;
|
int i;
|
||||||
boolean containedInPool = false;
|
boolean containedInPool = false;
|
||||||
for(i = 0; i < tagList.size(); i++) {
|
for (i = 0; i < tagList.size(); i++) {
|
||||||
if(tagList.get(i).getGroupName().equals(name)) {
|
if (tagList.get(i).getGroupName().equals(name)) {
|
||||||
containedInPool = true;
|
containedInPool = true;
|
||||||
System.out.println("found in pool");
|
System.out.println("found in pool");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(containedInPool) {
|
if (containedInPool) {
|
||||||
System.out.println("returned from pool");
|
System.out.println("returned from pool");
|
||||||
return tagList.get(i);
|
return tagList.get(i);
|
||||||
}else {
|
} else {
|
||||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
Config config = FmFramework.getSessionConfig();
|
||||||
|
|
||||||
|
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
|
||||||
FMObjList tag = net.getTag(name);
|
FMObjList tag = net.getTag(name);
|
||||||
tagList.add(tag);
|
tagList.add(tag);
|
||||||
System.out.println("pulling tag");
|
System.out.println("pulling tag");
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush() {
|
public void flush() {
|
||||||
tagList.clear();
|
tagList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
60
src/main/java/sarsoo/fmframework/config/Config.java
Normal file
60
src/main/java/sarsoo/fmframework/config/Config.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
src/main/java/sarsoo/fmframework/config/ConfigVariable.java
Normal file
47
src/main/java/sarsoo/fmframework/config/ConfigVariable.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
17
src/main/java/sarsoo/fmframework/config/VariableEvent.java
Normal file
17
src/main/java/sarsoo/fmframework/config/VariableEvent.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package sarsoo.fmframework.config;
|
||||||
|
|
||||||
|
public interface VariableListener {
|
||||||
|
|
||||||
|
public void listen(VariableEvent event);
|
||||||
|
|
||||||
|
}
|
@ -5,20 +5,28 @@ import javafx.fxml.FXMLLoader;
|
|||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
|
import sarsoo.fmframework.config.ConfigVariable;
|
||||||
import sarsoo.fmframework.fx.controller.RootController;
|
import sarsoo.fmframework.fx.controller.RootController;
|
||||||
import sarsoo.fmframework.util.Reference;
|
import sarsoo.fmframework.net.Key;
|
||||||
|
|
||||||
public class FmFramework extends Application {
|
public class FmFramework extends Application {
|
||||||
|
|
||||||
private static Stage stage;
|
private static Stage stage;
|
||||||
private Scene rootScene;
|
private Scene rootScene;
|
||||||
|
|
||||||
|
private static Config config;
|
||||||
|
|
||||||
private static RootController control;
|
private static RootController control;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws Exception {
|
public void start(Stage stage) throws Exception {
|
||||||
FmFramework.stage = stage;
|
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"));
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/RootPane.fxml"));
|
||||||
|
|
||||||
@ -40,6 +48,10 @@ public class FmFramework extends Application {
|
|||||||
stage.show();
|
stage.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Config getSessionConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
|
@ -3,9 +3,9 @@ package sarsoo.fmframework.fx.chart;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javafx.scene.chart.PieChart;
|
import javafx.scene.chart.PieChart;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
import sarsoo.fmframework.net.Key;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
|
|
||||||
public class GenreTotalPieChart extends GenrePieChart{
|
public class GenreTotalPieChart extends GenrePieChart{
|
||||||
|
|
||||||
@ -14,7 +14,9 @@ public class GenreTotalPieChart extends GenrePieChart{
|
|||||||
|
|
||||||
setTitle(name + " total");
|
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();
|
int totalScrobbles = net.getUserScrobbleCount();
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import javafx.event.EventHandler;
|
|||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
import sarsoo.fmframework.fx.FmFramework;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.fx.tab.ArtistTab;
|
import sarsoo.fmframework.fx.tab.ArtistTab;
|
||||||
@ -22,7 +23,6 @@ import sarsoo.fmframework.music.FMObj;
|
|||||||
import sarsoo.fmframework.net.Key;
|
import sarsoo.fmframework.net.Key;
|
||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
import sarsoo.fmframework.util.Maths;
|
import sarsoo.fmframework.util.Maths;
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.scene.chart.*;
|
import javafx.scene.chart.*;
|
||||||
import javafx.scene.chart.PieChart.Data;
|
import javafx.scene.chart.PieChart.Data;
|
||||||
@ -37,19 +37,21 @@ public class FMObjListPaneController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private GridPane gridPaneFMObjs;
|
private GridPane gridPaneFMObjs;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private PieChart pieChart;
|
private PieChart pieChart;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private PieChart pieChartArtists;
|
private PieChart pieChartArtists;
|
||||||
|
|
||||||
private FMObjList list;
|
private FMObjList list;
|
||||||
|
|
||||||
public void populate(FMObjList list) {
|
public void populate(FMObjList list) {
|
||||||
this.list = 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);
|
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||||
|
|
||||||
labelTotalScrobbles.setText(numberFormat.format(list.getTotalUserScrobbles()));
|
labelTotalScrobbles.setText(numberFormat.format(list.getTotalUserScrobbles()));
|
||||||
@ -64,9 +66,9 @@ public class FMObjListPaneController {
|
|||||||
FMObj obj = list.get(counter);
|
FMObj obj = list.get(counter);
|
||||||
|
|
||||||
Label name = new Label(obj.getName().toLowerCase());
|
Label name = new Label(obj.getName().toLowerCase());
|
||||||
|
|
||||||
name.getStyleClass().add("nameLabel");
|
name.getStyleClass().add("nameLabel");
|
||||||
|
|
||||||
name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>() {
|
name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -91,22 +93,23 @@ public class FMObjListPaneController {
|
|||||||
gridPaneFMObjs.add(totalScrobbles, 2, counter);
|
gridPaneFMObjs.add(totalScrobbles, 2, counter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
|
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
|
||||||
new PieChart.Data(list.getGroupName(), list.getTotalUserScrobbles()),
|
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)
|
||||||
ObservableList<PieChart.Data> pieChartArtistsData = FXCollections.observableArrayList();
|
.getUserScrobbleCount() - list.getTotalUserScrobbles()));
|
||||||
|
|
||||||
|
ObservableList<PieChart.Data> pieChartArtistsData = FXCollections.observableArrayList();
|
||||||
int counter2;
|
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());
|
PieChart.Data data = new PieChart.Data(list.get(counter2).getName(), list.get(counter2).getUserPlayCount());
|
||||||
|
|
||||||
pieChartArtistsData.add(data);
|
pieChartArtistsData.add(data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(pieChartArtistsData, new Comparator<PieChart.Data>() {
|
Collections.sort(pieChartArtistsData, new Comparator<PieChart.Data>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -114,19 +117,23 @@ public class FMObjListPaneController {
|
|||||||
return (int) (arg1.getPieValue() - arg0.getPieValue());
|
return (int) (arg1.getPieValue() - arg0.getPieValue());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pieChart.setData(pieChartData);
|
pieChart.setData(pieChartData);
|
||||||
pieChartArtists.setData(pieChartArtistsData);
|
pieChartArtists.setData(pieChartArtistsData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleRefresh(ActionEvent event) {
|
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");
|
||||||
|
|
||||||
|
list = new FmUserNetwork(api_key, username).getTag(list.getGroupName());
|
||||||
double percent = Maths.getPercentListening(list, Reference.getUserName());
|
|
||||||
|
double percent = Maths.getPercentListening(list, username);
|
||||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK);
|
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK);
|
||||||
|
|
||||||
labelTotalScrobbles.setText(numberFormat.format(list.getTotalUserScrobbles()));
|
labelTotalScrobbles.setText(numberFormat.format(list.getTotalUserScrobbles()));
|
||||||
@ -134,7 +141,7 @@ public class FMObjListPaneController {
|
|||||||
|
|
||||||
Collections.sort(list);
|
Collections.sort(list);
|
||||||
Collections.reverse(list);
|
Collections.reverse(list);
|
||||||
|
|
||||||
gridPaneFMObjs.getChildren().clear();
|
gridPaneFMObjs.getChildren().clear();
|
||||||
|
|
||||||
int counter;
|
int counter;
|
||||||
@ -143,9 +150,9 @@ public class FMObjListPaneController {
|
|||||||
FMObj obj = list.get(counter);
|
FMObj obj = list.get(counter);
|
||||||
|
|
||||||
Label name = new Label(obj.getName().toLowerCase());
|
Label name = new Label(obj.getName().toLowerCase());
|
||||||
|
|
||||||
name.getStyleClass().add("nameLabel");
|
name.getStyleClass().add("nameLabel");
|
||||||
|
|
||||||
name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>() {
|
name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -170,14 +177,13 @@ public class FMObjListPaneController {
|
|||||||
gridPaneFMObjs.add(totalScrobbles, 2, counter);
|
gridPaneFMObjs.add(totalScrobbles, 2, counter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
|
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
|
||||||
new PieChart.Data(list.getGroupName(), list.getTotalUserScrobbles()),
|
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);
|
pieChart.setData(pieChartData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import javafx.event.EventHandler;
|
|||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.file.ListPersister;
|
import sarsoo.fmframework.file.ListPersister;
|
||||||
import sarsoo.fmframework.fm.FmNetwork;
|
import sarsoo.fmframework.fm.FmNetwork;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
@ -28,10 +29,10 @@ import sarsoo.fmframework.music.Track;
|
|||||||
import sarsoo.fmframework.net.Key;
|
import sarsoo.fmframework.net.Key;
|
||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
import sarsoo.fmframework.util.Maths;
|
import sarsoo.fmframework.util.Maths;
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.scene.chart.*;
|
import javafx.scene.chart.*;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
|
|
||||||
public class FMObjListPaneEditController {
|
public class FMObjListPaneEditController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@ -140,28 +141,29 @@ public class FMObjListPaneEditController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateList() {
|
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();
|
FMObjList newList = new FMObjList();
|
||||||
int counter;
|
int counter;
|
||||||
for (counter = 0; counter < list.size(); counter++) {
|
for (counter = 0; counter < list.size(); counter++) {
|
||||||
|
|
||||||
newList.add(net.refresh(list.get(counter)));
|
newList.add(net.refresh(list.get(counter)));
|
||||||
}
|
}
|
||||||
|
|
||||||
setList(newList);
|
setList(newList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
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);
|
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK);
|
||||||
|
|
||||||
labelTotalScrobbles.setText(numberFormat.format(list.getTotalUserScrobbles()));
|
labelTotalScrobbles.setText(numberFormat.format(list.getTotalUserScrobbles()));
|
||||||
labelPercent.setText(String.format("%.2f%%", percent));
|
labelPercent.setText(String.format("%.2f%%", percent));
|
||||||
|
|
||||||
Collections.sort(list);
|
Collections.sort(list);
|
||||||
|
|
||||||
Collections.reverse(list);
|
Collections.reverse(list);
|
||||||
|
|
||||||
gridPaneFMObjs.getChildren().clear();
|
gridPaneFMObjs.getChildren().clear();
|
||||||
@ -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(
|
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
|
||||||
new PieChart.Data(String.format("%d%%", (int) list.getTotalUserScrobbles() * 100 / other),
|
new PieChart.Data(String.format("%d%%", (int) list.getTotalUserScrobbles() * 100 / other),
|
||||||
list.getTotalUserScrobbles()),
|
list.getTotalUserScrobbles()),
|
||||||
@ -229,13 +234,13 @@ public class FMObjListPaneEditController {
|
|||||||
pieChart.setData(pieChartData);
|
pieChart.setData(pieChartData);
|
||||||
|
|
||||||
ObservableList<PieChart.Data> pieChartArtistsData = FXCollections.observableArrayList();
|
ObservableList<PieChart.Data> pieChartArtistsData = FXCollections.observableArrayList();
|
||||||
|
|
||||||
for (counter = 0; counter < list.size(); counter++) {
|
for (counter = 0; counter < list.size(); counter++) {
|
||||||
|
|
||||||
PieChart.Data data = new PieChart.Data(list.get(counter).getName(), list.get(counter).getUserPlayCount());
|
PieChart.Data data = new PieChart.Data(list.get(counter).getName(), list.get(counter).getUserPlayCount());
|
||||||
pieChartArtistsData.add(data);
|
pieChartArtistsData.add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
pieChartArtists.setData(pieChartArtistsData);
|
pieChartArtists.setData(pieChartArtistsData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,8 +253,9 @@ public class FMObjListPaneEditController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleAddTrack(ActionEvent event) {
|
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 name = textTrack.getText();
|
||||||
String album = textAlbum.getText();
|
String album = textAlbum.getText();
|
||||||
@ -260,10 +266,10 @@ public class FMObjListPaneEditController {
|
|||||||
if (album != null) {
|
if (album != null) {
|
||||||
Album albumObj = net.getAlbum(album, artist);
|
Album albumObj = net.getAlbum(album, artist);
|
||||||
track.setAlbum(albumObj);
|
track.setAlbum(albumObj);
|
||||||
|
|
||||||
textAlbum.setText(null);
|
textAlbum.setText(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
textTrack.setText(null);
|
textTrack.setText(null);
|
||||||
textArtist.setText(null);
|
textArtist.setText(null);
|
||||||
|
|
||||||
@ -276,8 +282,10 @@ public class FMObjListPaneEditController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleAddAlbum(ActionEvent event) {
|
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 album = textAlbum.getText();
|
||||||
String artist = textArtist.getText();
|
String artist = textArtist.getText();
|
||||||
|
|
||||||
@ -295,8 +303,9 @@ public class FMObjListPaneEditController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleAddArtist(ActionEvent event) {
|
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();
|
String artist = textArtist.getText();
|
||||||
|
|
||||||
if (artist != null) {
|
if (artist != null) {
|
||||||
@ -304,27 +313,27 @@ public class FMObjListPaneEditController {
|
|||||||
Artist artistObj = net.getArtist(artist);
|
Artist artistObj = net.getArtist(artist);
|
||||||
|
|
||||||
list.add(artistObj);
|
list.add(artistObj);
|
||||||
|
|
||||||
textArtist.setText(null);
|
textArtist.setText(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleSave(ActionEvent event) {
|
protected void handleSave(ActionEvent event) {
|
||||||
|
|
||||||
FileChooser fileChooser = new FileChooser();
|
FileChooser fileChooser = new FileChooser();
|
||||||
fileChooser.setTitle("save fm list");
|
fileChooser.setTitle("save fm list");
|
||||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("FMObjList", "*.fmlist"));
|
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("FMObjList", "*.fmlist"));
|
||||||
File file = fileChooser.showSaveDialog(FmFramework.getStage());
|
File file = fileChooser.showSaveDialog(FmFramework.getStage());
|
||||||
|
|
||||||
if(file != null) {
|
if (file != null) {
|
||||||
|
|
||||||
ListPersister persist = new ListPersister();
|
ListPersister persist = new ListPersister();
|
||||||
persist.saveListToFile(file, list);
|
persist.saveListToFile(file, list);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
package sarsoo.fmframework.fx.controller;
|
package sarsoo.fmframework.fx.controller;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
@ -16,12 +13,10 @@ import javafx.event.ActionEvent;
|
|||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.stage.FileChooser;
|
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.file.ListPersister;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
|
||||||
import sarsoo.fmframework.fx.TextAreaConsole;
|
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.GetLastTrackService;
|
||||||
import sarsoo.fmframework.fx.service.GetScrobbleCountService;
|
import sarsoo.fmframework.fx.service.GetScrobbleCountService;
|
||||||
import sarsoo.fmframework.fx.service.GetTagMenuItemsService;
|
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.ArtistTab;
|
||||||
import sarsoo.fmframework.fx.tab.ConsoleTab;
|
import sarsoo.fmframework.fx.tab.ConsoleTab;
|
||||||
import sarsoo.fmframework.fx.tab.FMObjListEditTab;
|
import sarsoo.fmframework.fx.tab.FMObjListEditTab;
|
||||||
import sarsoo.fmframework.fx.tab.FMObjListTab;
|
|
||||||
import sarsoo.fmframework.fx.tab.GenrePieChartTab;
|
import sarsoo.fmframework.fx.tab.GenrePieChartTab;
|
||||||
import sarsoo.fmframework.fx.tab.ScrobbleChartTab;
|
import sarsoo.fmframework.fx.tab.ScrobbleChartTab;
|
||||||
import sarsoo.fmframework.fx.tab.TrackTab;
|
import sarsoo.fmframework.fx.tab.TrackTab;
|
||||||
import sarsoo.fmframework.log.Log;
|
import sarsoo.fmframework.log.Log;
|
||||||
import sarsoo.fmframework.log.Logger;
|
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.fx.FmFramework;
|
||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.music.Artist;
|
import sarsoo.fmframework.music.Artist;
|
||||||
import sarsoo.fmframework.music.Tag;
|
import sarsoo.fmframework.music.Tag;
|
||||||
import sarsoo.fmframework.music.Track;
|
import sarsoo.fmframework.music.Track;
|
||||||
import sarsoo.fmframework.net.Key;
|
|
||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.*;
|
|
||||||
|
|
||||||
import javafx.concurrent.*;
|
import javafx.concurrent.*;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
|
||||||
import org.json.*;
|
|
||||||
|
|
||||||
public class RootController {
|
public class RootController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
Logger.setLog(new Log(TextAreaConsole.getInstance(), false));
|
Logger.setLog(new Log(TextAreaConsole.getInstance(), false));
|
||||||
|
FmFramework.getSessionConfig().getVariable("username").addListener(new VariableListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void listen(VariableEvent event) {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
labelStatsUsername.setText(Reference.getUserName());
|
labelStatsUsername.setText(FmFramework.getSessionConfig().getValue("username"));
|
||||||
|
|
||||||
refreshScrobbleCounts();
|
refreshScrobbleCounts();
|
||||||
addLastTrackTab();
|
addLastTrackTab();
|
||||||
refreshTagMenu();
|
refreshTagMenu();
|
||||||
@ -189,14 +186,8 @@ public class RootController {
|
|||||||
|
|
||||||
String username = JOptionPane.showInputDialog("enter username:");
|
String username = JOptionPane.showInputDialog("enter username:");
|
||||||
if (username != null) {
|
if (username != null) {
|
||||||
Reference.setUserName(username);
|
FmFramework.getSessionConfig().getVariable("username").setValue(username);
|
||||||
|
|
||||||
Platform.runLater(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,9 @@ import javafx.concurrent.Service;
|
|||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.net.Key;
|
import sarsoo.fmframework.net.Key;
|
||||||
import javafx.scene.chart.BarChart;
|
import javafx.scene.chart.BarChart;
|
||||||
@ -57,7 +59,9 @@ public class ScrobbleChartPaneController {
|
|||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
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();
|
String value = (String) dropDownTimeRange.getValue();
|
||||||
|
|
||||||
int dayLength = 0;
|
int dayLength = 0;
|
||||||
|
@ -3,7 +3,6 @@ package sarsoo.fmframework.fx.controller.borderpane;
|
|||||||
import java.awt.Desktop;
|
import java.awt.Desktop;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.concurrent.Service;
|
import javafx.concurrent.Service;
|
||||||
@ -14,6 +13,7 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
import sarsoo.fmframework.fx.FmFramework;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.fx.controller.info.AlbumPaneController;
|
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.Logger;
|
||||||
import sarsoo.fmframework.log.entry.ErrorEntry;
|
import sarsoo.fmframework.log.entry.ErrorEntry;
|
||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.net.Key;
|
|
||||||
import sarsoo.fmframework.net.Network;
|
import sarsoo.fmframework.net.Network;
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
|
|
||||||
public class AlbumBorderPaneController extends FMObjBorderPaneController {
|
public class AlbumBorderPaneController extends FMObjBorderPaneController {
|
||||||
|
|
||||||
@ -125,8 +123,10 @@ public class AlbumBorderPaneController extends FMObjBorderPaneController {
|
|||||||
return new Task<Void>() {
|
return new Task<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
|
|
||||||
|
Config config = FmFramework.getSessionConfig();
|
||||||
|
|
||||||
album = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(album);
|
album = new FmUserNetwork(config.getValue("api_key"), config.getValue("username")).refresh(album);
|
||||||
|
|
||||||
Platform.runLater(new Runnable() {
|
Platform.runLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -12,12 +12,11 @@ import javafx.event.ActionEvent;
|
|||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.fx.controller.info.ArtistPaneController;
|
import sarsoo.fmframework.fx.controller.info.ArtistPaneController;
|
||||||
import sarsoo.fmframework.music.Artist;
|
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{
|
public class ArtistBorderPaneController extends FMObjBorderPaneController{
|
||||||
|
|
||||||
@ -91,7 +90,9 @@ public class ArtistBorderPaneController extends FMObjBorderPaneController{
|
|||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
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() {
|
Platform.runLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,15 +14,13 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
import sarsoo.fmframework.fx.FmFramework;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.fx.controller.info.TrackPaneController;
|
import sarsoo.fmframework.fx.controller.info.TrackPaneController;
|
||||||
import sarsoo.fmframework.fx.tab.AlbumTab;
|
import sarsoo.fmframework.fx.tab.AlbumTab;
|
||||||
import sarsoo.fmframework.fx.tab.ArtistTab;
|
import sarsoo.fmframework.fx.tab.ArtistTab;
|
||||||
import sarsoo.fmframework.music.Track;
|
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 {
|
public class TrackBorderPaneController extends FMObjBorderPaneController {
|
||||||
|
|
||||||
@ -131,8 +129,10 @@ public class TrackBorderPaneController extends FMObjBorderPaneController {
|
|||||||
return new Task<Void>() {
|
return new Task<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
|
|
||||||
|
Config config = FmFramework.getSessionConfig();
|
||||||
|
|
||||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
|
||||||
|
|
||||||
track = net.refresh(track);
|
track = net.refresh(track);
|
||||||
track.setScrobbles(net.getTrackScrobbles(track));
|
track.setScrobbles(net.getTrackScrobbles(track));
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
package sarsoo.fmframework.fx.controller.info;
|
package sarsoo.fmframework.fx.controller.info;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
|
||||||
import sarsoo.fmframework.fx.FmFramework;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.fx.tab.ArtistTab;
|
|
||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.music.Wiki;
|
import sarsoo.fmframework.music.Wiki;
|
||||||
import sarsoo.fmframework.net.Key;
|
|
||||||
import sarsoo.fmframework.net.Network;
|
|
||||||
import sarsoo.fmframework.util.Maths;
|
import sarsoo.fmframework.util.Maths;
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.BorderPane;
|
|
||||||
|
|
||||||
public class AlbumPaneController {
|
public class AlbumPaneController {
|
||||||
|
|
||||||
@ -38,36 +30,34 @@ public class AlbumPaneController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label labelTotalScrobbles;
|
private Label labelTotalScrobbles;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextArea textAreaWiki;
|
private TextArea textAreaWiki;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane infoAnchorPane;
|
private AnchorPane infoAnchorPane;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
|
||||||
labelAlbumName.setText("Hello World");
|
labelAlbumName.setText("Hello World");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void refresh(Album album) {
|
public void refresh(Album album) {
|
||||||
|
|
||||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK);
|
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK);
|
||||||
|
|
||||||
labelAlbumName.setText(album.getName());
|
labelAlbumName.setText(album.getName());
|
||||||
labelArtistName.setText(album.getArtist().getName());
|
labelArtistName.setText(album.getArtist().getName());
|
||||||
labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount())
|
labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount()) + String.format(" Scrobbles (%.2f%%)",
|
||||||
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName())));
|
Maths.getPercentListening(album, FmFramework.getSessionConfig().getValue("username"))));
|
||||||
|
|
||||||
labelTotalListeners.setText(numberFormat.format(album.getListeners()) + " Listeners");
|
labelTotalListeners.setText(numberFormat.format(album.getListeners()) + " Listeners");
|
||||||
labelTotalScrobbles.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles");
|
labelTotalScrobbles.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles");
|
||||||
|
|
||||||
double ratio = album.getTimeListenRatio();
|
double ratio = album.getTimeListenRatio();
|
||||||
|
|
||||||
|
|
||||||
if (ratio > 1) {
|
if (ratio > 1) {
|
||||||
labelRatio.setText(String.format("listen every %.2f days", ratio));
|
labelRatio.setText(String.format("listen every %.2f days", ratio));
|
||||||
} else if (ratio == 1) {
|
} else if (ratio == 1) {
|
||||||
@ -75,65 +65,16 @@ public class AlbumPaneController {
|
|||||||
} else {
|
} else {
|
||||||
labelRatio.setText(String.format("%.2f times a day", 1 / ratio));
|
labelRatio.setText(String.format("%.2f times a day", 1 / ratio));
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiki wiki = album.getWiki();
|
Wiki wiki = album.getWiki();
|
||||||
|
|
||||||
if(wiki != null) {
|
if (wiki != null) {
|
||||||
|
|
||||||
textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
|
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
|
||||||
}else {
|
} else {
|
||||||
// albumBorderPane.setCenter(infoAnchorPane);
|
// 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());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,16 @@ package sarsoo.fmframework.fx.controller.info;
|
|||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.music.Artist;
|
import sarsoo.fmframework.music.Artist;
|
||||||
import sarsoo.fmframework.music.Wiki;
|
import sarsoo.fmframework.music.Wiki;
|
||||||
import sarsoo.fmframework.net.Key;
|
|
||||||
import sarsoo.fmframework.net.Network;
|
|
||||||
import sarsoo.fmframework.util.Maths;
|
import sarsoo.fmframework.util.Maths;
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.BorderPane;
|
|
||||||
|
|
||||||
public class ArtistPaneController{
|
public class ArtistPaneController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label labelArtistName;
|
private Label labelArtistName;
|
||||||
|
|
||||||
@ -32,34 +27,31 @@ public class ArtistPaneController{
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label labelTotalScrobbles;
|
private Label labelTotalScrobbles;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextArea textAreaWiki;
|
private TextArea textAreaWiki;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane infoAnchorPane;
|
private AnchorPane infoAnchorPane;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void refresh(Artist artist) {
|
public void refresh(Artist artist) {
|
||||||
|
|
||||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||||
|
|
||||||
labelArtistName.setText(artist.getName());
|
labelArtistName.setText(artist.getName());
|
||||||
labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount())
|
labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount()) + String.format(" Scrobbles (%.2f%%)",
|
||||||
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(artist, Reference.getUserName())));
|
Maths.getPercentListening(artist, FmFramework.getSessionConfig().getValue("username"))));
|
||||||
|
|
||||||
labelTotalListeners.setText(numberFormat.format(artist.getListeners()) + " Listeners");
|
labelTotalListeners.setText(numberFormat.format(artist.getListeners()) + " Listeners");
|
||||||
labelTotalScrobbles.setText(numberFormat.format(artist.getPlayCount()) + " Total Scrobbles");
|
labelTotalScrobbles.setText(numberFormat.format(artist.getPlayCount()) + " Total Scrobbles");
|
||||||
|
|
||||||
double ratio = artist.getTimeListenRatio();
|
double ratio = artist.getTimeListenRatio();
|
||||||
|
|
||||||
|
|
||||||
if (ratio > 1) {
|
if (ratio > 1) {
|
||||||
labelRatio.setText(String.format("listen every %.2f days", ratio));
|
labelRatio.setText(String.format("listen every %.2f days", ratio));
|
||||||
} else if (ratio == 1) {
|
} else if (ratio == 1) {
|
||||||
@ -67,44 +59,15 @@ public class ArtistPaneController{
|
|||||||
} else {
|
} else {
|
||||||
labelRatio.setText(String.format("%.2f times a day", 1 / ratio));
|
labelRatio.setText(String.format("%.2f times a day", 1 / ratio));
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiki wiki = artist.getWiki();
|
Wiki wiki = artist.getWiki();
|
||||||
|
|
||||||
if(wiki != null) {
|
if (wiki != null) {
|
||||||
|
|
||||||
textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
|
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
|
||||||
}else {
|
} else {
|
||||||
// artistBorderPane.setCenter(infoAnchorPane);
|
// 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());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,15 @@
|
|||||||
package sarsoo.fmframework.fx.controller.info;
|
package sarsoo.fmframework.fx.controller.info;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
|
||||||
import sarsoo.fmframework.fx.FmFramework;
|
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.Track;
|
||||||
import sarsoo.fmframework.music.Wiki;
|
import sarsoo.fmframework.music.Wiki;
|
||||||
import sarsoo.fmframework.net.Key;
|
|
||||||
import sarsoo.fmframework.net.Network;
|
|
||||||
import sarsoo.fmframework.util.Maths;
|
import sarsoo.fmframework.util.Maths;
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.BorderPane;
|
|
||||||
|
|
||||||
public class TrackPaneController {
|
public class TrackPaneController {
|
||||||
|
|
||||||
@ -48,7 +39,7 @@ public class TrackPaneController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button buttonViewAlbum;
|
private Button buttonViewAlbum;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane infoAnchorPane;
|
private AnchorPane infoAnchorPane;
|
||||||
|
|
||||||
@ -64,15 +55,15 @@ public class TrackPaneController {
|
|||||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||||
|
|
||||||
labelTrackName.setText(track.getName());
|
labelTrackName.setText(track.getName());
|
||||||
|
|
||||||
if (track.getAlbum() == null)
|
if (track.getAlbum() == null)
|
||||||
labelAlbumName.setVisible(false);
|
labelAlbumName.setVisible(false);
|
||||||
else
|
else
|
||||||
labelAlbumName.setText(track.getAlbum().getName());
|
labelAlbumName.setText(track.getAlbum().getName());
|
||||||
|
|
||||||
labelArtistName.setText(track.getArtist().getName());
|
labelArtistName.setText(track.getArtist().getName());
|
||||||
labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount())
|
labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount()) + String.format(" Scrobbles (%.2f%%)",
|
||||||
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName())));
|
Maths.getPercentListening(track, FmFramework.getSessionConfig().getValue("username"))));
|
||||||
|
|
||||||
labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners");
|
labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners");
|
||||||
labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles");
|
labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles");
|
||||||
@ -92,7 +83,7 @@ public class TrackPaneController {
|
|||||||
if (wiki != null) {
|
if (wiki != null) {
|
||||||
|
|
||||||
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
|
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
|
||||||
}else {
|
} else {
|
||||||
// trackBorderPane.setCenter(infoAnchorPane);
|
// trackBorderPane.setCenter(infoAnchorPane);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,12 +2,14 @@ package sarsoo.fmframework.fx.service;
|
|||||||
|
|
||||||
import javafx.concurrent.Service;
|
import javafx.concurrent.Service;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
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.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
|
@Override
|
||||||
protected Task<Track> createTask() {
|
protected Task<Track> createTask() {
|
||||||
@ -15,12 +17,23 @@ public class GetLastTrackService extends Service<Track>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Track call() throws Exception {
|
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();
|
return net.getLastTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void failed() {
|
||||||
|
super.failed();
|
||||||
|
|
||||||
|
Logger.getLog().logError(new ErrorEntry("failed to get last track"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,11 +2,13 @@ package sarsoo.fmframework.fx.service;
|
|||||||
|
|
||||||
import javafx.concurrent.Service;
|
import javafx.concurrent.Service;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
import sarsoo.fmframework.net.Key;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.util.Reference;
|
import sarsoo.fmframework.log.Logger;
|
||||||
|
import sarsoo.fmframework.log.entry.ErrorEntry;
|
||||||
|
|
||||||
public class GetScrobbleCountService extends Service<ScrobbleCount>{
|
public class GetScrobbleCountService extends Service<ScrobbleCount> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Task<ScrobbleCount> createTask() {
|
protected Task<ScrobbleCount> createTask() {
|
||||||
@ -14,12 +16,22 @@ public class GetScrobbleCountService extends Service<ScrobbleCount>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ScrobbleCount call() throws Exception {
|
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());
|
return new ScrobbleCount(net.getScrobblesToday(), net.getUserScrobbleCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void failed() {
|
||||||
|
super.failed();
|
||||||
|
|
||||||
|
Logger.getLog().logError(new ErrorEntry("failed to get scrobble count"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ import javafx.scene.control.MenuItem;
|
|||||||
import sarsoo.fmframework.cache.TagPool;
|
import sarsoo.fmframework.cache.TagPool;
|
||||||
import sarsoo.fmframework.fx.FmFramework;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.fx.tab.FMObjListTab;
|
import sarsoo.fmframework.fx.tab.FMObjListTab;
|
||||||
|
import sarsoo.fmframework.log.Logger;
|
||||||
|
import sarsoo.fmframework.log.entry.ErrorEntry;
|
||||||
import sarsoo.fmframework.music.Tag;
|
import sarsoo.fmframework.music.Tag;
|
||||||
|
|
||||||
public class GetTagMenuItemsService extends Service<ArrayList<MenuItem>> {
|
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"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,14 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import javafx.concurrent.Service;
|
import javafx.concurrent.Service;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
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.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
|
@Override
|
||||||
protected Task<ArrayList<Tag>> createTask() {
|
protected Task<ArrayList<Tag>> createTask() {
|
||||||
@ -17,13 +19,23 @@ public class GetTagsService extends Service<ArrayList<Tag>>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ArrayList<Tag> call() throws Exception {
|
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();
|
return net.getTags();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void failed() {
|
||||||
|
super.failed();
|
||||||
|
|
||||||
|
Logger.getLog().logError(new ErrorEntry("failed to get tags"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,19 @@ package sarsoo.fmframework.jframe;
|
|||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.music.Artist;
|
import sarsoo.fmframework.music.Artist;
|
||||||
import sarsoo.fmframework.music.Track;
|
import sarsoo.fmframework.music.Track;
|
||||||
import sarsoo.fmframework.net.Key;
|
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
|
|
||||||
public class Getter {
|
public class Getter {
|
||||||
|
|
||||||
public static Album getAlbum() {
|
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");
|
String albumName = JOptionPane.showInputDialog(null, "Enter Album Name");
|
||||||
if (albumName != null) {
|
if (albumName != null) {
|
||||||
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
||||||
@ -24,7 +26,9 @@ public class Getter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Artist getArtist() {
|
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");
|
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
||||||
if (artistName != null) {
|
if (artistName != null) {
|
||||||
return net.getArtist(artistName);
|
return net.getArtist(artistName);
|
||||||
@ -33,7 +37,9 @@ public class Getter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Track getTrack() {
|
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");
|
String trackName = JOptionPane.showInputDialog(null, "Enter Track Name");
|
||||||
if (trackName != null) {
|
if (trackName != null) {
|
||||||
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
||||||
@ -45,7 +51,9 @@ public class Getter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Track getTrack(Album album) {
|
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");
|
String trackName = JOptionPane.showInputDialog(null, "Enter Track Name");
|
||||||
if (trackName != null) {
|
if (trackName != null) {
|
||||||
Track track = net.getTrack(trackName, album.getArtist().getName());
|
Track track = net.getTrack(trackName, album.getArtist().getName());
|
||||||
|
@ -3,10 +3,10 @@ package sarsoo.fmframework.music;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
import sarsoo.fmframework.net.Key;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.util.Maths;
|
import sarsoo.fmframework.util.Maths;
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
|
|
||||||
public abstract class FMObj implements Comparable<FMObj>, Serializable{
|
public abstract class FMObj implements Comparable<FMObj>, Serializable{
|
||||||
|
|
||||||
@ -64,7 +64,9 @@ public abstract class FMObj implements Comparable<FMObj>, Serializable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getPercent() {
|
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();
|
return ((double)userPlayCount*100)/(double) net.getUser().getScrobbleCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,12 +3,13 @@ package sarsoo.fmframework.util;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import sarsoo.fmframework.config.Config;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.music.Artist;
|
import sarsoo.fmframework.music.Artist;
|
||||||
import sarsoo.fmframework.music.FMObj;
|
import sarsoo.fmframework.music.FMObj;
|
||||||
import sarsoo.fmframework.music.Track;
|
import sarsoo.fmframework.music.Track;
|
||||||
import sarsoo.fmframework.net.Key;
|
|
||||||
|
|
||||||
public class FMObjList extends ArrayList<FMObj> implements Comparable<FMObjList>, Serializable {
|
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() {
|
public void refresh() {
|
||||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
Config config = FmFramework.getSessionConfig();
|
||||||
stream().forEach(item->net.refresh(item));
|
|
||||||
|
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
|
||||||
|
stream().forEach(item -> net.refresh(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,14 @@ import java.util.Date;
|
|||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.music.FMObj;
|
import sarsoo.fmframework.music.FMObj;
|
||||||
import sarsoo.fmframework.net.Key;
|
|
||||||
|
|
||||||
public class Maths {
|
public class Maths {
|
||||||
public static double getPercentListening(FMObj obj, String username) {
|
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();
|
double plays = (double) obj.getUserPlayCount();
|
||||||
if (userScrobbles > 0 && plays > 0) {
|
if (userScrobbles > 0 && plays > 0) {
|
||||||
|
|
||||||
@ -27,7 +28,8 @@ public class Maths {
|
|||||||
|
|
||||||
public static double getPercentListening(FMObjList objList, String username) {
|
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();
|
double plays = (double) objList.getTotalUserScrobbles();
|
||||||
if (userScrobbles > 0 && plays > 0) {
|
if (userScrobbles > 0 && plays > 0) {
|
||||||
|
|
||||||
@ -49,11 +51,11 @@ public class Maths {
|
|||||||
|
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
// System.out.println(date.getTime());
|
// System.out.println(date.getTime());
|
||||||
|
|
||||||
long diff = date.getTime() - calendar.getTime().getTime();
|
long diff = date.getTime() - calendar.getTime().getTime();
|
||||||
|
|
||||||
// System.out.println(diff/(1000*60*60*24));
|
// System.out.println(diff/(1000*60*60*24));
|
||||||
|
|
||||||
return (int) (diff/(1000*60*60*24));
|
return (int) (diff / (1000 * 60 * 60 * 24));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user