added artist scrobble getting
This commit is contained in:
parent
d9fb9195f9
commit
f9b81093db
@ -4,6 +4,7 @@ import java.text.NumberFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
@ -48,8 +49,13 @@ public class ScrobblesViewPaneController {
|
||||
|
||||
@FXML
|
||||
private CheckBox checkBoxCumulative;
|
||||
|
||||
@FXML
|
||||
private CheckBox checkBoxTotal;
|
||||
|
||||
private FMObj obj;
|
||||
|
||||
private List<Scrobble> scrobbles;
|
||||
|
||||
private LocalDate firstDate;
|
||||
|
||||
@ -63,10 +69,19 @@ public class ScrobblesViewPaneController {
|
||||
}
|
||||
|
||||
public void populate(FMObj obj) {
|
||||
|
||||
this.obj = obj;
|
||||
|
||||
ArrayList<Scrobble> scrobbles = obj.getScrobbles();
|
||||
this.scrobbles = obj.getScrobbles();
|
||||
populate();
|
||||
}
|
||||
|
||||
public void populate(ArrayList<Scrobble> scrobbles) {
|
||||
this.scrobbles = scrobbles;
|
||||
populate();
|
||||
}
|
||||
|
||||
private void populate() {
|
||||
|
||||
scrobbles.sort(Comparator.comparing(Scrobble::getDateTime).reversed());
|
||||
|
||||
if (scrobbles != null) {
|
||||
if (scrobbles.size() > 0) {
|
||||
@ -115,7 +130,7 @@ public class ScrobblesViewPaneController {
|
||||
|
||||
ScrobbleCountCalendar totalCalendar = new ScrobbleCountCalendar(firstDate, "total");
|
||||
|
||||
for (Scrobble scrobble : obj.getScrobbles()) {
|
||||
for (Scrobble scrobble : scrobbles) {
|
||||
|
||||
Boolean needNew = true;
|
||||
|
||||
@ -145,7 +160,7 @@ public class ScrobblesViewPaneController {
|
||||
List<ScrobbleCountCalendar> toShow = list.stream().map(FMObjCalendarWrapper::getCalendar)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (list.size() > 1) {
|
||||
if (list.size() > 1 && checkBoxTotal.isSelected()) {
|
||||
toShow.add(totalCalendar);
|
||||
}
|
||||
|
||||
@ -159,7 +174,7 @@ public class ScrobblesViewPaneController {
|
||||
|
||||
ScrobbleCountCalendar totalCalendar = new ScrobbleCountCalendar(firstDate, "total");
|
||||
|
||||
for (Scrobble scrobble : obj.getScrobbles()) {
|
||||
for (Scrobble scrobble : scrobbles) {
|
||||
|
||||
Boolean needNew = true;
|
||||
|
||||
@ -189,7 +204,7 @@ public class ScrobblesViewPaneController {
|
||||
List<ScrobbleCountCalendar> toShow = list.stream().map(FMObjCalendarWrapper::getCalendar)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (list.size() > 1) {
|
||||
if (list.size() > 1 && checkBoxTotal.isSelected()) {
|
||||
toShow.add(totalCalendar);
|
||||
}
|
||||
|
||||
@ -203,7 +218,7 @@ public class ScrobblesViewPaneController {
|
||||
|
||||
ScrobbleCountCalendar totalCalendar = new ScrobbleCountCalendar(firstDate, "total");
|
||||
|
||||
for (Scrobble scrobble : obj.getScrobbles()) {
|
||||
for (Scrobble scrobble : scrobbles) {
|
||||
|
||||
Boolean needNew = true;
|
||||
|
||||
@ -221,7 +236,7 @@ public class ScrobblesViewPaneController {
|
||||
|
||||
if (needNew) {
|
||||
|
||||
ScrobbleCountCalendar calendar = new ScrobbleCountCalendar(firstDate, scrobble.getAlbum().getName());
|
||||
ScrobbleCountCalendar calendar = new ScrobbleCountCalendar(firstDate, scrobble.getTrack().getName() + " / " + scrobble.getAlbum().getName());
|
||||
|
||||
calendar.addCount(scrobbleDate.getMonth(), scrobbleDate.getYear());
|
||||
|
||||
@ -234,7 +249,7 @@ public class ScrobblesViewPaneController {
|
||||
List<ScrobbleCountCalendar> toShow = list.stream().map(FMObjCalendarWrapper::getCalendar)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (list.size() > 1) {
|
||||
if (list.size() > 1 && checkBoxTotal.isSelected()) {
|
||||
toShow.add(totalCalendar);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.concurrent.Service;
|
||||
@ -17,6 +18,9 @@ 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.music.Scrobble;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
|
||||
public class ArtistBorderPaneController extends FMObjBorderPaneController{
|
||||
|
||||
@ -91,12 +95,26 @@ public class ArtistBorderPaneController extends FMObjBorderPaneController{
|
||||
protected Void call() throws Exception {
|
||||
|
||||
artist = FmFramework.getArtistPool().getNew(artist);
|
||||
|
||||
Config config = FmFramework.getSessionConfig();
|
||||
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
|
||||
|
||||
FMObjList topTracks = net.getArtistTopTracks(artist, 10);
|
||||
|
||||
ArrayList<Scrobble> scrobbles = new ArrayList<>();
|
||||
|
||||
topTracks.stream().forEach(t -> {
|
||||
|
||||
scrobbles.addAll(net.getTrackScrobbles((Track) t));
|
||||
|
||||
});
|
||||
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
infoPaneController.refresh(artist);
|
||||
scrobblePaneController.populate(scrobbles);
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -9,41 +9,46 @@ import sarsoo.fmframework.log.Logger;
|
||||
import sarsoo.fmframework.log.entry.ErrorEntry;
|
||||
|
||||
public class ScrobbleCountCalendar {
|
||||
|
||||
|
||||
private ArrayList<MonthScrobbles> months;
|
||||
private String name;
|
||||
|
||||
|
||||
public ScrobbleCountCalendar(LocalDate date, String name) {
|
||||
|
||||
|
||||
months = new ArrayList<>();
|
||||
this.name = name;
|
||||
|
||||
|
||||
LocalDate now = LocalDate.now();
|
||||
|
||||
long monthsDiff = ChronoUnit.MONTHS.between(date, now) + 1;
|
||||
|
||||
for(int i = 0; i < monthsDiff; i++) {
|
||||
|
||||
for (int i = 0; i < monthsDiff; i++) {
|
||||
LocalDate counter = date.plusMonths(i);
|
||||
|
||||
|
||||
months.add(new MonthScrobbles(counter.getMonth(), counter.getYear()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void addCount(Month monthIn, int year) {
|
||||
|
||||
for(MonthScrobbles month: months) {
|
||||
if(month.getMonth().getValue() == monthIn.getValue() && year == month.getYear()) {
|
||||
|
||||
Boolean found = false;
|
||||
|
||||
for (MonthScrobbles month : months) {
|
||||
if (month.getMonth().getValue() == monthIn.getValue() && year == month.getYear()) {
|
||||
month.addCount();
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.getLog().logError(new ErrorEntry("ScrobbleCountCalendar").addArg("add count").addArg("month not found"));
|
||||
|
||||
|
||||
if (found == false)
|
||||
Logger.getLog().logError(new ErrorEntry("ScrobbleCountCalendar").addArg("add count")
|
||||
.addArg("month not found").addArg(monthIn.toString()).addArg(Integer.toString(year)));
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<MonthScrobbles> getMonthScrobbles(){
|
||||
|
||||
public ArrayList<MonthScrobbles> getMonthScrobbles() {
|
||||
return months;
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@
|
||||
<Button fx:id="buttonAlbums" mnemonicParsing="false" onAction="#handleShowAlbums" text="albums" />
|
||||
<Button fx:id="buttonTracksAlbums" mnemonicParsing="false" onAction="#handleShowTracksByAlbums" text="tracks & albums" />
|
||||
<CheckBox fx:id="checkBoxCumulative" mnemonicParsing="false" selected="true" text="cumulative" />
|
||||
<CheckBox fx:id="checkBoxTotal" mnemonicParsing="false" selected="true" text="show total" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
</bottom>
|
||||
|
Loading…
Reference in New Issue
Block a user