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

Added showing multiple recent folders when choosing download location #823

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ app/.classpath
app/.project
app/.settings/*
app/target/*
.idea
app/xdman.iml
47 changes: 47 additions & 0 deletions app/src/main/java/xdman/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayDeque;

import xdman.util.Logger;
import xdman.util.StringUtils;
Expand Down Expand Up @@ -54,6 +55,8 @@ public class Config {
private boolean noTransparency;
private boolean hideTray;
private String lastFolder;
private final int maxRecentFoldersCount = 5;
private ArrayDeque<String> recentFolders;
private List<MonitoringListener> listeners;
private String queueIdFilter;
private boolean showVideoListOnlyInBrowser;
Expand Down Expand Up @@ -141,6 +144,7 @@ public void save() {
if (lastFolder != null) {
fw.write("lastFolder:" + this.lastFolder + newLine);
}
writeRecentFoldersToFile(fw);
fw.write("showVideoListOnlyInBrowser:" + this.showVideoListOnlyInBrowser + newLine);
fw.write("zoomLevelIndex:" + this.zoomLevelIndex + newLine);

Expand Down Expand Up @@ -277,6 +281,9 @@ public void load() {
} else if (key.equals("zoomLevelIndex")) {
this.zoomLevelIndex = Integer.parseInt(val);
}
else if (key.equals("recentFolders")){
readRecentFoldersFromFile(val);
}
}
} catch (Exception e) {
Logger.log(e);
Expand Down Expand Up @@ -356,6 +363,7 @@ private Config() {
this.noTransparency = false;
this.hideTray = true;
this.listeners = new ArrayList<>();
this.recentFolders = new ArrayDeque<>();

}

Expand All @@ -368,6 +376,32 @@ public void createFolders() {
getCategoryVideos();
}

private void writeRecentFoldersToFile(FileWriter fw)
{
if (recentFolders.isEmpty())
return;
try
{
fw.write("recentFolders:");
for (String recentFolder : recentFolders)
{
fw.write(recentFolder + ",");
}
fw.write("\n");
}
catch (Exception e)
{
Logger.log(e);
}

}
private void readRecentFoldersFromFile(String val)
{
String[] folders = val.split(",");
for (String folder: folders)
this.recentFolders.addLast(folder);
}

public static synchronized Config getInstance() {
if (_config == null) {
_config = new Config();
Expand Down Expand Up @@ -881,10 +915,23 @@ public String getLastFolder() {
return lastFolder;
}

public ArrayDeque<String> getRecentFolders()
{
return recentFolders;
}

public void setLastFolder(String lastFolder) {
this.lastFolder = lastFolder;
updateRecentFolders(lastFolder);
}

private void updateRecentFolders(String lastFolder)
{
if (recentFolders.size() == maxRecentFoldersCount)
recentFolders.removeLast();

recentFolders.addFirst(lastFolder);
}
public String getQueueIdFilter() {
return queueIdFilter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ private void initUI() {

add(hbox, BorderLayout.EAST);
pop = new JPopupMenu();
if (!StringUtils.isNullOrEmptyOrBlank(Config.getInstance().getLastFolder())) {
pop.add(createMenuItem(Config.getInstance().getLastFolder()));
}
for (String recentFolder : Config.getInstance().getRecentFolders())
{
pop.add(createMenuItem(recentFolder));
}
pop.add(createMenuItem(Config.getInstance().getDownloadFolder()));
if (!Config.getInstance().isForceSingleFolder()) {
pop.add(createMenuItem(Config.getInstance().getCategoryDocuments()));
Expand Down