Skip to content

Commit

Permalink
The download settings support customizing the default download group
Browse files Browse the repository at this point in the history
下载设置中支持自定义默认下载分组
  • Loading branch information
jiangtian616 committed Dec 31, 2023
1 parent 0a6a6f8 commit 04275bc
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 50 deletions.
2 changes: 2 additions & 0 deletions changelog/v7.4.8+147.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- 移动端支持自定义阅读页亮度
- 现在所有平台和布局模式下均可以自定义鼠标滚轮滚动速度
- 阅读页在从上至下布局模式下,现在可以支持自定义图片区域宽度
- 下载设置中支持自定义默认下载分组
- 优化保存图片时的图片命名规则
- 优化解压归档时的icon显示
- 收藏页和关注页搜索不再继承关键字
Expand All @@ -17,6 +18,7 @@
- Support customizing the brightness of the reading page on the mobile terminal
- Now you can customize the mouse wheel scrolling speed in all platforms and layout modes
- In the top to bottom layout mode, the reading page can now support customizing the width of the image area
- The download settings support customizing the default download group
- Optimize the toast message when canceling favorites
- Optimize the image naming rules when saving images
- Optimize the icon display when decompressing archives
Expand Down
2 changes: 2 additions & 0 deletions lib/src/l18n/en_US.dart
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ class en_US {
'downloadOriginalImageByDefault': 'Choose Original Image By Default',
'originalImage': 'Original',
'resampleImage': 'Resample',
'defaultGalleryGroup': 'Default Gallery Group',
'defaultArchiveGroup': 'Default Archive Group',
'never': 'Never',
'manual': 'Manual',
'always': 'Always',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/l18n/ko_KR.dart
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ class ko_KR {
'downloadOriginalImageByDefault': '기본값으로 원본 이미지 선택',
'originalImage': '원본',
'resampleImage': '압축',
'defaultGalleryGroup':'Default Gallery Group',
'defaultArchiveGroup':'Default Archive Group',
'never': '영원히 안 함',
'manual': '수동',
'always': '항상 함',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/l18n/pt_BR.dart
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ class pt_BR {
'downloadOriginalImageByDefault': 'Escolher imagem original por padrão',
'originalImage': 'Original',
'resampleImage': 'Redimensionada',
'defaultGalleryGroup':'Default Gallery Group',
'defaultArchiveGroup':'Default Archive Group',
'never': 'Nunca',
'manual': 'Manual',
'always': 'Sempre',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/l18n/zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ class zh_CN {
'downloadOriginalImageByDefault': '默认选中下载原图',
'originalImage': '原图',
'resampleImage': '压缩',
'defaultGalleryGroup':'默认分组(下载)',
'defaultArchiveGroup':'默认分组(归档)',
'never': '从不',
'manual': '手动',
'always': '总是',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/l18n/zh_TW.dart
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ class zh_TW {
'downloadOriginalImageByDefault': '默認選中下載原圖',
'originalImage': '原圖',
'resampleImage': '壓縮',
'defaultGalleryGroup':'默認分組(下載)',
'defaultArchiveGroup':'默認分組(歸檔)',
'never': '從不',
'manual': '手動',
'always': '總是',
Expand Down
30 changes: 18 additions & 12 deletions lib/src/pages/details/details_page_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:jhentai/src/network/eh_request.dart';
import 'package:jhentai/src/pages/download/download_base_page.dart';
import 'package:jhentai/src/service/local_gallery_service.dart';
import 'package:jhentai/src/service/super_resolution_service.dart';
import 'package:jhentai/src/setting/download_setting.dart';
import 'package:jhentai/src/setting/my_tags_setting.dart';
import 'package:jhentai/src/utils/string_uril.dart';
import 'package:jhentai/src/widget/eh_add_tag_dialog.dart';
Expand Down Expand Up @@ -246,11 +247,13 @@ class DetailsPageLogic extends GetxController with LoginRequiredMixin, Scroll2To

/// new download
if (galleryDownloadedData == null || downloadProgress == null) {
Map<String, dynamic>? result = await Get.dialog(
({String group, bool downloadOriginalImage})? result = await Get.dialog(
EHDownloadDialog(
title: 'chooseGroup'.tr,
currentGroup: DownloadSetting.defaultGalleryGroup.value,
candidates: downloadService.allGroups,
showDownloadOriginalImageCheckBox: true,
showDownloadOriginalImageCheckBox: UserSetting.hasLoggedIn(),
downloadOriginalImage: DownloadSetting.downloadOriginalImageByDefault.value,
),
);

Expand All @@ -259,8 +262,8 @@ class DetailsPageLogic extends GetxController with LoginRequiredMixin, Scroll2To
}

downloadService.downloadGallery(gallery.toGalleryDownloadedData(
downloadOriginalImage: result['downloadOriginalImage'] ?? false,
group: result['group'] ?? 'default'.tr,
downloadOriginalImage: result.downloadOriginalImage,
group: result.group,
));

toast('${'beginToDownload'.tr}: ${gallery.gid}', isCenter: false);
Expand Down Expand Up @@ -440,20 +443,23 @@ class DetailsPageLogic extends GetxController with LoginRequiredMixin, Scroll2To

/// new download
if (archiveStatus == null) {
Map<String, dynamic>? result = await Get.dialog(EHArchiveDialog(
archivePageUrl: state.galleryDetails!.archivePageUrl,
candidates: archiveDownloadService.allGroups,
currentGroup: 'default'.tr,
));
({bool isOriginal, int size, String group})? result = await Get.dialog(
EHArchiveDialog(
title: 'chhoseArchive'.tr,
archivePageUrl: state.galleryDetails!.archivePageUrl,
currentGroup: DownloadSetting.defaultArchiveGroup.value,
candidates: archiveDownloadService.allGroups,
),
);
if (result == null) {
return;
}

ArchiveDownloadedData archive = state.gallery!.toArchiveDownloadedData(
archivePageUrl: state.galleryDetails!.archivePageUrl,
isOriginal: result['isOriginal'],
size: result['size'],
group: result['group'] ?? 'default'.tr,
isOriginal: result.isOriginal,
size: result.size,
group: result.group,
);

archiveDownloadService.downloadArchive(archive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mixin ArchiveDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
Future<void> handleChangeArchiveGroup(ArchiveDownloadedData archive) async {
String oldGroup = archiveDownloadService.archiveDownloadInfos[archive.gid]!.group;

Map<String, dynamic>? result = await Get.dialog(
({String group, bool downloadOriginalImage})? result = await Get.dialog(
EHDownloadDialog(
title: 'changeGroup'.tr,
currentGroup: oldGroup,
Expand All @@ -49,7 +49,7 @@ mixin ArchiveDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
return;
}

String newGroup = result['group'] ?? 'default'.tr;
String newGroup = result.group;
if (newGroup == oldGroup) {
return;
}
Expand Down Expand Up @@ -84,7 +84,7 @@ mixin ArchiveDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
}

Future<void> handleRenameGroup(String oldGroup) async {
Map<String, dynamic>? result = await Get.dialog(
({String group, bool downloadOriginalImage})? result = await Get.dialog(
EHDownloadDialog(
title: 'renameGroup'.tr,
currentGroup: oldGroup,
Expand All @@ -96,7 +96,7 @@ mixin ArchiveDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
return;
}

String newGroup = result['group'] ?? 'default'.tr;
String newGroup = result.group;
if (newGroup == oldGroup) {
return;
}
Expand Down Expand Up @@ -243,7 +243,7 @@ mixin ArchiveDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
}

Future<void> handleMultiChangeGroup() async {
Map<String, dynamic>? result = await Get.dialog(
({String group, bool downloadOriginalImage})? result = await Get.dialog(
EHDownloadDialog(
title: 'changeGroup'.tr,
candidates: archiveDownloadService.allGroups,
Expand All @@ -254,7 +254,7 @@ mixin ArchiveDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
return;
}

String newGroup = result['group'] ?? 'default'.tr;
String newGroup = result.group;

for (int gid in multiSelectDownloadPageState.selectedGids) {
await archiveDownloadService.updateArchiveGroupByGid(gid, newGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mixin GalleryDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
Future<void> handleChangeGroup(GalleryDownloadedData gallery) async {
String oldGroup = downloadService.galleryDownloadInfos[gallery.gid]!.group;

Map<String, dynamic>? result = await Get.dialog(
({String group, bool downloadOriginalImage})? result = await Get.dialog(
EHDownloadDialog(
title: 'changeGroup'.tr,
currentGroup: oldGroup,
Expand All @@ -40,7 +40,7 @@ mixin GalleryDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
return;
}

String newGroup = result['group'] ?? 'default'.tr;
String newGroup = result.group;
if (newGroup == oldGroup) {
return;
}
Expand All @@ -58,7 +58,7 @@ mixin GalleryDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
}

Future<void> handleRenameGroup(String oldGroup) async {
Map<String, dynamic>? result = await Get.dialog(
({String group, bool downloadOriginalImage})? result = await Get.dialog(
EHDownloadDialog(
title: 'renameGroup'.tr,
currentGroup: oldGroup,
Expand All @@ -70,7 +70,7 @@ mixin GalleryDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
return;
}

String newGroup = result['group'] ?? 'default'.tr;
String newGroup = result.group;
if (newGroup == oldGroup) {
return;
}
Expand Down Expand Up @@ -316,7 +316,7 @@ mixin GalleryDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
}

Future<void> handleMultiChangeGroup() async {
Map<String, dynamic>? result = await Get.dialog(
({String group, bool downloadOriginalImage})? result = await Get.dialog(
EHDownloadDialog(
title: 'changeGroup'.tr,
candidates: downloadService.allGroups,
Expand All @@ -327,7 +327,7 @@ mixin GalleryDownloadPageLogicMixin on GetxController implements Scroll2TopLogic
return;
}

String newGroup = result['group'] ?? 'default'.tr;
String newGroup = result.group;

for (int gid in multiSelectDownloadPageState.selectedGids) {
await downloadService.updateGroupByGid(gid, newGroup);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jhentai/src/config/ui_config.dart';
import 'package:jhentai/src/model/read_page_info.dart';
import 'package:jhentai/src/pages/read/layout/vertical_list/vertical_list_layout_state.dart';
import 'package:photo_view/photo_view_gallery.dart';
Expand Down
47 changes: 46 additions & 1 deletion lib/src/pages/setting/download/setting_download_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import '../../../service/gallery_download_service.dart';
import '../../../utils/log.dart';
import '../../../utils/permission_util.dart';
import '../../../utils/route_util.dart';
import '../../../widget/eh_download_dialog.dart';

class SettingDownloadPage extends StatefulWidget {
const SettingDownloadPage({Key? key}) : super(key: key);
Expand Down Expand Up @@ -63,6 +64,8 @@ class _SettingDownloadPageState extends State<SettingDownloadPage> {
_buildExtraGalleryScanPath(),
if (GetPlatform.isDesktop) _buildSingleImageSavePath(),
_buildDownloadOriginalImage(),
_buildDefaultGalleryGroup(context),
_buildDefaultArchiveGroup(context),
_buildDownloadConcurrency(),
_buildSpeedLimit(context),
_buildDownloadAllGallerysOfSamePriority(),
Expand Down Expand Up @@ -119,7 +122,7 @@ class _SettingDownloadPageState extends State<SettingDownloadPage> {
return ListTile(
title: Text('downloadOriginalImageByDefault'.tr),
trailing: Switch(
value: DownloadSetting.downloadOriginalImageByDefault.value ?? false,
value: DownloadSetting.downloadOriginalImageByDefault.value,
onChanged: (value) {
if (!UserSetting.hasLoggedIn()) {
toast('needLoginToOperate'.tr);
Expand All @@ -131,6 +134,48 @@ class _SettingDownloadPageState extends State<SettingDownloadPage> {
);
}

Widget _buildDefaultGalleryGroup(BuildContext context) {
return ListTile(
title: Text('defaultGalleryGroup'.tr),
trailing: Text(DownloadSetting.defaultGalleryGroup.value ?? 'default'.tr, style: UIConfig.settingPageListTileTrailingTextStyle(context)),
onTap: () async {
({String group, bool downloadOriginalImage})? result = await showDialog(
context: context,
builder: (_) => EHDownloadDialog(
title: 'chooseGroup'.tr,
currentGroup: DownloadSetting.defaultGalleryGroup.value,
candidates: galleryDownloadService.allGroups,
),
);

if (result != null) {
DownloadSetting.saveDefaultGalleryGroup(result.group);
}
},
).marginOnly(right: 12);
}

Widget _buildDefaultArchiveGroup(BuildContext context) {
return ListTile(
title: Text('defaultArchiveGroup'.tr),
trailing: Text(DownloadSetting.defaultArchiveGroup.value ?? 'default'.tr, style: UIConfig.settingPageListTileTrailingTextStyle(context)),
onTap: () async {
({String group, bool downloadOriginalImage})? result = await showDialog(
context: context,
builder: (_) => EHDownloadDialog(
title: 'chooseGroup'.tr,
currentGroup: DownloadSetting.defaultArchiveGroup.value,
candidates: archiveDownloadService.allGroups,
),
);

if (result != null) {
DownloadSetting.saveDefaultArchiveGroup(result.group);
}
},
).marginOnly(right: 12);
}

Widget _buildDownloadConcurrency() {
return ListTile(
title: Text('downloadTaskConcurrency'.tr),
Expand Down
31 changes: 20 additions & 11 deletions lib/src/setting/download_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import '../service/storage_service.dart';
class DownloadSetting {
static String defaultDownloadPath = join(PathSetting.getVisibleDir().path, 'download');
static RxString downloadPath = defaultDownloadPath.obs;
static RxnBool downloadOriginalImageByDefault = RxnBool(UserSetting.hasLoggedIn() ? false : null);
static RxBool downloadOriginalImageByDefault = false.obs;
static RxnString defaultGalleryGroup = RxnString();
static RxnString defaultArchiveGroup = RxnString();
static String defaultExtraGalleryScanPath = join(PathSetting.getVisibleDir().path, 'local_gallery');
static RxList<String> extraGalleryScanPath = <String>[defaultExtraGalleryScanPath].obs;
static RxString singleImageSavePath = join(PathSetting.getVisibleDir().path, 'save').obs;
Expand All @@ -28,15 +30,6 @@ class DownloadSetting {
} else {
Log.debug('init DownloadSetting success: default', false);
}

/// listen to login and logout
ever(UserSetting.ipbMemberId, (v) {
if (UserSetting.hasLoggedIn()) {
saveDownloadOriginalImageByDefault(false);
} else {
saveDownloadOriginalImageByDefault(null);
}
});
}

static saveDownloadPath(String downloadPath) {
Expand All @@ -63,12 +56,24 @@ class DownloadSetting {
_save();
}

static saveDownloadOriginalImageByDefault(bool? value) {
static saveDownloadOriginalImageByDefault(bool value) {
Log.debug('saveDownloadOriginalImageByDefault:$value');
DownloadSetting.downloadOriginalImageByDefault.value = value;
_save();
}

static saveDefaultGalleryGroup(String? group) {
Log.debug('saveDefaultGalleryGroup:$group');
DownloadSetting.defaultGalleryGroup.value = group;
_save();
}

static saveDefaultArchiveGroup(String? group) {
Log.debug('saveDefaultArchiveGroup:$group');
DownloadSetting.defaultArchiveGroup.value = group;
_save();
}

static saveDownloadTaskConcurrency(int downloadTaskConcurrency) {
Log.debug('saveDownloadTaskConcurrency:$downloadTaskConcurrency');
DownloadSetting.downloadTaskConcurrency.value = downloadTaskConcurrency;
Expand Down Expand Up @@ -115,6 +120,8 @@ class DownloadSetting {
'extraGalleryScanPath': extraGalleryScanPath.value,
'singleImageSavePath': singleImageSavePath.value,
'downloadOriginalImageByDefault': downloadOriginalImageByDefault.value,
'defaultGalleryGroup': defaultGalleryGroup.value,
'defaultArchiveGroup': defaultArchiveGroup.value,
'downloadTaskConcurrency': downloadTaskConcurrency.value,
'maximum': maximum.value,
'period': period.value.inMilliseconds,
Expand All @@ -133,6 +140,8 @@ class DownloadSetting {
}
singleImageSavePath.value = map['singleImageSavePath'] ?? singleImageSavePath.value;
downloadOriginalImageByDefault.value = map['downloadOriginalImageByDefault'] ?? downloadOriginalImageByDefault.value;
defaultGalleryGroup.value = map['defaultGalleryGroup'];
defaultArchiveGroup.value = map['defaultArchiveGroup'];
downloadTaskConcurrency.value = map['downloadTaskConcurrency'];
maximum.value = map['maximum'];
period.value = Duration(milliseconds: map['period']);
Expand Down
Loading

0 comments on commit 04275bc

Please sign in to comment.