parent
f08beb768e
commit
dde5ec77ee
@ -0,0 +1,113 @@ |
||||
package com.github.catvod.bean.alist; |
||||
|
||||
import android.text.TextUtils; |
||||
|
||||
import com.github.catvod.bean.Vod; |
||||
import com.github.catvod.utils.Misc; |
||||
import com.google.gson.Gson; |
||||
import com.google.gson.annotations.SerializedName; |
||||
import com.google.gson.reflect.TypeToken; |
||||
|
||||
import java.lang.reflect.Type; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Locale; |
||||
|
||||
public class Item { |
||||
|
||||
@SerializedName("name") |
||||
private String name; |
||||
@SerializedName("type") |
||||
private int type; |
||||
@SerializedName("size") |
||||
private long size; |
||||
@SerializedName(value = "thumb", alternate = "thumbnail") |
||||
private String thumb; |
||||
@SerializedName(value = "url", alternate = "raw_url") |
||||
private String url; |
||||
@SerializedName(value = "modified", alternate = "updated_at") |
||||
private String modified; |
||||
|
||||
public static Item objectFrom(String str) { |
||||
return new Gson().fromJson(str, Item.class); |
||||
} |
||||
|
||||
public static List<Item> arrayFrom(String str) { |
||||
Type listType = new TypeToken<List<Item>>() {}.getType(); |
||||
return new Gson().fromJson(str, listType); |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public int getType() { |
||||
return type; |
||||
} |
||||
|
||||
public long getSize() { |
||||
return size; |
||||
} |
||||
|
||||
public String getThumb() { |
||||
return thumb; |
||||
} |
||||
|
||||
public String getUrl() { |
||||
return TextUtils.isEmpty(url) ? "" : url.startsWith("//") ? "http:" + url : url; |
||||
} |
||||
|
||||
public String getModified() { |
||||
return modified; |
||||
} |
||||
|
||||
public Date getDate() { |
||||
try { |
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.getDefault()); |
||||
return format.parse(getModified()); |
||||
} catch (Exception e) { |
||||
return new Date(); |
||||
} |
||||
} |
||||
|
||||
public boolean isFolder() { |
||||
return getType() == 1; |
||||
} |
||||
|
||||
public boolean isMedia() { |
||||
return getType() == 2 || getType() == 3 || getType() == 4 || getType() == 6; |
||||
} |
||||
|
||||
public boolean isSub() { |
||||
return getType() == 5 && Misc.isSub(getExt()); |
||||
} |
||||
|
||||
public boolean ignore() { |
||||
return !isFolder() && !isMedia() && !isSub(); |
||||
} |
||||
|
||||
public String getExt() { |
||||
return getName().substring(getName().lastIndexOf(".") + 1); |
||||
} |
||||
|
||||
public String getVodId(String tid) { |
||||
return tid + "/" + getName(); |
||||
} |
||||
|
||||
public String getPic() { |
||||
return getThumb().isEmpty() && isFolder() ? "http://img1.3png.com/281e284a670865a71d91515866552b5f172b.png" : getThumb(); |
||||
} |
||||
|
||||
public String getRemark() { |
||||
return Misc.getSize(getSize()) + (isFolder() ? " 文件夹" : ""); |
||||
} |
||||
|
||||
public String getVodTag() { |
||||
return isFolder() ? "folder" : "file"; |
||||
} |
||||
|
||||
public Vod getVod(String tid) { |
||||
return new Vod(getVodId(tid), getName(), getPic(), getRemark(), getVodTag()); |
||||
} |
||||
} |
||||
@ -0,0 +1,32 @@ |
||||
package com.github.catvod.bean.alist; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
|
||||
public class Sorter implements Comparator<Item> { |
||||
|
||||
private final String type; |
||||
|
||||
public static void sort(String type, List<Item> items) { |
||||
Collections.sort(items, new Sorter(type)); |
||||
} |
||||
|
||||
public Sorter(String type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
@Override |
||||
public int compare(Item o1, Item o2) { |
||||
switch (type) { |
||||
case "name": |
||||
return o1.getName().compareTo(o2.getName()); |
||||
case "size": |
||||
return Long.compare(o1.getSize(), o2.getSize()); |
||||
case "date": |
||||
return o1.getDate().compareTo(o2.getDate()); |
||||
default: |
||||
return -1; |
||||
} |
||||
} |
||||
} |
||||
Binary file not shown.
@ -1 +1 @@ |
||||
2238f733904942609bb90b337dee9713 |
||||
5e45ee53bd37b87d71cc591d1a2c208b |
||||
|
||||
Loading…
Reference in new issue