Fix Camsoda followed tab
This commit is contained in:
parent
947994f524
commit
f7fc33afd6
|
@ -1,7 +1,5 @@
|
||||||
package ctbrec.ui.sites.camsoda;
|
package ctbrec.ui.sites.camsoda;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import ctbrec.sites.camsoda.Camsoda;
|
import ctbrec.sites.camsoda.Camsoda;
|
||||||
import ctbrec.sites.camsoda.CamsodaModel;
|
import ctbrec.sites.camsoda.CamsodaModel;
|
||||||
import ctbrec.ui.tabs.FollowedTab;
|
import ctbrec.ui.tabs.FollowedTab;
|
||||||
|
@ -16,12 +14,14 @@ import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class CamsodaFollowedTab extends ThumbOverviewTab implements FollowedTab {
|
public class CamsodaFollowedTab extends ThumbOverviewTab implements FollowedTab {
|
||||||
private Label status;
|
private final Label status;
|
||||||
boolean showOnline = true;
|
boolean showOnline = true;
|
||||||
|
|
||||||
public CamsodaFollowedTab(String title, Camsoda camsoda) {
|
public CamsodaFollowedTab(String title, Camsoda camsoda) {
|
||||||
super(title, new CamsodaUpdateService(camsoda.getBaseUrl() + "/api/v1/browse/following", true, camsoda, m -> true), camsoda);
|
super(title, new CamsodaFollowedUpdateService(camsoda.getBaseUrl() + "/api/v1/browse/react/followed", true, camsoda, m -> true), camsoda);
|
||||||
status = new Label("Logging in...");
|
status = new Label("Logging in...");
|
||||||
grid.getChildren().add(status);
|
grid.getChildren().add(status);
|
||||||
((CamsodaUpdateService) updateService).setFilter(createFilter(this));
|
((CamsodaUpdateService) updateService).setFilter(createFilter(this));
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package ctbrec.ui.sites.camsoda;
|
||||||
|
|
||||||
|
import ctbrec.sites.camsoda.Camsoda;
|
||||||
|
import ctbrec.sites.camsoda.CamsodaModel;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class CamsodaFollowedUpdateService extends CamsodaUpdateService {
|
||||||
|
|
||||||
|
public CamsodaFollowedUpdateService(String url, boolean loginRequired, Camsoda camsoda, Predicate<CamsodaModel> filter) {
|
||||||
|
super(url, loginRequired, camsoda, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<CamsodaModel> parseModels(String body) {
|
||||||
|
List<CamsodaModel> models = new ArrayList<>();
|
||||||
|
var json = new JSONObject(body);
|
||||||
|
var userList = json.getJSONArray("userList");
|
||||||
|
for (var i = 0; i < userList.length(); i++) {
|
||||||
|
var jsonModel = userList.getJSONObject(i);
|
||||||
|
CamsodaModel model = (CamsodaModel) camsoda.createModel(jsonModel.getString("username"));
|
||||||
|
model.setDisplayName(jsonModel.optString("displayName"));
|
||||||
|
model.setPreview(jsonModel.optString("thumbUrl"));
|
||||||
|
model.setDescription(jsonModel.optString("subjectText"));
|
||||||
|
model.setOnlineStateByStatus(jsonModel.optString("status"));
|
||||||
|
models.add(model);
|
||||||
|
}
|
||||||
|
return models;
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,12 +27,12 @@ public class CamsodaUpdateService extends PaginatedScheduledService {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(CamsodaUpdateService.class);
|
private static final Logger LOG = LoggerFactory.getLogger(CamsodaUpdateService.class);
|
||||||
|
|
||||||
private final String url;
|
protected final String url;
|
||||||
private final boolean loginRequired;
|
protected final boolean loginRequired;
|
||||||
private final Camsoda camsoda;
|
protected final Camsoda camsoda;
|
||||||
int modelsPerPage = 50;
|
protected int modelsPerPage = 50;
|
||||||
|
|
||||||
private Predicate<CamsodaModel> filter;
|
protected Predicate<CamsodaModel> filter;
|
||||||
|
|
||||||
public CamsodaUpdateService(String url, boolean loginRequired, Camsoda camsoda, Predicate<CamsodaModel> filter) {
|
public CamsodaUpdateService(String url, boolean loginRequired, Camsoda camsoda, Predicate<CamsodaModel> filter) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
@ -51,7 +51,7 @@ public class CamsodaUpdateService extends PaginatedScheduledService {
|
||||||
.filter(filter)
|
.filter(filter)
|
||||||
.skip((page - 1) * (long) modelsPerPage)
|
.skip((page - 1) * (long) modelsPerPage)
|
||||||
.limit(modelsPerPage)
|
.limit(modelsPerPage)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList()); // NOSONAR
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ public class CamsodaUpdateService extends PaginatedScheduledService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CamsodaModel> parseModels(String body) {
|
protected List<CamsodaModel> parseModels(String body) {
|
||||||
List<CamsodaModel> models = new ArrayList<>();
|
List<CamsodaModel> models = new ArrayList<>();
|
||||||
var json = new JSONObject(body);
|
var json = new JSONObject(body);
|
||||||
var template = json.getJSONArray("template");
|
var template = json.getJSONArray("template");
|
||||||
|
|
|
@ -64,8 +64,7 @@ public class CamsodaModel extends AbstractModel {
|
||||||
StringBuilder url = new StringBuilder("https://");
|
StringBuilder url = new StringBuilder("https://");
|
||||||
url.append(edgeServer).append('/');
|
url.append(edgeServer).append('/');
|
||||||
url.append(streamName);
|
url.append(streamName);
|
||||||
url.append("_v1");
|
url.append("_v1/index.m3u8");
|
||||||
url.append("/index.m3u8");
|
|
||||||
if (!isPublic(streamName)) {
|
if (!isPublic(streamName)) {
|
||||||
url.append("?token=").append(token);
|
url.append("?token=").append(token);
|
||||||
}
|
}
|
||||||
|
@ -194,14 +193,12 @@ public class CamsodaModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
|
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
|
||||||
if (failFast) {
|
if (!failFast) {
|
||||||
return onlineState;
|
|
||||||
} else {
|
|
||||||
if (onlineState == UNKNOWN) {
|
if (onlineState == UNKNOWN) {
|
||||||
loadModel();
|
loadModel();
|
||||||
}
|
}
|
||||||
return onlineState;
|
|
||||||
}
|
}
|
||||||
|
return onlineState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue