@@ -11,9 +11,12 @@ import 'package:path/path.dart' as path;
11
11
import 'package:url_launcher/url_launcher_string.dart' ;
12
12
13
13
// Project imports:
14
+ import '../../../controller/app/progress_controller.dart' ;
14
15
import '../../../database/app/app_bmf.dart' ;
15
16
import '../../../database/app/app_rss.dart' ;
17
+ import '../../../models/bangumi/bangumi_model.dart' ;
16
18
import '../../../models/database/app_bmf_model.dart' ;
19
+ import '../../../request/bangumi/bangumi_api.dart' ;
17
20
import '../../../store/nav_store.dart' ;
18
21
import '../../../tools/file_tool.dart' ;
19
22
import '../../../tools/notifier_tool.dart' ;
@@ -29,11 +32,19 @@ class BsdBmfWidget extends StatefulWidget {
29
32
/// subjectId
30
33
final int subjectId;
31
34
35
+ /// title
36
+ final String title;
37
+
32
38
/// 模式-是用于详情页还是用于配置页
33
39
final bool isConfig;
34
40
35
41
/// 构造函数
36
- const BsdBmfWidget (this .subjectId, {super .key, this .isConfig = false });
42
+ const BsdBmfWidget (
43
+ this .subjectId,
44
+ this .title, {
45
+ super .key,
46
+ this .isConfig = false ,
47
+ });
37
48
38
49
@override
39
50
State <BsdBmfWidget > createState () => _BsdBmfWidgetState ();
@@ -48,11 +59,20 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
48
59
/// rss 数据库
49
60
final BtsAppRss sqliteRss = BtsAppRss ();
50
61
62
+ /// bgmApi
63
+ final BtrBangumiApi apiBgm = BtrBangumiApi ();
64
+
65
+ /// progress
66
+ late ProgressController progress = ProgressController ();
67
+
51
68
/// file tool
52
69
final BTFileTool fileTool = BTFileTool ();
53
70
54
71
/// bmf
55
- late AppBmfModel bmf = AppBmfModel (subject: widget.subjectId);
72
+ late AppBmfModel bmf = AppBmfModel (
73
+ subject: widget.subjectId,
74
+ title: widget.title,
75
+ );
56
76
57
77
/// 是否保持状态
58
78
@override
@@ -86,6 +106,67 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
86
106
);
87
107
}
88
108
109
+ /// 获取title
110
+ Future <String ?> getTitle () async {
111
+ if (mounted) {
112
+ progress = ProgressWidget .show (context, title: '正在查找标题' , text: '请稍后' );
113
+ }
114
+ var resp = await apiBgm.getSubjectDetail (widget.subjectId.toString ());
115
+ progress.end ();
116
+ if (resp.code != 0 || resp.data == null ) {
117
+ if (mounted) await showRespErr (resp, context);
118
+ return null ;
119
+ }
120
+ var data = resp.data as BangumiSubject ;
121
+ if (data.nameCn.isEmpty) return data.name;
122
+ return data.nameCn;
123
+ }
124
+
125
+ /// 标题检测
126
+ Future <void > titleCheck () async {
127
+ if (bmf.title != null && bmf.title! .isNotEmpty) return ;
128
+ var confirm = await showConfirm (
129
+ context,
130
+ title: '尝试获取标题?' ,
131
+ content: '检测到标题为空' ,
132
+ );
133
+ if (! confirm) return ;
134
+ var title = await getTitle ();
135
+ if (title != null ) bmf.title = title;
136
+ setState (() {});
137
+ await sqliteBmf.write (bmf);
138
+ if (mounted) {
139
+ await BtInfobar .success (context, '[${bmf .subject }]已设置标题:${bmf .title }' );
140
+ }
141
+ }
142
+
143
+ /// 更新标题
144
+ Future <void > updateTitle () async {
145
+ var hasTitle = bmf.title != null && bmf.rss! .isNotEmpty;
146
+ var title = bmf.title;
147
+ if (! hasTitle) title = await getTitle ();
148
+ title ?? = "" ;
149
+ if (mounted) {
150
+ var res = await showInput (
151
+ context,
152
+ title: hasTitle ? '修改标题' : '设置标题' ,
153
+ value: title,
154
+ content: '' ,
155
+ );
156
+ if (res != null ) {
157
+ setState (() {
158
+ bmf.title = title;
159
+ });
160
+ if (mounted) {
161
+ await BtInfobar .success (
162
+ context,
163
+ '[${bmf .subject }]已设置标题:${bmf .title }' ,
164
+ );
165
+ }
166
+ }
167
+ }
168
+ }
169
+
89
170
/// 更新Rss链接
90
171
Future <void > updateRss () async {
91
172
var input = await showInput (
@@ -108,6 +189,7 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
108
189
if (mounted) await BtInfobar .success (context, '成功删除旧 RSS 数据' );
109
190
}
110
191
bmf.rss = input;
192
+ await titleCheck ();
111
193
await sqliteBmf.write (bmf);
112
194
var read = await sqliteBmf.read (bmf.subject);
113
195
if (read != null ) {
@@ -127,6 +209,7 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
127
209
return ;
128
210
}
129
211
bmf.download = dir;
212
+ await titleCheck ();
130
213
await sqliteBmf.write (bmf);
131
214
var read = await sqliteBmf.read (bmf.subject);
132
215
if (read != null ) {
@@ -136,6 +219,18 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
136
219
if (mounted) await BtInfobar .success (context, '成功设置下载目录' );
137
220
}
138
221
222
+ /// buildHeaderActTitle
223
+ Widget buildHeaderActTitle (BuildContext context) {
224
+ var hasTitle = bmf.title != null && bmf.rss! .isNotEmpty;
225
+ return Tooltip (
226
+ message: hasTitle ? '修改标题' : '设置标题' ,
227
+ child: IconButton (
228
+ icon: BtIcon (hasTitle ? MdiIcons .bookEdit : MdiIcons .bookEditOutline),
229
+ onPressed: updateTitle,
230
+ ),
231
+ );
232
+ }
233
+
139
234
/// buildHeaderActRss
140
235
Widget buildHeaderActRss (BuildContext context) {
141
236
var hasRss = bmf.rss != null && bmf.rss! .isNotEmpty;
@@ -186,6 +281,8 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
186
281
Widget buildHeaderAction (BuildContext context) {
187
282
return Row (
188
283
children: [
284
+ buildHeaderActTitle (context),
285
+ SizedBox (width: 12. w),
189
286
buildHeaderActRss (context),
190
287
SizedBox (width: 12. w),
191
288
buildHeaderActFile (context),
@@ -222,7 +319,10 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
222
319
child: Expander (
223
320
leading: BsdBmfLeading (widget.isConfig, bmf),
224
321
header: widget.isConfig
225
- ? Text (bmf.subject.toString (), style: TextStyle (fontSize: 24. sp))
322
+ ? Text (
323
+ '${bmf .title ?? '' }(${bmf .subject })' ,
324
+ style: TextStyle (fontSize: 24. sp),
325
+ )
226
326
: Text ('BMF Config' , style: TextStyle (fontSize: 24. sp)),
227
327
content: Column (
228
328
crossAxisAlignment: CrossAxisAlignment .start,
0 commit comments