Skip to content

Commit 42b86e8

Browse files
committed
Order files lists.
1 parent dc337d6 commit 42b86e8

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

app/src/main/java/com/paulds/simpleftp/data/entities/FileEntity.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @author Paul-DS
77
*/
8-
public class FileEntity {
8+
public class FileEntity implements Comparable<FileEntity> {
99

1010
/**
1111
* The file name.
@@ -90,4 +90,20 @@ public boolean isDirectory() {
9090
public void setIsDirectory(boolean isDirectory) {
9191
this.isDirectory = isDirectory;
9292
}
93+
94+
/**
95+
* {@inheritDoc}
96+
*/
97+
@Override
98+
public int compareTo(FileEntity file) {
99+
if(this.isDirectory() && !file.isDirectory()) {
100+
return -1;
101+
}
102+
else if(!this.isDirectory() && file.isDirectory()) {
103+
return 1;
104+
}
105+
else {
106+
return this.getName().compareToIgnoreCase(file.getName());
107+
}
108+
}
93109
}

app/src/main/java/com/paulds/simpleftp/data/repository/FileRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import java.io.File;
88
import java.util.ArrayList;
9+
import java.util.Collection;
10+
import java.util.Collections;
911
import java.util.List;
1012

1113
/**
@@ -35,6 +37,8 @@ public List<FileEntity> listFiles(String path) {
3537
}
3638
}
3739

40+
Collections.sort(results);
41+
3842
return results;
3943
}
4044

app/src/main/java/com/paulds/simpleftp/data/repository/FtpRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.File;
99
import java.io.IOException;
1010
import java.util.ArrayList;
11+
import java.util.Collections;
1112
import java.util.Dictionary;
1213
import java.util.Enumeration;
1314
import java.util.Hashtable;
@@ -56,6 +57,8 @@ public List<FileEntity> listFiles(FtpServer server, String path) throws FTPExcep
5657
}
5758
}
5859

60+
Collections.sort(results);
61+
5962
return results;
6063
}
6164

0 commit comments

Comments
 (0)