Fix LiveJasmin Followed tab

This commit is contained in:
0xb00bface 2022-02-19 15:21:55 +01:00
parent 83d6fd526e
commit 26bf338807
1 changed files with 21 additions and 24 deletions

View File

@ -1,19 +1,5 @@
package ctbrec.ui.sites.jasmin;
import static ctbrec.io.HttpConstants.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Future;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.GlobalThreadPool;
import ctbrec.Model;
@ -26,12 +12,25 @@ import javafx.concurrent.Task;
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Future;
import static ctbrec.io.HttpConstants.*;
public class LiveJasminFollowedUpdateService extends PaginatedScheduledService {
private static final Logger LOG = LoggerFactory.getLogger(LiveJasminFollowedUpdateService.class);
private LiveJasmin liveJasmin;
private String url;
private final LiveJasmin liveJasmin;
private final String url;
private boolean showOnline = true;
public LiveJasminFollowedUpdateService(LiveJasmin liveJasmin) {
@ -41,15 +40,15 @@ public class LiveJasminFollowedUpdateService extends PaginatedScheduledService {
@Override
protected Task<List<Model>> createTask() {
return new Task<List<Model>>() {
return new Task<>() {
@Override
public List<Model> call() throws IOException {
if(!liveJasmin.credentialsAvailable()) {
if (!liveJasmin.credentialsAvailable()) {
throw new RuntimeException("Credentials missing");
}
boolean loggedIn = SiteUiFactory.getUi(liveJasmin).login();
if(!loggedIn) {
if (!loggedIn) {
throw new RuntimeException("Couldn't login to livejasmin");
}
Request request = new Request.Builder()
@ -77,7 +76,7 @@ public class LiveJasminFollowedUpdateService extends PaginatedScheduledService {
}
LiveJasminModel model = (LiveJasminModel) liveJasmin.createModel(name);
model.setId(m.getString("id"));
model.setId(String.valueOf(m.get("id")));
model.setDisplayName(m.getString("display_name"));
Model.State onlineState = LiveJasminModel.mapStatus(m.getInt("status"));
boolean online = onlineState == Model.State.ONLINE;
@ -85,9 +84,7 @@ public class LiveJasminFollowedUpdateService extends PaginatedScheduledService {
if (online == showOnline) {
models.add(model);
}
loadDetailsFutures.add(GlobalThreadPool.submit(() -> {
loadModelDetails(model);
}));
loadDetailsFutures.add(GlobalThreadPool.submit(() -> loadModelDetails(model)));
}
for (Future<?> future : loadDetailsFutures) {
try {
@ -130,7 +127,7 @@ public class LiveJasminFollowedUpdateService extends PaginatedScheduledService {
}
}
}
} catch(IOException e) {
} catch (IOException e) {
// details couldn't be loaded, but that doesn't matter
}
}