Skip to content

Commit

Permalink
improve "felt" performance by decoupling preview retrieval from metad…
Browse files Browse the repository at this point in the history
…ata retrieval
  • Loading branch information
s1mpl3x committed Aug 20, 2015
1 parent c158f85 commit 52a2e86
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,7 +70,7 @@ private static long getChannelUptime(final JsonObject channelObject) throws Pars
public static ChannelMetadata getChannelMetadata(final Channel channel) {

try {
final Future<Image> preview = ImageUtil.getPreviewAsyncFromTwitch(channel);
ImageUtil.getPreviewAsyncFromTwitch(channel);

final JsonObject streamResponse = getStreamData(channel.getName());
final ChannelMetadataBuilder builder = new ChannelMetadataBuilder();
Expand Down Expand Up @@ -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());
Expand Down
1 change: 0 additions & 1 deletion src/main/java/eu/over9000/skadi/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/eu/over9000/skadi/util/ImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -76,13 +75,12 @@ public static ImageView getChannelLogo(final String logoURL) {
return iv;
}

public static Future<Image> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@

import javafx.scene.image.Image;

public class AsyncImageRequest implements Callable<Image> {
private final String url;
import eu.over9000.skadi.model.Channel;

public AsyncImageRequest(final String url) {
public class AsyncImageUpdateTask implements Callable<Void> {
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;
}
}

0 comments on commit 52a2e86

Please sign in to comment.