X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Ftriggers%2FNewTorrentTrigger.java;h=f084c61b7dee3de6094fcd0d2230d9987dd58ef1;hb=ab360ae5ff4a8392a0ba3aa4a290f6b6502a13ea;hp=872349e06b32f13427b07c94d28a97727b5a996b;hpb=f43798b2b09447fadb82b6019029b5e6fa609ba2;p=rhynodge.git
diff --git a/src/main/java/net/pterodactylus/rhynodge/triggers/NewTorrentTrigger.java b/src/main/java/net/pterodactylus/rhynodge/triggers/NewTorrentTrigger.java
index 872349e..f084c61 100644
--- a/src/main/java/net/pterodactylus/rhynodge/triggers/NewTorrentTrigger.java
+++ b/src/main/java/net/pterodactylus/rhynodge/triggers/NewTorrentTrigger.java
@@ -33,6 +33,7 @@ import net.pterodactylus.rhynodge.states.TorrentState.TorrentFile;
import org.apache.commons.lang3.StringEscapeUtils;
import com.google.common.collect.Lists;
+import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
/**
@@ -95,7 +96,7 @@ public class NewTorrentTrigger implements Trigger {
}
//
- // STATIC METHODS
+ // PRIVATE METHODS
//
/**
@@ -131,24 +132,63 @@ public class NewTorrentTrigger implements Trigger {
* @return The generated HTML
*/
private String getHtmlTextList(Reaction reaction) {
- StringBuilder htmlText = new StringBuilder();
- htmlText.append("
\n");
- htmlText.append("New Torrents
\n");
- htmlText.append("\n");
- for (TorrentFile torrentFile : torrentFiles) {
- htmlText.append("- ").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append("
");
- htmlText.append("Size: ").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append(" in ").append(torrentFile.fileCount()).append(" file(s)
");
- htmlText.append("").append(torrentFile.seedCount()).append(" seed(s), ").append(torrentFile.leechCount()).append(" leecher(s)
");
- if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) {
- htmlText.append(String.format("", StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())));
- }
- if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) {
- htmlText.append(String.format("", StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())));
+ StringBuilder htmlBuilder = new StringBuilder();
+ htmlBuilder.append("\n");
+ htmlBuilder.append("\nAll Known Torrents\n");
+ htmlBuilder.append("\n");
+ htmlBuilder.append("");
+ htmlBuilder.append("Filename | ");
+ htmlBuilder.append("Size | ");
+ htmlBuilder.append("File(s) | ");
+ htmlBuilder.append("Seeds | ");
+ htmlBuilder.append("Leechers | ");
+ htmlBuilder.append("Magnet | ");
+ htmlBuilder.append("Download | ");
+ htmlBuilder.append("
\n");
+ htmlBuilder.append("\n");
+ htmlBuilder.append("\n");
+ for (TorrentFile torrentFile : sortNewFirst().sortedCopy(allTorrentFiles)) {
+ if (newTorrentFiles.contains(torrentFile)) {
+ htmlBuilder.append("");
+ } else {
+ htmlBuilder.append("
");
}
+ htmlBuilder.append("").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append(" | ");
+ htmlBuilder.append("").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append(" | ");
+ htmlBuilder.append("").append(torrentFile.fileCount()).append(" | ");
+ htmlBuilder.append("").append(torrentFile.seedCount()).append(" | ");
+ htmlBuilder.append("").append(torrentFile.leechCount()).append(" | ");
+ htmlBuilder.append("Link | ");
+ htmlBuilder.append("Link | ");
+ htmlBuilder.append("
\n");
}
- htmlText.append("\n");
- htmlText.append("\n");
- return htmlText.toString();
+ htmlBuilder.append("\n");
+ htmlBuilder.append("
\n");
+ htmlBuilder.append("\n");
+ return htmlBuilder.toString();
+ }
+
+ /**
+ * Returns an ordering that sorts torrent files by whether they are new
+ * (according to {@link #newTorrentFiles}) or not. New files will be sorted
+ * first.
+ *
+ * @return An ordering for ânew files firstâ
+ */
+ private Ordering sortNewFirst() {
+ return new Ordering() {
+
+ @Override
+ public int compare(TorrentFile leftTorrentFile, TorrentFile rightTorrentFile) {
+ if (newTorrentFiles.contains(leftTorrentFile) && !newTorrentFiles.contains(rightTorrentFile)) {
+ return -1;
+ }
+ if (!newTorrentFiles.contains(leftTorrentFile) && newTorrentFiles.contains(rightTorrentFile)) {
+ return 1;
+ }
+ return 0;
+ }
+ };
}
}