threaded initial api calls

This commit is contained in:
aj 2018-04-19 14:01:01 -07:00
parent 31146c5452
commit d3413d15eb

View File

@ -3,6 +3,7 @@ package sarsoo.fmframework.fx.controller;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import javax.swing.JOptionPane;
@ -61,17 +62,32 @@ public class ControllerMain {
public void initialize() {
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());
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;
for (counter = 0; counter < tags.size(); counter++) {
@ -98,30 +114,19 @@ public class ControllerMain {
menuTag.getItems().add(item);
}
// FMObjList rap = Getter.getUserTag(Reference.getUserName(), "rap");
// FMObjList classicRap = Getter.getUserTag(Reference.getUserName(), "classic
// rap");
// FMObjList grime = Getter.getUserTag(Reference.getUserName(), "grime");
//
// int rapTotal = rap.getTotalUserScrobbles() -
// classicRap.getTotalUserScrobbles() - grime.getTotalUserScrobbles();
//
// 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);
//
// 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);
}finally{
latch.countDown();
}
}
});
latch.await();
//Keep with the background work
return null;
}
};
}
};
service.start();
}
@ -293,9 +298,11 @@ public class ControllerMain {
FMObjList classicRap = Getter.getUserTag(Reference.getUserName(), "classic rap");
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("grime", grime.getTotalUserScrobbles()));
@ -304,7 +311,8 @@ public class ControllerMain {
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));
new PieChart.Data("grime", grime.getTotalUserScrobbles()),
new PieChart.Data("other", other));
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() {
@ -313,7 +321,6 @@ public class ControllerMain {
try {
pieChartRap.setData(rapData);
pieChartRapTotal.setData(rapTotalData);
accordionCharts.setExpandedPane(titledPaneRap);