fix up directory sorting
This commit is contained in:
parent
9081d1a579
commit
2f9c63e43b
|
@ -1,82 +0,0 @@
|
|||
package com.simplemobiletools.gallery.models;
|
||||
|
||||
import com.simplemobiletools.gallery.Constants;
|
||||
|
||||
public class Directory implements Comparable {
|
||||
private final String mPath;
|
||||
private final String mThumbnail;
|
||||
private final String mName;
|
||||
private final long mTimestamp;
|
||||
private int mMediaCnt;
|
||||
private long mSize;
|
||||
public static int mSorting;
|
||||
|
||||
public Directory(String path, String thumbnail, String name, int mediaCnt, long timestamp, long size) {
|
||||
mPath = path;
|
||||
mThumbnail = thumbnail;
|
||||
mName = name;
|
||||
mMediaCnt = mediaCnt;
|
||||
mTimestamp = timestamp;
|
||||
mSize = size;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return mPath;
|
||||
}
|
||||
|
||||
public String getThumbnail() {
|
||||
return mThumbnail;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
public int getMediaCnt() {
|
||||
return mMediaCnt;
|
||||
}
|
||||
|
||||
public void setMediaCnt(int cnt) {
|
||||
mMediaCnt = cnt;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return mTimestamp;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
public void addSize(long bytes) {
|
||||
mSize += bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object object) {
|
||||
final Directory directory = (Directory) object;
|
||||
int res;
|
||||
if ((mSorting & Constants.SORT_BY_NAME) != 0) {
|
||||
res = mPath.compareTo(directory.getPath());
|
||||
} else if ((mSorting & Constants.SORT_BY_DATE) != 0) {
|
||||
res = (mTimestamp > directory.getTimestamp()) ? 1 : -1;
|
||||
} else {
|
||||
res = (mSize > directory.getSize()) ? 1 : -1;
|
||||
}
|
||||
|
||||
if ((mSorting & Constants.SORT_DESCENDING) != 0) {
|
||||
res *= -1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Directory {" +
|
||||
"path=" + getPath() +
|
||||
", thumbnail=" + getThumbnail() +
|
||||
", name=" + getName() +
|
||||
", timestamp=" + getTimestamp() +
|
||||
", mediaCnt=" + getMediaCnt() + "}";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.simplemobiletools.gallery.models
|
||||
|
||||
import com.simplemobiletools.gallery.Constants
|
||||
|
||||
class Directory(val path: String, val thumbnail: String, val name: String, var mediaCnt: Int, val timestamp: Long, var size: Long) : Comparable<Directory> {
|
||||
fun addSize(bytes: Long) {
|
||||
size += bytes
|
||||
}
|
||||
|
||||
override fun compareTo(other: Directory): Int {
|
||||
var res: Int
|
||||
if (mSorting and Constants.SORT_BY_NAME != 0) {
|
||||
res = path.compareTo(other.path)
|
||||
} else if (mSorting and Constants.SORT_BY_DATE != 0) {
|
||||
res = if (timestamp > other.timestamp) 1 else -1
|
||||
} else {
|
||||
res = if (size > other.size) 1 else -1
|
||||
}
|
||||
|
||||
if (mSorting and Constants.SORT_DESCENDING != 0) {
|
||||
res *= -1
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "Directory {path=$path, thumbnail=$thumbnail, name=$name, timestamp=$timestamp, mediaCnt=$mediaCnt}"
|
||||
}
|
||||
|
||||
companion object {
|
||||
var mSorting: Int = 0
|
||||
}
|
||||
}
|
|
@ -77,7 +77,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
|||
val dirs = ArrayList(directories.values)
|
||||
filterDirectories(dirs)
|
||||
Directory.mSorting = mConfig.directorySorting
|
||||
//Collections.sort<Directory>(dirs)
|
||||
Collections.sort<Directory>(dirs)
|
||||
|
||||
val invalids = invalidFiles.toTypedArray()
|
||||
MediaScannerConnection.scanFile(context, invalids, null, null)
|
||||
|
|
Loading…
Reference in New Issue