diff --git a/lib/basic/Method.dart b/lib/basic/Method.dart index 5c804d84..edc779dd 100644 --- a/lib/basic/Method.dart +++ b/lib/basic/Method.dart @@ -1061,8 +1061,8 @@ class Method { return ComicSubscribe.fromJson(jsonDecode(data)); } - Future addSubscribed(ComicInfo comicInfo) async { - return _flatInvoke("addSubscribed", comicInfo); + Future addSubscribed(String comicId) async { + return _flatInvoke("addSubscribed", comicId); } Future removeAllSubscribed() async { diff --git a/lib/screens/ComicInfoScreen.dart b/lib/screens/ComicInfoScreen.dart index aaa97718..3b6f091c 100644 --- a/lib/screens/ComicInfoScreen.dart +++ b/lib/screens/ComicInfoScreen.dart @@ -41,6 +41,7 @@ class _ComicInfoScreenState extends State with RouteAware { late Future _comicFuture = _loadComic(); late Key _comicFutureKey = UniqueKey(); late Future _viewFuture = _loadViewLog(); + late Future _subscribedFuture = _loadSubscribed(); late Future> _epListFuture = _loadEps(); StreamSubscription? _linkSubscription; @@ -63,6 +64,10 @@ class _ComicInfoScreenState extends State with RouteAware { return method.loadView(widget.comicId); } + Future _loadSubscribed() { + return method.loadSubscribed(widget.comicId); + } + @override void didChangeDependencies() { super.didChangeDependencies(); @@ -144,6 +149,7 @@ class _ComicInfoScreenState extends State with RouteAware { appBar: AppBar( title: Text(_comicInfo.title), actions: [ + _buildSubscribeAction(_subscribedFuture, _comicInfo), _buildDownloadAction(_epListFuture, _comicInfo), ], ), @@ -262,6 +268,48 @@ class _ComicInfoScreenState extends State with RouteAware { ); } + Widget _buildSubscribeAction( + Future _subscribedFuture, + ComicInfo _comicInfo, + ) { + return FutureBuilder( + future: _subscribedFuture, + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasError) { + return IconButton( + onPressed: () { + setState(() { + this._subscribedFuture = _loadSubscribed(); + }); + }, + icon: const Icon(Icons.sync_problem), + ); + } + if (snapshot.connectionState != ConnectionState.done) { + return IconButton(onPressed: () {}, icon: const Icon(Icons.sync)); + } + var _subscribed = snapshot.data; + return IconButton( + onPressed: () async { + if (_subscribed == null) { + await method.addSubscribed(_comicInfo.id); + } else { + await method.removeSubscribed(_comicInfo.id); + } + setState(() { + this._subscribedFuture = _loadSubscribed(); + }); + }, + icon: Icon( + _subscribed == null + ? Icons.notifications_none + : Icons.notifications, + ), + ); + }, + ); + } + Widget _buildDownloadAction( Future> _epListFuture, ComicInfo _comicInfo,