This commit is contained in:
Cold-Mint 2023-01-31 16:36:28 +08:00
commit 5b4c2295cd
2 changed files with 132 additions and 1 deletions

View File

@ -0,0 +1,131 @@
import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class FileSort {
final int name=0,time=1,size=2,type=3;
public static String[] type_list;
public FileSort(List<File> a,int manner){
switch (manner){
case name:
sort_name(a);
break;
case time:
sort_time(a);
break;
case size:
sort_size(a);
break;
case type:
sort_type(a);
break;
default:
}
}
public static void sort_front(List<File> a){
Collections.sort(a, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
if (o1.isDirectory() && o2.isFile())
return -1;
if (o1.isFile() && o2.isDirectory())
return 1;
return 0;
}
});
}
public static void sort_name(List<File> a){
Collections.sort(a,new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
if (o1.isDirectory() && o2.isFile())
return -1;
if (o1.isFile() && o2.isDirectory())
return 1;
return o1.getName().compareTo(o2.getName());
}
});
sort_front(a);
}
public static void sort_time(List<File> a){
Collections.sort(a,new Comparator<File>() {
@Override
public int compare(File f1, File f2) {
long diff = f1.lastModified() - f2.lastModified();
if (diff > 0)
return 1;
else if (diff == 0)
return 0;
else
return -1;
//如果 if 中修改为 返回-1 同时此处修改为返回 1 排序就会是递减
}
});
sort_front(a);
}
public void sort_size(List<File> a){
Collections.sort(a, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
long diff = o1.length() - o2.length();
if (diff > 0)
return 1;
else if (diff == 0)
return 0;
else
return -1;
}
});
sort_front(a);
}
public static void sort_type(List<File> a){
//文件类型排序 按照后缀优先级
// System.out.println(type_list[0]);
Collections.sort(a, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
if (o1.isFile()) {
String name_a = o1.getName();
String o_z = name_a.substring(name_a.lastIndexOf("."));
// System.out.println(o_z);
//获取 name_a文件名字的后缀
int length=length(type_list,o_z);
System.out.println(length);
//查找后缀是不是存在于 type_list数据中 如果存在返回存在位置 如果不存在则返回<0的值
if (length>=0)
return -1;
} else if (o2.isFile()) {
String name_a = o2.getName();
// System.out.println(name_a);
String o_z = name_a.substring(name_a.lastIndexOf("."));
//获取 name_a文件名字的后缀
int length=length(type_list,o_z);
if (length>=0)
return 1;
}
return 0;
}
});
}
private static int length(String a){
for (int i=0;i<type_list.length;i++){
if (type_list[i].equals(a)){
return i;
}
}
return -1;
}
private static int length(String[] sz,String a){
for (int i=0;i<sz.length;i++){
if (sz[i].equals(a)) {
return i;
}
}
return -1;
}
}

View File

@ -35,7 +35,7 @@ class ThanksActivity : BaseActivity<ActivityThanksBinding>() {
viewBinding.recyclerView.layoutManager = LinearLayoutManager(this) viewBinding.recyclerView.layoutManager = LinearLayoutManager(this)
val list = ArrayList<ThanksDataBean>() val list = ArrayList<ThanksDataBean>()
list.add(ThanksDataBean("空调大郎", "帮助翻译俄语版本。", 1491779490)) list.add(ThanksDataBean("空调大郎", "帮助翻译俄语版本。", 1491779490))
list.add(ThanksDataBean("Ling ASDJ", "制作助手新手模板,已被整合至助手内置模版。跟随助手更新。", 2735951230)) list.add(ThanksDataBean("JDSA Ling", "制作助手新手模板,已被整合至助手内置模版。跟随助手更新。", 2735951230))
list.add(ThanksDataBean("Alice's Dream", "帮助薄荷优化代码表。", 3372003670)) list.add(ThanksDataBean("Alice's Dream", "帮助薄荷优化代码表。", 3372003670))
list.add(ThanksDataBean("克鲁鲁.采佩西", "帮助薄荷制作教程。", 2275140013)) list.add(ThanksDataBean("克鲁鲁.采佩西", "帮助薄荷制作教程。", 2275140013))
list.add(ThanksDataBean("慕青","帮助薄荷修复助手bug优化助手功能。",1966944300)) list.add(ThanksDataBean("慕青","帮助薄荷修复助手bug优化助手功能。",1966944300))