Skip to content

Commit

Permalink
Merge pull request #594 from HeXis-YS/ai_separate_dir
Browse files Browse the repository at this point in the history
AI作品下载至单独的目录 #502
  • Loading branch information
CeuiLiSA authored Mar 25, 2024
2 parents ba432a3 + e31160c commit 1a502cd
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 6 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/ceui/lisa/fragments/FragmentSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,23 @@ public void onClick(View v) {
}
});

// AI作品下载至单独的目录
baseBind.aiDivideSave.setChecked(Shaft.sSettings.isAIDivideSave());
baseBind.aiDivideSave.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Shaft.sSettings.setAIDivideSave(isChecked);
Common.showToast(getString(R.string.string_428));
Local.setSettings(Shaft.sSettings);
}
});
baseBind.aiDivideSaveRela.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
baseBind.aiDivideSave.performClick();
}
});

// 自定义下载文件名
baseBind.fileNameRela.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
53 changes: 47 additions & 6 deletions app/src/main/java/ceui/lisa/helper/FileStorageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,40 @@ public static String getIllustFileRelativeNameQ(DownloadItem downloadItem) {
}

public static String getIllustFileSAFFullName(String id, IllustsBean illustsBean, String fileName){
return id + getShaftIllustPathPartWithInnerR18Folder(illustsBean) + getAuthorPathPart(illustsBean) + File.separator + fileName;
String fullName = id;
if (isSaveToAIDir(illustsBean)) {
fullName += getShaftIllustPathPartWithInnerAIFolder(illustsBean);
} else if (isSaveToR18Dir(illustsBean)) {
fullName += getShaftIllustPathPartWithInnerR18Folder(illustsBean);
}
fullName += getAuthorPathPart(illustsBean) + File.separator + fileName;
return fullName;
}

public static String getIllustAbsolutePath(IllustsBean illustsBean){
return PathUtils.getExternalPicturesPath() + sep + getShaftIllustDirWithInnerR18Folder(isSaveToR18Dir(illustsBean)) + getAuthorPathPart(illustsBean);
String absolutePath = PathUtils.getExternalPicturesPath() + sep;
if (isSaveToAIDir(illustsBean)) {
absolutePath += getShaftIllustDirWithInnerAIFolder(true);
} else if (isSaveToR18Dir(illustsBean)) {
absolutePath += getShaftIllustDirWithInnerR18Folder(true);
}
absolutePath += getAuthorPathPart(illustsBean);
return absolutePath;
}

public static String getIllustAbsolutePath(IllustsBean illustsBean, boolean isR18){
return PathUtils.getExternalPicturesPath() + sep + getShaftIllustDirWithInnerR18Folder(isR18) + getAuthorPathPart(illustsBean);
}
// public static String getIllustAbsolutePath(IllustsBean illustsBean, boolean isR18){
// return PathUtils.getExternalPicturesPath() + sep + getShaftIllustDirWithInnerR18Folder(isR18) + getAuthorPathPart(illustsBean);
// }

public static String getIllustRelativePathQ(IllustsBean illustsBean) {
return Environment.DIRECTORY_PICTURES + sep + getShaftIllustDirWithInnerR18Folder(isSaveToR18Dir(illustsBean)) + getAuthorPathPart(illustsBean);
String relativePath = Environment.DIRECTORY_PICTURES + sep;
if (isSaveToAIDir(illustsBean)) {
relativePath += getShaftIllustDirWithInnerAIFolder(true);
} else if (isSaveToR18Dir(illustsBean)) {
relativePath += getShaftIllustDirWithInnerR18Folder(true);
}
relativePath += getAuthorPathPart(illustsBean);
return relativePath;
}

public static String getNovelRelativePathQ() {
Expand Down Expand Up @@ -75,6 +96,26 @@ private static boolean isSaveToR18Dir(IllustsBean illustsBean){
return illustsBean.isR18File() && Shaft.sSettings.isR18DivideSave();
}

public static String getShaftIllustAIDirNameWithInnerAIFolder(IllustsBean illustsBean) {
return isSaveToAIDir(illustsBean) ? "ShaftImages-AI" : "";
}

public static String getShaftIllustPathPartWithInnerAIFolder(IllustsBean illustsBean) {
return getShaftIllustPathPartWithInnerAIFolder(isSaveToAIDir(illustsBean));
}

public static String getShaftIllustPathPartWithInnerAIFolder(boolean isAI) {
return isAI ? sep + "ShaftImages-AI" : "";
}

public static String getShaftIllustDirWithInnerAIFolder(boolean isAI) {
return "ShaftImages" + getShaftIllustPathPartWithInnerAIFolder(isAI);
}

private static boolean isSaveToAIDir(IllustsBean illustsBean){
return illustsBean.isCreatedByAI() && Shaft.sSettings.isAIDivideSave();
}

private static String getAuthorPathPart(IllustsBean illustsBean) {
String name = getAuthorDirectoryName(illustsBean.getUser());
return name.length() > 0 ? sep + name : name;
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/ceui/lisa/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public void setCurrentProgress(long currentProgress) {

private boolean r18DivideSave = false;

//AI作品下载至单独的目录
private boolean AIDivideSave = false;


//在我的收藏列表,隐藏收藏按钮,默认显示
private boolean hideStarButtonAtMyCollection = false;
Expand Down Expand Up @@ -217,6 +220,14 @@ public void setR18DivideSave(boolean r18DivideSave) {
this.r18DivideSave = r18DivideSave;
}

public boolean isAIDivideSave() {
return AIDivideSave;
}

public void setAIDivideSave(boolean AIDivideSave) {
this.AIDivideSave = AIDivideSave;
}

public String getRootPathUri() {
return rootPathUri;
}
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,22 @@

<View style="@style/half_divider" />

<RelativeLayout
android:id="@+id/ai_divide_save_rela"
style="@style/ripple_rela">

<TextView
style="@style/setting_text_left_and_center"
android:text="@string/string_455" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/ai_divide_save"
style="@style/setting_right_switch"/>

</RelativeLayout>

<View style="@style/half_divider" />

<RelativeLayout
android:id="@+id/file_name_rela"
style="@style/ripple_rela">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@
<string name="string_452">Download limit type</string>
<string name="string_453">Do not auto start</string>
<string name="string_454">Share first image</string>
<string name="string_455">AI works download to another directory</string>
<string name="refresh">Refresh</string>
<string name="now_loading">Loading…</string>
<string name="retry">Retry</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@
<string name="string_452">ダウンロードの制限</string>
<string name="string_453">手動のみ</string>
<string name="string_454">最初の画像を共有する</string>
<string name="string_455">AI作品を別のフォルダに保存する</string>
<string name="terms_of_service">利用規約</string>
<string name="privacy_policy">プライバシーポリシー</string>
<string name="landing_terms_base">%sと%sに同意する</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,5 @@
<string name="string_452">다운로드 제한 유형</string>
<string name="string_453">자동 시작 안 함</string>
<string name="string_454">첫 번째 이미지 공유</string>
<string name="string_455">AI 작품 을 다른 디 렉 터 리 에 다운로드</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,5 @@
<string name="string_452">Тип лимита загрузки</string>
<string name="string_453">Не автозапуск</string>
<string name="string_454">Поделитесь первой картинкой</string>
<string name="string_455">работа AI загружена в другой каталог</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,5 @@
<string name="string_452">İndirme sınırı türü</string>
<string name="string_453">oto başlatma</string>
<string name="string_454">İlk resmi paylaş</string>
<string name="string_455">AI çalışmalarını başka bir dizine kaydet</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -608,4 +608,5 @@
<string name="string_452">下載限制類型</string>
<string name="string_453">不自動下載</string>
<string name="string_454">分享首圖</string>
<string name="string_455">AI 作品下載至另一目錄</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@
<string name="string_452">下载限制类型</string>
<string name="string_453">不自动下载</string>
<string name="string_454">分享首图</string>
<string name="string_455">AI 作品下载至另一目录</string>
<string name="terms_of_service">服务条款</string>
<string name="privacy_policy">隐私政策</string>
<string name="landing_terms_base">欢迎使用!继续即表示你同意 Shaft 的 %s 并且确认已阅读我们的 %s.</string>
Expand Down

0 comments on commit 1a502cd

Please sign in to comment.