Fix Camsoda followed tab
This commit is contained in:
parent
947994f524
commit
f7fc33afd6
|
@ -1,7 +1,5 @@
|
|||
package ctbrec.ui.sites.camsoda;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import ctbrec.sites.camsoda.Camsoda;
|
||||
import ctbrec.sites.camsoda.CamsodaModel;
|
||||
import ctbrec.ui.tabs.FollowedTab;
|
||||
|
@ -16,15 +14,17 @@ import javafx.scene.input.KeyCode;
|
|||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.HBox;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CamsodaFollowedTab extends ThumbOverviewTab implements FollowedTab {
|
||||
private Label status;
|
||||
private final Label status;
|
||||
boolean showOnline = true;
|
||||
|
||||
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...");
|
||||
grid.getChildren().add(status);
|
||||
((CamsodaUpdateService)updateService).setFilter(createFilter(this));
|
||||
((CamsodaUpdateService) updateService).setFilter(createFilter(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,7 +85,7 @@ public class CamsodaFollowedTab extends ThumbOverviewTab implements FollowedTab
|
|||
return m -> {
|
||||
try {
|
||||
return m.isOnline() == tab.showOnline;
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -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 final String url;
|
||||
private final boolean loginRequired;
|
||||
private final Camsoda camsoda;
|
||||
int modelsPerPage = 50;
|
||||
protected final String url;
|
||||
protected final boolean loginRequired;
|
||||
protected final Camsoda camsoda;
|
||||
protected int modelsPerPage = 50;
|
||||
|
||||
private Predicate<CamsodaModel> filter;
|
||||
protected Predicate<CamsodaModel> filter;
|
||||
|
||||
public CamsodaUpdateService(String url, boolean loginRequired, Camsoda camsoda, Predicate<CamsodaModel> filter) {
|
||||
this.url = url;
|
||||
|
@ -51,7 +51,7 @@ public class CamsodaUpdateService extends PaginatedScheduledService {
|
|||
.filter(filter)
|
||||
.skip((page - 1) * (long) 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<>();
|
||||
var json = new JSONObject(body);
|
||||
var template = json.getJSONArray("template");
|
||||
|
|
|
@ -64,8 +64,7 @@ public class CamsodaModel extends AbstractModel {
|
|||
StringBuilder url = new StringBuilder("https://");
|
||||
url.append(edgeServer).append('/');
|
||||
url.append(streamName);
|
||||
url.append("_v1");
|
||||
url.append("/index.m3u8");
|
||||
url.append("_v1/index.m3u8");
|
||||
if (!isPublic(streamName)) {
|
||||
url.append("?token=").append(token);
|
||||
}
|
||||
|
@ -194,14 +193,12 @@ public class CamsodaModel extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
|
||||
if (failFast) {
|
||||
return onlineState;
|
||||
} else {
|
||||
if (!failFast) {
|
||||
if (onlineState == UNKNOWN) {
|
||||
loadModel();
|
||||
}
|
||||
return onlineState;
|
||||
}
|
||||
return onlineState;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue