Skip to content

Commit

Permalink
feat: remember delete task option (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed May 17, 2024
1 parent a89c55b commit 0583e4a
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 42 deletions.
18 changes: 15 additions & 3 deletions ui/flutter/lib/api/model/downloader_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class DownloaderConfig {

factory DownloaderConfig.fromJson(Map<String, dynamic> json) =>
_$DownloaderConfigFromJson(json);

Map<String, dynamic> toJson() => _$DownloaderConfigToJson(this);
}

Expand All @@ -29,6 +30,7 @@ class ProtocolConfig {

factory ProtocolConfig.fromJson(Map<String, dynamic>? json) =>
json == null ? ProtocolConfig() : _$ProtocolConfigFromJson(json);

Map<String, dynamic> toJson() => _$ProtocolConfigToJson(this);
}

Expand All @@ -47,6 +49,7 @@ class HttpConfig {

factory HttpConfig.fromJson(Map<String, dynamic> json) =>
_$HttpConfigFromJson(json);

Map<String, dynamic> toJson() => _$HttpConfigToJson(this);
}

Expand All @@ -59,19 +62,27 @@ class BtConfig {

factory BtConfig.fromJson(Map<String, dynamic> json) =>
_$BtConfigFromJson(json);

Map<String, dynamic> toJson() => _$BtConfigToJson(this);
}

@JsonSerializable(explicitToJson: true)
class ExtraConfig {
String themeMode = '';
String locale = '';
String themeMode;
String locale;
bool lastDeleteTaskKeep;

ExtraConfigBt bt = ExtraConfigBt();

ExtraConfig();
ExtraConfig({
this.themeMode = '',
this.locale = '',
this.lastDeleteTaskKeep = false,
});

factory ExtraConfig.fromJson(Map<String, dynamic>? json) =>
json == null ? ExtraConfig() : _$ExtraConfigFromJson(json);

Map<String, dynamic> toJson() => _$ExtraConfigToJson(this);
}

Expand Down Expand Up @@ -112,5 +123,6 @@ class ExtraConfigBt {

factory ExtraConfigBt.fromJson(Map<String, dynamic> json) =>
_$ExtraConfigBtFromJson(json);

Map<String, dynamic> toJson() => _$ExtraConfigBtToJson(this);
}
16 changes: 9 additions & 7 deletions ui/flutter/lib/api/model/downloader_config.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ui/flutter/lib/api/model/options.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ui/flutter/lib/api/model/resource.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/flutter/lib/api/model/result.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ui/flutter/lib/api/model/task.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class AppController extends GetxController with WindowListener, TrayListener {
try {
downloaderConfig.value = await getConfig();
} catch (e) {
logger.w("load downloader config fail", e);
logger.w("load downloader config fail", e, StackTrace.current);
downloaderConfig.value = DownloaderConfig();
}
await _initDownloaderConfig();
Expand Down
27 changes: 9 additions & 18 deletions ui/flutter/lib/app/modules/create/views/create_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import '../../../../util/input_formatter.dart';
import '../../../../util/message.dart';
import '../../../../util/util.dart';
import '../../../routes/app_pages.dart';
import '../../../views/compact_checkbox.dart';
import '../../../views/directory_selector.dart';
import '../../../views/file_list_view.dart';
import '../../app/controllers/app_controller.dart';
Expand Down Expand Up @@ -321,23 +322,13 @@ class CreateView extends GetView<CreateController> {
Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
onPressed: () {
controller.directDownload.value =
!controller.directDownload.value;
},
child: Row(children: [
Obx(() => Checkbox(
value:
controller.directDownload.value,
onChanged: (bool? value) {
controller.directDownload.value =
value ?? false;
},
)),
Text('directDownload'.tr),
]),
),
CompactCheckbox(
label: 'directDownload'.tr,
value: controller.directDownload.value,
onChanged: (bool? value) {
controller.directDownload.value =
value ?? false;
}),
TextButton(
onPressed: () {
controller.showAdvanced.value =
Expand Down Expand Up @@ -415,7 +406,7 @@ class CreateView extends GetView<CreateController> {
}
}

/*
/*
Check if is direct download, there has two ways to direct download
1. Direct download option is checked
2. Muli line urls
Expand Down
15 changes: 11 additions & 4 deletions ui/flutter/lib/app/views/buid_task_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import '../../util/file_icon.dart';
import '../../util/icons.dart';
import '../../util/message.dart';
import '../../util/util.dart';
import '../modules/app/controllers/app_controller.dart';
import '../routes/app_pages.dart';

class BuildTaskListView extends GetView {
Expand Down Expand Up @@ -73,7 +74,7 @@ class BuildTaskListView extends GetView {
}

Future<void> showDeleteDialog(String id) {
final keep = true.obs;
final appController = Get.find<AppController>();

final context = Get.context!;

Expand All @@ -83,11 +84,14 @@ class BuildTaskListView extends GetView {
builder: (_) => AlertDialog(
title: Text('deleteTask'.tr),
content: Obx(() => CheckboxListTile(
value: keep.value,
value: appController
.downloaderConfig.value.extra.lastDeleteTaskKeep,
title: Text('deleteTaskTip'.tr,
style: context.textTheme.bodyLarge),
onChanged: (v) {
keep.value = v!;
appController.downloaderConfig.update((val) {
val!.extra.lastDeleteTaskKeep = v!;
});
})),
actions: [
TextButton(
Expand All @@ -101,7 +105,10 @@ class BuildTaskListView extends GetView {
),
onPressed: () async {
try {
await deleteTask(id, !keep.value);
final force = !appController
.downloaderConfig.value.extra.lastDeleteTaskKeep;
await appController.saveConfig();
await deleteTask(id, force);
Get.back();
} catch (e) {
showErrorMessage(e);
Expand Down
66 changes: 66 additions & 0 deletions ui/flutter/lib/app/views/compact_checkbox.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';

class CompactCheckbox extends StatefulWidget {
final String label;
final bool value;
final ValueChanged<bool?>? onChanged;
final double? scale;
final TextStyle? textStyle;

const CompactCheckbox({
super.key,
required this.label,
required this.value,
this.onChanged,
this.scale,
this.textStyle,
});

@override
State<CompactCheckbox> createState() => _CompactCheckboxState();
}

class _CompactCheckboxState extends State<CompactCheckbox> {
late bool _value;

@override
void initState() {
super.initState();
_value = widget.value;
}

valueChanged(bool? value) {
setState(() {
_value = value!;
});
widget.onChanged?.call(_value);
}

@override
Widget build(BuildContext context) {
final checkbox = Checkbox(
value: _value,
onChanged: valueChanged,
);

return TextButton(
onPressed: () {
valueChanged(!_value);
},
child: Row(
children: [
widget.scale == null
? checkbox
: Transform.scale(
scale: widget.scale,
child: checkbox,
),
Text(
widget.label,
style: widget.textStyle,
),
],
),
);
}
}
2 changes: 1 addition & 1 deletion ui/flutter/lib/core/common/start_config.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0583e4a

Please sign in to comment.