Skip to content

Commit 38e8e04

Browse files
committed
✨ subscribe comics more button
1 parent 91b9c54 commit 38e8e04

File tree

3 files changed

+80
-21
lines changed

3 files changed

+80
-21
lines changed

lib/basic/Method.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,4 +1082,8 @@ class Method {
10821082
Future updateSubscribed() async {
10831083
return _flatInvoke("updateSubscribed", "");
10841084
}
1085+
1086+
Future updateSubscribedForce() async {
1087+
return _flatInvoke("updateSubscribedForce", "");
1088+
}
10851089
}

lib/screens/ComicSubscribesScreen.dart

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:pikapika/screens/components/ComicList.dart';
55
import 'package:pikapika/screens/components/CommonData.dart';
66
import 'package:pikapika/screens/components/ContentBuilder.dart';
77

8+
import '../basic/config/Address.dart';
89
import 'components/Badge.dart';
910
import 'components/Common.dart';
1011

@@ -71,36 +72,75 @@ class ComicSubscribesScreen extends StatefulWidget {
7172
}
7273

7374
class _ComicSubscribesScreenState extends State<ComicSubscribesScreen> {
74-
Future<List<ComicSubscribe>> _future = method.allSubscribed();
75-
Key _key = UniqueKey();
75+
@override
76+
void initState() {
77+
super.initState();
78+
subscribedEvent.subscribe(_setState);
79+
}
80+
81+
@override
82+
void dispose() {
83+
subscribedEvent.unsubscribe(_setState);
84+
super.dispose();
85+
}
86+
87+
void _setState(_) {
88+
setState(() {});
89+
}
7690

7791
@override
7892
Widget build(BuildContext context) {
7993
return Scaffold(
8094
appBar: AppBar(
81-
title: const Text('订阅'),
95+
title: const Text('更新提醒'),
8296
actions: [
8397
commonPopMenu(context),
98+
addressPopMenu(context),
99+
_popMenu(context),
84100
],
85101
),
86-
body: ContentBuilder(
87-
future: _future,
88-
key: _key,
89-
onRefresh: () async {
90-
setState(() {
91-
_future = method.allSubscribed();
92-
_key = UniqueKey();
93-
});
94-
},
95-
successBuilder: (BuildContext context,
96-
AsyncSnapshot<List<ComicSubscribe>> snapshot) {
97-
List<ComicSimple> comicList = [];
98-
for (var comicSubscribe in snapshot.requireData) {
99-
comicList.add(ComicSimple.fromJson(comicSubscribe.toSimpleJson()));
100-
}
101-
return ComicList(comicList);
102-
},
103-
),
102+
body: _body(context),
104103
);
105104
}
105+
106+
Widget _body(BuildContext context) {
107+
final subs = allSubscribed.values.toList();
108+
List<ComicSimple> comicList = [];
109+
for (var comicSubscribe in subs) {
110+
comicList.add(ComicSimple.fromJson(comicSubscribe.toSimpleJson()));
111+
}
112+
return ComicList(comicList);
113+
}
114+
}
115+
116+
Widget _popMenu(BuildContext context) {
117+
return PopupMenuButton<int>(
118+
icon: const Icon(Icons.more_vert),
119+
itemBuilder: (BuildContext context) => <PopupMenuItem<int>>[
120+
const PopupMenuItem<int>(
121+
value: 0,
122+
child: ListTile(
123+
leading: Icon(Icons.share),
124+
title: Text("检查更新"),
125+
),
126+
),
127+
const PopupMenuItem<int>(
128+
value: 1,
129+
child: ListTile(
130+
leading: Icon(Icons.image_search),
131+
title: Text("取消所有更新提醒"),
132+
),
133+
),
134+
],
135+
onSelected: (int value) {
136+
switch (value) {
137+
case 0:
138+
updateSubscribedForce();
139+
break;
140+
case 1:
141+
removeAllSubscribed();
142+
break;
143+
}
144+
},
145+
);
106146
}

lib/screens/components/CommonData.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ final Map<String, ComicSubscribe> allSubscribed = {};
99

1010
Future updateSubscribed() async {
1111
await method.updateSubscribed();
12+
await _update();
13+
}
14+
15+
Future updateSubscribedForce() async {
16+
await method.updateSubscribedForce();
17+
await _update();
18+
}
19+
20+
Future _update() async {
1221
final _allSubscribed = await method.allSubscribed();
1322
allSubscribed.clear();
1423
for (var subscribed in _allSubscribed) {
@@ -17,6 +26,12 @@ Future updateSubscribed() async {
1726
subscribedEvent.broadcast();
1827
}
1928

29+
Future removeAllSubscribed() async {
30+
await method.removeAllSubscribed();
31+
allSubscribed.clear();
32+
subscribedEvent.broadcast();
33+
}
34+
2035
Future subscribedViewed(String id) async {
2136
if (allSubscribed.containsKey(id)) {
2237
allSubscribed.remove(id);

0 commit comments

Comments
 (0)