Skip to content

Commit

Permalink
Always fit the translation for "Watched" on the thumbnail and reset t…
Browse files Browse the repository at this point in the history
…he cached version

It's still doing the calculations each time so caching will improve the speed a lot. When I tested it it was still loading quickly but it's a shame to waste those calculations
  • Loading branch information
SubJunk committed Aug 29, 2015
1 parent 986a603 commit 6553693
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
28 changes: 22 additions & 6 deletions src/main/java/net/pms/dlna/DLNAMediaInfo.java
Expand Up @@ -965,20 +965,36 @@ public void parse(InputFile inputFile, Format ext, int type, boolean thumbOnly,
/**
* TODO: Cache the calculated values
* TODO: Include and use a custom font
* TODO: Reset the thumbnail if the cached version is unwatched
* TODO: Lower the font size if the text doesn't fit within the thumbnail
*/
String text = Messages.getString("DLNAResource.4");
int fontSize = renderer.getThumbnailWidth() / 6;
int thumbnailWidth = renderer.getThumbnailWidth();
int fontSize = thumbnailWidth / 6;
Graphics2D g = image.createGraphics();
g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.6f));
g.fillRect(0, 0, renderer.getThumbnailWidth(), renderer.getThumbnailHeight());
g.fillRect(0, 0, thumbnailWidth, renderer.getThumbnailHeight());
g.setColor(new Color(0.9f, 0.9f, 0.9f, 1.0f));
g.setFont(new Font("Arial", Font.PLAIN, fontSize));
FontMetrics fm = g.getFontMetrics();
Rectangle2D textsize = fm.getStringBounds(text, g);
int horizontalPosition = (int) (renderer.getThumbnailWidth() - textsize.getWidth()) / 2;
int verticalPosition = (int) (renderer.getThumbnailHeight() - textsize.getHeight()) / 2 + fm.getAscent();
int textWidth = (int) textsize.getWidth();
int horizontalPosition = (thumbnailWidth - textWidth) / 2;

// Use a smaller font size if there isn't enough room
if (textWidth > thumbnailWidth) {
for (int divider = 7; divider < 99; divider++) {
fontSize = thumbnailWidth / divider;
g.setFont(new Font("Arial", Font.PLAIN, fontSize));
fm = g.getFontMetrics();
textsize = fm.getStringBounds(text, g);
textWidth = (int) textsize.getWidth();
if (textWidth <= (thumbnailWidth * 0.9)) {
horizontalPosition = (thumbnailWidth - textWidth) / 2;
break;
}
}
}

int verticalPosition = (int) (renderer.getThumbnailHeight() - textsize.getHeight()) / 2 + fm.getAscent();
g.drawString(text, horizontalPosition, verticalPosition);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/pms/dlna/DLNAResource.java
Expand Up @@ -980,7 +980,7 @@ public void updateChild(DLNAResource child) {
}

/**
* Adds the supplied DNLA resource in the internal list of child nodes,
* Adds the supplied DLNA resource in the internal list of child nodes,
* and sets the parent to the current node. Avoids the side-effects
* associated with the {@link #addChild(DLNAResource)} method.
*
Expand Down Expand Up @@ -3052,7 +3052,7 @@ protected void checkThumbnail(InputFile inputFile) {
protected void checkThumbnail(InputFile inputFile, RendererConfiguration renderer) {
// Use device-specific pms conf, if any
PmsConfiguration configuration = PMS.getConfiguration(renderer);
if (media != null && !media.isThumbready() && configuration.isThumbnailGenerationEnabled()) {
if (media != null && (!media.isThumbready() || MediaMonitor.isWatched(inputFile.getFile().getAbsolutePath())) && configuration.isThumbnailGenerationEnabled()) {
Double seekPosition = (double) configuration.getThumbnailSeekPos();
if (isResume()) {
Double resumePosition = (double) (resume.getTimeOffset() / 1000);
Expand Down

0 comments on commit 6553693

Please sign in to comment.