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 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() {
|
||||
@ -21,47 +21,49 @@ 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;
|
||||
|
||||
|
||||
public FMObjList getTag(String name) {
|
||||
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");
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(containedInPool) {
|
||||
|
||||
if (containedInPool) {
|
||||
System.out.println("returned from pool");
|
||||
return tagList.get(i);
|
||||
}else {
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
return tagList.get(i);
|
||||
} 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");
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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.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"));
|
||||
|
||||
@ -40,6 +48,10 @@ public class FmFramework extends Application {
|
||||
stage.show();
|
||||
|
||||
}
|
||||
|
||||
public static Config getSessionConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
@ -37,19 +37,21 @@ public class FMObjListPaneController {
|
||||
|
||||
@FXML
|
||||
private GridPane gridPaneFMObjs;
|
||||
|
||||
|
||||
@FXML
|
||||
private PieChart pieChart;
|
||||
|
||||
|
||||
@FXML
|
||||
private PieChart pieChartArtists;
|
||||
|
||||
|
||||
private FMObjList list;
|
||||
|
||||
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()));
|
||||
@ -64,9 +66,9 @@ public class FMObjListPaneController {
|
||||
FMObj obj = list.get(counter);
|
||||
|
||||
Label name = new Label(obj.getName().toLowerCase());
|
||||
|
||||
|
||||
name.getStyleClass().add("nameLabel");
|
||||
|
||||
|
||||
name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>() {
|
||||
|
||||
@Override
|
||||
@ -91,22 +93,23 @@ public class FMObjListPaneController {
|
||||
gridPaneFMObjs.add(totalScrobbles, 2, counter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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()));
|
||||
|
||||
ObservableList<PieChart.Data> pieChartArtistsData = FXCollections.observableArrayList();
|
||||
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());
|
||||
|
||||
|
||||
pieChartArtistsData.add(data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(pieChartArtistsData, new Comparator<PieChart.Data>() {
|
||||
|
||||
@Override
|
||||
@ -114,19 +117,23 @@ public class FMObjListPaneController {
|
||||
return (int) (arg1.getPieValue() - arg0.getPieValue());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
pieChart.setData(pieChartData);
|
||||
pieChartArtists.setData(pieChartArtistsData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@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()));
|
||||
@ -134,7 +141,7 @@ public class FMObjListPaneController {
|
||||
|
||||
Collections.sort(list);
|
||||
Collections.reverse(list);
|
||||
|
||||
|
||||
gridPaneFMObjs.getChildren().clear();
|
||||
|
||||
int counter;
|
||||
@ -143,9 +150,9 @@ public class FMObjListPaneController {
|
||||
FMObj obj = list.get(counter);
|
||||
|
||||
Label name = new Label(obj.getName().toLowerCase());
|
||||
|
||||
|
||||
name.getStyleClass().add("nameLabel");
|
||||
|
||||
|
||||
name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>() {
|
||||
|
||||
@Override
|
||||
@ -170,14 +177,13 @@ public class FMObjListPaneController {
|
||||
gridPaneFMObjs.add(totalScrobbles, 2, counter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
@ -140,28 +141,29 @@ 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;
|
||||
for (counter = 0; counter < list.size(); counter++) {
|
||||
|
||||
|
||||
newList.add(net.refresh(list.get(counter)));
|
||||
}
|
||||
|
||||
|
||||
setList(newList);
|
||||
}
|
||||
|
||||
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()));
|
||||
labelPercent.setText(String.format("%.2f%%", percent));
|
||||
|
||||
Collections.sort(list);
|
||||
|
||||
|
||||
Collections.reverse(list);
|
||||
|
||||
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(
|
||||
new PieChart.Data(String.format("%d%%", (int) list.getTotalUserScrobbles() * 100 / other),
|
||||
list.getTotalUserScrobbles()),
|
||||
@ -229,13 +234,13 @@ public class FMObjListPaneEditController {
|
||||
pieChart.setData(pieChartData);
|
||||
|
||||
ObservableList<PieChart.Data> pieChartArtistsData = FXCollections.observableArrayList();
|
||||
|
||||
|
||||
for (counter = 0; counter < list.size(); counter++) {
|
||||
|
||||
|
||||
PieChart.Data data = new PieChart.Data(list.get(counter).getName(), list.get(counter).getUserPlayCount());
|
||||
pieChartArtistsData.add(data);
|
||||
}
|
||||
|
||||
|
||||
pieChartArtists.setData(pieChartArtistsData);
|
||||
}
|
||||
|
||||
@ -248,8 +253,9 @@ 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();
|
||||
@ -260,10 +266,10 @@ public class FMObjListPaneEditController {
|
||||
if (album != null) {
|
||||
Album albumObj = net.getAlbum(album, artist);
|
||||
track.setAlbum(albumObj);
|
||||
|
||||
|
||||
textAlbum.setText(null);
|
||||
}
|
||||
|
||||
|
||||
textTrack.setText(null);
|
||||
textArtist.setText(null);
|
||||
|
||||
@ -276,8 +282,10 @@ 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,8 +303,9 @@ 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();
|
||||
|
||||
if (artist != null) {
|
||||
@ -304,27 +313,27 @@ public class FMObjListPaneEditController {
|
||||
Artist artistObj = net.getArtist(artist);
|
||||
|
||||
list.add(artistObj);
|
||||
|
||||
|
||||
textArtist.setText(null);
|
||||
}
|
||||
|
||||
refresh();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@FXML
|
||||
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) {
|
||||
|
||||
ListPersister persist = new ListPersister();
|
||||
persist.saveListToFile(file, list);
|
||||
|
||||
}
|
||||
if (file != null) {
|
||||
|
||||
ListPersister persist = new ListPersister();
|
||||
persist.saveListToFile(file, list);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
||||
@ -125,8 +123,10 @@ public class AlbumBorderPaneController extends FMObjBorderPaneController {
|
||||
return new Task<Void>() {
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
||||
@ -131,8 +129,10 @@ public class TrackBorderPaneController extends FMObjBorderPaneController {
|
||||
return new Task<Void>() {
|
||||
@Override
|
||||
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.setScrobbles(net.getTrackScrobbles(track));
|
||||
|
@ -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 {
|
||||
|
||||
@ -38,36 +30,34 @@ public class AlbumPaneController {
|
||||
|
||||
@FXML
|
||||
private Label labelTotalScrobbles;
|
||||
|
||||
|
||||
@FXML
|
||||
private TextArea textAreaWiki;
|
||||
|
||||
|
||||
@FXML
|
||||
private AnchorPane infoAnchorPane;
|
||||
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
|
||||
labelAlbumName.setText("Hello World");
|
||||
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
@ -75,65 +65,16 @@ public class AlbumPaneController {
|
||||
} 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());
|
||||
}else {
|
||||
|
||||
if (wiki != null) {
|
||||
|
||||
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());
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,21 +3,16 @@ 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;
|
||||
|
||||
@ -32,34 +27,31 @@ public class ArtistPaneController{
|
||||
|
||||
@FXML
|
||||
private Label labelTotalScrobbles;
|
||||
|
||||
|
||||
@FXML
|
||||
private TextArea textAreaWiki;
|
||||
|
||||
|
||||
@FXML
|
||||
private AnchorPane infoAnchorPane;
|
||||
|
||||
@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) {
|
||||
@ -67,44 +59,15 @@ public class ArtistPaneController{
|
||||
} 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());
|
||||
}else {
|
||||
|
||||
if (wiki != null) {
|
||||
|
||||
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());
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
@ -48,7 +39,7 @@ public class TrackPaneController {
|
||||
|
||||
@FXML
|
||||
private Button buttonViewAlbum;
|
||||
|
||||
|
||||
@FXML
|
||||
private AnchorPane infoAnchorPane;
|
||||
|
||||
@ -64,15 +55,15 @@ public class TrackPaneController {
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
labelTrackName.setText(track.getName());
|
||||
|
||||
|
||||
if (track.getAlbum() == null)
|
||||
labelAlbumName.setVisible(false);
|
||||
else
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
@ -15,12 +17,23 @@ 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"));
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
@ -14,12 +16,22 @@ 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"));
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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() {
|
||||
@ -17,13 +19,23 @@ 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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@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 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());
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
||||
@ -49,11 +51,11 @@ public class Maths {
|
||||
|
||||
Date date = new Date();
|
||||
// System.out.println(date.getTime());
|
||||
|
||||
|
||||
long diff = date.getTime() - calendar.getTime().getTime();
|
||||
|
||||
|
||||
// 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