convert Medium to kotlin + Directory updates
This commit is contained in:
parent
a5deb81e58
commit
84613885ef
6 changed files with 44 additions and 92 deletions
|
@ -234,7 +234,7 @@ public class MediaActivity extends SimpleActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Medium.mSorting = mConfig.getSorting();
|
Medium.Companion.setSorting(mConfig.getSorting());
|
||||||
Collections.sort(media);
|
Collections.sort(media);
|
||||||
Utils.Companion.scanFiles(getApplicationContext(), invalidFiles);
|
Utils.Companion.scanFiles(getApplicationContext(), invalidFiles);
|
||||||
|
|
||||||
|
|
|
@ -380,7 +380,7 @@ public class ViewPagerActivity extends SimpleActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Medium.mSorting = mConfig.getSorting();
|
Medium.Companion.setSorting(mConfig.getSorting());
|
||||||
Collections.sort(media);
|
Collections.sort(media);
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (Medium medium : media) {
|
for (Medium medium : media) {
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
package com.simplemobiletools.gallery.models;
|
|
||||||
|
|
||||||
import com.simplemobiletools.gallery.Constants;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class Medium implements Serializable, Comparable {
|
|
||||||
private static final long serialVersionUID = -6543139465975455L;
|
|
||||||
private final String mName;
|
|
||||||
private final boolean mIsVideo;
|
|
||||||
private final long mTimestamp;
|
|
||||||
private final long mSize;
|
|
||||||
public static int mSorting;
|
|
||||||
private String mPath;
|
|
||||||
|
|
||||||
public Medium(String name, String path, boolean isVideo, long timestamp, long size) {
|
|
||||||
mName = name;
|
|
||||||
mPath = path;
|
|
||||||
mIsVideo = isVideo;
|
|
||||||
mTimestamp = timestamp;
|
|
||||||
mSize = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return mName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPath(String path) {
|
|
||||||
mPath = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return mPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getIsVideo() {
|
|
||||||
return mIsVideo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTimestamp() {
|
|
||||||
return mTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSize() {
|
|
||||||
return mSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGif() {
|
|
||||||
return getPath().toLowerCase().endsWith(".gif");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isImage() {
|
|
||||||
return !isGif() && !getIsVideo();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Object object) {
|
|
||||||
final Medium medium = (Medium) object;
|
|
||||||
int res;
|
|
||||||
if ((mSorting & Constants.SORT_BY_NAME) != 0) {
|
|
||||||
res = mPath.compareTo(medium.getPath());
|
|
||||||
} else if ((mSorting & Constants.SORT_BY_DATE) != 0) {
|
|
||||||
res = (mTimestamp > medium.getTimestamp()) ? 1 : -1;
|
|
||||||
} else {
|
|
||||||
res = (mSize > medium.getSize()) ? 1 : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((mSorting & Constants.SORT_DESCENDING) != 0) {
|
|
||||||
res *= -1;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Medium {" +
|
|
||||||
"isVideo=" + getIsVideo() +
|
|
||||||
", timestamp=" + getTimestamp() +
|
|
||||||
", size=" + getSize() +
|
|
||||||
", path=" + getPath() + "}";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -79,7 +79,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
|
|
||||||
val dirs = ArrayList(directories.values)
|
val dirs = ArrayList(directories.values)
|
||||||
filterDirectories(dirs)
|
filterDirectories(dirs)
|
||||||
Directory.mSorting = mConfig.directorySorting
|
Directory.sorting = mConfig.directorySorting
|
||||||
Collections.sort<Directory>(dirs)
|
Collections.sort<Directory>(dirs)
|
||||||
|
|
||||||
context.scanFiles(invalidFiles) {}
|
context.scanFiles(invalidFiles) {}
|
||||||
|
|
|
@ -9,25 +9,23 @@ class Directory(val path: String, val thumbnail: String, val name: String, var m
|
||||||
|
|
||||||
override fun compareTo(other: Directory): Int {
|
override fun compareTo(other: Directory): Int {
|
||||||
var res: Int
|
var res: Int
|
||||||
if (mSorting and Constants.SORT_BY_NAME != 0) {
|
if (sorting and Constants.SORT_BY_NAME != 0) {
|
||||||
res = path.compareTo(other.path)
|
res = path.compareTo(other.path)
|
||||||
} else if (mSorting and Constants.SORT_BY_DATE != 0) {
|
} else if (sorting and Constants.SORT_BY_DATE != 0) {
|
||||||
res = if (timestamp > other.timestamp) 1 else -1
|
res = if (timestamp > other.timestamp) 1 else -1
|
||||||
} else {
|
} else {
|
||||||
res = if (size > other.size) 1 else -1
|
res = if (size > other.size) 1 else -1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSorting and Constants.SORT_DESCENDING != 0) {
|
if (sorting and Constants.SORT_DESCENDING != 0) {
|
||||||
res *= -1
|
res *= -1
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString() = "Directory {path=$path, thumbnail=$thumbnail, name=$name, mediaCnt=$mediaCnt, timestamp=$timestamp, size $size}"
|
||||||
return "Directory {path=$path, thumbnail=$thumbnail, name=$name, timestamp=$timestamp, mediaCnt=$mediaCnt}"
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var mSorting: Int = 0
|
var sorting: Int = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.simplemobiletools.gallery.models
|
||||||
|
|
||||||
|
import com.simplemobiletools.gallery.Constants
|
||||||
|
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
|
class Medium(val name: String, var path: String, val isVideo: Boolean, val timestamp: Long, val size: Long) : Serializable, Comparable<Medium> {
|
||||||
|
val isGif: Boolean
|
||||||
|
get() = path.toLowerCase().endsWith(".gif")
|
||||||
|
|
||||||
|
val isImage: Boolean
|
||||||
|
get() = !isGif && !isVideo
|
||||||
|
|
||||||
|
override fun compareTo(other: Medium): Int {
|
||||||
|
var res: Int
|
||||||
|
if (sorting and Constants.SORT_BY_NAME != 0) {
|
||||||
|
res = path.compareTo(other.path)
|
||||||
|
} else if (sorting and Constants.SORT_BY_DATE != 0) {
|
||||||
|
res = if (timestamp > other.timestamp) 1 else -1
|
||||||
|
} else {
|
||||||
|
res = if (size > other.size) 1 else -1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sorting and Constants.SORT_DESCENDING != 0) {
|
||||||
|
res *= -1
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString() = "Medium {name=$name, path=$path, isVideo=$isVideo, timestamp=$timestamp, size=$size}"
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val serialVersionUID = -6543139465975455L
|
||||||
|
var sorting: Int = 0
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue