Skip to content

Commit

Permalink
自定义文件命名格式最终版
Browse files Browse the repository at this point in the history
  • Loading branch information
CeuiLiSA committed Jul 10, 2020
1 parent be4cb71 commit a879471
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 80 deletions.
95 changes: 21 additions & 74 deletions app/src/main/java/ceui/lisa/download/FileCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,90 +118,27 @@ public static File createLogFile(String name) {
public static final int ILLUST_SIZE = 6;

public static String customFileName(IllustsBean illustsBean, int index) {
List<CustomFileNameCell> result = new ArrayList<>();
List<CustomFileNameCell> result;
if (TextUtils.isEmpty(Shaft.sSettings.getFileNameJson())) {
result.add(new CustomFileNameCell("作品标题", "作品标题,可选项", 1, true));
result.add(new CustomFileNameCell("作品ID", "不选的话可能两个文件名重复,导致下载失败,必选项", 2, true));
result.add(new CustomFileNameCell("作品P数", "显示当前图片是作品的第几P,如果只有1P则隐藏,必选项", 3, true));
result.add(new CustomFileNameCell("画师ID", "画师ID,可选项", 4, false));
result.add(new CustomFileNameCell("画师昵称", "画师昵称,可选项", 5, false));
result.add(new CustomFileNameCell("作品尺寸", "显示当前图片的尺寸信息,可选项", 6, false));
result = defaultFileCells();
} else {
result.addAll(Shaft.sGson.fromJson(Shaft.sSettings.getFileNameJson(),
result = new ArrayList<>(Shaft.sGson.fromJson(Shaft.sSettings.getFileNameJson(),
new TypeToken<List<CustomFileNameCell>>() {
}.getType()));
}

String fileName = "";

for (int i = 0; i < result.size(); i++) {
CustomFileNameCell cell = result.get(i);
if (cell.isChecked()) {
switch (cell.getCode()) {
case ILLUST_ID:
if (!TextUtils.isEmpty(fileName)) {
fileName = fileName + "_" + illustsBean.getId();
} else {
fileName = String.valueOf(illustsBean.getId());
}
break;
case ILLUST_TITLE:
if (!TextUtils.isEmpty(fileName)) {
fileName = fileName + "_" + illustsBean.getTitle();
} else {
fileName = illustsBean.getTitle();
}
break;
case P_SIZE:
if (illustsBean.getPage_count() != 1) {
if (!TextUtils.isEmpty(fileName)) {
fileName = fileName + "_p" + (index + 1);
} else {
fileName = "p" + (index + 1);
}
}
break;
case USER_ID:
if (!TextUtils.isEmpty(fileName)) {
fileName = fileName + "_" + illustsBean.getUser().getId();
} else {
fileName = String.valueOf(illustsBean.getUser().getId());
}
break;
case USER_NAME:
if (!TextUtils.isEmpty(fileName)) {
fileName = fileName + "_" + illustsBean.getUser().getName();
} else {
fileName = illustsBean.getUser().getName();
}
break;
case ILLUST_SIZE:
if (!TextUtils.isEmpty(fileName)) {
fileName = fileName + "_" + illustsBean.getWidth() + "px*" + illustsBean.getHeight() + "px";
} else {
fileName = illustsBean.getWidth() + "px*" + illustsBean.getHeight() + "px";
}
break;
default:
break;
}
}
}

return deleteSpecialWords(fileName + "." + Shaft.sSettings.getFileLastType());
return deleteSpecialWords(illustToFileName(illustsBean, result, index) +
"." + Shaft.sSettings.getFileLastType());
}

public static String customFileNameForPreview(IllustsBean illustsBean,
List<CustomFileNameCell> cells, int index) {
List<CustomFileNameCell> result;
if (cells != null && cells.size() != 0) {
result = new ArrayList<>(cells);
} else {
result = new ArrayList<>();
}
return deleteSpecialWords(illustToFileName(illustsBean, cells, index) +
"." + Shaft.sSettings.getFileLastType());
}

private static String illustToFileName(IllustsBean illustsBean,
List<CustomFileNameCell> result, int index) {
String fileName = "";

for (int i = 0; i < result.size(); i++) {
CustomFileNameCell cell = result.get(i);
if (cell.isChecked()) {
Expand Down Expand Up @@ -255,7 +192,17 @@ public static String customFileNameForPreview(IllustsBean illustsBean,
}
}
}
return fileName;
}

return deleteSpecialWords(fileName + "." + Shaft.sSettings.getFileLastType());
public static List<CustomFileNameCell> defaultFileCells() {
List<CustomFileNameCell> cells = new ArrayList<>();
cells.add(new CustomFileNameCell("作品标题", "作品标题,可选项", 1, true));
cells.add(new CustomFileNameCell("作品ID", "不选的话可能两个文件名重复,导致下载失败,必选项", 2, true));
cells.add(new CustomFileNameCell("作品P数", "显示当前图片是作品的第几P,如果只有1P则隐藏,必选项", 3, true));
cells.add(new CustomFileNameCell("画师ID", "画师ID,可选项", 4, false));
cells.add(new CustomFileNameCell("画师昵称", "画师昵称,可选项", 5, false));
cells.add(new CustomFileNameCell("作品尺寸", "显示当前图片的尺寸信息,可选项", 6, false));
return cells;
}
}
7 changes: 1 addition & 6 deletions app/src/main/java/ceui/lisa/fragments/FragmentFileName.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ public void onClick(DialogInterface dialog, int which) {
protected void initData() {
allItems.clear();
if (TextUtils.isEmpty(Shaft.sSettings.getFileNameJson())) {
allItems.add(new CustomFileNameCell("作品标题", "作品标题,可选项", 1, true));
allItems.add(new CustomFileNameCell("作品ID", "不选的话可能两个文件名重复,导致下载失败,必选项", 2, true));
allItems.add(new CustomFileNameCell("作品P数", "显示当前图片是作品的第几P,如果只有1P则隐藏,必选项", 3, true));
allItems.add(new CustomFileNameCell("画师ID", "画师ID,可选项", 4, false));
allItems.add(new CustomFileNameCell("画师昵称", "画师昵称,可选项", 5, false));
allItems.add(new CustomFileNameCell("作品尺寸", "显示当前图片的尺寸信息,可选项", 6, false));
allItems.addAll(FileCreator.defaultFileCells());
} else {
allItems.addAll(Shaft.sGson.fromJson(Shaft.sSettings.getFileNameJson(),
new TypeToken<List<CustomFileNameCell>>() {
Expand Down

0 comments on commit a879471

Please sign in to comment.