threaded initial api calls
This commit is contained in:
parent
31146c5452
commit
d3413d15eb
@ -3,6 +3,7 @@ package sarsoo.fmframework.fx.controller;
|
|||||||
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.Locale;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
@ -61,17 +62,32 @@ public class ControllerMain {
|
|||||||
public void initialize() {
|
public void initialize() {
|
||||||
Reference.setUserName("sarsoo");
|
Reference.setUserName("sarsoo");
|
||||||
|
|
||||||
labelStatsScrobblesToday.setText(Integer.toString(Getter.getScrobblesToday(Reference.getUserName())));
|
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||||
|
|
||||||
labelStatsUsername.setText(Reference.getUserName());
|
Service<Void> service = new Service<Void>() {
|
||||||
|
@Override
|
||||||
|
protected Task<Void> createTask() {
|
||||||
|
return new Task<Void>() {
|
||||||
|
@Override
|
||||||
|
protected Void call() throws Exception {
|
||||||
|
|
||||||
// updateGenrePieChart();
|
|
||||||
|
|
||||||
labelStatsScrobblesTotal
|
|
||||||
.setText(NumberFormat.getInstance().format(Getter.getScrobbles(Reference.getUserName())));
|
|
||||||
|
|
||||||
|
String scrobblesToday = numberFormat.format(Getter.getScrobblesToday(Reference.getUserName()));
|
||||||
|
String scrobbles = numberFormat.format(Getter.getScrobbles(Reference.getUserName()));
|
||||||
tags = Getter.getUserTags(Reference.getUserName());
|
tags = Getter.getUserTags(Reference.getUserName());
|
||||||
|
|
||||||
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try{
|
||||||
|
|
||||||
|
labelStatsScrobblesToday.setText(scrobblesToday);
|
||||||
|
labelStatsUsername.setText(Reference.getUserName());
|
||||||
|
labelStatsScrobblesTotal.setText(scrobbles);
|
||||||
|
|
||||||
|
refreshPieCharts();
|
||||||
|
|
||||||
int counter;
|
int counter;
|
||||||
for (counter = 0; counter < tags.size(); counter++) {
|
for (counter = 0; counter < tags.size(); counter++) {
|
||||||
|
|
||||||
@ -98,30 +114,19 @@ public class ControllerMain {
|
|||||||
menuTag.getItems().add(item);
|
menuTag.getItems().add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FMObjList rap = Getter.getUserTag(Reference.getUserName(), "rap");
|
}finally{
|
||||||
// FMObjList classicRap = Getter.getUserTag(Reference.getUserName(), "classic
|
latch.countDown();
|
||||||
// rap");
|
}
|
||||||
// FMObjList grime = Getter.getUserTag(Reference.getUserName(), "grime");
|
}
|
||||||
//
|
});
|
||||||
// int rapTotal = rap.getTotalUserScrobbles() -
|
latch.await();
|
||||||
// classicRap.getTotalUserScrobbles() - grime.getTotalUserScrobbles();
|
//Keep with the background work
|
||||||
//
|
return null;
|
||||||
// ObservableList<PieChart.Data> rapData = FXCollections.observableArrayList(
|
}
|
||||||
// new PieChart.Data("rap", rapTotal),
|
};
|
||||||
// new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()),
|
}
|
||||||
// new PieChart.Data("grime", grime.getTotalUserScrobbles()));
|
};
|
||||||
// pieChartRap.setData(rapData);
|
service.start();
|
||||||
//
|
|
||||||
// int other = Getter.getScrobbles(Reference.getUserName()) -
|
|
||||||
// rap.getTotalUserScrobbles();
|
|
||||||
//
|
|
||||||
// ObservableList<PieChart.Data> rapTotalData =
|
|
||||||
// FXCollections.observableArrayList(
|
|
||||||
// new PieChart.Data("rap", rapTotal),
|
|
||||||
// new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()),
|
|
||||||
// new PieChart.Data("grime", grime.getTotalUserScrobbles()),
|
|
||||||
// new PieChart.Data("other", other));
|
|
||||||
// pieChartRapTotal.setData(rapTotalData);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,9 +298,11 @@ public class ControllerMain {
|
|||||||
FMObjList classicRap = Getter.getUserTag(Reference.getUserName(), "classic rap");
|
FMObjList classicRap = Getter.getUserTag(Reference.getUserName(), "classic rap");
|
||||||
FMObjList grime = Getter.getUserTag(Reference.getUserName(), "grime");
|
FMObjList grime = Getter.getUserTag(Reference.getUserName(), "grime");
|
||||||
|
|
||||||
int rapTotal = rap.getTotalUserScrobbles() - classicRap.getTotalUserScrobbles() - grime.getTotalUserScrobbles();
|
int rapTotal = rap.getTotalUserScrobbles() - classicRap.getTotalUserScrobbles()
|
||||||
|
- grime.getTotalUserScrobbles();
|
||||||
|
|
||||||
ObservableList<PieChart.Data> rapData = FXCollections.observableArrayList(new PieChart.Data("rap", rapTotal),
|
ObservableList<PieChart.Data> rapData = FXCollections.observableArrayList(
|
||||||
|
new PieChart.Data("rap", rapTotal),
|
||||||
new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()),
|
new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()),
|
||||||
new PieChart.Data("grime", grime.getTotalUserScrobbles()));
|
new PieChart.Data("grime", grime.getTotalUserScrobbles()));
|
||||||
|
|
||||||
@ -304,7 +311,8 @@ public class ControllerMain {
|
|||||||
ObservableList<PieChart.Data> rapTotalData = FXCollections.observableArrayList(
|
ObservableList<PieChart.Data> rapTotalData = FXCollections.observableArrayList(
|
||||||
new PieChart.Data("rap", rapTotal),
|
new PieChart.Data("rap", rapTotal),
|
||||||
new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()),
|
new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()),
|
||||||
new PieChart.Data("grime", grime.getTotalUserScrobbles()), new PieChart.Data("other", other));
|
new PieChart.Data("grime", grime.getTotalUserScrobbles()),
|
||||||
|
new PieChart.Data("other", other));
|
||||||
|
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
Platform.runLater(new Runnable() {
|
Platform.runLater(new Runnable() {
|
||||||
@ -313,7 +321,6 @@ public class ControllerMain {
|
|||||||
try {
|
try {
|
||||||
pieChartRap.setData(rapData);
|
pieChartRap.setData(rapData);
|
||||||
|
|
||||||
|
|
||||||
pieChartRapTotal.setData(rapTotalData);
|
pieChartRapTotal.setData(rapTotalData);
|
||||||
|
|
||||||
accordionCharts.setExpandedPane(titledPaneRap);
|
accordionCharts.setExpandedPane(titledPaneRap);
|
||||||
|
Loading…
Reference in New Issue
Block a user