forked from j62/ctbrec
Code cleanup
This commit is contained in:
parent
43d2676e11
commit
447ab46e39
|
@ -4,6 +4,7 @@ import static ctbrec.Model.State.*;
|
|||
import static ctbrec.io.HttpConstants.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -328,35 +329,45 @@ public class ThumbCell extends StackPane {
|
|||
if (!Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
|
||||
boolean updateThumbs = Config.getInstance().getSettings().updateThumbnails;
|
||||
if (updateThumbs || iv.getImage() == null) {
|
||||
imageLoadingThreadPool.submit(() -> {
|
||||
Request req = new Request.Builder().url(url).header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent).build();
|
||||
try (Response resp = CamrecApplication.httpClient.execute(req)) {
|
||||
if (resp.isSuccessful()) {
|
||||
Image img = new Image(resp.body().byteStream(), 0, 360, true, true);
|
||||
if (img.progressProperty().get() == 1.0) {
|
||||
Platform.runLater(() -> {
|
||||
iv.setImage(img);
|
||||
setThumbWidth(Config.getInstance().getSettings().thumbWidth);
|
||||
});
|
||||
} else {
|
||||
img.progressProperty().addListener((ChangeListener<Number>) (observable, oldValue, newValue) -> {
|
||||
if (newValue.doubleValue() == 1.0) {
|
||||
iv.setImage(img);
|
||||
setThumbWidth(Config.getInstance().getSettings().thumbWidth);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw new HttpException(resp.code(), resp.message());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Error loading thumbnail: {}", e.getLocalizedMessage());
|
||||
}
|
||||
});
|
||||
imageLoadingThreadPool.submit(createThumbDownload(url));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable createThumbDownload(String url) {
|
||||
return () -> {
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(REFERER, getModel().getSite().getBaseUrl())
|
||||
.build();
|
||||
try (Response resp = CamrecApplication.httpClient.execute(req)) {
|
||||
if (resp.isSuccessful()) {
|
||||
Image img = new Image(resp.body().byteStream(), 0, 360, true, true);
|
||||
if (img.progressProperty().get() == 1.0) {
|
||||
Platform.runLater(() -> {
|
||||
iv.setImage(img);
|
||||
setThumbWidth(Config.getInstance().getSettings().thumbWidth);
|
||||
});
|
||||
} else {
|
||||
img.progressProperty().addListener((ChangeListener<Number>) (observable, oldValue, newValue) -> {
|
||||
if (newValue.doubleValue() == 1.0) {
|
||||
iv.setImage(img);
|
||||
setThumbWidth(Config.getInstance().getSettings().thumbWidth);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw new HttpException(resp.code(), resp.message());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Error loading thumbnail: {}", e.getLocalizedMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Image getImage() {
|
||||
return iv.getImage();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue