Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Overhaul #36

Merged
merged 5 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/main/java/uk/co/harrypeach/configuration/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,87 @@ public class Configuration {
private List<String> keywordList;
private List<String> blacklistedSubreddits;

/**
* Whether NSFW filtering is enabled or not
* @return
*/
public boolean isNsfwFilteringEnabled() {
return nsfwFilteringEnabled;
}
public void setNsfwFilteringEnabled(boolean nsfwFilteringEnabled) {
this.nsfwFilteringEnabled = nsfwFilteringEnabled;
}

/**
* Whether the notification alert sound should be played
* @return
*/
public boolean isAlertSoundEnabled() {
return alertSoundEnabled;
}
public void setAlertSoundEnabled(boolean alertSoundEnabled) {
this.alertSoundEnabled = alertSoundEnabled;
}

/**
* What the current alert sound volume is
* @return
*/
public double getAlertSoundVolume() {
return alertSoundVolume;
}
public void setAlertSoundVolume(double alertSoundVolume) {
this.alertSoundVolume = alertSoundVolume;
}

/**
* The OAuth string to identify the client
* @return
*/
public String getOauthClient() {
return oauthClient;
}
public void setOauthClient(String oauthClient) {
this.oauthClient = oauthClient;
}

/**
* The keywords that posts are compared to in order to determine a match
* @return
*/
public List<String> getKeywordList() {
return keywordList;
}
public void setKeywordList(List<String> keywordList) {
this.keywordList = keywordList;
}

/**
* Whether pop-up notifications are enabled
* @return
*/
public boolean isNotificationsEnabled() {
return notificationsEnabled;
}
public void setNotificationsEnabled(boolean notificationsEnabled) {
this.notificationsEnabled = notificationsEnabled;
}

/**
* Return the list of blacklisted subreddits
* @return
*/
public List<String> getBlacklistedSubreddits() {
return blacklistedSubreddits;
}
public void setBlacklistedSubreddits(List<String> blacklistedSubreddits) {
this.blacklistedSubreddits = blacklistedSubreddits;
}

/**
* Return the delay between each check for new posts
* @return
*/
public int getUpdateDelay() {
return updateDelay;
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/uk/co/harrypeach/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ public class Main extends Application {
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("Core.fxml"));
primaryStage.getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("icon.png")));
primaryStage.getIcons().add(new Image(getClass().getClassLoader().getResource("icon.png").toExternalForm()));
Scene scene = new Scene(root, 500, 300);
primaryStage.setTitle("RedditMonitor");
primaryStage.setScene(scene);

// Stop users from resizing the UI
primaryStage.setResizable(false);

LOGGER.debug("Showing primary stage");
primaryStage.show();
Expand Down
130 changes: 70 additions & 60 deletions src/main/java/uk/co/harrypeach/misc/Result.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,70 @@
package uk.co.harrypeach.misc;
/**
* Model for each result in the search, bound to the listview.
* @author harry
*
*/
public class Result {

private String subreddit;
private String title;
private String url;
private String id;

public Result(String subreddit, String title, String url, String id) {
this.subreddit = subreddit;
this.title = title;
this.url = url;
this.id = id;
}

/**
* Default string return method which returns the title
*/
public String toString() {
return title;
}

/**
* Gets the subreddit name
* @return subreddit string
*/
public String getSubreddit() {
return subreddit;
}

/**
* Gets the title of the post
* @return title string
*/
public String getTitle() {
return title;
}

/**
* Gets the URL of the post
* @return URL string
*/
public String getUrl() {
return url;
}

/**
* Gets the ID of the post
* @return ID string
*/
public String getId() {
return id;
}

}
package uk.co.harrypeach.misc;
/**
* Model for each result in the search, bound to the listview.
* @author harry
*
*/
public class Result {

private String subreddit;
private String title;
private String url;
private String postUrl;
private String id;

public Result(String subreddit, String title, String url, String postUrl, String id) {
this.subreddit = subreddit;
this.title = title;
this.url = url;
this.postUrl = postUrl;
this.id = id;
}

/**
* Default string return method which returns the title
*/
public String toString() {
return title;
}

/**
* Gets the subreddit name
* @return subreddit string
*/
public String getSubreddit() {
return subreddit;
}

/**
* Gets the title of the post
* @return title string
*/
public String getTitle() {
return title;
}

/**
* Gets the URL of the post's content
* @return URL string
*/
public String getUrl() {
return url;
}

/**
* Gets the URL of the post itself
* @return URL string
*/
public String getPostUrl() {
return postUrl;
}

/**
* Gets the ID of the post
* @return ID string
*/
public String getId() {
return id;
}

}
59 changes: 49 additions & 10 deletions src/main/java/uk/co/harrypeach/ui/FXMLCoreController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
Expand Down Expand Up @@ -53,11 +52,11 @@ public class FXMLCoreController {
@FXML
private Button startButton;
@FXML
private Label titleLabel;
private Hyperlink titleHyperlink;
@FXML
private Label subredditLabel;
private Hyperlink subredditHyperlink;
@FXML
private Hyperlink urlLabel;
private Hyperlink urlHyperlink;
@FXML
private AnchorPane anchorPane;

Expand Down Expand Up @@ -142,6 +141,10 @@ protected void handleLogsButton(ActionEvent event) {
logReaderDialog.show();
}

/**
* Exports the items within the list to a CSV file
* @param event
*/
@FXML
protected void handleCsvExport(ActionEvent event) {
LOGGER.debug("Opening file dialog");
Expand Down Expand Up @@ -182,7 +185,7 @@ protected void handleCsvExport(ActionEvent event) {
@FXML
protected void handleDebugAddItem(ActionEvent event) {
LOGGER.debug("Adding dummy item to the post list");
postList.getItems().add(new Result("/r/test", "This is a test post", "https://reddit.com/", "t35t"));
postList.getItems().add(new Result("/r/test", "This is a test post", "https://reddit.com/", "https://reddit.com/r/test/comments/t35t", "t35t"));
playAlert();
}

Expand Down Expand Up @@ -223,15 +226,45 @@ protected void initialize() {
postList.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Result>() {
@Override
public void changed(ObservableValue<? extends Result> observable, Result oldValue, Result newValue) {

// Set the title hyperlink text and URL
String titleText = newValue.getTitle();
titleLabel.setText(titleText.substring(0, Math.min(titleText.length(), MAX_LABEL_CHARS)));
String titleUrl = "https://reddit.com" + newValue.getPostUrl();
titleHyperlink.setText(titleText.substring(0, Math.min(titleText.length(), MAX_LABEL_CHARS)));
titleHyperlink.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
try {
LOGGER.debug("Attempting to open selected URL in the users browser");
Desktop.getDesktop().browse(new URI(titleUrl));
} catch (IOException | URISyntaxException e1) {
LOGGER.warn(e1.getMessage());
e1.printStackTrace();
}
}
});

// Set the subreddit hyperlink text and URL
String subredditText = newValue.getSubreddit();
subredditLabel.setText(subredditText.substring(0, Math.min(subredditText.length(), MAX_LABEL_CHARS)));
String subredditUrl = "https://reddit.com/r/" + newValue.getSubreddit();
subredditHyperlink.setText(subredditText.substring(0, Math.min(subredditText.length(), MAX_LABEL_CHARS)));
subredditHyperlink.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
try {
LOGGER.debug("Attempting to open selected URL in the users browser");
Desktop.getDesktop().browse(new URI(subredditUrl));
} catch (IOException | URISyntaxException e1) {
LOGGER.warn(e1.getMessage());
e1.printStackTrace();
}
}
});

// Set the URL hyperlink text and URL
String urlText = newValue.getUrl();
urlLabel.setText(urlText.substring(0, Math.min(urlText.length(), MAX_LABEL_CHARS)));
urlLabel.setOnAction(new EventHandler<ActionEvent>() {
urlHyperlink.setText(urlText.substring(0, Math.min(urlText.length(), MAX_LABEL_CHARS)));
urlHyperlink.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
try {
Expand All @@ -246,6 +279,7 @@ public void handle(ActionEvent e) {
}
});

// Open the post's url in the browser when it is double clicked.
postList.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent click) {
Expand Down Expand Up @@ -330,6 +364,10 @@ public void shutdown() {

}

/**
* The updater thread which continiously checks for new posts that match the keywords and that are not blacklisted or already included
* @author Harry Peach
*/
class UpdateList implements Runnable {
private FXMLCoreController controllerInstance;
private static final int MAX_RESULT_QUEUE_SIZE = 100;
Expand Down Expand Up @@ -360,7 +398,7 @@ public void run() {
Listing<Submission> submissions = paginator.next();

for (Submission s : submissions) {
Result r = new Result(s.getSubreddit(), s.getTitle(), s.getUrl(), s.getId());
Result r = new Result(s.getSubreddit(), s.getTitle(), s.getUrl(), s.getPermalink(), s.getId());
// Checks whether the submission title contains a keyword, and whether it is
// already in the result queue
if (titleContainsWordList(r.getTitle(), stringList) && !containsResult(resultQueue, r)) {
Expand All @@ -381,6 +419,7 @@ public void run() {
return;
}

// Add item to the postlist and notify the user
addToQueue(r);
Runnable updater = new Runnable() {
public void run() {
Expand Down
Loading