From 52a2e86be528abf15c3f91faf012bf34e93ef236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Strau=C3=9F?= Date: Thu, 20 Aug 2015 23:55:50 +0200 Subject: [PATCH] improve "felt" performance by decoupling preview retrieval from metadata retrieval --- .../skadi/remote/ChannelDataRetriever.java | 9 +-------- .../java/eu/over9000/skadi/ui/MainWindow.java | 1 - .../java/eu/over9000/skadi/util/ImageUtil.java | 8 +++----- ...mageRequest.java => AsyncImageUpdateTask.java} | 15 ++++++++++----- 4 files changed, 14 insertions(+), 19 deletions(-) rename src/main/java/eu/over9000/skadi/util/helper/{AsyncImageRequest.java => AsyncImageUpdateTask.java} (79%) diff --git a/src/main/java/eu/over9000/skadi/remote/ChannelDataRetriever.java b/src/main/java/eu/over9000/skadi/remote/ChannelDataRetriever.java index 0fa9580..b2d564e 100644 --- a/src/main/java/eu/over9000/skadi/remote/ChannelDataRetriever.java +++ b/src/main/java/eu/over9000/skadi/remote/ChannelDataRetriever.java @@ -30,9 +30,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; -import java.util.concurrent.Future; - -import javafx.scene.image.Image; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -73,7 +70,7 @@ private static long getChannelUptime(final JsonObject channelObject) throws Pars public static ChannelMetadata getChannelMetadata(final Channel channel) { try { - final Future preview = ImageUtil.getPreviewAsyncFromTwitch(channel); + ImageUtil.getPreviewAsyncFromTwitch(channel); final JsonObject streamResponse = getStreamData(channel.getName()); final ChannelMetadataBuilder builder = new ChannelMetadataBuilder(); @@ -106,10 +103,6 @@ public static ChannelMetadata getChannelMetadata(final Channel channel) { builder.setFollowers(getIntIfPresent("followers", channelObject)); builder.setPartner(getBoolIfPresent("partner", channelObject)); - if (preview != null) { - builder.setPreview(preview.get()); - } - return builder.build(); } catch (final Exception e) { LOGGER.error("Exception getting metadata for channel " + channel + ": " + e.getMessage()); diff --git a/src/main/java/eu/over9000/skadi/ui/MainWindow.java b/src/main/java/eu/over9000/skadi/ui/MainWindow.java index 94838c9..07c5831 100644 --- a/src/main/java/eu/over9000/skadi/ui/MainWindow.java +++ b/src/main/java/eu/over9000/skadi/ui/MainWindow.java @@ -538,7 +538,6 @@ private void bindColumnWidths() { gameCol.prefWidthProperty().bind(tcw.multiply(0.2)); viewerCol.prefWidthProperty().bind(tcw.multiply(0.075)); uptimeCol.prefWidthProperty().bind(tcw.multiply(0.125)); - } public void doDetailSlide(final boolean doOpen) { diff --git a/src/main/java/eu/over9000/skadi/util/ImageUtil.java b/src/main/java/eu/over9000/skadi/util/ImageUtil.java index c418a0e..244be6e 100644 --- a/src/main/java/eu/over9000/skadi/util/ImageUtil.java +++ b/src/main/java/eu/over9000/skadi/util/ImageUtil.java @@ -26,7 +26,6 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.concurrent.Future; import javafx.scene.image.Image; import javafx.scene.image.ImageView; @@ -35,7 +34,7 @@ import org.slf4j.LoggerFactory; import eu.over9000.skadi.model.Channel; -import eu.over9000.skadi.util.helper.AsyncImageRequest; +import eu.over9000.skadi.util.helper.AsyncImageUpdateTask; public class ImageUtil { @@ -76,13 +75,12 @@ public static ImageView getChannelLogo(final String logoURL) { return iv; } - public static Future getPreviewAsyncFromTwitch(final Channel channel) { + public static void getPreviewAsyncFromTwitch(final Channel channel) { try { final String url = String.format(BASE_URL_PREVIEW, URLEncoder.encode(channel.getName().toLowerCase(), "UTF-8")); - return ExecutorServiceAccess.getExecutorService().submit(new AsyncImageRequest(url)); + ExecutorServiceAccess.getExecutorService().submit(new AsyncImageUpdateTask(channel, url)); } catch (final UnsupportedEncodingException e) { LOGGER.error("exception getting channel preview for " + channel, e); - return null; } } } diff --git a/src/main/java/eu/over9000/skadi/util/helper/AsyncImageRequest.java b/src/main/java/eu/over9000/skadi/util/helper/AsyncImageUpdateTask.java similarity index 79% rename from src/main/java/eu/over9000/skadi/util/helper/AsyncImageRequest.java rename to src/main/java/eu/over9000/skadi/util/helper/AsyncImageUpdateTask.java index 0f3cfab..1247314 100644 --- a/src/main/java/eu/over9000/skadi/util/helper/AsyncImageRequest.java +++ b/src/main/java/eu/over9000/skadi/util/helper/AsyncImageUpdateTask.java @@ -28,15 +28,20 @@ import javafx.scene.image.Image; -public class AsyncImageRequest implements Callable { - private final String url; +import eu.over9000.skadi.model.Channel; - public AsyncImageRequest(final String url) { +public class AsyncImageUpdateTask implements Callable { + private final Channel channel; + private String url; + + public AsyncImageUpdateTask(final Channel channel, final String url) { + this.channel = channel; this.url = url; } @Override - public Image call() throws Exception { - return new Image(url); + public Void call() throws Exception { + channel.setPreview(new Image(url)); + return null; } } \ No newline at end of file