Change comments.
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / triggers / NewEpisodeTrigger.java
index 5fc4537..4d97868 100644 (file)
@@ -136,7 +136,7 @@ public class NewEpisodeTrigger implements Trigger {
        }
 
        //
-       // STATIC METHODS
+       // PRIVATE METHODS
        //
 
        /**
@@ -212,59 +212,52 @@ public class NewEpisodeTrigger implements Trigger {
        private String generateHtmlText(Reaction reaction) {
                StringBuilder htmlBuilder = new StringBuilder();
                htmlBuilder.append("<html><body>\n");
-               htmlBuilder.append("<h1>").append(StringEscapeUtils.escapeHtml4(reaction.name())).append("</h1>\n");
-               if (!newEpisodes.isEmpty()) {
-                       htmlBuilder.append("<h2>New Episodes</h2>\n");
-                       htmlBuilder.append("<ul>\n");
-                       for (Episode episode : newEpisodes) {
-                               htmlBuilder.append("<li>Season ").append(episode.season()).append(", Episode ").append(episode.episode()).append("</li>\n");
-                               htmlBuilder.append("<ul>\n");
-                               for (TorrentFile torrentFile : episode) {
-                                       htmlBuilder.append("<li>").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append("</li>\n");
-                                       htmlBuilder.append("<div>");
-                                       htmlBuilder.append("<strong>").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append("</strong>, ");
-                                       htmlBuilder.append("<strong>").append(torrentFile.fileCount()).append("</strong> file(s), ");
-                                       htmlBuilder.append("<strong>").append(torrentFile.seedCount()).append("</strong> seed(s), ");
-                                       htmlBuilder.append("<strong>").append(torrentFile.leechCount()).append("</strong> leecher(s)</div>\n");
-                                       htmlBuilder.append("<div>");
-                                       if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) {
-                                               htmlBuilder.append("<a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())).append("\">Magnet</a> ");
-                                       }
-                                       if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) {
-                                               htmlBuilder.append("<a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())).append("\">Download</a>");
-                                       }
-                                       htmlBuilder.append("</div>\n");
-                               }
-                               htmlBuilder.append("</ul>\n");
-                       }
-                       htmlBuilder.append("</ul>\n");
-               }
-               if (!changedEpisodes.isEmpty()) {
-                       htmlBuilder.append("<h2>Changed Episodes</h2>\n");
-                       htmlBuilder.append("<ul>\n");
-                       for (Episode episode : changedEpisodes) {
-                               htmlBuilder.append("<li>Season ").append(episode.season()).append(", Episode ").append(episode.episode()).append("</li>\n");
-                               htmlBuilder.append("<ul>\n");
+               /* show all known episodes. */
+               htmlBuilder.append("<table>\n<caption>All Known Episodes</caption>\n");
+               htmlBuilder.append("<thead>\n");
+               htmlBuilder.append("<tr>");
+               htmlBuilder.append("<th>Season</th>");
+               htmlBuilder.append("<th>Episode</th>");
+               htmlBuilder.append("<th>Filename</th>");
+               htmlBuilder.append("<th>Size</th>");
+               htmlBuilder.append("<th>File(s)</th>");
+               htmlBuilder.append("<th>Seeds</th>");
+               htmlBuilder.append("<th>Leechers</th>");
+               htmlBuilder.append("<th>Magnet</th>");
+               htmlBuilder.append("<th>Download</th>");
+               htmlBuilder.append("</tr>\n");
+               htmlBuilder.append("</thead>\n");
+               htmlBuilder.append("<tbody>\n");
+               Episode lastEpisode = null;
+               for (Entry<Integer, Collection<Episode>> seasonEntry : FluentIterable.from(Ordering.natural().reverse().sortedCopy(allEpisodes)).index(Episode.BY_SEASON).asMap().entrySet()) {
+                       for (Episode episode : seasonEntry.getValue()) {
                                for (TorrentFile torrentFile : episode) {
-                                       htmlBuilder.append("<li>").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append("</li>\n");
-                                       htmlBuilder.append("<div>");
-                                       htmlBuilder.append("<strong>").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append("</strong>, ");
-                                       htmlBuilder.append("<strong>").append(torrentFile.fileCount()).append("</strong> file(s), ");
-                                       htmlBuilder.append("<strong>").append(torrentFile.seedCount()).append("</strong> seed(s), ");
-                                       htmlBuilder.append("<strong>").append(torrentFile.leechCount()).append("</strong> leecher(s)</div>\n");
-                                       htmlBuilder.append("<div>");
-                                       if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) {
-                                               htmlBuilder.append("<a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())).append("\">Magnet</a> ");
+                                       if (newEpisodes.contains(episode)) {
+                                               htmlBuilder.append("<tr style=\"color: #008000; font-weight: bold;\">");
+                                       } else if (newTorrentFiles.contains(torrentFile)) {
+                                               htmlBuilder.append("<tr style=\"color: #008000;\">");
+                                       } else {
+                                               htmlBuilder.append("<tr>");
                                        }
-                                       if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) {
-                                               htmlBuilder.append("<a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())).append("\">Download</a>");
+                                       if ((lastEpisode == null) || !lastEpisode.equals(episode)) {
+                                               htmlBuilder.append("<td>").append(episode.season()).append("</td><td>").append(episode.episode()).append("</td>");
+                                       } else {
+                                               htmlBuilder.append("<td colspan=\"2\"></td>");
                                        }
-                                       htmlBuilder.append("</div>\n");
+                                       htmlBuilder.append("<td>").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append("</td>");
+                                       htmlBuilder.append("<td>").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append("</td>");
+                                       htmlBuilder.append("<td>").append(torrentFile.fileCount()).append("</td>");
+                                       htmlBuilder.append("<td>").append(torrentFile.seedCount()).append("</td>");
+                                       htmlBuilder.append("<td>").append(torrentFile.leechCount()).append("</td>");
+                                       htmlBuilder.append("<td><a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())).append("\">Link</a></td>");
+                                       htmlBuilder.append("<td><a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())).append("\">Link</a></td>");
+                                       htmlBuilder.append("</tr>\n");
+                                       lastEpisode = episode;
                                }
-                               htmlBuilder.append("</ul>\n");
                        }
-                       htmlBuilder.append("</ul>\n");
                }
+               htmlBuilder.append("</tbody>\n");
+               htmlBuilder.append("</table>\n");
                htmlBuilder.append("</body></html>\n");
                return htmlBuilder.toString();
        }